Ejemplo n.º 1
0
// Uncomment if there are language overrides
//if ( $skinLangFile = loadLanguage( ZM_SKIN_PATH ) )
//require_once( $skinLangFile );
if (isset($_GET['devWidth'])) {
    $device['width'] = $_GET['devWidth'];
}
if (isset($_GET['devHeight'])) {
    $device['height'] = $_GET['devHeight'];
}
if (isset($device)) {
    $_SESSION['device'] = $device;
}
$wurflFile = "wurfl/wurfl_class.php";
if (file_exists($wurflFile)) {
    require_once $wurflFile;
    $wurfl = new wurfl_class($wurfl, $wurfl_agents);
    // Set the user agent
    $wurfl->GetDeviceCapabilitiesFromAgent($_SERVER['HTTP_USER_AGENT']);
    //print_r( $wurfl->wurfl_agent );
    if ($wurfl->wurfl_agent) {
        if ($wurfl->getDeviceCapability('html_wi_oma_xhtmlmp_1_0')) {
            $device['width'] = $wurfl->getDeviceCapability('resolution_width');
            $device['height'] = $wurfl->getDeviceCapability('resolution_height');
        }
    }
} else {
    // This is an example of using fixed device strings to just match your phone etc
    $devices = array(array('name' => "Motorola V600", 'ua_match' => "MOT-V600", 'skin' => "mobile", 'cookies' => false, 'width' => 176, 'height' => 220));
    foreach ($devices as $tempDevice) {
        if (preg_match('/' . $tempDevice['ua_match'] . '/', $_SERVER['HTTP_USER_AGENT'])) {
            $skin = $tempDevice['skin'];
 function scaleImages(&$dom, &$serendipity)
 {
     if ($this->get_config('wurfl')) {
         $this->debugItems[] = 'Trying to scale images with WURFL';
         // already did a wurfl check for this device in our session?
         if ($_SESSION['mobile_plugin']['ua'] == $_SERVER['HTTP_USER_AGENT'] && $_SESSION['mobile_plugin']['wurfl']['width']) {
             // got the wurfl result stored in session
             $imageWidth = $_SESSION['mobile_plugin']['wurfl']['width'];
             $this->debugItems[] = 'We don\'t need to query WURFL again as the result was stored in our session';
         } else {
             // load wurfl php
             require_once dirname(__FILE__) . '/wurfl/wurfl_config.php';
             require_once WURFL_CLASS_FILE;
             // create wurfl object
             $W = new wurfl_class();
             $this->debugItems[] = 'WURFL object created';
             // query wurfl
             $W->GetDeviceCapabilitiesFromAgent($_SERVER['HTTP_USER_AGENT']);
             // get maximum image width from wurfl
             $imageWidth = (int) $W->getDeviceCapability('max_image_width') - 20;
         }
         if ($imageWidth < 0) {
             // fallback
             $dom = $this->m->scaleImages($dom, $serendipity, $this->get_config('scale_image_width'), S9Y_PEAR_PATH, $this->debugItems);
             $this->debugItems[] = 'Device not found in WURFL or screen to small. Using maximum image width as fallback';
         } else {
             // found a device
             $_SESSION['mobile_plugin']['wurfl']['width'] = $imageWidth;
             $dom = $this->m->scaleImages($dom, $serendipity, $imageWidth, S9Y_PEAR_PATH, $this->debugItems);
             $this->debugItems[] = 'Device found in WURFL, images were scaled';
         }
     } else {
         if (serendipity_db_bool($this->get_config('wurfl')) && $this->m->isIPhone === true) {
             // fix image width for iphone if not found in wurfl
             $this->debugItems[] = 'Scaling images for iPhone device';
             $dom = $this->m->scaleImages($dom, $serendipity, 300, S9Y_PEAR_PATH, $this->debugItems);
             $this->debugItems[] = 'Scaled all images';
         } else {
             // don't use wurfl
             $dom = $this->m->scaleImages($dom, $serendipity, $this->get_config('scale_image_width'), S9Y_PEAR_PATH, $this->debugItems);
             $this->debugItems[] = 'Scaled all images';
         }
     }
     // store useragent in session to check if it has changed since the last request
     $_SESSION['mobile_plugin']['ua'] = $_SERVER['HTTP_USER_AGENT'];
 }
Ejemplo n.º 3
0
<?php 
/*
 * $Id: check_wurfl.php,v 1.1 2005/04/16 16:01:37 atrasatti Exp $
 * $RCSfile: check_wurfl.php,v $ v2.1 beta2 (Apr, 16 2005)
 *
 * Author: Andrea Trasatti ( atrasatti AT users DOT sourceforge DOT net )
 *
 */
set_time_limit(600);
list($usec, $sec) = explode(" ", microtime());
$start = (double) $usec + (double) $sec;
require_once './wurfl_config.php';
require_once WURFL_CLASS_FILE;
list($usec, $sec) = explode(" ", microtime());
$load_class = (double) $usec + (double) $sec;
$wurflObj = new wurfl_class();
list($usec, $sec) = explode(" ", microtime());
$init_class = (double) $usec + (double) $sec;
if (isset($_GET['force_ua']) && strlen($_GET['force_ua']) > 0) {
    $wurflObj->GetDeviceCapabilitiesFromAgent($_GET['force_ua']);
} else {
    //Forcing a test agent
    $wurflObj->GetDeviceCapabilitiesFromAgent("MOT-c350");
}
list($usec, $sec) = explode(" ", microtime());
$end = (double) $usec + (double) $sec;
echo "Time to load wurfl_class.php:" . ($load_class - $start) . "<br>\n";
echo "Time to initialize class:" . ($init_class - $load_class) . "<br>\n";
echo "Time to find the user agent:" . ($end - $init_class) . "<br>\n";
echo "Total:" . ($end - $start) . "<br>\n";
echo "<pre>";