Dotclear

Changeset 2773:65aa733ce8a4


Ignore:
Timestamp:
11/10/14 14:14:12 (11 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Add activation setting for simple menu, fixes #1958

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • locales/fr/plugins.po

    r2663 r2773  
    112112msgstr "Liste de liens" 
    113113 
     114msgid "Enable simple menu for this blog" 
     115msgstr "Acttiver le menu simple pour ce blog" 
     116 
    114117msgid "List of simple menu items" 
    115118msgstr "Liste des éléments de menu simple" 
  • plugins/simpleMenu/_define.php

    r2662 r2773  
    1616     /* Description*/         "Simple menu for Dotclear", 
    1717     /* Author */             "Franck Paul", 
    18      /* Version */            '1.2', 
     18     /* Version */            '1.3', 
    1919     array( 
    2020          'permissions' =>    'admin', 
  • plugins/simpleMenu/_install.php

    r2566 r2773  
    2424); 
    2525$core->blog->settings->system->put('simpleMenu',serialize($menu_default),'string','simpleMenu default menu',false,true); 
     26$core->blog->settings->system->put('simpleMenu_active',true,'boolean','Active',false,true); 
    2627 
    2728$core->setVersion('simpleMenu',$version); 
  • plugins/simpleMenu/_public.php

    r2667 r2773  
    2222     public static function simpleMenu($attr) 
    2323     { 
     24          global $core; 
     25 
     26          if (!(boolean) $core->blog->settings->system->simpleMenu_active) 
     27               return ''; 
     28 
    2429          $class = isset($attr['class']) ? trim($attr['class']) : ''; 
    2530          $id = isset($attr['id']) ? trim($attr['id']) : ''; 
     
    4247          global $core, $_ctx; 
    4348 
     49          if (!(boolean) $core->blog->settings->system->simpleMenu_active) 
     50               return; 
     51 
    4452          if (($w->homeonly == 1 && $core->url->type != 'default') || 
    4553               ($w->homeonly == 2 && $core->url->type == 'default')) { 
     
    6169 
    6270          $ret = ''; 
     71 
     72          if (!(boolean) $core->blog->settings->system->simpleMenu_active) 
     73               return $ret; 
    6374 
    6475          $menu = $GLOBALS['core']->blog->settings->system->get('simpleMenu'); 
  • plugins/simpleMenu/index.php

    r2701 r2773  
    111111} 
    112112 
    113 # Récupération paramètres postés 
    114 $item_type = isset($_POST['item_type']) ? $_POST['item_type'] : ''; 
    115 $item_select = isset($_POST['item_select']) ? $_POST['item_select'] : ''; 
    116 $item_label = isset($_POST['item_label']) ? $_POST['item_label'] : ''; 
    117 $item_descr = isset($_POST['item_descr']) ? $_POST['item_descr'] : ''; 
    118 $item_url = isset($_POST['item_url']) ? $_POST['item_url'] : ''; 
    119  
    120 # Traitement 
    121 $step = (!empty($_GET['add']) ? (integer) $_GET['add'] : 0); 
    122 if (($step > 4) || ($step < 0)) $step = 0; 
    123 if ($step) { 
    124  
    125      # Récupération libellés des choix 
    126      $item_type_label = isset($items[$item_type]) ? $items[$item_type][0] : ''; 
    127  
    128      switch ($step) { 
    129           case 1: 
    130                // First step, menu item type to be selected 
    131                $item_type = $item_select = ''; 
    132                break; 
    133           case 2: 
    134                if ($items[$item_type][1]) { 
    135                     // Second step (optional), menu item sub-type to be selected 
    136                     $item_select = ''; 
     113# Récupération état d'activation du menu 
     114$menu_active = (boolean) $core->blog->settings->system->simpleMenu_active; 
     115 
     116// Saving new configuration 
     117if (!empty($_POST['saveconfig'])) { 
     118     try 
     119     { 
     120          $menu_active = (empty($_POST['active'])) ? false : true; 
     121          $core->blog->settings->system->put('simpleMenu_active',$menu_active,'boolean'); 
     122          $core->blog->triggerBlog(); 
     123 
     124          // All done successfully, return to menu items list 
     125          dcPage::addSuccessNotice(__('Configuration successfully updated.')); 
     126          http::redirect($p_url); 
     127     } 
     128     catch (Exception $e) 
     129     { 
     130          $core->error->add($e->getMessage()); 
     131     } 
     132} else { 
     133     # Récupération paramètres postés 
     134     $item_type = isset($_POST['item_type']) ? $_POST['item_type'] : ''; 
     135     $item_select = isset($_POST['item_select']) ? $_POST['item_select'] : ''; 
     136     $item_label = isset($_POST['item_label']) ? $_POST['item_label'] : ''; 
     137     $item_descr = isset($_POST['item_descr']) ? $_POST['item_descr'] : ''; 
     138     $item_url = isset($_POST['item_url']) ? $_POST['item_url'] : ''; 
     139 
     140     # Traitement 
     141     $step = (!empty($_GET['add']) ? (integer) $_GET['add'] : 0); 
     142     if (($step > 4) || ($step < 0)) $step = 0; 
     143     if ($step) { 
     144 
     145          # Récupération libellés des choix 
     146          $item_type_label = isset($items[$item_type]) ? $items[$item_type][0] : ''; 
     147 
     148          switch ($step) { 
     149               case 1: 
     150                    // First step, menu item type to be selected 
     151                    $item_type = $item_select = ''; 
    137152                    break; 
    138                } 
    139           case 3: 
    140                // Third step, menu item attributes to be changed or completed if necessary 
    141                $item_select_label = ''; 
    142                $item_label = __('Label'); 
    143                $item_descr = __('Description'); 
    144                $item_url = $blog_url; 
    145                switch ($item_type) { 
    146                     case 'home': 
    147                          $item_label = __('Home'); 
    148                          $item_descr = __('Recent posts'); 
     153               case 2: 
     154                    if ($items[$item_type][1]) { 
     155                         // Second step (optional), menu item sub-type to be selected 
     156                         $item_select = ''; 
    149157                         break; 
    150                     case 'lang': 
    151                          $item_select_label = array_search($item_select,$langs_combo); 
    152                          $item_label = $item_select_label; 
    153                          $item_descr = sprintf(__('Switch to %s language'),$item_select_label); 
    154                          $item_url .= $core->url->getURLFor('lang',$item_select); 
    155                          break; 
    156                     case 'category': 
    157                          $item_select_label = $categories_label[$item_select]; 
    158                          $item_label = $item_select_label; 
    159                          $item_descr = __('Recent Posts from this category'); 
    160                          $item_url .= $core->url->getURLFor('category',$item_select); 
    161                          break; 
    162                     case 'archive': 
    163                          $item_select_label = array_search($item_select,$months_combo); 
    164                          if ($item_select == '-') { 
    165                               $item_label = __('Archives'); 
    166                               $item_descr = $first_year.($first_year != $last_year ? ' - '.$last_year : ''); 
    167                               $item_url .= $core->url->getURLFor('archive'); 
     158                    } 
     159               case 3: 
     160                    // Third step, menu item attributes to be changed or completed if necessary 
     161                    $item_select_label = ''; 
     162                    $item_label = __('Label'); 
     163                    $item_descr = __('Description'); 
     164                    $item_url = $blog_url; 
     165                    switch ($item_type) { 
     166                         case 'home': 
     167                              $item_label = __('Home'); 
     168                              $item_descr = __('Recent posts'); 
     169                              break; 
     170                         case 'lang': 
     171                              $item_select_label = array_search($item_select,$langs_combo); 
     172                              $item_label = $item_select_label; 
     173                              $item_descr = sprintf(__('Switch to %s language'),$item_select_label); 
     174                              $item_url .= $core->url->getURLFor('lang',$item_select); 
     175                              break; 
     176                         case 'category': 
     177                              $item_select_label = $categories_label[$item_select]; 
     178                              $item_label = $item_select_label; 
     179                              $item_descr = __('Recent Posts from this category'); 
     180                              $item_url .= $core->url->getURLFor('category',$item_select); 
     181                              break; 
     182                         case 'archive': 
     183                              $item_select_label = array_search($item_select,$months_combo); 
     184                              if ($item_select == '-') { 
     185                                   $item_label = __('Archives'); 
     186                                   $item_descr = $first_year.($first_year != $last_year ? ' - '.$last_year : ''); 
     187                                   $item_url .= $core->url->getURLFor('archive'); 
     188                              } else { 
     189                                   $item_label = $item_select_label; 
     190                                   $item_descr = sprintf(__('Posts from %s'),$item_select_label); 
     191                                   $item_url .= $core->url->getURLFor('archive',substr($item_select,0,4).'/'.substr($item_select,-2)); 
     192                              } 
     193                              break; 
     194                         case 'pages': 
     195                              $item_select_label = array_search($item_select,$pages_combo); 
     196                              $item_label = $item_select_label; 
     197                              $item_descr = ''; 
     198                              $item_url = html::stripHostURL($item_select); 
     199                              break; 
     200                         case 'tags': 
     201                              $item_select_label = array_search($item_select,$tags_combo); 
     202                              if ($item_select == '-') { 
     203                                   $item_label = __('All tags'); 
     204                                   $item_descr = ''; 
     205                                   $item_url .= $core->url->getURLFor('tags'); 
     206                              } else { 
     207                                   $item_label = $item_select_label; 
     208                                   $item_descr = sprintf(__('Recent posts for %s tag'),$item_select_label); 
     209                                   $item_url .= $core->url->getURLFor('tag',$item_select); 
     210                              } 
     211                              break; 
     212                         case 'special': 
     213                              break; 
     214                         default: 
     215                              # --BEHAVIOR-- adminSimpleMenuBeforeEdit 
     216                              # Should modify if necessary $item_label, $item_descr and $item_url 
     217                              # Should set if necessary $item_select_label (displayed on further admin step only) 
     218                              $core->callBehavior('adminSimpleMenuBeforeEdit',$item_type,$item_select, 
     219                                   array(&$item_label,&$item_descr,&$item_url,&$item_select_label)); 
     220                              break; 
     221                    } 
     222                    break; 
     223               case 4: 
     224                    // Fourth step, menu item to be added 
     225                    try { 
     226                         if (($item_label != '') && ($item_url != '')) 
     227                         { 
     228                              // Add new item menu in menu array 
     229                              $menu[] = array( 
     230                                   'label' => $item_label, 
     231                                   'descr' => $item_descr, 
     232                                   'url' => $item_url 
     233                              ); 
     234                              // Save menu in blog settings 
     235                              $core->blog->settings->system->put('simpleMenu',serialize($menu)); 
     236                              $core->blog->triggerBlog(); 
     237 
     238                              // All done successfully, return to menu items list 
     239                              dcPage::addSuccessNotice(__('Menu item has been successfully added.')); 
     240                              http::redirect($p_url); 
    168241                         } else { 
    169                               $item_label = $item_select_label; 
    170                               $item_descr = sprintf(__('Posts from %s'),$item_select_label); 
    171                               $item_url .= $core->url->getURLFor('archive',substr($item_select,0,4).'/'.substr($item_select,-2)); 
     242                              $step = 3; 
     243                              $item_select_label = $item_label; 
     244                              dcPage::addErrorNotice(__('Label and URL of menu item are mandatory.')); 
    172245                         } 
    173                          break; 
    174                     case 'pages': 
    175                          $item_select_label = array_search($item_select,$pages_combo); 
    176                          $item_label = $item_select_label; 
    177                          $item_descr = ''; 
    178                          $item_url = html::stripHostURL($item_select); 
    179                          break; 
    180                     case 'tags': 
    181                          $item_select_label = array_search($item_select,$tags_combo); 
    182                          if ($item_select == '-') { 
    183                               $item_label = __('All tags'); 
    184                               $item_descr = ''; 
    185                               $item_url .= $core->url->getURLFor('tags'); 
    186                          } else { 
    187                               $item_label = $item_select_label; 
    188                               $item_descr = sprintf(__('Recent posts for %s tag'),$item_select_label); 
    189                               $item_url .= $core->url->getURLFor('tag',$item_select); 
     246                    } 
     247                    catch (Exception $e) { 
     248                         $core->error->add($e->getMessage()); 
     249                    } 
     250                    break; 
     251          } 
     252     } else { 
     253 
     254          # Remove selected menu items 
     255          if (!empty($_POST['removeaction'])) 
     256          { 
     257               try { 
     258                    if (!empty($_POST['items_selected'])) { 
     259                         foreach ($_POST['items_selected'] as $k => $v) { 
     260                              $menu[$v]['label'] = ''; 
    190261                         } 
    191                          break; 
    192                     case 'special': 
    193                          break; 
    194                     default: 
    195                          # --BEHAVIOR-- adminSimpleMenuBeforeEdit 
    196                          # Should modify if necessary $item_label, $item_descr and $item_url 
    197                          # Should set if necessary $item_select_label (displayed on further admin step only) 
    198                          $core->callBehavior('adminSimpleMenuBeforeEdit',$item_type,$item_select, 
    199                               array(&$item_label,&$item_descr,&$item_url,&$item_select_label)); 
    200                          break; 
    201                } 
    202                break; 
    203           case 4: 
    204                // Fourth step, menu item to be added 
    205                try { 
    206                     if (($item_label != '') && ($item_url != '')) 
    207                     { 
    208                          // Add new item menu in menu array 
    209                          $menu[] = array( 
    210                               'label' => $item_label, 
    211                               'descr' => $item_descr, 
    212                               'url' => $item_url 
    213                          ); 
     262                         $newmenu = array(); 
     263                         foreach ($menu as $k => $v) { 
     264                              if ($v['label']) { 
     265                                   $newmenu[] = array( 
     266                                        'label' => $v['label'], 
     267                                        'descr' => $v['descr'], 
     268                                        'url' => $v['url']); 
     269                              } 
     270                         } 
     271                         $menu = $newmenu; 
    214272                         // Save menu in blog settings 
    215273                         $core->blog->settings->system->put('simpleMenu',serialize($menu)); 
     
    217275 
    218276                         // All done successfully, return to menu items list 
    219                          dcPage::addSuccessNotice(__('Menu item has been successfully added.')); 
     277                         dcPage::addSuccessNotice(__('Menu items have been successfully removed.')); 
    220278                         http::redirect($p_url); 
    221279                    } else { 
    222                          $step = 3; 
    223                          $item_select_label = $item_label; 
    224                          dcPage::addErrorNotice(__('Label and URL of menu item are mandatory.')); 
     280                         throw new Exception(__('No menu items selected.')); 
    225281                    } 
    226282               } 
     
    228284                    $core->error->add($e->getMessage()); 
    229285               } 
    230                break; 
    231      } 
    232 } else { 
    233  
    234      # Remove selected menu items 
    235      if (!empty($_POST['removeaction'])) 
    236      { 
    237           try { 
    238                if (!empty($_POST['items_selected'])) { 
    239                     foreach ($_POST['items_selected'] as $k => $v) { 
    240                          $menu[$v]['label'] = ''; 
     286          } 
     287 
     288          # Update menu items 
     289          if (!empty($_POST['updateaction'])) 
     290          { 
     291               try { 
     292                    foreach ($_POST['items_label'] as $k => $v) { 
     293                         if (!$v) throw new Exception(__('Label is mandatory.')); 
     294                    } 
     295                    foreach ($_POST['items_url'] as $k => $v) { 
     296                         if (!$v) throw new Exception(__('URL is mandatory.')); 
    241297                    } 
    242298                    $newmenu = array(); 
    243                     foreach ($menu as $k => $v) { 
    244                          if ($v['label']) { 
    245                               $newmenu[] = array( 
    246                                    'label' => $v['label'], 
    247                                    'descr' => $v['descr'], 
    248                                    'url' => $v['url']); 
    249                          } 
     299                    for ($i = 0; $i < count($_POST['items_label']); $i++) 
     300                    { 
     301                         $newmenu[] = array( 
     302                              'label' => $_POST['items_label'][$i], 
     303                              'descr' => $_POST['items_descr'][$i], 
     304                              'url' => $_POST['items_url'][$i]); 
    250305                    } 
    251306                    $menu = $newmenu; 
     
    255310 
    256311                    // All done successfully, return to menu items list 
    257                     dcPage::addSuccessNotice(__('Menu items have been successfully removed.')); 
     312                    dcPage::addSuccessNotice(__('Menu items have been successfully updated.')); 
    258313                    http::redirect($p_url); 
    259                } else { 
    260                     throw new Exception(__('No menu items selected.')); 
    261                } 
    262           } 
    263           catch (Exception $e) { 
    264                $core->error->add($e->getMessage()); 
    265           } 
    266      } 
    267  
    268      # Update menu items 
    269      if (!empty($_POST['updateaction'])) 
    270      { 
    271           try { 
    272                foreach ($_POST['items_label'] as $k => $v) { 
    273                     if (!$v) throw new Exception(__('Label is mandatory.')); 
    274                } 
    275                foreach ($_POST['items_url'] as $k => $v) { 
    276                     if (!$v) throw new Exception(__('URL is mandatory.')); 
    277                } 
    278                $newmenu = array(); 
    279                for ($i = 0; $i < count($_POST['items_label']); $i++) 
    280                { 
    281                     $newmenu[] = array( 
    282                          'label' => $_POST['items_label'][$i], 
    283                          'descr' => $_POST['items_descr'][$i], 
    284                          'url' => $_POST['items_url'][$i]); 
    285                } 
    286                $menu = $newmenu; 
    287                // Save menu in blog settings 
    288                $core->blog->settings->system->put('simpleMenu',serialize($menu)); 
    289                $core->blog->triggerBlog(); 
    290  
    291                // All done successfully, return to menu items list 
    292                dcPage::addSuccessNotice(__('Menu items have been successfully updated.')); 
    293                http::redirect($p_url); 
    294           } 
    295           catch (Exception $e) { 
    296                $core->error->add($e->getMessage()); 
    297           } 
    298      } 
    299  
    300      # Order menu items 
    301      $order = array(); 
    302      if (empty($_POST['im_order']) && !empty($_POST['order'])) { 
    303           $order = $_POST['order']; 
    304           asort($order); 
    305           $order = array_keys($order); 
    306      } elseif (!empty($_POST['im_order'])) { 
    307           $order = $_POST['im_order']; 
    308           if (substr($order,-1) == ',') { 
    309                $order = substr($order,0,strlen($order)-1); 
    310           } 
    311           $order = explode(',',$order); 
    312      } 
    313  
    314      if (!empty($_POST['updateaction']) && !empty($order)) 
    315      { 
    316           try { 
    317                $newmenu = array(); 
    318                foreach ($order as $i => $k) { 
    319                     $newmenu[] = array( 
    320                          'label' => $menu[$k]['label'], 
    321                          'descr' => $menu[$k]['descr'], 
    322                          'url' => $menu[$k]['url']); 
    323                } 
    324                $menu = $newmenu; 
    325                // Save menu in blog settings 
    326                $core->blog->settings->system->put('simpleMenu',serialize($menu)); 
    327                $core->blog->triggerBlog(); 
    328  
    329                // All done successfully, return to menu items list 
    330                dcPage::addSuccessNotice(__('Menu items have been successfully updated.')); 
    331                http::redirect($p_url); 
    332           } 
    333           catch (Exception $e) { 
    334                $core->error->add($e->getMessage()); 
    335           } 
    336      } 
    337  
     314               } 
     315               catch (Exception $e) { 
     316                    $core->error->add($e->getMessage()); 
     317               } 
     318          } 
     319 
     320          # Order menu items 
     321          $order = array(); 
     322          if (empty($_POST['im_order']) && !empty($_POST['order'])) { 
     323               $order = $_POST['order']; 
     324               asort($order); 
     325               $order = array_keys($order); 
     326          } elseif (!empty($_POST['im_order'])) { 
     327               $order = $_POST['im_order']; 
     328               if (substr($order,-1) == ',') { 
     329                    $order = substr($order,0,strlen($order)-1); 
     330               } 
     331               $order = explode(',',$order); 
     332          } 
     333 
     334          if (!empty($_POST['updateaction']) && !empty($order)) 
     335          { 
     336               try { 
     337                    $newmenu = array(); 
     338                    foreach ($order as $i => $k) { 
     339                         $newmenu[] = array( 
     340                              'label' => $menu[$k]['label'], 
     341                              'descr' => $menu[$k]['descr'], 
     342                              'url' => $menu[$k]['url']); 
     343                    } 
     344                    $menu = $newmenu; 
     345                    // Save menu in blog settings 
     346                    $core->blog->settings->system->put('simpleMenu',serialize($menu)); 
     347                    $core->blog->triggerBlog(); 
     348 
     349                    // All done successfully, return to menu items list 
     350                    dcPage::addSuccessNotice(__('Menu items have been successfully updated.')); 
     351                    http::redirect($p_url); 
     352               } 
     353               catch (Exception $e) { 
     354                    $core->error->add($e->getMessage()); 
     355               } 
     356          } 
     357 
     358     } 
    338359} 
    339360 
     
    397418          dcPage::notices(); 
    398419} 
     420 
    399421if ($step) 
    400422{ 
     
    464486               break; 
    465487     } 
     488} 
     489 
     490// Formulaire d'activation 
     491if (!$step) { 
     492     echo '<form id="settings" action="'.$p_url.'" method="post">'. 
     493          '<p>'.form::checkbox('active',1,$menu_active). 
     494          '<label class="classic" for="active">'.__('Enable simple menu for this blog').'</label>'.'</p>'. 
     495          '<p>'.$core->formNonce().'<input type="submit" name="saveconfig" value="'.__('Save configuration').'" />'.'</p>'. 
     496          '</form>'; 
    466497} 
    467498 
Note: See TracChangeset for help on using the changeset viewer.

Sites map