Dotclear

source: plugins/simpleMenu/_public.php @ 2870:89c05423e739

Revision 2870:89c05423e739, 4.0 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Revert part of rev 2866 as these modifications will implied CSS review (lot of) for Berlin theme, programmed for the next 2.8 release

RevLine 
[532]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[532]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     {
[2773]24          global $core;
25
26          if (!(boolean) $core->blog->settings->system->simpleMenu_active)
27               return '';
28
[532]29          $class = isset($attr['class']) ? trim($attr['class']) : '';
[538]30          $id = isset($attr['id']) ? trim($attr['id']) : '';
[566]31          $description = isset($attr['description']) ? trim($attr['description']) : '';
[2566]32
[567]33          if (!preg_match('#^(title|span)$#',$description)) {
34               $description = '';
35          }
[2566]36
[532]37          return '<?php echo tplSimpleMenu::displayMenu('.
[538]38                    "'".addslashes($class)."',".
[566]39                    "'".addslashes($id)."',".
40                    "'".addslashes($description)."'".
[532]41               '); ?>';
42     }
[2566]43
[587]44     # Widget function
45     public static function simpleMenuWidget($w)
46     {
47          global $core, $_ctx;
[2566]48
[2773]49          if (!(boolean) $core->blog->settings->system->simpleMenu_active)
50               return;
51
[2778]52          if ($w->offline)
53               return;
54
[945]55          if (($w->homeonly == 1 && $core->url->type != 'default') ||
56               ($w->homeonly == 2 && $core->url->type == 'default')) {
[587]57               return;
58          }
59
[588]60          $menu = tplSimpleMenu::displayMenu('','','title');
[587]61          if ($menu == '') {
62               return;
63          }
64
[2667]65          return $w->renderDiv($w->content_only,'simple-menu '.$w->class,'',
66               ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').$menu);
[587]67     }
[2566]68
[566]69     public static function displayMenu($class='',$id='',$description='')
[532]70     {
[1062]71          global $core;
72
[532]73          $ret = '';
[534]74
[2773]75          if (!(boolean) $core->blog->settings->system->simpleMenu_active)
76               return $ret;
77
[534]78          $menu = $GLOBALS['core']->blog->settings->system->get('simpleMenu');
79          $menu = @unserialize($menu);
80
[2566]81          if (is_array($menu))
[534]82          {
83               // Current relative URL
84               $url = $_SERVER['REQUEST_URI'];
85               $abs_url = http::getHost().$url;
[2566]86
[534]87               // Home recognition var
88               $home_url = html::stripHostURL($GLOBALS['core']->blog->url);
89               $home_directory = dirname($home_url);
90               if ($home_directory != '/')
91                    $home_directory = $home_directory.'/';
[532]92
[534]93               // Menu items loop
94               foreach ($menu as $i => $m) {
95                    # $href = lien de l'item de menu
96                    $href = $m['url'];
97                    $href = html::escapeHTML($href);
98
99                    # Active item test
100                    $active = false;
[2566]101                    if (($url == $href) ||
102                         ($abs_url == $href) ||
103                         ($_SERVER['URL_REQUEST_PART'] == $href) ||
[534]104                         (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) {
105                         $active = true;
106                    }
[566]107                    $title = $span = '';
108                    if ($m['descr']) {
109                         if ($description == 'title') {
[2576]110                              $title = ' title="'.html::escapeHTML(__($m['descr'])).'"';
[566]111                         } else {
[2576]112                              $span = ' <span>'.html::escapeHTML(__($m['descr'])).'</span>';
[566]113                         }
114                    }
[2576]115                    $label = html::escapeHTML(__($m['label']));
[1062]116
117                    $item = new ArrayObject(array(
118                         'url' => $href,                         // URL
[2576]119                         'label' => $label,                 // <a> link label
[1062]120                         'title' => $title,                 // <a> link title (optional)
121                         'span' => $span,                   // description (will be displayed after <a> link)
122                         'active' => $active,               // status (true/false)
123                         'class' => ''                      // additional <li> class (optional)
124                         ));
125
126                    # --BEHAVIOR-- publicSimpleMenuItem
127                    $core->callBehavior('publicSimpleMenuItem',$i,$item);
128
[538]129                    $ret .= '<li class="li'.($i+1).
[1062]130                                   ($item['active'] ? ' active' : '').
[538]131                                   ($i == 0 ? ' li-first' : '').
132                                   ($i == count($menu)-1 ? ' li-last' : '').
[1062]133                                   ($item['class'] ? $item['class'] : '').
[538]134                              '">'.
[1062]135                              '<a href="'.$href.'"'.$item['title'].'>'.$item['label'].$item['span'].'</a>'.
[534]136                              '</li>';
137               }
[2566]138
[534]139               // Final rendering
140               if ($ret) {
[2870]141                    $ret = '<ul '.($id ? 'id="'.$id.'"' : '').' class="simple-menu'.($class ? ' '.$class : '').' role="navigation">'."\n".$ret."\n".'</ul>';
[534]142               }
[532]143          }
[534]144
[532]145          return $ret;
146     }
147}
Note: See TracBrowser for help on using the repository browser.

Sites map