First almost working version

This commit is contained in:
Brice Maron 2012-06-01 22:05:20 +00:00
parent c960e42a17
commit b6c5ca126b
5 changed files with 100 additions and 71 deletions

View File

@ -78,7 +78,7 @@ class OC_App{
* @param string app
*/
public static function loadApp($app){
if(is_file(OC::$APPSROOT.'/apps/'.$app.'/appinfo/app.php')){
if(is_file(self::getAppPath($app).'/appinfo/app.php')){
require_once( $app.'/appinfo/app.php' );
}
}
@ -322,11 +322,25 @@ class OC_App{
return $list;
}
/**
* Get the directory for the given app.
* If the app is defined in multiple directory, the first one is taken. (false if not found)
*/
public static function getAppPath($appid) {
foreach(OC::$APPSROOTS as $dir) {
if(file_exists($dir.'/'.$appid)) {
return $dir.'/'.$appid;
}
}
// OC_Log::write('core','Unable to find app "'.$appid.'"',OC_Log::ERROR);
return false;
}
/**
* get the last version of the app, either from appinfo/version or from appinfo/info.xml
*/
public static function getAppVersion($appid){
$file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/version';
$file= self::getAppPath($appid).'/appinfo/version';
$version=@file_get_contents($file);
if($version){
return $version;
@ -349,7 +363,7 @@ class OC_App{
if(isset(self::$appInfo[$appid])){
return self::$appInfo[$appid];
}
$file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/info.xml';
$file= self::getAppPath($appid).'/appinfo/info.xml';
}
$data=array();
$content=@file_get_contents($file);
@ -462,10 +476,12 @@ class OC_App{
*/
public static function getAllApps(){
$apps=array();
$dh=opendir(OC::$APPSROOT.'/apps');
while($file=readdir($dh)){
if(substr($file,0,1)!='.' and is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){
$apps[]=$file;
foreach(OC::$APPSROOTS as $apps_dir) {
$dh=opendir($apps_dir);
while($file=readdir($dh)){
if(substr($file,0,1)!='.' and is_file($apps_dir.'/'.$file.'/appinfo/app.php')){
$apps[]=$file;
}
}
}
return $apps;
@ -530,14 +546,14 @@ class OC_App{
* @param string appid
*/
public static function updateApp($appid){
if(file_exists(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/database.xml')){
OC_DB::updateDbFromStructure(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/database.xml');
if(file_exists(self::getAppPath($appid).'/appinfo/database.xml')){
OC_DB::updateDbFromStructure(self::getAppPath($appid).'/appinfo/database.xml');
}
if(!self::isEnabled($appid)){
return;
}
if(file_exists(OC::$APPSROOT.'/apps/'.$appid.'/appinfo/update.php')){
include OC::$APPSROOT.'/apps/'.$appid.'/appinfo/update.php';
if(file_exists(self::getAppPath($appid).'/appinfo/update.php')){
include self::getAppPath($appid).'/appinfo/update.php';
}
//set remote/public handelers

View File

@ -57,7 +57,7 @@ class OC{
/**
* The installation path of the apps folder on the server (e.g. /srv/http/owncloud)
*/
public static $APPSROOT = '';
public static $APPSROOTS = array();
/**
* the root path of the apps folder for http requests (e.g. owncloud)
*/
@ -168,15 +168,17 @@ class OC{
// search the apps folder
if(OC_Config::getValue('appsroot', '')<>''){
OC::$APPSROOT=OC_Config::getValue('appsroot', '');
OC::$APPSROOTS=explode(':',OC_Config::getValue('appsroot', ''));
OC::$APPSWEBROOT=OC_Config::getValue('appsurl', '');
}elseif(file_exists(OC::$SERVERROOT.'/apps')){
OC::$APPSROOT=OC::$SERVERROOT;
OC::$APPSWEBROOT=OC::$WEBROOT;
}elseif(file_exists(OC::$SERVERROOT.'/../apps')){
OC::$APPSROOT=rtrim(dirname(OC::$SERVERROOT), '/');
OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
}else{
OC::$APPSROOTS= array(OC::$SERVERROOT.'/apps');
OC::$APPSWEBROOT=OC::$WEBROOT;
}
if(file_exists(OC::$SERVERROOT.'/../apps')){
OC::$APPSROOTS[] = rtrim(realpath(OC::$SERVERROOT.'/../apps'), '/');
// OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
}
if(empty(OC::$APPSROOTS)){
echo("apps directory not found! Please put the ownCloud apps folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file.");
exit;
}
@ -186,8 +188,7 @@ class OC{
OC::$SERVERROOT.'/lib'.PATH_SEPARATOR.
OC::$SERVERROOT.'/config'.PATH_SEPARATOR.
OC::$THIRDPARTYROOT.'/3rdparty'.PATH_SEPARATOR.
OC::$APPSROOT.PATH_SEPARATOR.
OC::$APPSROOT.'/apps'.PATH_SEPARATOR.
implode(OC::$APPSROOTS,PATH_SEPARATOR).PATH_SEPARATOR.
get_include_path().PATH_SEPARATOR.
OC::$SERVERROOT
);
@ -273,15 +274,15 @@ class OC{
}
public static function loadapp(){
if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php')){
require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php');
if(file_exists(OC_App::getAppPath(OC::$REQUESTEDAPP) . '/index.php')){
require_once(OC_App::getAppPath(OC::$REQUESTEDAPP) . '/index.php');
}else{
trigger_error('The requested App was not found.', E_USER_ERROR);//load default app instead?
}
}
public static function loadfile(){
if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE)){
if(file_exists(OC_App::getAppPath(OC::$REQUESTEDAPP) . '/' . OC::$REQUESTEDFILE)){
if(substr(OC::$REQUESTEDFILE, -3) == 'css'){
$file = 'apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE;
$minimizer = new OC_Minimizer_CSS();
@ -453,8 +454,8 @@ class OC{
$_GET['getfile'] = $file;
}
if(!is_null(self::$REQUESTEDFILE)){
$subdir = OC::$APPSROOT . '/apps/' . self::$REQUESTEDAPP . '/' . self::$REQUESTEDFILE;
$parent = OC::$APPSROOT . '/apps/' . self::$REQUESTEDAPP;
$subdir = OC_App::getAppPath(OC::$REQUESTEDAPP) . '/' . self::$REQUESTEDFILE;
$parent = OC_App::getAppPath(OC::$REQUESTEDAPP);
if(!OC_Helper::issubdirectory($subdir, $parent)){
self::$REQUESTEDFILE = null;
header('HTTP/1.0 404 Not Found');

View File

@ -40,7 +40,7 @@ class OC_Helper {
if( $app != '' ){
$app .= '/';
// Check if the app is in the app folder
if( file_exists( OC::$APPSROOT . '/apps/'. $app.$file )){
if( file_exists( OC_App::getAppPath($app).$file )){
if(substr($file, -3) == 'php' || substr($file, -3) == 'css'){
if(substr($app, -1, 1) == '/'){
$app = substr($app, 0, strlen($app) - 1);
@ -150,7 +150,7 @@ class OC_Helper {
// Check if the app is in the app folder
if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/img/$image" )){
return OC::$WEBROOT."/themes/$theme/apps/$app/img/$image";
}elseif( file_exists( OC::$APPSROOT."/apps/$app/img/$image" )){
}elseif( file_exists(OC_App::getAppPath($app)."/img/$image" )){
return OC::$APPSWEBROOT."/apps/$app/img/$image";
}elseif( !empty( $app ) and file_exists( OC::$SERVERROOT."/themes/$theme/$app/img/$image" )){
return OC::$WEBROOT."/themes/$theme/$app/img/$image";

View File

@ -263,8 +263,8 @@ class OC_L10N{
$i18ndir = OC::$SERVERROOT.'/core/l10n/';
if($app != ''){
// Check if the app is in the app folder
if(file_exists(OC::$APPSROOT.'/apps/'.$app.'/l10n/')){
$i18ndir = OC::$APPSROOT.'/apps/'.$app.'/l10n/';
if(file_exists(OC_App::getAppPath($app).'/l10n/')){
$i18ndir = OC_App::getAppPath($app).'/l10n/';
}
else{
$i18ndir = OC::$SERVERROOT.'/'.$app.'/l10n/';

View File

@ -202,10 +202,10 @@ class OC_Template{
// Check if it is a app template or not.
if( $app != "" ){
// Check if the app is in the app folder or in the root
if( file_exists( OC::$APPSROOT."/apps/$app/templates/" )){
if( file_exists(OC_App::getAppPath($app)."/templates/" )){
// Check if the template is overwritten by the selected theme
if ($this->checkPathForTemplate(OC::$SERVERROOT."/themes/$theme/apps/$app/templates/", $name, $fext)) {
}elseif ($this->checkPathForTemplate(OC::$APPSROOT."/apps/$app/templates/", $name, $fext)) {
}elseif ($this->checkPathForTemplate(OC_App::getAppPath($app)."/templates/", $name, $fext)) {
}
}else{
// Check if the template is overwritten by the selected theme
@ -317,29 +317,32 @@ class OC_Template{
}
}
/*
/**
* @brief append the $file-url if exist at $root
* @param $type of collection to use when appending
* @param $root path to check
* @param $web base for path
* @param $file the filename
* @param $in_app boolean is part of an app? (default false)
*/
public function appendIfExist($type, $root, $web, $file) {
if (is_file($root.'/'.$file)) {
$pathes = explode('/', $file);
if($type == 'cssfiles' && $root == OC::$APPSROOT && $pathes[0] == 'apps'){
$app = $pathes[1];
unset($pathes[0]);
unset($pathes[1]);
$path = implode('/', $pathes);
$this->append( $type, OC_Helper::linkTo($app, $path));
}else{
$this->append( $type, $web.'/'.$file);
}
return true;
}
return false;
}
public function appendIfExist($type, $root, $web, $file, $in_app = false) {
if (is_file($root.'/'.$file)) {
$pathes = explode('/', $file);
if($type == 'cssfiles' && $root == OC::$APPSROOTS[0] && $in_app){
$app = $pathes[0];
unset($pathes[0]);
// unset($pathes[1]);
$path = implode('/', $pathes);
$this->append( $type, OC_Helper::linkTo($app, $path));
}else{
$this->append( $type, $web.'/'.$file);
}
return true;
}
return false;
}
/**
* @brief Proceeds the template
* @returns content
@ -385,16 +388,12 @@ class OC_Template{
// Add the core js files or the js files provided by the selected theme
foreach(OC_Util::$scripts as $script){
// Is it in 3rd party?
if($page->appendIfExist('jsfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) {
if($page->appendIfExist('jsfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) {
// Is it in apps and overwritten by the theme?
}elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) {
}elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) {
// Is it part of an app?
}elseif($page->appendIfExist('jsfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) {
}elseif($page->appendIfExist('jsfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) {
// Is it in the owncloud root but overwritten by the theme?
}elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) {
}elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) {
@ -412,20 +411,24 @@ class OC_Template{
}elseif($page->appendIfExist('jsfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) {
}else{
echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
die();
// Is it part of an app?
$append = false;
foreach( OC::$APPSROOTS as $apps_dir)
{
if($page->appendIfExist('jsfiles', $apps_dir, OC::$APPSWEBROOT.'/apps/', "$script$fext.js" , true)) { $append =true; break; }
elseif($page->appendIfExist('jsfiles', $apps_dir, OC::$APPSWEBROOT.'/apps/', "$script.js", true )) { $append =true; break; }
}
if(! $append) {
echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
die();
}
}
}
// Add the css files
$page->assign('cssfiles', array());
foreach(OC_Util::$styles as $style){
// is it in 3rdparty?
if($page->appendIfExist('cssfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) {
// or in apps?
}elseif($page->appendIfExist('cssfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) {
}elseif($page->appendIfExist('cssfiles', OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) {
if($page->appendIfExist('cssfiles', OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) {
// or in the owncloud root?
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) {
@ -436,22 +439,31 @@ class OC_Template{
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) {
}else{
echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
die();
// or in apps?
$append = false;
foreach( OC::$APPSROOTS as $apps_dir)
{
if($page->appendIfExist('cssfiles', $apps_dir, OC::$APPSWEBROOT, "$style$fext.css", true)) { $append =true; break; }
elseif($page->appendIfExist('cssfiles', $apps_dir, OC::$APPSWEBROOT, "$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
if(!empty($theme)) {
foreach(OC_Util::$styles as $style){
if($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) {
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) {
if($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) {
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) {
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) {
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) {
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) {
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) {
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) {
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) {
}
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) {
}elseif($page->appendIfExist('cssfiles', OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) {
}
}
}