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