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