From 0c20647668f3575791dd9359d1dfcc6f3ab1fedf Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 14 May 2014 21:00:39 +0200 Subject: [PATCH] Adds page object types --- com.woltlab.wcf/objectType.xml | 169 ++++++++++++++++++ com.woltlab.wcf/objectTypeDefinition.xml | 4 + .../option/MultiSelectOptionType.class.php | 6 +- .../PageMultiSelectOptionType.class.php | 23 +++ .../option/PageSelectOptionType.class.php | 23 +++ .../option/RadioButtonOptionType.class.php | 17 +- .../system/option/SelectOptionType.class.php | 4 +- .../lib/system/page/PageManager.class.php | 98 ++++++++++ wcfsetup/install/lang/de.xml | 33 ++++ wcfsetup/install/lang/en.xml | 33 ++++ 10 files changed, 400 insertions(+), 10 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/option/PageMultiSelectOptionType.class.php create mode 100644 wcfsetup/install/files/lib/system/option/PageSelectOptionType.class.php create mode 100644 wcfsetup/install/files/lib/system/page/PageManager.class.php diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index 7e5123e449..5940d05086 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -419,5 +419,174 @@ userOptions + + + + com.woltlab.wcf.AccountManagementForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.AvatarEditForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.DisclaimerForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.EmailActivationForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.EmailNewActivationCodeForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.LoginForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.LostPasswordForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.MailForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.ModerationActivationForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.ModerationReportForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.NewPasswordForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.NotificationSettingsForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.RegisterActivationForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.RegisterForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.RegisterNewActivationCodeForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.SearchForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.SettingsForm + com.woltlab.wcf.page + + + + com.woltlab.wcf.SignatureEditForm + com.woltlab.wcf.page + + module_user_signature + + + com.woltlab.wcf.UserSearchForm + com.woltlab.wcf.page + + module_members_list + + + com.woltlab.wcf.DashboardPage + com.woltlab.wcf.page + + module_dashboard_page + + + com.woltlab.wcf.DeletedContentListPage + com.woltlab.wcf.page + + + + com.woltlab.wcf.FollowingPage + com.woltlab.wcf.page + + + + com.woltlab.wcf.IgnoredUsersPage + com.woltlab.wcf.page + + + + com.woltlab.wcf.MembersListPage + com.woltlab.wcf.page + + module_members_list + + + com.woltlab.wcf.ModerationListPage + com.woltlab.wcf.page + + + + com.woltlab.wcf.NotificationListPage + com.woltlab.wcf.page + + + + com.woltlab.wcf.RecentActivityListPage + com.woltlab.wcf.page + + + + com.woltlab.wcf.SearchResultPage + com.woltlab.wcf.page + + + + com.woltlab.wcf.TaggedPage + com.woltlab.wcf.page + + module_tagging + + + com.woltlab.wcf.TeamPage + com.woltlab.wcf.page + + module_team_page + + + com.woltlab.wcf.UserPage + com.woltlab.wcf.page + + + + com.woltlab.wcf.UsersOnlineListPage + com.woltlab.wcf.page + + + diff --git a/com.woltlab.wcf/objectTypeDefinition.xml b/com.woltlab.wcf/objectTypeDefinition.xml index 0f385cf5e2..1366360596 100644 --- a/com.woltlab.wcf/objectTypeDefinition.xml +++ b/com.woltlab.wcf/objectTypeDefinition.xml @@ -153,5 +153,9 @@ com.woltlab.wcf.condition.userGroupAssignment + + + com.woltlab.wcf.page + diff --git a/wcfsetup/install/files/lib/system/option/MultiSelectOptionType.class.php b/wcfsetup/install/files/lib/system/option/MultiSelectOptionType.class.php index a5e9a23015..65231a4f85 100644 --- a/wcfsetup/install/files/lib/system/option/MultiSelectOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/MultiSelectOptionType.class.php @@ -25,7 +25,7 @@ class MultiSelectOptionType extends SelectOptionType { public function getFormElement(Option $option, $value) { WCF::getTPL()->assign(array( 'option' => $option, - 'selectOptions' => $option->parseSelectOptions(), + 'selectOptions' => $this->getSelectOptions($option), 'value' => (!is_array($value) ? explode("\n", $value) : $value) )); return WCF::getTPL()->fetch('multiSelectOptionType'); @@ -38,7 +38,7 @@ class MultiSelectOptionType extends SelectOptionType { WCF::getTPL()->assign(array( 'option' => $option, 'searchOption' => $value !== $option->defaultValue || isset($_POST['searchOptions'][$option->optionName]), - 'selectOptions' => $option->parseSelectOptions(), + 'selectOptions' => $this->getSelectOptions($option), 'value' => (!is_array($value) ? explode("\n", $value) : $value) )); return WCF::getTPL()->fetch('multiSelectSearchableOptionType'); @@ -49,7 +49,7 @@ class MultiSelectOptionType extends SelectOptionType { */ public function validate(Option $option, $newValue) { if (!is_array($newValue)) $newValue = array(); - $options = $option->parseSelectOptions(); + $options = $this->getSelectOptions($option); foreach ($newValue as $value) { if (!isset($options[$value])) { throw new UserInputException($option->optionName, 'validationFailed'); diff --git a/wcfsetup/install/files/lib/system/option/PageMultiSelectOptionType.class.php b/wcfsetup/install/files/lib/system/option/PageMultiSelectOptionType.class.php new file mode 100644 index 0000000000..6149b2a72d --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/PageMultiSelectOptionType.class.php @@ -0,0 +1,23 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class PageMultiSelectOptionType extends MultiSelectOptionType { + /** + * @see \wcf\system\option\RadioButtonOptionType::getSelectOptions() + */ + protected function getSelectOptions(Option $option) { + return PageManager::getInstance()->getSelection($option->application); + } +} diff --git a/wcfsetup/install/files/lib/system/option/PageSelectOptionType.class.php b/wcfsetup/install/files/lib/system/option/PageSelectOptionType.class.php new file mode 100644 index 0000000000..e6e5db88cc --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/PageSelectOptionType.class.php @@ -0,0 +1,23 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class PageSelectOptionType extends SelectOptionType { + /** + * @see \wcf\system\option\RadioButtonOptionType::getSelectOptions() + */ + protected function getSelectOptions(Option $option) { + return PageManager::getInstance()->getSelection($option->application); + } +} diff --git a/wcfsetup/install/files/lib/system/option/RadioButtonOptionType.class.php b/wcfsetup/install/files/lib/system/option/RadioButtonOptionType.class.php index 4179b0971f..d58aea1202 100644 --- a/wcfsetup/install/files/lib/system/option/RadioButtonOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/RadioButtonOptionType.class.php @@ -29,9 +29,6 @@ class RadioButtonOptionType extends AbstractOptionType implements ISearchableCon * @see \wcf\system\option\IOptionType::getFormElement() */ public function getFormElement(Option $option, $value) { - // get options - $selectOptions = $option->parseSelectOptions(); - $availableOptions = $option->parseMultipleEnableOptions(); $options = array( 'disableOptions' => array(), @@ -49,7 +46,7 @@ class RadioButtonOptionType extends AbstractOptionType implements ISearchableCon 'disableOptions' => $options['disableOptions'], 'enableOptions' => $options['enableOptions'], 'option' => $option, - 'selectOptions' => $selectOptions, + 'selectOptions' => $this->getSelectOptions($option), 'value' => $value )); return WCF::getTPL()->fetch($this->templateName); @@ -60,7 +57,7 @@ class RadioButtonOptionType extends AbstractOptionType implements ISearchableCon */ public function validate(Option $option, $newValue) { if (!empty($newValue)) { - $options = $option->parseSelectOptions(); + $options = $this->getSelectOptions($option); if (!isset($options[$newValue])) { throw new UserInputException($option->optionName, 'validationFailed'); } @@ -107,4 +104,14 @@ class RadioButtonOptionType extends AbstractOptionType implements ISearchableCon public function getConditionData(Option $option, $newValue) { return $newValue; } + + /** + * Returns the select options for the given option. + * + * @param \wcf\dat\option\Option $option + * @return array + */ + protected function getSelectOptions(Option $option) { + return $option->parseSelectOptions(); + } } diff --git a/wcfsetup/install/files/lib/system/option/SelectOptionType.class.php b/wcfsetup/install/files/lib/system/option/SelectOptionType.class.php index e95ce3b6ab..64629ffcd5 100644 --- a/wcfsetup/install/files/lib/system/option/SelectOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/SelectOptionType.class.php @@ -26,7 +26,7 @@ class SelectOptionType extends RadioButtonOptionType { 'disableOptions' => $options['disableOptions'], 'enableOptions' => $options['enableOptions'], 'option' => $option, - 'selectOptions' => $option->parseSelectOptions(), + 'selectOptions' => $this->getSelectOptions($option), 'value' => $value, 'allowEmptyValue' => ($this->allowEmptyValue || $option->allowEmptyValue) )); @@ -44,7 +44,7 @@ class SelectOptionType extends RadioButtonOptionType { 'enableOptions' => $options['enableOptions'], 'option' => $option, 'searchOption' => ($value !== null && $value !== $option->defaultValue) || isset($_POST['searchOptions'][$option->optionName]), - 'selectOptions' => $option->parseSelectOptions(), + 'selectOptions' => $this->getSelectOptions($option), 'value' => $value )); return WCF::getTPL()->fetch('selectSearchableOptionType'); diff --git a/wcfsetup/install/files/lib/system/page/PageManager.class.php b/wcfsetup/install/files/lib/system/page/PageManager.class.php new file mode 100644 index 0000000000..64c709de65 --- /dev/null +++ b/wcfsetup/install/files/lib/system/page/PageManager.class.php @@ -0,0 +1,98 @@ + + * @package com.woltlab.wcf + * @subpackage system.page + * @category Community Framework + */ +class PageManager extends SingletonFactory { + /** + * list of available page object types + * @var array<\wcf\data\object\type\ObjectType> + */ + protected $objectTypes = array(); + + /** + * @see \wcf\system\SingletonFactory::init() + */ + protected function init() { + $this->objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.page'); + } + + /** + * Returns a list of the available page object types. + * + * @return array<\wcf\data\object\type\ObjectType> + */ + public function getObjectTypes() { + return $this->objectTypes; + } + + /** + * Returns an array used to build a page selection. If $application is given, + * only pages who belong to the application with the given abbreviation + * are returned. + * + * @param string $application + * @return array + */ + public function getSelection($application = null) { + $objectTypes = $this->objectTypes; + + // filter by application + if ($application !== null) { + // validate application + if ($application != 'wcf' && ApplicationHandler::getInstance()->getApplication($application) === null) { + throw new SystemException("Unknown application with abbreviation '".$application."'"); + } + + foreach ($objectTypes as $objectTypeName => $objectType) { + $classNamePieces = explode('\\', $objectType->className); + + if ($classNamePieces[0] != $application) { + unset($objectTypes[$objectTypeName]); + } + } + } + + // filter by options + foreach ($objectTypes as $objectTypeName => $objectType) { + if ($objectType->options) { + $options = explode(',', strtoupper($objectType->options)); + foreach ($options as $option) { + if (!defined($option) || !constant($option)) { + unset($objectTypes[$objectTypeName]); + break; + } + } + } + } + + $selection = array(); + foreach ($objectTypes as $objectType) { + $selection[$objectType->objectTypeID] = WCF::getLanguage()->get('wcf.page.'.$objectType->objectType); + + if ($application === null && substr($objectType->className, 0, 3) != 'wcf') { + $classNamePieces = explode('\\', $objectType->className); + + $selection[$objectType->objectTypeID] .= ' ('.PackageCache::getInstance()->getPackage(ApplicationHandler::getInstance()->getApplication($classNamePieces[0])->packageID).')'; + } + } + + sort($selection); + + return $selection; + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 7c8d0dd5bf..d0ffc71cb8 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2028,6 +2028,39 @@ Fehler sind beispielsweise: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 335fd2413f..73d16ce621 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1998,6 +1998,39 @@ Errors are: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.20.1