Dotclear

source: plugins/simpleMenu/_public.php @ 566:0a0f493ca970

Revision 566:0a0f493ca970, 2.5 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Rajout d'un attribut description (title ou span) dans la balise pour préciser la place de la description (title du <a> ou <span> après le libellé)

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14# Simple menu template functions
15$core->tpl->addValue('SimpleMenu',array('tplSimpleMenu','simpleMenu'));
16
17class tplSimpleMenu
18{
19     public static function simpleMenu($attr)
20     {
21          $class = isset($attr['class']) ? trim($attr['class']) : '';
22          $id = isset($attr['id']) ? trim($attr['id']) : '';
23          $description = isset($attr['description']) ? trim($attr['description']) : '';
24         
25          return '<?php echo tplSimpleMenu::displayMenu('.
26                    "'".addslashes($class)."',".
27                    "'".addslashes($id)."',".
28                    "'".addslashes($description)."'".
29               '); ?>';
30     }
31     
32     public static function displayMenu($class='',$id='',$description='')
33     {
34          $ret = '';
35
36          $menu = $GLOBALS['core']->blog->settings->system->get('simpleMenu');
37          $menu = @unserialize($menu);
38
39          if (is_array($menu)) 
40          {
41               // Current relative URL
42               $url = $_SERVER['REQUEST_URI'];
43               $abs_url = http::getHost().$url;
44         
45               // Home recognition var
46               $home_url = html::stripHostURL($GLOBALS['core']->blog->url);
47               $home_directory = dirname($home_url);
48               if ($home_directory != '/')
49                    $home_directory = $home_directory.'/';
50
51               // Menu items loop
52               foreach ($menu as $i => $m) {
53                    # $href = lien de l'item de menu
54                    $href = $m['url'];
55                    $href = html::escapeHTML($href);
56
57                    # Active item test
58                    $active = false;
59                    if (($url == $href) || 
60                         ($abs_url == $href) || 
61                         ($_SERVER['URL_REQUEST_PART'] == $href) || 
62                         (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) {
63                         $active = true;
64                    }
65                    $title = $span = '';
66                    if ($m['descr']) {
67                         if ($description == 'title') {
68                              $title = ' title="'.__($m['descr']).'"';
69                         } else {
70                              $span = ' <span>'.__($m['descr']).'</span>';
71                         }
72                    }
73                    $ret .= '<li class="li'.($i+1).
74                                   ($active ? ' active' : '').
75                                   ($i == 0 ? ' li-first' : '').
76                                   ($i == count($menu)-1 ? ' li-last' : '').
77                              '">'.
78                              '<a href="'.$href.'"'.$title.'>'.__($m['label']).$span.'</a>'.
79                              '</li>';
80               }
81               
82               // Final rendering
83               if ($ret) {
84                    $ret = '<ul '.($id ? 'id="'.$id.'"' : '').' class="simple-menu'.($class ? ' '.$class : '').'">'."\n".$ret."\n".'</ul>';
85               }
86          }
87
88          return $ret;
89     }
90}
91
92?>
Note: See TracBrowser for help on using the repository browser.

Sites map