Ticket #4336: mobile.2.diff
File mobile.2.diff, 3.9 KB (added by , 16 years ago) |
---|
-
includes/mobile.php
old new 33 33 /**/ 34 34 35 35 36 36 37 /** 37 38 * Return true if the user agent is mobile device. Otherwise return false. 38 39 * The user agent is determined based on the return value of getScreenSize() … … 41 42 * @return true or false 42 43 */ 43 44 function isMobileUser() { 44 return (get ScreenSize() === false) ? false : true;45 return (getMobileUserAgent() === null) ? false : true; 45 46 } 46 47 48 function getMobiles() { 47 49 48 /**49 * Return the screen size of the mobile user agent. This can be used to do very50 * detailed modifications to the web site's layout for the mobile user agents.51 * If the user is not regocnized to be a mobile device then return false. If the52 * user is a known mobile device but the screen size is unknown then return53 * an empty array. Mobile users are detected based on $_SERVER['HTTP_USER_AGENT']54 * and a list of known mobile user agent identification strings.55 *56 * @return array(width, height) or false57 */58 function getScreenSize() {59 static $isChecked = false;60 static $screen = false;61 62 if (!$isChecked) {63 50 /* 64 51 * The $mobiles array contains a list of known mobile phone user agent 65 52 * identification strings. Each key of the array is a substring of the … … 75 62 * an empty array or approximate dimensions. 76 63 */ 77 64 $mobiles = array( 65 /* Apple's iPhone */ 66 'iPhone' => array('width' => 320, 'height' => 480), 78 67 /* Phones using the Series 60 platform, e.g. Nokia 3650 and 6600. */ 79 68 'Series 60' => array('width' => 176, 'height' => 208), 80 69 'Series60' => array('width' => 176, 'height' => 208), … … 141 130 //'Opera' => array('width' => 176, 'height' => 208) 142 131 ); 143 132 133 return $mobiles; 134 } 135 136 137 /** 138 * Return the mobile user agent. If the user agent is not regocnized to be 139 * a known mobile device then return null. Mobile users are detected based 140 * on $_SERVER['HTTP_USER_AGENT'] and a list of known mobile user agent 141 * identification strings. 142 * 143 * @return array(width, height) if known or null 144 */ 145 function getMobileUserAgent() { 146 static $isChecked = false; 147 static $userAgent = null; 148 149 $mobiles = getMobiles(); 150 151 if (!$isChecked) { 152 144 153 /* Scan through $mobiles and try to find matching user agent. */ 145 154 foreach (array_keys($mobiles) as $needle) { 146 155 /* Check if user agent matches this screen size key. */ 147 156 if (strpos($_SERVER['HTTP_USER_AGENT'], $needle) !== false) { 148 $ screen = $mobiles[$needle];157 $userAgent = $needle; 149 158 break; 150 159 } 151 160 } 152 161 153 162 /* If the user agent was not in our list, check if the terminal accepts WML. */ 154 if ($screen === false) { 155 if (browserAcceptsMediaType(array('WAP', 'WML'))) { 156 $screen = array(); 157 } 163 if ($userAgent === null) { 164 165 if (browserAcceptsMediaType(array('text/html', '\*/\*'))) 166 if (browserAcceptsMediaType(array('WAP'))) 167 $userAgent = 'wap'; 168 169 else if (browserAcceptsMediaType(array('WML'))) 170 $userAgent = 'wml'; 158 171 } 159 172 160 173 $isChecked = true; 161 174 } 162 return $screen; 175 176 return $userAgent; 163 177 } 164 178 165 179 … … 182 196 183 197 184 198 /** 199 * Return the screen size of the mobile user agent. This can be used to do very 200 * detailed modifications to the web site's layout for the mobile user agents. 201 * Meant to be called if isMobileUser() returns true. 202 * 203 * @return array(width, height) if known or null 204 */ 205 function getScreenSize() { 206 207 $screen = null; 208 $mobiles = getMobiles(); 209 $userAgent = getMobileUserAgent(); 210 211 $screen = $mobiles[$userAgent]; 212 213 return $screen; 214 } 215 216 217 /** 185 218 * Return the width of the screen in pixels. Meant to be called if isMobileUser() 186 219 * returns true. See also getScreensize(). 187 220 *