[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 | |
---|
| 17 | # Remove a category |
---|
| 18 | if (!empty($_POST['del_cat'])) |
---|
| 19 | { |
---|
| 20 | try |
---|
| 21 | { |
---|
[1015] | 22 | # Check if category to delete exists |
---|
[0] | 23 | $c = $core->blog->getCategory((integer) $_POST['del_cat']); |
---|
| 24 | if ($c->isEmpty()) { |
---|
| 25 | throw new Exception(__('This category does not exist.')); |
---|
| 26 | } |
---|
| 27 | unset($c); |
---|
[1015] | 28 | |
---|
| 29 | # Check if category where to move posts exists |
---|
| 30 | $mov_cat = (integer) $_POST['mov_cat']; |
---|
| 31 | $mov_cat = $mov_cat ? $mov_cat : null; |
---|
| 32 | if ($mov_cat !== null) { |
---|
[1390] | 33 | $c = $core->blog->getCategory((integer) $_POST['mov_cat']); |
---|
[1015] | 34 | if ($c->isEmpty()) { |
---|
| 35 | throw new Exception(__('This category does not exist.')); |
---|
| 36 | } |
---|
[1016] | 37 | if ($mov_cat == $_POST['del_cat']) { |
---|
| 38 | throw new Exception(__('The entries cannot be moved to the category you choose to delete.')); |
---|
| 39 | } |
---|
[1015] | 40 | unset($c); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | # Move posts |
---|
[1030] | 44 | $core->blog->changePostsCategory($_POST['del_cat'],$mov_cat); |
---|
[1015] | 45 | |
---|
| 46 | # Delete category |
---|
[0] | 47 | $core->blog->delCategory($_POST['del_cat']); |
---|
[1015] | 48 | |
---|
[0] | 49 | http::redirect('categories.php?del=1'); |
---|
| 50 | } |
---|
| 51 | catch (Exception $e) |
---|
| 52 | { |
---|
| 53 | $core->error->add($e->getMessage()); |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | # Reset order |
---|
| 58 | if (!empty($_POST['reset'])) |
---|
| 59 | { |
---|
| 60 | try |
---|
| 61 | { |
---|
| 62 | $core->blog->resetCategoriesOrder(); |
---|
| 63 | http::redirect('categories.php?reord=1'); |
---|
| 64 | } |
---|
| 65 | catch (Exception $e) |
---|
| 66 | { |
---|
| 67 | $core->error->add($e->getMessage()); |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /* Display |
---|
| 72 | -------------------------------------------------------- */ |
---|
| 73 | dcPage::open(__('Categories'), |
---|
| 74 | dcPage::jsToolMan()."\n". |
---|
| 75 | dcPage::jsLoad('js/_categories.js') |
---|
| 76 | ); |
---|
| 77 | |
---|
| 78 | if (!empty($_GET['add'])) { |
---|
[907] | 79 | dcPage::message(__('The category has been successfully created.')); |
---|
[0] | 80 | } |
---|
| 81 | if (!empty($_GET['del'])) { |
---|
[907] | 82 | dcPage::message(__('The category has been successfully removed.')); |
---|
[0] | 83 | } |
---|
| 84 | if (!empty($_GET['reord'])) { |
---|
[907] | 85 | dcPage::message(__('Categories have been successfully reordered.')); |
---|
[0] | 86 | } |
---|
| 87 | if (!empty($_GET['moved'])) { |
---|
[907] | 88 | dcPage::message(__('The category has been successfully moved.')); |
---|
[0] | 89 | } |
---|
| 90 | |
---|
[500] | 91 | echo '<h2>'.html::escapeHTML($core->blog->name).' › <span class="page-title">'.__('Categories').'</span></h2>'; |
---|
[0] | 92 | |
---|
| 93 | $rs = $core->blog->getCategories(array('post_type'=>'post')); |
---|
| 94 | |
---|
| 95 | echo |
---|
| 96 | '<div class="two-cols">'. |
---|
| 97 | '<div class="col">'; |
---|
| 98 | if ($rs->isEmpty()) |
---|
| 99 | { |
---|
| 100 | echo '<p>'.__('No category yet.').'</p>'; |
---|
| 101 | } |
---|
| 102 | else |
---|
| 103 | { |
---|
| 104 | echo |
---|
| 105 | '<h3>'.__('Categories list').'</h3>'. |
---|
| 106 | '<div id="categories">'; |
---|
| 107 | |
---|
| 108 | $ref_level = $level = $rs->level-1; |
---|
| 109 | while ($rs->fetch()) |
---|
| 110 | { |
---|
| 111 | $attr = 'id="cat'.$rs->cat_id.'"'; |
---|
| 112 | if ($rs->nb_total == 0) { |
---|
| 113 | $attr .= ' class="deletable"'; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | if ($rs->level > $level) { |
---|
| 117 | echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level); |
---|
| 118 | } elseif ($rs->level < $level) { |
---|
| 119 | echo str_repeat('</li></ul>',-($rs->level - $level)); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | if ($rs->level <= $level) { |
---|
| 123 | echo '</li><li '.$attr.'>'; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | echo |
---|
| 127 | '<p><strong><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></strong>'. |
---|
| 128 | ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'. |
---|
| 129 | sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. |
---|
| 130 | ', '.__('total:').' '.$rs->nb_total.')</p>'. |
---|
| 131 | '<p>'.__('URL:').' '.html::escapeHTML($rs->cat_url).'</p>'; |
---|
| 132 | |
---|
| 133 | $level = $rs->level; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | if ($ref_level - $level < 0) { |
---|
| 137 | echo str_repeat('</li></ul>',-($ref_level - $level)); |
---|
| 138 | } |
---|
| 139 | echo '</div>'; |
---|
| 140 | } |
---|
| 141 | echo '</div>'; |
---|
| 142 | |
---|
[1390] | 143 | $categories_combo = array(); |
---|
| 144 | if (!$rs->isEmpty()) |
---|
| 145 | { |
---|
| 146 | $l = $rs->level; |
---|
| 147 | $full_name = array($rs->cat_title); |
---|
| 148 | |
---|
| 149 | while ($rs->fetch()) { |
---|
| 150 | if ($rs->level < $l) { |
---|
| 151 | $full_name = array(); |
---|
| 152 | } elseif ($rs->level == $l) { |
---|
| 153 | array_pop($full_name); |
---|
| 154 | } |
---|
| 155 | $full_name[] = html::escapeHTML($rs->cat_title); |
---|
| 156 | $categories_combo[implode(' / ',$full_name)] = $rs->cat_id; |
---|
| 157 | $l = $rs->level; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
[0] | 161 | echo '<div class="col">'. |
---|
| 162 | |
---|
| 163 | '<form action="category.php" method="post">'. |
---|
| 164 | '<fieldset><legend>'.__('Add a new category').'</legend>'. |
---|
[82] | 165 | '<p><label class="required" for="cat_title"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').' '. |
---|
[1390] | 166 | form::field('cat_title',30,255,'','maximal').'</label></p>'. |
---|
[38] | 167 | '<p><label for="new_cat_parent">'.__('Parent:').' '. |
---|
[1390] | 168 | form::combo('new_cat_parent',array_merge(array(__('(No cat)') => 0),$categories_combo),'','maximal'). |
---|
| 169 | '</label></p>'. |
---|
[559] | 170 | '<p><input type="submit" value="'.__('Create').'" /></p>'. |
---|
[0] | 171 | $core->formNonce(). |
---|
| 172 | '</fieldset>'. |
---|
| 173 | '</form>'; |
---|
| 174 | |
---|
| 175 | if (!$rs->isEmpty()) |
---|
| 176 | { |
---|
[1015] | 177 | echo |
---|
| 178 | '<form action="categories.php" method="post" id="delete-category">'. |
---|
| 179 | '<fieldset><legend>'.__('Remove a category').'</legend>'. |
---|
| 180 | '<p><label for="del_cat">'.__('Choose a category to remove:').' '. |
---|
[1390] | 181 | form::combo('del_cat',$categories_combo,'','maximal').'</label></p> '. |
---|
[1017] | 182 | '<p><label for="mov_cat">'.__('And choose the category which will receive its entries:').' '. |
---|
[1390] | 183 | form::combo('mov_cat',array_merge(array(__('(No cat)') => ''),$categories_combo),'','maximal').'</label></p> '. |
---|
[1015] | 184 | '<p><input type="submit" value="'.__('Delete').'" class="delete" /></p>'. |
---|
| 185 | $core->formNonce(). |
---|
| 186 | '</fieldset>'. |
---|
| 187 | '</form>'; |
---|
[0] | 188 | |
---|
| 189 | echo |
---|
| 190 | '<form action="categories.php" method="post" id="reset-order">'. |
---|
| 191 | '<fieldset><legend>'.__('Reorder categories').'</legend>'. |
---|
| 192 | '<p>'.__('This will relocate all categories on the top level').'</p> '. |
---|
| 193 | '<p><input type="submit" value="'.__('Reorder').'" /></p>'. |
---|
| 194 | form::hidden(array('reset'),1). |
---|
| 195 | $core->formNonce(). |
---|
| 196 | '</fieldset>'. |
---|
| 197 | '</form>'; |
---|
| 198 | } |
---|
| 199 | echo '</div>'; |
---|
| 200 | echo '</div>'; |
---|
| 201 | |
---|
| 202 | dcPage::helpBlock('core_categories'); |
---|
| 203 | dcPage::close(); |
---|
| 204 | ?> |
---|