Dotclear

source: admin/categories.php @ 1655:8a7a3512a770

Revision 1655:8a7a3512a770, 6.2 KB checked in by Lepeltier kévin, 11 years ago (diff)

Ticket #1604

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

Sites map