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 | |
---|
13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
14 | |
---|
15 | dcPage::check('categories'); |
---|
16 | |
---|
17 | # Remove a categories |
---|
18 | if (!empty($_POST['categories'])) { |
---|
19 | $error = false; |
---|
20 | foreach ($_POST['categories'] as $cat_id) { |
---|
21 | # Check if category to delete exists |
---|
22 | $c = $core->blog->getCategory((integer) $cat_id); |
---|
23 | if ($c->isEmpty()) { |
---|
24 | continue; |
---|
25 | } |
---|
26 | unset($c); |
---|
27 | |
---|
28 | try { |
---|
29 | # Delete category |
---|
30 | $core->blog->delCategory($cat_id); |
---|
31 | } catch (Exception $e) { |
---|
32 | $error = true; |
---|
33 | } |
---|
34 | } |
---|
35 | if (!$error) { |
---|
36 | http::redirect('categories.php?del='.count($_POST['categories'])); |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | # Reset order |
---|
41 | if (!empty($_POST['reset'])) |
---|
42 | { |
---|
43 | try |
---|
44 | { |
---|
45 | $core->blog->resetCategoriesOrder(); |
---|
46 | http::redirect('categories.php?reord=1'); |
---|
47 | } |
---|
48 | catch (Exception $e) |
---|
49 | { |
---|
50 | $core->error->add($e->getMessage()); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | # Actions combo box |
---|
55 | $combo_action = array(); |
---|
56 | if ($core->auth->check('categories',$core->blog->id)) { |
---|
57 | $combo_action[__('Delete')] = 'delete'; |
---|
58 | } |
---|
59 | |
---|
60 | # --BEHAVIOR-- adminCategoriesActionsCombo |
---|
61 | $core->callBehavior('adminCategoriesActionsCombo',array(&$combo_action)); |
---|
62 | |
---|
63 | |
---|
64 | /* Display |
---|
65 | -------------------------------------------------------- */ |
---|
66 | dcPage::open(__('Categories'), |
---|
67 | dcPage::jsToolMan()."\n". |
---|
68 | dcPage::jsLoad('js/_categories.js'), |
---|
69 | dcPage::breadcrumb( |
---|
70 | array( |
---|
71 | html::escapeHTML($core->blog->name) => '', |
---|
72 | '<span class="page-title">'.__('Categories').'</span>' => '' |
---|
73 | )) |
---|
74 | ); |
---|
75 | |
---|
76 | if (!empty($_GET['add'])) { |
---|
77 | dcPage::message(__('The category has been successfully created.')); |
---|
78 | } |
---|
79 | if (!empty($_GET['del'])) { |
---|
80 | dcPage::message(__('The category has been successfully removed.', |
---|
81 | 'The categories have been successfully removed.', |
---|
82 | (int) $_GET['del'] |
---|
83 | ) |
---|
84 | ); |
---|
85 | } |
---|
86 | if (!empty($_GET['reord'])) { |
---|
87 | dcPage::message(__('Categories have been successfully reordered.')); |
---|
88 | } |
---|
89 | if (!empty($_GET['moved'])) { |
---|
90 | dcPage::message(__('The category has been successfully moved.')); |
---|
91 | } |
---|
92 | |
---|
93 | $rs = $core->blog->getCategories(array('post_type'=>'post')); |
---|
94 | |
---|
95 | $categories_combo = array(); |
---|
96 | if (!$rs->isEmpty()) |
---|
97 | { |
---|
98 | while ($rs->fetch()) { |
---|
99 | $catparents_combo[] = $categories_combo[] = new formSelectOption( |
---|
100 | str_repeat(' ',$rs->level-1).($rs->level-1 == 0 ? '' : '• ').html::escapeHTML($rs->cat_title), |
---|
101 | $rs->cat_id |
---|
102 | ); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | echo |
---|
107 | '<p class="top-add"><a class="button add" href="category.php">'.__('New category').'</a></p>'; |
---|
108 | |
---|
109 | echo |
---|
110 | '<div class="col">'; |
---|
111 | if ($rs->isEmpty()) |
---|
112 | { |
---|
113 | echo '<p>'.__('No category yet.').'</p>'; |
---|
114 | } |
---|
115 | else |
---|
116 | { |
---|
117 | echo |
---|
118 | '<form action="categories.php" method="post" id="form-categories">'. |
---|
119 | '<h3>'.__('Categories list').'</h3>'. |
---|
120 | '<div id="categories">'; |
---|
121 | |
---|
122 | $ref_level = $level = $rs->level-1; |
---|
123 | while ($rs->fetch()) |
---|
124 | { |
---|
125 | $attr = 'id="cat'.$rs->cat_id.'"'; |
---|
126 | if ($rs->nb_total == 0) { |
---|
127 | $attr .= ' class="deletable"'; |
---|
128 | } |
---|
129 | |
---|
130 | if ($rs->level > $level) { |
---|
131 | echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level); |
---|
132 | } elseif ($rs->level < $level) { |
---|
133 | echo str_repeat('</li></ul>',-($rs->level - $level)); |
---|
134 | } |
---|
135 | |
---|
136 | if ($rs->level <= $level) { |
---|
137 | echo '</li><li '.$attr.'>'; |
---|
138 | } |
---|
139 | |
---|
140 | echo |
---|
141 | '<p>'; |
---|
142 | if ($rs->nb_total == 0) { |
---|
143 | echo form::checkbox(array('categories[]'),$rs->cat_id); |
---|
144 | } |
---|
145 | |
---|
146 | echo |
---|
147 | '<strong><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></strong>'. |
---|
148 | ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'. |
---|
149 | sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. |
---|
150 | ', '.__('total:').' '.$rs->nb_total.')</p>'. |
---|
151 | '<p>'.__('URL:').' '.html::escapeHTML($rs->cat_url).'</p>'; |
---|
152 | |
---|
153 | $level = $rs->level; |
---|
154 | } |
---|
155 | |
---|
156 | if ($ref_level - $level < 0) { |
---|
157 | echo str_repeat('</li></ul>',-($ref_level - $level)); |
---|
158 | } |
---|
159 | echo |
---|
160 | '</div>'; |
---|
161 | |
---|
162 | if (count($combo_action)>0) { |
---|
163 | echo |
---|
164 | '<div class="two-cols">'. |
---|
165 | '<p class="col checkboxes-helpers"></p>'. |
---|
166 | '<p class="col right"><label for="action" class="classic">'.__('Selected categories action:').'</label> '. |
---|
167 | form::combo('action',$combo_action). |
---|
168 | $core->formNonce(). |
---|
169 | '<input type="submit" value="'.__('ok').'" /></p>'. |
---|
170 | '</div>'. |
---|
171 | '</form>'; |
---|
172 | } |
---|
173 | |
---|
174 | echo |
---|
175 | '<div class="col clear">'. |
---|
176 | '<form action="categories.php" method="post" id="reset-order">'. |
---|
177 | '<h3>'.__('Reorder categories').'</h3>'. |
---|
178 | '<p>'.__('This will relocate all categories on the top level').'</p> '. |
---|
179 | '<p><input class="reset" type="submit" value="'.__('Reorder').'" />'. |
---|
180 | form::hidden(array('reset'),1). |
---|
181 | $core->formNonce().'</p>'. |
---|
182 | '</form>'. |
---|
183 | '</div>'; |
---|
184 | } |
---|
185 | |
---|
186 | echo '</div>'; |
---|
187 | |
---|
188 | dcPage::helpBlock('core_categories'); |
---|
189 | dcPage::close(); |
---|
190 | ?> |
---|