Ticket #4336: mythweb-iphone.diff

File mythweb-iphone.diff, 4.4 KB (added by mrandtx@…, 12 years ago)

Updated patch to trunk

  • mythplugins/mythweb/includes/skin.php

     
    1717    if (isMobileUser()) {
    1818    // Browser is mobile but does it accept HTML?
    1919    // @TODO Need to fail more gracefully...
    20         $_SESSION['tmpl'] = 'wap';
     20        $_SESSION['tmpl'] = getMobileUserAgent();
    2121    // Make sure the skin is set to the appropriate phone-template type
    2222        $_SESSION['skin'] = $_SESSION['tmpl'];
    2323        define('skin', $_SESSION['skin']);
  • mythplugins/mythweb/includes/mobile.php

     
    4141 * @return true or false
    4242 */
    4343function isMobileUser() {
    44   return (getScreenSize() === false) ? false : true;
     44  return (getMobileUserAgent() === null) ? false : true;
    4545}
    4646
     47function getMobiles() {
    4748
    48 /**
    49  * Return the screen size of the mobile user agent. This can be used to do very
    50  * 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 the
    52  * user is a known mobile device but the screen size is unknown then return
    53  * 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 false
    57  */
    58 function getScreenSize() {
    59   static $isChecked = false;
    60   static $screen = false;
    61 
    62   if (!$isChecked) {
    6349    /*
    6450     * The $mobiles array contains a list of known mobile phone user agent
    6551     * identification strings. Each key of the array is a substring of the
     
    7561     * an empty array or approximate dimensions.
    7662     */
    7763    $mobiles = array(
     64                /* Apple's iPhone */
     65                    'iPhone'     => array('width' => 320, 'height' => 480),
    7866                /* Phones using the Series 60 platform, e.g. Nokia 3650 and 6600. */
    7967                    'Series 60'  => array('width' => 176, 'height' => 208),
    8068                    'Series60'   => array('width' => 176, 'height' => 208),
     
    141129                     //'Opera' => array('width' => 176, 'height' => 208)
    142130             );
    143131
     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  */
     144function getMobileUserAgent() {
     145  static $isChecked = false;
     146  static $userAgent = null;
     147
     148  $mobiles = getMobiles();
     149
     150  if (!$isChecked) {
     151
    144152    /* Scan through $mobiles and try to find matching user agent. */
    145153    foreach (array_keys($mobiles) as $needle) {
    146154      /* Check if user agent matches this screen size key. */
    147155      if (strpos($_SERVER['HTTP_USER_AGENT'], $needle) !== false) {
    148         $screen = $mobiles[$needle];
     156        $userAgent = $needle;
    149157        break;
    150158      }
    151159    }
    152160
    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
    158168    }
    159169
    160170    $isChecked = true;
    161171  }
    162   return $screen;
     172
     173  return $userAgent;
    163174}
    164175
    165176
     
    182193
    183194
    184195/**
     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 */
     202function getScreenSize() {
     203
     204  $screen = null;
     205  $mobiles = getMobiles();
     206  $userAgent = getMobileUserAgent();
     207
     208  $screen = $mobiles[$userAgent];
     209
     210  return $screen;
     211}
     212
     213
     214/**
    185215 * Return the width of the screen in pixels. Meant to be called if isMobileUser()
    186216 * returns true. See also getScreensize().
    187217 *