This commit is contained in:
2024-05-20 15:37:46 +03:00
commit 00b7dbd0b7
10404 changed files with 3285853 additions and 0 deletions

View File

@ -0,0 +1,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;
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace Nextend\Framework\Asset\Css;
use Nextend\Framework\Asset\AbstractCache;
use Nextend\Framework\Filesystem\Filesystem;
use Nextend\Framework\Url\Url;
class Cache extends AbstractCache {
public $outputFileType = "css";
private $baseUrl = '';
private $basePath = '';
public function getAssetFileFolder() {
return Filesystem::getWebCachePath() . DIRECTORY_SEPARATOR . $this->group . DIRECTORY_SEPARATOR;
}
protected function parseFile($cache, $content, $originalFilePath) {
$this->basePath = dirname($originalFilePath);
$this->baseUrl = Filesystem::pathToAbsoluteURL($this->basePath);
return preg_replace_callback('#url\([\'"]?([^"\'\)]+)[\'"]?\)#', array(
$this,
'makeAbsoluteUrl'
), $content);
}
private function makeAbsoluteUrl($matches) {
if (substr($matches[1], 0, 5) == 'data:') return $matches[0];
if (substr($matches[1], 0, 4) == 'http') return $matches[0];
if (substr($matches[1], 0, 2) == '//') return $matches[0];
$exploded = explode('?', $matches[1]);
$realPath = realpath($this->basePath . '/' . $exploded[0]);
if ($realPath === false) {
return 'url(' . str_replace(array(
'http://',
'https://'
), '//', $this->baseUrl) . '/' . $matches[1] . ')';
}
$realPath = Filesystem::convertToRealDirectorySeparator($realPath);
return 'url(' . Url::pathToUri($realPath, false) . (isset($exploded[1]) ? '?' . $exploded[1] : '') . ')';
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace Nextend\Framework\Asset\Css;
use Nextend\Framework\Asset\AssetManager;
class Css {
public static function addFile($pathToFile, $group) {
AssetManager::$css->addFile($pathToFile, $group);
}
public static function addFiles($path, $files, $group) {
AssetManager::$css->addFiles($path, $files, $group);
}
public static function addStaticGroupPreload($file, $group) {
AssetManager::$css->addStaticGroupPreload($file, $group);
}
public static function addStaticGroup($file, $group) {
AssetManager::$css->addStaticGroup($file, $group);
}
public static function addCode($code, $group, $unshift = false) {
AssetManager::$css->addCode($code, $group, $unshift);
}
public static function addUrl($url) {
AssetManager::$css->addUrl($url);
}
public static function addInline($code, $name = null) {
AssetManager::$css->addInline($code, $name);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Nextend\Framework\Asset\Css\Less;
use Nextend\Framework\Asset\AbstractAsset;
class Asset extends AbstractAsset {
public function __construct() {
$this->cache = new Cache();
}
protected function uniqueFiles() {
$this->initGroups();
}
public function getFiles() {
$this->uniqueFiles();
$files = array();
foreach ($this->groups as $group) {
$files[$group] = $this->cache->getAssetFile($group, $this->files[$group], $this->codes[$group]);
}
return $files;
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace Nextend\Framework\Asset\Css\Less;
use Exception;
use Nextend\Framework\Cache\Manifest;
class Cache extends \Nextend\Framework\Asset\Css\Cache {
public $outputFileType = "less.css";
public function getAssetFile($group, &$files = array(), &$codes = array()) {
$this->group = $group;
$this->files = $files;
$this->codes = $codes;
$cache = new Manifest($group, false, true);
$hash = $this->getHash();
return $cache->makeCache($group . "." . $this->outputFileType, $hash, array(
$this,
'getCachedContent'
));
}
/**
* @param Manifest $cache
*
* @return string
* @throws Exception
*/
public function getCachedContent($cache) {
$fileContents = '';
foreach ($this->files as $parameters) {
$compiler = new LessCompiler();
if (!empty($parameters['importDir'])) {
$compiler->addImportDir($parameters['importDir']);
}
$compiler->setVariables($parameters['context']);
$fileContents .= $compiler->compileFile($parameters['file']);
}
return $fileContents;
}
protected function makeFileHash($parameters) {
return json_encode($parameters) . filemtime($parameters['file']);
}
protected function parseFile($cache, $content, $lessParameters) {
return parent::parseFile($cache, $content, $lessParameters['file']);
}
}

View File

@ -0,0 +1,104 @@
<?php
namespace Nextend\Framework\Asset\Css\Less\Formatter;
#[\AllowDynamicProperties]
class Classic {
public $indentChar = " ";
public $break = "\n";
public $open = " {";
public $close = "}";
public $selectorSeparator = ", ";
public $assignSeparator = ":";
public $openSingle = " { ";
public $closeSingle = " }";
public $disableSingle = false;
public $breakSelectors = false;
public $compressColors = false;
public function __construct() {
$this->indentLevel = 0;
}
public function indentStr($n = 0) {
return str_repeat($this->indentChar, max($this->indentLevel + $n, 0));
}
public function property($name, $value) {
return $name . $this->assignSeparator . $value . ";";
}
protected function isEmpty($block) {
if (empty($block->lines)) {
foreach ($block->children as $child) {
if (!$this->isEmpty($child)) return false;
}
return true;
}
return false;
}
public function block($block) {
$ret = '';
if ($this->isEmpty($block)) return $ret;
$inner = $pre = $this->indentStr();
$isSingle = !$this->disableSingle && is_null($block->type) && count($block->lines) == 1;
if (!empty($block->selectors)) {
$this->indentLevel++;
if ($this->breakSelectors) {
$selectorSeparator = $this->selectorSeparator . $this->break . $pre;
} else {
$selectorSeparator = $this->selectorSeparator;
}
$ret .= $pre . implode($selectorSeparator, $block->selectors);
if ($isSingle) {
$ret .= $this->openSingle;
$inner = "";
} else {
$ret .= $this->open . $this->break;
$inner = $this->indentStr();
}
}
if (!empty($block->lines)) {
$glue = $this->break . $inner;
$ret .= $inner . implode($glue, $block->lines);
if (!$isSingle && !empty($block->children)) {
$ret .= $this->break;
}
}
foreach ($block->children as $child) {
$ret .= $this->block($child);
}
if (!empty($block->selectors)) {
if (!$isSingle && empty($block->children)) $ret .= $this->break;
if ($isSingle) {
$ret .= $this->closeSingle . $this->break;
} else {
$ret .= $pre . $this->close . $this->break;
}
$this->indentLevel--;
}
return $ret;
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Nextend\Framework\Asset\Css\Less\Formatter;
class Compressed extends Classic {
public $disableSingle = true;
public $open = "{";
public $selectorSeparator = ",";
public $assignSeparator = ":";
public $break = "";
public $compressColors = true;
public function indentStr($n = 0) {
return "";
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Nextend\Framework\Asset\Css\Less\Formatter;
class Debug extends Classic {
public $disableSingle = true;
public $breakSelectors = true;
public $assignSeparator = ": ";
public $selectorSeparator = ",";
}

View File

@ -0,0 +1,32 @@
<?php
namespace Nextend\Framework\Asset\Css\Less;
use Nextend\Framework\Asset\AssetManager;
use Nextend\Framework\Asset\Css\Css;
class Less {
public static function addFile($pathToFile, $group, $context = array(), $importDir = null) {
AssetManager::$less->addFile(array(
'file' => $pathToFile,
'context' => $context,
'importDir' => $importDir
), $group);
}
public static function build() {
foreach (AssetManager::$less->getFiles() as $group => $file) {
if (substr($file, 0, 2) == '//') {
Css::addUrl($file);
} else if (!realpath($file)) {
// For database cache the $file contains the content of the generated CSS file
Css::addCode($file, $group, true);
} else {
Css::addFile($file, $group);
}
}
}
}

File diff suppressed because it is too large Load Diff