Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpmobiledeviceregexpfilter.php
Go to the documentation of this file.
1 <?php
15 class ezpMobileDeviceRegexpFilter implements ezpMobileDeviceDetectFilterInterface
16 {
22 protected $httpUserAgent;
23
29 protected $httpAccept;
30
36 protected $userAgentAlias = '';
37
43 protected $isMobileDevice = false;
44
49 public function __construct()
50 {
51 $this->httpUserAgent = '';
52 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) )
53 {
54 $this->httpUserAgent = $_SERVER['HTTP_USER_AGENT'];
55 }
56
57 $this->httpAccept = '';
58 if ( isset( $_SERVER['HTTP_ACCEPT'] ) )
59 {
60 $this->httpAccept = $_SERVER['HTTP_ACCEPT'];
61 }
62 }
63
70 public function process()
71 {
72 $ini = eZINI::instance();
73
74 if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] )
75 || isset( $_SERVER['HTTP_PROFILE'] )
76 || strpos( $this->httpAccept, 'text/vnd.wap.wml' ) > 0
77 || strpos( $this->httpAccept, 'application/vnd.wap.xhtml+xml' ) > 0)
78 {
79 $this->isMobileDevice = true;
80 }
81 else if ( in_array( strtolower( substr( $this->httpUserAgent, 0, 4 ) ),
82 explode( '|', $ini->variable( 'SiteAccessSettings', 'MobileUserAgentCodes' ) ) ) )
83 {
84 $this->isMobileDevice = true;
85 }
86 else
87 {
88 foreach ( $ini->variable( 'SiteAccessSettings', 'MobileUserAgentRegexps' ) as $userAgentAlias => $regexp )
89 {
90 if ( preg_match( $regexp, $this->httpUserAgent ) )
91 {
92 $this->isMobileDevice = true;
93 $this->userAgentAlias = $userAgentAlias;
94
95 break;
96 }
97 }
98 }
99 }
100
105 public function redirect()
106 {
107 $http = eZHTTPTool::instance();
108 $currentSiteAccess = eZSiteAccess::current();
109
110 if ( $http->hasGetVariable( 'notmobile' ) )
111 {
112 setcookie( 'eZMobileDeviceDetect', 1, time() + (int)eZINI::instance()->variable( 'SiteAccessSettings', 'MobileDeviceDetectCookieTimeout' ), '/' );
113
114 $http->redirect( eZSys::indexDir() );
115
116 eZExecution::cleanExit();
117 }
118
119 if ( !isset( $_COOKIE['eZMobileDeviceDetect'] )
120 && !in_array( $currentSiteAccess['name'], eZINI::instance()->variable( 'SiteAccessSettings', 'MobileSiteAccessList' ) ) )
121 {
122 $currentUrl = eZSys::serverURL() . eZSys::requestURI();
123 $redirectUrl = eZINI::instance()->variable( 'SiteAccessSettings', 'MobileSiteAccessURL' );
124
125 // Do not redirect if already on the redirect url
126 if ( strpos( $currentUrl, $redirectUrl ) !== 0 )
127 {
128 // Default siteaccess name needs to be removed from the uri when redirecting
129 $uri = explode( '/', ltrim( eZSys::requestURI(), '/' ) );
130
131 if ( array_shift( $uri ) == $currentSiteAccess['name'] )
132 {
133 $http->redirect( $redirectUrl . '/' . implode( '/', $uri ) . eZSys::queryString() );
134 }
135 else
136 {
137 $http->redirect( $redirectUrl . eZSys::requestURI() . eZSys::queryString() );
138 }
139 }
140
141 eZExecution::cleanExit();
142 }
143 }
144
150 public function isMobileDevice()
151 {
152 return $this->isMobileDevice;
153 }
154
160 public function getUserAgentAlias()
161 {
162 return $this->userAgentAlias;
163 }
164 }
$uri
$uri
Definition: activate.php:71
$http
$http
Definition: authorize.php:20
eZExecution\cleanExit
static cleanExit()
Definition: ezexecution.php:101
eZSiteAccess\current
static current()
Definition: ezsiteaccess.php:676
eZSys\indexDir
static indexDir( $withAccessList=true)
Definition: ezsys.php:594
eZSys\serverURL
static serverURL()
Definition: ezsys.php:793
eZSys\requestURI
static requestURI()
Definition: ezsys.php:1263
eZSys\queryString
static queryString()
Definition: ezsys.php:608
$ini
$ini
Definition: classes/admin/linklist.php:64
ezpMobileDeviceRegexpFilter
Definition: ezpmobiledeviceregexpfilter.php:16
ezpMobileDeviceRegexpFilter\$isMobileDevice
$isMobileDevice
Definition: ezpmobiledeviceregexpfilter.php:43
ezpMobileDeviceRegexpFilter\$httpUserAgent
$httpUserAgent
Definition: ezpmobiledeviceregexpfilter.php:22
ezpMobileDeviceRegexpFilter\redirect
redirect()
Definition: ezpmobiledeviceregexpfilter.php:105
ezpMobileDeviceRegexpFilter\getUserAgentAlias
getUserAgentAlias()
Definition: ezpmobiledeviceregexpfilter.php:160
ezpMobileDeviceRegexpFilter\process
process()
Definition: ezpmobiledeviceregexpfilter.php:70
ezpMobileDeviceRegexpFilter\__construct
__construct()
Definition: ezpmobiledeviceregexpfilter.php:49
ezpMobileDeviceRegexpFilter\$userAgentAlias
$userAgentAlias
Definition: ezpmobiledeviceregexpfilter.php:36
ezpMobileDeviceRegexpFilter\$httpAccept
$httpAccept
Definition: ezpmobiledeviceregexpfilter.php:29
ezpMobileDeviceRegexpFilter\isMobileDevice
isMobileDevice()
Definition: ezpmobiledeviceregexpfilter.php:150
ezpMobileDeviceDetectFilterInterface
Definition: ezpmobiledevicedetectfilterinterface.php:13
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.