PageRenderTime 57ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/mod_mainmenu/legacy.php

https://github.com/Shigaru/shigaru
PHP | 432 lines | 330 code | 50 blank | 52 comment | 77 complexity | da63c9f118710cebc3c2d82948257efa MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: legacy.php 14401 2010-01-26 14:10:00Z louis $
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  6. * @license GNU/GPL, see LICENSE.php
  7. * Joomla! is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13. // no direct access
  14. defined('_JEXEC') or die('Restricted access');
  15. /**
  16. * Utility function for writing a menu link
  17. */
  18. function mosGetMenuLink($mitem, $level = 0, & $params, $open = null)
  19. {
  20. global $Itemid;
  21. $txt = '';
  22. //needed to break reference to prevent altering the actual menu item
  23. $mitem = clone($mitem);
  24. // Menu Link is a special type that is a link to another item
  25. if ($mitem->type == 'menulink')
  26. {
  27. $menu = &JSite::getMenu();
  28. if ($tmp = $menu->getItem($mitem->query['Itemid'])) {
  29. $name = $mitem->name;
  30. $mid = $mitem->id;
  31. $parent = $mitem->parent;
  32. $mitem = clone($tmp);
  33. $mitem->name = $name;
  34. $mitem->mid = $mid;
  35. $mitem->parent = $parent;
  36. } else {
  37. return;
  38. }
  39. }
  40. switch ($mitem->type)
  41. {
  42. case 'separator' :
  43. $mitem->browserNav = 3;
  44. break;
  45. case 'url' :
  46. if (preg_match('#index.php\?#i', $mitem->link)) {
  47. if (!preg_match('#Itemid=#i', $mitem->link)) {
  48. $mitem->link .= '&amp;Itemid='.$mitem->id;
  49. }
  50. }
  51. break;
  52. default :
  53. $mitem->link = 'index.php?Itemid='.$mitem->id;
  54. break;
  55. }
  56. // Active Menu highlighting
  57. $current_itemid = intval( $Itemid );
  58. if (!$current_itemid) {
  59. $id = '';
  60. } else {
  61. if ($current_itemid == $mitem->id) {
  62. $id = 'id="active_menu' . $params->get('class_sfx') . '"';
  63. } else {
  64. if ($params->get('activate_parent') && isset ($open) && in_array($mitem->id, $open)) {
  65. $id = 'id="active_menu' . $params->get('class_sfx') . '"';
  66. } else {
  67. if ($mitem->type == 'url' && ItemidContained($mitem->link, $current_itemid)) {
  68. $id = 'id="active_menu' . $params->get('class_sfx') . '"';
  69. } else {
  70. $id = '';
  71. }
  72. }
  73. }
  74. }
  75. if ($params->get('full_active_id'))
  76. {
  77. // support for `active_menu` of 'Link - Url' if link is relative
  78. if ($id == '' && $mitem->type == 'url' && strpos($mitem->link, 'http') === false) {
  79. $url = array();
  80. if(strpos($mitem->link, '&amp;') !== false)
  81. {
  82. $mitem->link = str_replace('&amp;','&',$mitem->link);
  83. }
  84. parse_str($mitem->link, $url);
  85. if (isset ($url['Itemid'])) {
  86. if ($url['Itemid'] == $current_itemid) {
  87. $id = 'id="active_menu' . $params->get('class_sfx') . '"';
  88. }
  89. }
  90. }
  91. }
  92. // replace & with amp; for xhtml compliance
  93. $menu_params = new stdClass();
  94. $menu_params = new JParameter($mitem->params);
  95. $menu_secure = $menu_params->def('secure', 0);
  96. if (strcasecmp(substr($mitem->link, 0, 4), 'http')) {
  97. $mitem->url = JRoute::_($mitem->link, true, $menu_secure);
  98. } else {
  99. $mitem->url = $mitem->link;
  100. }
  101. $menuclass = 'mainlevel' . $params->get('class_sfx');
  102. if ($level > 0) {
  103. $menuclass = 'sublevel' . $params->get('class_sfx');
  104. }
  105. // replace & with amp; for xhtml compliance
  106. // remove slashes from excaped characters
  107. $mitem->name = stripslashes(htmlspecialchars($mitem->name));
  108. switch ($mitem->browserNav)
  109. {
  110. // cases are slightly different
  111. case 1 :
  112. // open in a new window
  113. $txt .= '<a href="' . $mitem->url . '" target="_blank" class="' . $menuclass . '" ' . $id . '>' . $mitem->name . '</a>';
  114. break;
  115. case 2 :
  116. // open in a popup window
  117. $txt .= "<a href=\"#\" onclick=\"javascript: window.open('" . $mitem->url . "', '', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550'); return false\" class=\"$menuclass\" " . $id . "></a>\n";
  118. break;
  119. case 3 :
  120. // don't link it
  121. $txt .= '' . $mitem->name . '';
  122. break;
  123. default : // formerly case 2
  124. // open in parent window
  125. $txt .= '<a href="' . $mitem->url . '" class="' . $menuclass . '" ' . $id . '>' . $mitem->name . '</a>';
  126. break;
  127. }
  128. if ($params->get('menu_images'))
  129. {
  130. $menu_params = new stdClass();
  131. $menu_params = new JParameter($mitem->params);
  132. $menu_image = $menu_params->def('menu_image', -1);
  133. if (($menu_image <> '-1') && $menu_image) {
  134. $image = '<img src="'.JURI::base(true).'/images/stories/' . $menu_image . '" border="0" alt="' . $mitem->name . '"/>';
  135. if ($params->get('menu_images_align')) {
  136. $txt = $txt . ' ' . $image;
  137. } else {
  138. $txt = $image . ' ' . $txt;
  139. }
  140. }
  141. }
  142. return $txt;
  143. }
  144. /**
  145. * Vertically Indented Menu
  146. */
  147. function mosShowVIMenu(& $params)
  148. {
  149. global $mainframe, $Itemid;
  150. $template = $mainframe->getTemplate();
  151. $menu =& JSite::getMenu();
  152. $user =& JFactory::getUser();
  153. // indent icons
  154. switch ($params->get('indent_image')) {
  155. case '1' :
  156. {
  157. // Default images
  158. $imgpath = JURI::base(true).'/images/M_images';
  159. for ($i = 1; $i < 7; $i++) {
  160. $img[$i] = '<img src="' . $imgpath . '/indent' . $i . '.png" alt="" />';
  161. }
  162. }
  163. break;
  164. case '2' :
  165. {
  166. // Use Params
  167. $imgpath = JURI::base(true).'/images/M_images';
  168. for ($i = 1; $i < 7; $i++) {
  169. if ($params->get('indent_image' . $i) == '-1') {
  170. $img[$i] = NULL;
  171. } else {
  172. $img[$i] = '<img src="' . $imgpath . '/' . $params->get('indent_image' . $i) . '" alt="" />';
  173. }
  174. }
  175. }
  176. break;
  177. case '3' :
  178. {
  179. // None
  180. for ($i = 1; $i < 7; $i++) {
  181. $img[$i] = NULL;
  182. }
  183. }
  184. break;
  185. default :
  186. {
  187. // Template
  188. $imgpath = JURI::base(true).'/templates/' . $template . '/images';
  189. for ($i = 1; $i < 7; $i++) {
  190. $img[$i] = '<img src="' . $imgpath . '/indent' . $i . '.png" alt="" />';
  191. }
  192. }
  193. }
  194. $indents = array (
  195. // block prefix / item prefix / item suffix / block suffix
  196. array (
  197. '<table width="100%" border="0" cellpadding="0" cellspacing="0">',
  198. '<tr ><td>',
  199. '</td></tr>',
  200. '</table>'
  201. ),
  202. array (
  203. '',
  204. '<div style="padding-left: 4px">' . $img[1],
  205. '</div>',
  206. ''
  207. ),
  208. array (
  209. '',
  210. '<div style="padding-left: 8px">' . $img[2],
  211. '</div>',
  212. ''
  213. ),
  214. array (
  215. '',
  216. '<div style="padding-left: 12px">' . $img[3],
  217. '</div>',
  218. ''
  219. ),
  220. array (
  221. '',
  222. '<div style="padding-left: 16px">' . $img[4],
  223. '</div>',
  224. ''
  225. ),
  226. array (
  227. '',
  228. '<div style="padding-left: 20px">' . $img[5],
  229. '</div>',
  230. ''
  231. ),
  232. array (
  233. '',
  234. '<div style="padding-left: 24px">' . $img[6],
  235. '</div>',
  236. ''
  237. ),
  238. );
  239. // establish the hierarchy of the menu
  240. $children = array ();
  241. //get menu items
  242. $rows = $menu->getItems('menutype', $params->get('menutype'));
  243. // first pass - collect children
  244. $cacheIndex = array();
  245. if(is_array($rows) && count($rows)) {
  246. foreach ($rows as $index => $v) {
  247. if ($v->access <= $user->get('aid')) {
  248. $pt = $v->parent;
  249. $list = @ $children[$pt] ? $children[$pt] : array ();
  250. array_push($list, $v);
  251. $children[$pt] = $list;
  252. }
  253. $cacheIndex[$v->id] = $index;
  254. }
  255. }
  256. // second pass - collect 'open' menus
  257. $open = array (
  258. $Itemid
  259. );
  260. $count = 20; // maximum levels - to prevent runaway loop
  261. $id = $Itemid;
  262. while (-- $count)
  263. {
  264. if (isset($cacheIndex[$id])) {
  265. $index = $cacheIndex[$id];
  266. if (isset ($rows[$index]) && $rows[$index]->parent > 0) {
  267. $id = $rows[$index]->parent;
  268. $open[] = $id;
  269. } else {
  270. break;
  271. }
  272. }
  273. }
  274. mosRecurseVIMenu(0, 0, $children, $open, $indents, $params);
  275. }
  276. /**
  277. * Utility function to recursively work through a vertically indented
  278. * hierarchial menu
  279. */
  280. function mosRecurseVIMenu($id, $level, & $children, & $open, & $indents, & $params)
  281. {
  282. if (@ $children[$id]) {
  283. $n = min($level, count($indents) - 1);
  284. echo "\n" . $indents[$n][0];
  285. foreach ($children[$id] as $row) {
  286. echo "\n" . $indents[$n][1];
  287. echo mosGetMenuLink($row, $level, $params, $open);
  288. // show menu with menu expanded - submenus visible
  289. if (!$params->get('expand_menu')) {
  290. if (in_array($row->id, $open)) {
  291. mosRecurseVIMenu($row->id, $level +1, $children, $open, $indents, $params);
  292. }
  293. } else {
  294. mosRecurseVIMenu($row->id, $level +1, $children, $open, $indents, $params);
  295. }
  296. echo $indents[$n][2];
  297. }
  298. echo "\n" . $indents[$n][3];
  299. }
  300. }
  301. /**
  302. * Draws a horizontal 'flat' style menu (very simple case)
  303. */
  304. function mosShowHFMenu(& $params, $style = 0)
  305. {
  306. $menu = & JSite::getMenu();
  307. $user = & JFactory::getUser();
  308. //get menu items
  309. $rows = $menu->getItems('menutype', $params->get('menutype'));
  310. $links = array ();
  311. if(is_array($rows) && count($rows)) {
  312. foreach ($rows as $row)
  313. {
  314. if ($row->access <= $user->get('aid', 0)) {
  315. $links[] = mosGetMenuLink($row, 0, $params);
  316. }
  317. }
  318. }
  319. $menuclass = 'mainlevel' . $params->get('class_sfx');
  320. $lang =& JFactory::getLanguage();
  321. $counter = 0;
  322. $lastchild = '';
  323. if (count($links))
  324. {
  325. switch ($style)
  326. {
  327. case 1 :
  328. echo '<ul id="' . $menuclass . '">';
  329. foreach ($links as $link) {
  330. if($counter == count($links)-1)$lastchild = 'class="last"';
  331. echo '<li '.$lastchild.' id="tab'.$counter.'" >' . $link . '</li>';
  332. $counter++;
  333. $lastchild = '';
  334. }
  335. echo '</ul>';
  336. break;
  337. default :
  338. $spacer_start = $params->get('spacer');
  339. $spacer_end = $params->get('end_spacer');
  340. echo '<table width="100%" border="0" cellpadding="0" cellspacing="1">';
  341. echo '<tr>';
  342. echo '<td nowrap="nowrap">';
  343. if ($spacer_end) {
  344. echo '<span class="' . $menuclass . '"> ' . $spacer_end . ' </span>';
  345. }
  346. if ($spacer_start) {
  347. $html = '<span class="' . $menuclass . '"> ' . $spacer_start . ' </span>';
  348. echo implode($html, $links);
  349. } else {
  350. echo implode('', $links);
  351. }
  352. if ($spacer_end) {
  353. echo '<span class="' . $menuclass . '"> ' . $spacer_end . ' </span>';
  354. }
  355. echo '</td>';
  356. echo '</tr>';
  357. echo '</table>';
  358. break;
  359. }
  360. }
  361. }
  362. /**
  363. * Search for Itemid in link
  364. */
  365. function ItemidContained($link, $Itemid)
  366. {
  367. $link = str_replace('&amp;', '&', $link);
  368. $temp = explode("&", $link);
  369. $linkItemid = "";
  370. foreach ($temp as $value) {
  371. $temp2 = explode("=", $value);
  372. if ($temp2[0] == "Itemid") {
  373. $linkItemid = $temp2[1];
  374. break;
  375. }
  376. }
  377. if ($linkItemid != "" && $linkItemid == $Itemid) {
  378. return true;
  379. } else {
  380. return false;
  381. }
  382. }