From 3fd6b1250cb5d2b4f022e2d4f7feb3f469e49c80 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sat, 2 Apr 2016 21:44:33 +0200 Subject: [PATCH] Added page types for cms pages --- com.woltlab.wcf/page.xml | 8 ++ com.woltlab.wcf/templates/cms.tpl | 10 +- .../install/files/acp/templates/pageAdd.tpl | 121 +++++++++++------- .../install/files/acp/templates/pageList.tpl | 105 +++++++++------ .../files/lib/acp/form/PageAddForm.class.php | 54 +++++++- .../files/lib/acp/form/PageEditForm.class.php | 64 ++++----- .../files/lib/acp/page/PageListPage.class.php | 40 +++++- .../files/lib/data/page/Page.class.php | 6 + .../PagePackageInstallationPlugin.class.php | 46 ++++++- wcfsetup/setup/db/install.sql | 1 + 10 files changed, 329 insertions(+), 126 deletions(-) diff --git a/com.woltlab.wcf/page.xml b/com.woltlab.wcf/page.xml index 5144bc8916..931f268351 100644 --- a/com.woltlab.wcf/page.xml +++ b/com.woltlab.wcf/page.xml @@ -3,6 +3,7 @@ + system wcf\page\DashboardPage @@ -10,6 +11,7 @@ + system wcf\page\MembersListPage @@ -17,12 +19,14 @@ module_members_list + system wcf\page\RecentActivityListPage com.woltlab.wcf.MembersList + system wcf\page\UsersOnlineListPage @@ -31,6 +35,7 @@ module_users_online + system wcf\page\TeamPage @@ -39,6 +44,7 @@ module_team_page + system wcf\page\UserSearchForm @@ -49,6 +55,7 @@ + text Cookie Policy Cookie-Richtlinie @@ -108,6 +115,7 @@ + text Privacy Policy Datenschutzerklärung module_privacy_policy_page diff --git a/com.woltlab.wcf/templates/cms.tpl b/com.woltlab.wcf/templates/cms.tpl index 6535d44282..1cee085e71 100644 --- a/com.woltlab.wcf/templates/cms.tpl +++ b/com.woltlab.wcf/templates/cms.tpl @@ -40,9 +40,15 @@ {/hascontent} {if $content[content]} -
+ {if $page->pageType == 'text'} +
+ {@$content[content]} +
+ {elseif $page->pageType == 'html'} {@$content[content]} -
+ {elseif $page->pageType == 'tpl'} + {*todo*} + {/if} {/if} {hascontent} diff --git a/wcfsetup/install/files/acp/templates/pageAdd.tpl b/wcfsetup/install/files/acp/templates/pageAdd.tpl index af67cc6941..62200b484b 100644 --- a/wcfsetup/install/files/acp/templates/pageAdd.tpl +++ b/wcfsetup/install/files/acp/templates/pageAdd.tpl @@ -62,49 +62,84 @@ - {if $action == 'add' || !$page->controller} - -
-
- - {if $errorField == 'parentPageID'} - - {if $errorType == 'empty'} - {lang}wcf.global.form.error.empty{/lang} - {else} - {lang}wcf.acp.page.parentPageID.error.{@$errorType}{/lang} - {/if} - - {/if} -
- - - -
-
- - {if $errorField == 'parentPageID'} - - {if $errorType == 'empty'} - {lang}wcf.global.form.error.empty{/lang} - {else} - {lang}wcf.acp.page.packageID.error.{@$errorType}{/lang} - {/if} - - {/if} -
- - {/if} + +
+
+ + + {if $errorField == 'pageType'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.page.pageType.error.{@$errorType}{/lang} + {/if} + + {/if} +
+ + + +
+
+ + {if $errorField == 'parentPageID'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.page.parentPageID.error.{@$errorType}{/lang} + {/if} + + {/if} +
+ + + +
+
+ + {if $errorField == 'parentPageID'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.page.packageID.error.{@$errorType}{/lang} + {/if} + + {/if} +
+ + + +
+
+ originIsSystem} readonly="readonly"{/if} /> + {if $errorField == 'controller'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.page.controller.error.{@$errorType}{/lang} + {/if} + + {/if} +
+ {if !$isMultilingual} diff --git a/wcfsetup/install/files/acp/templates/pageList.tpl b/wcfsetup/install/files/acp/templates/pageList.tpl index 4cfad27531..c994ca7d5a 100644 --- a/wcfsetup/install/files/acp/templates/pageList.tpl +++ b/wcfsetup/install/files/acp/templates/pageList.tpl @@ -13,47 +13,13 @@

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

-
-
-

{lang}wcf.global.filter{/lang}

- -
-
-
-
- -
-
- -
-
-
- -
-
- -
-
-
- -
-
- - {event name='filterFields'} -
-
- -
- - {@SECURITY_TOKEN_INPUT_TAG} -
-
-
{assign var='linkParameters' value=''} {if $name}{capture append=linkParameters}&name={@$name|rawurlencode}{/capture}{/if} {if $title}{capture append=linkParameters}&title={@$title|rawurlencode}{/capture}{/if} {if $content}{capture append=linkParameters}&content={@$content|rawurlencode}{/capture}{/if} + {if $packageID}{capture append=linkParameters}&packageID={@$packageID}{/capture}{/if} + {if $pageType}{capture append=linkParameters}&pageType={@$pageType|rawurlencode}{/capture}{/if} {pages print=true assign=pagesLinks controller="PageList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder$linkParameters"}
+
+
+

{lang}wcf.global.filter{/lang}

+ +
+
+
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ + {event name='filterFields'} +
+ +
+ + {@SECURITY_TOKEN_INPUT_TAG} +
+
+
+
+ {if $objects|count}
@@ -74,7 +101,7 @@ - + {event name='columnHeads'} @@ -106,8 +133,8 @@ + diff --git a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php index 425425c0ef..7c2e31ca7c 100644 --- a/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageAddForm.class.php @@ -42,6 +42,12 @@ class PageAddForm extends AbstractForm { */ public $isMultilingual = 0; + /** + * page type + * @var string + */ + public $pageType = ''; + /** * parent page id * @var integer @@ -84,6 +90,12 @@ class PageAddForm extends AbstractForm { */ public $customURL = []; + /** + * page controller + * @var string + */ + public $controller = ''; + /** * page titles * @var string[] @@ -129,10 +141,12 @@ class PageAddForm extends AbstractForm { parent::readFormParameters(); if (isset($_POST['parentPageID'])) $this->parentPageID = intval($_POST['parentPageID']); + if (isset($_POST['pageType'])) $this->pageType = $_POST['pageType']; if (isset($_POST['name'])) $this->name = StringUtil::trim($_POST['name']); if (isset($_POST['isDisabled'])) $this->isDisabled = 1; if (isset($_POST['isLandingPage'])) $this->isLandingPage = 1; if (isset($_POST['packageID'])) $this->packageID = intval($_POST['packageID']); + if (isset($_POST['controller'])) $this->controller = StringUtil::trim($_POST['controller']); if (isset($_POST['customURL']) && is_array($_POST['customURL'])) $this->customURL = ArrayUtil::trim($_POST['customURL']); if (isset($_POST['title']) && is_array($_POST['title'])) $this->title = ArrayUtil::trim($_POST['title']); @@ -149,10 +163,14 @@ class PageAddForm extends AbstractForm { $this->validateName(); + $this->validatePageType(); + $this->validateParentPageID(); $this->validatePackageID(); + $this->validateController(); + $this->validateCustomUrl(); } @@ -168,6 +186,15 @@ class PageAddForm extends AbstractForm { } } + /** + * Validates page type. + */ + protected function validatePageType() { + if (!in_array($this->pageType, Page::$availablePageTypes) || ($this->isMultilingual && $this->pageType == 'system')) { + throw new UserInputException('pageType'); + } + } + /** * Validates parent page id. */ @@ -189,6 +216,21 @@ class PageAddForm extends AbstractForm { } } + /** + * Validates controller. + */ + protected function validateController() { + if ($this->pageType == 'system') { + if (!$this->controller) { + throw new UserInputException('controller'); + } + + if (!class_exists($this->controller)) { + throw new UserInputException('controller', 'notFound'); + } + } + } + /** * Validates custom urls. */ @@ -230,13 +272,15 @@ class PageAddForm extends AbstractForm { $this->objectAction = new PageAction([], 'create', ['data' => array_merge($this->additionalFields, [ 'parentPageID' => ($this->parentPageID ?: null), + 'pageType' => $this->pageType, 'name' => $this->name, 'isDisabled' => ($this->isDisabled) ? 1 : 0, 'isLandingPage' => ($this->isLandingPage) ? 1 : 0, 'packageID' => ($this->packageID ?: null), 'lastUpdateTime' => TIME_NOW, 'isMultilingual' => $this->isMultilingual, - 'identifier' => '' + 'identifier' => '', + 'controller' => $this->controller ]), 'content' => $content]); $returnValues = $this->objectAction->executeAction(); // set generic page identifier @@ -254,7 +298,8 @@ class PageAddForm extends AbstractForm { // reset variables $this->parentPageID = $this->isDisabled = $this->isLandingPage = 0; $this->packageID = 1; - $this->name = ''; + $this->name = $this->controller = ''; + $this->pageType = 'text'; $this->customURL = $this->title = $this->content = $this->metaDescription = $this->metaKeywords = []; } @@ -264,14 +309,18 @@ class PageAddForm extends AbstractForm { public function assignVariables() { parent::assignVariables(); + $availablePageTypes = Page::$availablePageTypes; + if ($this->isMultilingual) unset($availablePageTypes[array_search('system', $availablePageTypes)]); WCF::getTPL()->assign([ 'action' => 'add', 'parentPageID' => $this->parentPageID, + 'pageType' => $this->pageType, 'name' => $this->name, 'isDisabled' => $this->isDisabled, 'isLandingPage' => $this->isLandingPage, 'isMultilingual' => $this->isMultilingual, 'packageID' => $this->packageID, + 'controller' => $this->controller, 'customURL' => $this->customURL, 'title' => $this->title, 'content' => $this->content, @@ -279,6 +328,7 @@ class PageAddForm extends AbstractForm { 'metaKeywords' => $this->metaKeywords, 'availableApplications' => $this->availableApplications, 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(), + 'availablePageTypes' => $availablePageTypes, 'pageNodeList' => (new PageNodeTree())->getNodeList() ]); } diff --git a/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php b/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php index 05d809e798..2afc5d0340 100644 --- a/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageEditForm.class.php @@ -54,30 +54,23 @@ class PageEditForm extends PageAddForm { /** * @inheritDoc */ - protected function validateName() { - if (mb_strtolower($this->name) != mb_strtolower($this->page->name)) { - parent::validateName(); - } - } - - /** - * @inheritDoc - */ - protected function validateParentPageID() { - if (!$this->page->controller && $this->parentPageID) { - $page = new Page($this->parentPageID); - if (!$page->pageID) { - throw new UserInputException('parentPageID', 'invalid'); - } + public function readFormParameters() { + parent::readFormParameters(); + + $this->pageType = $this->page->pageType; + if ($this->page->originIsSystem) { + $this->parentPageID = $this->page->parentPageID; + $this->packageID = $this->page->packageID; + $this->controller = $this->page->controller; } } /** * @inheritDoc */ - protected function validatePackageID() { - if (!$this->page->controller) { - parent::validatePackageID(); + protected function validateName() { + if (mb_strtolower($this->name) != mb_strtolower($this->page->name)) { + parent::validateName(); } } @@ -87,19 +80,23 @@ class PageEditForm extends PageAddForm { public function save() { AbstractForm::save(); - if ($this->page->controller) { - $this->objectAction = new PageAction(array($this->page), 'update', array('data' => array_merge($this->additionalFields, array( - 'name' => $this->name, - 'isDisabled' => ($this->isDisabled) ? 1 : 0, - 'isLandingPage' => ($this->isLandingPage) ? 1 : 0, - 'controllerCustomURL' => (!empty($_POST['customURL'][0]) ? $_POST['customURL'][0] : ''), - 'lastUpdateTime' => TIME_NOW - )))); + $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 + ); + + if ($this->pageType == 'system') { + $data['controllerCustomURL'] = (!empty($_POST['customURL'][0]) ? $_POST['customURL'][0] : ''); + $this->objectAction = new PageAction(array($this->page), 'update', array('data' => array_merge($this->additionalFields, $data))); $this->objectAction->executeAction(); } else { $content = array(); - if ($this->isMultilingual) { + if ($this->page->isMultilingual) { foreach (LanguageFactory::getInstance()->getLanguages() as $language) { $content[$language->languageID] = array( 'customURL' => (!empty($_POST['customURL'][$language->languageID]) ? $_POST['customURL'][$language->languageID] : ''), @@ -120,15 +117,7 @@ class PageEditForm extends PageAddForm { ); } - $this->objectAction = new PageAction(array($this->page), 'update', array('data' => array_merge($this->additionalFields, array( - 'parentPageID' => ($this->parentPageID ?: null), - 'name' => $this->name, - 'isDisabled' => ($this->isDisabled) ? 1 : 0, - 'isLandingPage' => ($this->isLandingPage) ? 1 : 0, - 'packageID' => ($this->packageID ?: null), - 'lastUpdateTime' => TIME_NOW, - 'isMultilingual' => $this->isMultilingual - )), 'content' => $content)); + $this->objectAction = new PageAction(array($this->page), 'update', array('data' => array_merge($this->additionalFields, $data), 'content' => $content)); $this->objectAction->executeAction(); } @@ -148,7 +137,10 @@ class PageEditForm extends PageAddForm { if (empty($_POST)) { $this->name = $this->page->name; $this->parentPageID = $this->page->parentPageID; + $this->pageType = $this->page->pageType; $this->packageID = $this->page->packageID; + $this->controller = $this->page->controller; + if ($this->page->controllerCustomURL) $this->customURL[0] = $this->page->controllerCustomURL; if ($this->page->isLandingPage) $this->isLandingPage = 1; if ($this->page->isDiabled) $this->isDisabled = 1; diff --git a/wcfsetup/install/files/lib/acp/page/PageListPage.class.php b/wcfsetup/install/files/lib/acp/page/PageListPage.class.php index 52e7707303..9f7d66b823 100644 --- a/wcfsetup/install/files/lib/acp/page/PageListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/PageListPage.class.php @@ -1,5 +1,6 @@ name = StringUtil::trim($_REQUEST['name']); if (!empty($_REQUEST['title'])) $this->title = StringUtil::trim($_REQUEST['title']); if (!empty($_REQUEST['content'])) $this->content = StringUtil::trim($_REQUEST['content']); + if (isset($_REQUEST['packageID'])) $this->packageID = intval($_REQUEST['packageID']); + if (!empty($_REQUEST['pageType'])) $this->pageType = $_REQUEST['pageType']; + + // get available applications + $applicationList = new ApplicationList(); + $applicationList->readObjects(); + $this->availableApplications = $applicationList->getObjects(); } /** @@ -85,6 +111,15 @@ class PageListPage extends SortablePage { if (!empty($this->content)) { $this->objectList->getConditionBuilder()->add('page.pageID IN (SELECT pageID FROM wcf'.WCF_N.'_page_content WHERE content LIKE ?)', array('%'.$this->content.'%')); } + if (!empty($this->packageID)) { + $this->objectList->getConditionBuilder()->add('page.packageID = ?', array($this->packageID)); + } + if ($this->pageType == 'static') { + $this->objectList->getConditionBuilder()->add('page.pageType IN (?, ?, ?)', array('text', 'html', 'tpl')); + } + else if ($this->pageType == 'system') { + $this->objectList->getConditionBuilder()->add('page.pageType IN (?)', array('system')); + } } /** @@ -96,7 +131,10 @@ class PageListPage extends SortablePage { WCF::getTPL()->assign(array( 'name' => $this->name, 'title' => $this->title, - 'content' => $this->content + 'content' => $this->content, + 'packageID' => $this->packageID, + 'pageType' => $this->pageType, + 'availableApplications' => $this->availableApplications )); } } diff --git a/wcfsetup/install/files/lib/data/page/Page.class.php b/wcfsetup/install/files/lib/data/page/Page.class.php index f61ea17a6c..dc3ea47e54 100644 --- a/wcfsetup/install/files/lib/data/page/Page.class.php +++ b/wcfsetup/install/files/lib/data/page/Page.class.php @@ -24,6 +24,12 @@ class Page extends DatabaseObject { use TDatabaseObjectOptions; use TDatabaseObjectPermissions; + /** + * available page types + * @var string[] + */ + public static $availablePageTypes = ['text', 'html', 'tpl', 'system']; + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php index 48f7b5f3cb..c880414ae7 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php @@ -144,13 +144,53 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin throw new SystemException("Invalid custom url for page identifier '" . $data['attributes']['identifier'] . "'"); } + // validate page type + $pageType = $data['elements']['pagetype']; + $controller = ''; + $identifier = $data['attributes']['identifier']; + $isMultilingual = 0; + switch ($pageType) { + case 'system': + if (empty($data['elements']['controller'])) { + throw new SystemException("Missing required element 'controller' for 'system'-type page '{$identifier}'"); + } + $controller = $data['elements']['controller']; + break; + + case 'html': + case 'text': + case 'tpl': + if (empty($data['elements']['content'])) { + throw new SystemException("Missing required 'content' element(s) for page '{$identifier}'"); + } + + if (count($data['elements']['content']) === 1) { + if (!isset($data['elements']['content'][''])) { + throw new SystemException("Expected one 'content' element without a 'language' attribute for page '{$identifier}'"); + } + } + else { + $isMultilingual = 1; + if (isset($data['elements']['content'][''])) { + throw new SystemException("Cannot mix 'content' elements with and without 'language' attribute for page '{$identifier}'"); + } + } + + break; + + default: + throw new SystemException("Unknown type '{$pageType}' for page '{$identifier}"); + break; + } + return [ + 'pageType' => $pageType, 'content' => ($isStatic) ? $data['elements']['content'] : [], - 'controller' => ($isStatic) ? '' : $data['elements']['controller'], + 'controller' => $controller, 'handler' => (!$isStatic && !empty($data['elements']['handler'])) ? $data['elements']['handler'] : '', 'controllerCustomURL' => $controllerCustomURL, - 'identifier' => $data['attributes']['identifier'], - 'isMultilingual' => ($isStatic) ? 1 : 0, + 'identifier' => $identifier, + 'isMultilingual' => $isMultilingual, 'lastUpdateTime' => TIME_NOW, 'name' => $name, 'originIsSystem' => 1, diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 9e8412db33..987530e416 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -906,6 +906,7 @@ CREATE TABLE wcf1_page ( parentPageID INT(10), identifier VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, + pageType VARCHAR(255) NOT NULL, isDisabled TINYINT(1) NOT NULL DEFAULT 0, isLandingPage TINYINT(1) NOT NULL DEFAULT 0, isMultilingual TINYINT(1) NOT NULL DEFAULT 0, -- 2.20.1
{lang}wcf.global.objectID{/lang} {lang}wcf.global.name{/lang}{lang}wcf.acp.page.url{/lang}{lang}wcf.acp.page.url{/lang} {lang}wcf.acp.page.lastUpdateTime{/lang} {@$page->pageID} {if $page->isLandingPage} {/if}{$page->name}{$page->getApplication()->getAbbreviation()} - {$page->getApplication()->getAbbreviation()} {$page->getDisplayLink()} {@$page->lastUpdateTime|time}