|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File holding the Menu component class |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the MediaWiki skin Chameleon. |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2013 - 2014, Stephan Gambke |
|
8
|
|
|
* @license GNU General Public License, version 3 (or any later version) |
|
9
|
|
|
* |
|
10
|
|
|
* The Chameleon skin is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU General Public License as published by the Free |
|
12
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any |
|
13
|
|
|
* later version. |
|
14
|
|
|
* |
|
15
|
|
|
* The Chameleon skin is distributed in the hope that it will be useful, but |
|
16
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
18
|
|
|
* details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU General Public License along |
|
21
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
* |
|
23
|
|
|
* @file |
|
24
|
|
|
* @ingroup Skins |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace Skins\Chameleon\Components; |
|
28
|
|
|
|
|
29
|
|
|
use Skins\Chameleon\Menu\MenuFactory; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Class Menu |
|
33
|
|
|
* |
|
34
|
|
|
* @author Stephan Gambke |
|
35
|
|
|
* @since 1.0 |
|
36
|
|
|
* @ingroup Skins |
|
37
|
|
|
*/ |
|
38
|
|
|
class Menu extends Component { |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Builds the HTML code for this component |
|
42
|
|
|
* |
|
43
|
|
|
* @return String the HTML code |
|
44
|
|
|
*/ |
|
45
|
3 |
|
public function getHtml() { |
|
46
|
|
|
|
|
47
|
3 |
|
$element = $this->getDomElement(); |
|
48
|
|
|
|
|
49
|
3 |
|
if ( $element === null ){ |
|
50
|
1 |
|
return ''; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
2 |
|
$msgKey = $element->getAttribute( 'message' ); |
|
54
|
|
|
|
|
55
|
2 |
|
$menuFactory = new MenuFactory(); |
|
56
|
|
|
|
|
57
|
2 |
|
if ( empty( $msgKey ) ) { |
|
58
|
1 |
|
$text = $element->textContent; |
|
59
|
1 |
|
$menu = $menuFactory->getMenuFromMessageText( $text ); |
|
60
|
1 |
|
} else { |
|
61
|
1 |
|
$menu = $menuFactory->getMenuFromMessage( $msgKey ); |
|
62
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
2 |
|
$menu->setMenuItemFormatter( |
|
66
|
|
|
function ( $href, $text, $depth, $subitems ) { |
|
67
|
|
|
$href = \Sanitizer::cleanUrl( $href ); |
|
68
|
|
|
$text = htmlspecialchars( $text ); |
|
69
|
|
|
if ( $depth === 1 && !empty( $subitems ) ) { |
|
70
|
|
|
return "<li class=\"dropdown\"><a class=\"dropdown-toggle\" href=\"#\" data-toggle=\"dropdown\">$text<b class=\"caret\"></b></a>$subitems</li>"; |
|
71
|
|
|
} else { |
|
72
|
|
|
return "<li><a href=\"$href\">$text</a>$subitems</li>"; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
2 |
|
); |
|
76
|
|
|
|
|
77
|
2 |
|
$menu->setItemListFormatter( |
|
78
|
|
|
function ( $rawItemsHtml, $depth ) { |
|
79
|
|
|
if ( $depth === 0 ) { |
|
80
|
|
|
return $rawItemsHtml; |
|
81
|
|
|
} elseif ( $depth === 1 ) { |
|
82
|
|
|
return "<ul class=\"dropdown-menu\">$rawItemsHtml</ul>"; |
|
83
|
|
|
} else { |
|
84
|
|
|
return "<ul>$rawItemsHtml</ul>"; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
2 |
|
); |
|
89
|
|
|
|
|
90
|
2 |
|
return $menu->getHtml(); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|