From bc2a1bf0a8e59f009c005cc78f1b22420e689c63 Mon Sep 17 00:00:00 2001 From: Michael Ang Date: Wed, 19 May 2010 23:33:58 +0000 Subject: [PATCH] Add browser detection for iPad and iPhone/iPod --- BookReaderIA/inc/BookReader.inc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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 -- 2.20.1