/** * Load the installed components into the components property. * * @param string $option The element value for the extension * @param boolean $strict If set and the component does not exist, the enabled attribute will be set to false. * @return object */ public function load($option, $strict = false) { $option = $this->canonical($option); if (isset(self::$components[$option])) { return self::$components[$option]; } $db = $this->app->get('db'); $query = $db->getQuery(true); $query->select('extension_id AS id, element AS "option", params, enabled'); $query->from('#__extensions'); $query->where($query->qn('type') . ' = ' . $db->quote('component')); $query->where($query->qn('element') . ' = ' . $db->quote($option)); $db->setQuery($query); if (!$this->app->has('cache.store') || !($cache = $this->app['cache.store'])) { $cache = new \Hubzero\Cache\Storage\None(); } if (!($data = $cache->get('_system.' . $option))) { $data = $db->loadObject(); $cache->put('_system.' . $option, $data, $this->app['config']->get('cachetime', 15)); } self::$components[$option] = $data; if ($error = $db->getErrorMsg()) { throw new Exception($this->app['language']->translate('JLIB_APPLICATION_ERROR_COMPONENT_NOT_LOADING', $option, $error), 500); } if (empty(self::$components[$option])) { self::$components[$option] = new stdClass(); self::$components[$option]->option = $option; self::$components[$option]->enabled = $strict ? 0 : 1; self::$components[$option]->params = ''; self::$components[$option]->id = 0; } // Convert the params to an object. if (is_string(self::$components[$option]->params)) { self::$components[$option]->params = new Registry(self::$components[$option]->params); } return self::$components[$option]; }
/** * Loads the published plugins. * * @return array An array of published plugins */ public function all() { if (self::$plugins !== null) { return self::$plugins; } if (!\App::has('cache.store') || !($cache = \App::get('cache.store'))) { $cache = new \Hubzero\Cache\Storage\None(); } $levels = implode(',', User::getAuthorisedViewLevels()); if (!(self::$plugins = $cache->get('com_plugins.' . $levels))) { $db = \App::get('db'); $query = $db->getQuery(true); $query->select('folder AS type, element AS name, protected, params')->from('#__extensions')->where('enabled >= 1')->where('type =' . $db->quote('plugin'))->where('state >= 0')->where('access IN (' . $levels . ')')->order('ordering'); self::$plugins = $db->setQuery($query)->loadObjectList(); if ($error = $db->getErrorMsg()) { throw new Exception($error, 500); } $cache->put('com_plugins.' . $levels, self::$plugins, \App::get('config')->get('cachetime', 15)); } return self::$plugins; }
/** * Get the site template * * @return object */ public function getSiteTemplate() { // Get the id of the active menu item $menu = $this->app['menu']; $item = $menu->getActive(); if (!$item) { $item = $menu->getItem($this->app['request']->getInt('Itemid', 0)); } $id = 0; if (is_object($item)) { // valid item retrieved $id = $item->template_style_id; } $condition = ''; $tid = $this->app['request']->getVar('templateStyle', 0); if (is_numeric($tid) && (int) $tid > 0) { $id = (int) $tid; } if (!$this->app->has('cache.store') || !($cache = $this->app['cache.store'])) { $cache = new \Hubzero\Cache\Storage\None(); } $tag = ''; if ($this->app->has('language.filter')) { $tag = $this->app['language']->getTag(); } if (!($templates = $cache->get('com_templates.templates0' . $tag))) { // Load styles try { $db = \App::get('db'); $query = $db->getQuery(true); $query->select('s.id, s.home, s.template, s.params, e.protected'); $query->from('#__template_styles as s'); $query->where('s.client_id = 0'); $query->where('e.enabled = 1'); $query->leftJoin('#__extensions as e ON e.element=s.template AND e.type=' . $db->quote('template') . ' AND e.client_id=s.client_id'); $db->setQuery($query); $templates = $db->loadObjectList('id'); foreach ($templates as &$template) { if (!$template->params instanceof Registry) { $registry = new Registry($template->params); $template->params = $registry; } // Create home element if ($template->home == 1 && !isset($templates[0])) { $templates[0] = clone $template; } } $cache->put('com_templates.templates0' . $tag, $templates, $this->app['config']->get('cachetime', 15)); } catch (Exception $e) { return $this->getSystemTemplate(); } } if (isset($templates[$id])) { $template = $templates[$id]; } else { // [!] zooley - Fixing template fallback to always load system template if current one is not found. // Previous way could cause code to get stuck in a loop and run out of memory. if (isset($templates[0])) { $template = $templates[0]; } else { $template = new stdClass(); $template->params = new Registry(); $template->home = 0; } $template->id = 0; $template->template = 'system'; $template->protected = 1; } // Allows for overriding the active template from the request //$template->template = $this->app['request']->getCmd('template', $template->template); $template->template = $this->canonical($template->template); // need to filter the default value as well // Fallback template foreach ($this->paths as $path) { if (file_exists($path . DS . $template->template . DS . 'index.php')) { $template->path = $path . DS . $template->template; return $template; } } return $this->getSystemTemplate(); }
/** * Get a list of templates for the specified client * * @param integer $client_id * @param integer $id * @return object */ public function getTemplate($client_id = 0, $id = 0) { if (!$this->app->has('cache.store') || !($cache = $this->app['cache.store'])) { $cache = new \Hubzero\Cache\Storage\None(); } $templates = $cache->get('com_templates.templates' . $client_id . $this->lang); if (!$templates || empty($templates)) { try { $db = $this->app['db']; $s = '#__template_styles'; $e = '#__extensions'; $query = new Query($db); $query->select($s . '.id')->select($s . '.home')->select($s . '.template')->select($s . '.params')->select($e . '.protected')->from($s)->join($e, $e . '.element', $s . '.template')->whereEquals($s . '.client_id', (int) $client_id)->whereEquals($e . '.enabled', 1)->whereEquals($e . '.type', 'template')->whereRaw($e . '.`client_id` = `' . $s . '`.`client_id`'); if ($id) { $query->whereEquals($s . '.id', $id); } $query->order('home', 'desc'); $db->setQuery($query->toString()); $templates = $db->loadObjectList('id'); foreach ($templates as $i => $template) { $template->params = new Registry($template->params); $template->path = $this->determinePath($template->protected) . DIRECTORY_SEPARATOR . $template->template; $templates[$i] = $template; // Create home element if ($template->home && !isset($templates[0])) { $templates[0] = clone $template; } } $cache->put('com_templates.templates' . $client_id . $this->lang, $templates, $this->app['config']->get('cachetime', 15)); } catch (Exception $e) { $templates = array(); } } $tmpl = null; if (isset($templates[$id])) { $tmpl = $templates[$id]; } else { if (isset($templates[0])) { $tmpl = $templates[0]; } } if ($tmpl && file_exists($tmpl->path . DIRECTORY_SEPARATOR . 'index.php')) { return $tmpl; } return $this->getSystemTemplate(); }