server/lib/minimizer/css.php

39 lines
987 B
PHP
Raw Normal View History

<?php
2012-09-05 21:28:59 +00:00
require_once 'mediawiki/CSSMin.php';
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-06 21:11:15 +00:00
$in_root = false;
foreach(OC::$APPSROOTS as $app_root) {
if(strpos($file, $app_root['path'].'/') === 0) {
$in_root = rtrim($webroot.$app_root['url'], '/');
2012-06-06 21:11:15 +00:00
break;
}
}
if ($in_root !== false) {
$css = str_replace('%appswebroot%', $in_root, $css);
$css = str_replace('%webroot%', $webroot, $css);
}
$remote = $file_info[1];
2012-06-05 16:09:32 +00:00
$remote .= '/';
$remote .= dirname($file_info[2]);
$css_out .= CSSMin::remap($css, dirname($file), $remote, true);
}
2012-09-07 13:22:01 +00:00
if (!defined('DEBUG') || !DEBUG) {
2012-06-14 16:22:48 +00:00
$css_out = CSSMin::minify($css_out);
}
return $css_out;
}
}