PluginProbe
SimpleTOC – Table of Contents Block / 7.4.1
SimpleTOC – Table of Contents Block v7.4.1
7.4.1 7.4.0 7.3.1 7.2.0 7.3.0 7.1.1 7.1.0 7.0.10 7.0.9 7.0.8 7.0.7 7.0.6 7.0.4 7.0.5 5.0.21.1 5.0.22 5.0.23 5.0.24 5.0.25 5.0.25.1 5.0.27 5.0.28 5.0.29 5.0.3 5.0.30 All 162 releases
← All changes | plugin.php +38 -11 7.2.0 → 7.4.1 View file →
@@ -2,9 +2,9 @@
2 2 /**
3 3 * Plugin Name: SimpleTOC - Table of Contents Block
4 4 * Plugin URI: https://marc.tv/simpletoc-wordpress-inhaltsverzeichnis-plugin-gutenberg/
5 5 * Description: SEO-friendly Table of Contents Gutenberg block. No JavaScript or CSS by default.
6 - * Version: 7.2.0
6 + * Version: 7.4.1
7 7 * Requires at least: 6.2
8 8 * Requires PHP: 7.3
9 9 * Author: Marc Tönsing
10 10 * Author URI: https://toensing.com
@@ -20,9 +20,9 @@
20 20 require_once __DIR__ . '/simpletoc-admin-settings.php';
21 21 require_once __DIR__ . '/simpletoc-class-headline-ids.php';
22 22
23 23 const DEFAULT_BOX_COLOR = '#ebebeb';
24 -const SIMPLETOC_VERSION = '7.2.0';
24 +const SIMPLETOC_VERSION = '7.4.1';
25 25
26 26 /**
27 27 * Prevents direct execution of the plugin file.
28 28 * If a WordPress function does not exist, it means that the file has not been run by WordPress.
@@ -57,9 +57,10 @@
57 57 wp_add_inline_script(
58 58 'simpletoc-toc-editor-script',
59 59 'window.simpletocEditorSettings = ' . wp_json_encode(
60 60 array(
61 - 'settingsUrl' => admin_url( 'options-general.php?page=simpletoc' ),
61 + 'settingsUrl' => admin_url( 'options-general.php?page=simpletoc' ),
62 + 'scrollSpyEnabled' => simpletoc_scroll_spy_enabled(),
62 63 )
63 64 ) . ';',
64 65 'before'
65 66 );
@@ -77,8 +78,10 @@
77 78 */
78 79 function add_simpletoc_block_editor_settings( $editor_settings, $editor_context ) {
79 80 $editor_settings['simpletocSettingsUrl'] = admin_url( 'options-general.php?page=simpletoc' );
80 81
82 + $editor_settings['simpletocScrollSpyEnabled'] = simpletoc_scroll_spy_enabled();
83 +
81 84 return $editor_settings;
82 85 }
83 86
84 87 add_filter( 'block_editor_settings_all', __NAMESPACE__ . '\add_simpletoc_block_editor_settings', 10, 2 );
@@ -221,9 +224,15 @@
221 224 // Need two separate instances so that IDs aren't double counted.
222 225 $inner_html_id_instance = new SimpleTOC_Headline_Ids();
223 226 $inner_content_id_instance = new SimpleTOC_Headline_Ids();
224 227
228 + $ignored_blocks = simpletoc_get_excluded_blocks();
229 +
225 230 foreach ( $blocks as &$block ) {
231 + if ( isset( $block['blockName'] ) && in_array( $block['blockName'], $ignored_blocks, true ) ) {
232 + continue;
233 + }
234 +
226 235 if ( isset( $block['blockName'] ) && in_array( $block['blockName'], $supported_blocks, true ) && isset( $block['innerHTML'] ) && isset( $block['innerContent'] ) && isset( $block['innerContent'][0] ) ) {
227 236 $block['innerHTML'] = add_anchor_attribute( $block['innerHTML'], $inner_html_id_instance, $block );
228 237 $block['innerContent'][0] = add_anchor_attribute( $block['innerContent'][0], $inner_content_id_instance, $block );
229 238 } elseif ( ! empty( $block['innerBlocks'] ) ) {
@@ -246,23 +255,28 @@
246 255 $title_text = $attributes['title_text'] ? esc_html( trim( $attributes['title_text'] ) ) : __( 'Table of Contents', 'simpletoc' );
247 256 $alignclass = ! empty( $attributes['align'] ) ? 'align' . $attributes['align'] : '';
248 257 $title_level = $attributes['title_level'];
249 258 $global_box_style_enabled = apply_filters( 'simpletoc_box_style_enabled', false ) || true === (bool) get_option( 'simpletoc_box_style_enabled', false );
250 - $box_style_enabled = $global_box_style_enabled || ! empty( $attributes['box_style'] );
259 + $legacy_box_style_enabled = ! empty( $attributes['box_style'] );
251 260 $typography_enabled = ! empty( $attributes['fontSize'] ) || ! empty( $attributes['style']['typography'] );
252 261 $wrapper_classes = array( 'simpletoc' );
253 262 $wrapper_style = '';
254 263
264 + if ( simpletoc_scroll_spy_enabled() || ! empty( $attributes['scroll_spy'] ) ) {
265 + $wrapper_classes[] = 'has-simpletoc-scroll-spy';
266 + }
267 +
255 268 if ( $typography_enabled ) {
256 269 $wrapper_classes[] = 'has-simpletoc-typography';
257 270 }
258 271
259 - if ( $box_style_enabled ) {
272 + if ( $global_box_style_enabled || $legacy_box_style_enabled ) {
273 + $wrapper_classes[] = 'is-style-boxed';
260 274 $wrapper_classes[] = 'has-simpletoc-box-style';
261 275
262 276 if ( $global_box_style_enabled ) {
263 277 $wrapper_classes[] = 'has-background';
264 - $wrapper_style = safecss_filter_attr( 'background-color:' . DEFAULT_BOX_COLOR . ';' );
278 + $wrapper_style = safecss_filter_attr( 'background-color:' . DEFAULT_BOX_COLOR . ';' );
265 279 } elseif ( ! empty( $attributes['box_color'] ) ) {
266 280 $wrapper_classes[] = 'has-background';
267 281 $wrapper_style = safecss_filter_attr( 'background-color:' . $attributes['box_color'] . ';' );
268 282 } else {
@@ -362,8 +376,22 @@
362 376 return $headings;
363 377 }
364 378
365 379 /**
380 + * Gets blocks excluded from both anchor generation and TOC collection.
381 + *
382 + * Query templates render repeatedly in a different post context.
383 + *
384 + * @return string[] Excluded block names.
385 + */
386 +function simpletoc_get_excluded_blocks() {
387 + return apply_filters(
388 + 'simpletoc_excluded_blocks',
389 + array( 'core/query', 'generateblocks/query-loop', 'generateblocks/query' )
390 + );
391 +}
392 +
393 +/**
366 394 * Return all headings with a recursive walk through all blocks.
367 395 * This includes groups and reusable block with groups within reusable blocks.
368 396 *
369 397 * @param array[] $blocks The blocks to filter headings from.
@@ -376,9 +404,9 @@
376 404 return $arr;
377 405 }
378 406
379 407 // allow developers to ignore specific blocks.
380 - $ignored_blocks = apply_filters( 'simpletoc_excluded_blocks', array() );
408 + $ignored_blocks = simpletoc_get_excluded_blocks();
381 409
382 410 foreach ( $blocks as $inner_block ) {
383 411 if ( is_array( $inner_block ) ) {
384 412 // if block is ignored, skip.
@@ -474,12 +502,11 @@
474 502 $html_wo_nbs = str_replace( ' ', ' ', $zero_punctuation );
475 503 // remove umlauts and accents.
476 504 $string_without_accents = remove_accents( $html_wo_nbs );
477 505 // Sanitizes a title, replacing whitespace and a few other characters with dashes.
478 - $sanitized_string = sanitize_title_with_dashes( $string_without_accents );
479 - // Encode for use in an url.
480 - $urlencoded = rawurlencode( $sanitized_string );
481 - return $urlencoded;
506 + // Already returns a URL-safe, percent-encoded slug for non-ASCII input, so no
507 + // further rawurlencode() is needed (that would double-encode the string).
508 + return sanitize_title_with_dashes( $string_without_accents );
482 509 }
483 510
484 511 /**
485 512 * Add additional plugin meta links to the SimpleTOC plugin page.