From e7bfc8814108c5a5dd2ad4d286bbe6a4b3503ca6 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 14 Dec 2013 21:11:52 +0100 Subject: [PATCH] Providing a sane implementation for application start pages Accessing a non-primary application by it's directory will no longer redirect to the landing page, instead user is redirected to the application's primary controller. --- .../install/files/lib/system/WCF.class.php | 28 ++++++++++++++++--- .../application/AbstractApplication.class.php | 13 +++++++++ .../system/application/IApplication.class.php | 7 +++++ .../system/request/RequestHandler.class.php | 14 ++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 379f7188f0..1acec6eeb1 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -61,10 +61,16 @@ if (!defined('NO_IMPORTS')) { class WCF { /** * list of currently loaded applications - * @var array<\wcf\system\application\IApplication> + * @var array<\wcf\data\application\Application> */ protected static $applications = array(); + /** + * list of currently loaded application objects + * @var array<\wcf\system\application\IApplication> + */ + protected static $applicationObjects = array(); + /** * list of autoload directories * @var array @@ -490,8 +496,8 @@ class WCF { } // init application and assign it as template variable - $applicationObject = call_user_func(array($className, 'getInstance')); - $this->getTPL()->assign('__'.$abbreviation, $applicationObject); + self::$applicationObjects[$application->packageID] = call_user_func(array($className, 'getInstance')); + $this->getTPL()->assign('__'.$abbreviation, self::$applicationObjects[$application->packageID]); } else { unset(self::$autoloadDirectories[$abbreviation]); @@ -510,7 +516,21 @@ class WCF { // register application self::$applications[$abbreviation] = $application; - return $applicationObject; + return self::$applicationObjects[$application->packageID]; + } + + /** + * Returns the corresponding application object. Does not support the 'wcf' pseudo application. + * + * @param wcf\data\application\Application $application + * @return \wcf\system\application\IApplication + */ + public static function getApplicationObject(Application $application) { + if (isset(self::$applicationObjects[$application->packageID])) { + return self::$applicationObjects[$application->packageID]; + } + + return null; } /** diff --git a/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php b/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php index 2adbf767f4..3ad882b2f1 100644 --- a/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php +++ b/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php @@ -33,6 +33,12 @@ abstract class AbstractApplication extends SingletonFactory implements IApplicat */ protected $packageID = 0; + /** + * qualified name of application's primary controller + * @var string + */ + protected $primaryController = ''; + /** * @see \wcf\system\SingletonFactory::init() */ @@ -77,6 +83,13 @@ abstract class AbstractApplication extends SingletonFactory implements IApplicat return PackageCache::getInstance()->getPackage($this->packageID); } + /** + * @see \wcf\system\application\IApplication::getPrimaryController() + */ + public function getPrimaryController() { + return $this->primaryController; + } + /** * @see \wcf\system\application\IApplication::__callStatic() */ diff --git a/wcfsetup/install/files/lib/system/application/IApplication.class.php b/wcfsetup/install/files/lib/system/application/IApplication.class.php index bde7c7d439..54e05ea309 100644 --- a/wcfsetup/install/files/lib/system/application/IApplication.class.php +++ b/wcfsetup/install/files/lib/system/application/IApplication.class.php @@ -24,6 +24,13 @@ interface IApplication { */ public function isActiveApplication(); + /** + * Returns the qualified name of this application's primary controller. + * + * @return string + */ + public function getPrimaryController(); + /** * Forwards unknown method calls to WCF. * diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index 898cbd651e..fb31735d66 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -1,5 +1,6 @@ getController(); } else { + // check if current URL matches an application but controller was omitted + $currentRequestURI = RouteHandler::getHost() . $requestUri; + foreach (ApplicationHandler::getInstance()->getApplications() as $application) { + if ($currentRequestURI == $application->getPageURL()) { + if ($controller = WCF::getApplicationObject($application)->getPrimaryController()) { + $controller = explode('\\', $controller); + HeaderUtil::redirect(LinkHandler::getInstance()->getLink(array_pop($controller), array('application' => $controller[0]))); + exit; + } + } + + } + // redirect to landing page HeaderUtil::redirect($landingPage->getLink(), true); exit; -- 2.20.1