Dotclear

Changeset 534:1f53e1c7b4c9 for plugins


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

Location:
plugins/simpleMenu
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • plugins/simpleMenu/_admin.php

    r532 r534  
    1616function simpleMenu_dashboard($core,$icons) 
    1717{ 
    18      $icons['simpleMenu'] = new ArrayObject(array(__('simpleMenu'),'plugin.php?p=simpleMenu','index.php?pf=simpleMenu/icon.png')); 
     18     $icons['simpleMenu'] = new ArrayObject(array(__('Simple menu'),'plugin.php?p=simpleMenu','index.php?pf=simpleMenu/icon.png')); 
    1919} 
    2020function simpleMenu_dashboard_favs($core,$favs) 
     
    2525} 
    2626 
    27 $_menu['Plugins']->addItem(__('simpleMenu'),'plugin.php?p=simpleMenu','index.php?pf=simpleMenu/icon-small.png', 
     27$_menu['Plugins']->addItem(__('Simple menu'),'plugin.php?p=simpleMenu','index.php?pf=simpleMenu/icon-small.png', 
    2828                preg_match('/plugin.php\?p=simpleMenu(&.*)?$/',$_SERVER['REQUEST_URI']), 
    2929                $core->auth->check('usage,contentadmin',$core->blog->id)); 
  • plugins/simpleMenu/_define.php

    r532 r534  
    1414$this->registerModule( 
    1515     /* Name */               "simpleMenu", 
    16      /* Description*/         "Simple menu bar for DC", 
     16     /* Description*/         "Simple menu for DC", 
    1717     /* Author */             "Franck Paul", 
    18      /* Version */            '0.1', 
     18     /* Version */            '0.2', 
    1919     array( 
    2020          'permissions' =>    'admin' 
  • plugins/simpleMenu/_public.php

    r532 r534  
    2929     { 
    3030          $ret = ''; 
     31 
     32          $menu = $GLOBALS['core']->blog->settings->system->get('simpleMenu'); 
     33          $menu = @unserialize($menu); 
     34 
     35          if (is_array($menu))  
     36          { 
     37               // Current relative URL 
     38               $url = $_SERVER['REQUEST_URI']; 
     39               $abs_url = http::getHost().$url; 
    3140           
    32           # Current relative URL 
    33           $url = $_SERVER['REQUEST_URI']; 
    34           $abs_url = http::getHost().$url; 
    35            
    36           # For detect if home 
    37           $home_url = html::stripHostURL($GLOBALS['core']->blog->url); 
    38           $home_directory = dirname($home_url); 
    39           if ($home_directory != '/') 
    40                $home_directory = $home_directory.'/'; 
    41            
    42           # $href = lien de l'item de menu 
    43           $href = 'archive'; 
    44           $href = html::escapeHTML($href); 
     41               // Home recognition var 
     42               $home_url = html::stripHostURL($GLOBALS['core']->blog->url); 
     43               $home_directory = dirname($home_url); 
     44               if ($home_directory != '/') 
     45                    $home_directory = $home_directory.'/'; 
    4546 
    46           # Active item test 
    47           $active = false; 
    48           if (($url == $href) ||  
    49                ($abs_url == $href) ||  
    50                ($_SERVER['URL_REQUEST_PART'] == $href) ||  
    51                (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) { 
    52                $active = true; 
     47               // Menu items loop 
     48               foreach ($menu as $i => $m) { 
     49                    # $href = lien de l'item de menu 
     50                    $href = $m['url']; 
     51                    $href = html::escapeHTML($href); 
     52 
     53                    # Active item test 
     54                    $active = false; 
     55                    if (($url == $href) ||  
     56                         ($abs_url == $href) ||  
     57                         ($_SERVER['URL_REQUEST_PART'] == $href) ||  
     58                         (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) { 
     59                         $active = true; 
     60                    } 
     61                    $ret .= '<li class="li'.$i.($active ? ' active' : '').'">'. 
     62                              '<a href="'.$href.'">'.$m['label'].($m['descr'] ? '<span>'.$m['descr'].'</span>' : '').'</a>'. 
     63                              '</li>'; 
     64               } 
     65                
     66               // Final rendering 
     67               if ($ret) { 
     68                    $ret = '<ul class="simple-menu'.($class ? ' '.$class : '').'">'."\n".$ret."\n".'</ul>'; 
     69               } 
    5370          } 
    54            
    55           $ret = '<p>Archives ? '.($active ? 'Oui' : 'Non').'</p>'; 
    56           $ret .= '<p>$class ? '.($class ? $class : '').'</p>'; 
    57           /* 
    58           $ret .= '<p>'.'$_SERVER[\'REQUEST_URI\']'.' = '.$_SERVER['REQUEST_URI'].'</p>'; 
    59           $ret .= '<p>'.'$_SERVER[\'URL_REQUEST_PART\']'.' = '.$_SERVER['URL_REQUEST_PART'].'</p>'; 
    60           $ret .= '<p>'.'$url'.' = '.$url.'</p>'; 
    61           $ret .= '<p>'.'$abs_url'.' = '.$abs_url.'</p>'; 
    62           $ret .= '<p>'.'$home_url'.' = '.$home_url.'</p>'; 
    63           $ret .= '<p>'.'$home_directory'.' = '.$home_directory.'</p>'; 
    64           $ret .= '<p>'.'$href'.' = '.$href.'</p>'; 
    65           */ 
     71 
    6672          return $ret; 
    6773     } 
  • 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