/** * Re-route Gantry templates to Gantry Administration component. */ public function onAfterRoute() { if ($this->app->isSite()) { $this->onAfterRouteSite(); } elseif ($this->app->isAdmin()) { $this->onAfterRouteAdmin(); } }
/** * Listener for onAfterInitialise event * * @return void */ public function onAfterInitialise() { // Only for site if (!$this->app->isSite()) { return; } // Register listeners for JHtml helpers if (!JHtml::isRegistered('bootstrap.loadCss')) { JHtml::register('bootstrap.loadCss', 'PlgSystemBootstrap3::loadCss'); } if (!JHtml::isRegistered('bootstrap.carousel')) { JHtml::register('bootstrap.carousel', 'PlgSystemBootstrap3::carousel'); } }
/** * This method should handle any logout logic and report back to the subject * * @param array $user Holds the user data. * @param array $options Array holding options (client, ...). * * @return object True on success * * @since 1.5 */ public function onUserLogout($user, $options = array()) { $my = JFactory::getUser(); $session = JFactory::getSession(); // Make sure we're a valid user first if ($user['id'] == 0 && !$my->get('tmp_user')) { return true; } // Check to see if we're deleting the current session if ($my->get('id') == $user['id'] && $options['clientid'] == $this->app->getClientId()) { // Hit the user last visit field $my->setLastVisit(); // Destroy the php session for this user $session->destroy(); } // Enable / Disable Forcing logout all users with same userid $forceLogout = $this->params->get('forceLogout', 1); if ($forceLogout) { $query = $this->db->getQuery(true)->delete($this->db->quoteName('#__session'))->where($this->db->quoteName('userid') . ' = ' . (int) $user['id'])->where($this->db->quoteName('client_id') . ' = ' . (int) $options['clientid']); try { $this->db->setQuery($query)->execute(); } catch (RuntimeException $e) { return false; } } // Delete "user state" cookie used for reverse caching proxies like Varnish, Nginx etc. $conf = JFactory::getConfig(); $cookie_domain = $conf->get('cookie_domain', ''); $cookie_path = $conf->get('cookie_path', '/'); if ($this->app->isSite()) { $this->app->input->cookie->set("joomla_user_state", "", time() - 86400, $cookie_path, $cookie_domain, 0); } return true; }
/** * System render. * * @return void */ public function onAfterRender() { $this->getFunction('includes.insertHeader'); $this->getFunction('includes.setStyle'); if ($this->params->get('cacheManagerEnabled', 0) && $this->app->isSite()) { $this->getFunction('system.cacheManager'); } @(include $this->includeEvent(__FUNCTION__)); }
/** * Get menu item by id * * @param string $language The language code. * * @return mixed The item object or null when not found for given language * * @since 1.6 */ public function getDefault($language = '*') { if (array_key_exists($language, $this->_default) && $this->app->isSite() && $this->app->getLanguageFilter()) { return $this->_items[$this->_default[$language]]; } if (array_key_exists('*', $this->_default)) { return $this->_items[$this->_default['*']]; } return null; }
/** * onAfterRender * * @return void */ public function onAfterRender() { $this->call(array('Article\\CodeInsert', 'insertHeader')); $this->call(array('Asset\\Style', 'register')); if ($this->app->get('caching', 0)) { $this->call(array('System\\Cache', 'cacheEzsetData'), $this); } if ($this->params->get('cacheManagerEnabled', 0) && $this->app->isSite()) { $this->call(array('System\\Cache', 'manage')); } @(include $this->includeEvent(__FUNCTION__)); }
/** * Method to add alternative meta tags for associated menu items. * * @return void * * @since 1.7 */ public function onAfterDispatch() { $doc = JFactory::getDocument(); if ($this->app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') { $languages = $this->lang_codes; $homes = JLanguageMultilang::getSiteHomePages(); $menu = $this->app->getMenu(); $active = $menu->getActive(); $levels = JFactory::getUser()->getAuthorisedViewLevels(); $remove_default_prefix = $this->params->get('remove_default_prefix', 0); $server = JUri::getInstance()->toString(array('scheme', 'host', 'port')); $is_home = false; if ($active) { $active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false); $current_link = JUri::getInstance()->toString(array('path', 'query')); // Load menu associations if ($active_link == $current_link) { $associations = MenusHelper::getAssociations($active->id); } // Check if we are on the homepage $is_home = $active->home && ($active_link == $current_link || $active_link == $current_link . 'index.php' || $active_link . '/' == $current_link); } // Load component associations. $option = $this->app->input->get('option'); $cName = JString::ucfirst(JString::str_ireplace('com_', '', $option)) . 'HelperAssociation'; JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php')); if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) { $cassociations = call_user_func(array($cName, 'getAssociations')); } // For each language... foreach ($languages as $i => &$language) { switch (true) { // Language without frontend UI || Language without specific home menu || Language without authorized access level case !array_key_exists($i, JLanguageMultilang::getSiteLangs()): case !isset($homes[$i]): case isset($language->access) && $language->access && !in_array($language->access, $levels): unset($languages[$i]); break; // Home page // Home page case $is_home: $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $homes[$i]->id); break; // Current language link // Current language link case $i == $this->current_lang: $language->link = JUri::getInstance()->toString(array('path', 'query')); break; // Component association // Component association case isset($cassociations[$i]): $language->link = JRoute::_($cassociations[$i] . '&lang=' . $language->sef); break; // Menu items association // Heads up! "$item = $menu" here below is an assignment, *NOT* comparison // Menu items association // Heads up! "$item = $menu" here below is an assignment, *NOT* comparison case isset($associations[$i]) && ($item = $menu->getItem($associations[$i])): $language->link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef); break; // Too bad... // Too bad... default: unset($languages[$i]); } } // If there are at least 2 of them, add the rel="alternate" links to the <head> if (count($languages) > 1) { // Remove the sef from the default language if "Remove URL Language Code" is on if (isset($languages[$this->default_lang]) && $remove_default_prefix) { $languages[$this->default_lang]->link = preg_replace('|/' . $languages[$this->default_lang]->sef . '/|', '/', $languages[$this->default_lang]->link, 1); } foreach ($languages as $i => &$language) { $doc->addHeadLink($server . $language->link, 'alternate', 'rel', array('hreflang' => $i)); } // Add x-default language tag if ($this->params->get('xdefault', 1)) { $xdefault_language = $this->params->get('xdefault_language', $this->default_lang); $xdefault_language = $xdefault_language == 'default' ? $this->default_lang : $xdefault_language; if (isset($languages[$xdefault_language])) { // Use a custom tag because addHeadLink is limited to one URI per tag $doc->addCustomTag('<link href="' . $server . $languages[$xdefault_language]->link . '" rel="alternate" hreflang="x-default" />'); } } } } }
/** * Method to add alternative meta tags for associated menu items. * * @return void * * @since 1.7 */ public function onAfterDispatch() { $doc = JFactory::getDocument(); $menu = $this->app->getMenu(); $server = JUri::getInstance()->toString(array('scheme', 'host', 'port')); $option = $this->app->input->get('option'); $eName = JString::ucfirst(JString::str_ireplace('com_', '', $option)); if ($this->app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') { // Get active menu item. $active = $menu->getActive(); $assocs = array(); $home = false; // Load menu associations. if ($active) { $active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false); // Get current link. $current_link = JUri::getInstance()->toString(array('path', 'query')); // Check the exact menu item's URL. if ($active_link == $current_link) { $associations = MenusHelper::getAssociations($active->id); unset($associations[$active->language]); $assocs = array_keys($associations); // If the menu item is a home menu item and the URLs are identical, we are on the homepage $home = true; } } // Load component associations. $cName = JString::ucfirst($eName . 'HelperAssociation'); JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php')); if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) { $cassociations = call_user_func(array($cName, 'getAssociations')); $lang_code = $this->app->input->cookie->getString(JApplicationHelper::getHash('language')); // No cookie - let's try to detect browser language or use site default. if (!$lang_code) { if ($this->params->get('detect_browser', 1)) { $lang_code = JLanguageHelper::detectLanguage(); } else { $lang_code = $this->default_lang; } } unset($cassociations[$lang_code]); $assocs = array_merge(array_keys($cassociations), $assocs); } // Handle the default associations. if ($this->params->get('item_associations') || $active && $active->home && $home) { $languages = JLanguageHelper::getLanguages('lang_code'); foreach ($assocs as $language) { if (!JLanguage::exists($language)) { continue; } $lang = $languages[$language]; if (isset($cassociations[$language])) { $link = JRoute::_($cassociations[$language] . '&lang=' . $lang->sef); // Check if language is the default site language and remove url language code is on if ($lang->sef == $this->lang_codes[$this->default_lang]->sef && $this->params->get('remove_default_prefix') == '1') { $link = preg_replace('|/' . $lang->sef . '/|', '/', $link, 1); } $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language)); } elseif (isset($associations[$language])) { $item = $menu->getItem($associations[$language]); if ($item) { $link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $lang->sef); $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language)); } } } } } }
/** * Convert the site URL to fit to the HTTP request. * * @return void */ public function onAfterRender() { if (!$this->app->isSite() || $this->app->get('sef', '0') == '0') { return; } // Replace src links. $base = JUri::base(true) . '/'; $buffer = $this->app->getBody(); // Replace index.php URI by SEF URI. if (strpos($buffer, 'href="index.php?') !== false) { preg_match_all('#href="index.php\\?([^"]+)"#m', $buffer, $matches); foreach ($matches[1] as $urlQueryString) { $buffer = str_replace('href="index.php?' . $urlQueryString . '"', 'href="' . JRoute::_('index.php?' . $urlQueryString) . '"', $buffer); } $this->checkBuffer($buffer); } // Check for all unknown protocals (a protocol must contain at least one alpahnumeric character followed by a ":"). $protocols = '[a-zA-Z0-9\\-]+:'; $attributes = array('href=', 'src=', 'poster='); foreach ($attributes as $attribute) { if (strpos($buffer, $attribute) !== false) { $regex = '#\\s+' . $attribute . '"(?!/|' . $protocols . '|\\#|\')([^"]*)"#m'; $buffer = preg_replace($regex, ' ' . $attribute . '"' . $base . '$1"', $buffer); $this->checkBuffer($buffer); } } // Replace all unknown protocals in javascript window open events. if (strpos($buffer, 'window.open(') !== false) { $regex = '#onclick="window.open\\(\'(?!/|' . $protocols . '|\\#)([^/]+[^\']*?\')#m'; $buffer = preg_replace($regex, 'onclick="window.open(\'' . $base . '$1', $buffer); $this->checkBuffer($buffer); } // Replace all unknown protocols in onmouseover and onmouseout attributes. $attributes = array('onmouseover=', 'onmouseout='); foreach ($attributes as $attribute) { if (strpos($buffer, $attribute) !== false) { $regex = '#' . $attribute . '"this.src=([\']+)(?!/|' . $protocols . '|\\#|\')([^"]+)"#m'; $buffer = preg_replace($regex, $attribute . '"this.src=$1' . $base . '$2"', $buffer); $this->checkBuffer($buffer); } } // Replace all unknown protocols in CSS background image. if (strpos($buffer, 'style=') !== false) { $regex = '#style=\\s*[\'\\"](.*):\\s*url\\s*\\([\'\\"]?(?!/|' . $protocols . '|\\#)([^\\)\'\\"]+)[\'\\"]?\\)#m'; $buffer = preg_replace($regex, 'style="$1: url(\'' . $base . '$2$3\')', $buffer); $this->checkBuffer($buffer); } // Replace all unknown protocols in OBJECT param tag. if (strpos($buffer, '<param') !== false) { // OBJECT <param name="xx", value="yy"> -- fix it only inside the <param> tag. $regex = '#(<param\\s+)name\\s*=\\s*"(movie|src|url)"[^>]\\s*value\\s*=\\s*"(?!/|' . $protocols . '|\\#|\')([^"]*)"#m'; $buffer = preg_replace($regex, '$1name="$2" value="' . $base . '$3"', $buffer); $this->checkBuffer($buffer); // OBJECT <param value="xx", name="yy"> -- fix it only inside the <param> tag. $regex = '#(<param\\s+[^>]*)value\\s*=\\s*"(?!/|' . $protocols . '|\\#|\')([^"]*)"\\s*name\\s*=\\s*"(movie|src|url)"#m'; $buffer = preg_replace($regex, '<param value="' . $base . '$2" name="$3"', $buffer); $this->checkBuffer($buffer); } // Replace all unknown protocols in OBJECT tag. if (strpos($buffer, '<object') !== false) { $regex = '#(<object\\s+[^>]*)data\\s*=\\s*"(?!/|' . $protocols . '|\\#|\')([^"]*)"#m'; $buffer = preg_replace($regex, '$1data="' . $base . '$2"', $buffer); $this->checkBuffer($buffer); } // Use the replaced HTML body. $this->app->setBody($buffer); }