Merge branch 'master' of https://github.com/crunchbutton/crunchbutton
This commit is contained in:
commit
d1c0f295ef
@ -2,101 +2,69 @@
|
|||||||
|
|
||||||
class Controller_assets_css_bundle_css extends Crunchbutton_Controller_AssetBundle {
|
class Controller_assets_css_bundle_css extends Crunchbutton_Controller_AssetBundle {
|
||||||
public function init() {
|
public function init() {
|
||||||
// $v = $_REQUEST['v'];
|
$this->cacheServe('crunchr-bundle-node-css');
|
||||||
$git = Cana_Util::gitVersion();
|
}
|
||||||
$v = $git ? $git : $_REQUEST['v'];
|
|
||||||
|
public function getData() {
|
||||||
$cacheid = 'crunchr-bundle-node-css'.$v;
|
if ($_REQUEST['s']) {
|
||||||
|
switch ($_REQUEST['s']) {
|
||||||
if (c::app()->cache()->cached($cacheid)) {
|
case 'style':
|
||||||
$mtime = c::cache()->mtime($cacheid);$mtime = c::cache()->mtime($cacheid);
|
$style = ['style'];
|
||||||
|
break;
|
||||||
$headers = apache_request_headers();
|
case 'seven':
|
||||||
if (isset($headers['If-Modified-Since']) && !$_REQUEST['nocache']) {
|
$style = ['seven'];
|
||||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$mtime).' GMT', true, 304);
|
break;
|
||||||
exit;
|
default:
|
||||||
|
$style = [];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cached = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cached && !$_REQUEST['nocache']) {
|
|
||||||
$data = c::app()->cache()->read($cacheid);
|
|
||||||
|
|
||||||
} else {
|
$src = c::view()->render('bundle/bundler.css',['set' => ['style' => $style]]);
|
||||||
|
|
||||||
if ($_REQUEST['s']) {
|
$doc = new DOMDocument('1.0');
|
||||||
switch ($_REQUEST['s']) {
|
@$doc->loadHTML($src);
|
||||||
case 'style':
|
|
||||||
$style = ['style'];
|
foreach ($doc->getElementsByTagName('link') as $script) {
|
||||||
break;
|
if ($script->getAttribute('href')) {
|
||||||
case 'seven':
|
$files[] = c::config()->dirs->www.preg_replace('/^(.*)(\?.*)$/','\\1',$script->getAttribute('href'));
|
||||||
$style = ['seven'];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$style = [];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$src = c::view()->render('bundle/bundler.css',['set' => ['style' => $style]]);
|
foreach ($doc->getElementsByTagName('style') as $script) {
|
||||||
|
$code = $script->nodeValue;
|
||||||
|
$tmp = tempnam('/tmp',$cacheid);
|
||||||
|
$tmps[] = $tmp;
|
||||||
|
file_put_contents($tmp,$code);
|
||||||
|
$files[] = $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
$doc = new DOMDocument('1.0');
|
$data = '';
|
||||||
@$doc->loadHTML($src);
|
foreach ($files as $file) {
|
||||||
|
if (preg_match('/\.scss$/',$file)) {
|
||||||
foreach ($doc->getElementsByTagName('link') as $script) {
|
$data .= Scss::compile($file);
|
||||||
if ($script->getAttribute('href')) {
|
} else {
|
||||||
$files[] = c::config()->dirs->www.preg_replace('/^(.*)(\?.*)$/','\\1',$script->getAttribute('href'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($doc->getElementsByTagName('style') as $script) {
|
|
||||||
$code = $script->nodeValue;
|
|
||||||
$tmp = tempnam('/tmp',$cacheid);
|
|
||||||
$tmps[] = $tmp;
|
|
||||||
file_put_contents($tmp,$code);
|
|
||||||
$files[] = $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = '';
|
|
||||||
foreach ($files as $file) {
|
|
||||||
$data .= file_get_contents($file);
|
$data .= file_get_contents($file);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($tmps) {
|
if ($tmps) {
|
||||||
foreach ($tmps as $tmp) {
|
foreach ($tmps as $tmp) {
|
||||||
unlink($tmp);
|
unlink($tmp);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
$callback = function($matches) {
|
|
||||||
$img = new ImageBase64(c::config()->dirs->www.$matches[1]);
|
|
||||||
return 'url('.$img->output().')';
|
|
||||||
};
|
|
||||||
|
|
||||||
$css = preg_replace_callback('/url\(([a-z0-9\/\-_\.]+)\)/i',$callback, $css);
|
|
||||||
*/
|
|
||||||
$data = preg_replace('/\t|\n/','',$data);
|
|
||||||
$mtime = time();
|
|
||||||
c::app()->cache()->write($cacheid, $data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
foreach ($data['headers'] as $key => $header) {
|
$callback = function($matches) {
|
||||||
header($key.': '.$header);
|
$img = new ImageBase64(c::config()->dirs->www.$matches[1]);
|
||||||
}
|
return 'url('.$img->output().')';
|
||||||
|
};
|
||||||
|
|
||||||
|
$css = preg_replace_callback('/url\(([a-z0-9\/\-_\.]+)\)/i',$callback, $css);
|
||||||
*/
|
*/
|
||||||
|
$data = preg_replace('/\t|\n/','',$data);
|
||||||
header('HTTP/1.1 200 OK');
|
$mtime = time();
|
||||||
header('Date: '.date('r'));
|
|
||||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$mtime).' GMT');
|
return ['mtime' => $mtime, 'data' => $data];
|
||||||
header('Accept-Ranges: bytes');
|
|
||||||
header('Content-Length: '.strlen($data));
|
|
||||||
header('Content-type: text/css');
|
|
||||||
header('Vary: Accept-Encoding');
|
|
||||||
|
|
||||||
echo $data;
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,20 @@
|
|||||||
|
<?
|
||||||
|
|
||||||
|
class Controller_assets_scss extends Crunchbutton_Controller_AssetBundle {
|
||||||
|
public function init() {
|
||||||
|
$this->cacheServe('crunchr-file-scss');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getData() {
|
||||||
|
|
||||||
|
$path = $file = c::config()->dirs->www.'assets/scss/';
|
||||||
|
$file = c::getPagePiece(2).'.scss';
|
||||||
|
|
||||||
|
$data = Scss::compile($path.$file);
|
||||||
|
|
||||||
|
$data = preg_replace('/\t|\n/','',$data);
|
||||||
|
$mtime = time();
|
||||||
|
|
||||||
|
return ['mtime' => $mtime, 'data' => $data];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -27,7 +27,7 @@ $GLOBALS['config'] = [
|
|||||||
'root' => dirname(__FILE__).'/../',
|
'root' => dirname(__FILE__).'/../',
|
||||||
'www' => dirname(__FILE__).'/../www/',
|
'www' => dirname(__FILE__).'/../www/',
|
||||||
'storage' => dirname(__FILE__).'/../storage/',
|
'storage' => dirname(__FILE__).'/../storage/',
|
||||||
],'libraries' => ['Crunchbutton','Cana','Services','Balanced','RESTful','Ordrin','QueryPath','Github','ApnsPHP'],
|
],'libraries' => ['Crunchbutton','Cana','Services','Balanced','RESTful','Ordrin','QueryPath','Github','ApnsPHP','Scss'],
|
||||||
'alias' => []
|
'alias' => []
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -12,12 +12,62 @@ class Crunchbutton_Controller_AssetBundle extends Cana_Controller {
|
|||||||
}
|
}
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
define('MINIFY_MIN_DIR', c::config()->dirs->library . 'Minify/old/lib');
|
define('MINIFY_MIN_DIR', c::config()->dirs->library . 'Minify/old/lib');
|
||||||
set_include_path(MINIFY_MIN_DIR . PATH_SEPARATOR . get_include_path());
|
set_include_path(MINIFY_MIN_DIR . PATH_SEPARATOR . get_include_path());
|
||||||
require 'Minify.php';
|
require 'Minify.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function cacheServe($id) {
|
||||||
|
|
||||||
|
$git = Cana_Util::gitVersion();
|
||||||
|
$v = $git ? $git : $_REQUEST['v'];
|
||||||
|
|
||||||
|
$headrs = apache_request_headers();
|
||||||
|
foreach ($headrs as $head => $er) {
|
||||||
|
$headers[strtolower($head)] = $er;
|
||||||
|
}
|
||||||
|
$nocache = ($_REQUEST['nocache'] || $headers['pragma'] == 'no-cache' || $headers['cache-control'] == 'no-cache') ? true : false;
|
||||||
|
|
||||||
|
$cacheid = $id.$v.$_REQUEST['s'];
|
||||||
|
|
||||||
|
if (c::app()->cache()->cached($cacheid)) {
|
||||||
|
$mtime = c::cache()->mtime($cacheid);
|
||||||
|
|
||||||
|
if (isset($headers['if-modified-since']) && !$nocache) {
|
||||||
|
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$mtime).' GMT', true, 304);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cached = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($cached && !$_REQUEST['nocache']) {
|
||||||
|
$data = c::app()->cache()->read($cacheid);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$res = $this->getData();
|
||||||
|
c::app()->cache()->write($cacheid, $res['data']);
|
||||||
|
$mtime = $res['mtime'];
|
||||||
|
$data = $res['data'];
|
||||||
|
}
|
||||||
|
|
||||||
|
header('HTTP/1.1 200 OK');
|
||||||
|
header('Date: '.date('r'));
|
||||||
|
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$mtime).' GMT');
|
||||||
|
header('Accept-Ranges: bytes');
|
||||||
|
header('Content-Length: '.strlen($data));
|
||||||
|
header('Content-type: text/css');
|
||||||
|
header('Vary: Accept-Encoding');
|
||||||
|
header('Cache-Control: max-age=290304000, public');
|
||||||
|
|
||||||
|
echo $data;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
public function serve($files, $quiet = true) {
|
public function serve($files, $quiet = true) {
|
||||||
foreach ($files as $key => $file) {
|
foreach ($files as $key => $file) {
|
||||||
if (!file_exists($file)) {
|
if (!file_exists($file)) {
|
||||||
|
|||||||
20
include/library/Crunchbutton/Scss.php
Normal file
20
include/library/Crunchbutton/Scss.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?
|
||||||
|
|
||||||
|
class Crunchbutton_Scss extends Cana_Model {
|
||||||
|
public static function compile($file) {
|
||||||
|
|
||||||
|
if (!file_exists($file)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = dirname($file).'/';
|
||||||
|
$file = basename($file);
|
||||||
|
|
||||||
|
$scss = new Scss_Scss;
|
||||||
|
$scss->setImportPaths($path);
|
||||||
|
$scss->setFormatter('scss_formatter_compressed');
|
||||||
|
$data = $scss->compile(file_get_contents($path.$file));
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
4383
include/library/Scss/Scss.php
Normal file
4383
include/library/Scss/Scss.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -5,10 +5,14 @@ Options +Followsymlinks -Indexes
|
|||||||
|
|
||||||
ReWriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
|
ReWriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
|
||||||
ReWriteRule .* - [F]
|
ReWriteRule .* - [F]
|
||||||
|
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
|
||||||
|
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]
|
||||||
|
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteCond %{REQUEST_FILENAME} !-d
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
RewriteRule ^(.+)$ index.php?__url=$1 [L,QSA]
|
RewriteRule ^(.+)$ index.php?__url=$1 [L,QSA]
|
||||||
|
RewriteRule ^(.+).scss$ index.php?__url=$1 [L,QSA]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<IfDefine !TRAVIS>
|
<IfDefine !TRAVIS>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user