Changeset 3017293
- Timestamp:
- 01/04/2024 07:34:27 AM (2 years ago)
- Location:
- footnotes-made-easy/trunk
- Files:
-
- 5 edited
-
assets/icon.svg (modified) (1 diff)
-
classes/controllers/class-footnotes-formatter.php (modified) (9 diffs)
-
classes/controllers/class-integrations.php (modified) (2 diffs)
-
footnotes-made-easy.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
footnotes-made-easy/trunk/assets/icon.svg
r3007350 r3017293 1 1 <?xml version="1.0" encoding="iso-8859-1"?> 2 2 <!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --> 3 <svg fill=" #000000" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"3 <svg fill="currentColor" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 4 4 viewBox="0 0 512.001 512.001" xml:space="preserve"> 5 5 <g> -
footnotes-made-easy/trunk/classes/controllers/class-footnotes-formatter.php
r3016308 r3017293 74 74 * 75 75 * @param array - The array with the hooks to be applied for the processing. 76 * 77 * @since 2.4.1 76 78 */ 77 79 $process_hooks = \apply_filters( 'fme_process_content_hooks', array( 'the_content' ) ); … … 83 85 ); 84 86 85 add_action( 'wp_head', array( __CLASS__, 'insert_styles' ) );86 87 add_shortcode( self::SHORTCODE_NAME, array( __CLASS__, 'show_footnotes' ) );87 \add_action( 'wp_head', array( __CLASS__, 'insert_styles' ) ); 88 89 \add_shortcode( self::SHORTCODE_NAME, array( __CLASS__, 'show_footnotes' ) ); 88 90 89 91 if ( Settings::get_current_options()['pretty_tooltips'] ) { 90 add_action( 'init', array( __CLASS__, 'register_script' ) );91 add_action( 'wp_footer', array( __CLASS__, 'print_script' ) );92 \add_action( 'init', array( __CLASS__, 'register_script' ) ); 93 \add_action( 'wp_footer', array( __CLASS__, 'print_script' ) ); 92 94 } 93 95 } … … 303 305 // } 304 306 307 $processed_data = self::get_footnotes( $data, $post->ID ); 308 309 $footnotes = $processed_data['footnotes']; 310 $identifiers = $processed_data['identifiers']; 311 312 $style = self::get_style( $post ); 313 314 // Footnotes and identifiers are stored in the array. 315 316 $use_full_link = false; 317 if ( is_feed() ) { 318 $use_full_link = true; 319 } 320 321 if ( is_preview() ) { 322 $use_full_link = false; 323 } 324 325 // Display identifiers. 326 327 foreach ( $identifiers as $key => $identifier ) { 328 329 $id_id = 'identifier_' . $key . '_' . $post->ID; 330 $id_num = ( 'decimal' === $style ) ? $identifier['use_footnote'] + $start_number : self::convert_num( $identifier['use_footnote'] + $start_number, $style, count( $footnotes ) ); 331 $id_href = ( ( $use_full_link ) ? get_permalink( $post->ID ) : '' ) . '#footnote_' . $identifier['use_footnote'] . '_' . $post->ID; 332 $id_title = str_replace( '"', '"', htmlentities( html_entity_decode( wp_strip_all_tags( $identifier['text'] ), ENT_QUOTES, 'UTF-8' ), ENT_QUOTES, 'UTF-8' ) ); 333 $id_replace = Settings::get_current_options()['pre_identifier'] . '<a href="' . $id_href . '" id="' . $id_id . '" class="footnote-link footnote-identifier-link" title="' . $id_title . '">' . Settings::get_current_options()['inner_pre_identifier'] . $id_num . Settings::get_current_options()['inner_post_identifier'] . '</a>' . Settings::get_current_options()['post_identifier']; 334 if ( Settings::get_current_options()['superscript'] ) { 335 $id_replace = '<sup>' . $id_replace . '</sup>'; 336 } 337 338 $pos = strpos( $data, self::TEXT_MARKER_PREFIX . $identifier['original_position'] ); 339 if ( false !== $pos ) { 340 $data = substr_replace( $data, $id_replace, $pos, strlen( self::TEXT_MARKER_PREFIX . $identifier['original_position'] ) ); 341 } 342 } 343 344 // Is there a shortcode present in the content? 345 if ( false !== \mb_strpos( $data, self::SHORT_CODE_POSITION_HOLDER ) ) { 346 // Yes. 347 $display = false; 348 $shortcode_replace = true; 349 } 350 351 if ( Settings::get_current_options()['no_display_post'] ) { 352 $display = false; 353 } 354 355 // Display footnotes. 356 if ( $display ) { 357 358 $data .= self::get_footnotes_markup(); 359 } elseif ( $shortcode_replace ) { 360 $data = \str_replace( self::SHORT_CODE_POSITION_HOLDER, self::get_footnotes_markup(), $data ); 361 } 362 363 return $data; 364 } 365 366 /** 367 * Builds the footnotes array 368 * 369 * @param string $data - The raw text. 370 * @param integer $post_id - The ID of the post. 371 * 372 * @return array 373 * 374 * @since 2.4.2 375 */ 376 private static function get_footnotes( string $data, int $post_id ): array { 377 305 378 $footnotes = array(); 306 379 307 $ style = self::get_style( $post);380 $identifiers = self::extract_current_notes( $data, $post_id ); 308 381 309 382 // Create 'em. … … 363 436 } 364 437 365 // Footnotes and identifiers are stored in the array. 366 367 $use_full_link = false; 368 if ( is_feed() ) { 369 $use_full_link = true; 370 } 371 372 if ( is_preview() ) { 373 $use_full_link = false; 374 } 375 376 // Display identifiers. 377 378 foreach ( $identifiers as $key => $identifier ) { 379 380 $id_id = 'identifier_' . $key . '_' . $post->ID; 381 $id_num = ( 'decimal' === $style ) ? $identifier['use_footnote'] + $start_number : self::convert_num( $identifier['use_footnote'] + $start_number, $style, count( $footnotes ) ); 382 $id_href = ( ( $use_full_link ) ? get_permalink( $post->ID ) : '' ) . '#footnote_' . $identifier['use_footnote'] . '_' . $post->ID; 383 $id_title = str_replace( '"', '"', htmlentities( html_entity_decode( wp_strip_all_tags( $identifier['text'] ), ENT_QUOTES, 'UTF-8' ), ENT_QUOTES, 'UTF-8' ) ); 384 $id_replace = Settings::get_current_options()['pre_identifier'] . '<a href="' . $id_href . '" id="' . $id_id . '" class="footnote-link footnote-identifier-link" title="' . $id_title . '">' . Settings::get_current_options()['inner_pre_identifier'] . $id_num . Settings::get_current_options()['inner_post_identifier'] . '</a>' . Settings::get_current_options()['post_identifier']; 385 if ( Settings::get_current_options()['superscript'] ) { 386 $id_replace = '<sup>' . $id_replace . '</sup>'; 387 } 388 389 $pos = strpos( $data, self::TEXT_MARKER_PREFIX . $identifier['original_position'] ); 390 if ( false !== $pos ) { 391 $data = substr_replace( $data, $id_replace, $pos, strlen( self::TEXT_MARKER_PREFIX . $identifier['original_position'] ) ); 392 } 393 } 394 395 // Is there a shortcode present in the content? 396 if ( false !== \mb_strpos( $data, self::SHORT_CODE_POSITION_HOLDER ) ) { 397 // Yes. 398 $display = false; 399 $shortcode_replace = true; 400 } 401 402 if ( Settings::get_current_options()['no_display_post'] ) { 403 $display = false; 404 } 405 406 // Display footnotes. 407 if ( $display ) { 408 409 $data .= self::get_footnotes_markup(); 410 } elseif ( $shortcode_replace ) { 411 $data = \str_replace( self::SHORT_CODE_POSITION_HOLDER, self::get_footnotes_markup(), $data ); 412 } 413 414 return $data; 438 return ['footnotes'=>$footnotes,'identifiers'=>$identifiers]; 415 439 } 416 440 … … 425 449 */ 426 450 private static function get_footnotes_markup( \WP_Post $post = null ): string { 427 428 $use_full_link = true;429 430 451 // check against post existing before processing. 431 452 if ( ! $post ) { … … 437 458 } 438 459 439 $footnotes = array();440 441 460 $style = self::get_style( $post ); 442 461 462 $use_full_link = true; 463 443 464 $data = \get_the_content( null, false, $post ); 444 465 445 466 $start_number = ( 1 === preg_match( '|<!\-\-startnum=(\d+)\-\->|', $data, $start_number_array ) ) ? $start_number_array[1] : 1; 446 467 447 $identifiers = self::extract_current_notes( $data, $post->ID ); 448 449 // Create 'em. 450 $identifiers_count = count( $identifiers ); 451 for ( $i = 0; $i < $identifiers_count; $i++ ) { 452 453 // Look for ref: and replace in identifiers array. 454 if ( 'ref:' === substr( $identifiers[ $i ]['raw_text'], 0, 4 ) ) { 455 $ref = (int) substr( $identifiers[ $i ]['raw_text'], 4 ); 456 457 if ( isset( $identifiers[ $ref - 1 ] ) && isset( $identifiers[ $ref - 1 ]['text'] ) ) { 458 $identifiers[ $i ]['text'] = $identifiers[ $ref - 1 ]['text']; 459 } else { 460 // In that case referred is not yet populated, lets mark it and assign it later. 461 $identifiers[ $i ]['refers_to'] = $ref - 1; 462 $identifiers[ $i ]['text'] = ''; 463 } 464 } else { 465 $identifiers[ $i ]['text'] = $identifiers[ $i ]['raw_text']; 466 } 467 } 468 469 // All footnotes are collected, lets fix missing references. 470 foreach ( $identifiers as &$identifier ) { 471 if ( isset( $identifier['refers_to'] ) ) { 472 if ( isset( $identifiers[ $identifier['refers_to'] ] ) && isset( $identifiers[ $identifier['refers_to'] ]['text'] ) ) { 473 $identifier['text'] = $identifiers[ $identifier['refers_to'] ]['text']; 474 unset( $identifier['refers_to'] ); 475 } 476 } 477 } 478 unset( $identifier ); 479 480 for ( $i = 0; $i < $identifiers_count; $i++ ) { 481 // if we're combining identical notes check if we've already got one like this & record keys. 482 483 if ( Settings::get_current_options()['combine_identical_notes'] ) { 484 $footnotes_count = count( $footnotes ); 485 for ( $j = 0; $j < $footnotes_count; $j++ ) { 486 if ( $footnotes[ $j ]['text'] === $identifiers[ $i ]['text'] ) { 487 $identifiers[ $i ]['use_footnote'] = $j; 488 $footnotes[ $j ]['identifiers'][] = $i; 489 break; 490 } 491 } 492 } 493 494 if ( ! isset( $identifiers[ $i ]['use_footnote'] ) ) { 495 496 // Add footnote and record the key. 497 498 $identifiers[ $i ]['use_footnote'] = count( $footnotes ); 499 $footnotes[ $identifiers[ $i ]['use_footnote'] ]['text'] = $identifiers[ $i ]['text']; 500 $footnotes[ $identifiers[ $i ]['use_footnote'] ]['symbol'] = isset( $identifiers[ $i ]['symbol'] ) ? $identifiers[ $i ]['symbol'] : ''; 501 $footnotes[ $identifiers[ $i ]['use_footnote'] ]['identifiers'][] = $i; 502 } 503 } 468 $footnotes = self::get_footnotes( $data, $post->ID )['footnotes']; 504 469 505 470 $footnotes_markup = ''; … … 620 585 621 586 if ( isset( self::$identifiers[ $post_id ] ) ) { 587 foreach ( self::$identifiers[ $post_id ] as $identifier ) { 588 $data = self::replace_identifiers( $data, $identifier['original_text'], $identifier['original_position'] ); 589 } 590 622 591 return self::$identifiers[ $post_id ]; 623 592 } else { … … 635 604 $notes[ $pos ]['original_text'] = Settings::get_current_options()['footnotes_open'] . $notes[ $pos ]['raw_text'] . Settings::get_current_options()['footnotes_close']; 636 605 637 $text_pos = \mb_strpos( $data, $notes[ $pos ]['original_text'] ); 638 if ( false !== $text_pos ) { 639 $data = self::mb_substr_replace( $data, self::TEXT_MARKER_PREFIX . $pos, $text_pos, \mb_strlen( $notes[ $pos ]['original_text'] ) ); 640 } 606 $data = self::replace_identifiers( $data, $notes[ $pos ]['original_text'], $pos ); 641 607 642 608 ++$pos; … … 648 614 649 615 return self::$identifiers[ $post_id ]; 616 } 617 618 /** 619 * Replaces the identifiers in text 620 * 621 * @param string $data - The raw text. 622 * @param string $text - The text to search for and replacing it. 623 * @param integer $pos - The number of the position to put after the footnote mark. 624 * 625 * @return string 626 * 627 * @since 2.4.2 628 */ 629 private static function replace_identifiers( string &$data, string $text, int $pos ): string { 630 631 $text_pos = \mb_strpos( $data, $text ); 632 if ( false !== $text_pos ) { 633 $data = self::mb_substr_replace( $data, self::TEXT_MARKER_PREFIX . $pos, $text_pos, \mb_strlen( $text ) ); 634 } 635 636 return $data; 650 637 } 651 638 -
footnotes-made-easy/trunk/classes/controllers/class-integrations.php
r3015380 r3017293 13 13 14 14 use FME\Helpers\Settings; 15 16 15 17 16 // Exit if accessed directly. … … 88 87 89 88 /** 90 * Add es tge necessary styles to the admin89 * Adds the necessary styles to the admin 91 90 * 92 91 * @return void -
footnotes-made-easy/trunk/footnotes-made-easy.php
r3016317 r3017293 14 14 * Plugin URI: https://github.com/sdobreff/footnotes-made-easy 15 15 * Description: Allows post authors to easily add and manage footnotes in posts. 16 * Version: 2.4. 116 * Version: 2.4.2 17 17 * Author: Footnotes 18 18 * Author URI: https://github.com/sdobreff … … 30 30 } 31 31 32 define( 'FME_VERSION', '2.4. 1' );32 define( 'FME_VERSION', '2.4.2' ); 33 33 define( 'FME_TEXTDOMAIN', 'footnotes-made-easy' ); 34 34 define( 'FME_NAME', 'Footnotes Made Easy' ); -
footnotes-made-easy/trunk/readme.txt
r3016317 r3017293 4 4 Tested up to: 6.4.2 5 5 Requires PHP: 7.4 6 Stable tag: 2.4. 16 Stable tag: 2.4.2 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 115 115 == Change Log == 116 116 117 = 2.4.2 = 118 * Fix: Fixed a WooCommerce bug with showing the notes in the description (thanks to [kmammasis](https://wordpress.org/support/users/kmammasis/) and [pranavmahapatra](https://wordpress.org/support/users/pranavmahapatra/)) 119 117 120 = 2.4.0 = 118 121 * Added shortcode to display the footnotes - `fme_show_footnotes`
Note: See TracChangeset
for help on using the changeset viewer.