Plugin Directory

Changeset 3017293


Ignore:
Timestamp:
01/04/2024 07:34:27 AM (2 years ago)
Author:
sdobreff
Message:

code changes before v.2.4.2

Location:
footnotes-made-easy/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • footnotes-made-easy/trunk/assets/icon.svg

    r3007350 r3017293  
    11<?xml version="1.0" encoding="iso-8859-1"?>
    22<!-- 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"
    44     viewBox="0 0 512.001 512.001" xml:space="preserve">
    55<g>
  • footnotes-made-easy/trunk/classes/controllers/class-footnotes-formatter.php

    r3016308 r3017293  
    7474             *
    7575             * @param array - The array with the hooks to be applied for the processing.
     76             *
     77             * @since 2.4.1
    7678             */
    7779            $process_hooks = \apply_filters( 'fme_process_content_hooks', array( 'the_content' ) );
     
    8385            );
    8486
    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' ) );
    8890
    8991            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' ) );
    9294            }
    9395        }
     
    303305            // }
    304306
     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( '"', '&quot;', 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
    305378            $footnotes = array();
    306379
    307             $style = self::get_style( $post );
     380            $identifiers = self::extract_current_notes( $data, $post_id );
    308381
    309382            // Create 'em.
     
    363436            }
    364437
    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( '"', '&quot;', 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];
    415439        }
    416440
     
    425449         */
    426450        private static function get_footnotes_markup( \WP_Post $post = null ): string {
    427 
    428             $use_full_link = true;
    429 
    430451            // check against post existing before processing.
    431452            if ( ! $post ) {
     
    437458            }
    438459
    439             $footnotes = array();
    440 
    441460            $style = self::get_style( $post );
    442461
     462            $use_full_link = true;
     463
    443464            $data = \get_the_content( null, false, $post );
    444465
    445466            $start_number = ( 1 === preg_match( '|<!\-\-startnum=(\d+)\-\->|', $data, $start_number_array ) ) ? $start_number_array[1] : 1;
    446467
    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'];
    504469
    505470            $footnotes_markup = '';
     
    620585
    621586            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
    622591                return self::$identifiers[ $post_id ];
    623592            } else {
     
    635604                            $notes[ $pos ]['original_text']     = Settings::get_current_options()['footnotes_open'] . $notes[ $pos ]['raw_text'] . Settings::get_current_options()['footnotes_close'];
    636605
    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 );
    641607
    642608                            ++$pos;
     
    648614
    649615            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;
    650637        }
    651638
  • footnotes-made-easy/trunk/classes/controllers/class-integrations.php

    r3015380 r3017293  
    1313
    1414use FME\Helpers\Settings;
    15 
    1615
    1716// Exit if accessed directly.
     
    8887
    8988        /**
    90          * Addes tge necessary styles to the admin
     89         * Adds the necessary styles to the admin
    9190         *
    9291         * @return void
  • footnotes-made-easy/trunk/footnotes-made-easy.php

    r3016317 r3017293  
    1414 * Plugin URI:      https://github.com/sdobreff/footnotes-made-easy
    1515 * Description:     Allows post authors to easily add and manage footnotes in posts.
    16  * Version:         2.4.1
     16 * Version:         2.4.2
    1717 * Author:          Footnotes
    1818 * Author URI:      https://github.com/sdobreff
     
    3030}
    3131
    32 define( 'FME_VERSION', '2.4.1' );
     32define( 'FME_VERSION', '2.4.2' );
    3333define( 'FME_TEXTDOMAIN', 'footnotes-made-easy' );
    3434define( 'FME_NAME', 'Footnotes Made Easy' );
  • footnotes-made-easy/trunk/readme.txt

    r3016317 r3017293  
    44Tested up to: 6.4.2
    55Requires PHP: 7.4
    6 Stable tag: 2.4.1
     6Stable tag: 2.4.2
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    115115== Change Log ==
    116116
     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
    117120= 2.4.0 =
    118121* Added shortcode to display the footnotes - `fme_show_footnotes`
Note: See TracChangeset for help on using the changeset viewer.