[532] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @brief simpleMenu, a plugin for Dotclear 2 |
---|
| 4 | * |
---|
| 5 | * @package Dotclear |
---|
| 6 | * @subpackage Plugins |
---|
| 7 | * |
---|
| 8 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 9 | * @copyright GPL-2.0-only |
---|
| 10 | */ |
---|
| 11 | |
---|
[3703] | 12 | if (!defined('DC_CONTEXT_ADMIN')) {return;} |
---|
[532] | 13 | |
---|
| 14 | dcPage::check('admin'); |
---|
| 15 | |
---|
| 16 | $page_title = __('Simple menu'); |
---|
| 17 | |
---|
| 18 | # Url de base |
---|
[2820] | 19 | $p_url = $core->adminurl->get('admin.plugin.simpleMenu'); |
---|
[532] | 20 | |
---|
[538] | 21 | # Url du blog |
---|
| 22 | $blog_url = html::stripHostURL($core->blog->url); |
---|
| 23 | |
---|
[532] | 24 | # Liste des catégories |
---|
| 25 | $categories_label = array(); |
---|
[3703] | 26 | $rs = $core->blog->getCategories(array('post_type' => 'post')); |
---|
| 27 | $categories_combo = dcAdminCombos::getCategoriesCombo($rs, false, true); |
---|
[1722] | 28 | $rs->moveStart(); |
---|
| 29 | while ($rs->fetch()) { |
---|
[3703] | 30 | $categories_label[$rs->cat_url] = html::escapeHTML($rs->cat_title); |
---|
[1722] | 31 | } |
---|
[2154] | 32 | |
---|
[532] | 33 | # Liste des langues utilisées |
---|
[1722] | 34 | $langs_combo = dcAdminCombos::getLangscombo( |
---|
[3703] | 35 | $core->blog->getLangs(array('order' => 'asc')) |
---|
[1722] | 36 | ); |
---|
[532] | 37 | |
---|
| 38 | # Liste des mois d'archive |
---|
[3703] | 39 | $rs = $core->blog->getDates(array('type' => 'month')); |
---|
[1722] | 40 | $months_combo = array_merge( |
---|
[3703] | 41 | array(__('All months') => '-'), |
---|
| 42 | dcAdmincombos::getDatesCombo($rs) |
---|
[1722] | 43 | ); |
---|
| 44 | |
---|
| 45 | $first_year = $last_year = 0; |
---|
| 46 | while ($rs->fetch()) { |
---|
[3703] | 47 | if (($first_year == 0) || ($rs->year() < $first_year)) { |
---|
| 48 | $first_year = $rs->year(); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | if (($last_year == 0) || ($rs->year() > $last_year)) { |
---|
| 52 | $last_year = $rs->year(); |
---|
| 53 | } |
---|
| 54 | |
---|
[1722] | 55 | } |
---|
| 56 | unset($rs); |
---|
[532] | 57 | |
---|
| 58 | # Liste des pages -- Doit être pris en charge plus tard par le plugin ? |
---|
| 59 | $pages_combo = array(); |
---|
| 60 | try { |
---|
[3703] | 61 | $rs = $core->blog->getPosts(array('post_type' => 'page')); |
---|
| 62 | while ($rs->fetch()) { |
---|
| 63 | $pages_combo[$rs->post_title] = $rs->getURL(); |
---|
| 64 | } |
---|
| 65 | unset($rs); |
---|
| 66 | } catch (Exception $e) {} |
---|
[532] | 67 | |
---|
| 68 | # Liste des tags -- Doit être pris en charge plus tard par le plugin ? |
---|
| 69 | $tags_combo = array(); |
---|
| 70 | try { |
---|
[3703] | 71 | $rs = $core->meta->getMetadata(array('meta_type' => 'tag')); |
---|
| 72 | $tags_combo[__('All tags')] = '-'; |
---|
| 73 | while ($rs->fetch()) { |
---|
| 74 | $tags_combo[$rs->meta_id] = $rs->meta_id; |
---|
| 75 | } |
---|
| 76 | unset($rs); |
---|
| 77 | } catch (Exception $e) {} |
---|
[532] | 78 | |
---|
| 79 | # Liste des types d'item de menu |
---|
[3703] | 80 | $items = new ArrayObject(); |
---|
| 81 | $items['home'] = new ArrayObject(array(__('Home'), false)); |
---|
[532] | 82 | |
---|
| 83 | if (count($langs_combo) > 1) { |
---|
[3703] | 84 | $items['lang'] = new ArrayObject(array(__('Language'), true)); |
---|
[532] | 85 | } |
---|
| 86 | if (count($categories_combo)) { |
---|
[3703] | 87 | $items['category'] = new ArrayObject(array(__('Category'), true)); |
---|
[532] | 88 | } |
---|
| 89 | if (count($months_combo) > 1) { |
---|
[3703] | 90 | $items['archive'] = new ArrayObject(array(__('Archive'), true)); |
---|
[532] | 91 | } |
---|
| 92 | if ($core->plugins->moduleExists('pages')) { |
---|
[3703] | 93 | if (count($pages_combo)) { |
---|
| 94 | $items['pages'] = new ArrayObject(array(__('Page'), true)); |
---|
| 95 | } |
---|
| 96 | |
---|
[532] | 97 | } |
---|
| 98 | if ($core->plugins->moduleExists('tags')) { |
---|
[3703] | 99 | if (count($tags_combo) > 1) { |
---|
| 100 | $items['tags'] = new ArrayObject(array(__('Tags'), true)); |
---|
| 101 | } |
---|
| 102 | |
---|
[532] | 103 | } |
---|
[554] | 104 | |
---|
[555] | 105 | # --BEHAVIOR-- adminSimpleMenuAddType |
---|
[587] | 106 | # Should add an item to $items[<id>] as an array(<label>,<optional step (true or false)>) |
---|
[3703] | 107 | $core->callBehavior('adminSimpleMenuAddType', $items); |
---|
[555] | 108 | |
---|
[3703] | 109 | $items['special'] = new ArrayObject(array(__('User defined'), false)); |
---|
[532] | 110 | |
---|
| 111 | $items_combo = array(); |
---|
| 112 | foreach ($items as $k => $v) { |
---|
[3703] | 113 | $items_combo[$v[0]] = $k; |
---|
[532] | 114 | } |
---|
| 115 | |
---|
[534] | 116 | # Lecture menu existant |
---|
| 117 | $menu = $core->blog->settings->system->get('simpleMenu'); |
---|
| 118 | if (!is_array($menu)) { |
---|
[3703] | 119 | $menu = array(); |
---|
[534] | 120 | } |
---|
| 121 | |
---|
[2773] | 122 | # Récupération état d'activation du menu |
---|
| 123 | $menu_active = (boolean) $core->blog->settings->system->simpleMenu_active; |
---|
[534] | 124 | |
---|
[2773] | 125 | // Saving new configuration |
---|
| 126 | if (!empty($_POST['saveconfig'])) { |
---|
[3703] | 127 | try |
---|
| 128 | { |
---|
| 129 | $menu_active = (empty($_POST['active'])) ? false : true; |
---|
| 130 | $core->blog->settings->system->put('simpleMenu_active', $menu_active, 'boolean'); |
---|
| 131 | $core->blog->triggerBlog(); |
---|
[532] | 132 | |
---|
[3703] | 133 | // All done successfully, return to menu items list |
---|
| 134 | dcPage::addSuccessNotice(__('Configuration successfully updated.')); |
---|
| 135 | http::redirect($p_url); |
---|
| 136 | } catch (Exception $e) { |
---|
| 137 | $core->error->add($e->getMessage()); |
---|
| 138 | } |
---|
[2773] | 139 | } else { |
---|
[3703] | 140 | # Récupération paramètres postés |
---|
| 141 | $item_type = isset($_POST['item_type']) ? $_POST['item_type'] : ''; |
---|
| 142 | $item_select = isset($_POST['item_select']) ? $_POST['item_select'] : ''; |
---|
| 143 | $item_label = isset($_POST['item_label']) ? $_POST['item_label'] : ''; |
---|
| 144 | $item_descr = isset($_POST['item_descr']) ? $_POST['item_descr'] : ''; |
---|
| 145 | $item_url = isset($_POST['item_url']) ? $_POST['item_url'] : ''; |
---|
| 146 | $item_targetBlank = isset($_POST['item_targetBlank']) ? (empty($_POST['item_targetBlank'])) ? false : true : false; |
---|
| 147 | # Traitement |
---|
| 148 | $step = (!empty($_GET['add']) ? (integer) $_GET['add'] : 0); |
---|
| 149 | if (($step > 4) || ($step < 0)) { |
---|
| 150 | $step = 0; |
---|
| 151 | } |
---|
[2773] | 152 | |
---|
[3703] | 153 | if ($step) { |
---|
[2773] | 154 | |
---|
[3703] | 155 | # Récupération libellés des choix |
---|
| 156 | $item_type_label = isset($items[$item_type]) ? $items[$item_type][0] : ''; |
---|
[3639] | 157 | |
---|
[3703] | 158 | switch ($step) { |
---|
| 159 | case 1: |
---|
| 160 | // First step, menu item type to be selected |
---|
| 161 | $item_type = $item_select = ''; |
---|
| 162 | break; |
---|
| 163 | case 2: |
---|
| 164 | if ($items[$item_type][1]) { |
---|
| 165 | // Second step (optional), menu item sub-type to be selected |
---|
| 166 | $item_select = ''; |
---|
| 167 | break; |
---|
| 168 | } |
---|
| 169 | case 3: |
---|
| 170 | // Third step, menu item attributes to be changed or completed if necessary |
---|
| 171 | $item_select_label = ''; |
---|
| 172 | $item_label = __('Label'); |
---|
| 173 | $item_descr = __('Description'); |
---|
| 174 | $item_url = $blog_url; |
---|
| 175 | switch ($item_type) { |
---|
| 176 | case 'home': |
---|
| 177 | $item_label = __('Home'); |
---|
| 178 | $item_descr = __('Recent posts'); |
---|
| 179 | break; |
---|
| 180 | case 'lang': |
---|
| 181 | $item_select_label = array_search($item_select, $langs_combo); |
---|
| 182 | $item_label = $item_select_label; |
---|
| 183 | $item_descr = sprintf(__('Switch to %s language'), $item_select_label); |
---|
| 184 | $item_url .= $core->url->getURLFor('lang', $item_select); |
---|
| 185 | break; |
---|
| 186 | case 'category': |
---|
| 187 | $item_select_label = $categories_label[$item_select]; |
---|
| 188 | $item_label = $item_select_label; |
---|
| 189 | $item_descr = __('Recent Posts from this category'); |
---|
| 190 | $item_url .= $core->url->getURLFor('category', $item_select); |
---|
| 191 | break; |
---|
| 192 | case 'archive': |
---|
| 193 | $item_select_label = array_search($item_select, $months_combo); |
---|
| 194 | if ($item_select == '-') { |
---|
| 195 | $item_label = __('Archives'); |
---|
| 196 | $item_descr = $first_year . ($first_year != $last_year ? ' - ' . $last_year : ''); |
---|
| 197 | $item_url .= $core->url->getURLFor('archive'); |
---|
| 198 | } else { |
---|
| 199 | $item_label = $item_select_label; |
---|
| 200 | $item_descr = sprintf(__('Posts from %s'), $item_select_label); |
---|
| 201 | $item_url .= $core->url->getURLFor('archive', substr($item_select, 0, 4) . '/' . substr($item_select, -2)); |
---|
| 202 | } |
---|
| 203 | break; |
---|
| 204 | case 'pages': |
---|
| 205 | $item_select_label = array_search($item_select, $pages_combo); |
---|
| 206 | $item_label = $item_select_label; |
---|
| 207 | $item_descr = ''; |
---|
| 208 | $item_url = html::stripHostURL($item_select); |
---|
| 209 | break; |
---|
| 210 | case 'tags': |
---|
| 211 | $item_select_label = array_search($item_select, $tags_combo); |
---|
| 212 | if ($item_select == '-') { |
---|
| 213 | $item_label = __('All tags'); |
---|
| 214 | $item_descr = ''; |
---|
| 215 | $item_url .= $core->url->getURLFor('tags'); |
---|
| 216 | } else { |
---|
| 217 | $item_label = $item_select_label; |
---|
| 218 | $item_descr = sprintf(__('Recent posts for %s tag'), $item_select_label); |
---|
| 219 | $item_url .= $core->url->getURLFor('tag', $item_select); |
---|
| 220 | } |
---|
| 221 | break; |
---|
| 222 | case 'special': |
---|
| 223 | break; |
---|
| 224 | default: |
---|
| 225 | # --BEHAVIOR-- adminSimpleMenuBeforeEdit |
---|
| 226 | # Should modify if necessary $item_label, $item_descr and $item_url |
---|
| 227 | # Should set if necessary $item_select_label (displayed on further admin step only) |
---|
| 228 | $core->callBehavior('adminSimpleMenuBeforeEdit', $item_type, $item_select, |
---|
| 229 | array(&$item_label, &$item_descr, &$item_url, &$item_select_label)); |
---|
| 230 | break; |
---|
| 231 | } |
---|
| 232 | break; |
---|
| 233 | case 4: |
---|
| 234 | // Fourth step, menu item to be added |
---|
| 235 | try { |
---|
| 236 | if (($item_label != '') && ($item_url != '')) { |
---|
| 237 | // Add new item menu in menu array |
---|
| 238 | $menu[] = array( |
---|
| 239 | 'label' => $item_label, |
---|
| 240 | 'descr' => $item_descr, |
---|
| 241 | 'url' => $item_url, |
---|
| 242 | 'targetBlank' => $item_targetBlank |
---|
| 243 | ); |
---|
[2773] | 244 | |
---|
[3703] | 245 | // Save menu in blog settings |
---|
| 246 | $core->blog->settings->system->put('simpleMenu', $menu); |
---|
| 247 | $core->blog->triggerBlog(); |
---|
[2773] | 248 | |
---|
[3703] | 249 | // All done successfully, return to menu items list |
---|
| 250 | dcPage::addSuccessNotice(__('Menu item has been successfully added.')); |
---|
| 251 | http::redirect($p_url); |
---|
| 252 | } else { |
---|
| 253 | $step = 3; |
---|
| 254 | $item_select_label = $item_label; |
---|
| 255 | dcPage::addErrorNotice(__('Label and URL of menu item are mandatory.')); |
---|
| 256 | } |
---|
| 257 | } catch (Exception $e) { |
---|
| 258 | $core->error->add($e->getMessage()); |
---|
| 259 | } |
---|
| 260 | break; |
---|
| 261 | } |
---|
| 262 | } else { |
---|
[2455] | 263 | |
---|
[3703] | 264 | # Remove selected menu items |
---|
| 265 | if (!empty($_POST['removeaction'])) { |
---|
| 266 | try { |
---|
| 267 | if (!empty($_POST['items_selected'])) { |
---|
| 268 | foreach ($_POST['items_selected'] as $k => $v) { |
---|
| 269 | $menu[$v]['label'] = ''; |
---|
| 270 | } |
---|
| 271 | $newmenu = array(); |
---|
| 272 | foreach ($menu as $k => $v) { |
---|
| 273 | if ($v['label']) { |
---|
| 274 | $newmenu[] = array( |
---|
| 275 | 'label' => $v['label'], |
---|
| 276 | 'descr' => $v['descr'], |
---|
| 277 | 'url' => $v['url'], |
---|
| 278 | 'targetBlank' => $v['targetBlank'] |
---|
| 279 | ); |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | $menu = $newmenu; |
---|
| 283 | // Save menu in blog settings |
---|
| 284 | $core->blog->settings->system->put('simpleMenu', $menu); |
---|
| 285 | $core->blog->triggerBlog(); |
---|
[2455] | 286 | |
---|
[3703] | 287 | // All done successfully, return to menu items list |
---|
| 288 | dcPage::addSuccessNotice(__('Menu items have been successfully removed.')); |
---|
| 289 | http::redirect($p_url); |
---|
| 290 | } else { |
---|
| 291 | throw new Exception(__('No menu items selected.')); |
---|
| 292 | } |
---|
| 293 | } catch (Exception $e) { |
---|
| 294 | $core->error->add($e->getMessage()); |
---|
| 295 | } |
---|
| 296 | } |
---|
[2455] | 297 | |
---|
[3703] | 298 | # Update menu items |
---|
| 299 | if (!empty($_POST['updateaction'])) { |
---|
| 300 | try { |
---|
| 301 | foreach ($_POST['items_label'] as $k => $v) { |
---|
| 302 | if (!$v) { |
---|
| 303 | throw new Exception(__('Label is mandatory.')); |
---|
| 304 | } |
---|
[2773] | 305 | |
---|
[3703] | 306 | } |
---|
| 307 | foreach ($_POST['items_url'] as $k => $v) { |
---|
| 308 | if (!$v) { |
---|
| 309 | throw new Exception(__('URL is mandatory.')); |
---|
| 310 | } |
---|
[2773] | 311 | |
---|
[3703] | 312 | } |
---|
| 313 | $newmenu = array(); |
---|
| 314 | for ($i = 0; $i < count($_POST['items_label']); $i++) { |
---|
| 315 | $newmenu[] = array( |
---|
| 316 | 'label' => $_POST['items_label'][$i], |
---|
| 317 | 'descr' => $_POST['items_descr'][$i], |
---|
| 318 | 'url' => $_POST['items_url'][$i], |
---|
| 319 | 'targetBlank' => (empty($_POST['items_targetBlank' . $i])) ? false : true |
---|
| 320 | ); |
---|
| 321 | } |
---|
| 322 | $menu = $newmenu; |
---|
| 323 | // Save menu in blog settings |
---|
| 324 | $core->blog->settings->system->put('simpleMenu', $menu); |
---|
| 325 | $core->blog->triggerBlog(); |
---|
[2773] | 326 | |
---|
[3703] | 327 | // All done successfully, return to menu items list |
---|
| 328 | dcPage::addSuccessNotice(__('Menu items have been successfully updated.')); |
---|
| 329 | http::redirect($p_url); |
---|
| 330 | } catch (Exception $e) { |
---|
| 331 | $core->error->add($e->getMessage()); |
---|
| 332 | } |
---|
| 333 | } |
---|
[2773] | 334 | |
---|
[3703] | 335 | # Order menu items |
---|
| 336 | $order = array(); |
---|
| 337 | if (empty($_POST['im_order']) && !empty($_POST['order'])) { |
---|
| 338 | $order = $_POST['order']; |
---|
| 339 | asort($order); |
---|
| 340 | $order = array_keys($order); |
---|
| 341 | } elseif (!empty($_POST['im_order'])) { |
---|
| 342 | $order = $_POST['im_order']; |
---|
| 343 | if (substr($order, -1) == ',') { |
---|
| 344 | $order = substr($order, 0, strlen($order) - 1); |
---|
| 345 | } |
---|
| 346 | $order = explode(',', $order); |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | if (!empty($_POST['updateaction']) && !empty($order)) { |
---|
| 350 | try { |
---|
| 351 | $newmenu = array(); |
---|
| 352 | foreach ($order as $i => $k) { |
---|
| 353 | $newmenu[] = array( |
---|
| 354 | 'label' => $menu[$k]['label'], |
---|
| 355 | 'descr' => $menu[$k]['descr'], |
---|
| 356 | 'url' => $menu[$k]['url']); |
---|
| 357 | } |
---|
| 358 | $menu = $newmenu; |
---|
| 359 | // Save menu in blog settings |
---|
| 360 | $core->blog->settings->system->put('simpleMenu', $menu); |
---|
| 361 | $core->blog->triggerBlog(); |
---|
| 362 | |
---|
| 363 | // All done successfully, return to menu items list |
---|
| 364 | dcPage::addSuccessNotice(__('Menu items have been successfully updated.')); |
---|
| 365 | http::redirect($p_url); |
---|
| 366 | } catch (Exception $e) { |
---|
| 367 | $core->error->add($e->getMessage()); |
---|
| 368 | } |
---|
| 369 | } |
---|
| 370 | |
---|
| 371 | } |
---|
[532] | 372 | } |
---|
| 373 | |
---|
| 374 | # Display |
---|
| 375 | ?> |
---|
| 376 | |
---|
| 377 | <html> |
---|
| 378 | <head> |
---|
[3703] | 379 | <title><?php echo $page_title; ?></title> |
---|
| 380 | <?php |
---|
| 381 | $core->auth->user_prefs->addWorkspace('accessibility'); |
---|
| 382 | if (!$core->auth->user_prefs->accessibility->nodragdrop) { |
---|
| 383 | echo |
---|
| 384 | dcPage::jsLoad('js/jquery/jquery-ui.custom.js') . |
---|
| 385 | dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js') . |
---|
[3709] | 386 | dcPage::jsLoad(dcPage::getPF('simpleMenu/js/simplemenu.js')); |
---|
[3703] | 387 | } |
---|
| 388 | echo dcPage::jsConfirmClose('settings', 'menuitemsappend', 'additem', 'menuitems'); |
---|
| 389 | ?> |
---|
[532] | 390 | </head> |
---|
| 391 | |
---|
| 392 | <body> |
---|
| 393 | |
---|
| 394 | <?php |
---|
| 395 | |
---|
[1358] | 396 | if ($step) { |
---|
[3703] | 397 | switch ($step) { |
---|
| 398 | case 1: |
---|
| 399 | $step_label = __('Step #1'); |
---|
| 400 | break; |
---|
| 401 | case 2: |
---|
| 402 | if ($items[$item_type][1]) { |
---|
| 403 | $step_label = __('Step #2'); |
---|
| 404 | break; |
---|
| 405 | } |
---|
| 406 | case 3: |
---|
| 407 | if ($items[$item_type][1]) { |
---|
| 408 | $step_label = __('Step #3'); |
---|
| 409 | } else { |
---|
| 410 | $step_label = __('Step #2'); |
---|
| 411 | } |
---|
| 412 | break; |
---|
| 413 | } |
---|
| 414 | echo dcPage::breadcrumb( |
---|
| 415 | array( |
---|
| 416 | html::escapeHTML($core->blog->name) => '', |
---|
| 417 | $page_title => $p_url, |
---|
| 418 | __('Add item') => '', |
---|
| 419 | $step_label => '' |
---|
| 420 | ), |
---|
| 421 | array( |
---|
| 422 | 'hl_pos' => -2) |
---|
| 423 | ) . |
---|
| 424 | dcPage::notices(); |
---|
[1358] | 425 | } else { |
---|
[3703] | 426 | echo dcPage::breadcrumb( |
---|
| 427 | array( |
---|
| 428 | html::escapeHTML($core->blog->name) => '', |
---|
| 429 | $page_title => '' |
---|
| 430 | )) . |
---|
| 431 | dcPage::notices(); |
---|
[538] | 432 | } |
---|
[2773] | 433 | |
---|
[3703] | 434 | if ($step) { |
---|
| 435 | // Formulaire d'ajout d'un item |
---|
| 436 | switch ($step) { |
---|
| 437 | case 1: |
---|
| 438 | // Selection du type d'item |
---|
| 439 | echo '<form id="additem" action="' . $p_url . '&add=2" method="post">'; |
---|
| 440 | echo '<fieldset><legend>' . __('Select type') . '</legend>'; |
---|
| 441 | echo '<p class="field"><label for="item_type" class="classic">' . __('Type of item menu:') . '</label>' . form::combo('item_type', $items_combo) . '</p>'; |
---|
| 442 | echo '<p>' . $core->formNonce() . '<input type="submit" name="appendaction" value="' . __('Continue...') . '" />' . '</p>'; |
---|
| 443 | echo '</fieldset>'; |
---|
| 444 | echo '</form>'; |
---|
| 445 | break; |
---|
| 446 | case 2: |
---|
| 447 | if ($items[$item_type][1]) { |
---|
| 448 | // Choix à faire |
---|
| 449 | echo '<form id="additem" action="' . $p_url . '&add=3" method="post">'; |
---|
| 450 | echo '<fieldset><legend>' . $item_type_label . '</legend>'; |
---|
| 451 | switch ($item_type) { |
---|
| 452 | case 'lang': |
---|
| 453 | echo '<p class="field"><label for="item_select" class="classic">' . __('Select language:') . '</label>' . |
---|
| 454 | form::combo('item_select', $langs_combo); |
---|
| 455 | break; |
---|
| 456 | case 'category': |
---|
| 457 | echo '<p class="field"><label for="item_select" class="classic">' . __('Select category:') . '</label>' . |
---|
| 458 | form::combo('item_select', $categories_combo); |
---|
| 459 | break; |
---|
| 460 | case 'archive': |
---|
| 461 | echo '<p class="field"><label for="item_select" class="classic">' . __('Select month (if necessary):') . '</label>' . |
---|
| 462 | form::combo('item_select', $months_combo); |
---|
| 463 | break; |
---|
| 464 | case 'pages': |
---|
| 465 | echo '<p class="field"><label for="item_select" class="classic">' . __('Select page:') . '</label>' . |
---|
| 466 | form::combo('item_select', $pages_combo); |
---|
| 467 | break; |
---|
| 468 | case 'tags': |
---|
| 469 | echo '<p class="field"><label for="item_select" class="classic">' . __('Select tag (if necessary):') . '</label>' . |
---|
| 470 | form::combo('item_select', $tags_combo); |
---|
| 471 | break; |
---|
| 472 | default: |
---|
| 473 | echo |
---|
| 474 | # --BEHAVIOR-- adminSimpleMenuSelect |
---|
| 475 | # Optional step once $item_type known : should provide a field using 'item_select' as id |
---|
| 476 | $core->callBehavior('adminSimpleMenuSelect', $item_type, 'item_select'); |
---|
| 477 | } |
---|
| 478 | echo form::hidden('item_type', $item_type); |
---|
| 479 | echo '<p>' . $core->formNonce() . '<input type="submit" name="appendaction" value="' . __('Continue...') . '" /></p>'; |
---|
| 480 | echo '</fieldset>'; |
---|
| 481 | echo '</form>'; |
---|
| 482 | break; |
---|
| 483 | } |
---|
| 484 | case 3: |
---|
| 485 | // Libellé et description |
---|
| 486 | echo '<form id="additem" action="' . $p_url . '&add=4" method="post">'; |
---|
| 487 | echo '<fieldset><legend>' . $item_type_label . ($item_select_label != '' ? ' (' . $item_select_label . ')' : '') . '</legend>'; |
---|
| 488 | echo '<p class="field"><label for="item_label" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . |
---|
| 489 | __('Label of item menu:') . '</label>' . |
---|
[3725] | 490 | form::field('item_label', 20, 255, array( |
---|
| 491 | 'default' => $item_label, |
---|
| 492 | 'extra_html' => 'required placeholder="' . __('Label') . '"' |
---|
| 493 | )) . |
---|
[3703] | 494 | '</p>'; |
---|
| 495 | echo '<p class="field"><label for="item_descr" class="classic">' . |
---|
| 496 | __('Description of item menu:') . '</label>' . form::field('item_descr', 30, 255, $item_descr) . '</p>'; |
---|
| 497 | echo '<p class="field"><label for="item_url" class="classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . |
---|
| 498 | __('URL of item menu:') . '</label>' . |
---|
[3725] | 499 | form::field('item_url', 40, 255, array( |
---|
| 500 | 'default' => $item_url, |
---|
| 501 | 'extra_html' => 'required placeholder="' . __('URL') . '"' |
---|
| 502 | )) . |
---|
[3703] | 503 | '</p>'; |
---|
| 504 | echo form::hidden('item_type', $item_type) . form::hidden('item_select', $item_select); |
---|
| 505 | echo '<p class="field"><label for="item_descr" class="classic">' . |
---|
| 506 | __('Open URL on a new tab') . ':</label>' . form::checkbox('item_targetBlank', 'blank') . '</p>'; |
---|
| 507 | echo '<p>' . $core->formNonce() . '<input type="submit" name="appendaction" value="' . __('Add this item') . '" /></p>'; |
---|
| 508 | echo '</fieldset>'; |
---|
| 509 | echo '</form>'; |
---|
| 510 | break; |
---|
| 511 | } |
---|
[538] | 512 | } |
---|
| 513 | |
---|
[2773] | 514 | // Formulaire d'activation |
---|
| 515 | if (!$step) { |
---|
[3703] | 516 | echo '<form id="settings" action="' . $p_url . '" method="post">' . |
---|
| 517 | '<p>' . form::checkbox('active', 1, $menu_active) . |
---|
| 518 | '<label class="classic" for="active">' . __('Enable simple menu for this blog') . '</label>' . '</p>' . |
---|
| 519 | '<p>' . $core->formNonce() . '<input type="submit" name="saveconfig" value="' . __('Save configuration') . '" />' . '</p>' . |
---|
| 520 | '</form>'; |
---|
[2773] | 521 | } |
---|
| 522 | |
---|
[538] | 523 | // Liste des items |
---|
| 524 | if (!$step) { |
---|
[3703] | 525 | echo '<form id="menuitemsappend" action="' . $p_url . '&add=1" method="post">'; |
---|
| 526 | echo '<p class="top-add">' . $core->formNonce() . '<input class="button add" type="submit" name="appendaction" value="' . __('Add an item') . '" /></p>'; |
---|
| 527 | echo '</form>'; |
---|
[573] | 528 | } |
---|
| 529 | |
---|
[538] | 530 | if (count($menu)) { |
---|
[3703] | 531 | if (!$step) { |
---|
| 532 | echo '<form id="menuitems" action="' . $p_url . '" method="post">'; |
---|
| 533 | } |
---|
| 534 | // Entête table |
---|
| 535 | echo |
---|
| 536 | '<div class="table-outer">' . |
---|
| 537 | '<table class="dragable">' . |
---|
| 538 | '<caption>' . __('Menu items list') . '</caption>' . |
---|
| 539 | '<thead>' . |
---|
| 540 | '<tr>'; |
---|
| 541 | if (!$step) { |
---|
| 542 | echo '<th scope="col"></th>'; |
---|
| 543 | echo '<th scope="col"></th>'; |
---|
| 544 | } |
---|
| 545 | echo |
---|
| 546 | '<th scope="col">' . __('Label') . '</th>' . |
---|
| 547 | '<th scope="col">' . __('Description') . '</th>' . |
---|
| 548 | '<th scope="col">' . __('URL') . '</th>' . |
---|
| 549 | '<th scope="col">' . __('Open URL on a new tab') . '</th>' . |
---|
| 550 | '</tr>' . |
---|
| 551 | '</thead>' . |
---|
| 552 | '<tbody' . (!$step ? ' id="menuitemslist"' : '') . '>'; |
---|
| 553 | $count = 0; |
---|
| 554 | foreach ($menu as $i => $m) { |
---|
| 555 | echo '<tr class="line" id="l_' . $i . '">'; |
---|
[3639] | 556 | |
---|
[3703] | 557 | //because targetBlank can not exists. This value has been added after this plugin creation. |
---|
| 558 | if ((isset($m['targetBlank'])) && ($m['targetBlank'])) { |
---|
| 559 | $targetBlank = true; |
---|
| 560 | $targetBlankStr = 'X'; |
---|
| 561 | } else { |
---|
| 562 | $targetBlank = false; |
---|
| 563 | $targetBlankStr = ''; |
---|
| 564 | } |
---|
[3639] | 565 | |
---|
[3703] | 566 | if (!$step) { |
---|
| 567 | $count++; |
---|
| 568 | echo '<td class="handle minimal">' . |
---|
[3725] | 569 | form::number(array('order[' . $i . ']'), array( |
---|
| 570 | 'min' => 1, |
---|
| 571 | 'default' => $count, |
---|
| 572 | 'class' => 'position', |
---|
| 573 | 'extra_html' => 'title="' . sprintf(__('position of %s'), html::escapeHTML(__($m['label']))) . '"' |
---|
| 574 | )) . |
---|
[3703] | 575 | form::hidden(array('dynorder[]', 'dynorder-' . $i), $i) . '</td>'; |
---|
| 576 | echo '<td class="minimal">' . form::checkbox(array('items_selected[]', 'ims-' . $i), $i) . '</td>'; |
---|
| 577 | echo '<td class="nowrap" scope="row">' . form::field(array('items_label[]', 'iml-' . $i), '', 255, html::escapeHTML(__($m['label']))) . '</td>'; |
---|
| 578 | echo '<td class="nowrap">' . form::field(array('items_descr[]', 'imd-' . $i), '30', 255, html::escapeHTML(__($m['descr']))) . '</td>'; |
---|
| 579 | echo '<td class="nowrap">' . form::field(array('items_url[]', 'imu-' . $i), '30', 255, html::escapeHTML($m['url'])) . '</td>'; |
---|
| 580 | echo '<td class="nowrap">' . form::checkbox('items_targetBlank' . $i, 'blank', $targetBlank) . '</td>'; |
---|
| 581 | } else { |
---|
| 582 | echo '<td class="nowrap" scope="row">' . html::escapeHTML(__($m['label'])) . '</td>'; |
---|
| 583 | echo '<td class="nowrap">' . html::escapeHTML(__($m['descr'])) . '</td>'; |
---|
| 584 | echo '<td class="nowrap">' . html::escapeHTML($m['url']) . '</td>'; |
---|
| 585 | echo '<td class="nowrap">' . $targetBlankStr . '</td>'; |
---|
[3639] | 586 | |
---|
[3703] | 587 | } |
---|
| 588 | echo '</tr>'; |
---|
| 589 | } |
---|
| 590 | echo '</tbody>' . |
---|
| 591 | '</table></div>'; |
---|
| 592 | if (!$step) { |
---|
| 593 | echo '<div class="two-cols">'; |
---|
| 594 | echo '<p class="col">' . form::hidden('im_order', '') . $core->formNonce(); |
---|
| 595 | echo '<input type="submit" name="updateaction" value="' . __('Update menu') . '" />' . '</p>'; |
---|
| 596 | echo '<p class="col right">' . '<input id="remove-action" type="submit" class="delete" name="removeaction" ' . |
---|
| 597 | 'value="' . __('Delete selected menu items') . '" ' . |
---|
| 598 | 'onclick="return window.confirm(\'' . html::escapeJS(__('Are you sure you want to remove selected menu items?')) . '\');" />' . |
---|
| 599 | '</p>'; |
---|
| 600 | echo '</div>'; |
---|
| 601 | echo '</form>'; |
---|
| 602 | } |
---|
[532] | 603 | } else { |
---|
[3703] | 604 | echo |
---|
| 605 | '<p>' . __('No menu items so far.') . '</p>'; |
---|
[538] | 606 | } |
---|
[532] | 607 | |
---|
[553] | 608 | dcPage::helpBlock('simpleMenu'); |
---|
[532] | 609 | ?> |
---|
| 610 | |
---|
| 611 | </body> |
---|
[3582] | 612 | </html> |
---|