Esempio n. 1
0
 /**
  * Inject UI switcher into default desktop template.
  *
  * @param   string  $device  Detected client device type.
  * @param   string  $html    Response body generated by Joomla.
  *
  * @return  void
  */
 private static function _injectUISwitcher($device, $html = '')
 {
     $lang = JFactory::getLanguage();
     self::$_app = JFactory::getApplication();
     $lang->load('plg_system_jsnmobilize', JPATH_ADMINISTRATOR);
     $detect = new JSN_Mobile_Detect();
     $textSwitcher = '';
     if ($detect->isMobile() && !$detect->isTablet()) {
         $textSwitcher = 'JSN_MOBILIZE_SWITCH_TO_WEB_UI_FOR_MOBILE';
     } else {
         if ($detect->isMobile() && $detect->isTablet()) {
             $textSwitcher = 'JSN_MOBILIZE_SWITCH_TO_WEB_UI_FOR_TABLET';
         } else {
             $textSwitcher = 'Switch To Mobile';
         }
     }
     // Initialize response body
     !empty($html) or $html = JResponse::getBody();
     // Get parsed request URI object
     $jUri = JURI::getInstance();
     // Build URI for switching back to mobile/tablet site
     if (substr($link = self::$_cfg->get("link_{$device}"), 0, 1) == '/') {
         $switch = str_replace(JURI::root(true), '/' . trim($link, '/'), $jUri->toString());
     } else {
         $switch = str_replace($jUri->getHost(), $link, $jUri->toString());
     }
     $getPreView = !empty($_GET['jsn_mobilize_preview']) ? $_GET['jsn_mobilize_preview'] : '';
     // Get input object
     $input = self::$_app->input;
     // Set necessary variables to request array
     $urlRequest = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : "";
     if ($getPreView == 1) {
         $url = JURI::root() . '?switch_to_desktop_ui=0&jsn_mobilize_preview=1';
     } else {
         $url = JURI::root() . '?switch_to_desktop_ui=0';
     }
     $switch = preg_replace('/(\\?|&)switch_to_desktop_ui=1/', '', $switch);
     // Get user selected style
     $style = self::$_cfg->get('style', 'default');
     // Inject UI switcher assets
     $html = str_replace('</head>', "\t" . '<link media="screen" type="text/css" href="' . JURI::root(true) . '/templates/jsn_mobilize/css/switcher.css" rel="stylesheet" />' . "\n</head>", $html);
     // Inject UI switcher link
     $html = str_replace('</body>', "\t" . '<div class="mobilize-ui-switcher"><a id="jsn-mobilize-ui-switcher" class="btn" href="' . $url . '" title="' . JText::_($textSwitcher) . '">' . JText::_($textSwitcher) . '</a></div>' . "\n</body>", $html);
     // Set manipulated HTML code
     JResponse::setBody($html);
 }
Esempio n. 2
0
 /**
  * Get options design os support
  *
  * @param   String  $type     Type OS
  * @param   String  $version  Version OS
  * @param   String  $device   Device
  *
  * @return stdClass
  */
 public static function getOSSupport($type, $version, $device)
 {
     // Get database object
     $db = JFactory::getDbo();
     // Build query to load module data
     $query = $db->getQuery(true);
     $query->select('*');
     $query->from('#__jsn_mobilize_os');
     $query->where('os_type = ' . $db->Quote($type));
     $db->setQuery($query);
     $lisOS = $db->loadObjectList();
     $support = "";
     if (!empty($version)) {
         $ver = explode(".", $version);
         if (!empty($ver[1])) {
             $version = $ver[0] . '.' . $ver[1];
         } else {
             $version = $ver[0];
         }
     }
     if ($type != "other") {
         foreach ($lisOS as $os) {
             $osValue = json_decode($os->os_value);
             if (!empty($osValue)) {
                 foreach ($osValue as $value) {
                     if (!empty($value[1]) && !empty($value[0]) && $value[1] == "<") {
                         if (is_float($value[0]) && version_compare($value[0], $version, ">=")) {
                             $support = $os->os_id;
                         } elseif (version_compare($value[0], (int) $version, ">=")) {
                             $support = $os->os_id;
                         }
                     } elseif (!empty($value[1]) && !empty($value[0]) && $value[1] == ">") {
                         if (is_float($value[0]) && version_compare($value[0], $version, "<=")) {
                             $support = $os->os_id;
                         } elseif (version_compare($value[0], (int) $version, "<=")) {
                             $support = $os->os_id;
                         }
                     } elseif (empty($value[1]) && !empty($value[0])) {
                         if (is_float($value[0]) && version_compare($value[0], $version, "=")) {
                             $support = $os->os_id;
                         } elseif (version_compare($value[0], (int) $version, "=")) {
                             $support = $os->os_id;
                         }
                     } elseif (!empty($value[1]) && !empty($value[0])) {
                         if (version_compare($value[0], $version, "=") || version_compare($value[1], $version, "=")) {
                             $support = $os->os_id;
                         }
                     }
                 }
             }
         }
         if (empty($support)) {
             return false;
         }
     } else {
         $support = $lisOS[0]->os_id;
     }
     $detect = new JSN_Mobile_Detect();
     $pfl_device = $detect->isTablet() ? '"jsn_tablet"' : '"jsn_mobile"';
     $query = $db->getQuery(true);
     $query->select('*');
     $query->from('#__jsn_mobilize_profiles AS p');
     $query->join('INNER', '#__jsn_mobilize_os_support AS s ON s.profile_id = p.profile_id');
     $query->where('s.os_id = ' . $db->Quote($support));
     $query->where('p.profile_state = 1 AND p.profile_device = ' . $pfl_device);
     //		$query->order( "p.ordering" );
     $db->setQuery($query, 0, 1);
     $profile = $db->loadObject();
     $profileID = !empty($profile->profile_id) ? $profile->profile_id : '';
     $query = $db->getQuery(true);
     $query->select('*');
     $query->from('#__jsn_mobilize_design');
     $query->where('profile_id = ' . $db->Quote($profileID));
     $db->setQuery($query);
     $dataDesign = $db->loadObjectList();
     $optionDesign = new stdClass();
     if (!empty($dataDesign)) {
         foreach ($dataDesign as $item) {
             $name = $item->name;
             $value = json_decode($item->value);
             if (!empty($value)) {
                 $optionDesign->{$name} = $value;
             } else {
                 $optionDesign->{$name} = $item->value;
             }
         }
     }
     $session = JFactory::getSession();
     $session->set('jsn_mobilize_profile', $profile);
     return $optionDesign;
 }
Esempio n. 3
0
 /**
  * Get configuration for device in use.
  *
  * @param   array    $device   Device in use: mobile or tablet?
  * @param   boolean  $preview  Get config from cookie for backend previewing?
  *
  * @return  JObject
  */
 public static function getConfig($device = '', $preview = false)
 {
     // Initialize client device type
     !empty($device) or $device = JFactory::getApplication()->input->getCmd('_device');
     if (!isset(self::$config) or !isset(self::$config[$device])) {
         // Get JSN Mobilize configuration
         if ($preview) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('*')->from('#__jsn_mobilize_config')->where("name = 'tmp_config'");
             $db->setQuery($query, 0, 1);
             $tmpConfig = $db->loadObject();
             if (!empty($tmpConfig->value)) {
                 $config = json_decode($tmpConfig->value);
             }
         } else {
             $detect = new JSN_Mobile_Detect();
             $checkIOS = '';
             if ($detect->isiOS()) {
                 if ($detect->isTablet()) {
                     $version = $detect->version('iPad');
                 } else {
                     $version = $detect->version('iPhone');
                 }
                 $config = JSNMobilizeTemplateHelper::getOSSupport('ios', $version, $device);
             } elseif ($detect->isAndroidOS()) {
                 $version = $detect->version('Android');
                 $config = JSNMobilizeTemplateHelper::getOSSupport('android', $version, $device);
             } elseif ($detect->isWindowsPhoneOS()) {
                 $version = $detect->version('Windows Phone OS');
                 $config = JSNMobilizeTemplateHelper::getOSSupport('wmobilie', $version, $device);
             } elseif ($detect->isBlackBerryOS()) {
                 $version = $detect->version('BlackBerry');
                 $config = JSNMobilizeTemplateHelper::getOSSupport('blackberry', $version, $device);
             } else {
                 $config = JSNMobilizeTemplateHelper::getOSSupport('other', '', $device);
             }
             if ($config === false) {
                 $config = JSNMobilizeTemplateHelper::getOSSupport('other', '', $device);
             }
         }
         if (!empty($config)) {
             foreach (get_object_vars($config) as $k => $v) {
                 isset($tmp) or $tmp = new JObject();
                 if (strpos($k, "{$device}-") === 0) {
                     // Shorten parameter name
                     $k = substr($k, strlen("{$device}-"));
                     // Set new parameter with cleaned name
                     $tmp->set($k, is_object($v) ? (array) $v : $v);
                 } elseif (!preg_match('/^(mobilize)-/', $k)) {
                     // Store shared parameter also
                     $tmp->set($k, is_object($v) ? (array) $v : $v);
                 }
             }
         }
         // Store device specific parameters
         if (!empty($tmp)) {
             self::$config[$device] = $tmp;
         }
         // Get device specific parameters
     }
     return self::$config[$device];
 }