Dotclear

source: plugins/simpleMenu/_public.php @ 1063:6636d160f15c

Revision 1063:6636d160f15c, 3.7 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Widget may now be displayed without inclusive div, fixes #1242

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

Sites map