Dotclear

source: plugins/simpleMenu/_public.php @ 587:98698950a78c

Revision 587:98698950a78c, 3.0 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Le menu simple peut dorénavant être placé en widget

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
14require dirname(__FILE__).'/_widgets.php';
15
16# Simple menu template functions
17$core->tpl->addValue('SimpleMenu',array('tplSimpleMenu','simpleMenu'));
18
19class tplSimpleMenu
20{
21     # Template function
22     public static function simpleMenu($attr)
23     {
24          $class = isset($attr['class']) ? trim($attr['class']) : '';
25          $id = isset($attr['id']) ? trim($attr['id']) : '';
26          $description = isset($attr['description']) ? trim($attr['description']) : '';
27         
28          if (!preg_match('#^(title|span)$#',$description)) {
29               $description = '';
30          }
31         
32          return '<?php echo tplSimpleMenu::displayMenu('.
33                    "'".addslashes($class)."',".
34                    "'".addslashes($id)."',".
35                    "'".addslashes($description)."'".
36               '); ?>';
37     }
38     
39     # Widget function
40     public static function simpleMenuWidget($w)
41     {
42          global $core, $_ctx;
43         
44          if ($w->homeonly && $core->url->type != 'default') {
45               return;
46          }
47
48          $menu = tplSimpleMenu::displayMenu();
49          if ($menu == '') {
50               return;
51          }
52
53          return '<div class="simple-menu">'.($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').$menu.'</div>';
54     }
55     
56     public static function displayMenu($class='',$id='',$description='')
57     {
58          $ret = '';
59
60          $menu = $GLOBALS['core']->blog->settings->system->get('simpleMenu');
61          $menu = @unserialize($menu);
62
63          if (is_array($menu)) 
64          {
65               // Current relative URL
66               $url = $_SERVER['REQUEST_URI'];
67               $abs_url = http::getHost().$url;
68         
69               // Home recognition var
70               $home_url = html::stripHostURL($GLOBALS['core']->blog->url);
71               $home_directory = dirname($home_url);
72               if ($home_directory != '/')
73                    $home_directory = $home_directory.'/';
74
75               // Menu items loop
76               foreach ($menu as $i => $m) {
77                    # $href = lien de l'item de menu
78                    $href = $m['url'];
79                    $href = html::escapeHTML($href);
80
81                    # Active item test
82                    $active = false;
83                    if (($url == $href) || 
84                         ($abs_url == $href) || 
85                         ($_SERVER['URL_REQUEST_PART'] == $href) || 
86                         (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) {
87                         $active = true;
88                    }
89                    $title = $span = '';
90                    if ($m['descr']) {
91                         if ($description == 'title') {
92                              $title = ' title="'.__($m['descr']).'"';
93                         } else {
94                              $span = ' <span>'.__($m['descr']).'</span>';
95                         }
96                    }
97                    $ret .= '<li class="li'.($i+1).
98                                   ($active ? ' active' : '').
99                                   ($i == 0 ? ' li-first' : '').
100                                   ($i == count($menu)-1 ? ' li-last' : '').
101                              '">'.
102                              '<a href="'.$href.'"'.$title.'>'.__($m['label']).$span.'</a>'.
103                              '</li>';
104               }
105               
106               // Final rendering
107               if ($ret) {
108                    $ret = '<ul '.($id ? 'id="'.$id.'"' : '').' class="simple-menu'.($class ? ' '.$class : '').'">'."\n".$ret."\n".'</ul>';
109               }
110          }
111
112          return $ret;
113     }
114}
115
116?>
Note: See TracBrowser for help on using the repository browser.

Sites map