Dotclear

source: plugins/simpleMenu/_public.php @ 567:8105b86c00fe

Revision 567:8105b86c00fe, 2.6 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Contrôle de l'attribut description (span ou title)

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          if (!preg_match('#^(title|span)$#',$description)) {
26               $description = '';
27          }
28         
29          return '<?php echo tplSimpleMenu::displayMenu('.
30                    "'".addslashes($class)."',".
31                    "'".addslashes($id)."',".
32                    "'".addslashes($description)."'".
33               '); ?>';
34     }
35     
36     public static function displayMenu($class='',$id='',$description='')
37     {
38          $ret = '';
39
40          $menu = $GLOBALS['core']->blog->settings->system->get('simpleMenu');
41          $menu = @unserialize($menu);
42
43          if (is_array($menu)) 
44          {
45               // Current relative URL
46               $url = $_SERVER['REQUEST_URI'];
47               $abs_url = http::getHost().$url;
48         
49               // Home recognition var
50               $home_url = html::stripHostURL($GLOBALS['core']->blog->url);
51               $home_directory = dirname($home_url);
52               if ($home_directory != '/')
53                    $home_directory = $home_directory.'/';
54
55               // Menu items loop
56               foreach ($menu as $i => $m) {
57                    # $href = lien de l'item de menu
58                    $href = $m['url'];
59                    $href = html::escapeHTML($href);
60
61                    # Active item test
62                    $active = false;
63                    if (($url == $href) || 
64                         ($abs_url == $href) || 
65                         ($_SERVER['URL_REQUEST_PART'] == $href) || 
66                         (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) {
67                         $active = true;
68                    }
69                    $title = $span = '';
70                    if ($m['descr']) {
71                         if ($description == 'title') {
72                              $title = ' title="'.__($m['descr']).'"';
73                         } else {
74                              $span = ' <span>'.__($m['descr']).'</span>';
75                         }
76                    }
77                    $ret .= '<li class="li'.($i+1).
78                                   ($active ? ' active' : '').
79                                   ($i == 0 ? ' li-first' : '').
80                                   ($i == count($menu)-1 ? ' li-last' : '').
81                              '">'.
82                              '<a href="'.$href.'"'.$title.'>'.__($m['label']).$span.'</a>'.
83                              '</li>';
84               }
85               
86               // Final rendering
87               if ($ret) {
88                    $ret = '<ul '.($id ? 'id="'.$id.'"' : '').' class="simple-menu'.($class ? ' '.$class : '').'">'."\n".$ret."\n".'</ul>';
89               }
90          }
91
92          return $ret;
93     }
94}
95
96?>
Note: See TracBrowser for help on using the repository browser.

Sites map