Ticket #4336: mythweb-iphone.diff
File mythweb-iphone.diff, 4.4 KB (added by , 16 years ago) |
---|
-
mythplugins/mythweb/includes/skin.php
17 17 if (isMobileUser()) { 18 18 // Browser is mobile but does it accept HTML? 19 19 // @TODO Need to fail more gracefully... 20 $_SESSION['tmpl'] = 'wap';20 $_SESSION['tmpl'] = getMobileUserAgent(); 21 21 // Make sure the skin is set to the appropriate phone-template type 22 22 $_SESSION['skin'] = $_SESSION['tmpl']; 23 23 define('skin', $_SESSION['skin']); -
mythplugins/mythweb/includes/mobile.php
41 41 * @return true or false 42 42 */ 43 43 function isMobileUser() { 44 return (get ScreenSize() === false) ? false : true;44 return (getMobileUserAgent() === null) ? false : true; 45 45 } 46 46 47 function getMobiles() { 47 48 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 49 /* 64 50 * The $mobiles array contains a list of known mobile phone user agent 65 51 * identification strings. Each key of the array is a substring of the … … 75 61 * an empty array or approximate dimensions. 76 62 */ 77 63 $mobiles = array( 64 /* Apple's iPhone */ 65 'iPhone' => array('width' => 320, 'height' => 480), 78 66 /* Phones using the Series 60 platform, e.g. Nokia 3650 and 6600. */ 79 67 'Series 60' => array('width' => 176, 'height' => 208), 80 68 'Series60' => array('width' => 176, 'height' => 208), … … 141 129 //'Opera' => array('width' => 176, 'height' => 208) 142 130 ); 143 131 132 return $mobiles; 133 } 134 135 136 /** 137 * Return the mobile user agent. If the user agent is not regocnized to be 138 * a known mobile device then return null. Mobile users are detected based 139 * on $_SERVER['HTTP_USER_AGENT'] and a list of known mobile user agent 140 * identification strings. 141 * 142 * @return array(width, height) if known or null 143 */ 144 function getMobileUserAgent() { 145 static $isChecked = false; 146 static $userAgent = null; 147 148 $mobiles = getMobiles(); 149 150 if (!$isChecked) { 151 144 152 /* Scan through $mobiles and try to find matching user agent. */ 145 153 foreach (array_keys($mobiles) as $needle) { 146 154 /* Check if user agent matches this screen size key. */ 147 155 if (strpos($_SERVER['HTTP_USER_AGENT'], $needle) !== false) { 148 $ screen = $mobiles[$needle];156 $userAgent = $needle; 149 157 break; 150 158 } 151 159 } 152 160 153 // If the user agent was not in our list, check if the terminal accepts WAP. 154 if ($screen === false) { 155 if (browserAcceptsMediaType(array('WAP'))) { 156 $screen = array(); 157 } 161 /* If the user agent was not in our list, check media type */ 162 if ($userAgent === null) { 163 164 if (browserAcceptsMediaType(array('text/html', '\*/\*'))) 165 if (browserAcceptsMediaType(array('WAP'))) 166 $userAgent = 'wap'; 167 158 168 } 159 169 160 170 $isChecked = true; 161 171 } 162 return $screen; 172 173 return $userAgent; 163 174 } 164 175 165 176 … … 182 193 183 194 184 195 /** 196 * Return the screen size of the mobile user agent. This can be used to do very 197 * detailed modifications to the web site's layout for the mobile user agents. 198 * Meant to be called if isMobileUser() returns true. 199 * 200 * @return array(width, height) if known or null 201 */ 202 function getScreenSize() { 203 204 $screen = null; 205 $mobiles = getMobiles(); 206 $userAgent = getMobileUserAgent(); 207 208 $screen = $mobiles[$userAgent]; 209 210 return $screen; 211 } 212 213 214 /** 185 215 * Return the width of the screen in pixels. Meant to be called if isMobileUser() 186 216 * returns true. See also getScreensize(). 187 217 *