Exemple #1
0
 /**
  * Event handler to get user preference.
  *
  * @return  void
  */
 public function onAfterInitialise()
 {
     // Initialize JSN Mobilize
     require_once dirname(__FILE__) . '/define.php';
     if (!class_exists('JSNConfigHelper')) {
         return;
     }
     $app = JFactory::getApplication();
     self::$_app = JFactory::getApplication();
     if (!self::$_app->isAdmin()) {
         require_once dirname(__FILE__) . '/libraries/joomlashine/client/mobiledetect.php';
         $detect = new JSN_Mobile_Detect();
         $deviceType = $detect->isMobile() ? 'mobilize' : 'desktop';
         if (isset($_GET['switch_to_desktop_ui'])) {
             $session =& JFactory::getSession();
             $session->set('switch', $_GET['switch_to_desktop_ui']);
         } else {
             $session =& JFactory::getSession();
             $switch = $session->get('switch');
             if (!isset($_GET['jsn_mobilize_preview'])) {
                 if ($switch == 1 && $deviceType == 'mobilize') {
                     $link = JURI::base() . '?switch_to_desktop_ui=1';
                     JFactory::getApplication()->redirect($link);
                 }
             }
         }
         // Get parsed request URI object
         $jUri = JURI::getInstance();
         // Get application object
         $config = JFactory::getConfig();
         $rewrite = $config->get("sef_rewrite") ? "/" : "/index.php/";
         // Get JSN Mobilize configuration
         $linkMobilize = JURI::root(true) . $rewrite;
         self::$_cfg = JSNConfigHelper::get('com_mobilize');
         self::$_cfg->set('link_mobilize', $linkMobilize);
         // Check cookie
         $urlRequest = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : "";
         $getPreView = !empty($_GET['jsn_mobilize_preview']) ? (int) $_GET['jsn_mobilize_preview'] : '';
         if ($getPreView == 1) {
             $deviceType = 'mobilize';
         }
         if ($getPreView != 1 && $deviceType == "desktop") {
             self::$_device = "";
         }
         // Continue only if not in administrator section
         if (!self::$_app->isAdmin()) {
             // Does user prefer desktop site?
             if (self::$_app->input->getInt('switch_to_desktop_ui') == 1) {
                 self::$_device = 'desktop';
             } elseif (self::$_app->input->getInt('switch_to_desktop_ui') == 2) {
                 $device = $deviceType;
                 self::$_device = $device;
             }
             if (!isset(self::$_device)) {
                 self::$_device = $deviceType;
             }
             require_once JPATH_BASE . '/templates/jsn_mobilize/helpers/mobilize.php';
             if ($getPreView == 1) {
                 $mCfg = JSNMobilizeTemplateHelper::getConfig(self::$_device, true);
             } else {
                 $mCfg = JSNMobilizeTemplateHelper::getConfig(self::$_device);
             }
             if (!empty($device)) {
                 $deviceUi = $device . "_ui_enabled";
             } else {
                 $deviceUi = "";
             }
             // Check if mobile/tablet UI is enabled?
             if ($getPreView != 1 && $deviceType == "desktop" && $deviceUi) {
                 if (!self::$_app->input->getInt('jsn_mobilize_preview') and !$mCfg->get($deviceUi) and self::$_device == "mobilize") {
                     self::$_device = 'desktop';
                 }
             }
             // Do some preparation for mobile/tablet site rendering
             if (self::$_device == "mobilize") {
                 // Reparse request URI
                 $jUri->parse($jUri->toString());
             }
             // Load language file
             $this->_loadLanguage();
             $router = $app->getRouter();
             self::$mode_sef = $router->getMode() == JROUTER_MODE_SEF ? true : false;
             // attach build rules for Preview SEF
             $router->attachBuildRule(array($this, 'buildRule'));
             // attach parse rules for language SEF
             $router->attachParseRule(array($this, 'parseRule'));
         }
         if (JPluginHelper::isEnabled('system', 'cache') && version_compare(JVERSION, '3.0.0', '>=')) {
             if ($getPreView != 1) {
                 if ($detect->isMobile() && !$detect->isTablet()) {
                     $cacheKey = 'mobile';
                 } elseif ($detect->isTablet()) {
                     $cacheKey = 'tablet';
                 } else {
                     $cacheKey = 'desktop';
                 }
             } else {
                 $cacheKey = time();
             }
             $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 = 'jsnmobilize' . $cacheKey . 'jsnmobilize' . $object->_cache_key;
                 }
             }
         }
     }
 }
 /**
  * Event handler to get user preference.
  *
  * @return  void
  */
 public function onAfterInitialise()
 {
     // Initialize JSN Mobilize
     require_once dirname(__FILE__) . '/define.php';
     if (!class_exists('JSNConfigHelper')) {
         return;
     }
     $app = JFactory::getApplication();
     self::$_app = JFactory::getApplication();
     if (!self::$_app->isAdmin()) {
         require_once dirname(__FILE__) . '/libraries/joomlashine/client/mobiledetect.php';
         $detect = new JSN_Mobile_Detect();
         $deviceType = $detect->isMobile() ? 'mobilize' : 'desktop';
         // Get parsed request URI object
         $jUri = JURI::getInstance();
         // Get application object
         $config = JFactory::getConfig();
         $rewrite = $config->get("sef_rewrite") ? "/" : "/index.php/";
         // Get JSN Mobilize configuration
         $linkMobilize = JURI::root(true) . $rewrite;
         self::$_cfg = JSNConfigHelper::get('com_mobilize');
         self::$_cfg->set('link_mobilize', $linkMobilize);
         // Check cookie
         $urlRequest = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : "";
         $getPreView = !empty($_GET['jsn_mobilize_preview']) ? (int) $_GET['jsn_mobilize_preview'] : '';
         if ($getPreView == 1) {
             $deviceType = 'mobilize';
         }
         if ($getPreView != 1 && $deviceType == "desktop") {
             self::$_device = "";
         }
         // Continue only if not in administrator section
         if (!self::$_app->isAdmin()) {
             // Does user prefer desktop site?
             if (self::$_app->input->getInt('switch_to_desktop_ui') == 1) {
                 self::$_device = 'desktop';
             } elseif (self::$_app->input->getInt('switch_to_desktop_ui') == 2) {
                 $device = $deviceType;
                 self::$_device = $device;
             }
             if (!isset(self::$_device)) {
                 self::$_device = $deviceType;
             }
             require_once JPATH_BASE . '/templates/jsn_mobilize/helpers/mobilize.php';
             if ($getPreView == 1) {
                 $mCfg = JSNMobilizeTemplateHelper::getConfig(self::$_device, true);
             } else {
                 $mCfg = JSNMobilizeTemplateHelper::getConfig(self::$_device);
             }
             if (!empty($device)) {
                 $deviceUi = $device . "_ui_enabled";
             } else {
                 $deviceUi = "";
             }
             // Check if mobile/tablet UI is enabled?
             if ($getPreView != 1 && $deviceType == "desktop" && $deviceUi) {
                 if (!self::$_app->input->getInt('jsn_mobilize_preview') and !$mCfg->get($deviceUi) and self::$_device == "mobilize") {
                     self::$_device = 'desktop';
                 }
             }
             // Do some preparation for mobile/tablet site rendering
             if (self::$_device == "mobilize") {
                 // Reparse request URI
                 $jUri->parse($jUri->toString());
             }
             // Load language file
             $this->_loadLanguage();
             $router = $app->getRouter();
             self::$mode_sef = $router->getMode() == JROUTER_MODE_SEF ? true : false;
             // attach build rules for Preview SEF
             $router->attachBuildRule(array($this, 'buildRule'));
             // attach parse rules for language SEF
             $router->attachParseRule(array($this, 'parseRule'));
         }
     }
 }