Example #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);
 }
Example #2
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'];
 }
Example #3
0
 /**
  * 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();
 }
 /**
  * Setup for testing.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function setUp()
 {
     parent::setUp();
     // We are only coupled to Document and Language in JFactory.
     $this->saveFactoryState();
     JFactory::$language = $this->getMockLanguage();
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return  void
  *
  * @since   3.2
  */
 public function setUp()
 {
     parent::setUp();
     // Add JApplication and JLanguage dependencies
     $this->saveFactoryState();
     JFactory::$language = $this->getMockLanguage();
     JFactory::$application = $this->getMockCmsApp();
 }
Example #6
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'] = '';
 }
Example #7
0
 /**
  * Setup for testing.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function setUp()
 {
     parent::setUp();
     $_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
     $_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
     // Get a new JApplicationWebInspector instance.
     $this->inspector = new JApplicationWebInspector();
     // We are only coupled to Document and Language in JFactory.
     $this->saveFactoryState();
     JFactory::$document = $this->getMockDocument();
     JFactory::$language = $this->getMockLanguage();
 }
Example #8
0
 /**
  * Sets the Factory pointers
  *
  * @return  void
  */
 protected function restoreFactoryState()
 {
     \JFactory::$application = $this->savedFactoryState['application'];
     \JFactory::$config = $this->savedFactoryState['config'];
     \JFactory::$dates = $this->savedFactoryState['dates'];
     \JFactory::$session = $this->savedFactoryState['session'];
     \JFactory::$language = $this->savedFactoryState['language'];
     \JFactory::$document = $this->savedFactoryState['document'];
     \JFactory::$acl = $this->savedFactoryState['acl'];
     \JFactory::$database = $this->savedFactoryState['database'];
     \JFactory::$mailer = $this->savedFactoryState['mailer'];
 }
Example #9
0
 /**
  * Setup for testing.
  *
  * @return  void
  *
  * @since   3.1
  */
 public function setUp()
 {
     parent::setUp();
     // Get mock CMS application
     $app = $this->getMockCmsApp();
     $app->expects($this->any())->method('getTemplate')->willReturn('foobar');
     // Whilst we inject the application into this class we still need the language
     // property to be set for JText and the application for inclusion of scripts (such as bootstrap for the tooltips)
     $this->saveFactoryState();
     JFactory::$language = $this->getMockLanguage();
     JFactory::$application = $app;
     $this->app = $app;
 }
 /**
  * Setup for testing.
  *
  * @return  void
  *
  * @since   3.6
  */
 public function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$document = $this->getMockDocument();
     JFactory::$language = $this->getMockLanguage();
     JFactory::$session = $this->getMockSession();
     $this->backupServer = $_SERVER;
     $_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
     $_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
     $_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
     $_SERVER['SCRIPT_NAME'] = '/index.php';
 }
 /**
  * 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::$config = $this->getMockConfig();
     JFactory::$document = $this->getMockDocument();
     JFactory::$language = $this->getMockLanguage();
     JFactory::$session = $this->getMockSession();
     $this->backupServer = $_SERVER;
     $_SERVER['HTTP_HOST'] = 'example.com';
     $_SERVER['SCRIPT_NAME'] = '';
 }
Example #12
0
 /**
  * Prepares the environment before running a test.
  *
  * @return  void
  *
  * @since   1.0
  */
 protected function setUp()
 {
     parent::setUp();
     $_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
     $_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
     $_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     // Get a new JApplicationWebInspector instance.
     $this->_instance = new WebServiceApplicationWebInspector();
     // We are only coupled to Document and Language in JFactory.
     $this->saveFactoryState();
     JFactory::$document = $this->getMockDocument();
     JFactory::$language = $this->getMockLanguage();
 }
Example #13
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);
 }
Example #14
0
 /**
  * Tests the JFactory::getDate method.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function testGetDate()
 {
     JFactory::$language = $this->getMockLanguage();
     $date = JFactory::getDate('2001-01-01 01:01:01');
     $this->assertThat((string) $date, $this->equalTo('2001-01-01 01:01:01'), 'Tests that a date passed in comes back unchanged.');
     $date = JFactory::getDate('now');
     sleep(2);
     $date2 = JFactory::getDate('now');
     $this->assertThat($date2, $this->equalTo($date), 'Tests that the cache for the same time is working.');
     $tz = 'Etc/GMT+0';
     $date = JFactory::getDate('2001-01-01 01:01:01', $tz);
     $this->assertThat((string) $date, $this->equalTo('2001-01-01 01:01:01'), 'Tests that a date passed in with UTC timezone string comes back unchanged.');
     $tz = new DateTimeZone('Etc/GMT+0');
     $date = JFactory::getDate('2001-01-01 01:01:01', $tz);
     $this->assertThat((string) $date, $this->equalTo('2001-01-01 01:01:01'), 'Tests that a date passed in with UTC timezone comes back unchanged.');
 }
Example #15
0
 function display($tpl = null)
 {
     $this->canDo = JCKHelper::getActions();
     $this->app = JFactory::getApplication();
     $this->user = JFactory::getUser();
     $this->state = $this->get('State');
     $this->item = $this->get('Item');
     $this->form = $this->get('Form');
     $this->params = $this->prepareForm($this->item);
     if (!$this->canDo->get('core.edit')) {
         $this->app->redirect(JRoute::_('index.php?option=com_jckman&view=list', false), JText::_('COM_JCKMAN_PLUGIN_PERM_NO_EDIT'), 'error');
         return false;
     }
     //end if
     //language
     $lang = JCKHelper::getLanguage();
     $tag = $lang->getTag();
     JFactory::$language = $lang;
     //override Joomla default language class
     $name = $this->item->name;
     $plugin = 'plg_jck' . $name;
     $pluginOverideFile = JPATH_COMPONENT . '/language/overrides/' . $tag . '.' . $plugin . '.ini';
     $pluginLangFile = JPATH_COMPONENT . '/language/' . $tag . '/' . $tag . '.' . $plugin . '.ini';
     if (JFile::exists($pluginOverideFile)) {
         //check in language overrides to see if user has installed an override language file
         $lang->loadFile($pluginOverideFile, $plugin);
     } else {
         if (JFile::exists($pluginLangFile)) {
             //load core language file if it exists
             $lang->load($plugin, JPATH_COMPONENT);
         } else {
             //load english default languge
             if (JFile::exists(JPATH_COMPONENT . '/language/en-GB/en-GB.plg_jck' . $name . '.ini')) {
                 $lang->load($plugin, JPATH_COMPONENT, 'en-GB');
             }
         }
     }
     $this->item->description = JText::_($this->item->description);
     $this->form->bind($this->item);
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JCKHelper::error(implode("\n", $errors));
         return false;
     }
     $this->addToolbar();
     parent::display($tpl);
 }
 /**
  * Setup for testing.
  *
  * @return  void
  *
  * @since   3.2
  */
 public function setUp()
 {
     parent::setUp();
     $_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
     $_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
     $_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     // Set the config for the app
     $config = new JRegistry();
     $config->set('session', false);
     // Get a new JApplicationCmsInspector instance.
     $this->class = new JApplicationCmsInspector(null, $config);
     // We are coupled to Document and Language in JFactory.
     $this->saveFactoryState();
     JFactory::$document = $this->getMockDocument();
     JFactory::$language = $this->getMockLanguage();
 }
 /**
  * Setup for testing.
  *
  * @return  void
  *
  * @since   3.2
  */
 public function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$document = $this->getMockDocument();
     JFactory::$language = $this->getMockLanguage();
     JFactory::$session = $this->getMockSession();
     $this->backupServer = $_SERVER;
     $_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
     $_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
     $_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     // Set the config for the app
     $config = new Registry();
     $config->set('session', false);
     // Get a new JApplicationSite instance.
     $this->class = new JApplicationSite($this->getMockInput(), $config);
     TestReflection::setValue('JApplicationCms', 'instances', array('site' => $this->class));
 }
Example #18
0
 /**
  * Setup for testing.
  *
  * @return  void
  *
  * @since   3.2
  */
 public function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$document = $this->getMockDocument();
     JFactory::$language = $this->getMockLanguage();
     JFactory::$session = $this->getMockSession();
     $this->backupServer = $_SERVER;
     $_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
     $_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
     $_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     // Set the config for the app
     $config = new Registry();
     $config->set('session', false);
     // Get a new JApplicationCmsInspector instance.
     $this->class = new JApplicationCmsInspector($this->getMockInput(), $config);
     $this->class->setSession(JFactory::$session);
     $this->class->setDispatcher($this->getMockDispatcher());
     JFactory::$application = $this->class;
 }
 /**
  * Test JComponentRouterBase::__construct
  *
  * @return  void
  *
  * @since   3.4
  * @covers  JComponentRouterBase::__construct
  */
 public function testConstruct()
 {
     $app_bkp = JFactory::$application;
     $app = TestMockApplication::create($this);
     JFactory::$application = $app;
     $menu = TestMockMenu::create($this);
     /**
      * Test if standard setup of JComponentRouterBase works and $app and
      * $menu are properly populated
      */
     $object = new JComponentRouterBaseInspector();
     $this->assertInstanceOf('JComponentRouterInterface', $object);
     $this->assertInstanceOf('JComponentRouterBase', $object);
     $this->assertEquals($app, $object->app);
     $this->assertEquals($app->getMenu(), $object->menu);
     $this->assertEquals(null, $object->app->get('value'));
     /**
      * Test if the setup works when an app object is handed over
      * Especially test if the app objects are different
      */
     $app2 = TestMockApplication::create($this);
     $object = new JComponentRouterBaseInspector($app2);
     $this->assertEquals($app2, $object->app);
     //The original $app is not the same object as $app2, thus we did not use JFactory
     $this->assertFalse($app === $object->app);
     /**
      * Test if the setup works when both an app and menu object is handed over
      */
     $menu2 = new stdClass();
     $object = new JComponentRouterBaseInspector($app, $menu2);
     $this->assertEquals($app, $object->app);
     $this->assertEquals($menu2, $object->menu);
     /**
      * Test what happens when no application, but a menu object is handed over
      */
     $object = new JComponentRouterBaseInspector(false, $menu);
     $this->assertEquals($app, $object->app);
     $this->assertEquals($menu, $object->menu);
     JFactory::$language = $app_bkp;
 }
Example #20
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;
 }
Example #21
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');
 }
Example #22
0
 /**
  * Get a language object.
  *
  * Returns the global {@link JLanguage} object, only creating it if it doesn't already exist.
  *
  * @return  JLanguage object
  *
  * @see     JLanguage
  * @since   11.1
  */
 public static function getLanguage()
 {
     if (!self::$language) {
         self::$language = self::createLanguage();
     }
     return self::$language;
 }
Example #23
0
 /**
  * Test...
  *
  * @return void
  */
 public function testGetInputUser_UTC()
 {
     // We create stubs for config and session/user objects
     $config = new JObject();
     // Put the stub in place
     JFactory::$config = $config;
     $sessionMock = $this->getMock('sessionMock', array('get'));
     require_once JPATH_PLATFORM . '/joomla/user/user.php';
     $userObject = new JUser();
     $sessionMock->expects($this->any())->method('get')->with('user')->will($this->returnValue($userObject));
     // Put the stub in place
     JFactory::$session = $sessionMock;
     $languageMock = $this->getMock('languageMock', array('getTag'));
     $languageMock->expects($this->any())->method('getTag')->will($this->returnValue('en-GB'));
     // Put the stub in place
     JFactory::$language = $languageMock;
     // Include our inspector which will allow us to manipulate and call protected methods and attributes
     require_once __DIR__ . '/inspectors/JFormFieldCalendar.php';
     $calendar = new JFormFieldCalendarInspector();
     // Setup our values from our data set
     $calendar->setProtectedProperty('element', array('format' => '%m-%Y-%d', 'size' => '25', 'maxlength' => '45', 'class' => 'myClass', 'readonly' => 'true', 'disabled' => 'false', 'onchange' => '', 'filter' => 'USER_UTC'));
     $calendar->setProtectedProperty('name', 'myElementName');
     $calendar->setProtectedProperty('id', 'myElementId');
     // 1269442718
     $calendar->setProtectedProperty('value', 1269442718);
     // +4
     $config->set('offset', 'Asia/Muscat');
     // We don't set the user param to see if it properly falls back to the server time (as it should)
     // Create the mock to implant into JHtml so that we can check our values
     $mock = $this->getMock('calendarHandler', array('calendar'));
     // Setup the expectation with the values from the dataset
     $mock->expects($this->once())->method('calendar')->with('2010-03-24 18:58:38', 'myElementName', 'myElementId', '%m-%Y-%d', array('size' => '25', 'maxlength' => '45', 'class' => 'myClass', 'readonly' => 'readonly'));
     // Register our mock with JHtml
     JHtml::register('calendar', array($mock, 'calendar'));
     // Invoke our method
     $calendar->getInput();
     // Unregister the mock
     JHtml::unregister('jhtml..calendar');
     // Create the mock to implant into JHtml so that we can check our values
     $mock2 = $this->getMock('calendarHandler', array('calendar'));
     // Setup the expectation with the values from the dataset
     $mock2->expects($this->once())->method('calendar')->with('2010-03-24 22:58:38', 'myElementName', 'myElementId', '%m-%Y-%d', array('size' => '25', 'maxlength' => '45', 'class' => 'myClass', 'readonly' => 'readonly'));
     // -5
     $config->set('offset', 'US/Eastern');
     // +4		// now we set the user param to test it out.
     $userObject->setParam('timezone', 'Asia/Muscat');
     // Register our mock with JHtml
     JHtml::register('calendar', array($mock2, 'calendar'));
     // Invoke our method
     $calendar->getInput();
     // Unregister the mock
     JHtml::unregister('jhtml..calendar');
 }
Example #24
0
 /**
  * @covers FOF30\Platform\Joomla\Platform::loadTranslations
  *
  * @dataProvider FOF30\Tests\Platform\PlatformJoomlaProvider::getTestLoadTranslations
  *
  */
 public function testLoadTranslations($appType, $regularPath, $otherPath, $message)
 {
     $this->forceApplicationTypeAndResetPlatformCliAdminCache($appType);
     $mockLanguage = MockLanguage::create($this);
     MockLanguage::$loadedLanguages = array();
     \JFactory::$language = $mockLanguage;
     $this->platform->loadTranslations('com_foobar');
     $expected = array(array('com_foobar', $regularPath, 'en-GB', true, true), array('com_foobar', $regularPath, null, true, true), array('com_foobar', $otherPath, 'en-GB', true, true), array('com_foobar', $otherPath, null, true, true));
     $this->assertEquals($expected, MockLanguage::$loadedLanguages, $message);
 }
Example #25
0
 /**
  * Tests the JFactory::getDate method.
  *
  * @return  void
  *
  * @since   12.3
  */
 public function testGetDateUTC2()
 {
     JFactory::$language = $this->getMockLanguage();
     $tz = new DateTimeZone('Etc/GMT+0');
     $date = JFactory::getDate('2001-01-01 01:01:01', $tz);
     $this->assertThat((string) $date, $this->equalTo('2001-01-01 01:01:01'), 'Tests that a date passed in with UTC timezone comes back unchanged.');
 }
 /**
  * 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';
         }
     }
     // Execute the parent initialiseApp method.
     parent::initialiseApp($options);
     // Load the language to the API
     $this->loadLanguage();
     // Load the language from the API
     $lang = $this->getLanguage();
     // Register the language object with JFactory
     JFactory::$language = $lang;
     // Load Library language
     $lang->load('lib_joomla', JPATH_ADMINISTRATOR);
 }
Example #27
0
 function loadLocale(&$order)
 {
     $locale = '';
     if (!empty($order->customer->user_cms_id)) {
         $user = JFactory::getUser($order->customer->user_cms_id);
         $locale = $user->getParam('language');
         if (empty($locale)) {
             $locale = $user->getParam('admin_language');
         }
     }
     if (empty($locale)) {
         $params = JComponentHelper::getParams('com_languages');
         $locale = $params->get('site', 'en-GB');
     }
     if (HIKASHOP_J16) {
         $config = JFactory::getConfig();
         $this->oldLocale = $config->get('language');
         $config->set('language', $locale);
         $debug = $config->get('debug');
         if (HIKASHOP_J25) {
             JFactory::$language = new hikaLanguage($locale, $debug);
         }
     }
     $lang = JFactory::getLanguage();
     $override_path = JLanguage::getLanguagePath(JPATH_ROOT) . DS . 'overrides' . DS . $locale . '.override.ini';
     $lang->load(HIKASHOP_COMPONENT, JPATH_SITE, $locale, true);
     if (file_exists($override_path)) {
         if (!HIKASHOP_J16) {
             $lang->_load($override_path, 'override');
         } elseif (HIKASHOP_J25) {
             $lang->publicLoadLanguage($override_path, 'override');
         }
     }
     return $locale;
 }
Example #28
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;
     // 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;
 }
 /**
  * Setup for testing.
  *
  * @return  void
  *
  * @since   11.3
  */
 public function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$document = $this->getMockDocument();
     JFactory::$language = $this->getMockLanguage();
     $this->backupServer = $_SERVER;
     $_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
     $_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
     $_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     // Get a new JApplicationWebInspector instance.
     $this->class = new JApplicationWebInspector();
 }
Example #30
0
 /**
  * Get a language object
  *
  * Returns the global {@link JLanguage} object, only creating it
  * if it doesn't already exist.
  *
  * @return object JLanguage
  */
 public static function getLanguage()
 {
     if (!is_object(JFactory::$language)) {
         //get the debug configuration setting
         $conf =& JFactory::getConfig();
         $debug = $conf->getValue('config.debug_lang');
         JFactory::$language = JFactory::_createLanguage();
         JFactory::$language->setDebug($debug);
     }
     return JFactory::$language;
 }