https-bitbucket.org-bityvip /tmp/busines13_bundle_installer/mod_roknavmenu/lib/RokNavMenu.php

Language PHP Lines 224
MD5 Hash 2ef9145affb0bd3c4dfe11735b471ef2 Estimated Cost $3,867 (why?)
Repository https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
 * @version   1.13 July 2, 2012
 * @author    RocketTheme http://www.rockettheme.com
 * @copyright Copyright (C) 2007 - 2012 RocketTheme, LLC
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 */

require_once(dirname(__FILE__) . "/librokmenu/includes.php");
require_once(dirname(__FILE__) . "/helper.php");

if (!class_exists('RokNavMenu'))
{
    class RokNavMenu extends RokMenu
    {
        const TOP_LEVEL_PARENT_ID = 1;
        static $themes = array();
        static $current_template;
        static $catalogs_loaded = false;

        public function __construct($args)
        {
            self::loadCatalogs();
            parent::__construct($args);
        }

        protected function getProvider()
        {
            require_once(dirname(__FILE__) . '/providers/RokMenuProviderJoomla16.php');
            return new RokMenuProviderJoomla16($this->args);
        }

        protected function getRenderer()
        {
            // if its a registered theme its a 2x theme
            if (array_key_exists('theme', $this->args) && array_key_exists($this->args['theme'], self::$themes))
            {
                $themeinfo = self::$themes[$this->args['theme']];
                $themeclass = $themeinfo['class'];

                $renderer = new RokNavMenu2XRenderer();

                $theme = new $themeclass();
                $renderer->setTheme($theme);
            }
            else
            {
                // its a 1x theme
                $renderer = new RokNavMenu1XRenderer();
            }
            return $renderer;
        }

        public function render()
        {
            $this->renderHeader();
            return $this->renderMenu();
        }

        public static function registerTheme($path, $name, $fullname, $themeClass)
        {
            $theme = array('name' => $name, 'fullname' => $fullname, 'path' => $path, 'class' => $themeClass);
            self::$themes[$name] = $theme;
        }

        public static function loadCatalogs()
        {
            if (!self::$catalogs_loaded) {
                // load the module themes catalog
                require_once(JPATH_ROOT . '/modules/mod_roknavmenu/themes/catalog.php');

                foreach (self::getTemplates() as $template) {
                    $template_theme_catalog = JPATH_ROOT . '/templates/' . $template . "/html/mod_roknavmenu/themes/catalog.php";
                    if (JFile::exists($template_theme_catalog)) {
                        //load the templates themes
                        include_once($template_theme_catalog);
                    }
                }
                self::$catalogs_loaded = true;
            }
        }

        protected static function getTemplates()
        {
            $Itemid = JRequest::getInt('Itemid');
        	        	
        	// Load specific style if one is assigned
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select('ts.template');
            $query->from('#__template_styles AS ts');
            $query->join('INNER','#__menu AS m ON ts.id=m.template_style_id');
            $query->where('m.id = '.$Itemid);
			$query->where('m.template_style_id != 0');
            
			$db->setQuery($query);
            $templates = $db->loadResultArray();
        	
	        if ($templates){
	        	return $templates;
	        }
	        	
            // Load styles normally if no specific style is assigned
            $query = $db->getQuery(true);
            $query->select('template');
            $query->from('#__template_styles');
            $query->where('home = 1');
            $query->where('client_id = 0');

            $db->setQuery($query);
            $templates = $db->loadResultArray();
            return $templates;
        }

        /**
         * Load published modules
         *
         * @return	array
         */
        public static function &loadModules()
        {
            static $clean;

            if (isset($clean)) {
                return $clean;
            }

            $Itemid 	= JRequest::getInt('Itemid');
            $app		= JFactory::getApplication();
            $user		= JFactory::getUser();
            $groups		= implode(',', $user->getAuthorisedViewLevels());
            $lang 		= JFactory::getLanguage()->getTag();
            $clientId 	= (int) $app->getClientId();

            $cache 		= JFactory::getCache ('com_modules', '');
            $cacheid 	= md5(serialize(array($Itemid, $groups, $clientId, $lang)));

            if (!($clean = $cache->get($cacheid))) {
                $db	= JFactory::getDbo();

                $query = $db->getQuery(true);
                $query->select('id, title, module, position, content, showtitle, params, mm.menuid');
                $query->from('#__modules AS m');
                $query->join('LEFT','#__modules_menu AS mm ON mm.moduleid = m.id');
                $query->where('m.published = 1');

                $date = JFactory::getDate();
                $now = $date->toMySQL();
                $nullDate = $db->getNullDate();
                $query->where('(m.publish_up = '.$db->Quote($nullDate).' OR m.publish_up <= '.$db->Quote($now).')');
                $query->where('(m.publish_down = '.$db->Quote($nullDate).' OR m.publish_down >= '.$db->Quote($now).')');

                $query->where('m.access IN ('.$groups.')');
                $query->where('m.client_id = '. $clientId);
                $query->where('(mm.menuid = '. (int) $Itemid .' OR mm.menuid <= 0)');

                // Filter by language
                if ($app->isSite() && $app->getLanguageFilter()) {
                    $query->where('m.language IN (' . $db->Quote($lang) . ',' . $db->Quote('*') . ')');
                }

                $query->order('position, ordering');

                // Set the query
                $db->setQuery($query);
                $modules = $db->loadObjectList();
                $clean	= array();

                if($db->getErrorNum()){
                    JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $db->getErrorMsg()));
                    return $clean;
                }

                // Apply negative selections and eliminate duplicates
                $negId	= $Itemid ? -(int)$Itemid : false;
                $dupes	= array();
                for ($i = 0, $n = count($modules); $i < $n; $i++)
                {
                    $module = &$modules[$i];

                    // The module is excluded if there is an explicit prohibition, or if
                    // the Itemid is missing or zero and the module is in exclude mode.
                    $negHit	= ($negId === (int) $module->menuid)
                            || (!$negId && (int)$module->menuid < 0);

                    if (isset($dupes[$module->id]))
                    {
                        // If this item has been excluded, keep the duplicate flag set,
                        // but remove any item from the cleaned array.
                        if ($negHit) {
                            unset($clean[$module->id]);
                        }
                        continue;
                    }
                    $dupes[$module->id] = true;

                    // Only accept modules without explicit exclusions.
                    if (!$negHit)
                    {
                        //determine if this is a custom module
                        $file				= $module->module;
                        $custom				= substr($file, 0, 4) == 'mod_' ?  0 : 1;
                        $module->user		= $custom;
                        // Custom module name is given by the title field, otherwise strip off "com_"
                        $module->name		= $custom ? $module->title : substr($file, 4);
                        $module->style		= null;
                        $module->position	= strtolower($module->position);
                        $clean[$module->id]	= $module;
                    }
                }
                unset($dupes);
                // Return to simple indexing that matches the query order.
                $clean = array_values($clean);

                $cache->store($clean, $cacheid);
            }

            return $clean;
        }
    }


}
Back to Top