Dotclear

source: admin/categories.php @ 1741:b669af061dda

Revision 1741:b669af061dda, 5.9 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

Organisation et factorisation des CSS, step 1: Organisation.
Work in progress. L'affichage de toutes les pages a été testé.
(Au passage, nettoyage de bizarreries dans les fichiers php.)

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$categories_combo = dcAdminCombos::getCategoriesCombo($rs);
117
118echo
119'<p class="top-add"><a class="button add" href="category.php">'.__('New category').'</a></p>';
120
121echo
122'<div class="col">';
123if ($rs->isEmpty())
124{
125     echo '<p>'.__('No category so far.').'</p>';
126}
127else
128{
129     echo
130     '<form action="categories.php" method="post" id="form-categories">'.
131     '<div id="categories">';
132
133     $ref_level = $level = $rs->level-1;
134     while ($rs->fetch())
135     {
136          $attr = 'id="cat_'.$rs->cat_id.'"';
137
138          if ($rs->level > $level) {
139               echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level);
140          } elseif ($rs->level < $level) {
141               echo str_repeat('</li></ul>',-($rs->level - $level));
142          }
143
144          if ($rs->level <= $level) {
145               echo '</li><li '.$attr.'>';
146          }
147
148          echo
149          '<p>'.
150          form::checkbox(array('categories[]','cat-'.$rs->cat_id),$rs->cat_id,null,$rs->nb_total>0?'notempty':'').
151          '<label class="classic" for="cat-'.$rs->cat_id.'"><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></label>'.
152          ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'.
153          sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'.
154          ', '.__('total:').' '.$rs->nb_total.') '.
155          '<span class="cat-url">'.__('URL:').' <code>'.html::escapeHTML($rs->cat_url).'</code></span></p>';
156
157          $level = $rs->level;
158     }
159
160     if ($ref_level - $level < 0) {
161          echo str_repeat('</li></ul>',-($ref_level - $level));
162     }
163     echo
164     '</div>';
165
166     echo
167     '<div class="two-cols">'.
168     '<p class="col checkboxes-helpers"></p>'.
169     '<p class="col right" id="mov-cat">'.
170     '<label for="mov_cat" class="classic">'.__('Category which will receive entries of deleted categories:').'</label> '.
171     form::combo('mov_cat',$categories_combo,'','').
172     '</p>'.
173     '<p class="right">'.
174     '<input type="submit" class="delete" name="delete" value="'.__('Delete selected categories').'"/>'.
175     '</p>'.
176     '</div>';
177
178     echo '<h3 class="clear hidden-if-no-js">'.__('Categories order').'</h3>';
179
180     if ($core->auth->check('categories',$core->blog->id) && $rs->count()>1) {
181          if (!$core->auth->user_prefs->accessibility->nodragdrop) {
182               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>';
183          }
184          echo
185          '<p class="hidden-if-no-js">'.
186          '<input type="hidden" id="categories_order" name="categories_order" value=""/>'.
187          '<input type="submit" name="save_order" id="save-set-order" value="'.__('Save categories order').'" />'.
188          '</p>';
189     }
190
191     echo
192     '<p class="hidden-if-js right"><input type="submit" name="reset" value="'.__('Reorder all categories on the top level and delete selected categories').'" />'.
193     $core->formNonce().'</p>'.
194     '<p class="hidden-if-no-js"><input type="submit" name="reset" value="'.__('Reorder all categories on the top level').'" />'.
195     $core->formNonce().'</p>'.
196     '</form>';
197}
198
199echo '</div>';
200
201dcPage::helpBlock('core_categories');
202dcPage::close();
203?>
Note: See TracBrowser for help on using the repository browser.

Sites map