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