Permalink
Browse files

Bumped to v0.2 (new cache engine + temlplate functions)

  • Loading branch information...
1 parent e7c914c commit c2576d144c280d47e6a0f736a1483cb7c0cfaff3 @colymba committed Jan 29, 2012
View
127 README
@@ -1,39 +1,88 @@
-------------------------------------------------------
-Device Aware v0.1
-SilverStripe module
-by Thierry Francois : colmyba.com
-------------------------------------------------------
-
-------------------------------------------------------
-DETAILS
-------------------------------------------------------
-Adds mobile functionlaities:
-- detection
-- template functions
-- resolutions
-
-Device resolution tools
-- default device resolution (classic and mobile)
-- save current visitor's resolution
-
-Image manipulation
-- image resizing depending on device/visitor resolution
-- pre-generated images (cache)
-
-All configured through _config.php
-
-------------------------------------------------------
-INSTALL
-------------------------------------------------------
-copy folder in your SS install. Run dev/build/
-
-------------------------------------------------------
-CONFIG
-------------------------------------------------------
-Open _config.php
-Add/remove extensions as required
-Reset defaults if required
-Set cache config
-
-
-...Full manual in a bit...
+------------------------------------------------------
+Device Aware v0.2 (29 Jan. 2012)
+SilverStripe module
+by Thierry Francois : colymba.com
+------------------------------------------------------
+
+------------------------------------------------------
+ABOUT
+------------------------------------------------------
+This extension was developed for the needs of responsive layouts
+where image sizes would vary with the user's screen resolution.
+
+
+------------------------------------------------------
+DETAILS
+------------------------------------------------------
+Adds mobile functionlaities:
+- detection
+- template functions
+- resolutions 'database'
+
+Device resolution tools
+- default device resolution (classic and mobile)
+- save current visitor's resolution
+
+Image manipulation
+- image resizing depending on device/visitor resolution
+- pre-generated images (cache)
+
+All configured through _config.php
+
+------------------------------------------------------
+INSTALL
+------------------------------------------------------
+copy folder in your SS install. Run dev/build/
+
+------------------------------------------------------
+CONFIG
+------------------------------------------------------
+Open _config.php
+Add/remove extensions as required
+Reset defaults if required
+Set cache config
+
+------------------------------------------------------
+EXAMPLES
+------------------------------------------------------
+Template code example with sample usage of templates functions
+
+------------------------------------------------------
+<% if isMobile %>
+
+ <% control Image %>
+ <% if Orientation = 2 %>
+ <img <% control deviceOptimizedImageWidthByRatio(0.95) %>src="$URL"<% end_control %> alt="$Name" />
+ <% else %>
+ <img <% control SetHeight(550) %>src="$URL"<% end_control %> alt="$Name" />
+ <% end_if %>
+ <% end_control %>
+
+<% else %>
+
+ <% if Image.isLandscape %>
+
+ <% if screenWidth1600Plus %>
+ <img <% control Image.deviceOptimizedImageWidthByRatio(0.6) %>src="$URL"<% end_control %> alt="$Name" />
+ <% else %>
+ <img <% control Image.deviceOptimizedImageWidthByRatio(0.7) %>src="$URL"<% end_control %> alt="$Name" />
+ <% end_if %>
+
+ <% else %>
+
+ <% if screenHeight1000Plus %>
+ <img <% control Image.SetHeight(700) %>src="$URL"<% end_control %> alt="$Name" />
+ <% else %>
+ <img <% control Image.SetHeight(550) %>src="$URL"<% end_control %> alt="$Name" />
+ <% end_if %>
+
+ <% end_if %>
+
+<% end_if %>
+
+------------------------------------------------------
+<% if Orientation = 2 %>
+ <img <% control Image.deviceOptimizedImageHeightByWidthRatio(0.266) %>src="$URL"<% end_control %> alt="$Name" />
+<% else %>
+ <img <% control Image.deviceOptimizedImageWidthByRatio(0.266) %>src="$URL"<% end_control %> alt="$Name" />
+<% end_if %>
View
170 _config.blank.php
@@ -1,170 +0,0 @@
-<?php
-/**
- * Device Aware Config file
- * * Registers extensions
- * * Register images to chache
- *
- * Copyright (c) 2011, Thierry Francois / COLYMBA
- * Licensed under the MIT license
- * http://colymba.com
- *
- * @package DeviceAware
- *
- * @copyright Thierry Francois / COLYMBA
- * @author thierry@colymba.com
- * @version 0.01
- *
- * @requires DeviceAware
- */
-
-///////////////////////////////////////////////////////////////////////////////
-/////////////////////// Extensions + rules
-
-/**
- * Register extensions
- */
-Object::add_extension('Page_Controller', 'DeviceAwarePage_Controller');
-Object::add_extension('Page', 'DeviceAwarePage');
-Object::add_extension('Image', 'DeviceAwareImage');
-
-/**
- * Add director URL rule to store current device resolution from AJAX call
- */
-Director::addRules(100, array(
- 'device_aware/$Action/$ID' => "Page_Controller"
-));
-
-Director::addRules(100, array(
- 'device_aware/dev/$Action/$Class/$ID' => "DeviceAwareDev_Controller"
-));
-
-///////////////////////////////////////////////////////////////////////////////
-/////////////////////// Image cache generations
-
-/**
- * By default images are not over-sampled
- * Uncomment if you would like to
- *
- * DeviceAware::$overSampleImages = TRUE;
- */
-
-/**
- * For mobile: devices to pre-generate image for
- * best to use the most common ones for your visitors
- */
-DeviceAware::$cachedMobileDevices = array('iPhone');
-
-/**
- * Overhide screen resolution for pre-generated images
- * Check you site analytics for the most common ones
- * or checkout: http://en.wikipedia.org/wiki/Display_resolution
- */
-DeviceAware::$screenResolutions = array(
- array(1280, 1024),
- array(1440, 900),
- array(1680, 1050),
- array(1024, 768),
- array(1920, 1200)
-);
-
-/*
- * Registers images to cache
- * TODO: handle image orientation conditions
- * TODO: handle pixel sizes
- */
-/*
-DeviceAware::$usedResolutionRatios = array(
- 'Project' => array(
- 'fields' => array(
- 'CoverID' => array(
- 'classic' => array(
- 'width' => array() //as used in template
- ),
- 'mobile' => array(
- 'width' => array()
- )
- )
- ),
- 'objects' => array(
- 'Snapshot' => array(
- 'foreignKey' => 'ProjectID',
- 'fields' => array(
- 'ImageID' => array(
- 'classic' => array(
- 'width' => array(), //as used in template
- 'height' => array() //as used in template
- ),
- 'mobile' => array(
- 'width' => array(), //as used in template
- 'height' => array() //as used in template
- )
- )
- )
- )
- )
- )
-);
- */
-DeviceAware::$usedResolutionRatios = array(
- 'Project' => array(
- 'fields' => array(
- 'CoverID' => array(
- 'classic' => array(
- 'width' => array() //as used in template
- ),
- 'mobile' => array(
- 'width' => array()
- )
- )
- ),
- 'objects' => array(
- 'Snapshot' => array(
- 'foreignKey' => 'ProjectID',
- 'fields' => array(
- 'ImageID' => array(
- 'classic' => array(
- 'width' => array()
- ),
- 'mobile' => array(
- 'width' => array()
- )
- )
- )
- )
- )
- ),
- 'Page' => array(
- 'objects' => array(
- 'ContentBlock' => array(
- 'foreignKey' => 'PageID',
- 'fields' => array(
- 'ImageID' => array(
- 'classic' => array(
- 'width' => array()
- ),
- 'mobile' => array(
- 'width' => array()
- )
- ),
- 'ImageSetImage2ID' => array(
- 'classic' => array(
- 'width' => array()
- ),
- 'mobile' => array(
- 'width' => array()
- )
- ),
- 'ImageSetImage3ID' => array(
- 'classic' => array(
- 'width' => array()
- ),
- 'mobile' => array(
- 'width' => array()
- )
- )
- )
- )
- )
- )
-);
-?>
View
9 _config.php
@@ -12,7 +12,6 @@
*
* @copyright Thierry Francois / COLYMBA
* @author thierry@colymba.com
- * @version 0.01
*
* @requires DeviceAware
*/
@@ -75,7 +74,7 @@
array('P', 0.102, 1680, 'W'),
array('S', 0.102, 1680, 'W'),
array('L', 0.102, 1680, 'H'),
- /*
+
array('P', 0.1498, 1440, 'W'),
array('S', 0.1498, 1440, 'W'),
array('L', 0.1498, 1440, 'H'),
@@ -95,7 +94,7 @@
array('P', 0.266, 960, 'W'),
array('S', 0.266, 960, 'W'),
- array('L', 0.266, 960, 'H') */
+ array('L', 0.266, 960, 'H')
)
),
'objects' => array(
@@ -105,7 +104,7 @@
// imageOrientation, ratio/pixelSize, screenResolution, imageDirectionToResize
// Classic devices
- /*array('L', 0.6, 1920, 'W'),
+ array('L', 0.6, 1920, 'W'),
array('L', 0.6, 1680, 'W'),
array('L', 0.7, 1440, 'W'),
array('L', 0.7, 1280, 'W'),
@@ -114,7 +113,7 @@
array('P', '700', 0, 'H'),
array('P', '550', 0, 'H'),
array('S', '700', 0, 'H'),
- array('S', '550', 0, 'H'),*/
+ array('S', '550', 0, 'H'),
// Mobile
array('P', '550', 0, 'H'),
View
1 code/Controllers/DeviceAwareDev_Controller.php
@@ -11,7 +11,6 @@
*
* @copyright Thierry Francois / COLYMBA
* @author thierry@colymba.com
- * @version 0.01
*
* @requires DeviceAware
*/
View
1 code/Controllers/DeviceAwarePage_Controller.php
@@ -12,7 +12,6 @@
*
* @copyright Thierry Francois / COLYMBA
* @author thierry@colymba.com
- * @version 0.01
*
* @requires DeviceAware
*/
View
1 code/DeviceAware.php
@@ -11,7 +11,6 @@
*
* @copyright Thierry Francois / COLYMBA
* @author thierry@colymba.com
- * @version 0.01
*
* @requires MobileBrowserDetector by Silverstripe
*/
View
1 code/DeviceAwareCache.php
@@ -10,7 +10,6 @@
*
* @copyright Thierry Francois / COLYMBA
* @author thierry@colymba.com
- * @version 0.01
*
* @requires MobileBrowserDetector by Silverstripe
*/
View
252 code/MobileBrowserDetector.php
@@ -1,127 +1,127 @@
-<?php
-/**
- * @package DeviceAware *
- * @author Silverstripe Ltd
- *
- * @note Added MSIE fake positive fix
- */
-
-/**
-* Copyright (c) 2010, Silverstripe Ltd.
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * Neither the name of the <organization> nor the
-* names of its contributors may be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY Silverstripe Ltd. ``AS IS'' AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL Silverstripe Ltd. BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-class MobileBrowserDetector {
-
- /**
- * List of known mobiles, found in the HTTP_USER_AGENT variable
- * @see MobileBrowserDetector::is_mobile() for how they're used.
- *
- * @return array
- */
- private static function mobile_index_list() {
- return explode(',', '1207,3gso,4thp,501i,502i,503i,504i,505i,506i,6310,6590,770s,802s,a wa,acer,acs-,airn,alav,asus,attw,au-m,aur ,aus ,abac,acoo,aiko,alco,alca,amoi,anex,anny,anyw,aptu,arch,argo,bell,bird,bw-n,bw-u,beck,benq,bilb,blac,c55/,cdm-,chtm,capi,comp,cond,craw,dall,dbte,dc-s,dica,ds-d,ds12,dait,devi,dmob,doco,dopo,el49,erk0,esl8,ez40,ez60,ez70,ezos,ezze,elai,emul,eric,ezwa,fake,fly-,fly_,g-mo,g1 u,g560,gf-5,grun,gene,go.w,good,grad,hcit,hd-m,hd-p,hd-t,hei-,hp i,hpip,hs-c,htc ,htc-,htca,htcg,htcp,htcs,htct,htc_,haie,hita,huaw,hutc,i-20,i-go,i-ma,i230,iac,iac-,iac/,ig01,im1k,inno,iris,jata,java,kddi,kgt,kgt/,kpt ,kwc-,klon,lexi,lg g,lg-a,lg-b,lg-c,lg-d,lg-f,lg-g,lg-k,lg-l,lg-m,lg-o,lg-p,lg-s,lg-t,lg-u,lg-w,lg/k,lg/l,lg/u,lg50,lg54,lge-,lge/,lynx,leno,m1-w,m3ga,m50/,maui,mc01,mc21,mcca,medi,meri,mio8,mioa,mo01,mo02,mode,modo,mot ,mot-,mt50,mtp1,mtv ,mate,maxo,merc,mits,mobi,motv,mozz,n100,n101,n102,n202,n203,n300,n302,n500,n502,n505,n700,n701,n710,nec-,nem-,newg,neon,netf,noki,nzph,o2 x,o2-x,opwv,owg1,opti,oran,p800,pand,pg-1,pg-2,pg-3,pg-6,pg-8,pg-c,pg13,phil,pn-2,pt-g,palm,pana,pire,pock,pose,psio,qa-a,qc-2,qc-3,qc-5,qc-7,qc07,qc12,qc21,qc32,qc60,qci-,qwap,qtek,r380,r600,raks,rim9,rove,s55/,sage,sams,sc01,sch-,scp-,sdk/,se47,sec-,sec0,sec1,semc,sgh-,shar,sie-,sk-0,sl45,slid,smb3,smt5,sp01,sph-,spv ,spv-,sy01,samm,sany,sava,scoo,send,siem,smar,smit,soft,sony,t-mo,t218,t250,t600,t610,t618,tcl-,tdg-,telm,tim-,ts70,tsm-,tsm3,tsm5,tx-9,tagt,talk,teli,topl,tosh,up.b,upg1,utst,v400,v750,veri,vk-v,vk40,vk50,vk52,vk53,vm40,vx98,virg,vite,voda,vulc,w3c ,w3c-,wapj,wapp,wapu,wapm,wig ,wapi,wapr,wapv,wapy,wapa,waps,wapt,winc,winw,wonu,x700,xda2,xdag,yas-,your,zte-,zeto,aste,audi,avan,blaz,brew,brvw,bumb,ccwa,cell,cldc,cmd-,dang,eml2,fetc,hipt,http,ibro,idea,ikom,ipaq,jbro,jemu,jigs,keji,kyoc,kyok,libw,m-cr,midp,mmef,moto,mwbp,mywa,newt,nok6,o2im,pant,pdxg,play,pluc,port,prox,rozo,sama,seri,smal,symb,treo,upsi,vx52,vx53,vx60,vx61,vx70,vx80,vx81,vx83,vx85,wap-,webc,whit,wmlb,xda-');
- }
-
- public static function is_android() {
- return (stripos($_SERVER['HTTP_USER_AGENT'], 'android') !== false) ? true : false;
- }
-
- public static function is_iphone() {
- return (preg_match('/(ipod|iphone)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
- }
-
- public static function is_opera_mini() {
- return (stripos($_SERVER['HTTP_USER_AGENT'], 'opera mini') !== false) ? true : false;
- }
-
- public static function is_blackberry() {
- return (stripos($_SERVER['HTTP_USER_AGENT'], 'blackberry') !== false) ? true : false;
- }
-
- public static function is_palm() {
- return (preg_match('/(palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
- }
-
- public static function is_windows() {
- return (preg_match('/(windows ce; ppc;|windows ce; smartphone;|windows ce; iemobile)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
- }
-
- /**
- * Is the current HTTP_USER_AGENT a known mobile device string?
- * @see http://mobiforge.com/developing/story/setting-http-headers-advise-transcoding-proxies
- *
- * @return bool
- */
- public static function is_mobile() {
- $isMobile = false;
- $agent = $_SERVER['HTTP_USER_AGENT'];
- $accept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : '';
-
- //print_r($_SERVER['HTTP_USER_AGENT']);
-
- switch(true) {
- case(self::is_iphone()):
- $isMobile = true;
- break;
- case(self::is_android()):
- $isMobile = true;
- break;
- case(self::is_opera_mini()):
- $isMobile = true;
- break;
- case(self::is_blackberry()):
- $isMobile = true;
- break;
- case(self::is_palm()):
- $isMobile = true;
- break;
- case(self::is_windows()):
- $isMobile = true;
- break;
- case(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo)/i', $agent)):
- $isMobile = true;
- break;
- case((strpos($accept, 'text/vnd.wap.wml') !== false) || (strpos($accept, 'application/vnd.wap.xhtml+xml') !== false)):
- $isMobile = true;
- break;
- case(isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])):
- $isMobile = true;
- break;
- case(in_array(strtolower(substr($agent, 0, 4)), self::mobile_index_list())):
- $isMobile = true;
- break;
- }
-
- // overhide MSIE fake positive
- if ( preg_match('/msie/i', $agent) && !self::is_windows() ) $isMobile = false;
-
- if(!headers_sent()) {
- header('Cache-Control: no-transform');
- header('Vary: User-Agent, Accept');
- }
-
- return $isMobile;
- }
+<?php
+/**
+ * @package DeviceAware *
+ * @author Silverstripe Ltd
+ *
+ * @note Added MSIE fake positive fix (@colymba)
+ */
+
+/**
+* Copyright (c) 2010, Silverstripe Ltd.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* * Neither the name of the <organization> nor the
+* names of its contributors may be used to endorse or promote products
+* derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY Silverstripe Ltd. ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL Silverstripe Ltd. BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+class MobileBrowserDetector {
+
+ /**
+ * List of known mobiles, found in the HTTP_USER_AGENT variable
+ * @see MobileBrowserDetector::is_mobile() for how they're used.
+ *
+ * @return array
+ */
+ private static function mobile_index_list() {
+ return explode(',', '1207,3gso,4thp,501i,502i,503i,504i,505i,506i,6310,6590,770s,802s,a wa,acer,acs-,airn,alav,asus,attw,au-m,aur ,aus ,abac,acoo,aiko,alco,alca,amoi,anex,anny,anyw,aptu,arch,argo,bell,bird,bw-n,bw-u,beck,benq,bilb,blac,c55/,cdm-,chtm,capi,comp,cond,craw,dall,dbte,dc-s,dica,ds-d,ds12,dait,devi,dmob,doco,dopo,el49,erk0,esl8,ez40,ez60,ez70,ezos,ezze,elai,emul,eric,ezwa,fake,fly-,fly_,g-mo,g1 u,g560,gf-5,grun,gene,go.w,good,grad,hcit,hd-m,hd-p,hd-t,hei-,hp i,hpip,hs-c,htc ,htc-,htca,htcg,htcp,htcs,htct,htc_,haie,hita,huaw,hutc,i-20,i-go,i-ma,i230,iac,iac-,iac/,ig01,im1k,inno,iris,jata,java,kddi,kgt,kgt/,kpt ,kwc-,klon,lexi,lg g,lg-a,lg-b,lg-c,lg-d,lg-f,lg-g,lg-k,lg-l,lg-m,lg-o,lg-p,lg-s,lg-t,lg-u,lg-w,lg/k,lg/l,lg/u,lg50,lg54,lge-,lge/,lynx,leno,m1-w,m3ga,m50/,maui,mc01,mc21,mcca,medi,meri,mio8,mioa,mo01,mo02,mode,modo,mot ,mot-,mt50,mtp1,mtv ,mate,maxo,merc,mits,mobi,motv,mozz,n100,n101,n102,n202,n203,n300,n302,n500,n502,n505,n700,n701,n710,nec-,nem-,newg,neon,netf,noki,nzph,o2 x,o2-x,opwv,owg1,opti,oran,p800,pand,pg-1,pg-2,pg-3,pg-6,pg-8,pg-c,pg13,phil,pn-2,pt-g,palm,pana,pire,pock,pose,psio,qa-a,qc-2,qc-3,qc-5,qc-7,qc07,qc12,qc21,qc32,qc60,qci-,qwap,qtek,r380,r600,raks,rim9,rove,s55/,sage,sams,sc01,sch-,scp-,sdk/,se47,sec-,sec0,sec1,semc,sgh-,shar,sie-,sk-0,sl45,slid,smb3,smt5,sp01,sph-,spv ,spv-,sy01,samm,sany,sava,scoo,send,siem,smar,smit,soft,sony,t-mo,t218,t250,t600,t610,t618,tcl-,tdg-,telm,tim-,ts70,tsm-,tsm3,tsm5,tx-9,tagt,talk,teli,topl,tosh,up.b,upg1,utst,v400,v750,veri,vk-v,vk40,vk50,vk52,vk53,vm40,vx98,virg,vite,voda,vulc,w3c ,w3c-,wapj,wapp,wapu,wapm,wig ,wapi,wapr,wapv,wapy,wapa,waps,wapt,winc,winw,wonu,x700,xda2,xdag,yas-,your,zte-,zeto,aste,audi,avan,blaz,brew,brvw,bumb,ccwa,cell,cldc,cmd-,dang,eml2,fetc,hipt,http,ibro,idea,ikom,ipaq,jbro,jemu,jigs,keji,kyoc,kyok,libw,m-cr,midp,mmef,moto,mwbp,mywa,newt,nok6,o2im,pant,pdxg,play,pluc,port,prox,rozo,sama,seri,smal,symb,treo,upsi,vx52,vx53,vx60,vx61,vx70,vx80,vx81,vx83,vx85,wap-,webc,whit,wmlb,xda-');
+ }
+
+ public static function is_android() {
+ return (stripos($_SERVER['HTTP_USER_AGENT'], 'android') !== false) ? true : false;
+ }
+
+ public static function is_iphone() {
+ return (preg_match('/(ipod|iphone)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
+ }
+
+ public static function is_opera_mini() {
+ return (stripos($_SERVER['HTTP_USER_AGENT'], 'opera mini') !== false) ? true : false;
+ }
+
+ public static function is_blackberry() {
+ return (stripos($_SERVER['HTTP_USER_AGENT'], 'blackberry') !== false) ? true : false;
+ }
+
+ public static function is_palm() {
+ return (preg_match('/(palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
+ }
+
+ public static function is_windows() {
+ return (preg_match('/(windows ce; ppc;|windows ce; smartphone;|windows ce; iemobile)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
+ }
+
+ /**
+ * Is the current HTTP_USER_AGENT a known mobile device string?
+ * @see http://mobiforge.com/developing/story/setting-http-headers-advise-transcoding-proxies
+ *
+ * @return bool
+ */
+ public static function is_mobile() {
+ $isMobile = false;
+ $agent = $_SERVER['HTTP_USER_AGENT'];
+ $accept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : '';
+
+ //print_r($_SERVER['HTTP_USER_AGENT']);
+
+ switch(true) {
+ case(self::is_iphone()):
+ $isMobile = true;
+ break;
+ case(self::is_android()):
+ $isMobile = true;
+ break;
+ case(self::is_opera_mini()):
+ $isMobile = true;
+ break;
+ case(self::is_blackberry()):
+ $isMobile = true;
+ break;
+ case(self::is_palm()):
+ $isMobile = true;
+ break;
+ case(self::is_windows()):
+ $isMobile = true;
+ break;
+ case(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo)/i', $agent)):
+ $isMobile = true;
+ break;
+ case((strpos($accept, 'text/vnd.wap.wml') !== false) || (strpos($accept, 'application/vnd.wap.xhtml+xml') !== false)):
+ $isMobile = true;
+ break;
+ case(isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])):
+ $isMobile = true;
+ break;
+ case(in_array(strtolower(substr($agent, 0, 4)), self::mobile_index_list())):
+ $isMobile = true;
+ break;
+ }
+
+ // overhide MSIE fake positive
+ if ( preg_match('/msie/i', $agent) && !self::is_windows() ) $isMobile = false;
+
+ if(!headers_sent()) {
+ header('Cache-Control: no-transform');
+ header('Vary: User-Agent, Accept');
+ }
+
+ return $isMobile;
+ }
}
View
1 code/Models/DeviceAwareImage.php
@@ -11,7 +11,6 @@
*
* @copyright Thierry Francois / COLYMBA
* @author thierry@colymba.com
- * @version 0.01
*
* @requires DeviceAware
*/
View
1 code/Models/DeviceAwarePage.php
@@ -12,7 +12,6 @@
*
* @copyright Thierry Francois / COLYMBA
* @author thierry@colymba.com
- * @version 0.01
*
* @requires DeviceAware
*/
View
95 javascript/deviceaware.js
@@ -1,49 +1,48 @@
-/**
- * Device Aware: jQuery addon for the SilverStripe module
- * Sends the current screen resolution to SilverStripe to be store in a Session
- * Used to create optimized version of the images displayed
- *
- * Copyright (c) 2011, Thierry Francois / COLYMBA
- * Licensed under the MIT license
- * http://colymba.com
- *
- * @package DeviceAware
- *
- * @copyright Thierry Francois / COLYMBA
- * @author thierry@colymba.com
- * @version 0.01
- *
- * @requires Jquery
- */
-$(document).ready(function(){
- jQuery.get( 'device_aware/saveScreenResolution', {width: screen.width, height: screen.height} );
-});
-// non JQuery version
-/*
-function device_aware_save_resolution()
-{
- var XBrowserXMLHttp = [
- function () {return new XMLHttpRequest()},
- function () {return new XDomainRequest()},
- function () {return new ActiveXObject("Msxml2.XMLHTTP")},
- function () {return new ActiveXObject("Msxml3.XMLHTTP")},
- function () {return new ActiveXObject("Microsoft.XMLHTTP")}
- ];
- var xmlhttp = false;
- for (var i=0;i<XBrowserXMLHttp.length;i++) {
- try {
- xmlhttp = XBrowserXMLHttp[i]();
- }
- catch (e) {
- continue;
- }
- break;
- }
- if (xmlhttp)
- {
- xmlhttp.open('GET','device_aware/saveScreenResolution?width='+screen.width+'&height='+screen.height,true);
- xmlhttp.setRequestHeader('User-Agent','XMLHTTP/1.0');
- xmlhttp.send(null);
- }
-}
+/**
+ * Device Aware: jQuery addon for the SilverStripe module
+ * Sends the current screen resolution to SilverStripe to be store in a Session
+ * Used to create optimized version of the images displayed
+ *
+ * Copyright (c) 2011, Thierry Francois / COLYMBA
+ * Licensed under the MIT license
+ * http://colymba.com
+ *
+ * @package DeviceAware
+ *
+ * @copyright Thierry Francois / COLYMBA
+ * @author thierry@colymba.com
+ *
+ * @requires Jquery
+ */
+$(document).ready(function(){
+ jQuery.get( 'device_aware/saveScreenResolution', {width: screen.width, height: screen.height} );
+});
+// non JQuery version
+/*
+function device_aware_save_resolution()
+{
+ var XBrowserXMLHttp = [
+ function () {return new XMLHttpRequest()},
+ function () {return new XDomainRequest()},
+ function () {return new ActiveXObject("Msxml2.XMLHTTP")},
+ function () {return new ActiveXObject("Msxml3.XMLHTTP")},
+ function () {return new ActiveXObject("Microsoft.XMLHTTP")}
+ ];
+ var xmlhttp = false;
+ for (var i=0;i<XBrowserXMLHttp.length;i++) {
+ try {
+ xmlhttp = XBrowserXMLHttp[i]();
+ }
+ catch (e) {
+ continue;
+ }
+ break;
+ }
+ if (xmlhttp)
+ {
+ xmlhttp.open('GET','device_aware/saveScreenResolution?width='+screen.width+'&height='+screen.height,true);
+ xmlhttp.setRequestHeader('User-Agent','XMLHTTP/1.0');
+ xmlhttp.send(null);
+ }
+}
device_aware_save_resolution();*/

0 comments on commit c2576d1

Please sign in to comment.