/**
  * Test the setPort method.
  *
  * @return  void
  *
  * @since   11.1
  * @covers  JUri::setPort
  */
 public function testSetPort()
 {
     $this->object->setPort('8888');
     $this->assertThat($this->object->getPort(), $this->equalTo('8888'));
 }
Exemplo n.º 2
0
 function onAfterInitialise()
 {
     /** @var JSite $app */
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         // don't use MobileJoomla in backend
         return;
     }
     $is_joomla15 = $this->isJoomla15();
     //load MobileJoomla class
     require_once JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/classes/mobilejoomla.php';
     //load config
     $MobileJoomla_Settings =& MobileJoomla::getConfig();
     $MobileJoomla_Device =& MobileJoomla::getDevice();
     // check for legacy redirect
     if (@$_GET['option'] == 'com_mobilejoomla' && @$_GET['task'] == 'setmarkup' && isset($_GET['markup']) && isset($_GET['return'])) {
         $desktop_uri = new JUri($MobileJoomla_Settings['desktop_url']);
         $uri = new JUri(base64_decode($_GET['return']));
         if (!$uri->getScheme()) {
             $uri->setScheme('http');
         }
         $uri->setHost($desktop_uri->getHost());
         $uri->setPort($desktop_uri->getPort());
         $app->redirect($uri->toString());
     }
     JPluginHelper::importPlugin('mobile');
     $cached_data = $app->getUserState('mobilejoomla.cache');
     if ($cached_data !== null) {
         $cached_data = @gzinflate(@base64_decode($cached_data));
         if ($cached_data !== false) {
             $cached_data = @unserialize($cached_data);
         }
     }
     if (is_array($cached_data)) {
         $MobileJoomla_Device = $cached_data['device'];
     } else {
         $app->triggerEvent('onDeviceDetection', array(&$MobileJoomla_Settings, &$MobileJoomla_Device));
         $gzlevel = 5;
         $cached_data = array('device' => $MobileJoomla_Device);
         $cached_data = base64_encode(gzdeflate(serialize($cached_data), $gzlevel));
         $app->setUserState('mobilejoomla.cache', $cached_data);
     }
     $MobileJoomla_Device['markup'] = self::CheckMarkup($MobileJoomla_Device['markup']);
     $MobileJoomla_Device['real_markup'] = $MobileJoomla_Device['markup'];
     $app->triggerEvent('onAfterDeviceDetection', array(&$MobileJoomla_Settings, &$MobileJoomla_Device));
     $MobileJoomla_Device['markup'] = self::CheckMarkup($MobileJoomla_Device['markup']);
     $markup = $MobileJoomla_Device['markup'];
     $MobileJoomla_Device['default_markup'] = $markup;
     //get user choice
     $user_markup = $this->getUserMarkup();
     if ($user_markup !== false) {
         $markup = $user_markup;
     }
     // template preview
     $getTemplate = isset($_GET['template']) ? $_GET['template'] : null;
     if (version_compare(JVERSION, '1.7', '>=')) {
         if ($getTemplate === null && isset($_GET['templateStyle']) && is_int($_GET['templateStyle'])) {
             $db = JFactory::getDBO();
             $query = 'SELECT template FROM #__template_styles WHERE id = ' . intval($_GET['templateStyle']) . ' AND client_id = 0';
             $db->setQuery($query);
             $getTemplate = $db->loadResult();
         }
     } elseif (version_compare(JVERSION, '1.6', '>=')) {
         if (is_int($getTemplate)) {
             $db = JFactory::getDBO();
             $query = 'SELECT template FROM #__template_styles WHERE id = ' . intval($getTemplate) . ' AND client_id = 0';
             $db->setQuery($query);
             $getTemplate = $db->loadResult();
         }
     }
     if ($getTemplate) {
         switch ($getTemplate) {
             case $MobileJoomla_Settings['xhtml.template']:
                 $markup = 'xhtml';
                 break;
             case $MobileJoomla_Settings['iphone.template']:
                 $markup = 'iphone';
                 break;
             case $MobileJoomla_Settings['wml.template']:
                 $markup = 'wml';
                 break;
             case $MobileJoomla_Settings['chtml.template']:
                 $markup = 'chtml';
                 break;
         }
     }
     $MobileJoomla_Device['markup'] = $markup;
     if ($MobileJoomla_Device['screenwidth'] == 0 || $MobileJoomla_Device['screenheight'] == 0) {
         switch ($markup) {
             case 'wml':
                 $MobileJoomla_Device['screenwidth'] = 64;
                 $MobileJoomla_Device['screenheight'] = 96;
                 break;
             case 'chtml':
                 $MobileJoomla_Device['screenwidth'] = 120;
                 $MobileJoomla_Device['screenheight'] = 128;
                 break;
             case 'xhtml':
                 $MobileJoomla_Device['screenwidth'] = 320;
                 $MobileJoomla_Device['screenheight'] = 480;
                 break;
             case 'iphone':
                 $MobileJoomla_Device['screenwidth'] = 320;
                 $MobileJoomla_Device['screenheight'] = 480;
                 break;
         }
     }
     if ($MobileJoomla_Device['imageformats'] === null) {
         switch ($markup) {
             case 'wml':
                 $MobileJoomla_Device['imageformats'] = array('wbmp');
                 break;
             case 'chtml':
                 $MobileJoomla_Device['imageformats'] = array('gif');
                 break;
             case 'xhtml':
             case 'iphone':
                 $MobileJoomla_Device['imageformats'] = array('png', 'gif', 'jpg');
                 break;
         }
     }
     if (count($MobileJoomla_Device['imageformats']) == 0) {
         $MobileJoomla_Settings['wml.img'] = 1;
         $MobileJoomla_Settings['chtml.img'] = 1;
         $MobileJoomla_Settings['xhtml.img'] = 1;
         $MobileJoomla_Settings['iphone.img'] = 1;
     }
     $app->triggerEvent('onBeforeMobileMarkupInit', array(&$MobileJoomla_Settings, &$MobileJoomla_Device));
     $MobileJoomla_Device['markup'] = self::CheckMarkup($MobileJoomla_Device['markup']);
     $this->updateUserMarkup();
     $app->triggerEvent('onMobileMarkupInit', array(&$MobileJoomla_Settings, &$MobileJoomla_Device));
     $markup = $MobileJoomla_Device['markup'];
     if (empty($markup)) {
         $MobileJoomla_Device['markup'] = false;
         return;
     }
     $MobileJoomla = MobileJoomla::getInstance($markup);
     // set headers here to be compatible with System-Cache
     $MobileJoomla->setHeader();
     if ($MobileJoomla_Settings['mobile_sitename']) {
         $this->setConfig('sitename', $MobileJoomla_Settings['mobile_sitename']);
     }
     if (!$is_joomla15) {
         if (!$MobileJoomla_Settings['caching']) {
             $this->setConfig('caching', 0);
         }
         $cachekey = MobileJoomla::getCacheKey();
         $registeredurlparams = isset($app->registeredurlparams) ? $app->registeredurlparams : null;
         if (empty($registeredurlparams)) {
             $registeredurlparams = new stdClass();
         }
         $this->setRequestVar('mjcachekey', $cachekey);
         $registeredurlparams->mjcachekey = 'CMD';
         $this->setRequestVar('mjurlkey', JRequest::getURI());
         $registeredurlparams->mjurlkey = 'STRING';
         $app->registeredurlparams = $registeredurlparams;
         //fix System-Cache plugin in J!3.0
         if (JPluginHelper::isEnabled('system', 'cache') && version_compare(JVERSION, '3.0.0', '>=')) {
             $dispatcher = JEventDispatcher::getInstance();
             $refObj = new ReflectionObject($dispatcher);
             $refProp = $refObj->getProperty('_observers');
             $refProp->setAccessible(true);
             $observers = $refProp->getValue($dispatcher);
             foreach ($observers as $index => $object) {
                 if (is_a($object, 'plgSystemCache')) {
                     $object->_cache_key = '~' . $cachekey . '~' . $object->_cache_key;
                 }
             }
         }
     } else {
         if ($MobileJoomla_Settings['caching']) {
             /** @var JRegistry $config */
             $config = JFactory::getConfig();
             $handler = $config->getValue('config.cache_handler', 'file');
             $handler .= '_mj';
             $config->setValue('config.cache_handler', $handler);
             $class = 'JCacheStorage' . ucfirst($handler);
             $path = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/override/cachestorage/' . $handler . '.php';
             jimport('joomla.cache.storage');
             JLoader::register($class, $path);
         } else {
             $this->setConfig('caching', 0);
             //disable System-Cache plugin
             $dispatcher = JDispatcher::getInstance();
             foreach ($dispatcher->_observers as $index => $object) {
                 if (is_a($object, 'plgSystemCache')) {
                     $object->_cache = new _CacheStub();
                     unset($dispatcher->_observers[$index]);
                     break;
                 }
             }
         }
     }
     if (@$_SERVER['REQUEST_METHOD'] != 'POST') {
         $router = $app->getRouter();
         $router->attachBuildRule(array($this, 'buildRule'));
     }
     if (!defined('SHMOBILE_MOBILE_TEMPLATE_SWITCHED')) {
         define('SHMOBILE_MOBILE_TEMPLATE_SWITCHED', 1);
     }
 }