2012-05-14 19:57:43 +04:00
|
|
|
<?php
|
|
|
|
|
2012-10-16 19:57:07 +04:00
|
|
|
require_once 'mediawiki/CSSMin.php';
|
2012-05-14 19:57:43 +04:00
|
|
|
|
|
|
|
class OC_Minimizer_CSS extends OC_Minimizer
|
|
|
|
{
|
|
|
|
protected $contentType = 'text/css';
|
|
|
|
|
|
|
|
public function minimizeFiles($files) {
|
|
|
|
$css_out = '';
|
|
|
|
$webroot = (string) OC::$WEBROOT;
|
|
|
|
foreach($files as $file_info) {
|
|
|
|
$file = $file_info[0] . '/' . $file_info[2];
|
|
|
|
$css_out .= '/* ' . $file . ' */' . "\n";
|
|
|
|
$css = file_get_contents($file);
|
2012-06-07 01:11:15 +04:00
|
|
|
|
|
|
|
$in_root = false;
|
|
|
|
foreach(OC::$APPSROOTS as $app_root) {
|
2012-10-16 19:57:07 +04:00
|
|
|
if(strpos($file, $app_root['path'].'/') === 0) {
|
2012-06-23 18:59:55 +04:00
|
|
|
$in_root = rtrim($webroot.$app_root['url'], '/');
|
2012-06-07 01:11:15 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($in_root !== false) {
|
|
|
|
$css = str_replace('%appswebroot%', $in_root, $css);
|
2012-05-14 19:57:43 +04:00
|
|
|
$css = str_replace('%webroot%', $webroot, $css);
|
|
|
|
}
|
|
|
|
$remote = $file_info[1];
|
2012-06-05 20:09:32 +04:00
|
|
|
$remote .= '/';
|
2012-05-14 19:57:43 +04:00
|
|
|
$remote .= dirname($file_info[2]);
|
|
|
|
$css_out .= CSSMin::remap($css, dirname($file), $remote, true);
|
|
|
|
}
|
2012-10-16 19:57:07 +04:00
|
|
|
if (!defined('DEBUG') || !DEBUG) {
|
2012-06-14 20:22:48 +04:00
|
|
|
$css_out = CSSMin::minify($css_out);
|
|
|
|
}
|
2012-05-14 19:57:43 +04:00
|
|
|
return $css_out;
|
|
|
|
}
|
|
|
|
}
|