Dotclear

source: admin/categories.php @ 1399:cdf556efc5ea

Revision 1399:cdf556efc5ea, 5.6 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

Semantic xhtml and a11y. Let labels to be labels. Step One: admin. Plugins and Themes will come later.

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('categories');
16
17# Remove a category
18if (!empty($_POST['del_cat']))
19{
20     try
21     {
22          # Check if category to delete exists
23          $c = $core->blog->getCategory((integer) $_POST['del_cat']);
24          if ($c->isEmpty()) {
25               throw new Exception(__('This category does not exist.'));
26          }
27          unset($c);
28         
29          # Check if category where to move posts exists
30          $mov_cat = (integer) $_POST['mov_cat'];
31          $mov_cat = $mov_cat ? $mov_cat : null;
32          if ($mov_cat !== null) {
33               $c = $core->blog->getCategory((integer) $_POST['del_cat']);
34               if ($c->isEmpty()) {
35                    throw new Exception(__('This category does not exist.'));
36               }
37               if ($mov_cat == $_POST['del_cat']) {
38                    throw new Exception(__('The entries cannot be moved to the category you choose to delete.'));
39               }
40               unset($c);
41          }
42         
43          # Move posts
44          $core->blog->changePostsCategory($_POST['del_cat'],$mov_cat);
45         
46          # Delete category
47          $core->blog->delCategory($_POST['del_cat']);
48         
49          http::redirect('categories.php?del=1');
50     }
51     catch (Exception $e)
52     {
53          $core->error->add($e->getMessage());
54     }
55}
56
57# Reset order
58if (!empty($_POST['reset']))
59{
60     try
61     {
62          $core->blog->resetCategoriesOrder();
63          http::redirect('categories.php?reord=1');
64     }
65     catch (Exception $e)
66     {
67          $core->error->add($e->getMessage());
68     }
69}
70
71/* Display
72-------------------------------------------------------- */
73dcPage::open(__('Categories'),
74     dcPage::jsToolMan()."\n".
75     dcPage::jsLoad('js/_categories.js'),
76     dcPage::breadcrumb(
77          array(
78               html::escapeHTML($core->blog->name) => '',
79               '<span class="page-title">'.__('Categories').'</span>' => ''
80          ))
81);
82
83if (!empty($_GET['add'])) {
84     dcPage::message(__('The category has been successfully created.'));
85}
86if (!empty($_GET['del'])) {
87     dcPage::message(__('The category has been successfully removed.'));
88}
89if (!empty($_GET['reord'])) {
90     dcPage::message(__('Categories have been successfully reordered.'));
91}
92if (!empty($_GET['moved'])) {
93     dcPage::message(__('The category has been successfully moved.'));
94}
95
96$rs = $core->blog->getCategories(array('post_type'=>'post'));
97
98echo
99'<div class="two-cols">'.
100'<div class="col">';
101if ($rs->isEmpty())
102{
103     echo '<p>'.__('No category yet.').'</p>';
104}
105else
106{
107     echo
108     '<h3>'.__('Categories list').'</h3>'.
109     '<div id="categories">';
110     
111     $ref_level = $level = $rs->level-1;
112     while ($rs->fetch())
113     {
114          $attr = 'id="cat'.$rs->cat_id.'"';
115          if ($rs->nb_total == 0) {
116               $attr .= ' class="deletable"';
117          }
118         
119          if ($rs->level > $level) {
120               echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level);
121          } elseif ($rs->level < $level) {
122               echo str_repeat('</li></ul>',-($rs->level - $level));
123          }
124         
125          if ($rs->level <= $level) {
126               echo '</li><li '.$attr.'>';
127          }
128         
129          echo
130          '<p><strong><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></strong>'.
131          ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'.
132          sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'.
133          ', '.__('total:').' '.$rs->nb_total.')</p>'.
134          '<p>'.__('URL:').' '.html::escapeHTML($rs->cat_url).'</p>';
135         
136          $level = $rs->level;
137     }
138     
139     if ($ref_level - $level < 0) {
140          echo str_repeat('</li></ul>',-($ref_level - $level));
141     }
142     echo '</div>';
143}
144echo '</div>';
145
146echo '<div class="col">'.
147
148'<form action="category.php" method="post">'.
149'<h3>'.__('Add a new category').'</h3>'.
150'<p><label class="required" for="cat_title"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label> '.
151form::field('cat_title',30,255).'</p>'.
152'<p><label for="new_cat_parent">'.__('Parent:').'</label> '.
153'<select id="new_cat_parent" name="new_cat_parent">'.
154'<option value="0">'.__('Top level').'</option>';
155while ($rs->fetch()) {
156     echo '<option value="'.$rs->cat_id.'">'.
157          str_repeat('&nbsp;&nbsp;',$rs->level-1).($rs->level-1 == 0 ? '' : '&bull; ').
158          html::escapeHTML($rs->cat_title).'</option>';
159}
160echo
161'</select></p>'.
162'<p><input type="submit" value="'.__('Create').'" />'.
163$core->formNonce().'</p>'.
164'</form>';
165
166if (!$rs->isEmpty())
167{
168     $cats = array();
169     $dest = array('&nbsp;' => '');
170     $l = $rs->level;
171     $full_name = array($rs->cat_title);
172     while ($rs->fetch())
173     {
174          if ($rs->level < $l) {
175               $full_name = array();
176          } elseif ($rs->level == $l) {
177               array_pop($full_name);
178          }
179          $full_name[] = html::escapeHTML($rs->cat_title);
180         
181          $cats[implode(' / ',$full_name)] = $rs->cat_id;
182          $dest[implode(' / ',$full_name)] = $rs->cat_id;
183         
184          $l = $rs->level;
185     }
186     
187     echo
188     '<form action="categories.php" method="post" id="delete-category" class="border-top">'.
189     '<h3>'.__('Remove a category').'</h3>'.
190     '<p><label for="del_cat">'.__('Choose a category to remove:').'</label> '.
191     form::combo('del_cat',$cats).'</p> '.
192     '<p><label for="mov_cat">'.__('And choose the category which will receive its entries:').'</label> '.
193     form::combo('mov_cat',$dest).'</p> '.
194     '<p><input type="submit" value="'.__('Delete').'" class="delete" />'.
195     $core->formNonce().'</p>'.
196     '</form>';
197     
198     echo
199     '<form action="categories.php" method="post" id="reset-order" class="border-top">'.
200     '<h3>'.__('Reorder categories').'</h3>'.
201     '<p>'.__('This will relocate all categories on the top level').'</p> '.
202     '<p><input type="submit" value="'.__('Reorder').'" />'.
203     form::hidden(array('reset'),1).
204     $core->formNonce().'</p>'.
205     '</form>';
206}
207echo '</div>';
208echo '</div>';
209
210dcPage::helpBlock('core_categories');
211dcPage::close();
212?>
Note: See TracBrowser for help on using the repository browser.

Sites map