1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Mobile |
5
|
|
|
* @author Iurii Makukh <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2015, Iurii Makukh |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl.html GNU/GPLv3 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\mobile; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Library; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Main class for Mobile theme |
16
|
|
|
*/ |
17
|
|
|
class Mobile |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Library class instance |
22
|
|
|
* @var \gplcart\core\Library $library |
23
|
|
|
*/ |
24
|
|
|
protected $library; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param Library $library |
28
|
|
|
*/ |
29
|
|
|
public function __construct(Library $library) |
30
|
|
|
{ |
31
|
|
|
$this->library = $library; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Implements hook "route.list" |
36
|
|
|
* @param array $routes |
37
|
|
|
*/ |
38
|
|
|
public function hookRouteList(array &$routes) |
39
|
|
|
{ |
40
|
|
|
$routes['admin/module/settings/mobile'] = array( |
41
|
|
|
'access' => 'module_edit', |
42
|
|
|
'handlers' => array( |
43
|
|
|
'controller' => array('gplcart\\modules\\mobile\\controllers\\Settings', 'editSettings') |
44
|
|
|
) |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Implements hook "template.data" |
50
|
|
|
* @param array $data |
51
|
|
|
* @param \gplcart\core\controllers\frontend\Controller $controller |
52
|
|
|
*/ |
53
|
|
|
public function hookTemplateData(array &$data, $controller) |
54
|
|
|
{ |
55
|
|
|
$this->replaceJquery($data, $controller); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Implements hook "theme" |
60
|
|
|
* @param \gplcart\core\Controller $controller |
61
|
|
|
*/ |
62
|
|
|
public function hookTheme($controller) |
63
|
|
|
{ |
64
|
|
|
if ($controller->isCurrentTheme('mobile') && !$controller->isInternalRoute()) { |
65
|
|
|
$this->setModuleAssets($controller); |
66
|
|
|
$this->setModuleMetaTags($controller); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Sets module specific assets |
72
|
|
|
* @param \gplcart\core\Controller $controller |
73
|
|
|
*/ |
74
|
|
|
protected function setModuleAssets($controller) |
75
|
|
|
{ |
76
|
|
|
$controller->addAssetLibrary('jquery_mobile'); |
77
|
|
|
$controller->setJs(__DIR__ . '/js/common.js'); |
78
|
|
|
$controller->setCss(__DIR__ . '/css/common.css'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Sets meta tags |
83
|
|
|
* @param \gplcart\core\Controller $controller |
84
|
|
|
*/ |
85
|
|
|
protected function setModuleMetaTags($controller) |
86
|
|
|
{ |
87
|
|
|
$controller->setMeta(array('charset' => 'utf-8')); |
88
|
|
|
$controller->setMeta(array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1')); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Downgrade jQuery |
93
|
|
|
* Jquery Mobile 1.4.5 does not work correctly with Jquery 2.2.4 |
94
|
|
|
* @link https://github.com/jquery/jquery/issues/2936 |
95
|
|
|
* @param array $data |
96
|
|
|
* @param \gplcart\core\controllers\frontend\Controller $controller |
97
|
|
|
* @return bool |
98
|
|
|
*/ |
99
|
|
|
protected function replaceJquery(array &$data, $controller) |
100
|
|
|
{ |
101
|
|
|
if (!$controller->isCurrentTheme('mobile') || empty($data['_js_top']) || $controller->isInternalRoute()) { |
102
|
|
|
return false; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$jquery = $this->library->get('jquery'); |
106
|
|
|
|
107
|
|
|
foreach ($data['_js_top'] as $key => $asset) { |
108
|
|
|
|
109
|
|
|
if (dirname($asset['file']) !== $jquery['basepath']) { |
110
|
|
|
continue; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$asset['file'] = __DIR__ . '/js/jquery.js'; |
114
|
|
|
$asset['key'] = $asset['asset'] = gplcart_path_normalize(gplcart_path_relative($asset['file'])); |
115
|
|
|
$data['_js_top'][$asset['key']] = $asset; |
116
|
|
|
|
117
|
|
|
unset($data['_js_top'][$key]); |
118
|
|
|
return true; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return false; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|