Asset.php
2.98 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
<?php
namespace Nextend\Framework\Asset\Css;
use Nextend\Framework\Asset\AbstractAsset;
use Nextend\Framework\Asset\Fonts\Google\Google;
use Nextend\Framework\Platform\Platform;
use Nextend\Framework\Plugin;
use Nextend\Framework\Settings;
use Nextend\Framework\Url\Url;
use Nextend\Framework\View\Html;
use Nextend\SmartSlider3\SmartSlider3Info;
class Asset extends AbstractAsset {
public function __construct() {
$this->cache = new Cache();
}
public function getOutput() {
$headerPreload = !!Settings::get('header-preload', '0');
$needProtocol = !Settings::get('protocol-relative', '1');
Google::build();
Less\Less::build();
$output = "";
$this->urls = array_unique($this->urls);
foreach ($this->staticGroupPreload as $file) {
$url = $this->filterSrc(Url::pathToUri($file, $needProtocol) . '?ver=' . SmartSlider3Info::$revisionShort);
$output .= Html::style($url, true, array(
'media' => 'all'
)) . "\n";
if ($headerPreload) {
header('Link: <' . $url . '>; rel=preload; as=style', false);
}
}
$linkAttributes = array(
'media' => 'all'
);
if (!Platform::isAdmin() && Settings::get('async-non-primary-css', 0)) {
$linkAttributes = array(
'media' => 'print',
'onload' => "this.media='all'"
);
}
foreach ($this->urls as $url) {
$url = $this->filterSrc($url);
$output .= Html::style($url, true, $linkAttributes) . "\n";
}
foreach ($this->getFiles() as $file) {
if (substr($file, 0, 2) == '//') {
$url = $this->filterSrc($file);
} else {
$url = $this->filterSrc(Url::pathToUri($file, $needProtocol) . '?ver=' . SmartSlider3Info::$revisionShort);
}
$output .= Html::style($url, true, $linkAttributes) . "\n";
}
$inlineText = '';
foreach ($this->inline as $key => $value) {
if (!is_numeric($key)) {
$output .= Html::style($value, false, array(
'data-related' => $key
)) . "\n";
} else {
$inlineText .= $value;
}
}
if (!empty($inlineText)) {
$output .= Html::style($inlineText) . "\n";
}
return $output;
}
private function filterSrc($src) {
return Plugin::applyFilters('n2_style_loader_src', $src);
}
public function get() {
Google::build();
Less\Less::build();
return array(
'url' => $this->urls,
'files' => array_merge($this->staticGroupPreload, $this->getFiles()),
'inline' => implode("\n", $this->inline)
);
}
public function getAjaxOutput() {
$output = implode("\n", $this->inline);
return $output;
}
}