| 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 | dcPage::addErrorNotice(__('This category does not exist.')); | 
|---|
| 26 | http::redirect($core->adminurl->get("admin.categories")); | 
|---|
| 27 | } | 
|---|
| 28 | $name = $c->cat_title; | 
|---|
| 29 | unset($c); | 
|---|
| 30 |  | 
|---|
| 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 | http::redirect($core->adminurl->get("admin.categories")); | 
|---|
| 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'])) { | 
|---|
| 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]; | 
|---|
| 48 |  | 
|---|
| 49 | $mov_cat = $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 posts 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 | http::redirect($core->adminurl->get("admin.categories")); | 
|---|
| 65 | } catch (Exception $e) { | 
|---|
| 66 | $core->error->add($e->getMessage()); | 
|---|
| 67 | } | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | # Update order | 
|---|
| 71 | if (!empty($_POST['save_order']) && !empty($_POST['categories_order'])) { | 
|---|
| 72 | $categories = json_decode($_POST['categories_order']); | 
|---|
| 73 |  | 
|---|
| 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 | } | 
|---|
| 79 |  | 
|---|
| 80 | dcPage::addSuccessNotice(__('Categories have been successfully reordered.')); | 
|---|
| 81 | http::redirect($core->adminurl->get("admin.categories")); | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 | # Reset order | 
|---|
| 85 | if (!empty($_POST['reset'])) | 
|---|
| 86 | { | 
|---|
| 87 | try | 
|---|
| 88 | { | 
|---|
| 89 | $core->blog->resetCategoriesOrder(); | 
|---|
| 90 | dcPage::addSuccessNotice(__('Categories order has been successfully reset.')); | 
|---|
| 91 | http::redirect($core->adminurl->get("admin.categories")); | 
|---|
| 92 | } | 
|---|
| 93 | catch (Exception $e) | 
|---|
| 94 | { | 
|---|
| 95 | $core->error->add($e->getMessage()); | 
|---|
| 96 | } | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 |  | 
|---|
| 100 | /* Display | 
|---|
| 101 | -------------------------------------------------------- */ | 
|---|
| 102 | $rs = $core->blog->getCategories(array('post_type'=>'post')); | 
|---|
| 103 |  | 
|---|
| 104 | $starting_script = ""; | 
|---|
| 105 |  | 
|---|
| 106 | $core->auth->user_prefs->addWorkspace('accessibility'); | 
|---|
| 107 | if (!$core->auth->user_prefs->accessibility->nodragdrop | 
|---|
| 108 | && $core->auth->check('categories',$core->blog->id) | 
|---|
| 109 | && $rs->count()>1) { | 
|---|
| 110 | $starting_script .= dcPage::jsLoad('js/jquery/jquery-ui.custom.js'); | 
|---|
| 111 | $starting_script .= dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js'); | 
|---|
| 112 | $starting_script .= dcPage::jsLoad('js/jquery/jquery.mjs.nestedSortable.js'); | 
|---|
| 113 | } | 
|---|
| 114 | $starting_script .= dcPage::jsConfirmClose('form-categories'); | 
|---|
| 115 | $starting_script .= dcPage::jsLoad('js/_categories.js'); | 
|---|
| 116 |  | 
|---|
| 117 | dcPage::open(__('Categories'),$starting_script, | 
|---|
| 118 | dcPage::breadcrumb( | 
|---|
| 119 | array( | 
|---|
| 120 | html::escapeHTML($core->blog->name) => '', | 
|---|
| 121 | __('Categories') => '' | 
|---|
| 122 | )) | 
|---|
| 123 | ); | 
|---|
| 124 |  | 
|---|
| 125 | if (!empty($_GET['del'])) { | 
|---|
| 126 | dcPage::success(__('The category has been successfully removed.')); | 
|---|
| 127 | } | 
|---|
| 128 | if (!empty($_GET['reord'])) { | 
|---|
| 129 | dcPage::success(__('Categories have been successfully reordered.')); | 
|---|
| 130 | } | 
|---|
| 131 | if (!empty($_GET['move'])) { | 
|---|
| 132 | dcPage::success(__('Entries have been successfully moved to the category you choose.')); | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 | $categories_combo = dcAdminCombos::getCategoriesCombo($rs); | 
|---|
| 136 |  | 
|---|
| 137 | echo | 
|---|
| 138 | '<p class="top-add"><a class="button add" href="'.$core->adminurl->get("admin.category").'">'.__('New category').'</a></p>'; | 
|---|
| 139 |  | 
|---|
| 140 | echo | 
|---|
| 141 | '<div class="col">'; | 
|---|
| 142 | if ($rs->isEmpty()) | 
|---|
| 143 | { | 
|---|
| 144 | echo '<p>'.__('No category so far.').'</p>'; | 
|---|
| 145 | } | 
|---|
| 146 | else | 
|---|
| 147 | { | 
|---|
| 148 | echo | 
|---|
| 149 | '<form action="'.$core->adminurl->get("admin.categories").'" method="post" id="form-categories">'. | 
|---|
| 150 | '<div id="categories">'; | 
|---|
| 151 |  | 
|---|
| 152 | $ref_level = $level = $rs->level-1; | 
|---|
| 153 | while ($rs->fetch()) | 
|---|
| 154 | { | 
|---|
| 155 | $attr = 'id="cat_'.$rs->cat_id.'" class="cat-line clearfix"'; | 
|---|
| 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 |  | 
|---|
| 167 | echo | 
|---|
| 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)).'">'. | 
|---|
| 172 | sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. | 
|---|
| 173 | ', '.__('total:').' '.$rs->nb_total.')</p>'. | 
|---|
| 174 | '<p class="cat-url">'.__('URL:').' <code>'.html::escapeHTML($rs->cat_url).'</code></p>'; | 
|---|
| 175 |  | 
|---|
| 176 | echo | 
|---|
| 177 | '<p class="cat-buttons">'; | 
|---|
| 178 | if ($rs->nb_total>0) { | 
|---|
| 179 | // remove current category | 
|---|
| 180 | echo | 
|---|
| 181 | '<label for="mov_cat_'.$rs->cat_id.'">'.__('Move entries to').'</label> '. | 
|---|
| 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;')),'',''). | 
|---|
| 183 | ' <input type="submit" class="reset" name="mov['.$rs->cat_id.']" value="'.__('OK').'"/>'; | 
|---|
| 184 |  | 
|---|
| 185 | $attr_disabled = ' disabled="disabled"'; | 
|---|
| 186 | $input_class = 'disabled '; | 
|---|
| 187 | } else { | 
|---|
| 188 | $attr_disabled = ''; | 
|---|
| 189 | $input_class = ''; | 
|---|
| 190 | } | 
|---|
| 191 | echo | 
|---|
| 192 | ' <input type="submit"'.$attr_disabled.' class="'.$input_class.'delete" name="delete['.$rs->cat_id.']" value="'.__('Delete category').'"/>'. | 
|---|
| 193 | '</p>'; | 
|---|
| 194 |  | 
|---|
| 195 | $level = $rs->level; | 
|---|
| 196 | } | 
|---|
| 197 |  | 
|---|
| 198 | if ($ref_level - $level < 0) { | 
|---|
| 199 | echo str_repeat('</li></ul>',-($ref_level - $level)); | 
|---|
| 200 | } | 
|---|
| 201 | echo | 
|---|
| 202 | '</div>'; | 
|---|
| 203 |  | 
|---|
| 204 | echo '<div class="clear">'; | 
|---|
| 205 |  | 
|---|
| 206 | if ($core->auth->check('categories',$core->blog->id) && $rs->count()>1) { | 
|---|
| 207 | if (!$core->auth->user_prefs->accessibility->nodragdrop) { | 
|---|
| 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>'; | 
|---|
| 209 | } | 
|---|
| 210 | echo | 
|---|
| 211 | '<p><span class="hidden-if-no-js">'. | 
|---|
| 212 | '<input type="hidden" id="categories_order" name="categories_order" value=""/>'. | 
|---|
| 213 | '<input type="submit" name="save_order" id="save-set-order" value="'.__('Save categories order').'" />'. | 
|---|
| 214 | '</span> '; | 
|---|
| 215 | } else { | 
|---|
| 216 | echo '<p>'; | 
|---|
| 217 | } | 
|---|
| 218 |  | 
|---|
| 219 | echo | 
|---|
| 220 | '<input type="submit" class="reset" name="reset" value="'.__('Reorder all categories on the top level').'" />'. | 
|---|
| 221 | $core->formNonce().'</p>'. | 
|---|
| 222 | '</div></form>'; | 
|---|
| 223 | } | 
|---|
| 224 |  | 
|---|
| 225 | echo '</div>'; | 
|---|
| 226 |  | 
|---|
| 227 | dcPage::helpBlock('core_categories'); | 
|---|
| 228 | dcPage::close(); | 
|---|