Dotclear


Ignore:
Timestamp:
07/09/11 09:41:16 (14 years ago)
Author:
Franck <carnet.franck.paul@…>
Branch:
themes
Children:
535:66f118a563a5, 538:aedf484a0a44
Message:

Mise en place du menu par défaut (Accueil et Archives), ajout d'item, affichage de la balise

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/simpleMenu/index.php

    r533 r534  
    1919$p_url = 'plugin.php?p=simpleMenu'; 
    2020 
    21 # Récupération paramètres postés 
    22 $item_type = isset($_POST['item_type']) ? $_POST['item_type'] : ''; 
    23 $item_select = isset($_POST['item_select']) ? $_POST['item_select'] : ''; 
    24  
    2521# Liste des catégories 
    2622$categories_combo = array(); 
     
    115111} 
    116112 
     113# Menu par défaut 
     114$blog_url = html::stripHostURL($core->blog->url); 
     115$menu_default = array( 
     116     array('label' => __('Home'), 'descr' => __('Recent posts'), 'url' => $blog_url), 
     117     array('label' => __('Archives'), 'descr' => __('Old posts'), 'url' => $blog_url.$core->url->getBase('archive')) 
     118); 
     119 
     120# Lecture menu existant 
     121$menu = $core->blog->settings->system->get('simpleMenu'); 
     122$menu = @unserialize($menu); 
     123if (!is_array($menu)) { 
     124     $menu = $menu_default; 
     125     $core->blog->settings->system->put('simpleMenu',serialize($menu)); 
     126} 
     127 
     128# Récupération paramètres postés 
     129$item_type = isset($_POST['item_type']) ? $_POST['item_type'] : ''; 
     130$item_select = isset($_POST['item_select']) ? $_POST['item_select'] : ''; 
     131 
    117132# Traitement 
    118133$step = (!empty($_GET['add']) ? (integer) $_GET['add'] : 0); 
     
    125140     switch ($step) { 
    126141          case 1: 
     142               // First step, menu item type to be selected 
    127143               $item_type = $item_select = ''; 
    128144               break; 
    129145          case 2: 
    130146               if ($items[$item_type][1] > 0) { 
     147                    // Second step (optional), menu item sub-type to be selected 
    131148                    $item_select = ''; 
    132149                    break; 
    133150               } 
    134151          case 3: 
     152               // Third step, menu item attributes to be changed or completed if necessary 
    135153               $item_select_label = ''; 
    136154               $item_label = __('Title'); 
    137155               $item_descr = __('Description'); 
    138                $item_url = html::stripHostURL($core->blog->url); 
     156               $item_url = $blog_url; 
    139157               switch ($item_type) { 
    140158                    case 'home': 
     
    188206               } 
    189207               break; 
     208          case 4: 
     209               // Fourth step, menu item to be added 
     210               try { 
     211                    if ($item_label && $item_url)  
     212                    { 
     213                         // Add new item menu in menu array 
     214                         $menu[] = array( 
     215                              'label' => $item_label, 
     216                              'descr' => $item_descr, 
     217                              'url' => $item_url 
     218                         ); 
     219                         // Save menu in blog settings 
     220                         $core->blog->settings->system->put('simpleMenu',serialize($menu)); 
     221                     
     222                         // All done successfully, return to menu items list 
     223                         http::redirect($p_url.'&added=1'); 
     224                    } else { 
     225                         throw new Exception(__('Label and URL of menu item are mandatory.')); 
     226                    } 
     227               } 
     228               catch (Exception $e) { 
     229                    $core->error->add($e->getMessage()); 
     230               } 
     231               break; 
    190232     } 
    191233} 
     
    202244 
    203245<?php 
     246 
     247if (!empty($_GET['added'])) { 
     248     echo '<p class="message">'.__('Menu item has been successfully added.').'</p>'; 
     249} 
     250if (!empty($_GET['removed'])) { 
     251     echo '<p class="message">'.__('Menu items have been successfully removed.').'</p>'; 
     252} 
     253if (!empty($_GET['neworder'])) { 
     254     echo '<p class="message">'.__('Menu items have been successfully updated.').'</p>'; 
     255} 
    204256 
    205257if ($step)  
Note: See TracChangeset for help on using the changeset viewer.

Sites map