|
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 Core\Plugin; |
|
19
|
|
|
use JBZoo\Utils\FS; |
|
20
|
|
|
use Cake\Core\Configure; |
|
21
|
|
|
use Cake\View\Helper\UrlHelper as CakeUrlHelper; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class UrlHelper |
|
25
|
|
|
* |
|
26
|
|
|
* @package Core\View\Helper |
|
27
|
|
|
*/ |
|
28
|
|
|
class UrlHelper extends CakeUrlHelper |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Get absolute asset path. |
|
33
|
|
|
* |
|
34
|
|
|
* @param string $source Plugin.path/to/file.css |
|
35
|
|
|
* @param null|string $type Assets folder - default is file ext |
|
36
|
|
|
* @return bool|string |
|
37
|
|
|
*/ |
|
38
|
|
|
public function assetPath($source, $type = null) |
|
39
|
|
|
{ |
|
40
|
|
|
$ext = FS::ext($source); |
|
41
|
|
|
$type = (empty($type)) ? $ext : $type; |
|
42
|
|
|
$path = '/' . $type . '/' . $source; |
|
43
|
|
|
|
|
44
|
|
|
$path = FS::clean(WWW_ROOT . $path, '/'); |
|
45
|
|
|
if (FS::isFile($path)) { |
|
46
|
|
|
return $path; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$path = $this->_findPluginAsset($source, $type); |
|
50
|
|
|
|
|
51
|
|
|
return $path; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Find plugin assets by source. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $source |
|
58
|
|
|
* @param null|string $type |
|
59
|
|
|
* @return bool|string |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function _findPluginAsset($source, $type = null) |
|
62
|
|
|
{ |
|
63
|
|
|
list($plugin, $path) = pluginSplit($source); |
|
64
|
|
|
if (Plugin::loaded($plugin)) { |
|
65
|
|
|
$plgPath = implode('/', [Plugin::path($plugin), Configure::read('App.webroot'), $type, $path]); |
|
66
|
|
|
$plgPath = FS::clean($plgPath, '/'); |
|
67
|
|
|
if (FS::isFile($plgPath)) { |
|
68
|
|
|
return $plgPath; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|