Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit c2576d144c280d47e6a0f736a1483cb7c0cfaff3 1 parent e7c914c
Thierry François authored
127 README
... ... @@ -1,39 +1,88 @@
1   -------------------------------------------------------
2   -Device Aware v0.1
3   -SilverStripe module
4   -by Thierry Francois : colmyba.com
5   -------------------------------------------------------
6   -
7   -------------------------------------------------------
8   -DETAILS
9   -------------------------------------------------------
10   -Adds mobile functionlaities:
11   -- detection
12   -- template functions
13   -- resolutions
14   -
15   -Device resolution tools
16   -- default device resolution (classic and mobile)
17   -- save current visitor's resolution
18   -
19   -Image manipulation
20   -- image resizing depending on device/visitor resolution
21   -- pre-generated images (cache)
22   -
23   -All configured through _config.php
24   -
25   -------------------------------------------------------
26   -INSTALL
27   -------------------------------------------------------
28   -copy folder in your SS install. Run dev/build/
29   -
30   -------------------------------------------------------
31   -CONFIG
32   -------------------------------------------------------
33   -Open _config.php
34   -Add/remove extensions as required
35   -Reset defaults if required
36   -Set cache config
37   -
38   -
39   -...Full manual in a bit...
  1 +------------------------------------------------------
  2 +Device Aware v0.2 (29 Jan. 2012)
  3 +SilverStripe module
  4 +by Thierry Francois : colymba.com
  5 +------------------------------------------------------
  6 +
  7 +------------------------------------------------------
  8 +ABOUT
  9 +------------------------------------------------------
  10 +This extension was developed for the needs of responsive layouts
  11 +where image sizes would vary with the user's screen resolution.
  12 +
  13 +
  14 +------------------------------------------------------
  15 +DETAILS
  16 +------------------------------------------------------
  17 +Adds mobile functionlaities:
  18 +- detection
  19 +- template functions
  20 +- resolutions 'database'
  21 +
  22 +Device resolution tools
  23 +- default device resolution (classic and mobile)
  24 +- save current visitor's resolution
  25 +
  26 +Image manipulation
  27 +- image resizing depending on device/visitor resolution
  28 +- pre-generated images (cache)
  29 +
  30 +All configured through _config.php
  31 +
  32 +------------------------------------------------------
  33 +INSTALL
  34 +------------------------------------------------------
  35 +copy folder in your SS install. Run dev/build/
  36 +
  37 +------------------------------------------------------
  38 +CONFIG
  39 +------------------------------------------------------
  40 +Open _config.php
  41 +Add/remove extensions as required
  42 +Reset defaults if required
  43 +Set cache config
  44 +
  45 +------------------------------------------------------
  46 +EXAMPLES
  47 +------------------------------------------------------
  48 +Template code example with sample usage of templates functions
  49 +
  50 +------------------------------------------------------
  51 +<% if isMobile %>
  52 +
  53 + <% control Image %>
  54 + <% if Orientation = 2 %>
  55 + <img <% control deviceOptimizedImageWidthByRatio(0.95) %>src="$URL"<% end_control %> alt="$Name" />
  56 + <% else %>
  57 + <img <% control SetHeight(550) %>src="$URL"<% end_control %> alt="$Name" />
  58 + <% end_if %>
  59 + <% end_control %>
  60 +
  61 +<% else %>
  62 +
  63 + <% if Image.isLandscape %>
  64 +
  65 + <% if screenWidth1600Plus %>
  66 + <img <% control Image.deviceOptimizedImageWidthByRatio(0.6) %>src="$URL"<% end_control %> alt="$Name" />
  67 + <% else %>
  68 + <img <% control Image.deviceOptimizedImageWidthByRatio(0.7) %>src="$URL"<% end_control %> alt="$Name" />
  69 + <% end_if %>
  70 +
  71 + <% else %>
  72 +
  73 + <% if screenHeight1000Plus %>
  74 + <img <% control Image.SetHeight(700) %>src="$URL"<% end_control %> alt="$Name" />
  75 + <% else %>
  76 + <img <% control Image.SetHeight(550) %>src="$URL"<% end_control %> alt="$Name" />
  77 + <% end_if %>
  78 +
  79 + <% end_if %>
  80 +
  81 +<% end_if %>
  82 +
  83 +------------------------------------------------------
  84 +<% if Orientation = 2 %>
  85 + <img <% control Image.deviceOptimizedImageHeightByWidthRatio(0.266) %>src="$URL"<% end_control %> alt="$Name" />
  86 +<% else %>
  87 + <img <% control Image.deviceOptimizedImageWidthByRatio(0.266) %>src="$URL"<% end_control %> alt="$Name" />
  88 +<% end_if %>
170 _config.blank.php
... ... @@ -1,170 +0,0 @@
1   -<?php
2   -/**
3   - * Device Aware Config file
4   - * * Registers extensions
5   - * * Register images to chache
6   - *
7   - * Copyright (c) 2011, Thierry Francois / COLYMBA
8   - * Licensed under the MIT license
9   - * http://colymba.com
10   - *
11   - * @package DeviceAware
12   - *
13   - * @copyright Thierry Francois / COLYMBA
14   - * @author thierry@colymba.com
15   - * @version 0.01
16   - *
17   - * @requires DeviceAware
18   - */
19   -
20   -///////////////////////////////////////////////////////////////////////////////
21   -/////////////////////// Extensions + rules
22   -
23   -/**
24   - * Register extensions
25   - */
26   -Object::add_extension('Page_Controller', 'DeviceAwarePage_Controller');
27   -Object::add_extension('Page', 'DeviceAwarePage');
28   -Object::add_extension('Image', 'DeviceAwareImage');
29   -
30   -/**
31   - * Add director URL rule to store current device resolution from AJAX call
32   - */
33   -Director::addRules(100, array(
34   - 'device_aware/$Action/$ID' => "Page_Controller"
35   -));
36   -
37   -Director::addRules(100, array(
38   - 'device_aware/dev/$Action/$Class/$ID' => "DeviceAwareDev_Controller"
39   -));
40   -
41   -///////////////////////////////////////////////////////////////////////////////
42   -/////////////////////// Image cache generations
43   -
44   -/**
45   - * By default images are not over-sampled
46   - * Uncomment if you would like to
47   - *
48   - * DeviceAware::$overSampleImages = TRUE;
49   - */
50   -
51   -/**
52   - * For mobile: devices to pre-generate image for
53   - * best to use the most common ones for your visitors
54   - */
55   -DeviceAware::$cachedMobileDevices = array('iPhone');
56   -
57   -/**
58   - * Overhide screen resolution for pre-generated images
59   - * Check you site analytics for the most common ones
60   - * or checkout: http://en.wikipedia.org/wiki/Display_resolution
61   - */
62   -DeviceAware::$screenResolutions = array(
63   - array(1280, 1024),
64   - array(1440, 900),
65   - array(1680, 1050),
66   - array(1024, 768),
67   - array(1920, 1200)
68   -);
69   -
70   -/*
71   - * Registers images to cache
72   - * TODO: handle image orientation conditions
73   - * TODO: handle pixel sizes
74   - */
75   -/*
76   -DeviceAware::$usedResolutionRatios = array(
77   - 'Project' => array(
78   - 'fields' => array(
79   - 'CoverID' => array(
80   - 'classic' => array(
81   - 'width' => array() //as used in template
82   - ),
83   - 'mobile' => array(
84   - 'width' => array()
85   - )
86   - )
87   - ),
88   - 'objects' => array(
89   - 'Snapshot' => array(
90   - 'foreignKey' => 'ProjectID',
91   - 'fields' => array(
92   - 'ImageID' => array(
93   - 'classic' => array(
94   - 'width' => array(), //as used in template
95   - 'height' => array() //as used in template
96   - ),
97   - 'mobile' => array(
98   - 'width' => array(), //as used in template
99   - 'height' => array() //as used in template
100   - )
101   - )
102   - )
103   - )
104   - )
105   - )
106   -);
107   - */
108   -DeviceAware::$usedResolutionRatios = array(
109   - 'Project' => array(
110   - 'fields' => array(
111   - 'CoverID' => array(
112   - 'classic' => array(
113   - 'width' => array() //as used in template
114   - ),
115   - 'mobile' => array(
116   - 'width' => array()
117   - )
118   - )
119   - ),
120   - 'objects' => array(
121   - 'Snapshot' => array(
122   - 'foreignKey' => 'ProjectID',
123   - 'fields' => array(
124   - 'ImageID' => array(
125   - 'classic' => array(
126   - 'width' => array()
127   - ),
128   - 'mobile' => array(
129   - 'width' => array()
130   - )
131   - )
132   - )
133   - )
134   - )
135   - ),
136   - 'Page' => array(
137   - 'objects' => array(
138   - 'ContentBlock' => array(
139   - 'foreignKey' => 'PageID',
140   - 'fields' => array(
141   - 'ImageID' => array(
142   - 'classic' => array(
143   - 'width' => array()
144   - ),
145   - 'mobile' => array(
146   - 'width' => array()
147   - )
148   - ),
149   - 'ImageSetImage2ID' => array(
150   - 'classic' => array(
151   - 'width' => array()
152   - ),
153   - 'mobile' => array(
154   - 'width' => array()
155   - )
156   - ),
157   - 'ImageSetImage3ID' => array(
158   - 'classic' => array(
159   - 'width' => array()
160   - ),
161   - 'mobile' => array(
162   - 'width' => array()
163   - )
164   - )
165   - )
166   - )
167   - )
168   - )
169   -);
170   -?>
9 _config.php
@@ -12,7 +12,6 @@
12 12 *
13 13 * @copyright Thierry Francois / COLYMBA
14 14 * @author thierry@colymba.com
15   - * @version 0.01
16 15 *
17 16 * @requires DeviceAware
18 17 */
@@ -75,7 +74,7 @@
75 74 array('P', 0.102, 1680, 'W'),
76 75 array('S', 0.102, 1680, 'W'),
77 76 array('L', 0.102, 1680, 'H'),
78   - /*
  77 +
79 78 array('P', 0.1498, 1440, 'W'),
80 79 array('S', 0.1498, 1440, 'W'),
81 80 array('L', 0.1498, 1440, 'H'),
@@ -95,7 +94,7 @@
95 94
96 95 array('P', 0.266, 960, 'W'),
97 96 array('S', 0.266, 960, 'W'),
98   - array('L', 0.266, 960, 'H') */
  97 + array('L', 0.266, 960, 'H')
99 98 )
100 99 ),
101 100 'objects' => array(
@@ -105,7 +104,7 @@
105 104 // imageOrientation, ratio/pixelSize, screenResolution, imageDirectionToResize
106 105
107 106 // Classic devices
108   - /*array('L', 0.6, 1920, 'W'),
  107 + array('L', 0.6, 1920, 'W'),
109 108 array('L', 0.6, 1680, 'W'),
110 109 array('L', 0.7, 1440, 'W'),
111 110 array('L', 0.7, 1280, 'W'),
@@ -114,7 +113,7 @@
114 113 array('P', '700', 0, 'H'),
115 114 array('P', '550', 0, 'H'),
116 115 array('S', '700', 0, 'H'),
117   - array('S', '550', 0, 'H'),*/
  116 + array('S', '550', 0, 'H'),
118 117
119 118 // Mobile
120 119 array('P', '550', 0, 'H'),
1  code/Controllers/DeviceAwareDev_Controller.php
@@ -11,7 +11,6 @@
11 11 *
12 12 * @copyright Thierry Francois / COLYMBA
13 13 * @author thierry@colymba.com
14   - * @version 0.01
15 14 *
16 15 * @requires DeviceAware
17 16 */
1  code/Controllers/DeviceAwarePage_Controller.php
@@ -12,7 +12,6 @@
12 12 *
13 13 * @copyright Thierry Francois / COLYMBA
14 14 * @author thierry@colymba.com
15   - * @version 0.01
16 15 *
17 16 * @requires DeviceAware
18 17 */
1  code/DeviceAware.php
@@ -11,7 +11,6 @@
11 11 *
12 12 * @copyright Thierry Francois / COLYMBA
13 13 * @author thierry@colymba.com
14   - * @version 0.01
15 14 *
16 15 * @requires MobileBrowserDetector by Silverstripe
17 16 */
1  code/DeviceAwareCache.php
@@ -10,7 +10,6 @@
10 10 *
11 11 * @copyright Thierry Francois / COLYMBA
12 12 * @author thierry@colymba.com
13   - * @version 0.01
14 13 *
15 14 * @requires MobileBrowserDetector by Silverstripe
16 15 */
252 code/MobileBrowserDetector.php
... ... @@ -1,127 +1,127 @@
1   -<?php
2   -/**
3   - * @package DeviceAware *
4   - * @author Silverstripe Ltd
5   - *
6   - * @note Added MSIE fake positive fix
7   - */
8   -
9   -/**
10   -* Copyright (c) 2010, Silverstripe Ltd.
11   -* All rights reserved.
12   -*
13   -* Redistribution and use in source and binary forms, with or without
14   -* modification, are permitted provided that the following conditions are met:
15   -* * Redistributions of source code must retain the above copyright
16   -* notice, this list of conditions and the following disclaimer.
17   -* * Redistributions in binary form must reproduce the above copyright
18   -* notice, this list of conditions and the following disclaimer in the
19   -* documentation and/or other materials provided with the distribution.
20   -* * Neither the name of the <organization> nor the
21   -* names of its contributors may be used to endorse or promote products
22   -* derived from this software without specific prior written permission.
23   -*
24   -* THIS SOFTWARE IS PROVIDED BY Silverstripe Ltd. ``AS IS'' AND ANY
25   -* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26   -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   -* DISCLAIMED. IN NO EVENT SHALL Silverstripe Ltd. BE LIABLE FOR ANY
28   -* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29   -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30   -* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31   -* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32   -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33   -* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   -*/
35   -class MobileBrowserDetector {
36   -
37   - /**
38   - * List of known mobiles, found in the HTTP_USER_AGENT variable
39   - * @see MobileBrowserDetector::is_mobile() for how they're used.
40   - *
41   - * @return array
42   - */
43   - private static function mobile_index_list() {
44   - 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-');
45   - }
46   -
47   - public static function is_android() {
48   - return (stripos($_SERVER['HTTP_USER_AGENT'], 'android') !== false) ? true : false;
49   - }
50   -
51   - public static function is_iphone() {
52   - return (preg_match('/(ipod|iphone)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
53   - }
54   -
55   - public static function is_opera_mini() {
56   - return (stripos($_SERVER['HTTP_USER_AGENT'], 'opera mini') !== false) ? true : false;
57   - }
58   -
59   - public static function is_blackberry() {
60   - return (stripos($_SERVER['HTTP_USER_AGENT'], 'blackberry') !== false) ? true : false;
61   - }
62   -
63   - public static function is_palm() {
64   - return (preg_match('/(palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
65   - }
66   -
67   - public static function is_windows() {
68   - return (preg_match('/(windows ce; ppc;|windows ce; smartphone;|windows ce; iemobile)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
69   - }
70   -
71   - /**
72   - * Is the current HTTP_USER_AGENT a known mobile device string?
73   - * @see http://mobiforge.com/developing/story/setting-http-headers-advise-transcoding-proxies
74   - *
75   - * @return bool
76   - */
77   - public static function is_mobile() {
78   - $isMobile = false;
79   - $agent = $_SERVER['HTTP_USER_AGENT'];
80   - $accept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : '';
81   -
82   - //print_r($_SERVER['HTTP_USER_AGENT']);
83   -
84   - switch(true) {
85   - case(self::is_iphone()):
86   - $isMobile = true;
87   - break;
88   - case(self::is_android()):
89   - $isMobile = true;
90   - break;
91   - case(self::is_opera_mini()):
92   - $isMobile = true;
93   - break;
94   - case(self::is_blackberry()):
95   - $isMobile = true;
96   - break;
97   - case(self::is_palm()):
98   - $isMobile = true;
99   - break;
100   - case(self::is_windows()):
101   - $isMobile = true;
102   - break;
103   - case(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo)/i', $agent)):
104   - $isMobile = true;
105   - break;
106   - case((strpos($accept, 'text/vnd.wap.wml') !== false) || (strpos($accept, 'application/vnd.wap.xhtml+xml') !== false)):
107   - $isMobile = true;
108   - break;
109   - case(isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])):
110   - $isMobile = true;
111   - break;
112   - case(in_array(strtolower(substr($agent, 0, 4)), self::mobile_index_list())):
113   - $isMobile = true;
114   - break;
115   - }
116   -
117   - // overhide MSIE fake positive
118   - if ( preg_match('/msie/i', $agent) && !self::is_windows() ) $isMobile = false;
119   -
120   - if(!headers_sent()) {
121   - header('Cache-Control: no-transform');
122   - header('Vary: User-Agent, Accept');
123   - }
124   -
125   - return $isMobile;
126   - }
  1 +<?php
  2 +/**
  3 + * @package DeviceAware *
  4 + * @author Silverstripe Ltd
  5 + *
  6 + * @note Added MSIE fake positive fix (@colymba)
  7 + */
  8 +
  9 +/**
  10 +* Copyright (c) 2010, Silverstripe Ltd.
  11 +* All rights reserved.
  12 +*
  13 +* Redistribution and use in source and binary forms, with or without
  14 +* modification, are permitted provided that the following conditions are met:
  15 +* * Redistributions of source code must retain the above copyright
  16 +* notice, this list of conditions and the following disclaimer.
  17 +* * Redistributions in binary form must reproduce the above copyright
  18 +* notice, this list of conditions and the following disclaimer in the
  19 +* documentation and/or other materials provided with the distribution.
  20 +* * Neither the name of the <organization> nor the
  21 +* names of its contributors may be used to endorse or promote products
  22 +* derived from this software without specific prior written permission.
  23 +*
  24 +* THIS SOFTWARE IS PROVIDED BY Silverstripe Ltd. ``AS IS'' AND ANY
  25 +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26 +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27 +* DISCLAIMED. IN NO EVENT SHALL Silverstripe Ltd. BE LIABLE FOR ANY
  28 +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29 +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30 +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  31 +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32 +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33 +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34 +*/
  35 +class MobileBrowserDetector {
  36 +
  37 + /**
  38 + * List of known mobiles, found in the HTTP_USER_AGENT variable
  39 + * @see MobileBrowserDetector::is_mobile() for how they're used.
  40 + *
  41 + * @return array
  42 + */
  43 + private static function mobile_index_list() {
  44 + 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-');
  45 + }
  46 +
  47 + public static function is_android() {
  48 + return (stripos($_SERVER['HTTP_USER_AGENT'], 'android') !== false) ? true : false;
  49 + }
  50 +
  51 + public static function is_iphone() {
  52 + return (preg_match('/(ipod|iphone)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
  53 + }
  54 +
  55 + public static function is_opera_mini() {
  56 + return (stripos($_SERVER['HTTP_USER_AGENT'], 'opera mini') !== false) ? true : false;
  57 + }
  58 +
  59 + public static function is_blackberry() {
  60 + return (stripos($_SERVER['HTTP_USER_AGENT'], 'blackberry') !== false) ? true : false;
  61 + }
  62 +
  63 + public static function is_palm() {
  64 + return (preg_match('/(palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
  65 + }
  66 +
  67 + public static function is_windows() {
  68 + return (preg_match('/(windows ce; ppc;|windows ce; smartphone;|windows ce; iemobile)/i', $_SERVER['HTTP_USER_AGENT'])) ? true : false;
  69 + }
  70 +
  71 + /**
  72 + * Is the current HTTP_USER_AGENT a known mobile device string?
  73 + * @see http://mobiforge.com/developing/story/setting-http-headers-advise-transcoding-proxies
  74 + *
  75 + * @return bool
  76 + */
  77 + public static function is_mobile() {
  78 + $isMobile = false;
  79 + $agent = $_SERVER['HTTP_USER_AGENT'];
  80 + $accept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : '';
  81 +
  82 + //print_r($_SERVER['HTTP_USER_AGENT']);
  83 +
  84 + switch(true) {
  85 + case(self::is_iphone()):
  86 + $isMobile = true;
  87 + break;
  88 + case(self::is_android()):
  89 + $isMobile = true;
  90 + break;
  91 + case(self::is_opera_mini()):
  92 + $isMobile = true;
  93 + break;
  94 + case(self::is_blackberry()):
  95 + $isMobile = true;
  96 + break;
  97 + case(self::is_palm()):
  98 + $isMobile = true;
  99 + break;
  100 + case(self::is_windows()):
  101 + $isMobile = true;
  102 + break;
  103 + case(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|pda|psp|treo)/i', $agent)):
  104 + $isMobile = true;
  105 + break;
  106 + case((strpos($accept, 'text/vnd.wap.wml') !== false) || (strpos($accept, 'application/vnd.wap.xhtml+xml') !== false)):
  107 + $isMobile = true;
  108 + break;
  109 + case(isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])):
  110 + $isMobile = true;
  111 + break;
  112 + case(in_array(strtolower(substr($agent, 0, 4)), self::mobile_index_list())):
  113 + $isMobile = true;
  114 + break;
  115 + }
  116 +
  117 + // overhide MSIE fake positive
  118 + if ( preg_match('/msie/i', $agent) && !self::is_windows() ) $isMobile = false;
  119 +
  120 + if(!headers_sent()) {
  121 + header('Cache-Control: no-transform');
  122 + header('Vary: User-Agent, Accept');
  123 + }
  124 +
  125 + return $isMobile;
  126 + }
127 127 }
1  code/Models/DeviceAwareImage.php
@@ -11,7 +11,6 @@
11 11 *
12 12 * @copyright Thierry Francois / COLYMBA
13 13 * @author thierry@colymba.com
14   - * @version 0.01
15 14 *
16 15 * @requires DeviceAware
17 16 */
1  code/Models/DeviceAwarePage.php
@@ -12,7 +12,6 @@
12 12 *
13 13 * @copyright Thierry Francois / COLYMBA
14 14 * @author thierry@colymba.com
15   - * @version 0.01
16 15 *
17 16 * @requires DeviceAware
18 17 */
95 javascript/deviceaware.js
... ... @@ -1,49 +1,48 @@
1   -/**
2   - * Device Aware: jQuery addon for the SilverStripe module
3   - * Sends the current screen resolution to SilverStripe to be store in a Session
4   - * Used to create optimized version of the images displayed
5   - *
6   - * Copyright (c) 2011, Thierry Francois / COLYMBA
7   - * Licensed under the MIT license
8   - * http://colymba.com
9   - *
10   - * @package DeviceAware
11   - *
12   - * @copyright Thierry Francois / COLYMBA
13   - * @author thierry@colymba.com
14   - * @version 0.01
15   - *
16   - * @requires Jquery
17   - */
18   -$(document).ready(function(){
19   - jQuery.get( 'device_aware/saveScreenResolution', {width: screen.width, height: screen.height} );
20   -});
21   -// non JQuery version
22   -/*
23   -function device_aware_save_resolution()
24   -{
25   - var XBrowserXMLHttp = [
26   - function () {return new XMLHttpRequest()},
27   - function () {return new XDomainRequest()},
28   - function () {return new ActiveXObject("Msxml2.XMLHTTP")},
29   - function () {return new ActiveXObject("Msxml3.XMLHTTP")},
30   - function () {return new ActiveXObject("Microsoft.XMLHTTP")}
31   - ];
32   - var xmlhttp = false;
33   - for (var i=0;i<XBrowserXMLHttp.length;i++) {
34   - try {
35   - xmlhttp = XBrowserXMLHttp[i]();
36   - }
37   - catch (e) {
38   - continue;
39   - }
40   - break;
41   - }
42   - if (xmlhttp)
43   - {
44   - xmlhttp.open('GET','device_aware/saveScreenResolution?width='+screen.width+'&height='+screen.height,true);
45   - xmlhttp.setRequestHeader('User-Agent','XMLHTTP/1.0');
46   - xmlhttp.send(null);
47   - }
48   -}
  1 +/**
  2 + * Device Aware: jQuery addon for the SilverStripe module
  3 + * Sends the current screen resolution to SilverStripe to be store in a Session
  4 + * Used to create optimized version of the images displayed
  5 + *
  6 + * Copyright (c) 2011, Thierry Francois / COLYMBA
  7 + * Licensed under the MIT license
  8 + * http://colymba.com
  9 + *
  10 + * @package DeviceAware
  11 + *
  12 + * @copyright Thierry Francois / COLYMBA
  13 + * @author thierry@colymba.com
  14 + *
  15 + * @requires Jquery
  16 + */
  17 +$(document).ready(function(){
  18 + jQuery.get( 'device_aware/saveScreenResolution', {width: screen.width, height: screen.height} );
  19 +});
  20 +// non JQuery version
  21 +/*
  22 +function device_aware_save_resolution()
  23 +{
  24 + var XBrowserXMLHttp = [
  25 + function () {return new XMLHttpRequest()},
  26 + function () {return new XDomainRequest()},
  27 + function () {return new ActiveXObject("Msxml2.XMLHTTP")},
  28 + function () {return new ActiveXObject("Msxml3.XMLHTTP")},
  29 + function () {return new ActiveXObject("Microsoft.XMLHTTP")}
  30 + ];
  31 + var xmlhttp = false;
  32 + for (var i=0;i<XBrowserXMLHttp.length;i++) {
  33 + try {
  34 + xmlhttp = XBrowserXMLHttp[i]();
  35 + }
  36 + catch (e) {
  37 + continue;
  38 + }
  39 + break;
  40 + }
  41 + if (xmlhttp)
  42 + {
  43 + xmlhttp.open('GET','device_aware/saveScreenResolution?width='+screen.width+'&height='+screen.height,true);
  44 + xmlhttp.setRequestHeader('User-Agent','XMLHTTP/1.0');
  45 + xmlhttp.send(null);
  46 + }
  47 +}
49 48 device_aware_save_resolution();*/

0 comments on commit c2576d1

Please sign in to comment.
Something went wrong with that request. Please try again.