Exemple #1
1
 /**
  * Task to switch the administrator language.
  *
  * @return  void
  */
 public function switchAdminLanguage()
 {
     // Check for request forgeries.
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $cid = $this->input->get('cid', '');
     $model = $this->getModel('installed');
     // Fetching the language name from the xx-XX.xml
     $file = JPATH_ADMINISTRATOR . '/language/' . $cid . '/' . $cid . '.xml';
     $info = JInstaller::parseXMLInstallFile($file);
     $languageName = $info['name'];
     if ($model->switchAdminLanguage($cid)) {
         // Switching to the new language for the message
         $language = JFactory::getLanguage();
         $newLang = JLanguage::getInstance($cid);
         JFactory::$language = $newLang;
         JFactory::getApplication()->loadLanguage($language = $newLang);
         $newLang->load('com_languages', JPATH_ADMINISTRATOR);
         $msg = JText::sprintf('COM_LANGUAGES_MSG_SWITCH_ADMIN_LANGUAGE_SUCCESS', $languageName);
         $type = 'message';
     } else {
         $msg = $model->getError();
         $type = 'error';
     }
     $this->setRedirect('index.php?option=com_languages&view=installed', $msg, $type);
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$language = JLanguage::getInstance('en-GB');
     $this->object = new JDocumentHTML();
 }
Exemple #3
0
 /**
  * 
  *
  * 
  */
 protected function setFile()
 {
     $params = JComponentHelper::getParams('com_languages');
     $frontend_lang = $params->get('site', 'en-GB');
     $language = JLanguage::getInstance($frontend_lang);
     // get language file for edit
     $language = JFactory::getLanguage();
     $language->load('com_jdownloads');
     $lang_file = JLanguage::getLanguagePath(JPATH_SITE);
     $lang_file .= DS . $frontend_lang . DS . $frontend_lang . '.com_jdownloads.ini';
     @chmod($lang_file, 0755);
     clearstatcache();
     if (is_writable($lang_file) == false) {
         $language_writable = false;
     } else {
         $language_writable = true;
     }
     if ($language_writable) {
         $f = fopen($lang_file, "r");
         $language_text = fread($f, filesize($lang_file));
         $this->languagetext = htmlspecialchars($language_text);
     } else {
         $this->languagetext = '';
     }
     $this->languagefile = $lang_file;
     $this->languagefile_writable = $language_writable;
 }
Exemple #4
0
 public function getItem($id = 'en-GB', $refresh = false, $emptyState = true)
 {
     if (empty($this->_item)) {
         $lang = JLanguage::getInstance($id);
         // Load only site language (Email language costants should be only there)
         $lang->load('com_citruscart', JPATH_ADMINISTRATOR, $id, true);
         $temp_paths = $lang->getPaths('com_citruscart');
         foreach ($temp_paths as $p => $k) {
             $path = $p;
         }
         $result = new JObject();
         $result->name = $lang->getName();
         $result->code = $lang->getTag();
         $result->path = $path;
         $result->strings = array();
         // Load File and Take only the constants that contains "EMAIL_"
         $file = new DSCParameter();
         $file->loadFile($path);
         $strings = $file->toArray();
         $result_strings = array();
         foreach ($strings as $k => $v) {
             // Only if it is a prefix!
             if (stripos($k, $this->email_prefix) === 0) {
                 $result_strings[$k] = $v;
             }
         }
         $result->strings = array('file' => $path, 'strings' => $result_strings);
         JFactory::getApplication()->triggerEvent('onPrepare' . $this->getTable()->get('_suffix'), array(&$result));
         $this->_item = $result;
     }
     return $this->_item;
 }
Exemple #5
0
 public function parseLang($vars)
 {
     if (Mijosef::getConfig()->multilang == 0) {
         return;
     }
     if (empty($vars['lang'])) {
         $lang = JRequest::getWord('lang', '');
         if (empty($lang)) {
             return;
         }
         $vars['lang'] = $lang;
     }
     $languages = JLanguageHelper::getLanguages('sef');
     $lang_code = $languages[$vars['lang']]->lang_code;
     // if current language, don't bother
     if ($lang_code == JFactory::getLanguage()->getTag()) {
         //self::checkHomepage($vars['lang']);
         return;
     }
     // Create a cookie
     $conf = JFactory::getConfig();
     $cookie_domain = $conf->get('config.cookie_domain', '');
     $cookie_path = $conf->get('config.cookie_path', '/');
     setcookie(JUtility::getHash('language'), $lang_code, time() + 365 * 86400, $cookie_path, $cookie_domain);
     // set the request var
     JRequest::setVar('language', $lang_code);
     // set current language
     jimport('joomla.language.language');
     $conf = JFactory::getConfig();
     $debug = $conf->get('debug_lang');
     $lang = JLanguage::getInstance($lang_code, $debug);
     JFactory::$language = $lang;
     self::$_lang = $vars['lang'];
 }
Exemple #6
0
 /**
  * @todo Implement testGetInstance().
  */
 public function testGetInstance()
 {
     // This method returns the language in use
     // English is the default language
     $langEqual = 'en-GB';
     $langNotEqual = 'es-ES';
     $lang = new JLanguage('');
     $listEqual = $lang->getInstance($langEqual);
     $this->assertObjectHasAttribute('metadata', $listEqual);
     $this->assertObjectNotHasAttribute('name', $listEqual);
     $this->assertTrue($listEqual->exists($langEqual));
     $this->assertFalse($listEqual->exists($langNotEqual));
     $listNotEqual = $lang->getInstance($langNotEqual);
     $this->assertObjectHasAttribute('metadata', $listNotEqual);
     $this->assertObjectNotHasAttribute('name', $listNotEqual);
     $this->assertTrue($listNotEqual->exists($langEqual));
 }
 /**
  * @covers JLanguage::getInstance
  */
 public function testGetInstance()
 {
     $instance = JLanguage::getInstance(null);
     $this->assertInstanceOf('JLanguage', $instance);
     $instance = JLanguage::getInstance(null, true);
     $this->assertInstanceOf('JLanguage', $instance);
     $this->assertTrue($instance->getDebug());
 }
Exemple #8
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.1
  */
 protected function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$application = $this->getMockCmsApp();
     JFactory::$language = JLanguage::getInstance('en-GB', false);
     $this->backupServer = $_SERVER;
     $_SERVER['HTTP_HOST'] = 'example.com';
     $_SERVER['SCRIPT_NAME'] = '';
 }
 public static function transliterate($string, $languageId)
 {
     if ($languageId == '*') {
         $params = JComponentHelper::getParams('com_languages');
         $tag = $params->get('site');
     } else {
         $tag = $languageId;
     }
     $language = JLanguage::getInstance($tag);
     $string = $language->transliterate($string);
     $string = JFilterOutput::stringURLSafe($string);
     return $string;
 }
Exemple #10
0
 /**
  * This method processes a string and replaces all accented UTF-8 characters by unaccented
  * ASCII-7 "equivalents", whitespaces are replaced by hyphens and the string is lowercase.
  *
  * @param   string  $string    String to process
  * @param   string  $language  Language to transilterate to
  *
  * @return  string  Processed string
  *
  * @since   11.1
  */
 public static function stringURLSafe($string, $language = '')
 {
     // Remove any '-' from the string since they will be used as concatenaters
     $str = str_replace('-', ' ', $string);
     // Transliterate on the language requested (fallback to current language if not specified)
     $lang = $language == '' || $language == '*' ? JFactory::getLanguage() : JLanguage::getInstance($language);
     $str = $lang->transliterate($str);
     // Trim white spaces at beginning and end of alias and make lowercase
     $str = trim(StringHelper::strtolower($str));
     // Remove any duplicate whitespace, and ensure all characters are alphanumeric
     $str = preg_replace('/(\\s|[^A-Za-z0-9\\-])+/', '-', $str);
     // Trim dashes at beginning and end of alias
     $str = trim($str, '-');
     return $str;
 }
Exemple #11
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.0
  */
 protected function setUp()
 {
     parent::setUp();
     // Store the factory state so we can mock the necessary objects
     $this->saveFactoryState();
     JFactory::$application = $this->getMockCmsApp();
     JFactory::$config = $this->getMockConfig();
     JFactory::$session = $this->getMockSession();
     JFactory::$language = JLanguage::getInstance('en-GB');
     // Set up our mock config
     $this->config = JFactory::getConfig();
     $this->config->set('helpurl', 'https://help.joomla.org/proxy/index.php?option=com_help&keyref=Help{major}{minor}:{keyref}');
     // Load the admin en-GB.ini language file
     JFactory::getLanguage()->load('', JPATH_ADMINISTRATOR);
 }
Exemple #12
0
 /**
  * Method to get the record form.
  *
  * @param   array    $data      Data for the form.
  * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
  *
  * @return  mixed A JForm object on success, false on failure.
  *
  * @since   2.5
  */
 public function getForm($data = array(), $loadData = true)
 {
     // Get the form.
     $form = $this->loadForm('com_languages.override', 'override', array('control' => 'jform', 'load_data' => $loadData));
     if (empty($form)) {
         return false;
     }
     $client = $this->getState('filter.client', 'site');
     $language = $this->getState('filter.language', 'en-GB');
     $langName = JLanguage::getInstance($language)->getName();
     if (!$langName) {
         // If a language only exists in frontend, it's meta data cannot be
         // loaded in backend at the moment, so fall back to the language tag.
         $langName = $language;
     }
     $form->setValue('client', null, JText::_('COM_LANGUAGES_VIEW_OVERRIDE_CLIENT_' . strtoupper($client)));
     $form->setValue('language', null, JText::sprintf('COM_LANGUAGES_VIEW_OVERRIDE_LANGUAGE', $langName, $language));
     $form->setValue('file', null, JPath::clean(constant('JPATH_' . strtoupper($client)) . '/language/overrides/' . $language . '.override.ini'));
     return $form;
 }
 /**
  * Example after save content method
  * Article is passed by reference, but after the save, so no changes will be saved.
  * Method is called right after the content is saved
  *
  * @param   string   $context  The context of the content passed to the plugin (added in 1.6)
  * @param   object   $article  A JTableContent object
  * @param   boolean  $isNew    If the content is just about to be created
  *
  * @return  boolean   true if function not enabled, is in frontend or is new. Else true or
  *                    false depending on success of save function.
  *
  * @since   1.6
  */
 public function onContentAfterSave($context, $article, $isNew)
 {
     // Check we are handling the frontend edit form.
     if ($context != 'com_content.form') {
         return true;
     }
     // Check if this function is enabled.
     if (!$this->params->def('email_new_fe', 1)) {
         return true;
     }
     // Check this is a new article.
     if (!$isNew) {
         return true;
     }
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__users'))->where($db->quoteName('sendEmail') . ' = 1')->where($db->quoteName('block') . ' = 0');
     $db->setQuery($query);
     $users = (array) $db->loadColumn();
     if (empty($users)) {
         return true;
     }
     $user = JFactory::getUser();
     // Messaging for new items
     JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_messages/models', 'MessagesModel');
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_messages/tables');
     $default_language = JComponentHelper::getParams('com_languages')->get('administrator');
     $debug = JFactory::getConfig()->get('debug_lang');
     $result = true;
     foreach ($users as $user_id) {
         if ($user_id != $user->id) {
             // Load language for messaging
             $receiver = JUser::getInstance($user_id);
             $lang = JLanguage::getInstance($receiver->getParam('admin_language', $default_language), $debug);
             $lang->load('com_content');
             $message = array('user_id_to' => $user_id, 'subject' => $lang->_('COM_CONTENT_NEW_ARTICLE'), 'message' => sprintf($lang->_('COM_CONTENT_ON_NEW_CONTENT'), $user->get('name'), $article->title));
             $model_message = JModelLegacy::getInstance('Message', 'MessagesModel');
             $result = $model_message->save($message);
         }
     }
     return $result;
 }
Exemple #14
0
 /**
  * Example after save content method
  * Article is passed by reference, but after the save, so no changes will be saved.
  * Method is called right after the content is saved
  *
  * @param	string		The context of the content passed to the plugin (added in 1.6)
  * @param	object		A JTableContent object
  * @param	bool		If the content is just about to be created
  * @since	1.6
  */
 public function onContentAfterSave($context, &$article, $isNew)
 {
     // Check we are handling the frontend edit form.
     if ($context != 'com_content.form') {
         return true;
     }
     // Check if this function is enabled.
     if (!$this->params->def('email_new_fe', 1)) {
         return true;
     }
     // Check this is a new article.
     if (!$isNew) {
         return true;
     }
     $user = User::getRoot();
     // Messaging for new items
     JModelLegacy::addIncludePath(PATH_CORE . '/components/com_messages/admin/models', 'MessagesModel');
     JTable::addIncludePath(PATH_CORE . '/components/com_messages/admin/tables');
     $db = App::get('db');
     $db->setQuery('SELECT id FROM #__users WHERE sendEmail = 1');
     $users = (array) $db->loadColumn();
     $default_language = Component::params('com_languages')->get('administrator');
     $debug = Config::get('debug_lang');
     foreach ($users as $user_id) {
         if ($user_id != $user->id) {
             // Load language for messaging
             $receiver = User::getInstance($user_id);
             $lang = JLanguage::getInstance($receiver->getParam('admin_language', $default_language), $debug);
             $lang->load('com_content');
             $message = array('user_id_to' => $user_id, 'subject' => $lang->_('COM_CONTENT_NEW_ARTICLE'), 'message' => sprintf($lang->_('COM_CONTENT_ON_NEW_CONTENT'), $user->get('name'), $article->title));
             $model_message = JModelLegacy::getInstance('Message', 'MessagesModel');
             $model_message->save($message);
         }
     }
     return true;
 }
Exemple #15
0
 /**
  * Create a language object
  *
  * @access private
  * @return object JLanguage
  * @since 1.5
  */
 private static function &_createLanguage()
 {
     jimport('joomla.language.language');
     $conf =& JFactory::getConfig();
     $locale = $conf->getValue('config.language');
     $lang =& JLanguage::getInstance($locale);
     $lang->setDebug($conf->getValue('config.debug_lang'));
     return $lang;
 }
Exemple #16
0
 /**
  * Create a language object
  *
  * @return  JLanguage object
  *
  * @see     JLanguage
  * @since   11.1
  */
 protected static function createLanguage()
 {
     $conf = self::getConfig();
     $locale = $conf->get('language');
     $debug = $conf->get('debug_lang');
     $lang = JLanguage::getInstance($locale, $debug);
     return $lang;
 }
Exemple #17
0
 /**
  * Add parse rule to router.
  *
  * @param   JRouter  &$router  JRouter object.
  * @param   JUri     &$uri     JUri object.
  *
  * @return  void
  *
  * @since   1.6
  */
 public function parseRule(&$router, &$uri)
 {
     // Did we find the current and existing language yet?
     $found = false;
     $lang_code = false;
     // Are we in SEF mode or not?
     if ($this->mode_sef) {
         $path = $uri->getPath();
         $parts = explode('/', $path);
         $sef = $parts[0];
         // Do we have a URL Language Code ?
         if (!isset($this->sefs[$sef])) {
             // Check if remove default url language code is set
             if ($this->params->get('remove_default_prefix', 0)) {
                 if ($parts[0]) {
                     // We load a default site language page
                     $lang_code = $this->default_lang;
                 } else {
                     // We check for an existing language cookie
                     $lang_code = $this->getLanguageCookie();
                 }
             } else {
                 $lang_code = $this->getLanguageCookie();
             }
             // No language code. Try using browser settings or default site language
             if (!$lang_code && $this->params->get('detect_browser', 0) == 1) {
                 $lang_code = JLanguageHelper::detectLanguage();
             }
             if (!$lang_code) {
                 $lang_code = $this->default_lang;
             }
             if ($this->params->get('remove_default_prefix', 0) && $lang_code == $this->default_lang) {
                 $found = true;
             }
         } else {
             // We found our language
             $found = true;
             $lang_code = $this->sefs[$sef]->lang_code;
             // If we found our language, but its the default language and we don't want a prefix for that, we are on a wrong URL.
             // Or we try to change the language back to the default language. We need a redirect to the proper URL for the default language.
             if ($this->params->get('remove_default_prefix', 0) && $lang_code == $this->default_lang) {
                 // Create a cookie.
                 $this->setLanguageCookie($lang_code);
                 $found = false;
                 array_shift($parts);
                 $path = implode('/', $parts);
             }
             // We have found our language and the first part of our URL is the language prefix
             if ($found) {
                 array_shift($parts);
                 $uri->setPath(implode('/', $parts));
             }
         }
     } else {
         $lang_code = $this->getLanguageCookie();
         if ($this->params->get('detect_browser', 1) && !$lang_code) {
             $lang_code = JLanguageHelper::detectLanguage();
         }
         if (!isset($this->lang_codes[$lang_code])) {
             $lang_code = $this->default_lang;
         }
     }
     $lang = $uri->getVar('lang', $lang_code);
     if (isset($this->sefs[$lang])) {
         // We found our language
         $found = true;
         $lang_code = $this->sefs[$lang]->lang_code;
     }
     // We are called via POST. We don't care about the language
     // and simply set the default language as our current language.
     if ($this->app->input->getMethod() == "POST" || count($this->app->input->post) > 0 || count($this->app->input->files) > 0) {
         $found = true;
         if (!isset($lang_code)) {
             $lang_code = $this->getLanguageCookie();
         }
         if ($this->params->get('detect_browser', 1) && !$lang_code) {
             $lang_code = JLanguageHelper::detectLanguage();
         }
         if (!isset($this->lang_codes[$lang_code])) {
             $lang_code = $this->default_lang;
         }
     }
     // We have not found the language and thus need to redirect
     if (!$found) {
         // Lets find the default language for this user
         if (!isset($lang_code) || !isset($this->lang_codes[$lang_code])) {
             $lang_code = false;
             if ($this->params->get('detect_browser', 1)) {
                 $lang_code = JLanguageHelper::detectLanguage();
                 if (!isset($this->lang_codes[$lang_code])) {
                     $lang_code = false;
                 }
             }
             if (!$lang_code) {
                 $lang_code = $this->default_lang;
             }
         }
         if ($this->mode_sef) {
             // Use the current language sef or the default one.
             if (!$this->params->get('remove_default_prefix', 0) || $lang_code != $this->default_lang) {
                 $path = $this->lang_codes[$lang_code]->sef . '/' . $path;
             }
             $uri->setPath($path);
             if (!$this->app->get('sef_rewrite')) {
                 $uri->setPath('index.php/' . $uri->getPath());
             }
             $this->app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')), 301);
         } else {
             $uri->setVar('lang', $this->lang_codes[$lang_code]->sef);
             $this->app->redirect($uri->base() . 'index.php?' . $uri->getQuery(), 301);
         }
     }
     // We have found our language and now need to set the cookie and the language value in our system
     $array = array('lang' => $lang_code);
     $this->current_lang = $lang_code;
     // Set the request var.
     $this->app->input->set('language', $lang_code);
     $this->app->set('language', $lang_code);
     $language = JFactory::getLanguage();
     if ($language->getTag() != $lang_code) {
         $newLang = JLanguage::getInstance($lang_code);
         foreach ($language->getPaths() as $extension => $files) {
             $newLang->load($extension);
         }
         JFactory::$language = $newLang;
         $this->app->loadLanguage($newLang);
     }
     // Create a cookie.
     if ($this->getLanguageCookie() != $lang_code) {
         $this->setLanguageCookie($lang_code);
     }
     return $array;
 }
Exemple #18
0
 /**
  * Initialise the application.
  *
  * @param   array  $options  An optional associative array of configuration settings.
  *
  * @return  void
  *
  * @since   3.2
  */
 protected function initialiseApp($options = array())
 {
     // Set the configuration in the API.
     $this->config = JFactory::getConfig();
     // Check that we were given a language in the array (since by default may be blank).
     if (isset($options['language'])) {
         $this->set('language', $options['language']);
     }
     // Build our language object
     $lang = JLanguage::getInstance($this->get('language'), $this->get('debug_lang'));
     // Load the language to the API
     $this->loadLanguage($lang);
     // Register the language object with JFactory
     JFactory::$language = $this->getLanguage();
     // Set user specific editor.
     $user = JFactory::getUser();
     $editor = $user->getParam('editor', $this->get('editor'));
     if (!JPluginHelper::isEnabled('editors', $editor)) {
         $editor = $this->get('editor');
         if (!JPluginHelper::isEnabled('editors', $editor)) {
             $editor = 'none';
         }
     }
     $this->set('editor', $editor);
     // Trigger the onAfterInitialise event.
     JPluginHelper::importPlugin('system');
     $this->triggerEvent('onAfterInitialise');
 }
Exemple #19
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since   1.6
  */
 public function save($data)
 {
     $table = $this->getTable();
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Assign empty values.
     if (empty($table->user_id_from)) {
         $table->user_id_from = JFactory::getUser()->get('id');
     }
     if ((int) $table->date_time == 0) {
         $table->date_time = JFactory::getDate()->toSql();
     }
     // Check the data.
     if (!$table->check()) {
         $this->setError($table->getError());
         return false;
     }
     // Load the recipient user configuration.
     $model = JModelLegacy::getInstance('Config', 'MessagesModel', array('ignore_request' => true));
     $model->setState('user.id', $table->user_id_to);
     $config = $model->getItem();
     if (empty($config)) {
         $this->setError($model->getError());
         return false;
     }
     if ($config->get('locked', false)) {
         $this->setError(JText::_('COM_MESSAGES_ERR_SEND_FAILED'));
         return false;
     }
     // Store the data.
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     if ($config->get('mail_on_new', true)) {
         // Load the user details (already valid from table check).
         $fromUser = JUser::getInstance($table->user_id_from);
         $toUser = JUser::getInstance($table->user_id_to);
         $debug = JFactory::getConfig()->get('debug_lang');
         $default_language = JComponentHelper::getParams('com_languages')->get('administrator');
         $lang = JLanguage::getInstance($toUser->getParam('admin_language', $default_language), $debug);
         $lang->load('com_messages', JPATH_ADMINISTRATOR);
         // Build the email subject and message
         $sitename = JFactory::getApplication()->get('sitename');
         $siteURL = JUri::root() . 'administrator/index.php?option=com_messages&view=message&message_id=' . $table->message_id;
         $subject = sprintf($lang->_('COM_MESSAGES_NEW_MESSAGE_ARRIVED'), $sitename);
         $msg = sprintf($lang->_('COM_MESSAGES_PLEASE_LOGIN'), $siteURL);
         // Send the email
         JFactory::getMailer()->sendMail($fromUser->email, $fromUser->name, $toUser->email, $subject, $msg);
     }
     return true;
 }
Exemple #20
0
 /**
  * Create a language object
  *
  * @return JLanguage object
  * @since 1.5
  */
 private static function _createLanguage()
 {
     jimport('joomla.language.language');
     $conf = self::getConfig();
     $locale = $conf->get('language');
     $debug = $conf->get('debug_lang');
     $lang = JLanguage::getInstance($locale, $debug);
     return $lang;
 }
Exemple #21
0
 private static function initialize_jpagetitle_list()
 {
     $jlang = JFactory::getLanguage();
     $db = JFactory::getDbo();
     $langs = $jlang->getKnownLanguages();
     $jpts = array();
     foreach (array_keys($langs) as $lang) {
         $over_path = JPATH_SITE . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR . 'overrides' . DIRECTORY_SEPARATOR . "{$lang}.override.ini";
         if (JFile::exists($over_path)) {
             $cnt = @file_get_contents($over_path);
             if ($cnt !== false) {
                 $cnt = str_replace('_QQ_', '"\\""', $cnt);
                 $ors = @parse_ini_string($cnt);
                 if (is_array($ors)) {
                     if (isset($ors['JPAGETITLE']) && !empty($ors['JPAGETITLE'])) {
                         $jpts[$ors['JPAGETITLE']] = 1;
                         continue;
                     }
                 }
             }
         }
         $jo = JLanguage::getInstance($lang);
         if ($jo->load('joomla', JPATH_SITE)) {
             $jpt = $jo->_('JPAGETITLE');
             if (!empty($jpt)) {
                 $jpts[$jpt] = 1;
             }
         }
     }
     if (empty($jpts)) {
         $jpts['%1$s - %2$s'] = 1;
     }
     self::$jpagetitles = array_keys($jpts);
 }
Exemple #22
0
}
?>

<?php 
if ($params->get('dropdown', 1)) {
    ?>
	<form name="lang" method="post" action="<?php 
    echo htmlspecialchars(JURI::current());
    ?>
">
	<select class="inputbox" onchange="document.location.replace(this.value);" >
	<?php 
    foreach ($list as $language) {
        ?>
		<option dir=<?php 
        echo JLanguage::getInstance($language->lang_code)->isRTL() ? '"rtl"' : '"ltr"';
        ?>
 value="<?php 
        echo $language->link;
        ?>
" <?php 
        echo $language->active ? 'selected="selected"' : '';
        ?>
>
		<?php 
        echo $language->title_native;
        ?>
</option>
	<?php 
    }
    ?>
Exemple #23
0
 /**
  * Add parse rule to router.
  *
  * @param   JRouter  &$router  JRouter object.
  * @param   JUri     &$uri     JUri object.
  *
  * @return  void
  *
  * @since   1.6
  */
 public function parseRule(&$router, &$uri)
 {
     // Did we find the current and existing language yet?
     $found = false;
     $lang_code = false;
     // Are we in SEF mode or not?
     if ($this->mode_sef) {
         $path = $uri->getPath();
         $parts = explode('/', $path);
         $sef = $parts[0];
         // Do we have a URL Language Code ?
         if (!isset($this->sefs[$sef])) {
             // Check if remove default url language code is set
             if ($this->params->get('remove_default_prefix', 0)) {
                 if ($parts[0]) {
                     // We load a default site language page
                     $lang_code = $this->default_lang;
                 } else {
                     // We check for an existing language cookie
                     $lang_code = $this->getLanguageCookie();
                 }
             } else {
                 $lang_code = $this->getLanguageCookie();
             }
             // No language code. Try using browser settings or default site language
             if (!$lang_code && $this->params->get('detect_browser', 0) == 1) {
                 $lang_code = JLanguageHelper::detectLanguage();
             }
             if (!$lang_code) {
                 $lang_code = $this->default_lang;
             }
             if ($this->params->get('remove_default_prefix', 0) && $lang_code == $this->default_lang) {
                 $found = true;
             }
         } else {
             // We found our language
             $found = true;
             $lang_code = $this->sefs[$sef]->lang_code;
             // If we found our language, but its the default language and we don't want a prefix for that, we are on a wrong URL.
             // Or we try to change the language back to the default language. We need a redirect to the proper URL for the default language.
             if ($this->params->get('remove_default_prefix', 0) && $lang_code == $this->default_lang) {
                 // Create a cookie.
                 $this->setLanguageCookie($lang_code);
                 $found = false;
                 array_shift($parts);
                 $path = implode('/', $parts);
             }
             // We have found our language and the first part of our URL is the language prefix
             if ($found) {
                 array_shift($parts);
                 $uri->setPath(implode('/', $parts));
             }
         }
     } else {
         $lang_code = $this->getLanguageCookie();
         if ($this->params->get('detect_browser', 1) && !$lang_code) {
             $lang_code = JLanguageHelper::detectLanguage();
         }
         if (!isset($this->lang_codes[$lang_code])) {
             $lang_code = $this->default_lang;
         }
     }
     $lang = $uri->getVar('lang', $lang_code);
     if (isset($this->sefs[$lang])) {
         // We found our language
         $found = true;
         $lang_code = $this->sefs[$lang]->lang_code;
     }
     // We are called via POST. We don't care about the language
     // and simply set the default language as our current language.
     if ($this->app->input->getMethod() == "POST" || count($this->app->input->post) > 0 || count($this->app->input->files) > 0) {
         $found = true;
         if (!isset($lang_code)) {
             $lang_code = $this->getLanguageCookie();
         }
         if ($this->params->get('detect_browser', 1) && !$lang_code) {
             $lang_code = JLanguageHelper::detectLanguage();
         }
         if (!isset($this->lang_codes[$lang_code])) {
             $lang_code = $this->default_lang;
         }
     }
     // We have not found the language and thus need to redirect
     if (!$found) {
         // Lets find the default language for this user
         if (!isset($lang_code) || !isset($this->lang_codes[$lang_code])) {
             $lang_code = false;
             if ($this->params->get('detect_browser', 1)) {
                 $lang_code = JLanguageHelper::detectLanguage();
                 if (!isset($this->lang_codes[$lang_code])) {
                     $lang_code = false;
                 }
             }
             if (!$lang_code) {
                 $lang_code = $this->default_lang;
             }
         }
         if ($this->mode_sef) {
             // Use the current language sef or the default one.
             if (!$this->params->get('remove_default_prefix', 0) || $lang_code != $this->default_lang) {
                 $path = $this->lang_codes[$lang_code]->sef . '/' . $path;
             }
             $uri->setPath($path);
             if (!$this->app->get('sef_rewrite')) {
                 $uri->setPath('index.php/' . $uri->getPath());
             }
             $redirectUri = $uri->base() . $uri->toString(array('path', 'query', 'fragment'));
         } else {
             $uri->setVar('lang', $this->lang_codes[$lang_code]->sef);
             $redirectUri = $uri->base() . 'index.php?' . $uri->getQuery();
         }
         // Set redirect HTTP code to "302 Found".
         $redirectHttpCode = 302;
         // If selected language is the default language redirect code is "301 Moved Permanently".
         if ($lang_code === $this->default_lang) {
             $redirectHttpCode = 301;
             // We cannot cache this redirect in browser. 301 is cachable by default so we need to force to not cache it in browsers.
             $this->app->setHeader('Expires', 'Wed, 17 Aug 2005 00:00:00 GMT', true);
             $this->app->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
             $this->app->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', false);
             $this->app->setHeader('Pragma', 'no-cache');
             $this->app->sendHeaders();
         }
         // Redirect to language.
         $this->app->redirect($redirectUri, $redirectHttpCode);
     }
     // We have found our language and now need to set the cookie and the language value in our system
     $array = array('lang' => $lang_code);
     $this->current_lang = $lang_code;
     // Set the request var.
     $this->app->input->set('language', $lang_code);
     $this->app->set('language', $lang_code);
     $language = JFactory::getLanguage();
     if ($language->getTag() != $lang_code) {
         $newLang = JLanguage::getInstance($lang_code);
         foreach ($language->getPaths() as $extension => $files) {
             $newLang->load($extension);
         }
         JFactory::$language = $newLang;
         $this->app->loadLanguage($newLang);
     }
     // Create a cookie.
     if ($this->getLanguageCookie() != $lang_code) {
         $this->setLanguageCookie($lang_code);
     }
     return $array;
 }
Exemple #24
0
 function check()
 {
     jimport('joomla.filter.output');
     $params = JComponentHelper::getParams('com_k2');
     // $this->params->fabrics = 'kuku';
     $this->title = JString::trim($this->title);
     if ($this->title == '') {
         $this->setError(JText::_('K2_ITEM_MUST_HAVE_A_TITLE'));
         return false;
     }
     if (!$this->catid) {
         $this->setError(JText::_('K2_ITEM_MUST_HAVE_A_CATEGORY'));
         return false;
     }
     if (empty($this->alias)) {
         $this->alias = $this->title;
     }
     if (K2_JVERSION == '15') {
         if (JPluginHelper::isEnabled('system', 'unicodeslug') || JPluginHelper::isEnabled('system', 'jw_unicodeSlugsExtended')) {
             $this->alias = JFilterOutput::stringURLSafe($this->alias);
         } else {
             mb_internal_encoding("UTF-8");
             mb_regex_encoding("UTF-8");
             $this->alias = trim(mb_strtolower($this->alias));
             $this->alias = str_replace('-', ' ', $this->alias);
             $this->alias = str_replace('/', '-', $this->alias);
             $this->alias = mb_ereg_replace('[[:space:]]+', ' ', $this->alias);
             $this->alias = trim(str_replace(' ', '-', $this->alias));
             $this->alias = str_replace('.', '', $this->alias);
             $this->alias = str_replace('"', '', $this->alias);
             $this->alias = str_replace("'", '', $this->alias);
             $stripthese = ',|~|!|@|%|^|(|)|<|>|:|;|{|}|[|]|&|`|„|‹|’|‘|“|â€�|•|›|«|´|»|°|«|»|…';
             $strips = explode('|', $stripthese);
             foreach ($strips as $strip) {
                 $this->alias = str_replace($strip, '', $this->alias);
             }
             if (trim(str_replace('-', '', $this->alias)) == '') {
                 $datenow = JFactory::getDate();
                 $this->alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
             }
             $this->alias = trim($this->alias, '-.');
         }
     } else {
         if (JFactory::getConfig()->get('unicodeslugs') == 1) {
             $this->alias = JFilterOutput::stringURLUnicodeSlug($this->alias);
         } else {
             // Detect the site language we will transliterate
             if ($this->language == '*') {
                 $langParams = JComponentHelper::getParams('com_languages');
                 $languageTag = $langParams->get('site');
             } else {
                 $languageTag = $this->language;
             }
             $language = JLanguage::getInstance($languageTag);
             $this->alias = $language->transliterate($this->alias);
             $this->alias = JFilterOutput::stringURLSafe($this->alias);
             if (trim(str_replace('-', '', $this->alias)) == '') {
                 $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
             }
         }
     }
     if (K2_JVERSION == '15' || $params->get('enforceSEFReplacements')) {
         $SEFReplacements = array();
         $items = explode(',', $params->get('SEFReplacements'));
         foreach ($items as $item) {
             if (!empty($item)) {
                 @(list($src, $dst) = explode('|', trim($item)));
                 $SEFReplacements[trim($src)] = trim($dst);
             }
         }
         foreach ($SEFReplacements as $key => $value) {
             $this->alias = str_replace($key, $value, $this->alias);
         }
         $this->alias = trim($this->alias, '-.');
     }
     if (K2_JVERSION == '15') {
         if (trim(str_replace('-', '', $this->alias)) == '') {
             $datenow = JFactory::getDate();
             $this->alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
         }
     }
     // Check if alias already exists. If so warn the user
     $params = JComponentHelper::getParams('com_k2');
     if ($params->get('k2Sef') && !$params->get('k2SefInsertItemId')) {
         $db = JFactory::getDBO();
         $db->setQuery("SELECT id FROM #__k2_items WHERE alias = " . $db->quote($this->alias) . " AND id != " . (int) $this->id);
         $result = count($db->loadObjectList());
         if ($result > 1) {
             $this->alias .= '-' . (int) $result + 1;
             $application = JFactory::getApplication();
             $application->enqueueMessage(JText::_('K2_WARNING_DUPLICATE_TITLE_ALIAS_DETECTED'), 'notice');
         }
     }
     return true;
 }
 /**
  * Test...
  *
  * @covers JLanguage::getInstance
  *
  * @return void
  */
 public function testGetInstance()
 {
     $instance = JLanguage::getInstance(null);
     $this->assertInstanceOf('JLanguage', $instance);
 }
 private function setLang()
 {
     if ($this->seo_translate) {
         /* use translator */
         $this->Jlang = JLanguage::getInstance($this->langTag);
         $extension = 'com_virtuemart.sef';
         $base_dir = JPATH_SITE;
         $this->Jlang->load($extension, $base_dir);
     }
 }
 /**
  * Sends an email to all newly assigned users
  *
  * @param    array    $uids    The users to notify
  * @param    integer   $task_id  The task id
  *
  * @return    void
  */
 protected function notifyAssignedUsers($uids, $pk)
 {
     // Load the relevant task information
     $query = $this->_db->getQuery(true);
     $query->select('a.id, a.project_id, a.milestone_id, a.list_id, a.title, a.description, a.priority')->select('a.start_date, a.end_date')->select('p.title AS p_title, m.title AS ms_title, l.title AS l_title')->from('#__pf_tasks AS a')->join('LEFT', '#__pf_projects AS p ON p.id = a.project_id')->join('LEFT', '#__pf_milestones AS m ON m.id = a.milestone_id')->join('LEFT', '#__pf_task_lists AS l ON l.id = a.list_id')->where('a.id = ' . (int) $pk);
     $this->_db->setQuery($query);
     $task = $this->_db->loadObject();
     if (empty($task)) {
         return;
     }
     // Get the default language
     $def_lang = JComponentHelper::getParams('com_languages')->get('administrator');
     $debug = JFactory::getConfig()->get('debug_lang');
     // Email settings
     $mailfrom = JFactory::getConfig()->get('mailfrom');
     $fromname = JFactory::getConfig()->get('fromname');
     // Own user account
     $user = JFactory::getUser();
     // mysql nulldate
     $nd = $this->_db->getNullDate();
     // Task link
     $link = JRoute::_(JURI::root() . PFtasksHelperRoute::getTaskRoute($task->id, $task->project_id, $task->milestone_id, $task->list_id));
     $is_site = JFactory::getApplication()->isSite();
     // Send to each user...
     foreach ($uids as $uid) {
         // Dont email to self
         if ($uid == $user->id) {
             continue;
         }
         // Get recipient
         $recipient = JFactory::getUser($uid);
         // Load the default language of the recipient
         $lang = JLanguage::getInstance($recipient->getParam('site_language', $def_lang), $debug);
         $lang->load('com_projectfork');
         $lang->load('com_pftasks');
         if ($is_site) {
             $lang->load('com_projectfork', JPATH_ADMINISTRATOR);
             $lang->load('com_pftasks', JPATH_ADMINISTRATOR);
         }
         // Prepare subject
         $format = $lang->_('COM_PROJECTFORK_TASK_EMAIL_ASSIGN_SUBJECT');
         $subject = sprintf($format, $task->p_title, $user->name, $task->title);
         // Prepare text
         $format = $lang->_('COM_PROJECTFORK_TASK_EMAIL_ASSIGN_MESSAGE');
         $text = array();
         // Title
         $text[] = '* ' . $lang->_('JGLOBAL_TITLE') . ': \\n  ' . $task->title . '\\n';
         // Milestone
         $text[] = '* ' . $lang->_('COM_PROJECTFORK_EMAIL_LABEL_MILESTONE_ID') . ': \\n  ' . (empty($task->m_title) ? '-' : $task->m_title) . '\\n';
         // Task list
         $text[] = '* ' . $lang->_('COM_PROJECTFORK_EMAIL_LABEL_LIST_ID') . ': \\n  ' . (empty($task->l_title) ? '-' : $task->l_title) . '\\n';
         // Start
         $text[] = '* ' . $lang->_('COM_PROJECTFORK_EMAIL_LABEL_START_DATE') . ': \\n  ' . ($task->start_date == $nd ? '-' : JHtml::_('date', $task->start_date, JText::_('DATE_FORMAT_LC3'))) . '\\n';
         // End
         $text[] = '* ' . $lang->_('COM_PROJECTFORK_EMAIL_LABEL_END_DATE') . ': \\n  ' . ($task->end_date == $nd ? '  -' : JHtml::_('date', $task->end_date, JText::_('DATE_FORMAT_LC3'))) . '\\n';
         // Priority
         $text[] = '* ' . $lang->_('COM_PROJECTFORK_EMAIL_LABEL_PRIORITY') . ': \\n  ' . PFTasksHelper::priority2string($task->priority) . '\\n';
         // Description
         $text[] = '* ' . $lang->_('COM_PROJECTFORK_EMAIL_LABEL_DESCRIPTION') . ': \\n' . strip_tags($task->description);
         // Done. Compile text
         $text = implode('', $text);
         $text = str_replace('\\n', "\n", $text);
         $text = sprintf($format, $recipient->name, $user->name, $text, $link) . "\n\n" . sprintf($lang->_('COM_PROJECTFORK_EMAIL_FOOTER'), JURI::root());
         // Mail it
         $result = JFactory::getMailer()->sendMail($mailfrom, $fromname, $recipient->email, $subject, $text);
         // Break on the first failure, assuming emails aren't working
         if (!$result) {
             break;
         }
     }
 }
Exemple #28
0
		<?php 
    echo JText::_('TPL_MN_PROFILE_INFORMATION_UPPER') . ' | ';
    ?>
	</a>
	<a href="<?php 
    echo JRoute::_('index.php?option=com_users&view=profile');
    ?>
">
		<img alt="icon_profile.gif" src="templates/medicnexus/images/icon_profile.gif">
	</a>
	</div>	
	<?php 
    echo JText::_('TPL_MN_ACTIVE_LANGUAGE') . ': ';
    ?>
	<?php 
    echo JLanguage::getInstance(JFactory::getUser()->getParam('language'))->getName();
    ?>
	</div>
<?php 
}
?>
	<div class="controls" align="right" style="margin: 10px 5px 0 0;">
		<button type="submit" name="Submit"><?php 
echo JText::_('JLOGOUT');
?>
</button>
		<input type="hidden" name="option" value="com_users" />
		<input type="hidden" name="task" value="user.logout" />
		<input type="hidden" name="return" value="<?php 
echo $return;
?>
    ?>
	<ul class="<?php 
    echo $params->get('inline', 1) ? 'lang-inline' : 'lang-block';
    ?>
">
	<?php 
    foreach ($list as $language) {
        ?>
		<?php 
        if ($params->get('show_active', 0) || !$language->active) {
            ?>
			<li class="<?php 
            echo $language->active ? 'lang-active' : '';
            ?>
" dir="<?php 
            echo JLanguage::getInstance($language->lang_code)->isRTL() ? 'rtl' : 'ltr';
            ?>
">
			<a href="<?php 
            echo $language->link;
            ?>
">
			<?php 
            if ($params->get('image', 1)) {
                ?>
				<?php 
                echo JHtml::_('image', 'mod_languages/' . $language->image . '.gif', $language->title_native, array('title' => $language->title_native), true);
                ?>
			<?php 
            } else {
                ?>
 /**
  * Add parse rule to router.
  *
  * @param   JRouter  &$router  JRouter object.
  * @param   JUri     &$uri     JUri object.
  *
  * @return  void
  *
  * @since   1.6
  */
 public function parseRule(&$router, &$uri)
 {
     // Did we find the current and existing language yet?
     $found = false;
     // Are we in SEF mode or not?
     if ($this->mode_sef) {
         $path = $uri->getPath();
         $parts = explode('/', $path);
         $sef = $parts[0];
         // If the default prefix should be removed and the SEF prefix is not among those
         // that we have in our system, its the default language and we "found" the right language
         if ($this->params->get('remove_default_prefix', 0) && !isset($this->sefs[$sef])) {
             $found = true;
             $lang_code = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
         } else {
             // If the language prefix should always be present or it is indeed , we can now look it up in our array
             if (isset($this->sefs[$sef])) {
                 // We found our language
                 $found = true;
                 $lang_code = $this->sefs[$sef]->lang_code;
             }
             // If we found our language, but its the default language and we don't want a prefix for that, we are on a wrong URL
             if ($this->params->get('remove_default_prefix', 0) && $lang_code == JComponentHelper::getParams('com_languages')->get('site', 'en-GB')) {
                 $found = false;
                 array_shift($parts);
                 $path = implode('/', $parts);
             }
             // We have found our language and the first part of our URL is the language prefix
             if ($found) {
                 array_shift($parts);
                 $uri->setPath(implode('/', $parts));
             }
         }
     } else {
         // We are not in SEF mode
         $lang = $uri->getVar('lang');
         if (isset($this->sefs[$lang])) {
             // We found our language
             $found = true;
             $lang_code = $this->sefs[$lang]->lang_code;
         }
     }
     // We are called via POST. We don't care about the language
     // and simply set the default language as our current language.
     if ($this->app->input->getMethod() == "POST" || count($this->app->input->post) > 0 || count($this->app->input->files) > 0) {
         $found = true;
         $lang_code = $this->app->input->cookie->getString(JApplicationHelper::getHash('language'));
         if ($this->params->get('detect_browser', 1) && !$lang_code) {
             $lang_code = JLanguageHelper::detectLanguage();
         }
         if (!isset($this->lang_codes[$lang_code])) {
             $lang_code = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
         }
     }
     // We have not found the language and thus need to redirect
     if (!$found) {
         // Lets find the default language for this user
         if (!isset($lang_code) || !isset($this->lang_codes[$lang_code])) {
             $lang_code = false;
             if ($this->params->get('detect_browser', 1)) {
                 $lang_code = JLanguageHelper::detectLanguage();
                 if (!isset($this->lang_codes[$lang_code])) {
                     $lang_code = false;
                 }
             }
             if (!$lang_code) {
                 $lang_code = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
             }
             // Either we detected the language via the browser or we got it from the cookie. In worst case
             // we fall back to the application setting
             $lang_code = $this->app->input->cookie->getString(JApplicationHelper::getHash('language'), $lang_code);
         }
         if ($this->mode_sef) {
             // Use the current language sef or the default one.
             if (!$this->params->get('remove_default_prefix', 0) || $lang_code != JComponentHelper::getParams('com_languages')->get('site', 'en-GB')) {
                 $path = $this->lang_codes[$lang_code]->sef . '/' . $path;
             }
             $uri->setPath($path);
             if (!$this->app->get('sef_rewrite')) {
                 $uri->setPath('index.php/' . $uri->getPath());
             }
             $this->app->redirect($uri->base() . $uri->toString(array('path', 'query', 'fragment')));
         } else {
             $uri->setVar('lang', $this->lang_codes[$lang_code]->sef);
             $this->app->redirect($uri->base() . 'index.php?' . $uri->getQuery());
         }
     }
     // We have found our language and now need to set the cookie and the language value in our system
     $array = array('lang' => $lang_code);
     $this->default_lang = $lang_code;
     // Set the request var.
     $this->app->input->set('language', $lang_code);
     $this->app->set('language', $lang_code);
     $language = JFactory::getLanguage();
     if ($language->getTag() != $lang_code) {
         $newLang = JLanguage::getInstance($lang_code);
         foreach ($language->getPaths() as $extension => $files) {
             $newLang->load($extension);
         }
         JFactory::$language = $newLang;
         $this->app->loadLanguage($newLang);
     }
     // Create a cookie.
     if ($this->app->input->cookie->getString(JApplicationHelper::getHash('language')) != $lang_code) {
         $cookie_domain = $this->app->get('cookie_domain');
         $cookie_path = $this->app->get('cookie_path', $uri->base(true));
         $this->app->input->cookie->set(JApplicationHelper::getHash('language'), $lang_code, $this->getLangCookieTime(), $cookie_path, $cookie_domain);
     }
     return $array;
 }