nextcloud/lib/minimizer/css.php

39 lines
983 B
PHP
Raw Normal View History

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