OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / templates / art26_test1 / html / mod_mainmenu / default.php
1 <?php
2 defined('_JEXEC') or die;
3
4 ob_start();
5 require_once realpath(dirname(__FILE__) . str_replace('/', DIRECTORY_SEPARATOR, '/../../../../modules/mod_mainmenu/tmpl/default.php'));
6 ob_clean();
7
8 if (!defined('modMainMenuArtxExtensions'))
9 {
10
11         function modMainMenuArtXMLCallback(&$node, $args)
12         {
13                 $options = $GLOBALS['modMainMenuArtXMLCallbackOptions'];
14                 if ($node->name() == 'li') {
15                         if (!$options['show_submenus'] && $node->level() == 1) {
16                                 if ($ul = $node->getElementByPath('ul'))
17                                         $node->removeChild($ul);
18                         }
19                         $liChildren = & $node->_children;
20                         if (count($liChildren) > 0) {
21                                 // element                 ( $img?,                                          $span ( $text     )  )      )
22                                 // <a href="...">          <img src="..." (align="left|right")? alt="..." />?<span><![CDATA[...]]></span></a>
23                                 // <span class="separator"><img src="..." (align="left|right")? alt="..." />?<span><![CDATA[...]]></span></span>
24                                 $element = & $liChildren[0];
25                                 $img = null;
26                                 if ($element->_children[0]->name() == 'img') {
27                                         $img = & $element->_children[0];
28                                         $element->removeChild($img);
29                                 }
30                                 $span = & $element->_children[0];
31                                 if (count($liChildren) > 1)
32                                         $sublist = & $liChildren[1];
33                                 else
34                                         $sublist = null;
35                                 $element->removeChild($span);
36                                 // convert separator to anchor
37                                 if ($element->name() == 'span' && $element->attributes('class') == 'separator') {
38                                         $element->_name = 'a';
39                                         $element->addAttribute('href', '#');
40                                         $element->addAttribute('onclick', 'return false;');
41                                         if ($sublist == null)
42                                                 $element->addAttribute('class', 'separator separator-without-submenu');
43                                 }
44                                 // add extra spans for top level items, required for design
45                                 if ($element->level() == ($options['start'] + 1) * 2) {
46                                         $lspan = & $element->addChild('span', array('class' => 'l'));
47                                         $rspan = & $element->addChild('span', array('class' => 'r'));
48                                         $tspan = & $element->addChild('span', array('class' => 't'));
49                                         $container = & $tspan;
50                                 } else {
51                                         $container = & $element;
52                                 }
53                                 $text = $span->data();
54                                 // container is always <a ...>...</a> here
55                                 if ($img != null) {
56                                         $align = $img->attributes('align');
57                                         if ($align == 'left' || $align == '') {
58                                                 $container->addChild('img', array('class' => 'art-metadata-icon',
59                                                         'src' => $img->attributes('src'),
60                                                         'style' => 'margin-right: 5px; vertical-align: middle;',
61                                                         'alt' => $img->attributes('alt')));
62                                                 $extraArtxSpan = & $container->addChild('artx-extra-span');
63                                                 $extraArtxSpan->setData($text);
64                                         } else if ($align == 'right') {
65                                                 $extraArtxSpan = & $container->addChild('artx-extra-span');
66                                                 $extraArtxSpan->setData($text);
67                                                 $container->addChild('img', array('class' => 'art-metadata-icon',
68                                                         'src' => $img->attributes('src'),
69                                                         'style' => 'margin-left: 5px; vertical-align: middle;',
70                                                         'alt' => $img->attributes('alt')));
71                                         }
72                                 } else {
73                                         $container->setData($text);
74                                 }
75                         }
76
77                         modMainMenuXMLCallback($node, $args);
78
79                         // this should be after modMainMenuXMLCallback, because the callback sets class='active' and id='current'
80                         if ($options['vmenu'] !== null && !$options['vmenu']['simple']) {
81                                 $class = $node->attributes('class');
82                                 $isActive = $class && false !== strpos(' ' . $class, ' active');
83                                 if ($node->attributes('id') != 'current' && !$isActive) {
84                                         if ($ul = $node->getElementByPath('ul'))
85                                                 $node->removeChild($ul);
86                                 }
87                         }
88
89                         $class = $node->attributes('class');
90                         if ($class && false !== strpos(' ' . $class, ' active')) {
91                                 $element->addAttribute('class', 'active');
92                         }
93                 } else {
94                         modMainMenuXMLCallback($node, $args);
95                 }
96         }
97
98         define('modMainMenuArtxExtensions', true);
99 }
100
101 if (isset($attribs['name']) && $attribs['name'] == 'user3') {
102         $GLOBALS['modMainMenuArtXMLCallbackOptions'] = array(
103                 'show_submenus' => $GLOBALS['artx_settings']['menu']['show_submenus'] && 1 == $params->get('showAllChildren'),
104                 'vmenu' => null,
105                 'start' => $params->get('startLevel')
106         );
107         $xml = modMainMenuHelper::getXML($params->get('menutype'), $params, 'modMainMenuArtXMLCallback');
108         if ($xml) {
109                 $xml->addAttribute('class', 'art-menu');
110                 if ($tagId = $params->get('tag_id')) {
111                         $xml->addAttribute('id', $tagId);
112                 }
113                 $result = JFilterOutput::ampReplace($xml->toString((bool)$params->get('show_whitespace')));
114                 $result = str_replace(array('<ul/>', '<ul />', '<artx-extra-span>', '</artx-extra-span>'), '', $result);
115                 $result = preg_replace('~<span([^>]*) />~', '<span$1></span>', $result);
116                 echo $result;
117         }
118         unset($GLOBALS['tmp_menu_show_submenus']);
119 } else if (0 === strpos($params->get('moduleclass_sfx'), 'art-vmenu') || false !== strpos($params->get('moduleclass_sfx'), ' art-vmenu')) {
120         $GLOBALS['modMainMenuArtXMLCallbackOptions'] = array(
121                 'show_submenus' => $GLOBALS['artx_settings']['vmenu']['show_submenus'] && 1 == $params->get('showAllChildren'),
122                 'vmenu' => array('simple' => $GLOBALS['artx_settings']['vmenu']['simple']),
123                 'start' => $params->get('startLevel')
124         );
125         $xml = modMainMenuHelper::getXML($params->get('menutype'), $params, 'modMainMenuArtXMLCallback');
126         if ($xml) {
127                 $xml->addAttribute('class', 'art-vmenu');
128                 if ($tagId = $params->get('tag_id')) {
129                         $xml->addAttribute('id', $tagId);
130                 }
131                 $result = JFilterOutput::ampReplace($xml->toString((bool)$params->get('show_whitespace')));
132                 $result = str_replace(array('<ul/>', '<ul />', '<artx-extra-span>', '</artx-extra-span>'), '', $result);
133                 $result = preg_replace('~<span([^>]*) />~', '<span$1></span>', $result);
134                 echo $result;
135         }
136         unset($GLOBALS['tmp_menu_show_submenus']);
137 } else {
138         modMainMenuHelper::render($params, 'modMainMenuXMLCallback');
139 }