From: Michael Ang Date: Wed, 19 May 2010 23:33:58 +0000 (+0000) Subject: Add browser detection for iPad and iPhone/iPod X-Git-Url: http://git.rot13.org/?p=bookreader.git;a=commitdiff_plain;h=bc2a1bf0a8e59f009c005cc78f1b22420e689c63 Add browser detection for iPad and iPhone/iPod --- diff --git a/BookReaderIA/inc/BookReader.inc b/BookReaderIA/inc/BookReader.inc index 41c0595..56a1fd6 100644 --- a/BookReaderIA/inc/BookReader.inc +++ b/BookReaderIA/inc/BookReader.inc @@ -266,6 +266,34 @@ class BookReader return null; // was not handled } + // $$$ Ideally we will not rely on user agent, but for the moment we do + public static function paramsFromUserAgent($userAgent) { + $browserParams = array( + 'ipad' => array( 'ui' => 'touch' ), + 'iphone' => array( 'ui' => 'embed', 'mode' => '1up'), + ); + + $browser = BookReader::browserFromUserAgent($userAgent); + if ($browser) { + return $browserParams[$browser]; + } + return array(); + } + + public static function browserFromUserAgent($userAgent) { + $browserPatterns = array( + 'ipad' => '/iPad/', + 'iphone' => '/iPhone/', // Also cover iPod Touch + ); + + foreach ($browserPatterns as $browser => $pattern) { + if (preg_match($pattern, $userAgent)) { + return $browser; + } + } + return null; + } + } ?> \ No newline at end of file