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