Example #1
0
 /**
  * Initialise the application.
  *
  * @param	array	An optional associative array of configuration settings.
  */
 function initialise($options = array())
 {
     $config =& JFactory::getConfig();
     // if a language was specified it has priority
     // otherwise use user or default language settings
     if (empty($options['language'])) {
         $user =& JFactory::getUser();
         $lang = $user->getParam('admin_language');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         } else {
             $params = JComponentHelper::getParams('com_languages');
             $client =& JApplicationHelper::getClientInfo($this->getClientId());
             $options['language'] = $params->get($client->name, $config->getValue('config.language', 'en-GB'));
         }
     }
     // One last check to make sure we have something
     if (!JLanguage::exists($options['language'])) {
         $lang = $config->getValue('config.language', 'en-GB');
         if (JLanguage::exists($lang)) {
             $options['language'] = $lang;
         } else {
             $options['language'] = 'en-GB';
             // as a last ditch fail to english
         }
     }
     parent::initialise($options);
 }
 /**
  * Test...
  *
  * @covers JLanguage::exists
  * @todo Implement testExists().
  *
  * @return void
  */
 public function testExists()
 {
     $this->assertFalse($this->object->exists(null));
     $basePath = __DIR__ . '/data';
     $this->assertTrue($this->object->exists('en-GB', $basePath));
     $this->assertFalse($this->object->exists('es-ES', $basePath));
 }
Example #3
0
File: helper.php Project: akksi/jcg
 public static function getList(&$params)
 {
     $lang = JFactory::getLanguage();
     $languages = JLanguageHelper::getLanguages();
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $query = $db->getQuery(true);
     $query->select('id');
     $query->select('language');
     $query->from($db->nameQuote('#__menu'));
     $query->where('home=1');
     $db->setQuery($query);
     $homes = $db->loadObjectList('language');
     foreach ($languages as $i => &$language) {
         // Do not display language without frontend UI
         if (!JLanguage::exists($language->lang_code)) {
             unset($languages[$i]);
         } elseif (!isset($homes[$language->lang_code])) {
             unset($languages[$i]);
         } else {
             if ($app->getLanguageFilter()) {
                 $language->active = $language->lang_code == $lang->getTag();
                 if ($app->getCfg('sef') == '1') {
                     $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
                     $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
                 } else {
                     $language->link = 'index.php?lang=' . $language->sef;
                 }
             } else {
                 $language->link = 'index.php';
             }
         }
     }
     return $languages;
 }
 /**
  * Initialise the application.
  *
  * @param	array	$options	An optional associative array of configuration settings.
  *
  * @return	void
  * @since	1.5
  */
 public function initialise($options = array())
 {
     $config = JFactory::getConfig();
     // if a language was specified it has priority
     // otherwise use user or default language settings
     if (empty($options['language'])) {
         $user = JFactory::getUser();
         $lang = $user->getParam('admin_language');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         } else {
             $params = JComponentHelper::getParams('com_languages');
             $client = JApplicationHelper::getClientInfo($this->getClientId());
             $options['language'] = $params->get($client->name, $config->get('language', 'es-LA'));
         }
     }
     // One last check to make sure we have something
     if (!JLanguage::exists($options['language'])) {
         $lang = $config->get('language', 'es-LA');
         if (JLanguage::exists($lang)) {
             $options['language'] = $lang;
         } else {
             $options['language'] = 'es-LA';
             // as a last ditch fail to english
         }
     }
     // Execute the parent initialise method.
     parent::initialise($options);
     // Load Library language
     $lang = JFactory::getLanguage();
     $lang->load('lib_joomla', JPATH_ADMINISTRATOR, null, false, true);
 }
Example #5
0
	/**
	* Initialise the application.
	*
	* @access public
	*/
	function initialise( $options = array())
	{
		// if a language was specified it has priority
		// otherwise use user or default language settings
		if (empty($options['language']))
		{
			$user = & JFactory::getUser();
			$lang	= $user->getParam( 'language' );

			// Make sure that the user's language exists
			if ( $lang && JLanguage::exists($lang) ) {
				$options['language'] = $lang;
			} 
			else 
			{
				$params =  JComponentHelper::getParams('com_extensions');
				$client	=& JApplicationHelper::getClientInfo($this->getClientId());
				$options['language'] = $params->get('language_'.$client->name, 'en-GB');
			}

		}

		// One last check to make sure we have something
		if ( ! JLanguage::exists($options['language']) ) {
			$options['language'] = 'en-GB';
		}

		parent::initialise($options);
	}
 public static function getList(&$params)
 {
     $user = JFactory::getUser();
     $lang = JFactory::getLanguage();
     $app = JFactory::getApplication();
     $menu = $app->getMenu();
     // Get menu home items
     $homes = array();
     foreach ($menu->getMenu() as $item) {
         if ($item->home) {
             $homes[$item->language] = $item;
         }
     }
     // Load associations
     $assoc = isset($app->menu_associations) ? $app->menu_associations : 0;
     if ($assoc) {
         $active = $menu->getActive();
         if ($active) {
             $associations = MenusHelper::getAssociations($active->id);
         }
     }
     $levels = $user->getAuthorisedViewLevels();
     $languages = JLanguageHelper::getLanguages();
     // Filter allowed languages
     foreach ($languages as $i => &$language) {
         // Do not display language without frontend UI
         if (!JLanguage::exists($language->lang_code)) {
             unset($languages[$i]);
         } elseif (!isset($homes[$language->lang_code])) {
             unset($languages[$i]);
         } elseif (isset($language->access) && $language->access && !in_array($language->access, $levels)) {
             unset($languages[$i]);
         } else {
             $language->active = $language->lang_code == $lang->getTag();
             if ($app->getLanguageFilter()) {
                 if (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
                     $itemid = $associations[$language->lang_code];
                     if ($app->getCfg('sef') == '1') {
                         $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
                     } else {
                         $language->link = 'index.php?lang=' . $language->sef . '&Itemid=' . $itemid;
                     }
                 } else {
                     if ($app->getCfg('sef') == '1') {
                         $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
                         $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
                     } else {
                         $language->link = 'index.php?lang=' . $language->sef;
                     }
                 }
             } else {
                 $language->link = JRoute::_('&Itemid=' . $homes['*']->id);
             }
         }
     }
     return $languages;
 }
Example #7
0
 /**
  * Method to initialise the database
  *
  * @param   array  $options  The options to use for configuration
  *
  * @return  boolean
  *
  * @since   3.0
  */
 public function initialise($options)
 {
     // Get the options as a object for easier handling.
     $options = JArrayHelper::toObject($options);
     // Load the back-end language files so that the DB error messages work
     $lang = JFactory::getLanguage();
     $currentLang = $lang->getTag();
     // Load the selected language
     if (JLanguage::exists($currentLang, JPATH_ADMINISTRATOR)) {
         $lang->load('joomla', JPATH_ADMINISTRATOR, $currentLang, true);
     } else {
         $lang->load('joomla', JPATH_ADMINISTRATOR, 'en-GB', true);
     }
     // Ensure a database type was selected.
     if (empty($options->db_type)) {
         $this->setError(JText::_('INSTL_DATABASE_INVALID_TYPE'));
         return false;
     }
     // Ensure that a hostname and user name were input.
     if (empty($options->db_host) || empty($options->db_user)) {
         $this->setError(JText::_('INSTL_DATABASE_INVALID_DB_DETAILS'));
         return false;
     }
     // Ensure that a database name was input.
     if (empty($options->db_name)) {
         $this->setError(JText::_('INSTL_DATABASE_EMPTY_NAME'));
         return false;
     }
     // Validate database table prefix.
     if (!preg_match('#^[a-zA-Z]+[a-zA-Z0-9_]*$#', $options->db_prefix)) {
         $this->setError(JText::_('INSTL_DATABASE_PREFIX_INVALID_CHARS'));
         return false;
     }
     // Validate length of database table prefix.
     if (strlen($options->db_prefix) > 15) {
         $this->setError(JText::_('INSTL_DATABASE_FIX_TOO_LONG'));
         return false;
     }
     // Validate length of database name.
     if (strlen($options->db_name) > 64) {
         $this->setError(JText::_('INSTL_DATABASE_NAME_TOO_LONG'));
         return false;
     }
     // Get a database object.
     try {
         return InstallationHelperDatabase::getDbo($options->db_type, $options->db_host, $options->db_user, $options->db_pass, $options->db_name, $options->db_prefix, $options->db_select);
     } catch (RuntimeException $e) {
         $this->setError(JText::sprintf('INSTL_DATABASE_COULD_NOT_CONNECT', $e->getMessage()));
         return false;
     }
 }
Example #8
0
 public function parseRule(&$router, &$uri)
 {
     $array = array();
     $lang_code = JRequest::getString(JUtility::getHash('language'), null, 'cookie');
     if (!$lang_code) {
         $lang_code = JLanguageHelper::detectLanguage();
     }
     if (self::$mode_sef) {
         $path = $uri->getPath();
         $parts = explode('/', $path);
         $sef = $parts[0];
         if (!isset(self::$sefs[$sef])) {
             $sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
             $uri->setPath($sef . '/' . $path);
             $post = JRequest::get('POST');
             if (JRequest::getMethod() != "POST" || count($post) == 0) {
                 $app = JFactory::getApplication();
                 if ($app->getCfg('sef_rewrite')) {
                     $app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
                 } else {
                     $app->redirect($uri->base() . 'index.php/' . $uri->toString(array('path', 'query', 'fragment')));
                 }
             }
         }
         $lang_code = self::$sefs[$sef]->lang_code;
         if ($lang_code && JLanguage::exists($lang_code)) {
             array_shift($parts);
             $uri->setPath(implode('/', $parts));
         }
     } else {
         $sef = $uri->getVar('lang');
         if (!isset(self::$sefs[$sef])) {
             $sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
             $uri->setVar('lang', $sef);
             $post = JRequest::get('POST');
             if (JRequest::getMethod() != "POST" || count($post) == 0) {
                 $app = JFactory::getApplication();
                 $app->redirect(JURI::base(true) . '/index.php?' . $uri->getQuery());
             }
         }
     }
     $array = array('lang' => $sef);
     return $array;
 }
Example #9
0
 public function parseRule(&$router, &$uri)
 {
     $array = array();
     $lang_code = JRequest::getString(JUtility::getHash('language'), null, 'cookie');
     // 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 = self::$default_sef;
         }
     }
     if (self::$mode_sef) {
         $path = $uri->getPath();
         $parts = explode('/', $path);
         $sef = $parts[0];
         $app = JFactory::getApplication();
         // Redirect only if not in post
         $post = JRequest::get('POST');
         if (JRequest::getMethod() != "POST" || count($post) == 0) {
             if ($this->params->get('remove_default_prefix', 0) == 0) {
                 // redirect if sef does not exists
                 if (!isset(self::$sefs[$sef])) {
                     // Use the current language sef or the default one
                     $sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
                     $uri->setPath($sef . '/' . $path);
                     if ($app->getCfg('sef_rewrite')) {
                         $app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
                     } else {
                         $path = $uri->toString(array('path', 'query', 'fragment'));
                         $app->redirect($uri->base() . 'index.php' . ($path ? '/' . $path : ''));
                     }
                 }
             } else {
                 // redirect if sef does not exists and language is not the default one
                 if (!isset(self::$sefs[$sef]) && $lang_code != self::$default_lang) {
                     $sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
                     $uri->setPath($sef . '/' . $path);
                     if ($app->getCfg('sef_rewrite')) {
                         $app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
                     } else {
                         $path = $uri->toString(array('path', 'query', 'fragment'));
                         $app->redirect($uri->base() . 'index.php' . ($path ? '/' . $path : ''));
                     }
                 } elseif ($sef == self::$default_sef) {
                     array_shift($parts);
                     $uri->setPath(implode('/', $parts));
                     if ($app->getCfg('sef_rewrite')) {
                         $app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
                     } else {
                         $path = $uri->toString(array('path', 'query', 'fragment'));
                         $app->redirect($uri->base() . 'index.php' . ($path ? '/' . $path : ''));
                     }
                 }
             }
         }
         $lang_code = isset(self::$sefs[$sef]) ? self::$sefs[$sef]->lang_code : '';
         if ($lang_code && JLanguage::exists($lang_code)) {
             array_shift($parts);
             $uri->setPath(implode('/', $parts));
         }
     } else {
         $sef = $uri->getVar('lang');
         if (!isset(self::$sefs[$sef])) {
             $sef = isset(self::$lang_codes[$lang_code]) ? self::$lang_codes[$lang_code]->sef : self::$default_sef;
             $uri->setVar('lang', $sef);
             $post = JRequest::get('POST');
             if (JRequest::getMethod() != "POST" || count($post) == 0) {
                 $app = JFactory::getApplication();
                 $app->redirect(JURI::base(true) . '/index.php?' . $uri->getQuery());
             }
         }
     }
     $array = array('lang' => $sef);
     return $array;
 }
 /**
  * Initialise the application.
  *
  * @param   array  $options  An optional associative array of configuration settings.
  *
  * @return  void
  *
  * @since   3.2
  */
 protected function initialiseApp($options = array())
 {
     $user = JFactory::getUser();
     // If the user is a guest we populate it with the guest user group.
     if ($user->guest) {
         $guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
         $user->groups = array($guestUsergroup);
     }
     /*
      * If a language was specified it has priority, otherwise use user or default language settings
      * Check this only if the languagefilter plugin is enabled
      *
      * @TODO - Remove the hardcoded dependency to the languagefilter plugin
      */
     if (JPluginHelper::isEnabled('system', 'languagefilter')) {
         $plugin = JPluginHelper::getPlugin('system', 'languagefilter');
         $pluginParams = new Registry($plugin->params);
         $this->setLanguageFilter(true);
         $this->setDetectBrowser($pluginParams->get('detect_browser', '1') == '1');
     }
     if (empty($options['language'])) {
         // Detect the specified language
         $lang = $this->input->getString('language', null);
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if ($this->getLanguageFilter() && empty($options['language'])) {
         // Detect cookie language
         $lang = $this->input->cookie->get(md5($this->get('secret') . 'language'), null, 'string');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if (empty($options['language'])) {
         // Detect user language
         $lang = $user->getParam('language');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if ($this->getDetectBrowser() && empty($options['language'])) {
         // Detect browser language
         $lang = JLanguageHelper::detectLanguage();
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if (empty($options['language'])) {
         // Detect default language
         $params = JComponentHelper::getParams('com_languages');
         $options['language'] = $params->get('site', $this->get('language', 'en-GB'));
     }
     // One last check to make sure we have something
     if (!JLanguage::exists($options['language'])) {
         $lang = $this->config->get('language', 'en-GB');
         if (JLanguage::exists($lang)) {
             $options['language'] = $lang;
         } else {
             // As a last ditch fail to english
             $options['language'] = 'en-GB';
         }
     }
     // Finish initialisation
     parent::initialiseApp($options);
 }
 /**
  * This method adds alternate meta tags for associated menu items
  *
  * @return	nothing
  * @since	1.7
  */
 public function onAfterDispatch()
 {
     if (App::isSite() && $this->params->get('alternate_meta') && Document::getType() == 'html') {
         // Get active menu item
         $active = App::get('menu')->getActive();
         if (!$active) {
             return;
         }
         // Get menu item link
         if (Config::get('sef')) {
             $active_link = Route::url('index.php?Itemid=' . $active->id, false);
         } else {
             $active_link = Route::url($active->link . '&Itemid=' . $active->id, false);
         }
         if ($active_link == JUri::base(true) . '/') {
             $active_link .= 'index.php';
         }
         // Get current link
         $current_link = Request::getUri();
         if ($current_link == Request::base(true) . '/') {
             $current_link .= 'index.php';
         }
         // Check the exact menu item's URL
         if ($active_link == $current_link) {
             // Get menu item associations
             JLoader::register('MenusHelper', PATH_CORE . '/components/com_menus/admin/helpers/menus.php');
             $associations = MenusHelper::getAssociations($active->id);
             // Remove current menu item
             unset($associations[$active->language]);
             // Associated menu items in other languages
             if ($associations && $this->params->get('menu_associations')) {
                 $menu = App::get('menu');
                 $server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
                 foreach (JLanguageHelper::getLanguages() as $language) {
                     if (isset($associations[$language->lang_code])) {
                         $item = $menu->getItem($associations[$language->lang_code]);
                         if ($item && Lang::exists($language->lang_code)) {
                             if (Config::get('sef')) {
                                 $link = Route::url('index.php?Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef);
                             } else {
                                 $link = Route::url($item->link . '&Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef);
                             }
                             // Check if language is the default site language and remove url language code is on
                             if ($language->sef == self::$default_sef && $this->params->get('remove_default_prefix') == '1') {
                                 $relLink = preg_replace('|/' . $language->sef . '/|', '/', $link, 1);
                                 Document::addHeadLink($server . $relLink, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                             } else {
                                 Document::addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                             }
                         }
                     }
                 }
             } elseif ($active->home) {
                 $menu = App::get('menu');
                 $server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
                 foreach (JLanguageHelper::getLanguages() as $language) {
                     $item = $menu->getDefault($language->lang_code);
                     if ($item && $item->language != $active->language && $item->language != '*' && JLanguage::exists($language->lang_code)) {
                         if (Config::get('sef')) {
                             $link = Route::url('index.php?Itemid=' . $item->id . '&lang=' . $language->sef);
                         } else {
                             $link = Route::url($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
                         }
                         // Check if language is the default site language and remove url language code is on
                         if ($language->sef == self::$default_sef && $this->params->get('remove_default_prefix') == '1') {
                             $relLink = preg_replace('|/' . $language->sef . '/|', '/', $link, 1);
                             Document::addHeadLink($server . $relLink, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                         } else {
                             Document::addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                         }
                     }
                 }
             }
         }
     }
 }
Example #12
0
 /**
  * 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));
                     }
                 }
             }
         }
     }
 }
Example #13
0
	/**
	 * Initialise the application.
	 *
	 * @param	array
	 */
	public function initialise($options = array())
	{
		$config = JFactory::getConfig();

		jimport('joomla.language.helper');

		if (empty($options['language'])) {
			$lang = JRequest::getString('language', null);
			if ($lang && JLanguage::exists($lang)) {
				$options['language'] = $lang;
			}
		}

		if ($this->_language_filter && empty($options['language'])) {
			// Detect cookie language
			jimport('joomla.utilities.utility');
			$lang = JRequest::getString(JUtility::getHash('language'), null ,'cookie');
			// Make sure that the user's language exists
			if ($lang && JLanguage::exists($lang)) {
				$options['language'] = $lang;
			}
		}

		if (empty($options['language'])) {
			// Detect user language
			$lang = JFactory::getUser()->getParam('language');
			// Make sure that the user's language exists
			if ($lang && JLanguage::exists($lang)) {
				$options['language'] = $lang;
			}
		}

		if ($this->_detect_browser && empty($options['language'])) {
			// Detect browser language
			$lang = JLanguageHelper::detectLanguage();
			// Make sure that the user's language exists
			if ($lang && JLanguage::exists($lang)) {
				$options['language'] = $lang;
			}
		}

		if (empty($options['language'])) {
			// Detect default language
			$params =  JComponentHelper::getParams('com_languages');
			$client	= JApplicationHelper::getClientInfo($this->getClientId());
			$options['language'] = $params->get($client->name, $config->get('language', 'en-GB'));
		}

		// One last check to make sure we have something
		if (!JLanguage::exists($options['language'])) {
			$lang = $config->get('language','en-GB');
			if (JLanguage::exists($lang)) {
				$options['language'] = $lang;
			}
			else {
				$options['language'] = 'en-GB'; // as a last ditch fail to english
			}
		}

		// Execute the parent initialise method.
		parent::initialise($options);

		// Load Library language
		$lang = JFactory::getLanguage();
		$lang->load('lib_joomla', JPATH_SITE)
		|| $lang->load('lib_joomla', JPATH_ADMINISTRATOR);

	}
Example #14
0
 /**
  * Envía la invitación a calificar a los clientes
  * @return void
  */
 function sendInvitations()
 {
     $option = JRequest::getCmd('option');
     $params =& JComponentHelper::getParams('com_catalogo_planes');
     $max_attempts = (int) $params->get('cfg_comments_invitation');
     $db =& JFactory::getDBO();
     $query = 'SELECT * FROM #__cp_pending_comments WHERE end_date < CURDATE()';
     // Si se ha definido un máximo de envío de correos, agregar a consulta.
     if ($max_attempts) {
         $max_attempts++;
         $query .= ' AND total_attempts < ' . $max_attempts;
     }
     $db->setQuery($query);
     $result = $db->loadObjectList();
     if (count($result)) {
         $msg = JText::_('CP.COMMENTS_EMAIL_SENT');
         $type = 'message';
         $link = JURI::root() . 'index.php?option=' . $option . '&view=comments&layout=display&id=';
         $lang =& JFactory::getLanguage();
         $languages = array();
         $langparams = JComponentHelper::getParams('com_languages');
         $langTag = $defaultLang = $langparams->get("site");
         // Si el idioma actual no es el idioma por defecto, cargarlo
         if ($langTag != $lang->getTag()) {
             $lang =& JLanguage::getInstance($langTag);
             $lang->load($option);
         }
         $languages[$langTag] = $lang;
         // Preparar envío de correo
         $mailer =& JFactory::getMailer();
         $config =& JFactory::getConfig();
         $sender = array($config->getValue('config.mailfrom'), $config->getValue('config.fromname'));
         $mailer->setSender($sender);
         $mailer->isHTML(true);
         // Enviar correo por cada reserva pendiente
         foreach ($result as $row) {
             $langTag = $row->language;
             // Carga el idioma de la reserva para enviar el correo
             if (isset($languages[$langTag])) {
                 $lang =& $languages[$langTag];
             } else {
                 if (JLanguage::exists($langTag)) {
                     $lang =& JLanguage::getInstance($langTag);
                     $lang->load($option);
                 } else {
                     $lang =& $languages[$defaultLang];
                 }
                 $languages[$langTag] =& $lang;
             }
             //print_r($languages[$langTag]->getTag() . ' ' . $languages[$langTag]->_strings['CP.CLONE']);
             //echo '<br />';
             //print_r(nl2br(sprintf($languages[$langTag]->_strings['CP.COMMENTS_EMAIL_BODY'], $row->contact_name, $row->product_name)));
             $email_link = $link . $row->comment_id . '&lang=' . substr($langTag, 0, 2) . '&key=' . base64_encode($row->product_name);
             $body = nl2br(sprintf($lang->_('CP.COMMENTS_EMAIL_BODY'), $row->contact_name, $row->product_name, JRoute::_($email_link)));
             $subject = sprintf($lang->_('CP.COMMENTS_EMAIL_SUBJECT'), $row->product_name);
             $mailer->setSubject($subject);
             $mailer->ClearAllRecipients();
             $mailer->addRecipient($row->contact_email);
             $mailer->setBody($body);
             $send =& $mailer->Send();
             //echo 'aqui='.$send;die();
             if ($send !== true) {
                 $type = 'error';
                 $msg = JText::_('CP.COMMENTS_EMAIL_ERROR') . '<div class="hiddenerrormessage">' . $send . '</div>';
                 break;
             } else {
                 $query = 'UPDATE #__cp_pending_comments SET total_attempts = total_attempts + 1 WHERE comment_id = ' . $row->comment_id;
                 $db->setQuery($query);
                 $db->query();
             }
         }
     } else {
         $type = 'notice';
         $msg = JText::_('CP.COMMENTS_NO_PENDING_INVITATIONS');
     }
     $this->setRedirect('index.php?option=' . $option . '&view=comments', $msg, $type);
 }
 /**
  * Method to add alternative meta tags for associated menu items.
  *
  * @return  void
  *
  * @since   1.7
  */
 public function onAfterDispatch()
 {
     $app = JFactory::getApplication();
     $doc = JFactory::getDocument();
     $menu = $app->getMenu();
     $server = JUri::getInstance()->toString(array('scheme', 'host', 'port'));
     $option = $app->input->get('option');
     $eName = JString::ucfirst(JString::str_ireplace('com_', '', $option));
     if ($app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') {
         // Get active menu item.
         $active = $menu->getActive();
         // Load menu associations.
         if ($active) {
             // Get menu item link.
             if ($app->get('sef')) {
                 $active_link = JRoute::_('index.php?Itemid=' . $active->id, false);
             } else {
                 $active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false);
             }
             if ($active_link == JUri::base(true) . '/') {
                 $active_link .= 'index.php';
             }
             // Get current link.
             $current_link = JUri::getInstance()->toString(array('path', 'query'));
             if ($current_link == JUri::base(true) . '/') {
                 $current_link .= 'index.php';
             }
             // Check the exact menu item's URL.
             if ($active_link == $current_link) {
                 $associations = MenusHelper::getAssociations($active->id);
                 unset($associations[$active->language]);
             }
         }
         // 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 = $app->input->cookie->getString(JApplication::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 = self::$default_lang;
                 }
             }
             unset($cassociations[$lang_code]);
         }
         // Handle the default associations.
         if ((!empty($associations) || !empty($cassociations)) && $this->params->get('item_associations')) {
             foreach (JLanguageHelper::getLanguages() as $language) {
                 if (!JLanguage::exists($language->lang_code)) {
                     continue;
                 }
                 if (isset($cassociations[$language->lang_code])) {
                     $link = JRoute::_($cassociations[$language->lang_code] . '&lang=' . $language->sef);
                     $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                 } elseif (isset($associations[$language->lang_code])) {
                     $item = $menu->getItem($associations[$language->lang_code]);
                     if ($item) {
                         if ($app->get('sef')) {
                             $link = JRoute::_('index.php?Itemid=' . $item->id . '&lang=' . $language->sef);
                         } else {
                             $link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
                         }
                         $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                     }
                 }
             }
         } elseif ($active && $active->home) {
             foreach (JLanguageHelper::getLanguages() as $language) {
                 if (!JLanguage::exists($language->lang_code)) {
                     continue;
                 }
                 $item = $menu->getDefault($language->lang_code);
                 if ($item && $item->language != $active->language && $item->language != '*') {
                     if ($app->get('sef')) {
                         $link = JRoute::_('index.php?Itemid=' . $item->id . '&lang=' . $language->sef);
                     } else {
                         $link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
                     }
                     $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                 }
             }
         }
     }
 }
Example #16
0
File: helper.php Project: 01J/topm
 /**
  * Gets a list of available languages
  *
  * @param   JRegistry  &$params  module params
  *
  * @return  array
  */
 public static function getList(&$params)
 {
     $user = JFactory::getUser();
     $lang = JFactory::getLanguage();
     $app = JFactory::getApplication();
     $menu = $app->getMenu();
     // Get menu home items
     $homes = array();
     foreach ($menu->getMenu() as $item) {
         if ($item->home) {
             $homes[$item->language] = $item;
         }
     }
     // Load associations
     $assoc = JLanguageAssociations::isEnabled();
     if ($assoc) {
         $active = $menu->getActive();
         if ($active) {
             $associations = MenusHelper::getAssociations($active->id);
         }
         // Load component associations
         $option = $app->input->get('option');
         $eName = JString::ucfirst(JString::str_ireplace('com_', '', $option));
         $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'));
         }
     }
     $levels = $user->getAuthorisedViewLevels();
     $languages = JLanguageHelper::getLanguages();
     // Filter allowed languages
     foreach ($languages as $i => &$language) {
         // Do not display language without frontend UI
         if (!JLanguage::exists($language->lang_code)) {
             unset($languages[$i]);
         } elseif (!isset($homes[$language->lang_code])) {
             unset($languages[$i]);
         } elseif (isset($language->access) && $language->access && !in_array($language->access, $levels)) {
             unset($languages[$i]);
         } else {
             $language->active = $language->lang_code == $lang->getTag();
             if (JLanguageMultilang::isEnabled()) {
                 if (isset($cassociations[$language->lang_code])) {
                     $language->link = JRoute::_($cassociations[$language->lang_code] . '&lang=' . $language->sef);
                 } elseif (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
                     $itemid = $associations[$language->lang_code];
                     if ($app->get('sef') == '1') {
                         $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
                     } else {
                         $language->link = 'index.php?lang=' . $language->sef . '&amp;Itemid=' . $itemid;
                     }
                 } else {
                     if ($app->get('sef') == '1') {
                         $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
                         $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
                     } else {
                         $language->link = 'index.php?lang=' . $language->sef;
                     }
                 }
             } else {
                 $language->link = JRoute::_('&Itemid=' . $homes['*']->id);
             }
         }
     }
     return $languages;
 }
Example #17
0
 /**
  * Initialise the application.
  *
  * @param   array  $options  An optional associative array of configuration settings.
  *
  * @return  void
  *
  * @since   3.2
  */
 protected function initialiseApp($options = array())
 {
     $user = JFactory::getUser();
     // If the user is a guest we populate it with the guest user group.
     if ($user->guest) {
         $guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
         $user->groups = array($guestUsergroup);
     }
     // If a language was specified it has priority, otherwise use user or default language settings
     JPluginHelper::importPlugin('system', 'languagefilter');
     if (empty($options['language'])) {
         // Detect the specified language
         $lang = $this->input->getString('language', null);
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if ($this->_language_filter && empty($options['language'])) {
         // Detect cookie language
         $lang = $this->input->cookie->get(md5($this->get('secret') . 'language'), null, 'string');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if (empty($options['language'])) {
         // Detect user language
         $lang = $user->getParam('language');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if ($this->_detect_browser && empty($options['language'])) {
         // Detect browser language
         $lang = JLanguageHelper::detectLanguage();
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if (empty($options['language'])) {
         // Detect default language
         $params = JComponentHelper::getParams('com_languages');
         $options['language'] = $params->get('site', $this->get('language', 'en-GB'));
     }
     // One last check to make sure we have something
     if (!JLanguage::exists($options['language'])) {
         $lang = $this->config->get('language', 'en-GB');
         if (JLanguage::exists($lang)) {
             $options['language'] = $lang;
         } else {
             // As a last ditch fail to english
             $options['language'] = 'en-GB';
         }
     }
     // Finish initialisation
     parent::initialiseApp($options);
     /*
      * Try the lib_joomla file in the current language (without allowing the loading of the file in the default language)
      * Fallback to the default language if necessary
      */
     $this->getLanguage()->load('lib_joomla', JPATH_SITE, null, false, true) || $this->getLanguage()->load('lib_joomla', JPATH_ADMINISTRATOR, null, false, true);
 }
Example #18
0
 /**
  * @return array
  */
 public function getLanguages()
 {
     $languages = JLanguageHelper::getLanguages();
     foreach ($languages as $i => &$language) {
         if (!JLanguage::exists($language->lang_code)) {
             unset($languages[$i]);
             continue;
         }
     }
     return $languages;
 }
Example #19
0
	/**
	 * Get language data
	 */
	protected static function _buildLanguageLookup()
	{
		if( self::$lang_lookup !== null ) return;
		
		// Create map of: item language code to SEF URL language code
		// We don't use helper function so that we also get non-published ones
		$db = JFactory::getDbo();
		$query = $db->getQuery(true)
			->select('a.sef AS sef')
			->select('a.lang_code AS lang_code')
			->from('#__languages AS a');

		$db->setQuery($query);
		$langs = $db->loadObjectList();
		foreach ($langs as $lang)
		{
			self::$lang_lookup[$lang->lang_code] = $lang->sef;
		}
		
		// Get configuration whether to remove SEF language code from URL
		$plugin = JPluginHelper::getPlugin('system', 'languagefilter');
		if (!empty($plugin)) {
			$pluginParams = FLEXI_J16GE ? new JRegistry($plugin->params) : new JParameter($plugin->params);
			self::$add_url_lang = ! $pluginParams->get('remove_default_prefix', 0);
		} else {
			self::$add_url_lang = 1;
		}
		
		// No need to do more work since we will not add language code to the URLs
		if ( !self::$add_url_lang ) return;
		
		// Get user's access levels
		$user	= JFactory::getUser();
		$levels = JAccess::getAuthorisedViewLevels($user->id);
		
		// Get home page menu items according to language, and 
		$menus = JFactory::getApplication()->getMenu('site', array());
		
		// Get content languages and filter them to include only inteface languages
		$content_langs = JLanguageHelper::getLanguages();
		$interface_langs = array();
		
		foreach ($content_langs as $i => &$language)
		{
			// Do not display language without frontend UI
			if (!JLanguage::exists($language->lang_code))
				continue;
			
			// Do not display language without specific home menu
			elseif (!$menus->getDefault($language->lang_code))
				continue;
			
			// Do not display language without authorized access level
			elseif (isset($language->access) && $language->access && !in_array($language->access, $levels))
				continue;
			
			self::$interface_langs[$language->lang_code] = $language;
		}
		// DEBUG print the filtered languages
		//foreach (self::$interface_langs as $lang_code => $lang) echo $lang->title.'['.$lang_code.']'."<br/>\n";
	}
Example #20
0
 /**
  * Initialise the application.
  *
  * @param   array  $options  An optional associative array of configuration settings.
  *
  * @return  void
  *
  * @since   3.2
  */
 protected function initialiseApp($options = array())
 {
     $user = JFactory::getUser();
     // If the user is a guest we populate it with the guest user group.
     if ($user->guest) {
         $guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
         $user->groups = array($guestUsergroup);
     }
     if (empty($options['language'])) {
         // Detect the specified language
         $lang = $this->input->getString('language', null);
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if ($this->getLanguageFilter() && empty($options['language'])) {
         // Detect cookie language
         $lang = $this->input->cookie->get(md5($this->get('secret') . 'language'), null, 'string');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if (empty($options['language'])) {
         // Detect user language
         $lang = $user->getParam('language');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if ($this->getDetectBrowser() && empty($options['language'])) {
         // Detect browser language
         $lang = JLanguageHelper::detectLanguage();
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if (empty($options['language'])) {
         // Detect default language
         $params = JComponentHelper::getParams('com_languages');
         $options['language'] = $params->get('site', $this->get('language', 'en-GB'));
     }
     // One last check to make sure we have something
     if (!JLanguage::exists($options['language'])) {
         $lang = $this->config->get('language', 'en-GB');
         if (JLanguage::exists($lang)) {
             $options['language'] = $lang;
         } else {
             // As a last ditch fail to english
             $options['language'] = 'en-GB';
         }
     }
     // Finish initialisation
     parent::initialiseApp($options);
 }
Example #21
0
 function determineLanguage($get_lang = null)
 {
     // Set the language for JoomFish
     if (AcesefUtility::JoomFishInstalled()) {
         $registry = JFactory::getConfig();
         // save the default language of the site if needed
         $locale = $registry->get('config.language');
         $GLOBALS['mosConfig_defaultLang'] = $locale;
         $registry->set("config.defaultlang", $locale);
         // Get language from request
         if (!empty($get_lang)) {
             $lang = $get_lang;
         }
         // Try to get language code from JF cookie
         if ($this->AcesefConfig->joomfish_cookie) {
             $jf_cookie = JRequest::getVar('jfcookie', null, 'COOKIE');
             if (isset($jf_cookie['lang'])) {
                 $cookieCode = $jf_cookie['lang'];
             }
         }
         // Try to find language from browser settings
         if ($this->AcesefConfig->joomfish_browser && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && class_exists('JoomFishManager')) {
             $active_iso = array();
             $active_isocountry = array();
             $active_code = array();
             $active_languages = JoomFishManager::getInstance()->getActiveLanguages();
             if (count($active_languages) > 0) {
                 foreach ($active_languages as $a_lang) {
                     $active_iso[] = $a_lang->iso;
                     if (preg_match('/[_-]/i', $a_lang->iso)) {
                         $iso = str_replace('_', '-', $a_lang->iso);
                         $isocountry = explode('-', $iso);
                         $active_isocountry[] = $isocountry[0];
                     }
                     $active_code[] = $a_lang->shortcode;
                 }
                 // figure out which language to use - browser languages are based on ISO codes
                 $browser_lang = explode(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
                 foreach ($browser_lang as $b_lang) {
                     if (in_array($b_lang, $active_iso)) {
                         $client_lang = $b_lang;
                         break;
                     }
                     $short_lang = substr($b_lang, 0, 2);
                     if (in_array($short_lang, $active_isocountry)) {
                         $client_lang = $short_lang;
                         break;
                     }
                     // compare with code
                     if (in_array($short_lang, $active_code)) {
                         $client_lang = $short_lang;
                         break;
                     }
                 }
                 if (!empty($client_lang)) {
                     if (strlen($client_lang) == 2) {
                         $browser_code = self::getLangLongCode($client_lang);
                     } else {
                         $browser_code = $client_lang;
                     }
                 }
             }
         }
         // Check if language is selected
         if (empty($lang)) {
             if (empty($code) || !JLanguage::exists($code)) {
                 if ($this->AcesefConfig->joomfish_main_lang != '0') {
                     $code = self::getLangLongCode($this->AcesefConfig->joomfish_main_lang);
                 }
             }
             // Try to get language code from JF cookie
             if (empty($code) || !JLanguage::exists($code)) {
                 if (isset($cookieCode)) {
                     $code = $cookieCode;
                 }
             }
             // Try to get language from browser if needed
             if (empty($code) || !JLanguage::exists($code)) {
                 if (isset($browser_code)) {
                     $code = $browser_code;
                 }
             }
             // Get language from configuration if needed
             if (empty($code) || !JLanguage::exists($code)) {
                 if ($this->AcesefConfig->joomfish_main_lang != '0') {
                     $code = self::getLangLongCode($this->AcesefConfig->joomfish_main_lang);
                 }
             }
             // Get default language if needed
             if (empty($code) || !JLanguage::exists($code)) {
                 $code = $registry->get('config.language');
             }
         }
         // get language long code if needed
         if (empty($code)) {
             if (empty($lang)) {
                 return;
             }
             $code = self::getLangLongCode($lang);
         }
         if (!empty($code)) {
             // set the site language
             $reset_lang = false;
             if ($code != self::getLangLongCode()) {
                 $language = JFactory::getLanguage();
                 $language->setLanguage($code);
                 $language->load();
                 // set the backward compatible language
                 $back_lang = $language->getBackwardLang();
                 $GLOBALS['mosConfig_lang'] = $back_lang;
                 $registry->set("config.lang", $back_lang);
                 $reset_lang = true;
             }
             // set joomfish language if needed
             if ($reset_lang) {
                 $jf_lang = TableJFLanguage::createByJoomla($code);
                 $registry->set("joomfish.language", $jf_lang);
                 // set some more variables
                 $mainframe = JFactory::getApplication();
                 $registry->set("config.multilingual_support", true);
                 $mainframe->setUserState('application.lang', $jf_lang->code);
                 $registry->set("config.jflang", $jf_lang->code);
                 $registry->set("config.lang_site", $jf_lang->code);
                 $registry->set("config.language", $jf_lang->code);
                 $registry->set("joomfish.language", $jf_lang);
                 // overwrite global config with values from $jf_lang if set to in JoomFish
                 $jf_params = JComponentHelper::getParams("com_joomfish");
                 $overwriteGlobalConfig = $jf_params->get('overwriteGlobalConfig', 0);
                 if ($overwriteGlobalConfig) {
                     // We should overwrite additional global variables based on the language parameter configuration
                     $lang_params = new JParameter($jf_lang->params);
                     $param_array = $lang_params->toArray();
                     foreach ($param_array as $key => $val) {
                         $registry->set("config." . $key, $val);
                         if (defined("_JLEGACY")) {
                             $name = 'mosConfig_' . $key;
                             $GLOBALS[$name] = $val;
                         }
                     }
                 }
                 // set the cookie with language
                 if ($this->AcesefConfig->joomfish_cookie) {
                     setcookie("lang", "", time() - 1800, "/");
                     setcookie("jfcookie", "", time() - 1800, "/");
                     setcookie("jfcookie[lang]", $code, time() + 24 * 3600, '/');
                 }
             }
         }
     }
 }
Example #22
0
 /**
  * Initialise the application.
  *
  * @param   array  $options  An optional associative array of configuration settings.
  *
  * @return  void
  *
  * @since   3.2
  */
 protected function initialiseApp($options = array())
 {
     $user = JFactory::getUser();
     // If the user is a guest we populate it with the guest user group.
     if ($user->guest) {
         $guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
         $user->groups = array($guestUsergroup);
     }
     // If a language was specified it has priority, otherwise use user or default language settings
     if (empty($options['language'])) {
         $lang = $user->getParam('admin_language');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         } else {
             $params = JComponentHelper::getParams('com_languages');
             $options['language'] = $params->get('administrator', $this->get('language', 'en-GB'));
         }
     }
     // One last check to make sure we have something
     if (!JLanguage::exists($options['language'])) {
         $lang = $this->get('language', 'en-GB');
         if (JLanguage::exists($lang)) {
             $options['language'] = $lang;
         } else {
             // As a last ditch fail to english
             $options['language'] = 'en-GB';
         }
     }
     // Finish initialisation
     parent::initialiseApp($options);
     // Load Library language
     $this->getLanguage()->load('lib_joomla', JPATH_ADMINISTRATOR);
 }
Example #23
0
 /**
  * @todo Implement testExists().
  */
 public function testExists()
 {
     // This method checks the existence of a language in a directory
     $l1 = 'en-GB';
     $l2 = 'es-ES';
     $basePath = '../../administrator/';
     $lang = new JLanguage('');
     // In this case, returns TRUE with en-GB
     $this->assertTrue($lang->exists($l1, $basePath));
     $this->assertFalse($lang->exists($l2, $basePath));
 }
Example #24
0
 function _determineLanguage($getLang = null, $redir = false, $useMainLang = false)
 {
     // set the language for JoomFish
     if (SEFTools::JoomFishInstalled()) {
         $sefConfig =& SEFConfig::getConfig();
         $registry =& JFactory::getConfig();
         // Check if the Jfrouter is enabled
         $jfrouterEnabled = JPluginHelper::isEnabled('system', 'jfrouter');
         // save the default language of the site if needed
         if (!$jfrouterEnabled) {
             $locale = $registry->getValue('config.language');
             $GLOBALS['mosConfig_defaultLang'] = $locale;
             $registry->setValue("config.defaultlang", $locale);
         }
         // get instance of JoomFishManager to obtain active language list and config values
         $jfm =& JoomFishManager::getInstance();
         // Get language from request
         if (!empty($getLang)) {
             $lang = $getLang;
         }
         // Try to get language code from JF cookie
         if ($sefConfig->jfLangCookie) {
             $jfCookie = JRequest::getVar('jfcookie', null, 'COOKIE');
             if (isset($jfCookie['lang'])) {
                 $cookieCode = $jfCookie['lang'];
             }
         }
         // Try to find language from browser settings
         if ($sefConfig->jfBrowserLang && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
             $active_iso = array();
             $active_isocountry = array();
             $active_code = array();
             $activeLanguages = $jfm->getActiveLanguages();
             if (count($activeLanguages) > 0) {
                 foreach ($activeLanguages as $alang) {
                     $active_iso[] = $alang->iso;
                     if (preg_match('/[_-]/i', $alang->iso)) {
                         $iso = str_replace('_', '-', $alang->iso);
                         $isocountry = explode('-', $iso);
                         $active_isocountry[] = $isocountry[0];
                     }
                     $active_code[] = $alang->shortcode;
                 }
                 // figure out which language to use - browser languages are based on ISO codes
                 $browserLang = explode(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
                 foreach ($browserLang as $blang) {
                     if (in_array($blang, $active_iso)) {
                         $client_lang = $blang;
                         break;
                     }
                     $shortLang = substr($blang, 0, 2);
                     if (in_array($shortLang, $active_isocountry)) {
                         $client_lang = $shortLang;
                         break;
                     }
                     // compare with code
                     if (in_array($shortLang, $active_code)) {
                         $client_lang = $shortLang;
                         break;
                     }
                 }
                 if (!empty($client_lang)) {
                     if (strlen($client_lang) == 2) {
                         $browserCode = SEFTools::getLangLongCode($client_lang);
                     } else {
                         $browserCode = $client_lang;
                     }
                 }
             }
         }
         if (!$jfrouterEnabled && $redir && $sefConfig->langPlacement != _COM_SEF_LANG_DOMAIN && (isset($cookieCode) || isset($browserCode)) && $sefConfig->mainLanguage != '0') {
             if (isset($cookieCode)) {
                 $sc = SEFTools::getLangCode($cookieCode);
             } else {
                 $sc = SEFTools::getLangCode($browserCode);
             }
             // Check the referer to see if we should redirect
             $shouldRedir = false;
             if (isset($_SERVER['HTTP_REFERER'])) {
                 $refUri = new JURI($_SERVER['HTTP_REFERER']);
                 $uri = JURI::getInstance();
                 $refHost = $refUri->getHost();
                 $host = $uri->getHost();
                 if ($refHost != $host) {
                     $shouldRedir = true;
                 }
             } else {
                 $shouldRedir = true;
             }
             if ($shouldRedir) {
                 if (!empty($lang) && $sc != $lang || empty($lang) && $sc != $sefConfig->mainLanguage) {
                     // Redirect to correct site
                     $mainframe =& JFactory::getApplication();
                     $href = JRoute::_('index.php?lang=' . $sc, false);
                     $mainframe->redirect($href);
                     exit;
                 }
             }
         }
         // Check if language is selected
         if (empty($lang) && !$jfrouterEnabled) {
             // If route and query string are empty, use the main language
             // note: removed  && $redir  - it was not possible to switch language to main language
             // on other page than homepage (let's see if it causes any other problem)
             // note: added $useMainLang - now it should work for both the VM checkout and using
             // main language with component's own router
             if ($useMainLang && (empty($code) || !JLanguage::exists($code))) {
                 if ($sefConfig->mainLanguage != '0') {
                     $code = SEFTools::GetLangLongCode($sefConfig->mainLanguage);
                 }
             }
             // Try to get language code from JF cookie
             if (empty($code) || !JLanguage::exists($code)) {
                 if (isset($cookieCode)) {
                     $code = $cookieCode;
                 }
             }
             // Try to get language from browser if needed
             if (empty($code) || !JLanguage::exists($code)) {
                 if (isset($browserCode)) {
                     $code = $browserCode;
                 }
             }
             // Get language from configuration if needed
             if (empty($code) || !JLanguage::exists($code)) {
                 if ($sefConfig->mainLanguage != '0') {
                     $code = SEFTools::GetLangLongCode($sefConfig->mainLanguage);
                 }
             }
             // Get default language if needed
             if (empty($code) || !JLanguage::exists($code)) {
                 $code = $registry->getValue('config.language');
             }
         }
         // get language long code if needed
         if (empty($code)) {
             if (empty($lang)) {
                 return;
             }
             $code = SEFTools::getLangLongCode($lang);
         }
         if (!empty($code)) {
             $jfrparams = $registry->getValue('jfrouter.params');
             // set the site language
             $resetLang = false;
             if ($code != SEFTools::getLangLongCode()) {
                 if (!$jfrouterEnabled || $jfrouterEnabled && $jfrparams->get('sefordomain', 'sefprefix') == 'sefprefix') {
                     $language =& JFactory::getLanguage();
                     $language->setLanguage($code);
                     $language->load();
                     // set the backward compatible language
                     $backLang = $language->getBackwardLang();
                     $GLOBALS['mosConfig_lang'] = $backLang;
                     $registry->setValue("config.lang", $backLang);
                     $resetLang = true;
                 }
             }
             // set joomfish language if needed
             if ($resetLang || !$jfrouterEnabled) {
                 $jfLang = TableJFLanguage::createByJoomla($code);
                 $registry->setValue("joomfish.language", $jfLang);
                 // set some more variables
                 $mainframe =& JFactory::getApplication();
                 $registry->setValue("config.multilingual_support", true);
                 $mainframe->setUserState('application.lang', $jfLang->code);
                 $registry->setValue("config.jflang", $jfLang->code);
                 $registry->setValue("config.lang_site", $jfLang->code);
                 $registry->setValue("config.language", $jfLang->code);
                 $registry->setValue("joomfish.language", $jfLang);
                 // overwrite global config with values from $jfLang if set to in JoomFish
                 $jfparams = JComponentHelper::getParams("com_joomfish");
                 $overwriteGlobalConfig = $jfparams->get('overwriteGlobalConfig', 0);
                 if ($overwriteGlobalConfig) {
                     // We should overwrite additional global variables based on the language parameter configuration
                     $langParams = new JParameter($jfLang->params);
                     $paramarray = $langParams->toArray();
                     foreach ($paramarray as $key => $val) {
                         $registry->setValue("config." . $key, $val);
                         if (defined("_JLEGACY")) {
                             $name = 'mosConfig_' . $key;
                             $GLOBALS[$name] = $val;
                         }
                     }
                 }
                 // set the cookie with language
                 if (!$jfrouterEnabled && $sefConfig->jfLangCookie || $jfrouterEnabled && $jfrparams->get('enableCookie', 1)) {
                     setcookie("lang", "", time() - 1800, "/");
                     setcookie("jfcookie", "", time() - 1800, "/");
                     setcookie("jfcookie[lang]", $code, time() + 24 * 3600, '/');
                 }
             }
         }
     }
 }
/**
 * Get list of front-end available langauges
 *
 * @return unknown
 */
function shGetFrontEndActiveLanguages() {

  static $shLangs = null;

  if(is_null( $shLangs)) {
    $shLangs = array();
    jimport('joomla.language.helper');
    $languages	= JLanguageHelper::getLanguages();
    foreach($languages as $i => &$language) {
      // Do not display language without frontend UI
      if (!JLanguage::exists($language->lang_code)) {
        unset($languages[$i]);
      }
    }
    foreach($languages as $language) {
      $shLang = new StdClass();
      $shLang->iso = $language->sef;
      if(empty($shLang->iso)) {
        $shLang->iso = substr( $language->lang_code, 0, 2);
      }
      $shLang->code = $language->lang_code;
      $shLangs[] = $shLang;
    }
  }

  return $shLangs;

}
Example #26
0
 /**
  * Initialise the application.
  *
  * @param   array
  */
 public function initialise($options = array())
 {
     $config = JFactory::getConfig();
     $user = JFactory::getUser();
     // If the user is a guest we populate it with the guest user group.
     if ($user->guest) {
         $guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1);
         $user->groups = array($guestUsergroup);
     }
     // if a language was specified it has priority
     // otherwise use user or default language settings
     JPluginHelper::importPlugin('system', 'languagefilter');
     if (empty($options['language'])) {
         $lang = $this->input->getString('language', null);
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if ($this->_language_filter && empty($options['language'])) {
         // Detect cookie language
         $lang = $this->input->getString(self::getHash('language'), null, 'cookie');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if (empty($options['language'])) {
         // Detect user language
         $lang = $user->getParam('language');
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if ($this->_detect_browser && empty($options['language'])) {
         // Detect browser language
         $lang = JLanguageHelper::detectLanguage();
         // Make sure that the user's language exists
         if ($lang && JLanguage::exists($lang)) {
             $options['language'] = $lang;
         }
     }
     if (empty($options['language'])) {
         // Detect default language
         $params = JComponentHelper::getParams('com_languages');
         $client = JApplicationHelper::getClientInfo($this->getClientId());
         $options['language'] = $params->get($client->name, $config->get('language', 'en-GB'));
     }
     // One last check to make sure we have something
     if (!JLanguage::exists($options['language'])) {
         $lang = $config->get('language', 'en-GB');
         if (JLanguage::exists($lang)) {
             $options['language'] = $lang;
         } else {
             $options['language'] = 'en-GB';
             // as a last ditch fail to english
         }
     }
     // Execute the parent initialise method.
     parent::initialise($options);
     // Load Library language
     $lang = JFactory::getLanguage();
     // Try the lib_joomla file in the current language (without allowing the loading of the file in the default language)
     $lang->load('lib_joomla', JPATH_SITE, null, false, false) || $lang->load('lib_joomla', JPATH_ADMINISTRATOR, null, false, false) || $lang->load('lib_joomla', JPATH_SITE, null, true) || $lang->load('lib_joomla', JPATH_ADMINISTRATOR, null, true);
 }
Example #27
0
	public static function getList(&$params)
	{
		$lang = JFactory::getLanguage();
		$languages	= JLanguageHelper::getLanguages();
		$app		= JFactory::getApplication();

        //use to remove default language code in url
        $lang_codes 	= JLanguageHelper::getLanguages('lang_code');
        $default_lang = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
        $default_sef 	= $lang_codes[$default_lang]->sef;

        $sefToolsEnabled = modFaLangHelper::sefToolEnabled();


        $menu = $app->getMenu();
        $active = $menu->getActive();
        $uri = JURI::getInstance();


        // Get menu home items
        $homes = array();

        foreach ($menu->getMenu() as $item)
        {
            if ($item->home)
            {
                $homes[$item->language] = $item;
            }
        }


        if (FALANG_J30) {
            //since 3.2
            if (version_compare(JVERSION, '3.2', 'ge')) {
                $assoc =  JLanguageAssociations::isEnabled();
            } else {
                $assoc = isset($app->item_associations) ? (boolean) $app->item_associations : false;
            }
        } else {
            $assoc = (boolean) $app->get('menu_associations', true);
        }


		if ($assoc) {
			if ($active) {
				$associations = MenusHelper::getAssociations($active->id);
			}
		}
   		foreach($languages as $i => &$language) {
			// Do not display language without frontend UI
			if (!JLanguage::exists($language->lang_code)) {
				unset($languages[$i]);
			}
            if (FALANG_J30) {
                $language_filter = JLanguageMultilang::isEnabled();
            } else {
                $language_filter = $app->getLanguageFilter();
            }



            //set language active before language filter use for sh404 notice
            $language->active =  $language->lang_code == $lang->getTag();

            //since v1.4 change in 1.5 , ex rsform preview don't have active
            if (isset($active)){
                $language->display = ($active->language == '*' || $language->active)?true:false;
            } else {
                $language->display = true;
            }


            if ($language_filter) {
                if (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
                    $language->display = true;
                    $itemid = $associations[$language->lang_code];
                    if ($app->getCfg('sef')=='1') {
                        $language->link = JRoute::_('index.php?lang='.$language->sef.'&Itemid='.$itemid);
                    }
                    else {
                        $language->link = 'index.php?lang='.$language->sef.'&Itemid='.$itemid;
                    }
                }
                else {
                    //sef case
                    if ($app->getCfg('sef')=='1') {

                        //sefToolsEnabled
                        if ($sefToolsEnabled) {
                            $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
                            $language->link = JRoute::_('index.php?lang='.$language->sef.'&Itemid='.$itemid);
                            continue;
                        }


                         //$uri->setVar('lang',$language->sef);
                         $router = JApplication::getRouter();
                         $tmpuri = clone($uri);

                         $router->parse($tmpuri);

                         $vars = $router->getVars();
                         //workaround to fix index language
                         $vars['lang'] = $language->sef;

                        //case of category article
                        if (!empty($vars['view']) && $vars['view'] == 'article' && !empty($vars['option']) && $vars['option'] == 'com_content') {

                            if (FALANG_J30){
                                JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
                                $model = JModelLegacy::getInstance('Article', 'ContentModel', array('ignore_request'=>true));
                                $appParams = JFactory::getApplication()->getParams();
                            } else {
                                JModel::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
                                $model =& JModel::getInstance('Article', 'ContentModel', array('ignore_request'=>true));
                                $appParams = JFactory::getApplication()->getParams();
                            }


                            $model->setState('params', $appParams);

                            //in sef some link have this url
                            //index.php/component/content/article?id=39
                            //id is not in vars but in $tmpuri
                            if (empty($vars['id'])) {
                                $tmpid = $tmpuri->getVar('id');
                                if (!empty($tmpid)) {
                                    $vars['id'] = $tmpuri->getVar('id');
                                } else {
                                    continue;
                                }
                            }

                            $item = $model->getItem($vars['id']);

                            //get alias of content item without the id , so i don't have the translation
                            $db = JFactory::getDbo();
                            $query = $db->getQuery(true);
                            $query->select('alias')->from('#__content')->where('id = ' . (int) $item->id);
                            $db->setQuery($query);
                            $alias = $db->loadResult();

                            $vars['id'] = $item->id.':'.$alias;
                            $vars['catid'] =$item->catid.':'.$item->category_alias;
                        }

                        //new version 1.5
                        //case for k2 item alias write twice
                        if (isset($vars['option']) && $vars['option'] == 'com_k2'){
                            if ($vars['task'] == $vars['id']){
                                unset($vars['id']);
                            }
                        }
                        $url = 'index.php?'.JURI::buildQuery($vars);
                        $language->link = JRoute::_($url);

                        //TODO check performance 3 queries by languages -1
                        /**
                         * Replace the slug from the language switch with correctly translated slug.
                         * $language->lang_code language de la boucle (icone lien)
                         * $lang->getTag() => language en cours sur le site
                         * $default_lang langue par default du site
                         */
                        if($lang->getTag() != $language->lang_code && !empty($vars['Itemid']))
                        {
                            $fManager = FalangManager::getInstance();
                            $id_lang = $fManager->getLanguageID($language->lang_code);
                            $db = JFactory::getDbo();
                            // get translated path if exist
                            $query = $db->getQuery(true);
                            $query->select('fc.value')
                                ->from('#__falang_content fc')
                                ->where('fc.reference_id = '.(int)$vars['Itemid'])
                                ->where('fc.language_id = '.(int) $id_lang )
                                ->where('fc.reference_field = \'path\'')
                                ->where('fc.reference_table = \'menu\'');
                            $db->setQuery($query);
                            $translatedPath = $db->loadResult();

                            // $translatedPath not exist if not translated or site default language
                            // don't pass id to the query , so no translation given by falang
                            $query = $db->getQuery(true);
                            $query->select('m.path')
                                ->from('#__menu m')
                                ->where('m.id = '.(int)$vars['Itemid']);
                            $db->setQuery($query);
                            $originalPath = $db->loadResult();

                            $pathInUse = null;
                            //si on est sur une page traduite on doit récupérer la traduction du path en cours
                            if ($default_lang != $lang->getTag() ) {
                                $id_lang = $fManager->getLanguageID($lang->getTag());
                                // get translated path if exist
                                $query = $db->getQuery(true);
                                $query->select('fc.value')
                                    ->from('#__falang_content fc')
                                    ->where('fc.reference_id = '.(int)$vars['Itemid'])
                                    ->where('fc.language_id = '.(int) $id_lang )
                                    ->where('fc.reference_field = \'path\'')
                                    ->where('fc.reference_table = \'menu\'');
                                $db->setQuery($query);
                                $pathInUse = $db->loadResult();

                            }

                            if (!isset($translatedPath)) {
                                $translatedPath = $originalPath;
                            }

                            // not exist if not translated or site default language
                            if (!isset($pathInUse)) {
                                $pathInUse = $originalPath ;
                            }

                            //make replacement in the url

                            //si language de boucle et language site
                            if($language->lang_code == $default_lang) {
                                if (isset($pathInUse) && isset($originalPath)){
                                    $language->link = str_replace($pathInUse, $originalPath, $language->link);
                                }
                            } else {
                                if (isset($pathInUse) && isset($translatedPath)){
                                    $language->link = str_replace($pathInUse, $translatedPath, $language->link);
                                }
                            }

                        }
                    }
                    //default case
             else {
                        //we can't remove default language in the link
                        $uri->setVar('lang',$language->sef);
                        $language->link = 'index.php?'.$uri->getQuery();
                    }
                }
            }
            else {
                $language->link = 'index.php';
            }

		}
		return $languages;
	}
Example #28
0
 /**
  * This method adds alternate meta tags for associated menu items
  *
  * @return	nothing
  * @since	1.7
  */
 public function onAfterDispatch()
 {
     $app = JFactory::getApplication();
     $doc = JFactory::getDocument();
     if ($app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') {
         // Get active menu item
         $active = $app->getMenu()->getActive();
         if (!$active) {
             return;
         }
         // Get menu item link
         if ($app->getCfg('sef')) {
             $active_link = JRoute::_('index.php?Itemid=' . $active->id, false);
         } else {
             $active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false);
         }
         if ($active_link == JUri::base(true) . '/') {
             $active_link .= 'index.php';
         }
         // Get current link
         $current_link = JRequest::getUri();
         if ($current_link == JUri::base(true) . '/') {
             $current_link .= 'index.php';
         }
         // Check the exact menu item's URL
         if ($active_link == $current_link) {
             // Get menu item associations
             JLoader::register('MenusHelper', JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php');
             $associations = MenusHelper::getAssociations($active->id);
             // Remove current menu item
             unset($associations[$active->language]);
             // Associated menu items in other languages
             if ($associations && $this->params->get('menu_associations')) {
                 $menu = $app->getMenu();
                 $server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
                 foreach (JLanguageHelper::getLanguages() as $language) {
                     if (isset($associations[$language->lang_code])) {
                         $item = $menu->getItem($associations[$language->lang_code]);
                         if ($item && JLanguage::exists($language->lang_code)) {
                             if ($app->getCfg('sef')) {
                                 $link = JRoute::_('index.php?Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef, false);
                             } else {
                                 $link = JRoute::_($item->link . '&Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef, false);
                             }
                             $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                         }
                     }
                 }
             } elseif ($active->home) {
                 $menu = $app->getMenu();
                 $server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
                 foreach (JLanguageHelper::getLanguages() as $language) {
                     $item = $menu->getDefault($language->lang_code);
                     if ($item && $item->language != $active->language && $item->language != '*' && JLanguage::exists($language->lang_code)) {
                         if ($app->getCfg('sef')) {
                             $link = JRoute::_('index.php?Itemid=' . $item->id . '&lang=' . $language->sef, false);
                         } else {
                             $link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef, false);
                         }
                         $doc->addHeadLink($server . JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef), 'alternate', 'rel', array('hreflang' => $language->lang_code));
                     }
                 }
             }
         }
     }
 }
Example #29
0
 /**
  * Load email template strings for provided type
  *
  * @param strng
  * @param string
  *
  * @return mixed
  */
 public function loadTemplate($type, $language = '')
 {
     $set = new stdClass();
     $check_corrupted_pattern = '~^PLG~';
     $subject_template = 'PLG_ZOOCART_EMAIL_' . strtoupper($type) . '_SUBJECT_TEMPLATE';
     $body_template = 'PLG_ZOOCART_EMAIL_' . strtoupper($type) . '_BODY_TEMPLATE';
     if ($language && JLanguage::exists($language)) {
         // Loading templates for chosen language from ini-file:
         $lang = JLanguage::getInstance($language);
         $loaded = $lang->load('plg_system_zoocart', JPATH_ADMINISTRATOR, $language, true, JFactory::getLanguage()->get('tag'));
         if ($loaded) {
             $subject_template = $lang->_($subject_template);
             $body_template = $lang->_($body_template);
         }
     }
     // Additional check if template constants were not defined:
     if (preg_match($check_corrupted_pattern, $subject_template)) {
         $subject_template = JText::_($subject_template);
     }
     if (preg_match($check_corrupted_pattern, $body_template)) {
         $body_template = JText::_($body_template);
     }
     $set->subject = $subject_template;
     $set->body = $body_template;
     return $set;
 }