From 7d86e262e18d931f613a6dac16afe66a70d963ac Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 16 Jul 2013 22:32:04 +0200 Subject: [PATCH 1/5] Use autoloader for Patchwork/PHP/Shim/Normalizer --- lib/base.php | 1 + lib/util.php | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/base.php b/lib/base.php index 53aa7b09fd5..43145e1733c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -370,6 +370,7 @@ class OC { self::$loader->registerPrefix('Symfony\\Component\\Routing', 'symfony/routing'); self::$loader->registerPrefix('Sabre\\VObject', '3rdparty'); self::$loader->registerPrefix('Sabre_', '3rdparty'); + self::$loader->registerPrefix('Patchwork', '3rdparty'); spl_autoload_register(array(self::$loader, 'load')); // set some stuff diff --git a/lib/util.php b/lib/util.php index 981b05b2b46..2586ad28320 100755 --- a/lib/util.php +++ b/lib/util.php @@ -1,7 +1,5 @@ Date: Tue, 16 Jul 2013 22:36:39 +0200 Subject: [PATCH 2/5] Cleanup error generation in base.php --- lib/base.php | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/base.php b/lib/base.php index 43145e1733c..1ff462819db 100644 --- a/lib/base.php +++ b/lib/base.php @@ -124,10 +124,9 @@ class OC { OC::$THIRDPARTYWEBROOT = rtrim(dirname(OC::$WEBROOT), '/'); OC::$THIRDPARTYROOT = rtrim(dirname(OC::$SERVERROOT), '/'); } else { - echo('3rdparty directory not found! Please put the ownCloud 3rdparty' + throw new Exception('3rdparty directory not found! Please put the ownCloud 3rdparty' .' folder in the ownCloud folder or the folder above.' .' You can also configure the location in the config.php file.'); - exit; } // search the apps folder $config_paths = OC_Config::getValue('apps_paths', array()); @@ -150,9 +149,8 @@ class OC { } if (empty(OC::$APPSROOTS)) { - echo('apps directory not found! Please put the ownCloud apps folder in the ownCloud folder' + throw new Exception('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; } $paths = array(); foreach (OC::$APPSROOTS as $path) { @@ -174,14 +172,11 @@ class OC { if (file_exists(OC::$SERVERROOT . "/config/config.php") and !is_writable(OC::$SERVERROOT . "/config/config.php")) { $defaults = new OC_Defaults(); - $tmpl = new OC_Template('', 'error', 'guest'); - $tmpl->assign('errors', array(1 => array( - 'error' => "Can't write into config directory 'config'", - 'hint' => 'This can usually be fixed by ' + OC_Template::printErrorPage( + "Can't write into config directory 'config'", + 'This can usually be fixed by ' .'giving the webserver write access to the config directory.' - ))); - $tmpl->printPage(); - exit(); + ); } } @@ -223,10 +218,7 @@ class OC { header('Retry-After: 120'); // render error page - $tmpl = new OC_Template('', 'error', 'guest'); - $tmpl->assign('errors', array(1 => array('error' => 'ownCloud is in maintenance mode'))); - $tmpl->printPage(); - exit(); + OC_Template::printErrorPage('ownCloud is in maintenance mode'); } } @@ -305,11 +297,7 @@ class OC { $error = 'Session could not be initialized. Please contact your '; $error .= 'system administrator'; - $tmpl = new OC_Template('', 'error', 'guest'); - $tmpl->assign('errors', array(1 => array('error' => $error))); - $tmpl->printPage(); - - exit(); + OC_Template::printErrorPage($error); } $sessionLifeTime = self::getSessionLifeTime(); From 971a3fd124785033e7ed7db1018512b838c5ec58 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 16 Jul 2013 22:37:32 +0200 Subject: [PATCH 3/5] Early errors (in base.php) don't have session available --- lib/template.php | 5 ++++- lib/user.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/template.php b/lib/template.php index ae9ea187445..a1808c0b356 100644 --- a/lib/template.php +++ b/lib/template.php @@ -181,7 +181,7 @@ class OC_Template{ $this->renderas = $renderas; $this->application = $app; $this->vars = array(); - $this->vars['requesttoken'] = OC_Util::callRegister(); + $this->vars['requesttoken'] = OC::$session && OC_Util::callRegister(); $parts = explode('/', $app); // fix translation when app is something like core/lostpassword $this->l10n = OC_L10N::get($parts[0]); @@ -243,6 +243,9 @@ class OC_Template{ */ static public function getFormFactorExtension() { + if (!\OC::$session) { + return ''; + } // if the formfactor is not yet autodetected do the // autodetection now. For possible formfactors check the // detectFormfactor documentation diff --git a/lib/user.php b/lib/user.php index 830f13bb8df..d93ab1a5f73 100644 --- a/lib/user.php +++ b/lib/user.php @@ -316,7 +316,7 @@ class OC_User { * @return string uid or false */ public static function getUser() { - $uid = OC::$session->get('user_id'); + $uid = OC::$session ? OC::$session->get('user_id') : null; if (!is_null($uid)) { return $uid; } else { From 5b60fad467164326a776103e6a6ffc5a69b91a37 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 16 Jul 2013 22:42:09 +0200 Subject: [PATCH 4/5] Display the exception error backtrace preformatted --- lib/template.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/template.php b/lib/template.php index a1808c0b356..9ad1a330d4f 100644 --- a/lib/template.php +++ b/lib/template.php @@ -550,6 +550,9 @@ class OC_Template{ $error_msg = '['.$exception->getCode().'] '.$error_msg; } $hint = $exception->getTraceAsString(); + if (!empty($hint)) { + $hint = '
'.$hint.'
'; + } while (method_exists($exception,'previous') && $exception = $exception->previous()) { $error_msg .= '
Caused by: '; if ($exception->getCode()) { From 11f28d78805674ea06ef9227cf922140bff4a4ae Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 19 Jul 2013 17:37:42 +0200 Subject: [PATCH 5/5] Result of && if not the part --- lib/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/template.php b/lib/template.php index 9ad1a330d4f..9b16ed94661 100644 --- a/lib/template.php +++ b/lib/template.php @@ -181,7 +181,7 @@ class OC_Template{ $this->renderas = $renderas; $this->application = $app; $this->vars = array(); - $this->vars['requesttoken'] = OC::$session && OC_Util::callRegister(); + $this->vars['requesttoken'] = OC::$session ? OC_Util::callRegister() : ''; $parts = explode('/', $app); // fix translation when app is something like core/lostpassword $this->l10n = OC_L10N::get($parts[0]);