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 {
|
||||
public function init() {
|
||||
// $v = $_REQUEST['v'];
|
||||
$git = Cana_Util::gitVersion();
|
||||
$v = $git ? $git : $_REQUEST['v'];
|
||||
|
||||
$cacheid = 'crunchr-bundle-node-css'.$v;
|
||||
|
||||
if (c::app()->cache()->cached($cacheid)) {
|
||||
$mtime = c::cache()->mtime($cacheid);$mtime = c::cache()->mtime($cacheid);
|
||||
|
||||
$headers = apache_request_headers();
|
||||
if (isset($headers['If-Modified-Since']) && !$_REQUEST['nocache']) {
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$mtime).' GMT', true, 304);
|
||||
exit;
|
||||
$this->cacheServe('crunchr-bundle-node-css');
|
||||
}
|
||||
|
||||
public function getData() {
|
||||
if ($_REQUEST['s']) {
|
||||
switch ($_REQUEST['s']) {
|
||||
case 'style':
|
||||
$style = ['style'];
|
||||
break;
|
||||
case 'seven':
|
||||
$style = ['seven'];
|
||||
break;
|
||||
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']) {
|
||||
switch ($_REQUEST['s']) {
|
||||
case 'style':
|
||||
$style = ['style'];
|
||||
break;
|
||||
case 'seven':
|
||||
$style = ['seven'];
|
||||
break;
|
||||
default:
|
||||
$style = [];
|
||||
break;
|
||||
}
|
||||
$doc = new DOMDocument('1.0');
|
||||
@$doc->loadHTML($src);
|
||||
|
||||
foreach ($doc->getElementsByTagName('link') as $script) {
|
||||
if ($script->getAttribute('href')) {
|
||||
$files[] = c::config()->dirs->www.preg_replace('/^(.*)(\?.*)$/','\\1',$script->getAttribute('href'));
|
||||
}
|
||||
}
|
||||
|
||||
$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');
|
||||
@$doc->loadHTML($src);
|
||||
|
||||
foreach ($doc->getElementsByTagName('link') as $script) {
|
||||
if ($script->getAttribute('href')) {
|
||||
$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 = '';
|
||||
foreach ($files as $file) {
|
||||
if (preg_match('/\.scss$/',$file)) {
|
||||
$data .= Scss::compile($file);
|
||||
} else {
|
||||
$data .= file_get_contents($file);
|
||||
}
|
||||
}
|
||||
|
||||
if ($tmps) {
|
||||
foreach ($tmps as $tmp) {
|
||||
unlink($tmp);
|
||||
}
|
||||
if ($tmps) {
|
||||
foreach ($tmps as $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) {
|
||||
header($key.': '.$header);
|
||||
}
|
||||
$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);
|
||||
*/
|
||||
|
||||
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');
|
||||
|
||||
echo $data;
|
||||
exit;
|
||||
$data = preg_replace('/\t|\n/','',$data);
|
||||
$mtime = time();
|
||||
|
||||
return ['mtime' => $mtime, 'data' => $data];
|
||||
}
|
||||
}
|
||||
|
||||
@ -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__).'/../',
|
||||
'www' => dirname(__FILE__).'/../www/',
|
||||
'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' => []
|
||||
];
|
||||
|
||||
|
||||
@ -12,12 +12,62 @@ class Crunchbutton_Controller_AssetBundle extends Cana_Controller {
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
|
||||
public function __construct() {
|
||||
define('MINIFY_MIN_DIR', c::config()->dirs->library . 'Minify/old/lib');
|
||||
set_include_path(MINIFY_MIN_DIR . PATH_SEPARATOR . get_include_path());
|
||||
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) {
|
||||
foreach ($files as $key => $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)
|
||||
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} !-d
|
||||
RewriteRule ^(.+)$ index.php?__url=$1 [L,QSA]
|
||||
RewriteRule ^(.+).scss$ index.php?__url=$1 [L,QSA]
|
||||
|
||||
|
||||
|
||||
<IfDefine !TRAVIS>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user