| @@ -1,96 +1,125 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -declare(strict_types=1); | |
| 4 | - | |
| 2 | +/** | |
| 3 | + * Config.php | |
| 4 | + * | |
| 5 | + * The Config class file. | |
| 6 | + * | |
| 7 | + * PHP versions 5 | |
| 8 | + * | |
| 9 | + * @author Alexander Schneider <[email protected]> | |
| 10 | + * @copyright 2008-2017 Alexander Schneider | |
| 11 | + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 | |
| 12 | + * @version SVN: $id$ | |
| 13 | + * @link http://wordpress.org/extend/plugins/user-access-manager/ | |
| 14 | + */ | |
| 5 | 15 | namespace UserAccessManager\Config; |
| 6 | 16 | |
| 7 | -use Exception; | |
| 8 | 17 | use UserAccessManager\Cache\Cache; |
| 9 | -use UserAccessManager\Config\Parameter\ConfigParameter; | |
| 10 | -use UserAccessManager\Config\Parameter\ConfigParameterFactory; | |
| 11 | 18 | use UserAccessManager\Object\ObjectHandler; |
| 12 | 19 | use UserAccessManager\Wrapper\Wordpress; |
| 13 | 20 | |
| 21 | +/** | |
| 22 | + * Class Config | |
| 23 | + * | |
| 24 | + * @package UserAccessManager\Config | |
| 25 | + */ | |
| 14 | 26 | class MainConfig extends Config |
| 15 | 27 | { |
| 16 | - public const MAIN_CONFIG_KEY = 'uamAdminOptions'; | |
| 17 | - public const DEFAULT_TYPE = 'default'; | |
| 18 | - public const CACHE_PROVIDER_NONE = 'none'; | |
| 28 | + const MAIN_CONFIG_KEY = 'uamAdminOptions'; | |
| 29 | + const DEFAULT_TYPE = 'default'; | |
| 30 | + const CACHE_PROVIDER_NONE = 'none'; | |
| 19 | 31 | |
| 20 | - public function __construct( | |
| 21 | - Wordpress $wordpress, | |
| 22 | - private ObjectHandler $objectHandler, | |
| 23 | - private Cache $cache, | |
| 24 | - private ConfigParameterFactory $configParameterFactory | |
| 25 | - ) { | |
| 26 | - parent::__construct($wordpress, self::MAIN_CONFIG_KEY); | |
| 27 | - } | |
| 32 | + /** | |
| 33 | + * @var ObjectHandler | |
| 34 | + */ | |
| 35 | + private $objectHandler; | |
| 28 | 36 | |
| 29 | 37 | /** |
| 30 | - * @throws Exception | |
| 38 | + * @var Cache | |
| 31 | 39 | */ |
| 32 | - private function addBoolean(array &$configParameters, string $id, bool $defaultValue = false): void | |
| 33 | - { | |
| 34 | - $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, $defaultValue); | |
| 35 | - } | |
| 40 | + private $cache; | |
| 36 | 41 | |
| 37 | 42 | /** |
| 38 | - * @throws Exception | |
| 43 | + * @var ConfigParameterFactory | |
| 39 | 44 | */ |
| 40 | - private function addString(array &$configParameters, string $id, string $defaultValue = ''): void | |
| 41 | - { | |
| 42 | - $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id, $defaultValue); | |
| 43 | - } | |
| 45 | + protected $configParameterFactory; | |
| 44 | 46 | |
| 45 | 47 | /** |
| 46 | - * @throws Exception | |
| 48 | + * MainConfig constructor. | |
| 49 | + * | |
| 50 | + * @param Wordpress $wordpress | |
| 51 | + * @param ObjectHandler $objectHandler | |
| 52 | + * @param Cache $cache | |
| 53 | + * @param ConfigParameterFactory $configParameterFactory | |
| 47 | 54 | */ |
| 48 | - private function addSelection( | |
| 49 | - array &$configParameters, | |
| 50 | - string $id, | |
| 51 | - string $defaultValue, | |
| 52 | - array $selections | |
| 53 | - ): void { | |
| 54 | - $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter( | |
| 55 | - $id, | |
| 56 | - $defaultValue, | |
| 57 | - $selections | |
| 58 | - ); | |
| 55 | + public function __construct( | |
| 56 | + Wordpress $wordpress, | |
| 57 | + ObjectHandler $objectHandler, | |
| 58 | + Cache $cache, | |
| 59 | + ConfigParameterFactory $configParameterFactory | |
| 60 | + ) { | |
| 61 | + $this->objectHandler = $objectHandler; | |
| 62 | + $this->cache = $cache; | |
| 63 | + $this->configParameterFactory = $configParameterFactory; | |
| 64 | + | |
| 65 | + parent::__construct($wordpress, self::MAIN_CONFIG_KEY); | |
| 59 | 66 | } |
| 60 | 67 | |
| 61 | 68 | /** |
| 62 | - * @throws Exception | |
| 69 | + * Adds the default general config parameters to the config parameters. | |
| 70 | + * | |
| 71 | + * @param array $configParameters | |
| 63 | 72 | */ |
| 64 | - private function addDefaultGeneralConfigParameters(array &$configParameters): void | |
| 73 | + private function addDefaultGeneralConfigParameters(array &$configParameters) | |
| 65 | 74 | { |
| 66 | - $this->addSelection( | |
| 67 | - $configParameters, | |
| 68 | - 'redirect', | |
| 75 | + $id = 'redirect'; | |
| 76 | + $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter( | |
| 77 | + $id, | |
| 69 | 78 | 'false', |
| 70 | - ['false', 'blog', 'login', 'custom_page', 'custom_url', 'origin'] | |
| 79 | + ['false', 'blog', 'login', 'custom_page', 'custom_url'] | |
| 71 | 80 | ); |
| 72 | - $this->addString($configParameters, 'redirect_custom_page'); | |
| 73 | - $this->addString($configParameters, 'redirect_custom_url'); | |
| 74 | - $this->addBoolean($configParameters, 'append_redirect_to_parameter'); | |
| 75 | - $this->addBoolean($configParameters, 'lock_recursive', true); | |
| 76 | - $this->addBoolean($configParameters, 'authors_has_access_to_own', true); | |
| 77 | - $this->addBoolean($configParameters, 'authors_can_add_posts_to_groups'); | |
| 78 | - $this->addBoolean($configParameters, 'blog_admin_hint', true); | |
| 79 | - $this->addString($configParameters, 'blog_admin_hint_text', '[L]'); | |
| 80 | - $this->addBoolean($configParameters, 'show_assigned_groups', true); | |
| 81 | - $this->addBoolean($configParameters, 'hide_edit_link_on_no_access', true); | |
| 82 | - $this->addString($configParameters, 'extra_ip_header', 'HTTP_X_REAL_IP'); | |
| 83 | - $this->addBoolean($configParameters, 'protect_feed', true); | |
| 84 | - $this->addSelection( | |
| 85 | - $configParameters, | |
| 86 | - 'full_access_role', | |
| 81 | + | |
| 82 | + $id = 'redirect_custom_page'; | |
| 83 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id); | |
| 84 | + | |
| 85 | + $id = 'redirect_custom_url'; | |
| 86 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id); | |
| 87 | + | |
| 88 | + $id = 'lock_recursive'; | |
| 89 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true); | |
| 90 | + | |
| 91 | + $id = 'authors_has_access_to_own'; | |
| 92 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true); | |
| 93 | + | |
| 94 | + $id = 'authors_can_add_posts_to_groups'; | |
| 95 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id); | |
| 96 | + | |
| 97 | + $id = 'blog_admin_hint'; | |
| 98 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true); | |
| 99 | + | |
| 100 | + $id = 'blog_admin_hint_text'; | |
| 101 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id, '[L]'); | |
| 102 | + | |
| 103 | + $id = 'show_assigned_groups'; | |
| 104 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true); | |
| 105 | + | |
| 106 | + $id = 'hide_edit_link_on_no_access'; | |
| 107 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true); | |
| 108 | + | |
| 109 | + $id = 'protect_feed'; | |
| 110 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true); | |
| 111 | + | |
| 112 | + $id = 'full_access_role'; | |
| 113 | + $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter( | |
| 114 | + $id, | |
| 87 | 115 | 'administrator', |
| 88 | 116 | ['administrator', 'editor', 'author', 'contributor', 'subscriber'] |
| 89 | 117 | ); |
| 90 | - $this->addSelection( | |
| 91 | - $configParameters, | |
| 92 | - 'active_cache_provider', | |
| 118 | + | |
| 119 | + $id = 'active_cache_provider'; | |
| 120 | + $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter( | |
| 121 | + $id, | |
| 93 | 122 | self::CACHE_PROVIDER_NONE, |
| 94 | 123 | array_merge([self::CACHE_PROVIDER_NONE], array_keys($this->cache->getRegisteredCacheProviders())) |
| 95 | 124 | ); |
| 96 | 125 | } |
| @@ -95,11 +124,13 @@ | ||
| 95 | 124 | ); |
| 96 | 125 | } |
| 97 | 126 | |
| 98 | 127 | /** |
| 99 | - * @throws Exception | |
| 128 | + * Adds the default post config parameters to the config parameters. | |
| 129 | + * | |
| 130 | + * @param array $configParameters | |
| 100 | 131 | */ |
| 101 | - private function addDefaultPostConfigParameters(array &$configParameters): void | |
| 132 | + private function addDefaultPostConfigParameters(array &$configParameters) | |
| 102 | 133 | { |
| 103 | 134 | $postTypes = $this->objectHandler->getPostTypes(); |
| 104 | 135 | array_unshift($postTypes, self::DEFAULT_TYPE); |
| 105 | 136 | |
| @@ -108,30 +139,53 @@ | ||
| 108 | 139 | continue; |
| 109 | 140 | } |
| 110 | 141 | |
| 111 | 142 | if ($postType !== self::DEFAULT_TYPE) { |
| 112 | - $this->addBoolean($configParameters, "{$postType}_use_default"); | |
| 143 | + $id = "{$postType}_use_default"; | |
| 144 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id); | |
| 113 | 145 | } |
| 114 | 146 | |
| 115 | - $this->addBoolean($configParameters, "hide_$postType"); | |
| 116 | - $this->addBoolean($configParameters, "hide_{$postType}_title"); | |
| 117 | - $this->addString($configParameters, "{$postType}_title", TXT_UAM_SETTING_DEFAULT_NO_RIGHTS); | |
| 118 | - $this->addString($configParameters, "{$postType}_content", TXT_UAM_SETTING_DEFAULT_NO_RIGHTS_FOR_ENTRY); | |
| 119 | - $this->addBoolean($configParameters, "hide_{$postType}_comment"); | |
| 120 | - $this->addString( | |
| 121 | - $configParameters, | |
| 122 | - "{$postType}_comment_content", | |
| 147 | + $id = "hide_{$postType}"; | |
| 148 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id); | |
| 149 | + | |
| 150 | + $id = "hide_{$postType}_title"; | |
| 151 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id); | |
| 152 | + | |
| 153 | + $id = "{$postType}_title"; | |
| 154 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter( | |
| 155 | + $id, | |
| 156 | + TXT_UAM_SETTING_DEFAULT_NO_RIGHTS | |
| 157 | + ); | |
| 158 | + | |
| 159 | + $id = "{$postType}_content"; | |
| 160 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter( | |
| 161 | + $id, | |
| 162 | + TXT_UAM_SETTING_DEFAULT_NO_RIGHTS_FOR_ENTRY | |
| 163 | + ); | |
| 164 | + | |
| 165 | + $id = "hide_{$postType}_comment"; | |
| 166 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id); | |
| 167 | + | |
| 168 | + $id = "{$postType}_comment_content"; | |
| 169 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter( | |
| 170 | + $id, | |
| 123 | 171 | TXT_UAM_SETTING_DEFAULT_NO_RIGHTS_FOR_COMMENTS |
| 124 | 172 | ); |
| 125 | - $this->addBoolean($configParameters, "{$postType}_comments_locked"); | |
| 126 | - $this->addBoolean($configParameters, "show_{$postType}_content_before_more"); | |
| 173 | + | |
| 174 | + $id = "{$postType}_comments_locked"; | |
| 175 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id); | |
| 176 | + | |
| 177 | + $id = "show_{$postType}_content_before_more"; | |
| 178 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id); | |
| 127 | 179 | } |
| 128 | 180 | } |
| 129 | 181 | |
| 130 | 182 | /** |
| 131 | - * @throws Exception | |
| 183 | + * Adds the default taxonomy config parameters to the config parameters. | |
| 184 | + * | |
| 185 | + * @param array $configParameters | |
| 132 | 186 | */ |
| 133 | - private function addDefaultTaxonomyConfigParameters(array &$configParameters): void | |
| 187 | + private function addDefaultTaxonomyConfigParameters(array &$configParameters) | |
| 134 | 188 | { |
| 135 | 189 | $taxonomies = $this->objectHandler->getTaxonomies(); |
| 136 | 190 | array_unshift($taxonomies, self::DEFAULT_TYPE); |
| 137 | 191 | |
| @@ -136,256 +190,449 @@ | ||
| 136 | 190 | array_unshift($taxonomies, self::DEFAULT_TYPE); |
| 137 | 191 | |
| 138 | 192 | foreach ($taxonomies as $taxonomy) { |
| 139 | 193 | if ($taxonomy !== self::DEFAULT_TYPE) { |
| 140 | - $this->addBoolean($configParameters, "{$taxonomy}_use_default"); | |
| 194 | + $id = "{$taxonomy}_use_default"; | |
| 195 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id); | |
| 141 | 196 | } |
| 142 | 197 | |
| 143 | - $this->addBoolean($configParameters, "hide_empty_$taxonomy", true); | |
| 198 | + $id = 'hide_empty_'.$taxonomy; | |
| 199 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true); | |
| 144 | 200 | } |
| 145 | 201 | } |
| 146 | 202 | |
| 147 | 203 | /** |
| 148 | - * @throws Exception | |
| 204 | + * Adds the default file config parameters to the config parameters. | |
| 205 | + * | |
| 206 | + * @param array $configParameters | |
| 149 | 207 | */ |
| 150 | - private function addDefaultFileConfigParameters(array &$configParameters): void | |
| 208 | + private function addDefaultFileConfigParameters(array &$configParameters) | |
| 151 | 209 | { |
| 152 | - $this->addBoolean($configParameters, 'lock_file'); | |
| 153 | - $this->addSelection($configParameters, 'download_type', 'fopen', ['xsendfile', 'fopen', 'normal']); | |
| 154 | - $this->addString($configParameters, 'inline_files', 'pdf'); | |
| 155 | - $this->addSelection($configParameters, 'no_access_image_type', 'default', ['default', 'custom']); | |
| 156 | - $this->addString($configParameters, 'custom_no_access_image'); | |
| 157 | - $this->addBoolean($configParameters, 'use_custom_file_handling_file'); | |
| 158 | - $this->addSelection($configParameters, 'locked_directory_type', 'wordpress', ['wordpress', 'all', 'custom']); | |
| 159 | - $this->addString($configParameters, 'custom_locked_directories'); | |
| 160 | - $this->addSelection($configParameters, 'file_pass_type', 'random', ['random', 'user']); | |
| 161 | - $this->addSelection($configParameters, 'lock_file_types', 'all', ['all', 'selected', 'not_selected']); | |
| 162 | - $this->addString($configParameters, 'locked_file_types', 'zip,rar,tar,gz'); | |
| 163 | - $this->addString($configParameters, 'not_locked_file_types', 'gif,jpg,jpeg,png'); | |
| 210 | + $id = 'lock_file'; | |
| 211 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id); | |
| 212 | + | |
| 213 | + $id = 'download_type'; | |
| 214 | + $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter( | |
| 215 | + $id, | |
| 216 | + 'fopen', | |
| 217 | + ['xsendfile', 'fopen', 'normal'] | |
| 218 | + ); | |
| 219 | + | |
| 220 | + $id = 'inline_files'; | |
| 221 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id, 'pdf'); | |
| 222 | + | |
| 223 | + $id = 'no_access_image_type'; | |
| 224 | + $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter( | |
| 225 | + $id, | |
| 226 | + 'default', | |
| 227 | + ['default', 'custom'] | |
| 228 | + ); | |
| 229 | + | |
| 230 | + $id = 'custom_no_access_image'; | |
| 231 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id); | |
| 232 | + | |
| 233 | + $id = 'use_custom_file_handling_file'; | |
| 234 | + $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id); | |
| 235 | + | |
| 236 | + $id = 'locked_directory_type'; | |
| 237 | + $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter( | |
| 238 | + $id, | |
| 239 | + 'wordpress', | |
| 240 | + ['wordpress', 'all', 'custom'] | |
| 241 | + ); | |
| 242 | + | |
| 243 | + $id = 'custom_locked_directories'; | |
| 244 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id); | |
| 245 | + | |
| 246 | + $id = 'file_pass_type'; | |
| 247 | + $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter( | |
| 248 | + $id, | |
| 249 | + 'random', | |
| 250 | + ['random', 'user'] | |
| 251 | + ); | |
| 252 | + | |
| 253 | + $id = 'lock_file_types'; | |
| 254 | + $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter( | |
| 255 | + $id, | |
| 256 | + 'all', | |
| 257 | + ['all', 'selected', 'not_selected'] | |
| 258 | + ); | |
| 259 | + | |
| 260 | + $id = 'locked_file_types'; | |
| 261 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter( | |
| 262 | + $id, | |
| 263 | + 'zip,rar,tar,gz' | |
| 264 | + ); | |
| 265 | + | |
| 266 | + $id = 'not_locked_file_types'; | |
| 267 | + $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter( | |
| 268 | + $id, | |
| 269 | + 'gif,jpg,jpeg,png' | |
| 270 | + ); | |
| 164 | 271 | } |
| 165 | 272 | |
| 166 | 273 | /** |
| 274 | + * Returns the default config parameters settings | |
| 275 | + * | |
| 167 | 276 | * @return ConfigParameter[] |
| 168 | - * @throws Exception | |
| 169 | 277 | */ |
| 170 | - protected function getDefaultConfigParameters(): array | |
| 278 | + protected function getDefaultConfigParameters() | |
| 171 | 279 | { |
| 172 | - if ($this->defaultConfigParameters !== []) { | |
| 173 | - return $this->defaultConfigParameters; | |
| 174 | - } | |
| 280 | + if ($this->defaultConfigParameters === []) { | |
| 281 | + /** | |
| 282 | + * @var ConfigParameter[] $configParameters | |
| 283 | + */ | |
| 284 | + $configParameters = []; | |
| 175 | 285 | |
| 176 | - /** | |
| 177 | - * @var ConfigParameter[] $configParameters | |
| 178 | - */ | |
| 179 | - $configParameters = []; | |
| 286 | + $this->addDefaultGeneralConfigParameters($configParameters); | |
| 287 | + $this->addDefaultPostConfigParameters($configParameters); | |
| 288 | + $this->addDefaultTaxonomyConfigParameters($configParameters); | |
| 289 | + $this->addDefaultFileConfigParameters($configParameters); | |
| 180 | 290 | |
| 181 | - $this->addDefaultGeneralConfigParameters($configParameters); | |
| 182 | - $this->addDefaultPostConfigParameters($configParameters); | |
| 183 | - $this->addDefaultTaxonomyConfigParameters($configParameters); | |
| 184 | - $this->addDefaultFileConfigParameters($configParameters); | |
| 291 | + $this->defaultConfigParameters = $configParameters; | |
| 292 | + } | |
| 185 | 293 | |
| 186 | - return $this->defaultConfigParameters = $configParameters; | |
| 294 | + return $this->defaultConfigParameters; | |
| 187 | 295 | } |
| 188 | 296 | |
| 189 | - private function getObjectParameter(string $objectType, string $rawParameterName): ?ConfigParameter | |
| 297 | + /** | |
| 298 | + * Returns the object parameter name. | |
| 299 | + * | |
| 300 | + * @param string $objectType | |
| 301 | + * @param string $rawParameterName | |
| 302 | + * | |
| 303 | + * @return ConfigParameter|null | |
| 304 | + */ | |
| 305 | + private function getObjectParameter($objectType, $rawParameterName) | |
| 190 | 306 | { |
| 191 | 307 | $options = $this->getConfigParameters(); |
| 192 | 308 | $parameterName = sprintf($rawParameterName, $objectType); |
| 193 | - $useDefaultParameter = $options["{$objectType}_use_default"] ?? null; | |
| 194 | 309 | |
| 195 | - if (isset($options[$parameterName]) === false || $useDefaultParameter?->getValue() === true) { | |
| 310 | + if (isset($options[$parameterName]) === false | |
| 311 | + || isset($options["{$objectType}_use_default"]) === true | |
| 312 | + && $options["{$objectType}_use_default"]->getValue() === true | |
| 313 | + ) { | |
| 196 | 314 | $parameterName = sprintf($rawParameterName, self::DEFAULT_TYPE); |
| 197 | 315 | } |
| 198 | 316 | |
| 199 | - return $options[$parameterName] ?? null; | |
| 317 | + return (isset($options[$parameterName]) === true) ? $options[$parameterName] : null; | |
| 200 | 318 | } |
| 201 | 319 | |
| 202 | - private function hideObject(string $objectType, string $parameterName): bool | |
| 320 | + /** | |
| 321 | + * Returns the option value if the option exists otherwise true. | |
| 322 | + * | |
| 323 | + * @param string $objectType | |
| 324 | + * @param string $parameterName | |
| 325 | + * | |
| 326 | + * @return bool | |
| 327 | + */ | |
| 328 | + private function hideObject($objectType, $parameterName) | |
| 203 | 329 | { |
| 204 | - return $this->getObjectParameter($objectType, $parameterName)?->getValue() ?? true; | |
| 330 | + $parameter = $this->getObjectParameter($objectType, $parameterName); | |
| 331 | + return ($parameter !== null) ? $parameter->getValue() : true; | |
| 205 | 332 | } |
| 206 | 333 | |
| 207 | - private function getObjectContent(string $objectType, string $parameterName): bool|string | |
| 334 | + /** | |
| 335 | + * Returns the option value if the option exists otherwise an empty string. | |
| 336 | + * | |
| 337 | + * @param string $objectType | |
| 338 | + * @param string $parameterName | |
| 339 | + * | |
| 340 | + * @return string | |
| 341 | + */ | |
| 342 | + private function getObjectContent($objectType, $parameterName) | |
| 208 | 343 | { |
| 209 | - return $this->getObjectParameter($objectType, $parameterName)?->getValue() ?? ''; | |
| 344 | + $parameter = $this->getObjectParameter($objectType, $parameterName); | |
| 345 | + return ($parameter !== null) ? $parameter->getValue() : ''; | |
| 210 | 346 | } |
| 211 | 347 | |
| 212 | - public function hidePostType(string $postType): bool | |
| 348 | + /** | |
| 349 | + * @param string $postType | |
| 350 | + * | |
| 351 | + * @return bool | |
| 352 | + */ | |
| 353 | + public function hidePostType($postType) | |
| 213 | 354 | { |
| 214 | 355 | return $this->hideObject($postType, 'hide_%s'); |
| 215 | 356 | } |
| 216 | 357 | |
| 217 | - public function hidePostTypeTitle(string $postType): bool | |
| 358 | + /** | |
| 359 | + * @param string $postType | |
| 360 | + * | |
| 361 | + * @return bool | |
| 362 | + */ | |
| 363 | + public function hidePostTypeTitle($postType) | |
| 218 | 364 | { |
| 219 | 365 | return $this->hideObject($postType, 'hide_%s_title'); |
| 220 | 366 | } |
| 221 | 367 | |
| 222 | - public function hidePostTypeComments(string $postType): bool | |
| 368 | + /** | |
| 369 | + * @param string $postType | |
| 370 | + * | |
| 371 | + * @return bool | |
| 372 | + */ | |
| 373 | + public function hidePostTypeComments($postType) | |
| 223 | 374 | { |
| 224 | 375 | return $this->hideObject($postType, 'hide_%s_comment'); |
| 225 | 376 | } |
| 226 | 377 | |
| 227 | - public function lockPostTypeComments(string $postType): bool | |
| 378 | + /** | |
| 379 | + * @param string $postType | |
| 380 | + * | |
| 381 | + * @return bool | |
| 382 | + */ | |
| 383 | + public function lockPostTypeComments($postType) | |
| 228 | 384 | { |
| 229 | 385 | return $this->hideObject($postType, '%s_comments_locked'); |
| 230 | 386 | } |
| 231 | 387 | |
| 232 | - public function getPostTypeTitle(string $postType): string | |
| 388 | + /** | |
| 389 | + * @param string $postType | |
| 390 | + * | |
| 391 | + * @return string | |
| 392 | + */ | |
| 393 | + public function getPostTypeTitle($postType) | |
| 233 | 394 | { |
| 234 | 395 | return $this->getObjectContent($postType, '%s_title'); |
| 235 | 396 | } |
| 236 | 397 | |
| 237 | - public function getPostTypeContent(string $postType): string | |
| 398 | + /** | |
| 399 | + * @param string $postType | |
| 400 | + * | |
| 401 | + * @return string | |
| 402 | + */ | |
| 403 | + public function getPostTypeContent($postType) | |
| 238 | 404 | { |
| 239 | 405 | return $this->getObjectContent($postType, '%s_content'); |
| 240 | 406 | } |
| 241 | 407 | |
| 242 | - public function getPostTypeCommentContent(string $postType): string | |
| 408 | + /** | |
| 409 | + * @param string $postType | |
| 410 | + * | |
| 411 | + * @return string | |
| 412 | + */ | |
| 413 | + public function getPostTypeCommentContent($postType) | |
| 243 | 414 | { |
| 244 | 415 | return $this->getObjectContent($postType, '%s_comment_content'); |
| 245 | 416 | } |
| 246 | 417 | |
| 247 | - public function showPostTypeContentBeforeMore(string $postType): bool | |
| 418 | + /** | |
| 419 | + * @param string $postType | |
| 420 | + * | |
| 421 | + * @return bool | |
| 422 | + */ | |
| 423 | + public function showPostTypeContentBeforeMore($postType) | |
| 248 | 424 | { |
| 249 | - return (bool) $this->getObjectContent($postType, 'show_%s_content_before_more'); | |
| 425 | + return $this->getObjectContent($postType, 'show_%s_content_before_more'); | |
| 250 | 426 | } |
| 251 | 427 | |
| 252 | - public function getRedirect(): ?string | |
| 428 | + /** | |
| 429 | + * @return string | |
| 430 | + */ | |
| 431 | + public function getRedirect() | |
| 253 | 432 | { |
| 254 | 433 | return $this->getParameterValue('redirect'); |
| 255 | 434 | } |
| 256 | 435 | |
| 257 | - public function getRedirectCustomPage(): ?string | |
| 436 | + /** | |
| 437 | + * @return string | |
| 438 | + */ | |
| 439 | + public function getRedirectCustomPage() | |
| 258 | 440 | { |
| 259 | 441 | return $this->getParameterValue('redirect_custom_page'); |
| 260 | 442 | } |
| 261 | 443 | |
| 262 | - public function getRedirectCustomUrl(): ?string | |
| 444 | + /** | |
| 445 | + * @return string | |
| 446 | + */ | |
| 447 | + public function getRedirectCustomUrl() | |
| 263 | 448 | { |
| 264 | 449 | return $this->getParameterValue('redirect_custom_url'); |
| 265 | 450 | } |
| 266 | 451 | |
| 267 | - public function appendRedirectToParameter(): bool | |
| 452 | + /** | |
| 453 | + * @return bool | |
| 454 | + */ | |
| 455 | + public function lockRecursive() | |
| 268 | 456 | { |
| 269 | - return (bool) $this->getParameterValue('append_redirect_to_parameter'); | |
| 457 | + return $this->getParameterValue('lock_recursive'); | |
| 270 | 458 | } |
| 271 | 459 | |
| 272 | - public function lockRecursive(): bool | |
| 460 | + /** | |
| 461 | + * @return bool | |
| 462 | + */ | |
| 463 | + public function authorsHasAccessToOwn() | |
| 273 | 464 | { |
| 274 | - return (bool) $this->getParameterValue('lock_recursive'); | |
| 465 | + return $this->getParameterValue('authors_has_access_to_own'); | |
| 275 | 466 | } |
| 276 | 467 | |
| 277 | - public function authorsHasAccessToOwn(): bool | |
| 468 | + /** | |
| 469 | + * @return bool | |
| 470 | + */ | |
| 471 | + public function authorsCanAddPostsToGroups() | |
| 278 | 472 | { |
| 279 | - return (bool) $this->getParameterValue('authors_has_access_to_own'); | |
| 473 | + return $this->getParameterValue('authors_can_add_posts_to_groups'); | |
| 280 | 474 | } |
| 281 | 475 | |
| 282 | - public function authorsCanAddPostsToGroups(): bool | |
| 476 | + /** | |
| 477 | + * @return bool | |
| 478 | + */ | |
| 479 | + public function lockFile() | |
| 283 | 480 | { |
| 284 | - return (bool) $this->getParameterValue('authors_can_add_posts_to_groups'); | |
| 481 | + return $this->getParameterValue('lock_file'); | |
| 285 | 482 | } |
| 286 | 483 | |
| 287 | - public function lockFile(): bool | |
| 484 | + /** | |
| 485 | + * @return string | |
| 486 | + */ | |
| 487 | + public function getInlineFiles() | |
| 288 | 488 | { |
| 289 | - return (bool) $this->getParameterValue('lock_file'); | |
| 290 | - } | |
| 291 | - | |
| 292 | - public function getInlineFiles(): ?string | |
| 293 | - { | |
| 294 | 489 | return $this->getParameterValue('inline_files'); |
| 295 | 490 | } |
| 296 | 491 | |
| 297 | - public function getNoAccessImageType(): ?string | |
| 492 | + /** | |
| 493 | + * @return string | |
| 494 | + */ | |
| 495 | + public function getNoAccessImageType() | |
| 298 | 496 | { |
| 299 | 497 | return $this->getParameterValue('no_access_image_type'); |
| 300 | 498 | } |
| 301 | 499 | |
| 302 | - public function getCustomNoAccessImage(): ?string | |
| 500 | + /** | |
| 501 | + * @return string | |
| 502 | + */ | |
| 503 | + public function getCustomNoAccessImage() | |
| 303 | 504 | { |
| 304 | 505 | return $this->getParameterValue('custom_no_access_image'); |
| 305 | 506 | } |
| 306 | 507 | |
| 307 | - public function useCustomFileHandlingFile(): bool | |
| 508 | + /** | |
| 509 | + * @return bool | |
| 510 | + */ | |
| 511 | + public function useCustomFileHandlingFile() | |
| 308 | 512 | { |
| 309 | - return (bool) $this->getParameterValue('use_custom_file_handling_file'); | |
| 513 | + return $this->getParameterValue('use_custom_file_handling_file'); | |
| 310 | 514 | } |
| 311 | 515 | |
| 312 | - public function getLockedDirectoryType(): ?string | |
| 516 | + /** | |
| 517 | + * @return string | |
| 518 | + */ | |
| 519 | + public function getLockedDirectoryType() | |
| 313 | 520 | { |
| 314 | 521 | return $this->getParameterValue('locked_directory_type'); |
| 315 | 522 | } |
| 316 | 523 | |
| 317 | - public function getCustomLockedDirectories(): ?string | |
| 524 | + /** | |
| 525 | + * @return string | |
| 526 | + */ | |
| 527 | + public function getCustomLockedDirectories() | |
| 318 | 528 | { |
| 319 | 529 | return $this->getParameterValue('custom_locked_directories'); |
| 320 | 530 | } |
| 321 | 531 | |
| 322 | - public function getFilePassType(): ?string | |
| 532 | + /** | |
| 533 | + * @return string | |
| 534 | + */ | |
| 535 | + public function getFilePassType() | |
| 323 | 536 | { |
| 324 | 537 | return $this->getParameterValue('file_pass_type'); |
| 325 | 538 | } |
| 326 | 539 | |
| 327 | - public function getDownloadType(): ?string | |
| 540 | + /** | |
| 541 | + * @return string | |
| 542 | + */ | |
| 543 | + public function getDownloadType() | |
| 328 | 544 | { |
| 329 | 545 | return $this->getParameterValue('download_type'); |
| 330 | 546 | } |
| 331 | 547 | |
| 332 | - public function getLockedFileType(): ?string | |
| 548 | + /** | |
| 549 | + * @return string | |
| 550 | + */ | |
| 551 | + public function getLockedFileType() | |
| 333 | 552 | { |
| 334 | 553 | return $this->getParameterValue('lock_file_types'); |
| 335 | 554 | } |
| 336 | 555 | |
| 337 | - public function getLockedFiles(): ?string | |
| 556 | + /** | |
| 557 | + * @return string | |
| 558 | + */ | |
| 559 | + public function getLockedFiles() | |
| 338 | 560 | { |
| 339 | 561 | return $this->getParameterValue('locked_file_types'); |
| 340 | 562 | } |
| 341 | 563 | |
| 342 | - public function getNotLockedFiles(): ?string | |
| 564 | + /** | |
| 565 | + * @return string | |
| 566 | + */ | |
| 567 | + public function getNotLockedFiles() | |
| 343 | 568 | { |
| 344 | 569 | return $this->getParameterValue('not_locked_file_types'); |
| 345 | 570 | } |
| 346 | 571 | |
| 347 | - public function blogAdminHint(): bool | |
| 572 | + /** | |
| 573 | + * @return bool | |
| 574 | + */ | |
| 575 | + public function blogAdminHint() | |
| 348 | 576 | { |
| 349 | - return (bool) $this->getParameterValue('blog_admin_hint'); | |
| 577 | + return $this->getParameterValue('blog_admin_hint'); | |
| 350 | 578 | } |
| 351 | 579 | |
| 352 | - public function getBlogAdminHintText(): ?string | |
| 580 | + /** | |
| 581 | + * @return string | |
| 582 | + */ | |
| 583 | + public function getBlogAdminHintText() | |
| 353 | 584 | { |
| 354 | 585 | return $this->getParameterValue('blog_admin_hint_text'); |
| 355 | 586 | } |
| 356 | 587 | |
| 357 | - public function showAssignedGroups(): bool | |
| 588 | + /** | |
| 589 | + * @return bool | |
| 590 | + */ | |
| 591 | + public function showAssignedGroups() | |
| 358 | 592 | { |
| 359 | - return (bool) $this->getParameterValue('show_assigned_groups'); | |
| 593 | + return $this->getParameterValue('show_assigned_groups'); | |
| 360 | 594 | } |
| 361 | 595 | |
| 362 | - public function hideEditLinkOnNoAccess(): bool | |
| 596 | + /** | |
| 597 | + * @return bool | |
| 598 | + */ | |
| 599 | + public function hideEditLinkOnNoAccess() | |
| 363 | 600 | { |
| 364 | - return (bool) $this->getParameterValue('hide_edit_link_on_no_access'); | |
| 601 | + return $this->getParameterValue('hide_edit_link_on_no_access'); | |
| 365 | 602 | } |
| 366 | 603 | |
| 367 | - public function hideEmptyTaxonomy(string $taxonomy): bool | |
| 604 | + /** | |
| 605 | + * @param string $taxonomy | |
| 606 | + * | |
| 607 | + * @return bool | |
| 608 | + */ | |
| 609 | + public function hideEmptyTaxonomy($taxonomy) | |
| 368 | 610 | { |
| 369 | - return $this->getObjectParameter($taxonomy, 'hide_empty_%s')?->getValue() ?? false; | |
| 611 | + $parameter = $this->getObjectParameter($taxonomy, 'hide_empty_%s'); | |
| 612 | + return ($parameter !== null) ? $parameter->getValue() : false; | |
| 370 | 613 | } |
| 371 | 614 | |
| 372 | - public function protectFeed(): bool | |
| 615 | + /** | |
| 616 | + * @return bool | |
| 617 | + */ | |
| 618 | + public function protectFeed() | |
| 373 | 619 | { |
| 374 | - return (bool) $this->getParameterValue('protect_feed'); | |
| 620 | + return $this->getParameterValue('protect_feed'); | |
| 375 | 621 | } |
| 376 | 622 | |
| 377 | - public function getFullAccessRole(): ?string | |
| 623 | + /** | |
| 624 | + * @return string | |
| 625 | + */ | |
| 626 | + public function getFullAccessRole() | |
| 378 | 627 | { |
| 379 | 628 | return $this->getParameterValue('full_access_role'); |
| 380 | 629 | } |
| 381 | 630 | |
| 382 | - public function getActiveCacheProvider(): ?string | |
| 631 | + /** | |
| 632 | + * @return null|string | |
| 633 | + */ | |
| 634 | + public function getActiveCacheProvider() | |
| 383 | 635 | { |
| 384 | 636 | return $this->getParameterValue('active_cache_provider'); |
| 385 | - } | |
| 386 | - | |
| 387 | - public function getExtraIpHeader(): ?string | |
| 388 | - { | |
| 389 | - return $this->getParameterValue('extra_ip_header'); | |
| 390 | 637 | } |
| 391 | 638 | } |