PluginProbe
SimpleTOC – Table of Contents Block / 7.3.1
SimpleTOC – Table of Contents Block v7.3.1
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 5.0.31 5.0.32 All 160 releases
← All changes | plugin.php +23 -28 7.1.17.3.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.1.1
6 + * Version: 7.3.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.1.1';
24 +const SIMPLETOC_VERSION = '7.3.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.
@@ -244,21 +244,26 @@
244 244 function render_callback_simpletoc( $attributes ) {
245 245 $is_backend = defined( 'REST_REQUEST' ) && REST_REQUEST && 'edit' === filter_input( INPUT_GET, 'context' );
246 246 $title_text = $attributes['title_text'] ? esc_html( trim( $attributes['title_text'] ) ) : __( 'Table of Contents', 'simpletoc' );
247 247 $alignclass = ! empty( $attributes['align'] ) ? 'align' . $attributes['align'] : '';
248 - $class_name = ! empty( $attributes['className'] ) ? wp_strip_all_tags( $attributes['className'] ) : '';
249 248 $title_level = $attributes['title_level'];
250 249 $global_box_style_enabled = apply_filters( 'simpletoc_box_style_enabled', false ) || true === (bool) get_option( 'simpletoc_box_style_enabled', false );
251 - $box_style_enabled = $global_box_style_enabled || ! empty( $attributes['box_style'] );
250 + $legacy_box_style_enabled = ! empty( $attributes['box_style'] );
251 + $typography_enabled = ! empty( $attributes['fontSize'] ) || ! empty( $attributes['style']['typography'] );
252 252 $wrapper_classes = array( 'simpletoc' );
253 253 $wrapper_style = '';
254 254
255 - if ( $box_style_enabled ) {
255 + if ( $typography_enabled ) {
256 + $wrapper_classes[] = 'has-simpletoc-typography';
257 + }
258 +
259 + if ( $global_box_style_enabled || $legacy_box_style_enabled ) {
260 + $wrapper_classes[] = 'is-style-boxed';
256 261 $wrapper_classes[] = 'has-simpletoc-box-style';
257 262
258 263 if ( $global_box_style_enabled ) {
259 264 $wrapper_classes[] = 'has-background';
260 - $wrapper_style = safecss_filter_attr( 'background-color:' . DEFAULT_BOX_COLOR . ';' );
265 + $wrapper_style = safecss_filter_attr( 'background-color:' . DEFAULT_BOX_COLOR . ';' );
261 266 } elseif ( ! empty( $attributes['box_color'] ) ) {
262 267 $wrapper_classes[] = 'has-background';
263 268 $wrapper_style = safecss_filter_attr( 'background-color:' . $attributes['box_color'] . ';' );
264 269 } else {
@@ -266,9 +271,8 @@
266 271 $wrapper_style = safecss_filter_attr( 'background-color:' . DEFAULT_BOX_COLOR . ';' );
267 272 }
268 273 }
269 274
270 - $wrapper_enabled = apply_filters( 'simpletoc_wrapper_enabled', false ) || true === (bool) get_option( 'simpletoc_wrapper_enabled', false ) || true === (bool) get_option( 'simpletoc_accordion_enabled', false );
271 275 $wrapper_attrs = get_block_wrapper_attributes(
272 276 array(
273 277 'class' => implode( ' ', $wrapper_classes ),
274 278 'style' => $wrapper_style,
@@ -273,11 +277,10 @@
273 277 'class' => implode( ' ', $wrapper_classes ),
274 278 'style' => $wrapper_style,
275 279 )
276 280 );
277 - $has_wrapper = ! empty( $class_name ) || $wrapper_enabled || $attributes['accordion'] || $attributes['wrapper'] || $box_style_enabled;
278 - $pre_html = $has_wrapper ? '<div role="navigation" aria-label="' . esc_attr__( 'Table of Contents', 'simpletoc' ) . '" ' . $wrapper_attrs . '>' : '';
279 - $post_html = $has_wrapper ? '</div>' : '';
281 + $pre_html = '<div role="navigation" aria-label="' . esc_attr__( 'Table of Contents', 'simpletoc' ) . '" ' . $wrapper_attrs . '>';
282 + $post_html = '</div>';
280 283
281 284 $post = get_post();
282 285 $blocks = ! is_null( $post ) && ! is_null( $post->post_content ) ? parse_blocks( $post->post_content ) : '';
283 286
@@ -286,17 +289,17 @@
286 289 $headings_clean = array_map( 'trim', $headings );
287 290 $toc_html = generate_toc( $headings_clean, $attributes );
288 291
289 292 if ( empty( $blocks ) ) {
290 - return get_empty_blocks_message( $is_backend, $attributes, $title_level, $alignclass, $title_text, __( 'No blocks found.', 'simpletoc' ), __( 'Save or update post first.', 'simpletoc' ), $wrapper_attrs, $has_wrapper );
293 + return get_empty_blocks_message( $is_backend, $attributes, $title_level, $alignclass, $title_text, __( 'No blocks found.', 'simpletoc' ), __( 'Save or update post first.', 'simpletoc' ), $wrapper_attrs );
291 294 }
292 295
293 296 if ( empty( $headings_clean ) ) {
294 - return get_empty_blocks_message( $is_backend, $attributes, $title_level, $alignclass, $title_text, __( 'No headings found.', 'simpletoc' ), __( 'Save or update post first.', 'simpletoc' ), $wrapper_attrs, $has_wrapper );
297 + return get_empty_blocks_message( $is_backend, $attributes, $title_level, $alignclass, $title_text, __( 'No headings found.', 'simpletoc' ), __( 'Save or update post first.', 'simpletoc' ), $wrapper_attrs );
295 298 }
296 299
297 300 if ( empty( $toc_html ) ) {
298 - return get_empty_blocks_message( $is_backend, $attributes, $title_level, $alignclass, $title_text, __( 'No headings found.', 'simpletoc' ), __( 'Check minimal and maximum level block settings.', 'simpletoc' ), $wrapper_attrs, $has_wrapper );
301 + return get_empty_blocks_message( $is_backend, $attributes, $title_level, $alignclass, $title_text, __( 'No headings found.', 'simpletoc' ), __( 'Check minimal and maximum level block settings.', 'simpletoc' ), $wrapper_attrs );
299 302 }
300 303
301 304 return $pre_html . $toc_html . $post_html;
302 305 }
@@ -310,27 +313,20 @@
310 313 * @param string $alignclass The CSS class for alignment of the Table of Contents block.
311 314 * @param string $title_text The text for the Table of Contents title.
312 315 * @param string $warning_text1 The first part of the warning message to be displayed.
313 316 * @param string $warning_text2 The second part of the warning message to be displayed.
314 - * @param string $wrapper_attrs Wrapper attributes for the optional block wrapper.
315 - * @param bool $has_wrapper Indicates if the wrapper should be rendered.
317 + * @param string $wrapper_attrs Block wrapper attributes.
316 318 *
317 319 * @return string The HTML output for the empty blocks message.
318 320 */
319 -function get_empty_blocks_message( $is_backend, $attributes, $title_level, $alignclass, $title_text, $warning_text1, $warning_text2, $wrapper_attrs = '', $has_wrapper = false ) {
321 +function get_empty_blocks_message( $is_backend, $attributes, $title_level, $alignclass, $title_text, $warning_text1, $warning_text2, $wrapper_attrs = '' ) {
320 322 $html = '';
321 323
322 324 if ( $is_backend ) {
323 - if ( $has_wrapper ) {
324 - $html .= '<div role="navigation" aria-label="' . esc_attr__( 'Table of Contents', 'simpletoc' ) . '" ' . $wrapper_attrs . '>';
325 - }
326 -
325 + $html .= '<div role="navigation" aria-label="' . esc_attr__( 'Table of Contents', 'simpletoc' ) . '" ' . $wrapper_attrs . '>';
327 326 $html .= sprintf( '<h%d class="%s">%s</h%d>', $title_level, esc_attr( trim( 'simpletoc-title ' . $alignclass ) ), $title_text, $title_level );
328 327 $html .= sprintf( '<p class="components-notice is-warning %s">%s %s</p>', esc_attr( $alignclass ), esc_html( $warning_text1 ), esc_html( $warning_text2 ) );
329 -
330 - if ( $has_wrapper ) {
331 - $html .= '</div>';
332 - }
328 + $html .= '</div>';
333 329 }
334 330
335 331 return $html;
336 332 }
@@ -479,12 +475,11 @@
479 475 $html_wo_nbs = str_replace( '&nbsp;', ' ', $zero_punctuation );
480 476 // remove umlauts and accents.
481 477 $string_without_accents = remove_accents( $html_wo_nbs );
482 478 // Sanitizes a title, replacing whitespace and a few other characters with dashes.
483 - $sanitized_string = sanitize_title_with_dashes( $string_without_accents );
484 - // Encode for use in an url.
485 - $urlencoded = rawurlencode( $sanitized_string );
486 - return $urlencoded;
479 + // Already returns a URL-safe, percent-encoded slug for non-ASCII input, so no
480 + // further rawurlencode() is needed (that would double-encode the string).
481 + return sanitize_title_with_dashes( $string_without_accents );
487 482 }
488 483
489 484 /**
490 485 * Add additional plugin meta links to the SimpleTOC plugin page.