Dotclear

source: plugins/simpleMenu/_public.php @ 945:a373e04f8ac3

Revision 945:a373e04f8ac3, 3.1 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Add/complement display modes (all pages, home page only, except on home page) for all widgets, fixes #1345

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 == 1 && $core->url->type != 'default') ||
45               ($w->homeonly == 2 && $core->url->type == 'default')) {
46               return;
47          }
48
49          $menu = tplSimpleMenu::displayMenu('','','title');
50          if ($menu == '') {
51               return;
52          }
53
54          return '<div class="simple-menu'.
55               ($w->class ? ' '.html::escapeHTML($w->class) : '').'">'.
56               ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').$menu.'</div>';
57     }
58     
59     public static function displayMenu($class='',$id='',$description='')
60     {
61          $ret = '';
62
63          $menu = $GLOBALS['core']->blog->settings->system->get('simpleMenu');
64          $menu = @unserialize($menu);
65
66          if (is_array($menu)) 
67          {
68               // Current relative URL
69               $url = $_SERVER['REQUEST_URI'];
70               $abs_url = http::getHost().$url;
71         
72               // Home recognition var
73               $home_url = html::stripHostURL($GLOBALS['core']->blog->url);
74               $home_directory = dirname($home_url);
75               if ($home_directory != '/')
76                    $home_directory = $home_directory.'/';
77
78               // Menu items loop
79               foreach ($menu as $i => $m) {
80                    # $href = lien de l'item de menu
81                    $href = $m['url'];
82                    $href = html::escapeHTML($href);
83
84                    # Active item test
85                    $active = false;
86                    if (($url == $href) || 
87                         ($abs_url == $href) || 
88                         ($_SERVER['URL_REQUEST_PART'] == $href) || 
89                         (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) {
90                         $active = true;
91                    }
92                    $title = $span = '';
93                    if ($m['descr']) {
94                         if ($description == 'title') {
95                              $title = ' title="'.__($m['descr']).'"';
96                         } else {
97                              $span = ' <span>'.__($m['descr']).'</span>';
98                         }
99                    }
100                    $ret .= '<li class="li'.($i+1).
101                                   ($active ? ' active' : '').
102                                   ($i == 0 ? ' li-first' : '').
103                                   ($i == count($menu)-1 ? ' li-last' : '').
104                              '">'.
105                              '<a href="'.$href.'"'.$title.'>'.__($m['label']).$span.'</a>'.
106                              '</li>';
107               }
108               
109               // Final rendering
110               if ($ret) {
111                    $ret = '<ul '.($id ? 'id="'.$id.'"' : '').' class="simple-menu'.($class ? ' '.$class : '').'">'."\n".$ret."\n".'</ul>';
112               }
113          }
114
115          return $ret;
116     }
117}
118
119?>
Note: See TracBrowser for help on using the repository browser.

Sites map