[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 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 | |
---|
[1525] | 17 | # Remove a categories |
---|
| 18 | if (!empty($_POST['categories'])) { |
---|
| 19 | $error = false; |
---|
| 20 | foreach ($_POST['categories'] as $cat_id) { |
---|
[1015] | 21 | # Check if category to delete exists |
---|
[1525] | 22 | $c = $core->blog->getCategory((integer) $cat_id); |
---|
[0] | 23 | if ($c->isEmpty()) { |
---|
[1525] | 24 | continue; |
---|
[0] | 25 | } |
---|
| 26 | unset($c); |
---|
[1525] | 27 | |
---|
| 28 | try { |
---|
| 29 | # Delete category |
---|
| 30 | $core->blog->delCategory($cat_id); |
---|
| 31 | } catch (Exception $e) { |
---|
| 32 | $error = true; |
---|
[1015] | 33 | } |
---|
[0] | 34 | } |
---|
[1525] | 35 | if (!$error) { |
---|
| 36 | http::redirect('categories.php?del='.count($_POST['categories'])); |
---|
[0] | 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 | |
---|
[1525] | 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 | |
---|
[0] | 64 | /* Display |
---|
| 65 | -------------------------------------------------------- */ |
---|
| 66 | dcPage::open(__('Categories'), |
---|
| 67 | dcPage::jsToolMan()."\n". |
---|
[1358] | 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 | )) |
---|
[0] | 74 | ); |
---|
| 75 | |
---|
| 76 | if (!empty($_GET['add'])) { |
---|
[907] | 77 | dcPage::message(__('The category has been successfully created.')); |
---|
[0] | 78 | } |
---|
| 79 | if (!empty($_GET['del'])) { |
---|
[1525] | 80 | dcPage::message(__('The category has been successfully removed.', |
---|
| 81 | 'The categories have been successfully removed.', |
---|
| 82 | (int) $_GET['del'] |
---|
| 83 | ) |
---|
| 84 | ); |
---|
[0] | 85 | } |
---|
| 86 | if (!empty($_GET['reord'])) { |
---|
[907] | 87 | dcPage::message(__('Categories have been successfully reordered.')); |
---|
[0] | 88 | } |
---|
| 89 | if (!empty($_GET['moved'])) { |
---|
[907] | 90 | dcPage::message(__('The category has been successfully moved.')); |
---|
[0] | 91 | } |
---|
| 92 | |
---|
| 93 | $rs = $core->blog->getCategories(array('post_type'=>'post')); |
---|
| 94 | |
---|
[1390] | 95 | $categories_combo = array(); |
---|
| 96 | if (!$rs->isEmpty()) |
---|
| 97 | { |
---|
| 98 | while ($rs->fetch()) { |
---|
[1421] | 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 | ); |
---|
[1390] | 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
[1525] | 106 | echo |
---|
| 107 | '<p class="top-add"><a class="button add" href="category.php">'.__('New category').'</a></p>'; |
---|
[0] | 108 | |
---|
[1525] | 109 | echo |
---|
| 110 | '<div class="col">'; |
---|
| 111 | if ($rs->isEmpty()) |
---|
| 112 | { |
---|
| 113 | echo '<p>'.__('No category yet.').'</p>'; |
---|
| 114 | } |
---|
| 115 | else |
---|
[0] | 116 | { |
---|
[1015] | 117 | echo |
---|
[1525] | 118 | '<form action="categories.php" method="post" id="form-categories">'. |
---|
| 119 | '<h3>'.__('Categories list').'</h3>'. |
---|
| 120 | '<div id="categories">'; |
---|
[1468] | 121 | |
---|
[1525] | 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 | } |
---|
[0] | 159 | echo |
---|
[1525] | 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">'. |
---|
[1399] | 177 | '<h3>'.__('Reorder categories').'</h3>'. |
---|
[0] | 178 | '<p>'.__('This will relocate all categories on the top level').'</p> '. |
---|
[1525] | 179 | '<p><input class="reset" type="submit" value="'.__('Reorder').'" />'. |
---|
[0] | 180 | form::hidden(array('reset'),1). |
---|
[1399] | 181 | $core->formNonce().'</p>'. |
---|
[1525] | 182 | '</form>'. |
---|
| 183 | '</div>'; |
---|
[0] | 184 | } |
---|
[1525] | 185 | |
---|
[0] | 186 | echo '</div>'; |
---|
| 187 | |
---|
| 188 | dcPage::helpBlock('core_categories'); |
---|
| 189 | dcPage::close(); |
---|
[1468] | 190 | ?> |
---|