PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tmp/busines13_bundle_installer/mod_roknavmenu/lib/RokNavMenu.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 223 lines | 158 code | 37 blank | 28 comment | 18 complexity | 2ef9145affb0bd3c4dfe11735b471ef2 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
  1. <?php
  2. /**
  3. * @version 1.13 July 2, 2012
  4. * @author RocketTheme http://www.rockettheme.com
  5. * @copyright Copyright (C) 2007 - 2012 RocketTheme, LLC
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  7. */
  8. require_once(dirname(__FILE__) . "/librokmenu/includes.php");
  9. require_once(dirname(__FILE__) . "/helper.php");
  10. if (!class_exists('RokNavMenu'))
  11. {
  12. class RokNavMenu extends RokMenu
  13. {
  14. const TOP_LEVEL_PARENT_ID = 1;
  15. static $themes = array();
  16. static $current_template;
  17. static $catalogs_loaded = false;
  18. public function __construct($args)
  19. {
  20. self::loadCatalogs();
  21. parent::__construct($args);
  22. }
  23. protected function getProvider()
  24. {
  25. require_once(dirname(__FILE__) . '/providers/RokMenuProviderJoomla16.php');
  26. return new RokMenuProviderJoomla16($this->args);
  27. }
  28. protected function getRenderer()
  29. {
  30. // if its a registered theme its a 2x theme
  31. if (array_key_exists('theme', $this->args) && array_key_exists($this->args['theme'], self::$themes))
  32. {
  33. $themeinfo = self::$themes[$this->args['theme']];
  34. $themeclass = $themeinfo['class'];
  35. $renderer = new RokNavMenu2XRenderer();
  36. $theme = new $themeclass();
  37. $renderer->setTheme($theme);
  38. }
  39. else
  40. {
  41. // its a 1x theme
  42. $renderer = new RokNavMenu1XRenderer();
  43. }
  44. return $renderer;
  45. }
  46. public function render()
  47. {
  48. $this->renderHeader();
  49. return $this->renderMenu();
  50. }
  51. public static function registerTheme($path, $name, $fullname, $themeClass)
  52. {
  53. $theme = array('name' => $name, 'fullname' => $fullname, 'path' => $path, 'class' => $themeClass);
  54. self::$themes[$name] = $theme;
  55. }
  56. public static function loadCatalogs()
  57. {
  58. if (!self::$catalogs_loaded) {
  59. // load the module themes catalog
  60. require_once(JPATH_ROOT . '/modules/mod_roknavmenu/themes/catalog.php');
  61. foreach (self::getTemplates() as $template) {
  62. $template_theme_catalog = JPATH_ROOT . '/templates/' . $template . "/html/mod_roknavmenu/themes/catalog.php";
  63. if (JFile::exists($template_theme_catalog)) {
  64. //load the templates themes
  65. include_once($template_theme_catalog);
  66. }
  67. }
  68. self::$catalogs_loaded = true;
  69. }
  70. }
  71. protected static function getTemplates()
  72. {
  73. $Itemid = JRequest::getInt('Itemid');
  74. // Load specific style if one is assigned
  75. $db = JFactory::getDbo();
  76. $query = $db->getQuery(true);
  77. $query->select('ts.template');
  78. $query->from('#__template_styles AS ts');
  79. $query->join('INNER','#__menu AS m ON ts.id=m.template_style_id');
  80. $query->where('m.id = '.$Itemid);
  81. $query->where('m.template_style_id != 0');
  82. $db->setQuery($query);
  83. $templates = $db->loadResultArray();
  84. if ($templates){
  85. return $templates;
  86. }
  87. // Load styles normally if no specific style is assigned
  88. $query = $db->getQuery(true);
  89. $query->select('template');
  90. $query->from('#__template_styles');
  91. $query->where('home = 1');
  92. $query->where('client_id = 0');
  93. $db->setQuery($query);
  94. $templates = $db->loadResultArray();
  95. return $templates;
  96. }
  97. /**
  98. * Load published modules
  99. *
  100. * @return array
  101. */
  102. public static function &loadModules()
  103. {
  104. static $clean;
  105. if (isset($clean)) {
  106. return $clean;
  107. }
  108. $Itemid = JRequest::getInt('Itemid');
  109. $app = JFactory::getApplication();
  110. $user = JFactory::getUser();
  111. $groups = implode(',', $user->getAuthorisedViewLevels());
  112. $lang = JFactory::getLanguage()->getTag();
  113. $clientId = (int) $app->getClientId();
  114. $cache = JFactory::getCache ('com_modules', '');
  115. $cacheid = md5(serialize(array($Itemid, $groups, $clientId, $lang)));
  116. if (!($clean = $cache->get($cacheid))) {
  117. $db = JFactory::getDbo();
  118. $query = $db->getQuery(true);
  119. $query->select('id, title, module, position, content, showtitle, params, mm.menuid');
  120. $query->from('#__modules AS m');
  121. $query->join('LEFT','#__modules_menu AS mm ON mm.moduleid = m.id');
  122. $query->where('m.published = 1');
  123. $date = JFactory::getDate();
  124. $now = $date->toMySQL();
  125. $nullDate = $db->getNullDate();
  126. $query->where('(m.publish_up = '.$db->Quote($nullDate).' OR m.publish_up <= '.$db->Quote($now).')');
  127. $query->where('(m.publish_down = '.$db->Quote($nullDate).' OR m.publish_down >= '.$db->Quote($now).')');
  128. $query->where('m.access IN ('.$groups.')');
  129. $query->where('m.client_id = '. $clientId);
  130. $query->where('(mm.menuid = '. (int) $Itemid .' OR mm.menuid <= 0)');
  131. // Filter by language
  132. if ($app->isSite() && $app->getLanguageFilter()) {
  133. $query->where('m.language IN (' . $db->Quote($lang) . ',' . $db->Quote('*') . ')');
  134. }
  135. $query->order('position, ordering');
  136. // Set the query
  137. $db->setQuery($query);
  138. $modules = $db->loadObjectList();
  139. $clean = array();
  140. if($db->getErrorNum()){
  141. JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $db->getErrorMsg()));
  142. return $clean;
  143. }
  144. // Apply negative selections and eliminate duplicates
  145. $negId = $Itemid ? -(int)$Itemid : false;
  146. $dupes = array();
  147. for ($i = 0, $n = count($modules); $i < $n; $i++)
  148. {
  149. $module = &$modules[$i];
  150. // The module is excluded if there is an explicit prohibition, or if
  151. // the Itemid is missing or zero and the module is in exclude mode.
  152. $negHit = ($negId === (int) $module->menuid)
  153. || (!$negId && (int)$module->menuid < 0);
  154. if (isset($dupes[$module->id]))
  155. {
  156. // If this item has been excluded, keep the duplicate flag set,
  157. // but remove any item from the cleaned array.
  158. if ($negHit) {
  159. unset($clean[$module->id]);
  160. }
  161. continue;
  162. }
  163. $dupes[$module->id] = true;
  164. // Only accept modules without explicit exclusions.
  165. if (!$negHit)
  166. {
  167. //determine if this is a custom module
  168. $file = $module->module;
  169. $custom = substr($file, 0, 4) == 'mod_' ? 0 : 1;
  170. $module->user = $custom;
  171. // Custom module name is given by the title field, otherwise strip off "com_"
  172. $module->name = $custom ? $module->title : substr($file, 4);
  173. $module->style = null;
  174. $module->position = strtolower($module->position);
  175. $clean[$module->id] = $module;
  176. }
  177. }
  178. unset($dupes);
  179. // Return to simple indexing that matches the query order.
  180. $clean = array_values($clean);
  181. $cache->store($clean, $cacheid);
  182. }
  183. return $clean;
  184. }
  185. }
  186. }