Dotclear

source: admin/categories.php @ 1954:107cf75bb37b

Revision 1954:107cf75bb37b, 6.2 KB checked in by Nicolas <nikrou77@…>, 12 years ago (diff)

Remove closure and use create_function instead.

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 categories
18if (!empty($_POST['delete'])) {
19     $keys = array_keys($_POST['delete']);
20     $cat_id = (int) $keys[0];
21
22     # Check if category to delete exists
23     $c = $core->blog->getCategory((integer) $cat_id);
24     if ($c->isEmpty()) {
25          http::redirect('categories.php?unknown=1');
26     }
27     unset($c);
28
29     try {
30          # Delete category
31          $core->blog->delCategory($cat_id);
32          http::redirect('categories.php?del=1');
33     } catch (Exception $e) {
34          $core->error->add($e->getMessage());
35     }
36}
37
38# move post into a category
39if (!empty($_POST['mov']) && !empty($_POST['mov_cat'])) {
40     try {
41          # Check if category where to move posts exists
42          $keys = array_keys($_POST['mov']);
43          $cat_id = (int) $keys[0];
44          $mov_cat = (int) $_POST['mov_cat'][$cat_id];
45         
46          $mov_cat = $mov_cat ? $mov_cat : null;
47          if ($mov_cat !== null) {
48               $c = $core->blog->getCategory($mov_cat);
49               if ($c->isEmpty()) {
50                    throw new Exception(__('Category where to move posts does not exist'));
51               }
52               unset($c);
53          }
54          # Move posts
55          if ($mov_cat != $cat_id) {
56               $core->blog->changePostsCategory($cat_id,$mov_cat);
57          }
58          http::redirect('categories.php?move=1');
59     } catch (Exception $e) {
60          $core->error->add($e->getMessage());
61     }
62}
63
64# Update order
65if (!empty($_POST['save_order']) && !empty($_POST['categories_order'])) {
66     $categories = json_decode($_POST['categories_order']);
67
68     foreach ($categories as $category) {
69          if (!empty($category->item_id)) {
70               $core->blog->updCategoryPosition($category->item_id, $category->left, $category->right);
71          }
72     }
73
74     http::redirect('categories.php?reord=1');
75}
76
77# Reset order
78if (!empty($_POST['reset']))
79{
80     try
81     {
82          $core->blog->resetCategoriesOrder();
83          http::redirect('categories.php?reord=1');
84     }
85     catch (Exception $e)
86     {
87          $core->error->add($e->getMessage());
88     }
89}
90
91
92/* Display
93-------------------------------------------------------- */
94$rs = $core->blog->getCategories(array('post_type'=>'post'));
95
96$starting_script = "";
97if (!$core->auth->user_prefs->accessibility->nodragdrop
98     && $core->auth->check('categories',$core->blog->id)
99     && $rs->count()>1) {
100          $starting_script .= dcPage::jsLoad('js/jquery/jquery-ui.custom.js');
101          $starting_script .= dcPage::jsLoad('js/jquery/jquery.mjs.nestedSortable.js');
102}
103$starting_script .= dcPage::jsLoad('js/_categories.js');
104
105dcPage::open(__('Categories'),$starting_script,
106     dcPage::breadcrumb(
107          array(
108               html::escapeHTML($core->blog->name) => '',
109               '<span class="page-title">'.__('Categories').'</span>' => ''
110          ))
111);
112
113if (!empty($_GET['del'])) {
114     dcPage::success(__('The category has been successfully removed.'));
115}
116if (!empty($_GET['reord'])) {
117     dcPage::success(__('Categories have been successfully reordered.'));
118}
119if (!empty($_GET['unknown'])) {
120     dcPage::success(__('This category does not exist.'));
121}
122if (!empty($_GET['move'])) {
123     dcPage::success(__('Entries have been successfully moved to the category you choose.'));
124}
125
126$categories_combo = dcAdminCombos::getCategoriesCombo($rs);
127
128echo
129'<p class="top-add"><a class="button add" href="category.php">'.__('New category').'</a></p>';
130
131echo
132'<div class="col">';
133if ($rs->isEmpty())
134{
135     echo '<p>'.__('No category so far.').'</p>';
136}
137else
138{
139     echo
140     '<form action="categories.php" method="post" id="form-categories">'.
141     '<div id="categories">';
142
143     $ref_level = $level = $rs->level-1;
144     while ($rs->fetch())
145     {
146          $attr = 'id="cat_'.$rs->cat_id.'"';
147
148          if ($rs->level > $level) {
149               echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level);
150          } elseif ($rs->level < $level) {
151               echo str_repeat('</li></ul>',-($rs->level - $level));
152          }
153
154          if ($rs->level <= $level) {
155               echo '</li><li '.$attr.'>';
156          }
157
158          echo
159          '<p>'.       
160          '<label class="classic" for="cat-'.$rs->cat_id.'"><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></label>'.
161          ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'.
162          sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'.
163          ', '.__('total:').' '.$rs->nb_total.') '.
164               '<span class="cat-url">'.__('URL:').' <code>'.html::escapeHTML($rs->cat_url).'</code></span>';
165
166          if ($rs->nb_total>0) {
167               // remove current category
168               echo             
169               form::combo('mov_cat['.$rs->cat_id.']',array_filter($categories_combo, create_function('$cat', 'return $cat->value!=$GLOBALS[\'rs\']->cat_id;')),'','').
170               '<input type="submit" class="" name="mov['.$rs->cat_id.']" value="'.__('Ok').'"/>';
171             
172               $attr_disabled = ' disabled="disabled"';
173               $input_class = 'disabled ';
174          } else {
175               $attr_disabled = '';
176               $input_class = '';
177          }
178          echo 
179          '<input type="submit"'.$attr_disabled.' class="'.$input_class.'delete" name="delete['.$rs->cat_id.']" value="'.__('Delete category').'"/>'.
180          '</p>';
181
182          $level = $rs->level;
183     }
184
185     if ($ref_level - $level < 0) {
186          echo str_repeat('</li></ul>',-($ref_level - $level));
187     }
188     echo
189     '</div>';
190
191     echo '<div class="fieldset"><h3 class="clear hidden-if-no-js">'.__('Categories order').'</h3>';
192
193     if ($core->auth->check('categories',$core->blog->id) && $rs->count()>1) {
194          if (!$core->auth->user_prefs->accessibility->nodragdrop) {
195               echo '<p class="hidden-if-no-js">'.__('To rearrange categories order, move items by drag and drop, then click on “Save categories order” button.').'</p>';
196          }
197          echo
198          '<p class="hidden-if-no-js">'.
199          '<input type="hidden" id="categories_order" name="categories_order" value=""/>'.
200          '<input type="submit" name="save_order" id="save-set-order" value="'.__('Save categories order').'" />'.
201          '</p>';
202     }
203
204     echo
205     '<p class="hidden-if-js right"><input type="submit" name="reset" value="'.__('Reorder all categories on the top level and delete selected categories').'" />'.
206     $core->formNonce().'</p>'.
207     '<p class="hidden-if-no-js"><input type="submit" name="reset" value="'.__('Reorder all categories on the top level').'" />'.
208     $core->formNonce().'</p>'.
209     '</div></form>';
210}
211
212echo '</div>';
213
214dcPage::helpBlock('core_categories');
215dcPage::close();
216?>
Note: See TracBrowser for help on using the repository browser.

Sites map