[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.')); |
---|
[2852] | 26 | $core->adminurl->redirect("admin.categories"); |
---|
[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))); |
---|
[2852] | 35 | $core->adminurl->redirect("admin.categories"); |
---|
[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 | |
---|
[3340] | 49 | $mov_cat = $mov_cat ?: null; |
---|
[1531] | 50 | if ($mov_cat !== null) { |
---|
| 51 | $c = $core->blog->getCategory($mov_cat); |
---|
| 52 | if ($c->isEmpty()) { |
---|
[3210] | 53 | throw new Exception(__('Category where to move entries does not exist')); |
---|
[1531] | 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))); |
---|
[2852] | 64 | $core->adminurl->redirect("admin.categories"); |
---|
[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) { |
---|
[2709] | 75 | if (!empty($category->item_id) && !empty($category->left) && !empty($category->right)) { |
---|
[1595] | 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.')); |
---|
[2852] | 81 | $core->adminurl->redirect("admin.categories"); |
---|
[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.')); |
---|
[2852] | 91 | $core->adminurl->redirect("admin.categories"); |
---|
[0] | 92 | } |
---|
| 93 | catch (Exception $e) |
---|
| 94 | { |
---|
| 95 | $core->error->add($e->getMessage()); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
[1525] | 99 | |
---|
[0] | 100 | /* Display |
---|
| 101 | -------------------------------------------------------- */ |
---|
[3209] | 102 | $rs = $core->blog->getCategories(); |
---|
[1532] | 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 | } |
---|
[2805] | 114 | $starting_script .= dcPage::jsConfirmClose('form-categories'); |
---|
[1532] | 115 | $starting_script .= dcPage::jsLoad('js/_categories.js'); |
---|
| 116 | |
---|
| 117 | dcPage::open(__('Categories'),$starting_script, |
---|
[1358] | 118 | dcPage::breadcrumb( |
---|
| 119 | array( |
---|
| 120 | html::escapeHTML($core->blog->name) => '', |
---|
[2166] | 121 | __('Categories') => '' |
---|
[1358] | 122 | )) |
---|
[0] | 123 | ); |
---|
| 124 | |
---|
| 125 | if (!empty($_GET['del'])) { |
---|
[1953] | 126 | dcPage::success(__('The category has been successfully removed.')); |
---|
[0] | 127 | } |
---|
| 128 | if (!empty($_GET['reord'])) { |
---|
[1553] | 129 | dcPage::success(__('Categories have been successfully reordered.')); |
---|
[0] | 130 | } |
---|
[1953] | 131 | if (!empty($_GET['move'])) { |
---|
| 132 | dcPage::success(__('Entries have been successfully moved to the category you choose.')); |
---|
| 133 | } |
---|
| 134 | |
---|
[1719] | 135 | $categories_combo = dcAdminCombos::getCategoriesCombo($rs); |
---|
[1390] | 136 | |
---|
[1525] | 137 | echo |
---|
[2720] | 138 | '<p class="top-add"><a class="button add" href="'.$core->adminurl->get("admin.category").'">'.__('New category').'</a></p>'; |
---|
[0] | 139 | |
---|
[1525] | 140 | echo |
---|
| 141 | '<div class="col">'; |
---|
| 142 | if ($rs->isEmpty()) |
---|
| 143 | { |
---|
[1636] | 144 | echo '<p>'.__('No category so far.').'</p>'; |
---|
[1525] | 145 | } |
---|
| 146 | else |
---|
[0] | 147 | { |
---|
[1015] | 148 | echo |
---|
[2720] | 149 | '<form action="'.$core->adminurl->get("admin.categories").'" method="post" id="form-categories">'. |
---|
[1525] | 150 | '<div id="categories">'; |
---|
[1468] | 151 | |
---|
[1525] | 152 | $ref_level = $level = $rs->level-1; |
---|
| 153 | while ($rs->fetch()) |
---|
| 154 | { |
---|
[1957] | 155 | $attr = 'id="cat_'.$rs->cat_id.'" class="cat-line clearfix"'; |
---|
[1525] | 156 | |
---|
| 157 | if ($rs->level > $level) { |
---|
| 158 | echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level); |
---|
| 159 | } elseif ($rs->level < $level) { |
---|
| 160 | echo str_repeat('</li></ul>',-($rs->level - $level)); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | if ($rs->level <= $level) { |
---|
| 164 | echo '</li><li '.$attr.'>'; |
---|
| 165 | } |
---|
| 166 | |
---|
[2464] | 167 | echo |
---|
[2720] | 168 | '<p class="cat-title"><label class="classic" for="cat_'.$rs->cat_id.'"><a href="'. |
---|
| 169 | $core->adminurl->get("admin.category",array('id' => $rs->cat_id)).'">'.html::escapeHTML($rs->cat_title). |
---|
| 170 | '</a></label> </p>'. |
---|
| 171 | '<p class="cat-nb-posts">(<a href="'.$core->adminurl->get("admin.posts",array('cat_id' => $rs->cat_id)).'">'. |
---|
[1957] | 172 | sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. |
---|
| 173 | ', '.__('total:').' '.$rs->nb_total.')</p>'. |
---|
[2125] | 174 | '<p class="cat-url">'.__('URL:').' <code>'.html::escapeHTML($rs->cat_url).'</code></p>'; |
---|
[1957] | 175 | |
---|
[1525] | 176 | echo |
---|
[1957] | 177 | '<p class="cat-buttons">'; |
---|
[1953] | 178 | if ($rs->nb_total>0) { |
---|
| 179 | // remove current category |
---|
[1957] | 180 | echo |
---|
[2790] | 181 | '<label for="mov_cat_'.$rs->cat_id.'">'.__('Move entries to').'</label> '. |
---|
[1963] | 182 | 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] | 183 | ' <input type="submit" class="reset" name="mov['.$rs->cat_id.']" value="'.__('OK').'"/>'; |
---|
[2464] | 184 | |
---|
[1953] | 185 | $attr_disabled = ' disabled="disabled"'; |
---|
| 186 | $input_class = 'disabled '; |
---|
| 187 | } else { |
---|
| 188 | $attr_disabled = ''; |
---|
| 189 | $input_class = ''; |
---|
| 190 | } |
---|
[2464] | 191 | echo |
---|
[2342] | 192 | ' <input type="submit"'.$attr_disabled.' class="'.$input_class.'delete" name="delete['.$rs->cat_id.']" value="'.__('Delete category').'"/>'. |
---|
[1953] | 193 | '</p>'; |
---|
[1525] | 194 | |
---|
| 195 | $level = $rs->level; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | if ($ref_level - $level < 0) { |
---|
| 199 | echo str_repeat('</li></ul>',-($ref_level - $level)); |
---|
| 200 | } |
---|
[0] | 201 | echo |
---|
[1525] | 202 | '</div>'; |
---|
| 203 | |
---|
[1961] | 204 | echo '<div class="clear">'; |
---|
[1532] | 205 | |
---|
[1576] | 206 | if ($core->auth->check('categories',$core->blog->id) && $rs->count()>1) { |
---|
| 207 | if (!$core->auth->user_prefs->accessibility->nodragdrop) { |
---|
[1960] | 208 | 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] | 209 | } |
---|
| 210 | echo |
---|
[1961] | 211 | '<p><span class="hidden-if-no-js">'. |
---|
[1532] | 212 | '<input type="hidden" id="categories_order" name="categories_order" value=""/>'. |
---|
[1594] | 213 | '<input type="submit" name="save_order" id="save-set-order" value="'.__('Save categories order').'" />'. |
---|
[1960] | 214 | '</span> '; |
---|
[1961] | 215 | } else { |
---|
| 216 | echo '<p>'; |
---|
[1576] | 217 | } |
---|
[1566] | 218 | |
---|
| 219 | echo |
---|
[1960] | 220 | '<input type="submit" class="reset" name="reset" value="'.__('Reorder all categories on the top level').'" />'. |
---|
[1566] | 221 | $core->formNonce().'</p>'. |
---|
[1760] | 222 | '</div></form>'; |
---|
[0] | 223 | } |
---|
[1525] | 224 | |
---|
[0] | 225 | echo '</div>'; |
---|
| 226 | |
---|
| 227 | dcPage::helpBlock('core_categories'); |
---|
| 228 | dcPage::close(); |
---|