This repository was archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobileesp.php
More file actions
306 lines (203 loc) · 6.26 KB
/
mobileesp.php
File metadata and controls
306 lines (203 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?php
/*
* MobileESP
* The MobileESP Project is Copyright 2010-2012, Anthony Hand
*
* Plugin Author: Robert Gerald Porter <rob@weeverapps.com>
* Library Author: Anthony Hand <http://code.google.com/p/mobileesp/>
* Version: 2.0
* License: GPL v3.0
*
* This extension is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This extension is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details <http://www.gnu.org/licenses/>.
*
*/
defined('_JEXEC') or die();
# Joomla 3.0 nonsense
if( !defined('DS') )
define( 'DS', DIRECTORY_SEPARATOR );
jimport('joomla.plugin.plugin');
require_once JPATH_PLUGINS.DS.'system'.DS.'mobileesp'.DS.'mdetect.php';
class plgSystemMobileESP extends JPlugin
{
public function plgSystemMobileESP(&$subject, $config)
{
$app = JFactory::getApplication();
// disable on the admin backend
if( $app->isAdmin() )
return;
parent::__construct($subject, $config);
$this->checkRedirect();
}
public function checkRedirect()
{
$session = JFactory::getSession();
// none of this if it's an RSS request, specific template, or
// component-only setting to play nice with Joomla devs & Weever
if( JRequest::getVar('template') || JRequest::getVar('format') || JRequest::getVar('tmpl') || JRequest::getVar('wxfeed') || JRequest::getVar('jCorsRequest') )
return;
/* Compatibility with login extension */
if( JRequest::getVar('option') == 'com_weeverlogin' )
return;
if( JRequest::getVar('option') == "com_user" || JRequest::getVar('option') == "com_users" || JRequest::getVar('wxConfirmLogin') == 1)
return;
// kill the ignore_mobile session var if full=0 added to query
if (JRequest::getVar('full') == '0')
{
$session->set( 'ignore_mobile', '' );
}
// if requesting the full site, ignore all this
if(JRequest::getVar('full') > 0 || $session->get( 'ignore_mobile', '' ) == '1')
{
$session->set( 'ignore_mobile', '1' );
return;
}
switch($this->params->get('appService'))
{
case "weever":
// no sense in doing anything if the component isn't installed
if(!JComponentHelper::isEnabled('com_weever'))
return;
$settings = mobileESPWeeverHelper::getWeeverSettingsDB();
if(mobileESPWeeverHelper::getAppEnabled($settings) == "0")
return;
$devices = mobileESPWeeverHelper::getDevices($settings);
if(strstr($devices,","))
$deviceList = explode(",",$devices);
else
$deviceList[] = $devices;
$uagent_obj = new uagent_info();
if(!$uagent_obj->DetectWebkit())
{
$session->set( 'ignore_mobile', '1' );
return;
}
$weeverApp = false;
foreach( (array) $deviceList as $v )
{
if(!$v)
continue;
if( $uagent_obj->$v() )
$weeverApp = true;
}
if($weeverApp == false)
{
$session->set( 'ignore_mobile', '1' );
return;
}
$request_uri = $_SERVER['REQUEST_URI'];
$request_uri = str_replace("?full=0","",$request_uri);
$request_uri = str_replace("&full=0","",$request_uri);
if($request_uri && $request_uri != 'index.php' && $request_uri != '/' )
$exturl = '?exturl='.urlencode($request_uri);
else
$exturl = "";
// requires version 0.9.2+ of com_weever
if($customAppDomain = mobileESPWeeverHelper::getCustomAppDomain($settings))
{
header('Location: http://'.$customAppDomain.$exturl);
jexit();
}
else
{
$siteDomain = mobileESPWeeverHelper::getPrimaryDomain($settings);
header('Location: http://weeverapp.com/app/'.$siteDomain.$exturl);
jexit();
}
break;
default:
if( !$this->params->get('forwardingEnabled', 0) )
return;
$uagent_obj = new uagent_info();
if( !$this->params->get('webkitOnly', 0) && ( !$uagent_obj->DetectWebkit() ) )
{
$session->set( 'ignore_mobile', '1' );
return;
}
$devices = $this->params->get('devicesForwarded', '');
if(!$devices)
return;
$deviceList = explode(",", $devices);
$forwardApp = false;
foreach( (array) $deviceList as $v )
{
if( $uagent_obj->$v() )
$forwardApp = true;
}
// only iterate once, in the case that the redirect is to a landing page
if( mobileESPWeeverHelper::currentPageURL() == $this->params->get('forwardingUrl', '') )
$session->set( 'ignore_mobile', '1' );
else
$session->set( 'ignore_mobile', '' );
if($forwardApp == false)
return;
header( 'Location: '.$this->params->get('forwardingUrl', '') );
break;
}
}
}
class mobileESPWeeverHelper {
static function getWeeverSettingsDB()
{
$db = JFactory::getDBO();
$query = " SELECT * ".
" FROM #__weever_config ";
$db->setQuery($query);
$result = $db->loadObjectList();
return $result;
}
static function getPrimaryDomain($result)
{
foreach((array)$result as $k=>$v)
{
if($v->option == "primary_domain")
return $v->setting;
}
return null;
}
static function getDevices($result)
{
foreach((array)$result as $k=>$v)
{
if($v->option == "devices")
return $v->setting;
}
return null;
}
static function getAppEnabled($result)
{
foreach((array)$result as $k=>$v)
{
if($v->option == "app_enabled")
return $v->setting;
}
return null;
}
static function getCustomAppDomain($result)
{
foreach((array)$result as $k=>$v)
{
if($v->option == "domain")
return $v->setting;
}
return null;
}
static function currentPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on")
$pageURL .= "s";
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
return $pageURL;
}
}