[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 | |
---|
[3703] | 10 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; |
---|
[0] | 11 | |
---|
| 12 | dcPage::check('categories'); |
---|
| 13 | |
---|
[3703] | 14 | $cat_id = ''; |
---|
| 15 | $cat_title = ''; |
---|
| 16 | $cat_url = ''; |
---|
| 17 | $cat_desc = ''; |
---|
[0] | 18 | $cat_position = ''; |
---|
| 19 | |
---|
[3898] | 20 | $blog_settings = new dcSettings($core, $core->blog->id); |
---|
| 21 | $blog_lang = $blog_settings->system->lang; |
---|
| 22 | |
---|
[0] | 23 | # Getting existing category |
---|
[3703] | 24 | if (!empty($_REQUEST['id'])) { |
---|
| 25 | try { |
---|
| 26 | $rs = $core->blog->getCategory($_REQUEST['id']); |
---|
| 27 | } catch (Exception $e) { |
---|
| 28 | $core->error->add($e->getMessage()); |
---|
| 29 | } |
---|
[2566] | 30 | |
---|
[3703] | 31 | if (!$core->error->flag() && !$rs->isEmpty()) { |
---|
| 32 | $cat_id = (integer) $rs->cat_id; |
---|
| 33 | $cat_title = $rs->cat_title; |
---|
| 34 | $cat_url = $rs->cat_url; |
---|
| 35 | $cat_desc = $rs->cat_desc; |
---|
| 36 | } |
---|
| 37 | unset($rs); |
---|
[2566] | 38 | |
---|
[3703] | 39 | # Getting hierarchy information |
---|
| 40 | $parents = $core->blog->getCategoryParents($cat_id); |
---|
| 41 | $rs = $core->blog->getCategoryParent($cat_id); |
---|
| 42 | $cat_parent = $rs->isEmpty() ? 0 : (integer) $rs->cat_id; |
---|
| 43 | unset($rs); |
---|
[2566] | 44 | |
---|
[3703] | 45 | # Allowed parents list |
---|
[3874] | 46 | $children = $core->blog->getCategories(['start' => $cat_id]); |
---|
| 47 | $allowed_parents = [__('Top level') => 0]; |
---|
[2566] | 48 | |
---|
[3874] | 49 | $p = []; |
---|
[3703] | 50 | while ($children->fetch()) { |
---|
| 51 | $p[$children->cat_id] = 1; |
---|
| 52 | } |
---|
[2566] | 53 | |
---|
[3703] | 54 | $rs = $core->blog->getCategories(); |
---|
| 55 | while ($rs->fetch()) { |
---|
| 56 | if (!isset($p[$rs->cat_id])) { |
---|
| 57 | $allowed_parents[] = new formSelectOption( |
---|
| 58 | str_repeat(' ', $rs->level - 1) . ($rs->level - 1 == 0 ? '' : '• ') . html::escapeHTML($rs->cat_title), |
---|
| 59 | $rs->cat_id |
---|
| 60 | ); |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | unset($rs); |
---|
[2566] | 64 | |
---|
[3703] | 65 | # Allowed siblings list |
---|
[3874] | 66 | $siblings = []; |
---|
[3703] | 67 | $rs = $core->blog->getCategoryFirstChildren($cat_parent); |
---|
| 68 | while ($rs->fetch()) { |
---|
| 69 | if ($rs->cat_id != $cat_id) { |
---|
| 70 | $siblings[html::escapeHTML($rs->cat_title)] = $rs->cat_id; |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | unset($rs); |
---|
[0] | 74 | } |
---|
| 75 | |
---|
| 76 | # Changing parent |
---|
[3703] | 77 | if ($cat_id && isset($_POST['cat_parent'])) { |
---|
| 78 | $new_parent = (integer) $_POST['cat_parent']; |
---|
| 79 | if ($cat_parent != $new_parent) { |
---|
| 80 | try { |
---|
| 81 | $core->blog->setCategoryParent($cat_id, $new_parent); |
---|
| 82 | dcPage::addSuccessNotice(__('The category has been successfully moved')); |
---|
| 83 | $core->adminurl->redirect("admin.categories"); |
---|
| 84 | } catch (Exception $e) { |
---|
| 85 | $core->error->add($e->getMessage()); |
---|
| 86 | } |
---|
| 87 | } |
---|
[0] | 88 | } |
---|
| 89 | |
---|
| 90 | # Changing sibling |
---|
[3703] | 91 | if ($cat_id && isset($_POST['cat_sibling'])) { |
---|
| 92 | try { |
---|
| 93 | $core->blog->setCategoryPosition($cat_id, (integer) $_POST['cat_sibling'], $_POST['cat_move']); |
---|
| 94 | dcPage::addSuccessNotice(__('The category has been successfully moved')); |
---|
| 95 | $core->adminurl->redirect("admin.categories"); |
---|
| 96 | } catch (Exception $e) { |
---|
| 97 | $core->error->add($e->getMessage()); |
---|
| 98 | } |
---|
[0] | 99 | } |
---|
| 100 | |
---|
| 101 | # Create or update a category |
---|
[3703] | 102 | if (isset($_POST['cat_title'])) { |
---|
| 103 | $cur = $core->con->openCursor($core->prefix . 'category'); |
---|
[2566] | 104 | |
---|
[3703] | 105 | $cur->cat_title = $cat_title = $_POST['cat_title']; |
---|
[2566] | 106 | |
---|
[3703] | 107 | if (isset($_POST['cat_desc'])) { |
---|
| 108 | $cur->cat_desc = $cat_desc = $_POST['cat_desc']; |
---|
| 109 | } |
---|
[2566] | 110 | |
---|
[3703] | 111 | if (isset($_POST['cat_url'])) { |
---|
| 112 | $cur->cat_url = $cat_url = $_POST['cat_url']; |
---|
| 113 | } else { |
---|
| 114 | $cur->cat_url = $cat_url; |
---|
| 115 | } |
---|
[2566] | 116 | |
---|
[3703] | 117 | try |
---|
| 118 | { |
---|
| 119 | # Update category |
---|
| 120 | if ($cat_id) { |
---|
| 121 | # --BEHAVIOR-- adminBeforeCategoryUpdate |
---|
| 122 | $core->callBehavior('adminBeforeCategoryUpdate', $cur, $cat_id); |
---|
[2566] | 123 | |
---|
[3703] | 124 | $core->blog->updCategory($_POST['id'], $cur); |
---|
[2566] | 125 | |
---|
[3703] | 126 | # --BEHAVIOR-- adminAfterCategoryUpdate |
---|
| 127 | $core->callBehavior('adminAfterCategoryUpdate', $cur, $cat_id); |
---|
[2566] | 128 | |
---|
[3703] | 129 | dcPage::addSuccessNotice(__('The category has been successfully updated.')); |
---|
[2189] | 130 | |
---|
[3874] | 131 | $core->adminurl->redirect("admin.category", ['id' => $_POST['id']]); |
---|
[3703] | 132 | } |
---|
| 133 | # Create category |
---|
| 134 | else { |
---|
| 135 | # --BEHAVIOR-- adminBeforeCategoryCreate |
---|
| 136 | $core->callBehavior('adminBeforeCategoryCreate', $cur); |
---|
[2566] | 137 | |
---|
[3703] | 138 | $id = $core->blog->addCategory($cur, (integer) $_POST['new_cat_parent']); |
---|
[2566] | 139 | |
---|
[3703] | 140 | # --BEHAVIOR-- adminAfterCategoryCreate |
---|
| 141 | $core->callBehavior('adminAfterCategoryCreate', $cur, $id); |
---|
[2566] | 142 | |
---|
[3703] | 143 | dcPage::addSuccessNotice(sprintf(__('The category "%s" has been successfully created.'), |
---|
| 144 | html::escapeHTML($cur->cat_title))); |
---|
| 145 | $core->adminurl->redirect("admin.categories"); |
---|
| 146 | } |
---|
| 147 | } catch (Exception $e) { |
---|
| 148 | $core->error->add($e->getMessage()); |
---|
| 149 | } |
---|
[0] | 150 | } |
---|
| 151 | |
---|
| 152 | $title = $cat_id ? html::escapeHTML($cat_title) : __('New category'); |
---|
| 153 | |
---|
[3874] | 154 | $elements = [ |
---|
[3703] | 155 | html::escapeHTML($core->blog->name) => '', |
---|
| 156 | __('Categories') => $core->adminurl->get("admin.categories") |
---|
[3874] | 157 | ]; |
---|
[1332] | 158 | if ($cat_id) { |
---|
[3703] | 159 | while ($parents->fetch()) { |
---|
[3874] | 160 | $elements[html::escapeHTML($parents->cat_title)] = $core->adminurl->get("admin.category", ['id' => $parents->cat_id]); |
---|
[3703] | 161 | } |
---|
[0] | 162 | } |
---|
[2166] | 163 | $elements[$title] = ''; |
---|
[1358] | 164 | |
---|
[2891] | 165 | $category_editor = $core->auth->getOption('editor'); |
---|
[3703] | 166 | $rte_flag = true; |
---|
| 167 | $rte_flags = @$core->auth->user_prefs->interface->rte_flags; |
---|
| 168 | if (is_array($rte_flags) && in_array('cat_descr', $rte_flags)) { |
---|
| 169 | $rte_flag = $rte_flags['cat_descr']; |
---|
[3330] | 170 | } |
---|
[2891] | 171 | |
---|
[1358] | 172 | dcPage::open($title, |
---|
[3703] | 173 | dcPage::jsConfirmClose('category-form') . |
---|
| 174 | dcPage::jsLoad('js/_category.js') . |
---|
[3874] | 175 | ($rte_flag ? $core->callBehavior('adminPostEditor', $category_editor['xhtml'], 'category', ['#cat_desc'], 'xhtml') : ''), |
---|
[3703] | 176 | dcPage::breadcrumb($elements) |
---|
[1358] | 177 | ); |
---|
| 178 | |
---|
| 179 | if (!empty($_GET['upd'])) { |
---|
[3703] | 180 | dcPage::success(__('Category has been successfully updated.')); |
---|
[1358] | 181 | } |
---|
[0] | 182 | |
---|
| 183 | echo |
---|
[3703] | 184 | '<form action="' . $core->adminurl->get("admin.category") . '" method="post" id="category-form">' . |
---|
| 185 | '<h3>' . __('Category information') . '</h3>' . |
---|
| 186 | '<p><label class="required" for="cat_title"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Name:') . '</label> ' . |
---|
[3874] | 187 | form::field('cat_title', 40, 255, [ |
---|
[3725] | 188 | 'default' => html::escapeHTML($cat_title), |
---|
[3898] | 189 | 'extra_html' => 'required placeholder="' . __('Name') . '" lang="' . $blog_lang . '" spellcheck="true"' |
---|
[3874] | 190 | ]) . |
---|
[3730] | 191 | '</p>'; |
---|
[3703] | 192 | if (!$cat_id) { |
---|
| 193 | $rs = $core->blog->getCategories(); |
---|
| 194 | echo |
---|
| 195 | '<p><label for="new_cat_parent">' . __('Parent:') . ' ' . |
---|
| 196 | '<select id="new_cat_parent" name="new_cat_parent" >' . |
---|
| 197 | '<option value="0">' . __('(none)') . '</option>'; |
---|
| 198 | while ($rs->fetch()) { |
---|
| 199 | echo '<option value="' . $rs->cat_id . '" ' . (!empty($_POST['new_cat_parent']) && $_POST['new_cat_parent'] == $rs->cat_id ? 'selected="selected"' : '') . '>' . |
---|
| 200 | str_repeat(' ', $rs->level - 1) . ($rs->level - 1 == 0 ? '' : '• ') . html::escapeHTML($rs->cat_title) . '</option>'; |
---|
| 201 | } |
---|
| 202 | echo |
---|
| 203 | '</select></label></p>'; |
---|
| 204 | unset($rs); |
---|
[0] | 205 | } |
---|
| 206 | echo |
---|
[3703] | 207 | '<div class="lockable">' . |
---|
| 208 | '<p><label for="cat_url">' . __('URL:') . '</label> ' |
---|
| 209 | . form::field('cat_url', 40, 255, html::escapeHTML($cat_url)) . |
---|
| 210 | '</p>' . |
---|
| 211 | '<p class="form-note warn" id="note-cat-url">' . |
---|
| 212 | __('Warning: If you set the URL manually, it may conflict with another category.') . '</p>' . |
---|
| 213 | '</div>' . |
---|
[0] | 214 | |
---|
[3703] | 215 | '<p class="area"><label for="cat_desc">' . __('Description:') . '</label> ' . |
---|
[3898] | 216 | form::textarea('cat_desc', 50, 8, |
---|
| 217 | [ |
---|
| 218 | 'default' => html::escapeHTML($cat_desc), |
---|
| 219 | 'extra_html' => 'lang="' . $blog_lang . '" spellcheck="true"' |
---|
| 220 | ]) . |
---|
[3703] | 221 | '</p>' . |
---|
[0] | 222 | |
---|
[3703] | 223 | '<p><input type="submit" accesskey="s" value="' . __('Save') . '" />' . |
---|
| 224 | ($cat_id ? form::hidden('id', $cat_id) : '') . |
---|
| 225 | $core->formNonce() . |
---|
| 226 | '</p>' . |
---|
| 227 | '</form>'; |
---|
[0] | 228 | |
---|
[3703] | 229 | if ($cat_id) { |
---|
| 230 | echo |
---|
| 231 | '<h3 class="border-top">' . __('Move this category') . '</h3>' . |
---|
| 232 | '<div class="two-cols">' . |
---|
| 233 | '<div class="col">' . |
---|
[2566] | 234 | |
---|
[3703] | 235 | '<form action="' . $core->adminurl->get("admin.category") . '" method="post" class="fieldset">' . |
---|
| 236 | '<h4>' . __('Category parent') . '</h4>' . |
---|
| 237 | '<p><label for="cat_parent" class="classic">' . __('Parent:') . '</label> ' . |
---|
| 238 | form::combo('cat_parent', $allowed_parents, $cat_parent) . '</p>' . |
---|
| 239 | '<p><input type="submit" accesskey="s" value="' . __('Save') . '" />' . |
---|
[3874] | 240 | form::hidden(['id'], $cat_id) . $core->formNonce() . '</p>' . |
---|
[3703] | 241 | '</form>' . |
---|
| 242 | '</div>'; |
---|
[2566] | 243 | |
---|
[3703] | 244 | if (count($siblings) > 0) { |
---|
| 245 | echo |
---|
| 246 | '<div class="col">' . |
---|
| 247 | '<form action="' . $core->adminurl->get("admin.category") . '" method="post" class="fieldset">' . |
---|
| 248 | '<h4>' . __('Category sibling') . '</h4>' . |
---|
| 249 | '<p><label class="classic" for="cat_sibling">' . __('Move current category') . '</label> ' . |
---|
[3874] | 250 | form::combo('cat_move', [__('before') => 'before', __('after') => 'after'], |
---|
| 251 | ['extra_html' => 'title="' . __('position: ') . '"']) . ' ' . |
---|
[3703] | 252 | form::combo('cat_sibling', $siblings) . '</p>' . |
---|
| 253 | '<p><input type="submit" accesskey="s" value="' . __('Save') . '" />' . |
---|
[3874] | 254 | form::hidden(['id'], $cat_id) . $core->formNonce() . '</p>' . |
---|
[3703] | 255 | '</form>' . |
---|
| 256 | '</div>'; |
---|
| 257 | } |
---|
[2566] | 258 | |
---|
[3703] | 259 | echo '</div>'; |
---|
[0] | 260 | } |
---|
| 261 | |
---|
[2314] | 262 | dcPage::helpBlock('core_category'); |
---|
[0] | 263 | dcPage::close(); |
---|