[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 ----------------------------------------- |
---|
| 12 | if (!defined('DC_RC_PATH')) { return; } |
---|
| 13 | |
---|
| 14 | # Simple menu template functions |
---|
| 15 | $core->tpl->addValue('SimpleMenu',array('tplSimpleMenu','simpleMenu')); |
---|
| 16 | |
---|
| 17 | class tplSimpleMenu |
---|
| 18 | { |
---|
| 19 | public static function simpleMenu($attr) |
---|
| 20 | { |
---|
| 21 | $class = isset($attr['class']) ? trim($attr['class']) : ''; |
---|
[538] | 22 | $id = isset($attr['id']) ? trim($attr['id']) : ''; |
---|
[566] | 23 | $description = isset($attr['description']) ? trim($attr['description']) : ''; |
---|
[532] | 24 | |
---|
| 25 | return '<?php echo tplSimpleMenu::displayMenu('. |
---|
[538] | 26 | "'".addslashes($class)."',". |
---|
[566] | 27 | "'".addslashes($id)."',". |
---|
| 28 | "'".addslashes($description)."'". |
---|
[532] | 29 | '); ?>'; |
---|
| 30 | } |
---|
| 31 | |
---|
[566] | 32 | public static function displayMenu($class='',$id='',$description='') |
---|
[532] | 33 | { |
---|
| 34 | $ret = ''; |
---|
[534] | 35 | |
---|
| 36 | $menu = $GLOBALS['core']->blog->settings->system->get('simpleMenu'); |
---|
| 37 | $menu = @unserialize($menu); |
---|
| 38 | |
---|
| 39 | if (is_array($menu)) |
---|
| 40 | { |
---|
| 41 | // Current relative URL |
---|
| 42 | $url = $_SERVER['REQUEST_URI']; |
---|
| 43 | $abs_url = http::getHost().$url; |
---|
[532] | 44 | |
---|
[534] | 45 | // Home recognition var |
---|
| 46 | $home_url = html::stripHostURL($GLOBALS['core']->blog->url); |
---|
| 47 | $home_directory = dirname($home_url); |
---|
| 48 | if ($home_directory != '/') |
---|
| 49 | $home_directory = $home_directory.'/'; |
---|
[532] | 50 | |
---|
[534] | 51 | // Menu items loop |
---|
| 52 | foreach ($menu as $i => $m) { |
---|
| 53 | # $href = lien de l'item de menu |
---|
| 54 | $href = $m['url']; |
---|
| 55 | $href = html::escapeHTML($href); |
---|
| 56 | |
---|
| 57 | # Active item test |
---|
| 58 | $active = false; |
---|
| 59 | if (($url == $href) || |
---|
| 60 | ($abs_url == $href) || |
---|
| 61 | ($_SERVER['URL_REQUEST_PART'] == $href) || |
---|
| 62 | (($_SERVER['URL_REQUEST_PART'] == '') && (($href == $home_url) || ($href == $home_directory)))) { |
---|
| 63 | $active = true; |
---|
| 64 | } |
---|
[566] | 65 | $title = $span = ''; |
---|
| 66 | if ($m['descr']) { |
---|
| 67 | if ($description == 'title') { |
---|
| 68 | $title = ' title="'.__($m['descr']).'"'; |
---|
| 69 | } else { |
---|
| 70 | $span = ' <span>'.__($m['descr']).'</span>'; |
---|
| 71 | } |
---|
| 72 | } |
---|
[538] | 73 | $ret .= '<li class="li'.($i+1). |
---|
| 74 | ($active ? ' active' : ''). |
---|
| 75 | ($i == 0 ? ' li-first' : ''). |
---|
| 76 | ($i == count($menu)-1 ? ' li-last' : ''). |
---|
| 77 | '">'. |
---|
[566] | 78 | '<a href="'.$href.'"'.$title.'>'.__($m['label']).$span.'</a>'. |
---|
[534] | 79 | '</li>'; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | // Final rendering |
---|
| 83 | if ($ret) { |
---|
[538] | 84 | $ret = '<ul '.($id ? 'id="'.$id.'"' : '').' class="simple-menu'.($class ? ' '.$class : '').'">'."\n".$ret."\n".'</ul>'; |
---|
[534] | 85 | } |
---|
[532] | 86 | } |
---|
[534] | 87 | |
---|
[532] | 88 | return $ret; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | ?> |
---|