diff --git a/CHANGELOG.md b/CHANGELOG.md index 46cebad..b6eb0df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Feat - Theme tiles, enabled by setting. +- PDC item table of contents, enabled by setting. ## Version [3.12.2] (2024-08-19) diff --git a/config/api.php b/config/api.php index cfa3d17..8f5fb0d 100644 --- a/config/api.php +++ b/config/api.php @@ -29,7 +29,8 @@ 'escape_element' => OWC\PDC\Base\RestAPI\ItemFields\EscapeElementField::class, 'seopress' => OWC\PDC\Base\RestAPI\ItemFields\SeoPress::class, 'yoast' => OWC\PDC\Base\RestAPI\ItemFields\Yoast::class, - 'hide_feedback_form' => OWC\PDC\Base\RestAPI\SharedFields\HideFeedbackForm::class + 'hide_feedback_form' => OWC\PDC\Base\RestAPI\SharedFields\HideFeedbackForm::class, + 'table_of_contents_is_active' => OWC\PDC\Base\RestAPI\ItemFields\TableOfContentsField::class ], ], 'subthema' => [ diff --git a/config/settings.php b/config/settings.php index 08b5170..2afc038 100644 --- a/config/settings.php +++ b/config/settings.php @@ -87,6 +87,12 @@ 'desc' => __('Enable theme tiles.', 'pdc-base'), 'id' => 'setting_pdc_use_theme_tiles', 'type' => 'checkbox', + ], + 'pdc_use_table_of_contents' => [ + 'name' => __('Table of contents', 'pdc-base'), + 'desc' => __('Enable use of table of contents.', 'pdc-base'), + 'id' => 'setting_pdc_use_table_of_contents', + 'type' => 'checkbox', ], 'upl_heading' => [ 'type' => 'heading', diff --git a/config/table_of_contents_metabox.php b/config/table_of_contents_metabox.php new file mode 100644 index 0000000..5dcb482 --- /dev/null +++ b/config/table_of_contents_metabox.php @@ -0,0 +1,22 @@ + [ + 'id' => 'table_of_contents', + 'title' => __('Table of contents', 'pdc-base'), + 'post_types' => ['pdc-item'], + 'context' => 'normal', + 'priority' => 'high', + 'autosave' => true, + 'fields' => [ + 'table_of_contents' => [ + [ + 'name' => __('Table of contents', 'pdc-base'), + 'desc' => __('Use this option if you want to use a table of contents', 'pdc-base'), + 'id' => 'pdc_use_table_of_contents', + 'type' => 'checkbox', + ] + ], + ] + ] +]; diff --git a/languages/pdc-base-nl_NL.mo b/languages/pdc-base-nl_NL.mo index 4e61002..ce20404 100644 Binary files a/languages/pdc-base-nl_NL.mo and b/languages/pdc-base-nl_NL.mo differ diff --git a/languages/pdc-base-nl_NL.po b/languages/pdc-base-nl_NL.po index d88d627..83de626 100644 --- a/languages/pdc-base-nl_NL.po +++ b/languages/pdc-base-nl_NL.po @@ -240,7 +240,7 @@ msgstr "Alternatieve titel" #: config/metaboxes.php:19 msgid "Use this option if you want to use an alternative title" -msgstr "Gebruik deze mogelijkheid als de website een alternatieve titel gebruikt" +msgstr "Gebruik deze optie als de website een alternatieve titel gebruikt" #: config/metaboxes.php:24 msgid "Synonyms" @@ -248,7 +248,7 @@ msgstr "Synoniemen" #: config/metaboxes.php:25 msgid "Use this option to add an comma separated list of synonyms or related terms" -msgstr "Gebruik deze mogelijkheid om een komma gescheiden lijst van synoniemen of gerelateerde termen mee te geven" +msgstr "Gebruik deze optie om een komma gescheiden lijst van synoniemen of gerelateerde termen mee te geven" #: config/metaboxes.php:31 msgid "Is this product active yes/no" @@ -830,18 +830,22 @@ msgstr "Thema tegels" #: config/settings.php:87 msgid "Enable theme tiles." -msgstr "Gebruik thema tegels" +msgstr "Gebruik thema tegels." #: config/settings.php:93 +msgid "Enable use of table of contents." +msgstr "Gebruik inhoudsopgaven." + +#: config/settings.php:99 msgid "The Uniform Product list of names (upl)" msgstr "De Uniforme Productnamenlijst (UPL)" -#: config/settings.php:96 +#: config/settings.php:102 #: config/theme_tiles_metabox.php:27 msgid "URL" msgstr "URL" -#: config/settings.php:97 +#: config/settings.php:103 msgid "URL used for retrieving UPL terms." msgstr "URL om de UPL termen op te halen." @@ -965,10 +969,19 @@ msgstr "Tegels" msgid "Add new tile" msgstr "Voeg nieuwe tegel toe" -#: config/theme_tiles_metabox.php: +#: config/theme_tiles_metabox.php:22 msgid "Title" msgstr "Titel" +#: config/table_of_contents_metabox.php:6 +#: config/table_of_contents_metabox.php:14 +msgid "Table of contents" +msgstr "Inhoudsopgave" + +#: config/table_of_contents_metabox.php:15 +msgid "Use this option if you want to use a table of contents" +msgstr "Gebruik deze optie als er een inhoudsopgave getoond moet worden op de website" + #: src/Base/Foundation/DependencyChecker.php:70 msgid "The following plugins are required to use the PDC:" msgstr "De volgende plugins zijn vereist om gebruik te maken van de PDC:" diff --git a/languages/pdc-base.pot b/languages/pdc-base.pot index 502d127..75f4e58 100644 --- a/languages/pdc-base.pot +++ b/languages/pdc-base.pot @@ -862,15 +862,19 @@ msgid "Enable theme tiles." msgstr "" #: config/settings.php:93 +msgid "Enable use of table of contents." +msgstr "" + +#: config/settings.php:99 msgid "The Uniform Product list of names (upl)" msgstr "" -#: config/settings.php:96 +#: config/settings.php:102 #: config/theme_tiles_metabox.php:27 msgid "URL" msgstr "" -#: config/settings.php:97 +#: config/settings.php:103 msgid "URL used for retrieving UPL terms." msgstr "" @@ -996,10 +1000,20 @@ msgstr "" msgid "Add new tile" msgstr "" -#: config/theme_tiles_metabox.php: +#: config/theme_tiles_metabox.php:22 msgid "Title" msgstr "" +#: config/settings.php:92 +#: config/table_of_contents_metabox.php:6 +#: config/table_of_contents_metabox.php:14 +msgid "Table of contents" +msgstr "" + +#: config/table_of_contents_metabox.php:15 +msgid "Use this option if you want to use a table of contents" +msgstr "" + #: src/Base/Foundation/DependencyChecker.php:70 msgid "The following plugins are required to use the PDC:" msgstr "" diff --git a/src/Base/Metabox/MetaboxServiceProvider.php b/src/Base/Metabox/MetaboxServiceProvider.php index 1ab49dc..7e668ed 100644 --- a/src/Base/Metabox/MetaboxServiceProvider.php +++ b/src/Base/Metabox/MetaboxServiceProvider.php @@ -45,6 +45,10 @@ public function registerMetaboxes(array $rwmbMetaboxes): array $configMetaboxes = $this->getTilesMetabox($configMetaboxes); } + if ($this->plugin->settings->useTableOfContents()) { + $configMetaboxes = $this->getTableOfContentsMetabox($configMetaboxes); + } + if ($this->plugin->settings->useFeedbackForm()) { $configMetaboxes = $this->getFeedbackFormMetabox($configMetaboxes); } @@ -87,6 +91,11 @@ protected function getTilesMetabox(array $configMetaboxes): array return array_merge($configMetaboxes, $this->plugin->config->get('theme_tiles_metabox')); } + protected function getTableOfContentsMetabox(array $configMetaboxes): array + { + return array_merge($configMetaboxes, $this->plugin->config->get('table_of_contents_metabox')); + } + protected function getFeedbackFormMetabox(array $configMetaboxes): array { $feedbackFormMetabox = $this->plugin->config->get('hide_feedback_form_metabox'); diff --git a/src/Base/Models/Item.php b/src/Base/Models/Item.php index 633f495..918fd46 100644 --- a/src/Base/Models/Item.php +++ b/src/Base/Models/Item.php @@ -252,7 +252,16 @@ public function getMeta(string $value, $default = '', $single = true, $prefix = public function getEscapeElement(): bool { - return $this->getMeta('escape_element_active', '0', true, '_owc_'); + $value = $this->getMeta('escape_element_active', '0', true, '_owc_'); + + return boolval($value); + } + + public function useTableOfContents(): bool + { + $value = $this->getMeta('pdc_use_table_of_contents', '0', true, '_owc_'); + + return boolval($value); } /** diff --git a/src/Base/RestAPI/ItemFields/TableOfContentsField.php b/src/Base/RestAPI/ItemFields/TableOfContentsField.php new file mode 100644 index 0000000..671d89c --- /dev/null +++ b/src/Base/RestAPI/ItemFields/TableOfContentsField.php @@ -0,0 +1,30 @@ +plugin->settings->useTableOfContents(); + }; + } + + public function create(WP_Post $post): bool + { + $itemModel = new Item($post->to_array()); + + return $itemModel->useTableOfContents(); + } +} diff --git a/src/Base/Settings/SettingsPageOptions.php b/src/Base/Settings/SettingsPageOptions.php index a7ee29e..9f0c818 100644 --- a/src/Base/Settings/SettingsPageOptions.php +++ b/src/Base/Settings/SettingsPageOptions.php @@ -127,6 +127,13 @@ public function useThemeTiles(): bool return boolval($setting); } + public function useTableOfContents(): bool + { + $setting = $this->settings['_owc_setting_pdc_use_table_of_contents'] ?? false; + + return boolval($setting); + } + /** * URL used for retrieving UPL terms. */ @@ -150,7 +157,8 @@ public static function make(): self '_owc_setting_pdc_enable_show_on' => 0, '_owc_setting_pdc_use_feedback_form' => 0, '_owc_upl_terms_url' => '', - '_owc_setting_pdc_use_theme_tiles' => 0 + '_owc_setting_pdc_use_theme_tiles' => 0, + '_owc_setting_pdc_use_table_of_contents' => 0, ]; return new static(wp_parse_args(get_option('_owc_pdc_base_settings'), $defaultSettings));