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