示例#1
0
/**
 * return the device type: mobile, tablet or desktop
 *
 * @return string
 */
function get_device()
{
    $device = pwg_get_session_var('device');
    if (is_null($device)) {
        include_once PHPWG_ROOT_PATH . 'include/mdetect.php';
        $uagent_obj = new uagent_info();
        if ($uagent_obj->DetectSmartphone()) {
            $device = 'mobile';
        } elseif ($uagent_obj->DetectTierTablet()) {
            $device = 'tablet';
        } else {
            $device = 'desktop';
        }
        pwg_set_session_var('device', $device);
    }
    return $device;
}
 /**
  * Device Detection
  *
  * Detect the user's device by using the MobileESP library written by Anthony Hand [http://blog.mobileesp.com/].
  * Return the string name of their device.
  *
  * @internal         Called during object instantiation
  * @uses             get_option, uagent_info
  * @param    void
  * @return   string  The current user's device in one of four options:
  *                      active, handheld, tablet, low_support
  */
 public function detect_users_device()
 {
     //Default is active (default computer theme set by the admin) until it's overridden
     $device = 'active';
     $low_support_device = 'handheld';
     $low_support_theme = get_option('dts_low_support_theme');
     // Give the handheld theme to any low_support device
     // UNLESS one has been set in the admin already
     if (!empty($low_support_theme) && is_array($low_support_theme)) {
         if (isset($low_support_theme['name'])) {
             if (!empty($low_support_theme['name'])) {
                 //Detect if the device is a low support device (poor css and javascript rendering / older devices)
                 $low_support_device = 'low_support';
             }
             // end if
         }
         // end if
     }
     // end if
     // Check for Varnish Device Detect: https://github.com/varnish/varnish-devicedetect/
     // Thanks to Tim Broder for this addition! https://github.com/broderboy | http://timbroder.com/
     $http_xua_handheld_devices = array('mobile-iphone', 'mobile-android', 'mobile-firefoxos', 'mobile-smartphone', 'mobile-generic');
     $http_xua_tablet_devices = array('tablet-ipad', 'tablet-android');
     // Determine if the HTTP X UA server variable is present
     if (isset($_SERVER['HTTP_X_UA_DEVICE'])) {
         // if it is, determine which device type is being used
         if (in_array($_SERVER['HTTP_X_UA_DEVICE'], $http_xua_handheld_devices)) {
             $device = 'handheld';
         } elseif (in_array($_SERVER['HTTP_X_UA_DEVICE'], $http_xua_tablet_devices)) {
             $device = 'tablet';
         }
     } else {
         // DEFAULT ACTION - Use MobileESP to sniff the UserAgent string
         // Include the MobileESP code library for acertaining device user agents
         include_once 'mobile-esp.php';
         // Setup the MobileESP Class
         $ua = new uagent_info();
         // Detect if the device is a handheld
         if ($ua->DetectSmartphone() || $ua->DetectTierRichCss()) {
             $device = 'handheld';
         }
         // Detect if the device is a tablet
         if ($ua->DetectTierTablet() || $ua->DetectKindle() || $ua->DetectAmazonSilk()) {
             $device = 'tablet';
         }
         // Detect if the device is a low_support device (poor javascript and css support / text-only)
         if ($ua->DetectBlackBerryLow() || $ua->DetectTierOtherPhones()) {
             $device = $low_support_device;
         }
     }
     // end if
     // Return the user's device
     return $device;
 }
function buildSubnav($skel, $section, $subsections)
{
    $result = "\t<div class=\"subnavbar\">\n";
    $uagent_obj = new uagent_info();
    if ($uagent_obj->DetectSmartphone()) {
        //$result .= "\t<h2>" . $skel['sectionname'] . "</h2>\n";
        $result .= "\t\t<ul>\n";
        for ($i = 0; $i < count($subsections); $i++) {
            if ('' != trim($subsections[$i])) {
                $pagekey = getKey($subsections[$i]);
                $page = getValue($subsections[$i]);
                if ('#' != $pagekey[0] && '' != trim($page)) {
                    if (isset($skel['page']) && $pagekey == $skel['page']) {
                        $active = ' class="highlight"';
                    } else {
                        $active = '';
                    }
                    $result .= "\t\t\t<li><a href=\"" . $skel['base_uri'] . 'page/' . $section . '/' . $pagekey . '/"' . $active . '>' . trim($page) . "</a></li>\n";
                }
            }
        }
        $result .= "\t\t</ul>\n";
        /*
        		$result .= "\t\t<ul class=\"info\">\n";
        		$result .= "\t\t\t<li><form action=\"http://www.google.com/search\" method=\"get\"><input type=\"hidden\" name=\"q\" value=\"site:aquariusoft.org\" /><input type=\"text\" class=\"searchfield\" name=\"q\" size=\"20\" /><input type=\"submit\" value=\"find\" /></form></li>\n";
        		$result .= "\t\t</ul>\n"; 
        		$uagent_obj = new uagent_info();
        		if (!$uagent_obj->DetectSmartphone())
        		{
        			$result .= "\t\t<ul class=\"info\">\n";
        			$result .= "\t\t\t<li><a href=\"http://www.mozilla.com/firefox/\" title=\"Get Firefox - Web Browsing Redefined [and take back the web]\"><img src=\"images/firefox_pixel.png\" alt=\"Get Firefox\"/></a></li>\n";
        			$result .= "\t\t\t<li><a href=\"http://www.mozilla.com/thunderbird/\" title=\"Get Thunderbird and reclaim your inbox!\"><img src=\"images/thunderbird_pixel.png\" alt=\"Get Thunderbird\"/></a></li>\n";
        			$result .= "\t\t</ul>\n";
        		}
        		$result .= "\t\t<ul class=\"info\">\n";
        		$result .= "\t\t\t<li><a href=\"http://aquariusoft.org/page/html/qik/\">build with qik</a></li>\n";
        		$result .= "\t\t</ul>\n";
        */
    } else {
        /* regular site */
        for ($i = 0; $i < count($subsections); $i++) {
            if ('' != trim($subsections[$i])) {
                $pagekey = getKey($subsections[$i]);
                $page = getValue($subsections[$i]);
                if ('#' != $pagekey[0] && '' != trim($page)) {
                    if (isset($skel['page']) && $pagekey == $skel['page']) {
                        $active = ' class="highlight"';
                    } else {
                        $active = '';
                    }
                    $result .= "<a href=\"" . $skel['base_uri'] . 'page/' . $section . '/' . $pagekey . '/"' . $active . '>' . trim($page) . " </a>";
                }
            }
        }
    }
    return $result . "</div>\n";
}
示例#4
0
 public static function isSmartphone()
 {
     require_once OW_DIR_LIB . 'mobileesp' . DS . 'mdetect.php';
     $obj = new uagent_info();
     return (bool) $obj->DetectSmartphone();
 }