Rework to fit with minizer

This commit is contained in:
Brice Maron 2012-06-06 21:11:15 +00:00
parent 5c2b2fc842
commit e8447e0bda
4 changed files with 47 additions and 23 deletions

View file

@ -284,12 +284,12 @@ class OC{
public static function loadfile(){ public static function loadfile(){
if(file_exists(OC_App::getAppPath(OC::$REQUESTEDAPP) . '/' . OC::$REQUESTEDFILE)){ if(file_exists(OC_App::getAppPath(OC::$REQUESTEDAPP) . '/' . OC::$REQUESTEDFILE)){
if(substr(OC::$REQUESTEDFILE, -3) == 'css'){ if(substr(OC::$REQUESTEDFILE, -3) == 'css'){
$file = 'apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE; $file = OC_App::getAppWebPath(OC::$REQUESTEDAPP). '/' . OC::$REQUESTEDFILE;
$minimizer = new OC_Minimizer_CSS(); $minimizer = new OC_Minimizer_CSS();
$minimizer->output(array(array(OC::$APPSROOT, OC::$APPSWEBROOT, $file))); $minimizer->output(array(array(OC_App::getAppPath(OC::$REQUESTEDAPP), OC_App::getAppWebPath(OC::$REQUESTEDAPP), OC::$REQUESTEDFILE)));
exit; exit;
}elseif(substr(OC::$REQUESTEDFILE, -3) == 'php'){ }elseif(substr(OC::$REQUESTEDFILE, -3) == 'php'){
require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE); require_once(OC_App::getAppPath(OC::$REQUESTEDAPP). '/' . OC::$REQUESTEDFILE);
} }
}else{ }else{
die(); die();

View file

@ -16,10 +16,6 @@ class OC_Minimizer_CSS extends OC_Minimizer
// is it in 3rdparty? // is it in 3rdparty?
if($this->appendIfExist(OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) { if($this->appendIfExist(OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) {
// or in apps?
}elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) {
}elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) {
// or in the owncloud root? // or in the owncloud root?
}elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) { }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) {
}elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) { }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) {
@ -29,8 +25,16 @@ class OC_Minimizer_CSS extends OC_Minimizer
}elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) { }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) {
}else{ }else{
echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); $append = false;
die(); foreach( OC::$APPSROOTS as $apps_dir)
{
if($this->appendIfExist('cssfiles', $apps_dir['path'], $apps_dir['web'], "$style$fext.css", true)) { $append =true; break; }
elseif($this->appendIfExist('cssfiles', $apps_dir['path'], $apps_dir['web'], "$style.css", true )) { $append =true; break; }
}
if(! $append) {
echo('css file not found: style:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
die();
}
} }
} }
// Add the theme css files. you can override the default values here // Add the theme css files. you can override the default values here
@ -52,14 +56,21 @@ class OC_Minimizer_CSS extends OC_Minimizer
public function minimizeFiles($files) { public function minimizeFiles($files) {
$css_out = ''; $css_out = '';
$appswebroot = (string) OC::$APPSWEBROOT;
$webroot = (string) OC::$WEBROOT; $webroot = (string) OC::$WEBROOT;
foreach($files as $file_info) { foreach($files as $file_info) {
$file = $file_info[0] . '/' . $file_info[2]; $file = $file_info[0] . '/' . $file_info[2];
$css_out .= '/* ' . $file . ' */' . "\n"; $css_out .= '/* ' . $file . ' */' . "\n";
$css = file_get_contents($file); $css = file_get_contents($file);
if (strpos($file, OC::$APPSROOT) == 0) {
$css = str_replace('%appswebroot%', $appswebroot, $css); $in_root = false;
foreach(OC::$APPSROOTS as $app_root) {
if(strpos($file, $app_root['path']) == 0) {
$in_root = $app_root['web'];
break;
}
}
if ($in_root !== false) {
$css = str_replace('%appswebroot%', $in_root, $css);
$css = str_replace('%webroot%', $webroot, $css); $css = str_replace('%webroot%', $webroot, $css);
} }
$remote = $file_info[1]; $remote = $file_info[1];

View file

@ -21,10 +21,6 @@ class OC_Minimizer_JS extends OC_Minimizer
}elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) { }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) {
}elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) { }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) {
// Is it part of an app?
}elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) {
}elseif($this->appendIfExist(OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) {
// Is it in the owncloud root but overwritten by the theme? // Is it in the owncloud root but overwritten by the theme?
}elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) { }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) {
}elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) { }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) {
@ -42,8 +38,17 @@ class OC_Minimizer_JS extends OC_Minimizer
}elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) { }elseif($this->appendIfExist(OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) {
}else{ }else{
echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); // Is it part of an app?
die(); $append = false;
foreach( OC::$APPSROOTS as $apps_dir)
{
if($page->appendIfExist('jsfiles', $apps_dir['path'], $apps_dir['web'], "$script$fext.js" , true)) { $append =true; break; }
elseif($page->appendIfExist('jsfiles', $apps_dir['path'], $apps_dir['web'], "$script.js", true )) { $append =true; break; }
}
if(! $append) {
echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
die();
}
} }
} }
return $this->files; return $this->files;

View file

@ -17,9 +17,17 @@ if(is_null($file)){
exit; exit;
} }
$parts=explode('/', $file, 2); if(count(explode('/',$file)) == 3) {
$app=$parts[0]; $parts=explode('/',$file);
OC_App::loadApp($app); $app=$parts[2];
OC_App::loadApp($app);
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
require_once( OC::$SERVERROOT.$file);
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; } else {
require_once(OC_App::getAppPath($app) .'/'. $parts[1]); $parts=explode('/', $file, 2);
$app=$parts[0];
OC_App::loadApp($app);
$baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
require_once(OC_App::getAppPath($app) .'/'. $parts[1]);
}