|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CakeCMS Core |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the of the simple cms based on CakePHP 3. |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @package Core |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php |
|
12
|
|
|
* @link https://github.com/CakeCMS/Core". |
|
13
|
|
|
* @author Sergey Kalistratov <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Core\View\Helper; |
|
17
|
|
|
|
|
18
|
|
|
use JBZoo\Utils\Str; |
|
19
|
|
|
use Cake\Utility\Hash; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class AssetsHelper |
|
23
|
|
|
* |
|
24
|
|
|
* @package Core\View\Helper |
|
25
|
|
|
* @property \Cake\View\Helper\UrlHelper $Url |
|
26
|
|
|
* @property \Core\View\Helper\HtmlHelper $Html |
|
27
|
|
|
*/ |
|
28
|
|
|
class AssetsHelper extends AppHelper |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Use helpers. |
|
33
|
|
|
* |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
public $helpers = [ |
|
37
|
|
|
'Url' => ['className' => 'Core.Url'], |
|
38
|
|
|
'Html' => ['className' => 'Core.Html'], |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Default assets options. |
|
43
|
|
|
* |
|
44
|
|
|
* @var array |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $_options = [ |
|
47
|
|
|
'block' => 'assets', |
|
48
|
|
|
'fullBase' => true, |
|
49
|
|
|
'weight' => 10, |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get sort assets included list. |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $type |
|
56
|
|
|
* @return array|null |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getAssets($type = 'css') |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->Html->getAssets($type); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Include bootstrap. |
|
65
|
|
|
* |
|
66
|
|
|
* @return $this |
|
67
|
|
|
*/ |
|
68
|
|
View Code Duplication |
public function bootstrap() |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
|
|
$this->jquery(); |
|
71
|
|
|
|
|
72
|
|
|
$this->Html->script('libs/bootstrap.min.js', $this->_setOptions([ |
|
73
|
|
|
'weight' => 2, |
|
74
|
|
|
'alias' => __FUNCTION__, |
|
75
|
|
|
])); |
|
76
|
|
|
|
|
77
|
|
|
$this->Html->css('libs/bootstrap.min.css', $this->_setOptions([ |
|
78
|
|
|
'weight' => 1, |
|
79
|
|
|
'alias' => __FUNCTION__, |
|
80
|
|
|
])); |
|
81
|
|
|
|
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Include fancybox. |
|
87
|
|
|
* |
|
88
|
|
|
* @return $this |
|
89
|
|
|
*/ |
|
90
|
|
View Code Duplication |
public function fancyBox() |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
|
|
$this->jquery(); |
|
93
|
|
|
|
|
94
|
|
|
$this->Html->script('libs/fancybox.min.js', $this->_setOptions([ |
|
95
|
|
|
'weight' => 2, |
|
96
|
|
|
'alias' => __FUNCTION__, |
|
97
|
|
|
])); |
|
98
|
|
|
|
|
99
|
|
|
$this->Html->css('libs/fancybox.min.css', $this->_setOptions([ |
|
100
|
|
|
'weight' => 1, |
|
101
|
|
|
'alias' => __FUNCTION__, |
|
102
|
|
|
])); |
|
103
|
|
|
|
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Include font awesome. |
|
109
|
|
|
* |
|
110
|
|
|
* @return $this |
|
111
|
|
|
*/ |
|
112
|
|
|
public function fontAwesome() |
|
113
|
|
|
{ |
|
114
|
|
|
$this->Html->css('libs/font-awesome.min.css', $this->_setOptions([ |
|
115
|
|
|
'weight' => 1, |
|
116
|
|
|
'alias' => 'font-awesome', |
|
117
|
|
|
])); |
|
118
|
|
|
|
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Include jquery lib. |
|
124
|
|
|
* |
|
125
|
|
|
* @return $this |
|
126
|
|
|
*/ |
|
127
|
|
|
public function jquery() |
|
128
|
|
|
{ |
|
129
|
|
|
$this->Html->script('libs/jquery.min.js', $this->_setOptions([ |
|
130
|
|
|
'weight' => 1, |
|
131
|
|
|
'alias' => __FUNCTION__, |
|
132
|
|
|
])); |
|
133
|
|
|
|
|
134
|
|
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Include jquery factory. |
|
139
|
|
|
* |
|
140
|
|
|
* @return $this |
|
141
|
|
|
*/ |
|
142
|
|
View Code Duplication |
public function jqueryFactory() |
|
|
|
|
|
|
143
|
|
|
{ |
|
144
|
|
|
$this->jquery(); |
|
145
|
|
|
|
|
146
|
|
|
$this->Html->script('libs/utils.min.js', $this->_setOptions([ |
|
147
|
|
|
'weight' => 2, |
|
148
|
|
|
'alias' => 'jquery-utils', |
|
149
|
|
|
])); |
|
150
|
|
|
|
|
151
|
|
|
$this->Html->script('libs/jquery-factory.min.js', $this->_setOptions([ |
|
152
|
|
|
'weight' => 2, |
|
153
|
|
|
'alias' => 'jquery-factory', |
|
154
|
|
|
])); |
|
155
|
|
|
|
|
156
|
|
|
return $this; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Include materialize design. |
|
161
|
|
|
* |
|
162
|
|
|
* @return $this |
|
163
|
|
|
*/ |
|
164
|
|
View Code Duplication |
public function materialize() |
|
|
|
|
|
|
165
|
|
|
{ |
|
166
|
|
|
$this->jquery(); |
|
167
|
|
|
|
|
168
|
|
|
$this->Html->script('libs/materialize.min.js', $this->_setOptions([ |
|
169
|
|
|
'weight' => 2, |
|
170
|
|
|
'alias' => __FUNCTION__, |
|
171
|
|
|
])); |
|
172
|
|
|
|
|
173
|
|
|
$this->Html->css('libs/materialize.min.css', $this->_setOptions([ |
|
174
|
|
|
'weight' => 1, |
|
175
|
|
|
'alias' => __FUNCTION__, |
|
176
|
|
|
])); |
|
177
|
|
|
|
|
178
|
|
|
return $this; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Include sweet alert. |
|
183
|
|
|
* |
|
184
|
|
|
* @return $this |
|
185
|
|
|
*/ |
|
186
|
|
View Code Duplication |
public function sweetAlert() |
|
|
|
|
|
|
187
|
|
|
{ |
|
188
|
|
|
$this->jquery(); |
|
189
|
|
|
|
|
190
|
|
|
$this->Html->script('libs/sweetalert.min.js', $this->_setOptions([ |
|
191
|
|
|
'weight' => 2, |
|
192
|
|
|
'alias' => __FUNCTION__, |
|
193
|
|
|
])); |
|
194
|
|
|
|
|
195
|
|
|
$this->Html->css('libs/sweetalert.min.css', $this->_setOptions([ |
|
196
|
|
|
'weight' => 1, |
|
197
|
|
|
'alias' => __FUNCTION__, |
|
198
|
|
|
])); |
|
199
|
|
|
|
|
200
|
|
|
return $this; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Include jquery table check all. |
|
205
|
|
|
* |
|
206
|
|
|
* @return $this |
|
207
|
|
|
*/ |
|
208
|
|
|
public function tableCheckAll() |
|
209
|
|
|
{ |
|
210
|
|
|
$this->jquery(); |
|
211
|
|
|
|
|
212
|
|
|
$this->Html->script(['libs/jquery-check-all.min.js'], $this->_setOptions([ |
|
213
|
|
|
'weight' => 2, |
|
214
|
|
|
'alias' => __FUNCTION__, |
|
215
|
|
|
])); |
|
216
|
|
|
|
|
217
|
|
|
return $this; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* Autoload plugin assets. |
|
222
|
|
|
* |
|
223
|
|
|
* @return void |
|
224
|
|
|
*/ |
|
225
|
|
|
public function loadPluginAssets() |
|
226
|
|
|
{ |
|
227
|
|
|
$plugin = (string) $this->request->param('plugin'); |
|
228
|
|
|
$prefix = ($this->request->param('prefix')) ? $this->request->param('prefix') . '/' : null; |
|
229
|
|
|
$action = (string) $this->request->param('action'); |
|
230
|
|
|
|
|
231
|
|
|
$controller = (string) $this->request->param('controller'); |
|
232
|
|
|
$widgetName = Str::slug($controller . '-' . $action) . '.js'; |
|
233
|
|
|
$cssOptions = ['block' => 'css_bottom', 'fullBase' => true]; |
|
234
|
|
|
|
|
235
|
|
|
$this->Html->css($plugin . '.' . $prefix . 'styles.css', $cssOptions); |
|
236
|
|
|
$this->Html->less($plugin . '.' . $prefix . 'styles.less', $cssOptions); |
|
237
|
|
|
$this->Html->script([ |
|
238
|
|
|
$plugin . '.' . $prefix . 'widget/' . $widgetName, |
|
239
|
|
|
$plugin . '.' . $prefix . 'script.js', |
|
240
|
|
|
], ['block' => 'script_bottom', 'fullBase' => true]); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* Setup asset options. |
|
245
|
|
|
* |
|
246
|
|
|
* @param array $options |
|
247
|
|
|
* @return array |
|
248
|
|
|
*/ |
|
249
|
|
|
protected function _setOptions(array $options = []) |
|
250
|
|
|
{ |
|
251
|
|
|
return Hash::merge($this->_options, $options); |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.