[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 |
---|
[1953] | 18 | if (!empty($_POST['delete'])) { |
---|
| 19 | $keys = array_keys($_POST['delete']); |
---|
| 20 | $cat_id = (int) $keys[0]; |
---|
| 21 | |
---|
| 22 | # Check if category to delete exists |
---|
| 23 | $c = $core->blog->getCategory((integer) $cat_id); |
---|
| 24 | if ($c->isEmpty()) { |
---|
[2189] | 25 | dcPage::addErrorNotice(__('This category does not exist.')); |
---|
| 26 | http::redirect('categories.php'); |
---|
[1953] | 27 | } |
---|
[2189] | 28 | $name = $c->cat_title; |
---|
[1953] | 29 | unset($c); |
---|
| 30 | |
---|
| 31 | try { |
---|
| 32 | # Delete category |
---|
| 33 | $core->blog->delCategory($cat_id); |
---|
[2189] | 34 | dcPage::addSuccessNotice(sprintf(__('The category "%s" has been successfully deleted.'),html::escapeHTML($name))); |
---|
| 35 | http::redirect('categories.php'); |
---|
[1953] | 36 | } catch (Exception $e) { |
---|
| 37 | $core->error->add($e->getMessage()); |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | # move post into a category |
---|
| 42 | if (!empty($_POST['mov']) && !empty($_POST['mov_cat'])) { |
---|
[1531] | 43 | try { |
---|
| 44 | # Check if category where to move posts exists |
---|
[1953] | 45 | $keys = array_keys($_POST['mov']); |
---|
| 46 | $cat_id = (int) $keys[0]; |
---|
| 47 | $mov_cat = (int) $_POST['mov_cat'][$cat_id]; |
---|
[2464] | 48 | |
---|
[1531] | 49 | $mov_cat = $mov_cat ? $mov_cat : null; |
---|
| 50 | if ($mov_cat !== null) { |
---|
| 51 | $c = $core->blog->getCategory($mov_cat); |
---|
| 52 | if ($c->isEmpty()) { |
---|
| 53 | throw new Exception(__('Category where to move posts does not exist')); |
---|
| 54 | } |
---|
[2189] | 55 | $name = $c->cat_title; |
---|
[1531] | 56 | unset($c); |
---|
[0] | 57 | } |
---|
[1953] | 58 | # Move posts |
---|
| 59 | if ($mov_cat != $cat_id) { |
---|
| 60 | $core->blog->changePostsCategory($cat_id,$mov_cat); |
---|
[1015] | 61 | } |
---|
[2189] | 62 | dcPage::addSuccessNotice(sprintf(__('The entries have been successfully moved to category "%s"'), |
---|
| 63 | html::escapeHTML($name))); |
---|
| 64 | http::redirect('categories.php'); |
---|
[1531] | 65 | } catch (Exception $e) { |
---|
| 66 | $core->error->add($e->getMessage()); |
---|
[0] | 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
[1532] | 70 | # Update order |
---|
[1595] | 71 | if (!empty($_POST['save_order']) && !empty($_POST['categories_order'])) { |
---|
| 72 | $categories = json_decode($_POST['categories_order']); |
---|
[1532] | 73 | |
---|
[1595] | 74 | foreach ($categories as $category) { |
---|
| 75 | if (!empty($category->item_id)) { |
---|
| 76 | $core->blog->updCategoryPosition($category->item_id, $category->left, $category->right); |
---|
[1532] | 77 | } |
---|
| 78 | } |
---|
[1594] | 79 | |
---|
[2256] | 80 | dcPage::addSuccessNotice(__('Categories have been successfully reordered.')); |
---|
| 81 | http::redirect('categories.php'); |
---|
[1532] | 82 | } |
---|
| 83 | |
---|
[0] | 84 | # Reset order |
---|
| 85 | if (!empty($_POST['reset'])) |
---|
| 86 | { |
---|
| 87 | try |
---|
| 88 | { |
---|
| 89 | $core->blog->resetCategoriesOrder(); |
---|
[2256] | 90 | dcPage::addSuccessNotice(__('Categories order has been successfully reset.')); |
---|
[2189] | 91 | http::redirect('categories.php'); |
---|
[0] | 92 | } |
---|
| 93 | catch (Exception $e) |
---|
| 94 | { |
---|
| 95 | $core->error->add($e->getMessage()); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
[1525] | 99 | |
---|
[0] | 100 | /* Display |
---|
| 101 | -------------------------------------------------------- */ |
---|
[1532] | 102 | $rs = $core->blog->getCategories(array('post_type'=>'post')); |
---|
| 103 | |
---|
[1655] | 104 | $starting_script = ""; |
---|
[2464] | 105 | |
---|
| 106 | $core->auth->user_prefs->addWorkspace('accessibility'); |
---|
[1532] | 107 | if (!$core->auth->user_prefs->accessibility->nodragdrop |
---|
| 108 | && $core->auth->check('categories',$core->blog->id) |
---|
| 109 | && $rs->count()>1) { |
---|
[1662] | 110 | $starting_script .= dcPage::jsLoad('js/jquery/jquery-ui.custom.js'); |
---|
[2495] | 111 | $starting_script .= dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js'); |
---|
[1655] | 112 | $starting_script .= dcPage::jsLoad('js/jquery/jquery.mjs.nestedSortable.js'); |
---|
[1532] | 113 | } |
---|
| 114 | $starting_script .= dcPage::jsLoad('js/_categories.js'); |
---|
| 115 | |
---|
| 116 | dcPage::open(__('Categories'),$starting_script, |
---|
[1358] | 117 | dcPage::breadcrumb( |
---|
| 118 | array( |
---|
| 119 | html::escapeHTML($core->blog->name) => '', |
---|
[2166] | 120 | __('Categories') => '' |
---|
[1358] | 121 | )) |
---|
[0] | 122 | ); |
---|
| 123 | |
---|
| 124 | if (!empty($_GET['del'])) { |
---|
[1953] | 125 | dcPage::success(__('The category has been successfully removed.')); |
---|
[0] | 126 | } |
---|
| 127 | if (!empty($_GET['reord'])) { |
---|
[1553] | 128 | dcPage::success(__('Categories have been successfully reordered.')); |
---|
[0] | 129 | } |
---|
[1953] | 130 | if (!empty($_GET['move'])) { |
---|
| 131 | dcPage::success(__('Entries have been successfully moved to the category you choose.')); |
---|
| 132 | } |
---|
| 133 | |
---|
[1719] | 134 | $categories_combo = dcAdminCombos::getCategoriesCombo($rs); |
---|
[1390] | 135 | |
---|
[1525] | 136 | echo |
---|
| 137 | '<p class="top-add"><a class="button add" href="category.php">'.__('New category').'</a></p>'; |
---|
[0] | 138 | |
---|
[1525] | 139 | echo |
---|
| 140 | '<div class="col">'; |
---|
| 141 | if ($rs->isEmpty()) |
---|
| 142 | { |
---|
[1636] | 143 | echo '<p>'.__('No category so far.').'</p>'; |
---|
[1525] | 144 | } |
---|
| 145 | else |
---|
[0] | 146 | { |
---|
[1015] | 147 | echo |
---|
[1525] | 148 | '<form action="categories.php" method="post" id="form-categories">'. |
---|
| 149 | '<div id="categories">'; |
---|
[1468] | 150 | |
---|
[1525] | 151 | $ref_level = $level = $rs->level-1; |
---|
| 152 | while ($rs->fetch()) |
---|
| 153 | { |
---|
[1957] | 154 | $attr = 'id="cat_'.$rs->cat_id.'" class="cat-line clearfix"'; |
---|
[1525] | 155 | |
---|
| 156 | if ($rs->level > $level) { |
---|
| 157 | echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level); |
---|
| 158 | } elseif ($rs->level < $level) { |
---|
| 159 | echo str_repeat('</li></ul>',-($rs->level - $level)); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | if ($rs->level <= $level) { |
---|
| 163 | echo '</li><li '.$attr.'>'; |
---|
| 164 | } |
---|
| 165 | |
---|
[2464] | 166 | echo |
---|
[2125] | 167 | '<p class="cat-title"><label class="classic" for="cat_'.$rs->cat_id.'"><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></label> </p>'. |
---|
| 168 | '<p class="cat-nb-posts">(<a href="posts.php?cat_id='.$rs->cat_id.'">'. |
---|
[1957] | 169 | sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. |
---|
| 170 | ', '.__('total:').' '.$rs->nb_total.')</p>'. |
---|
[2125] | 171 | '<p class="cat-url">'.__('URL:').' <code>'.html::escapeHTML($rs->cat_url).'</code></p>'; |
---|
[1957] | 172 | |
---|
[1525] | 173 | echo |
---|
[1957] | 174 | '<p class="cat-buttons">'; |
---|
[1953] | 175 | if ($rs->nb_total>0) { |
---|
| 176 | // remove current category |
---|
[1957] | 177 | echo |
---|
[2464] | 178 | '<label>'.__('Move entries to').'</label> '. |
---|
[1963] | 179 | form::combo(array('mov_cat['.$rs->cat_id.']', 'mov_cat_'.$rs->cat_id),array_filter($categories_combo, create_function('$cat', 'return $cat->value!=$GLOBALS[\'rs\']->cat_id;')),'',''). |
---|
[1957] | 180 | ' <input type="submit" class="reset" name="mov['.$rs->cat_id.']" value="'.__('OK').'"/>'; |
---|
[2464] | 181 | |
---|
[1953] | 182 | $attr_disabled = ' disabled="disabled"'; |
---|
| 183 | $input_class = 'disabled '; |
---|
| 184 | } else { |
---|
| 185 | $attr_disabled = ''; |
---|
| 186 | $input_class = ''; |
---|
| 187 | } |
---|
[2464] | 188 | echo |
---|
[2342] | 189 | ' <input type="submit"'.$attr_disabled.' class="'.$input_class.'delete" name="delete['.$rs->cat_id.']" value="'.__('Delete category').'"/>'. |
---|
[1953] | 190 | '</p>'; |
---|
[1525] | 191 | |
---|
| 192 | $level = $rs->level; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | if ($ref_level - $level < 0) { |
---|
| 196 | echo str_repeat('</li></ul>',-($ref_level - $level)); |
---|
| 197 | } |
---|
[0] | 198 | echo |
---|
[1525] | 199 | '</div>'; |
---|
| 200 | |
---|
[1961] | 201 | echo '<div class="clear">'; |
---|
[1532] | 202 | |
---|
[1576] | 203 | if ($core->auth->check('categories',$core->blog->id) && $rs->count()>1) { |
---|
| 204 | if (!$core->auth->user_prefs->accessibility->nodragdrop) { |
---|
[1960] | 205 | echo '<p class="form-note hidden-if-no-js">'.__('To rearrange categories order, move items by drag and drop, then click on “Save categories order” button.').'</p>'; |
---|
[1576] | 206 | } |
---|
| 207 | echo |
---|
[1961] | 208 | '<p><span class="hidden-if-no-js">'. |
---|
[1532] | 209 | '<input type="hidden" id="categories_order" name="categories_order" value=""/>'. |
---|
[1594] | 210 | '<input type="submit" name="save_order" id="save-set-order" value="'.__('Save categories order').'" />'. |
---|
[1960] | 211 | '</span> '; |
---|
[1961] | 212 | } else { |
---|
| 213 | echo '<p>'; |
---|
[1576] | 214 | } |
---|
[1566] | 215 | |
---|
| 216 | echo |
---|
[1960] | 217 | '<input type="submit" class="reset" name="reset" value="'.__('Reorder all categories on the top level').'" />'. |
---|
[1566] | 218 | $core->formNonce().'</p>'. |
---|
[1760] | 219 | '</div></form>'; |
---|
[0] | 220 | } |
---|
[1525] | 221 | |
---|
[0] | 222 | echo '</div>'; |
---|
| 223 | |
---|
| 224 | dcPage::helpBlock('core_categories'); |
---|
| 225 | dcPage::close(); |
---|
[1468] | 226 | ?> |
---|