From 314b5b8166f4b40b95f90de974dfd3a50b5075d6 Mon Sep 17 00:00:00 2001 From: Mike van den Hoek Date: Mon, 30 Sep 2024 11:24:12 +0200 Subject: [PATCH] (feat): PDC item table of contents, enabled by setting --- CHANGELOG.md | 1 + config/api.php | 3 +- config/settings.php | 6 ++++ config/table_of_contents_metabox.php | 22 +++++++++++++ languages/pdc-base-nl_NL.mo | Bin 18416 -> 18673 bytes languages/pdc-base-nl_NL.po | 25 +++++++++++---- languages/pdc-base.pot | 20 ++++++++++-- src/Base/Metabox/MetaboxServiceProvider.php | 9 ++++++ src/Base/Models/Item.php | 11 ++++++- .../ItemFields/TableOfContentsField.php | 30 ++++++++++++++++++ src/Base/Settings/SettingsPageOptions.php | 10 +++++- 11 files changed, 125 insertions(+), 12 deletions(-) create mode 100644 config/table_of_contents_metabox.php create mode 100644 src/Base/RestAPI/ItemFields/TableOfContentsField.php 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 4e61002619dbd33ff2b3125019e5927ac704d3ac..ce20404ce0abfe79e72c8a2bc356e94765162fb6 100644 GIT binary patch delta 5490 zcmZYC3w(~(0mt!!B*Zn6APGrccZqw%CF+t%#7Nz$sk%*tS6q`c7Zly&QgtguC{Z?( zt|P{DF_&qzXkCjY-KJX7*5)#sHd!|C( z*r|HLcBrN5hs>rKW!q4c|m9Z3Qw3ra`28zZlIwWiycvb^JWG!WV6Q4{8Pu zpl0ASY6i;CgCC)$_TQ*Au17E0%u%SNYH#ZasPiedeKc05?sX`rgK5Y;%mUOC6(WN* z`%oR6M-P6A>_^`Y)AeEOG+o~VHLz6cNbFC2w5@NpZbvOi5$e89F$E3am~ALUt?3P0 ze~8+IK_0iG2-Hk;M%|z{YVC)iW-uGo{v7IiYf$&!jGCEZ)Dj#*R?{)16ts4CQ5OVo zH$7np`lb*ypaj$nN1&c~ENUQGs1E1b`dZXf7os{YM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2U-Dmk_hi$}=}@>?>UcuNeGKa-W@ zIr0waNpy;SM^uVk_>=Mb{@8HO@B-S^q!XD&s))Bl*vfa<(c6jjgjdT`bWEekY`1B6 zB|PtU zl0yDU%E=`16$vEUz5D+d4R0AkC6p{DXUTD*@*(jj?~+Qghz`pE8ASp}lKx(KkBUlaNljRUbBbDf(wHnIH%J^=OYSdMZKKvY4--fYIYCYm zmHA|_r{?}3ZnO0_FvQkHF!_!574xMrQoWR2E@mHoOd4!kC+E|O;_&AKD&pI`-lU=? ww#dJtC?P+nqIpty(~9Ku#DJh_({pq3CQq3getTilesMetabox($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));