Add browser detection for iPad and iPhone/iPod
authorMichael Ang <mang@archive.org>
Wed, 19 May 2010 23:33:58 +0000 (23:33 +0000)
committerMichael Ang <mang@archive.org>
Wed, 19 May 2010 23:33:58 +0000 (23:33 +0000)
BookReaderIA/inc/BookReader.inc

index 41c0595..56a1fd6 100644 (file)
@@ -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