[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'])) { |
---|
[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 |
---|
| 58 | if (!empty($_POST['categories_order'])) |
---|
| 59 | { |
---|
| 60 | $categories = json_decode($_POST['categories_order']); |
---|
| 61 | |
---|
| 62 | foreach ($categories as $category) { |
---|
| 63 | if (!empty($category->item_id)) { |
---|
| 64 | $core->blog->updCategoryPosition($category->item_id, $category->left, $category->right); |
---|
| 65 | } |
---|
| 66 | } |
---|
| 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 | # Actions combo box |
---|
| 85 | $combo_action = array(); |
---|
| 86 | if ($core->auth->check('categories',$core->blog->id)) { |
---|
| 87 | $combo_action[__('Delete')] = 'delete'; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
[0] | 91 | /* Display |
---|
| 92 | -------------------------------------------------------- */ |
---|
[1532] | 93 | $rs = $core->blog->getCategories(array('post_type'=>'post')); |
---|
| 94 | |
---|
| 95 | $starting_script = dcPage::jsToolMan()."\n"; |
---|
| 96 | if (!$core->auth->user_prefs->accessibility->nodragdrop |
---|
| 97 | && $core->auth->check('categories',$core->blog->id) |
---|
| 98 | && $rs->count()>1) { |
---|
| 99 | $starting_script .= dcPage::jsLoad('js/jquery/jquery-ui.custom.js'); |
---|
| 100 | $starting_script .= dcPage::jsLoad('js/jquery/jquery.mjs.nestedSortable.js'); |
---|
| 101 | } |
---|
| 102 | $starting_script .= dcPage::jsLoad('js/_categories.js'); |
---|
| 103 | |
---|
| 104 | dcPage::open(__('Categories'),$starting_script, |
---|
[1358] | 105 | dcPage::breadcrumb( |
---|
| 106 | array( |
---|
| 107 | html::escapeHTML($core->blog->name) => '', |
---|
| 108 | '<span class="page-title">'.__('Categories').'</span>' => '' |
---|
| 109 | )) |
---|
[0] | 110 | ); |
---|
| 111 | |
---|
| 112 | if (!empty($_GET['del'])) { |
---|
[1531] | 113 | dcPage::message(__('The category has been successfully removed.', |
---|
| 114 | 'The categories have been successfully removed.', |
---|
| 115 | (int) $_GET['del'] |
---|
| 116 | ) |
---|
| 117 | ); |
---|
[0] | 118 | } |
---|
| 119 | if (!empty($_GET['reord'])) { |
---|
[907] | 120 | dcPage::message(__('Categories have been successfully reordered.')); |
---|
[0] | 121 | } |
---|
| 122 | |
---|
[1390] | 123 | $categories_combo = array(); |
---|
| 124 | if (!$rs->isEmpty()) |
---|
| 125 | { |
---|
| 126 | while ($rs->fetch()) { |
---|
[1421] | 127 | $catparents_combo[] = $categories_combo[] = new formSelectOption( |
---|
| 128 | str_repeat(' ',$rs->level-1).($rs->level-1 == 0 ? '' : '• ').html::escapeHTML($rs->cat_title), |
---|
| 129 | $rs->cat_id |
---|
| 130 | ); |
---|
[1390] | 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
[1525] | 134 | echo |
---|
| 135 | '<p class="top-add"><a class="button add" href="category.php">'.__('New category').'</a></p>'; |
---|
[0] | 136 | |
---|
[1525] | 137 | echo |
---|
| 138 | '<div class="col">'; |
---|
| 139 | if ($rs->isEmpty()) |
---|
| 140 | { |
---|
| 141 | echo '<p>'.__('No category yet.').'</p>'; |
---|
| 142 | } |
---|
| 143 | else |
---|
[0] | 144 | { |
---|
[1015] | 145 | echo |
---|
[1525] | 146 | '<form action="categories.php" method="post" id="form-categories">'. |
---|
[1534] | 147 | '<h3>'.__('List of blog\'s categories').'</h3>'. |
---|
[1525] | 148 | '<div id="categories">'; |
---|
[1468] | 149 | |
---|
[1525] | 150 | $ref_level = $level = $rs->level-1; |
---|
| 151 | while ($rs->fetch()) |
---|
| 152 | { |
---|
[1532] | 153 | $attr = 'id="cat_'.$rs->cat_id.'"'; |
---|
[1525] | 154 | |
---|
| 155 | if ($rs->level > $level) { |
---|
| 156 | echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level); |
---|
| 157 | } elseif ($rs->level < $level) { |
---|
| 158 | echo str_repeat('</li></ul>',-($rs->level - $level)); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | if ($rs->level <= $level) { |
---|
| 162 | echo '</li><li '.$attr.'>'; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | echo |
---|
[1531] | 166 | '<p>'. |
---|
[1551] | 167 | form::checkbox(array('categories[]','cat-'.$rs->cat_id),$rs->cat_id,null,$rs->nb_total>0?'notempty':''). |
---|
[1534] | 168 | '<label class="classic" for="cat-'.$rs->cat_id.'"><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></label>'. |
---|
[1525] | 169 | ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'. |
---|
| 170 | sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. |
---|
[1547] | 171 | ', '.__('total:').' '.$rs->nb_total.') '. |
---|
| 172 | __('URL:').' <code>'.html::escapeHTML($rs->cat_url).'</code></p>'; |
---|
[1525] | 173 | |
---|
| 174 | $level = $rs->level; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | if ($ref_level - $level < 0) { |
---|
| 178 | echo str_repeat('</li></ul>',-($ref_level - $level)); |
---|
| 179 | } |
---|
[0] | 180 | echo |
---|
[1525] | 181 | '</div>'; |
---|
| 182 | |
---|
| 183 | if (count($combo_action)>0) { |
---|
| 184 | echo |
---|
| 185 | '<div class="two-cols">'. |
---|
| 186 | '<p class="col checkboxes-helpers"></p>'. |
---|
[1547] | 187 | '<div class="col right">'. |
---|
| 188 | '<p class="cat-actions"><label for="action" class="classic">'.__('Selected categories action:').'</label> '. |
---|
| 189 | form::combo('action',$combo_action).' '. |
---|
| 190 | '<span id="mov-cat"><label for="mov_cat">'.__('Choose the category which will receive its entries:').'</label> '. |
---|
| 191 | form::combo('mov_cat',array_merge(array(__('(No cat)') => ''),$categories_combo),'','').' </span>'. |
---|
[1525] | 192 | $core->formNonce(). |
---|
[1547] | 193 | '<input type="submit" value="'.__('OK').'" /></p>'. |
---|
| 194 | '</div>'. |
---|
[1525] | 195 | '</div>'. |
---|
| 196 | '</form>'; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | echo |
---|
| 200 | '<div class="col clear">'. |
---|
[1534] | 201 | '<h3>'.__('Categories order').'</h3>'. |
---|
[1525] | 202 | '<form action="categories.php" method="post" id="reset-order">'. |
---|
[1534] | 203 | '<p><input type="submit" value="'.__('Reorder all categories on the top level').'" />'. |
---|
[0] | 204 | form::hidden(array('reset'),1). |
---|
[1399] | 205 | $core->formNonce().'</p>'. |
---|
[1525] | 206 | '</form>'. |
---|
| 207 | '</div>'; |
---|
[1532] | 208 | |
---|
| 209 | if (!$core->auth->user_prefs->accessibility->nodragdrop |
---|
| 210 | && $core->auth->check('categories',$core->blog->id) |
---|
| 211 | && $rs->count()>1) { |
---|
| 212 | echo |
---|
[1534] | 213 | '<div class="col">'. |
---|
[1532] | 214 | '<form action="categories.php" method="post">'. |
---|
[1534] | 215 | '<p>'.__('To rearrange categories order, move items by drag and drop, then click on “Save categories order” button.').'</p>'. |
---|
[1532] | 216 | '<p>'. |
---|
| 217 | '<input type="hidden" id="categories_order" name="categories_order" value=""/>'. |
---|
[1534] | 218 | '<input type="submit" id="save-set-order" value="'.__('Save categories order').'" />'. |
---|
[1532] | 219 | $core->formNonce().'</p>'. |
---|
| 220 | '</form>'. |
---|
| 221 | '</div>'; |
---|
| 222 | } |
---|
[0] | 223 | } |
---|
[1525] | 224 | |
---|
[0] | 225 | echo '</div>'; |
---|
| 226 | |
---|
| 227 | dcPage::helpBlock('core_categories'); |
---|
| 228 | dcPage::close(); |
---|
[1468] | 229 | ?> |
---|