[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 |
---|
[1594] | 18 | if (!empty($_POST['categories']) && !empty($_POST['delete'])) { |
---|
[1531] | 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 | } |
---|
[0] | 33 | } |
---|
[1525] | 34 | |
---|
[1531] | 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 | |
---|
[1525] | 48 | # Delete category |
---|
| 49 | $core->blog->delCategory($cat_id); |
---|
[1015] | 50 | } |
---|
[1525] | 51 | http::redirect('categories.php?del='.count($_POST['categories'])); |
---|
[1531] | 52 | } catch (Exception $e) { |
---|
| 53 | $core->error->add($e->getMessage()); |
---|
[0] | 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
[1532] | 57 | # Update order |
---|
[1595] | 58 | if (!empty($_POST['save_order']) && !empty($_POST['categories_order'])) { |
---|
| 59 | $categories = json_decode($_POST['categories_order']); |
---|
[1532] | 60 | |
---|
[1595] | 61 | foreach ($categories as $category) { |
---|
| 62 | if (!empty($category->item_id)) { |
---|
| 63 | $core->blog->updCategoryPosition($category->item_id, $category->left, $category->right); |
---|
[1532] | 64 | } |
---|
| 65 | } |
---|
[1594] | 66 | |
---|
[1532] | 67 | http::redirect('categories.php?reord=1'); |
---|
| 68 | } |
---|
| 69 | |
---|
[0] | 70 | # Reset order |
---|
| 71 | if (!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 | |
---|
[1525] | 84 | |
---|
[0] | 85 | /* Display |
---|
| 86 | -------------------------------------------------------- */ |
---|
[1532] | 87 | $rs = $core->blog->getCategories(array('post_type'=>'post')); |
---|
| 88 | |
---|
[1655] | 89 | $starting_script = ""; |
---|
[1532] | 90 | if (!$core->auth->user_prefs->accessibility->nodragdrop |
---|
| 91 | && $core->auth->check('categories',$core->blog->id) |
---|
| 92 | && $rs->count()>1) { |
---|
[1662] | 93 | $starting_script .= dcPage::jsLoad('js/jquery/jquery-ui.custom.js'); |
---|
[1655] | 94 | $starting_script .= dcPage::jsLoad('js/jquery/jquery.mjs.nestedSortable.js'); |
---|
[1532] | 95 | } |
---|
| 96 | $starting_script .= dcPage::jsLoad('js/_categories.js'); |
---|
| 97 | |
---|
| 98 | dcPage::open(__('Categories'),$starting_script, |
---|
[1358] | 99 | dcPage::breadcrumb( |
---|
| 100 | array( |
---|
| 101 | html::escapeHTML($core->blog->name) => '', |
---|
| 102 | '<span class="page-title">'.__('Categories').'</span>' => '' |
---|
| 103 | )) |
---|
[0] | 104 | ); |
---|
| 105 | |
---|
| 106 | if (!empty($_GET['del'])) { |
---|
[1553] | 107 | dcPage::success(__('The category has been successfully removed.', |
---|
[1531] | 108 | 'The categories have been successfully removed.', |
---|
| 109 | (int) $_GET['del'] |
---|
| 110 | ) |
---|
| 111 | ); |
---|
[0] | 112 | } |
---|
| 113 | if (!empty($_GET['reord'])) { |
---|
[1553] | 114 | dcPage::success(__('Categories have been successfully reordered.')); |
---|
[0] | 115 | } |
---|
| 116 | |
---|
[1390] | 117 | $categories_combo = array(); |
---|
| 118 | if (!$rs->isEmpty()) |
---|
| 119 | { |
---|
| 120 | while ($rs->fetch()) { |
---|
[1421] | 121 | $catparents_combo[] = $categories_combo[] = new formSelectOption( |
---|
| 122 | str_repeat(' ',$rs->level-1).($rs->level-1 == 0 ? '' : '• ').html::escapeHTML($rs->cat_title), |
---|
| 123 | $rs->cat_id |
---|
| 124 | ); |
---|
[1390] | 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
[1525] | 128 | echo |
---|
| 129 | '<p class="top-add"><a class="button add" href="category.php">'.__('New category').'</a></p>'; |
---|
[0] | 130 | |
---|
[1525] | 131 | echo |
---|
| 132 | '<div class="col">'; |
---|
| 133 | if ($rs->isEmpty()) |
---|
| 134 | { |
---|
[1636] | 135 | echo '<p>'.__('No category so far.').'</p>'; |
---|
[1525] | 136 | } |
---|
| 137 | else |
---|
[0] | 138 | { |
---|
[1015] | 139 | echo |
---|
[1525] | 140 | '<form action="categories.php" method="post" id="form-categories">'. |
---|
[1534] | 141 | '<h3>'.__('List of blog\'s categories').'</h3>'. |
---|
[1525] | 142 | '<div id="categories">'; |
---|
[1468] | 143 | |
---|
[1525] | 144 | $ref_level = $level = $rs->level-1; |
---|
| 145 | while ($rs->fetch()) |
---|
| 146 | { |
---|
[1532] | 147 | $attr = 'id="cat_'.$rs->cat_id.'"'; |
---|
[1525] | 148 | |
---|
| 149 | if ($rs->level > $level) { |
---|
| 150 | echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level); |
---|
| 151 | } elseif ($rs->level < $level) { |
---|
| 152 | echo str_repeat('</li></ul>',-($rs->level - $level)); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | if ($rs->level <= $level) { |
---|
| 156 | echo '</li><li '.$attr.'>'; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | echo |
---|
[1531] | 160 | '<p>'. |
---|
[1551] | 161 | form::checkbox(array('categories[]','cat-'.$rs->cat_id),$rs->cat_id,null,$rs->nb_total>0?'notempty':''). |
---|
[1534] | 162 | '<label class="classic" for="cat-'.$rs->cat_id.'"><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></label>'. |
---|
[1525] | 163 | ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'. |
---|
| 164 | sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. |
---|
[1547] | 165 | ', '.__('total:').' '.$rs->nb_total.') '. |
---|
[1595] | 166 | '<span class="cat-url">'.__('URL:').' <code>'.html::escapeHTML($rs->cat_url).'</code></span></p>'; |
---|
[1525] | 167 | |
---|
| 168 | $level = $rs->level; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | if ($ref_level - $level < 0) { |
---|
| 172 | echo str_repeat('</li></ul>',-($ref_level - $level)); |
---|
| 173 | } |
---|
[0] | 174 | echo |
---|
[1525] | 175 | '</div>'; |
---|
| 176 | |
---|
[1576] | 177 | echo |
---|
| 178 | '<div class="two-cols">'. |
---|
| 179 | '<p class="col checkboxes-helpers"></p>'. |
---|
| 180 | '<p class="col right" id="mov-cat">'. |
---|
| 181 | '<label for="mov_cat" class="classic">'.__('Category which will receive entries of deleted categories:').'</label> '. |
---|
| 182 | form::combo('mov_cat',array_merge(array(__('(No cat)') => ''),$categories_combo),'',''). |
---|
| 183 | '</p>'. |
---|
| 184 | '<p class="right">'. |
---|
[1599] | 185 | '<input type="submit" class="delete" name="delete" value="'.__('Delete selected categories').'"/>'. |
---|
[1576] | 186 | '</p>'. |
---|
[1594] | 187 | '</div>'; |
---|
[1525] | 188 | |
---|
[1599] | 189 | echo '<h3 class="clear hidden-if-no-js">'.__('Categories order').'</h3>'; |
---|
[1532] | 190 | |
---|
[1576] | 191 | if ($core->auth->check('categories',$core->blog->id) && $rs->count()>1) { |
---|
| 192 | if (!$core->auth->user_prefs->accessibility->nodragdrop) { |
---|
[1599] | 193 | 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>'; |
---|
[1576] | 194 | } |
---|
| 195 | echo |
---|
[1599] | 196 | '<p class="hidden-if-no-js">'. |
---|
[1532] | 197 | '<input type="hidden" id="categories_order" name="categories_order" value=""/>'. |
---|
[1594] | 198 | '<input type="submit" name="save_order" id="save-set-order" value="'.__('Save categories order').'" />'. |
---|
| 199 | '</p>'; |
---|
[1576] | 200 | } |
---|
[1566] | 201 | |
---|
| 202 | echo |
---|
[1599] | 203 | '<p class="hidden-if-js right"><input type="submit" name="reset" value="'.__('Reorder all categories on the top level and delete selected categories').'" />'. |
---|
| 204 | $core->formNonce().'</p>'. |
---|
| 205 | '<p class="hidden-if-no-js"><input type="submit" name="reset" value="'.__('Reorder all categories on the top level').'" />'. |
---|
[1566] | 206 | $core->formNonce().'</p>'. |
---|
| 207 | '</form>'; |
---|
[0] | 208 | } |
---|
[1525] | 209 | |
---|
[0] | 210 | echo '</div>'; |
---|
| 211 | |
---|
| 212 | dcPage::helpBlock('core_categories'); |
---|
| 213 | dcPage::close(); |
---|
[1468] | 214 | ?> |
---|