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