Dotclear


Ignore:
Timestamp:
02/15/18 16:39:52 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Use array form of optionnal parameters for form::combo(), code formatting (PSR-2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/simpleMenu/index.php

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

Sites map