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