PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_patch/patch/administrator/components/com_jaclplus/patch/mod_mainmenu.php

https://github.com/viollarr/alab
PHP | 422 lines | 304 code | 61 blank | 57 comment | 71 complexity | 43a3c8df67e3915f22a4c04a382d2e5a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, AGPL-3.0, Apache-2.0, BSD-3-Clause, GPL-3.0
  1. <?php
  2. /**
  3. * This file has been modified by Vincent Cheah, ByOS Technologies 2008-02-27 12:07
  4. * for integration with JACLPlus Component
  5. */
  6. /**
  7. * @version $Id: mod_mainmenu.php 5943 2006-12-06 13:23:38Z predator $
  8. * @package Joomla
  9. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  10. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  11. * Joomla! is free software. This version may have been modified pursuant
  12. * to the GNU General Public License, and as distributed it includes or
  13. * is derivative of works licensed under the GNU General Public License or
  14. * other free or open source software licenses.
  15. * See COPYRIGHT.php for copyright notices and details.
  16. */
  17. // no direct access
  18. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  19. if (!defined( '_MOS_MAINMENU_MODULE' )) {
  20. /** ensure that functions are declared only once */
  21. define( '_MOS_MAINMENU_MODULE', 1 );
  22. /**
  23. * Utility function for writing a menu link
  24. */
  25. function mosGetMenuLink( $mitem, $level=0, &$params, $open=null ) {
  26. global $Itemid, $mosConfig_live_site, $mainframe;
  27. $txt = '';
  28. switch ($mitem->type) {
  29. case 'separator':
  30. case 'component_item_link':
  31. break;
  32. case 'url':
  33. if ( eregi( 'index.php\?', $mitem->link ) && !eregi( 'http', $mitem->link ) && !eregi( 'https', $mitem->link ) ) {
  34. if ( !eregi( 'Itemid=', $mitem->link ) ) {
  35. $mitem->link .= '&Itemid='. $mitem->id;
  36. }
  37. }
  38. break;
  39. case 'content_item_link':
  40. case 'content_typed':
  41. // load menu params
  42. $menuparams = new mosParameters( $mitem->params, $mainframe->getPath( 'menu_xml', $mitem->type ), 'menu' );
  43. $unique_itemid = $menuparams->get( 'unique_itemid', 1 );
  44. if ( $unique_itemid ) {
  45. $mitem->link .= '&Itemid='. $mitem->id;
  46. } else {
  47. $temp = split('&task=view&id=', $mitem->link);
  48. if ( $mitem->type == 'content_typed' ) {
  49. $mitem->link .= '&Itemid='. $mainframe->getItemid($temp[1], 1, 0);
  50. } else {
  51. $mitem->link .= '&Itemid='. $mainframe->getItemid($temp[1], 0, 1);
  52. }
  53. }
  54. break;
  55. default:
  56. $mitem->link .= '&Itemid='. $mitem->id;
  57. break;
  58. }
  59. // Active Menu highlighting
  60. $current_itemid = $Itemid;
  61. if ( !$current_itemid ) {
  62. $id = '';
  63. } else if ( $current_itemid == $mitem->id ) {
  64. $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"';
  65. } else if( $params->get( 'activate_parent' ) && isset( $open ) && in_array( $mitem->id, $open ) ) {
  66. $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"';
  67. } else {
  68. $id = '';
  69. }
  70. if ( $params->get( 'full_active_id' ) ) {
  71. // support for `active_menu` of 'Link - Component Item'
  72. if ( $id == '' && $mitem->type == 'component_item_link' ) {
  73. parse_str( $mitem->link, $url );
  74. if ( $url['Itemid'] == $current_itemid ) {
  75. $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"';
  76. }
  77. }
  78. // support for `active_menu` of 'Link - Url' if link is relative
  79. if ( $id == '' && $mitem->type == 'url' && strpos( 'http', $mitem->link ) === false) {
  80. parse_str( $mitem->link, $url );
  81. if ( isset( $url['Itemid'] ) ) {
  82. if ( $url['Itemid'] == $current_itemid ) {
  83. $id = 'id="active_menu'. $params->get( 'class_sfx' ) .'"';
  84. }
  85. }
  86. }
  87. }
  88. // replace & with amp; for xhtml compliance
  89. $mitem->link = ampReplace( $mitem->link );
  90. // run through SEF convertor
  91. $mitem->link = sefRelToAbs( $mitem->link );
  92. $menuclass = 'mainlevel'. $params->get( 'class_sfx' );
  93. if ($level > 0) {
  94. $menuclass = 'sublevel'. $params->get( 'class_sfx');
  95. }
  96. // replace & with amp; for xhtml compliance
  97. // remove slashes from excaped characters
  98. $mitem->name = stripslashes( ampReplace($mitem->name) );
  99. switch ($mitem->browserNav) {
  100. // cases are slightly different
  101. case 1:
  102. // open in a new window
  103. $txt = '<a href="'. $mitem->link .'" target="_blank" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>';
  104. break;
  105. case 2:
  106. // open in a popup window
  107. $txt = "<a href=\"#\" onclick=\"javascript: window.open('". $mitem->link ."', '', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=550'); return false\" class=\"$menuclass\" ". $id .">". $mitem->name ."</a>\n";
  108. break;
  109. case 3:
  110. // don't link it
  111. $txt = '<span class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</span>';
  112. break;
  113. default:
  114. // open in parent window
  115. $txt = '<a href="'. $mitem->link .'" class="'. $menuclass .'" '. $id .'>'. $mitem->name .'</a>';
  116. break;
  117. }
  118. if ( $params->get( 'menu_images' ) ) {
  119. $menu_params = new stdClass();
  120. $menu_params = new mosParameters( $mitem->params );
  121. $menu_image = $menu_params->def( 'menu_image', -1 );
  122. if ( ( $menu_image != '-1' ) && $menu_image ) {
  123. $image = '<img src="'. $mosConfig_live_site .'/images/stories/'. $menu_image .'" border="0" alt="'. $mitem->name .'"/>';
  124. if ( $params->get( 'menu_images_align' ) ) {
  125. $txt = $txt .' '. $image;
  126. } else {
  127. $txt = $image .' '. $txt;
  128. }
  129. }
  130. }
  131. return $txt;
  132. }
  133. /**
  134. * Vertically Indented Menu
  135. */
  136. function mosShowVIMenu( &$params ) {
  137. global $database, $my, $cur_template, $Itemid;
  138. global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_shownoauth;
  139. /* If a user has signed in, get their user type */
  140. $intUserType = 0;
  141. if($my->gid){
  142. switch ($my->usertype) {
  143. case 'Super Administrator':
  144. $intUserType = 0;
  145. break;
  146. case 'Administrator':
  147. $intUserType = 1;
  148. break;
  149. case 'Editor':
  150. $intUserType = 2;
  151. break;
  152. case 'Registered':
  153. $intUserType = 3;
  154. break;
  155. case 'Author':
  156. $intUserType = 4;
  157. break;
  158. case 'Publisher':
  159. $intUserType = 5;
  160. break;
  161. case 'Manager':
  162. $intUserType = 6;
  163. break;
  164. }
  165. } else {
  166. /* user isn't logged in so make their usertype 0 */
  167. $intUserType = 0;
  168. }
  169. $and = '';
  170. if ( !$mosConfig_shownoauth ) {
  171. //$and = "\n AND access <= " . (int) $my->gid;
  172. $and = "\n AND access " . ( isset($my->jaclplus) ? "IN ( $my->jaclplus )" : "<= " . (int) $my->gid );
  173. }
  174. $sql = "SELECT m.*"
  175. . "\n FROM #__menu AS m"
  176. . "\n WHERE menutype = " . $database->Quote( $params->get( 'menutype' ) )
  177. . "\n AND published = 1"
  178. . $and
  179. . "\n ORDER BY parent, ordering";
  180. $database->setQuery( $sql );
  181. $rows = $database->loadObjectList( 'id' );
  182. // indent icons
  183. switch ( $params->get( 'indent_image' ) ) {
  184. case '1':
  185. // Default images
  186. $imgpath = $mosConfig_live_site .'/images/M_images';
  187. for ( $i = 1; $i < 7; $i++ ) {
  188. $img[$i] = '<img src="'. $imgpath .'/indent'. $i .'.png" alt="" />';
  189. }
  190. break;
  191. case '2':
  192. // Use Params
  193. $imgpath = $mosConfig_live_site .'/images/M_images';
  194. for ( $i = 1; $i < 7; $i++ ) {
  195. if ( $params->get( 'indent_image'. $i ) == '-1' ) {
  196. $img[$i] = NULL;
  197. } else {
  198. $img[$i] = '<img src="'. $imgpath .'/'. $params->get( 'indent_image'. $i ) .'" alt="" />';
  199. }
  200. }
  201. break;
  202. case '3':
  203. // None
  204. for ( $i = 1; $i < 7; $i++ ) {
  205. $img[$i] = NULL;
  206. }
  207. break;
  208. default:
  209. // Template
  210. $imgpath = $mosConfig_live_site .'/templates/'. $cur_template .'/images';
  211. for ( $i = 1; $i < 7; $i++ ) {
  212. $img[$i] = '<img src="'. $imgpath .'/indent'. $i .'.png" alt="" />';
  213. }
  214. break;
  215. }
  216. $indents = array(
  217. // block prefix / item prefix / item suffix / block suffix
  218. array( '<table width="100%" border="0" cellpadding="0" cellspacing="0">', '<tr align="left"><td>' , '</td></tr>', '</table>' ),
  219. array( '', '<div style="padding-left: 4px">'. $img[1] , '</div>', '' ),
  220. array( '', '<div style="padding-left: 8px">'. $img[2] , '</div>', '' ),
  221. array( '', '<div style="padding-left: 12px">'. $img[3] , '</div>', '' ),
  222. array( '', '<div style="padding-left: 16px">'. $img[4] , '</div>', '' ),
  223. array( '', '<div style="padding-left: 20px">'. $img[5] , '</div>', '' ),
  224. array( '', '<div style="padding-left: 24px">'. $img[6] , '</div>', '' ),
  225. );
  226. // establish the hierarchy of the menu
  227. $children = array();
  228. // first pass - collect children
  229. foreach ($rows as $v ) {
  230. $pt = $v->parent;
  231. $list = @$children[$pt] ? $children[$pt] : array();
  232. array_push( $list, $v );
  233. $children[$pt] = $list;
  234. }
  235. // second pass - collect 'open' menus
  236. $open = array( $Itemid );
  237. $count = 20; // maximum levels - to prevent runaway loop
  238. $id = $Itemid;
  239. while (--$count) {
  240. if (isset($rows[$id]) && $rows[$id]->parent > 0) {
  241. $id = $rows[$id]->parent;
  242. $open[] = $id;
  243. } else {
  244. break;
  245. }
  246. }
  247. mosRecurseVIMenu( 0, 0, $children, $open, $indents, $params );
  248. }
  249. /**
  250. * Utility function to recursively work through a vertically indented
  251. * hierarchial menu
  252. */
  253. function mosRecurseVIMenu( $id, $level, &$children, &$open, &$indents, &$params ) {
  254. if (@$children[$id]) {
  255. $n = min( $level, count( $indents )-1 );
  256. echo "\n".$indents[$n][0];
  257. foreach ($children[$id] as $row) {
  258. echo "\n".$indents[$n][1];
  259. echo mosGetMenuLink( $row, $level, $params, $open );
  260. // show menu with menu expanded - submenus visible
  261. if ( !$params->get( 'expand_menu' ) ) {
  262. if ( in_array( $row->id, $open )) {
  263. mosRecurseVIMenu( $row->id, $level+1, $children, $open, $indents, $params );
  264. }
  265. } else {
  266. mosRecurseVIMenu( $row->id, $level+1, $children, $open, $indents, $params );
  267. }
  268. echo $indents[$n][2];
  269. }
  270. echo "\n".$indents[$n][3];
  271. }
  272. }
  273. /**
  274. * Draws a horizontal 'flat' style menu (very simple case)
  275. */
  276. function mosShowHFMenu( &$params, $style=0 ) {
  277. global $database, $my, $cur_template, $Itemid;
  278. global $mosConfig_absolute_path, $mosConfig_shownoauth;
  279. $and = '';
  280. if ( !$mosConfig_shownoauth ) {
  281. //$and = "\n AND access <= " . (int) $my->gid;
  282. $and = "\n AND access " . ( isset($my->jaclplus) ? "IN ( $my->jaclplus )" : "<= " . (int) $my->gid );
  283. }
  284. $sql = "SELECT m.*"
  285. . "\n FROM #__menu AS m"
  286. . "\n WHERE menutype = " . $database->Quote( $params->get( 'menutype' ) )
  287. . "\n AND published = 1"
  288. . $and
  289. . "\n AND parent = 0"
  290. . "\n ORDER BY ordering"
  291. ;
  292. $database->setQuery( $sql );
  293. $rows = $database->loadObjectList( 'id' );
  294. $links = array();
  295. foreach ($rows as $row) {
  296. $links[] = mosGetMenuLink( $row, 0, $params );
  297. }
  298. $menuclass = 'mainlevel'. $params->get( 'class_sfx' );
  299. if (count( $links )) {
  300. switch ($style) {
  301. case 1:
  302. echo '<ul id="'. $menuclass .'">';
  303. foreach ($links as $link) {
  304. echo '<li>' . $link . '</li>';
  305. }
  306. echo '</ul>';
  307. break;
  308. default:
  309. $spacer_start = $params->get( 'spacer' );
  310. $spacer_end = $params->get( 'end_spacer' );
  311. echo '<table width="100%" border="0" cellpadding="0" cellspacing="1">';
  312. echo '<tr>';
  313. echo '<td nowrap="nowrap">';
  314. if ( $spacer_end ) {
  315. echo '<span class="'. $menuclass .'"> '. $spacer_end .' </span>';
  316. }
  317. if ( $spacer_start ) {
  318. $html = '<span class="'. $menuclass .'"> '. $spacer_start .' </span>';
  319. echo implode( $html, $links );
  320. } else {
  321. echo implode( '', $links );
  322. }
  323. if ( $spacer_end ) {
  324. echo '<span class="'. $menuclass .'"> '. $spacer_end .' </span>';
  325. }
  326. echo '</td>';
  327. echo '</tr>';
  328. echo '</table>';
  329. break;
  330. }
  331. }
  332. }
  333. }
  334. $params->def('menutype', 'mainmenu');
  335. $params->def('class_sfx', '');
  336. $params->def('menu_images', 0);
  337. $params->def('menu_images_align', 0);
  338. $params->def('expand_menu', 0);
  339. $params->def('activate_parent', 0);
  340. $params->def('indent_image', 0);
  341. $params->def('indent_image1', 'indent1.png');
  342. $params->def('indent_image2', 'indent2.png');
  343. $params->def('indent_image3', 'indent3.png');
  344. $params->def('indent_image4', 'indent4.png');
  345. $params->def('indent_image5', 'indent5.png');
  346. $params->def('indent_image6', 'indent.png');
  347. $params->def('spacer', '');
  348. $params->def('end_spacer', '');
  349. $params->def('full_active_id', 0);
  350. switch ( $params->get( 'menu_style', 'vert_indent' ) ) {
  351. case 'list_flat':
  352. mosShowHFMenu( $params, 1 );
  353. break;
  354. case 'horiz_flat':
  355. mosShowHFMenu( $params, 0 );
  356. break;
  357. default:
  358. mosShowVIMenu( $params );
  359. break;
  360. }
  361. ?>