From: Alexander Ebert Date: Tue, 5 Apr 2016 20:12:21 +0000 (+0200) Subject: Properly implemented landing page X-Git-Tag: 3.0.0_Beta_1~1975 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a80873d5fe45732dd39a51a89f6f58a91656fc50;p=GitHub%2FWoltLab%2FWCF.git Properly implemented landing page --- diff --git a/com.woltlab.wcf/acpMenu.xml b/com.woltlab.wcf/acpMenu.xml index 3d3f75b860..94d96a8f89 100644 --- a/com.woltlab.wcf/acpMenu.xml +++ b/com.woltlab.wcf/acpMenu.xml @@ -279,12 +279,6 @@ wcf.acp.menu.link.cms admin.content.cms.canManagePage - - - wcf.acp.menu.link.cms.page.list - admin.content.cms.canManagePage - fa-home - wcf.acp.menu.link.cms.page.list diff --git a/com.woltlab.wcf/templates/dashboard.tpl b/com.woltlab.wcf/templates/dashboard.tpl index e40e9b3c64..b25eea05e6 100644 --- a/com.woltlab.wcf/templates/dashboard.tpl +++ b/com.woltlab.wcf/templates/dashboard.tpl @@ -1,7 +1,7 @@ {include file='documentHeader'} - {if $__wcf->getPageMenu()->getLandingPage()->menuItem != 'wcf.user.dashboard'}{lang}wcf.user.dashboard{/lang} - {/if}{PAGE_TITLE|language} + {if !$__wcf->isLandingPage()}{lang}wcf.user.dashboard{/lang} - {/if}{PAGE_TITLE|language} {include file='headInclude'} @@ -18,7 +18,7 @@ {include file='header'} -{if $__wcf->getPageMenu()->getLandingPage()->menuItem == 'wcf.user.dashboard'} +{if $__wcf->isLandingPage()}

{PAGE_TITLE|language}

diff --git a/wcfsetup/install/files/acp/install.php b/wcfsetup/install/files/acp/install.php index a86c1ec0d0..98326293c3 100644 --- a/wcfsetup/install/files/acp/install.php +++ b/wcfsetup/install/files/acp/install.php @@ -2,11 +2,10 @@ use wcf\system\session\SessionHandler; use wcf\system\WCF; use wcf\util\DateUtil; -use wcf\util\StringUtil; /** * @author Marcel Werk - * @copyright 2001-2015 WoltLab GmbH + * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @category Community Framework @@ -15,7 +14,7 @@ use wcf\util\StringUtil; $sql = "UPDATE wcf".WCF_N."_package_installation_plugin SET priority = ?"; $statement = WCF::getDB()->prepareStatement($sql); -$statement->execute(array(1)); +$statement->execute([1]); // reset sessions SessionHandler::resetSessions(); @@ -24,36 +23,46 @@ SessionHandler::resetSessions(); $sql = "UPDATE wcf".WCF_N."_acp_template SET packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); -$statement->execute(array(1)); +$statement->execute([1]); // update language $sql = "UPDATE wcf".WCF_N."_language_item SET packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); -$statement->execute(array(1)); +$statement->execute([1]); // update installation logs $sql = "UPDATE wcf".WCF_N."_package_installation_file_log SET packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); -$statement->execute(array(1)); +$statement->execute([1]); $sql = "UPDATE wcf".WCF_N."_package_installation_sql_log SET packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); -$statement->execute(array(1)); +$statement->execute([1]); // update pips $sql = "UPDATE wcf".WCF_N."_package_installation_plugin SET packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); -$statement->execute(array(1)); +$statement->execute([1]); // group options $sql = "UPDATE wcf".WCF_N."_user_group_option SET packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); -$statement->execute(array(1)); +$statement->execute([1]); + +// landing page +$sql = "UPDATE wcf".WCF_N."_page + SET isLandingPage = ? + WHERE identifier = ?"; +$statement = WCF::getDB()->prepareStatement($sql); +$statement->execute([ + 1, + 'com.woltlab.wcf.Dashboard' +]); // get server timezone if ($timezone = @date_default_timezone_get()) { @@ -62,6 +71,9 @@ if ($timezone = @date_default_timezone_get()) { SET optionValue = ? WHERE optionName = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($timezone, 'timezone')); + $statement->execute([ + $timezone, + 'timezone' + ]); } } diff --git a/wcfsetup/install/files/acp/templates/pageAdd.tpl b/wcfsetup/install/files/acp/templates/pageAdd.tpl index 62200b484b..6d959a4343 100644 --- a/wcfsetup/install/files/acp/templates/pageAdd.tpl +++ b/wcfsetup/install/files/acp/templates/pageAdd.tpl @@ -159,12 +159,14 @@ {/if} -
-
-
- -
-
+ {if $action != 'edit' || !$page->requireObjectID} +
+
+
+ +
+
+ {/if}
diff --git a/wcfsetup/install/files/acp/templates/pageLanding.tpl b/wcfsetup/install/files/acp/templates/pageLanding.tpl deleted file mode 100644 index 94ed4225a2..0000000000 --- a/wcfsetup/install/files/acp/templates/pageLanding.tpl +++ /dev/null @@ -1,59 +0,0 @@ -{include file='header' pageTitle='wcf.acp.page.landing'} - -
-

{lang}wcf.acp.page.landing{/lang}

-
- -{include file='formError'} - -{if $success|isset} -

{lang}wcf.global.success.{$action}{/lang}

-{/if} - -
- -
- -
-
- - - - - - - - - - - {foreach from=$applications item=application} - - - - - - {/foreach} - -
{lang}wcf.acp.page.landing.application{/lang}{lang}wcf.acp.page.landing.pageURL{/lang}{lang}wcf.acp.page.landing.landingPage{/lang}
{$application->getPackage()}{$application->getPageURL()} - -
-
- -
- - {@SECURITY_TOKEN_INPUT_TAG} -
-
- -{include file='footer'} diff --git a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php index d021ca7033..16a5b43e63 100644 --- a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php @@ -275,20 +275,27 @@ class PageAddForm extends AbstractForm { 'pageType' => $this->pageType, 'name' => $this->name, 'isDisabled' => ($this->isDisabled) ? 1 : 0, - 'isLandingPage' => ($this->isLandingPage) ? 1 : 0, + 'isLandingPage' => 0, 'packageID' => ($this->packageID ?: null), 'lastUpdateTime' => TIME_NOW, 'isMultilingual' => $this->isMultilingual, 'identifier' => '', 'controller' => $this->controller ]), 'content' => $content]); - $returnValues = $this->objectAction->executeAction(); + + /** @var Page $page */ + $page = $this->objectAction->executeAction()['returnValues']; + // set generic page identifier - $pageEditor = new PageEditor($returnValues['returnValues']); + $pageEditor = new PageEditor($page); $pageEditor->update([ 'identifier' => 'com.woltlab.wcf.generic'.$pageEditor->pageID ]); + if ($this->isLandingPage) { + $page->setAsLandingPage(); + } + // call saved event $this->saved(); diff --git a/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php b/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php index 315bf0671c..5f210ade9c 100644 --- a/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php @@ -63,6 +63,11 @@ class PageEditForm extends PageAddForm { $this->packageID = $this->page->packageID; $this->controller = $this->page->controller; } + + if ($this->page->requireObjectID) { + // pages that require an object id can never be set as landing page + $this->isLandingPage = 0; + } } /** @@ -83,7 +88,6 @@ class PageEditForm extends PageAddForm { $data = array( 'name' => $this->name, 'isDisabled' => ($this->isDisabled) ? 1 : 0, - 'isLandingPage' => ($this->isLandingPage) ? 1 : 0, 'lastUpdateTime' => TIME_NOW, 'parentPageID' => ($this->parentPageID ?: null), 'packageID' => $this->packageID @@ -121,6 +125,10 @@ class PageEditForm extends PageAddForm { $this->objectAction->executeAction(); } + if ($this->isLandingPage != $this->page->isLandingPage) { + $this->page->setAsLandingPage(); + } + // call saved event $this->saved(); diff --git a/wcfsetup/install/files/lib/acp/form/PageLandingForm.class.php b/wcfsetup/install/files/lib/acp/form/PageLandingForm.class.php deleted file mode 100644 index c996b41023..0000000000 --- a/wcfsetup/install/files/lib/acp/form/PageLandingForm.class.php +++ /dev/null @@ -1,134 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage acp.form - * @category Community Framework - */ -class PageLandingForm extends AbstractForm { - /** - * @inheritDoc - */ - public $activeMenuItem = 'wcf.acp.menu.link.cms.page.landing'; - - /** - * list of available applications - * @var Application[] - */ - public $applications; - - /** - * landing page id per application package id - * @var integer[] - */ - public $landingPages = []; - - /** - * @inheritDoc - */ - public $neededPermissions = ['admin.content.cms.canManagePage']; - - /** - * list of available pages - * @var Page[] - */ - public $pages = []; - - /** - * @inheritDoc - */ - public function readParameters() { - parent::readParameters(); - - // get available applications and pages - $applicationList = new ApplicationList(); - $applicationList->readObjects(); - $this->applications = $applicationList->getObjects(); - - $pageList = new PageList(); - $pageList->readObjects(); - foreach ($pageList as $page) { - if (!isset($this->pages[$page->packageID])) $this->pages[$page->packageID] = []; - - $this->pages[$page->packageID][$page->pageID] = $page; - } - } - - /** - * @inheritDoc - */ - public function readFormParameters() { - parent::readFormParameters(); - - if (isset($_POST['landingPages']) && is_array($_POST['landingPages'])) $this->landingPages = ArrayUtil::toIntegerArray($_POST['landingPages']); - } - - /** - * @inheritDoc - */ - public function validate() { - parent::validate(); - - foreach ($this->applications as $packageID => $application) { - if (empty($this->landingPages[$packageID])) { - throw new UserInputException('landingPage'); - } - - // handle application default - if ($this->landingPages[$packageID] === -1) { - $this->landingPages[$packageID] = null; - - continue; - } - - $page = new Page($this->landingPages[$packageID]); - if (!$page->pageID) { - throw new UserInputException('landingPage', 'notValid'); - } - } - } - - /** - * @inheritDoc - */ - public function save() { - parent::save(); - - $this->objectAction = new ApplicationAction($this->applications, 'setLandingPage', ['landingPages' => $this->landingPages]); - $this->objectAction->executeAction(); - - // call saved event - $this->saved(); - - // show success - WCF::getTPL()->assign('success', true); - } - - /** - * @inheritDoc - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign([ - 'applications' => $this->applications, - 'pageNodeList' => (new PageNodeTree())->getNodeList() - ]); - } -} diff --git a/wcfsetup/install/files/lib/data/page/Page.class.php b/wcfsetup/install/files/lib/data/page/Page.class.php index f03f641fe8..a35e913327 100644 --- a/wcfsetup/install/files/lib/data/page/Page.class.php +++ b/wcfsetup/install/files/lib/data/page/Page.class.php @@ -5,6 +5,7 @@ use wcf\data\TDatabaseObjectOptions; use wcf\data\TDatabaseObjectPermissions; use wcf\system\application\ApplicationHandler; use wcf\system\database\util\PreparedStatementConditionBuilder; +use wcf\system\exception\SystemException; use wcf\system\request\LinkHandler; use wcf\system\WCF; @@ -203,6 +204,37 @@ class Page extends DatabaseObject { return true; } + /** + * Sets the current page as landing page. + * + * @throws SystemException + */ + public function setAsLandingPage() { + if ($this->requireObjectID) { + throw new SystemException('Pages requiring an object id cannot be set as landing page.'); + } + + // unmark existing landing page + $sql = "UPDATE wcf".WCF_N."_page + SET isLandingPage = ? + AND isLandingPage = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([ + 0, + 1 + ]); + + // set current page as landing page + $sql = "UPDATE wcf".WCF_N."_page + SET isLandingPage = ? + WHERE pageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([ + 1, + $this->pageID + ]); + } + /** * Returns the page's internal name. * diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 718c434f92..c28cac1581 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -20,6 +20,7 @@ use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\SystemException; use wcf\system\language\LanguageFactory; use wcf\system\package\PackageInstallationDispatcher; +use wcf\system\request\RequestHandler; use wcf\system\request\RouteHandler; use wcf\system\session\SessionFactory; use wcf\system\session\SessionHandler; @@ -55,7 +56,7 @@ if (!defined('NO_IMPORTS')) { * It holds the database connection, access to template and language engine. * * @author Marcel Werk - * @copyright 2001-2015 WoltLab GmbH + * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system @@ -909,6 +910,15 @@ class WCF { return self::getPath() . 'images/favicon.ico'; } + /** + * Returns true if currently active request represents the landing page. + * + * @return boolean + */ + public function isLandingPage() { + return RequestHandler::getInstance()->getActiveRequest()->isLandingPage(); + } + /** * Initialises the cronjobs. */ diff --git a/wcfsetup/install/files/lib/system/cache/builder/PageCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/PageCacheBuilder.class.php index b0b115fd9f..6447f21216 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/PageCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/PageCacheBuilder.class.php @@ -1,5 +1,6 @@ [], 'controller' => [], - 'pages' => [] + 'pages' => [], + 'landingPage' => null ]; $pageList = new PageList(); @@ -28,9 +30,14 @@ class PageCacheBuilder extends AbstractCacheBuilder { $data['pages'] = $pageList->getObjects(); // build lookup table + /** @var Page $page */ foreach ($pageList as $page) { $data['identifier'][$page->identifier] = $page->pageID; $data['controller'][$page->controller] = $page->pageID; + + if ($page->isLandingPage) { + $data['landingPage'] = $page; + } } return $data; diff --git a/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php index 5fc0428c45..8c8509808f 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php @@ -2,6 +2,7 @@ namespace wcf\system\cache\builder; use wcf\data\application\Application; use wcf\data\page\Page; +use wcf\page\CmsPage; use wcf\system\application\ApplicationHandler; use wcf\system\request\ControllerMap; use wcf\system\WCF; @@ -169,25 +170,37 @@ class RoutingCacheBuilder extends AbstractCacheBuilder { } foreach (ApplicationHandler::getInstance()->getApplications() as $application) { - if ($application->landingPageID) { - $page = new Page($application->landingPageID); - if ($page->controller) { - $controller = $page->controller; + $controller = null; + + if ($application->packageID == 1) { + // handle WCF + $page = PageCacheBuilder::getInstance()->getData([], 'landingPage'); + if ($page === null) { + // no landing page defined + $controller = ['', '', '']; } else { - $controller = '__WCF_CMS__' . $page->pageID; - $controller = [$controller, $controller]; + if ($page->controller) { + $controller = $page->controller; + } + else { + $controller = '__WCF_CMS__' . $page->pageID; + $controller = [$controller, $controller, CmsPage::class]; + } + } } - else if ($application->packageID == 1) { - // WCF has no default controller - $controller = ['', '']; - } else { - $controller = preg_replace('~^.*?\\\([^\\\]+)(?:Action|Form|Page)$~', '\\1', WCF::getApplicationObject($application)->getPrimaryController()); + $controller = WCF::getApplicationObject($application)->getPrimaryController(); + } + + if (is_string($controller)) { + $fqnController = $controller; + $controller = preg_replace('~^.*?\\\([^\\\]+)(?:Action|Form|Page)$~', '\\1', $controller); $controller = [ $controller, - ControllerMap::transformController($controller) + ControllerMap::transformController($controller), + $fqnController ]; } diff --git a/wcfsetup/install/files/lib/system/request/ControllerMap.class.php b/wcfsetup/install/files/lib/system/request/ControllerMap.class.php index 2393c91926..9cc705ef20 100644 --- a/wcfsetup/install/files/lib/system/request/ControllerMap.class.php +++ b/wcfsetup/install/files/lib/system/request/ControllerMap.class.php @@ -246,6 +246,28 @@ class ControllerMap extends SingletonFactory { return false; } + /** + * Returns true if currently active request represents the landing page. + * + * @param string[] $classData + * @param array $metaData + * @return boolean + */ + public function isLandingPage(array $classData, array $metaData) { + if ($classData['className'] !== $this->landingPages['wcf'][2]) { + return false; + } + + if ($classData['className'] === CmsPage::class) { + // check if page id matches + if ($this->landingPages['wcf'][1] !== '__WCF_CMS__' . $metaData['cms']['pageID']) { + return false; + } + } + + return true; + } + /** * Returns the class data for the active request or null if for the given * configuration no proper class exist. diff --git a/wcfsetup/install/files/lib/system/request/Request.class.php b/wcfsetup/install/files/lib/system/request/Request.class.php index 9c80572c12..1634c80d05 100644 --- a/wcfsetup/install/files/lib/system/request/Request.class.php +++ b/wcfsetup/install/files/lib/system/request/Request.class.php @@ -18,6 +18,11 @@ class Request { */ protected $className = ''; + /** + * @var boolean + */ + protected $isLandingPage = false; + /** * request meta data * @var string[] @@ -57,6 +62,13 @@ class Request { $this->pageType = $pageType; } + /** + * Marks this request as landing page. + */ + public function setIsLandingPage() { + $this->isLandingPage = true; + } + /** * Executes this request. */ @@ -76,6 +88,15 @@ class Request { return ($this->requestObject !== null); } + /** + * Returns true if this request represents the landing page. + * + * @return boolean + */ + public function isLandingPage() { + return $this->isLandingPage; + } + /** * Returns the page class name of this request. * diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index 8985988808..6cfcb74e3b 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -167,6 +167,11 @@ class RequestHandler extends SingletonFactory { } $this->activeRequest = new Request($classData['className'], $classData['controller'], $classData['pageType'], $metaData); + + // determine if current request matches the landing page + if (ControllerMap::getInstance()->isLandingPage($classData, $metaData)) { + $this->activeRequest->setIsLandingPage(); + } } catch (SystemException $e) { throw new IllegalLinkException(); diff --git a/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php b/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php index 0473ad60d6..c1ab7b433f 100644 --- a/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php +++ b/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php @@ -79,7 +79,7 @@ class DynamicRequestRoute implements IRequestRoute { } /** - * @see IRequestRoute::setIsACP() + * @inheritDoc */ public function setIsACP($isACP) { $this->isACP = $isACP; diff --git a/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php b/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php index ce8baa6fb9..7bf2715357 100644 --- a/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php +++ b/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php @@ -27,7 +27,7 @@ class StaticRequestRoute extends DynamicRequestRoute { protected $staticController = ''; /** - * @see \wcf\system\request\route\IRequestRoute::setIsACP() + * @inheritDoc */ public function setIsACP($isACP) { // static routes are disallowed for ACP @@ -48,7 +48,7 @@ class StaticRequestRoute extends DynamicRequestRoute { } /** - * @see \wcf\system\request\IRoute::buildLink() + * @inheritDoc */ public function buildLink(array $components) { // static routes don't have these components @@ -59,7 +59,7 @@ class StaticRequestRoute extends DynamicRequestRoute { } /** - * @see \wcf\system\request\IRoute::canHandle() + * @inheritDoc */ public function canHandle(array $components) { if (isset($components['application']) && $components['application'] == $this->staticApplication) { @@ -72,7 +72,7 @@ class StaticRequestRoute extends DynamicRequestRoute { } /** - * @see \wcf\system\request\IRoute::matches() + * @inheritDoc */ public function matches($requestURL) { if (parent::matches($requestURL)) { diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 866d2aa536..130ad586a5 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -128,8 +128,7 @@ CREATE TABLE wcf1_application ( domainName VARCHAR(255) NOT NULL, domainPath VARCHAR(255) NOT NULL DEFAULT '/', cookieDomain VARCHAR(255) NOT NULL, - cookiePath VARCHAR(255) NOT NULL DEFAULT '/', - landingPageID INT(10) NULL + cookiePath VARCHAR(255) NOT NULL DEFAULT '/' ); DROP TABLE IF EXISTS wcf1_attachment;