Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.97 KB | None | 0 0
  1.     public static function isMobile($check = true)
  2.     {
  3.         if ($check) {
  4.             if (self::get('nomobile') !== null) {
  5.                 if (self::get('nomobile')) {
  6.                     waSystem::getInstance()->getStorage()->write('nomobile', true);
  7.                 } else {
  8.                     waSystem::getInstance()->getStorage()->remove('nomobile');
  9.                 }
  10.             } elseif (self::get('mobile')) {
  11.                 waSystem::getInstance()->getStorage()->remove('nomobile');
  12.             }
  13.             if (waSystem::getInstance()->getStorage()->read('nomobile')) {
  14.                 return false;
  15.             }
  16.         }
  17.  
  18.         if (self::$mobile !== null) {
  19.             return self::$mobile;
  20.         }
  21.         $user_agent = self::server('HTTP_USER_AGENT');
  22.  
  23.         $desktop_platforms = array(
  24.             'ipad'       => 'ipad',
  25.             'galaxy-tab' => 'android.*?GT\-P',
  26.         );
  27.         foreach ($desktop_platforms as $pattern) {
  28.             if (preg_match('/'.$pattern.'/i', $user_agent)) {
  29.                 self::$mobile = false;
  30.                 return false;
  31.             }
  32.         }
  33.  
  34.         $mobile_platforms = array(
  35.             "google-mobile" => "googlebot\-mobile",
  36.             "android"    => "android",
  37.             "blackberry" => "(blackberry|rim tablet os)",
  38.             "iphone"     => "(iphone|ipod)",
  39.             "opera"      => "opera (mini|mobi|mobile)",
  40.             "palm"       => "(palmos|avantgo|blazer|elaine|hiptop|palm|plucker|xiino)",
  41.             "windows"    => "windows\sce;\s(iemobile|ppc|smartphone)",
  42.             "generic"    => "(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap)"
  43.         );
  44.         foreach ($mobile_platforms as $id => $pattern) {
  45.             if (preg_match('/'.$pattern.'/i', $user_agent)) {
  46.                 self::$mobile = $id;
  47.                 return $id;
  48.             }
  49.         }
  50.  
  51.         self::$mobile = false;
  52.         return false;
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement