| 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of Dotclear 2. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
|---|
| 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 | |
|---|
| 17 | # Remove a categories |
|---|
| 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'])) { |
|---|
| 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]; |
|---|
| 45 | |
|---|
| 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); |
|---|
| 53 | } |
|---|
| 54 | # Move posts |
|---|
| 55 | if ($mov_cat != $cat_id) { |
|---|
| 56 | $core->blog->changePostsCategory($cat_id,$mov_cat); |
|---|
| 57 | } |
|---|
| 58 | http::redirect('categories.php?move=1'); |
|---|
| 59 | } catch (Exception $e) { |
|---|
| 60 | $core->error->add($e->getMessage()); |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | # Update order |
|---|
| 65 | if (!empty($_POST['save_order']) && !empty($_POST['categories_order'])) { |
|---|
| 66 | $categories = json_decode($_POST['categories_order']); |
|---|
| 67 | |
|---|
| 68 | foreach ($categories as $category) { |
|---|
| 69 | if (!empty($category->item_id)) { |
|---|
| 70 | $core->blog->updCategoryPosition($category->item_id, $category->left, $category->right); |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | http::redirect('categories.php?reord=1'); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 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 | |
|---|
| 91 | |
|---|
| 92 | /* Display |
|---|
| 93 | -------------------------------------------------------- */ |
|---|
| 94 | $rs = $core->blog->getCategories(array('post_type'=>'post')); |
|---|
| 95 | |
|---|
| 96 | $starting_script = ""; |
|---|
| 97 | if (!$core->auth->user_prefs->accessibility->nodragdrop |
|---|
| 98 | && $core->auth->check('categories',$core->blog->id) |
|---|
| 99 | && $rs->count()>1) { |
|---|
| 100 | $starting_script .= dcPage::jsLoad('js/jquery/jquery-ui.custom.js'); |
|---|
| 101 | $starting_script .= dcPage::jsLoad('js/jquery/jquery.mjs.nestedSortable.js'); |
|---|
| 102 | } |
|---|
| 103 | $starting_script .= dcPage::jsLoad('js/_categories.js'); |
|---|
| 104 | |
|---|
| 105 | dcPage::open(__('Categories'),$starting_script, |
|---|
| 106 | dcPage::breadcrumb( |
|---|
| 107 | array( |
|---|
| 108 | html::escapeHTML($core->blog->name) => '', |
|---|
| 109 | '<span class="page-title">'.__('Categories').'</span>' => '' |
|---|
| 110 | )) |
|---|
| 111 | ); |
|---|
| 112 | |
|---|
| 113 | if (!empty($_GET['del'])) { |
|---|
| 114 | dcPage::success(__('The category has been successfully removed.')); |
|---|
| 115 | } |
|---|
| 116 | if (!empty($_GET['reord'])) { |
|---|
| 117 | dcPage::success(__('Categories have been successfully reordered.')); |
|---|
| 118 | } |
|---|
| 119 | if (!empty($_GET['unknown'])) { |
|---|
| 120 | dcPage::error(__('This category does not exist.')); |
|---|
| 121 | } |
|---|
| 122 | if (!empty($_GET['move'])) { |
|---|
| 123 | dcPage::success(__('Entries have been successfully moved to the category you choose.')); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | $categories_combo = dcAdminCombos::getCategoriesCombo($rs); |
|---|
| 127 | |
|---|
| 128 | echo |
|---|
| 129 | '<p class="top-add"><a class="button add" href="category.php">'.__('New category').'</a></p>'; |
|---|
| 130 | |
|---|
| 131 | echo |
|---|
| 132 | '<div class="col">'; |
|---|
| 133 | if ($rs->isEmpty()) |
|---|
| 134 | { |
|---|
| 135 | echo '<p>'.__('No category so far.').'</p>'; |
|---|
| 136 | } |
|---|
| 137 | else |
|---|
| 138 | { |
|---|
| 139 | echo |
|---|
| 140 | '<form action="categories.php" method="post" id="form-categories">'. |
|---|
| 141 | '<div id="categories">'; |
|---|
| 142 | |
|---|
| 143 | $ref_level = $level = $rs->level-1; |
|---|
| 144 | while ($rs->fetch()) |
|---|
| 145 | { |
|---|
| 146 | $attr = 'id="cat_'.$rs->cat_id.'" class="cat-line clearfix"'; |
|---|
| 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 | |
|---|
| 158 | echo |
|---|
| 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>'. |
|---|
| 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 | |
|---|
| 165 | echo |
|---|
| 166 | '<p class="cat-buttons">'; |
|---|
| 167 | if ($rs->nb_total>0) { |
|---|
| 168 | // remove current category |
|---|
| 169 | echo |
|---|
| 170 | '<label>'.__('Move entries to').'</label> '. |
|---|
| 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;')),'',''). |
|---|
| 172 | ' <input type="submit" class="reset" name="mov['.$rs->cat_id.']" value="'.__('OK').'"/>'; |
|---|
| 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>'; |
|---|
| 183 | |
|---|
| 184 | $level = $rs->level; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | if ($ref_level - $level < 0) { |
|---|
| 188 | echo str_repeat('</li></ul>',-($ref_level - $level)); |
|---|
| 189 | } |
|---|
| 190 | echo |
|---|
| 191 | '</div>'; |
|---|
| 192 | |
|---|
| 193 | echo '<div class="clear">'; |
|---|
| 194 | |
|---|
| 195 | if ($core->auth->check('categories',$core->blog->id) && $rs->count()>1) { |
|---|
| 196 | if (!$core->auth->user_prefs->accessibility->nodragdrop) { |
|---|
| 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>'; |
|---|
| 198 | } |
|---|
| 199 | echo |
|---|
| 200 | '<p><span class="hidden-if-no-js">'. |
|---|
| 201 | '<input type="hidden" id="categories_order" name="categories_order" value=""/>'. |
|---|
| 202 | '<input type="submit" name="save_order" id="save-set-order" value="'.__('Save categories order').'" />'. |
|---|
| 203 | '</span> '; |
|---|
| 204 | } else { |
|---|
| 205 | echo '<p>'; |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | echo |
|---|
| 209 | '<input type="submit" class="reset" name="reset" value="'.__('Reorder all categories on the top level').'" />'. |
|---|
| 210 | $core->formNonce().'</p>'. |
|---|
| 211 | '</div></form>'; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | echo '</div>'; |
|---|
| 215 | |
|---|
| 216 | dcPage::helpBlock('core_categories'); |
|---|
| 217 | dcPage::close(); |
|---|
| 218 | ?> |
|---|