| @@ -2,10 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: Easy Footnotes |
| 4 | 4 | * Plugin URI: https://jasonyingling.me/easy-footnotes-wordpress/ |
| 5 | 5 | * Description: Easily add footnotes to your posts with a simple shortcode. |
| 6 | - * Text Domain: easy-footnotes | |
| 7 | - * Version: 1.1.14 | |
| 6 | + * Version: 1.1.1 | |
| 8 | 7 | * Author: Jason Yingling |
| 9 | 8 | * Author URI: https://jasonyingling.me |
| 10 | 9 | * License: GPL2 |
| 11 | 10 | * |
| @@ -41,43 +40,30 @@ | ||
| 41 | 40 | public $footnotes = array(); |
| 42 | 41 | public $footnoteCount = 0; |
| 43 | 42 | public $prevPost; |
| 44 | 43 | public $footnoteOptions; |
| 45 | - public $footnoteLookup = array(); | |
| 46 | - public $usedFootnoteNumbers = array(); | |
| 47 | 44 | |
| 48 | 45 | private $footnoteSettings; |
| 49 | 46 | |
| 50 | - private $version = '1.1.14'; | |
| 51 | - | |
| 52 | 47 | /** |
| 53 | 48 | * Constructing the initial plugin options, shortcodes, and hooks. |
| 54 | 49 | */ |
| 55 | 50 | public function __construct() { |
| 56 | - $this->footnoteSettings = array( | |
| 57 | - 'footnoteLabel' => 'Footnotes', | |
| 51 | + $footnoteSettings = array( | |
| 52 | + 'footnoteLabel' => __( 'Footnotes', 'easy-footnotes' ), | |
| 58 | 53 | 'useLabel' => false, |
| 59 | 54 | 'hide_easy_footnote_after_posts' => false, |
| 60 | 55 | 'show_easy_footnote_on_front' => false, |
| 61 | - 'reset_footnotes' => false, | |
| 62 | - 'combine_duplicate_footnotes' => false, | |
| 63 | 56 | ); |
| 64 | 57 | |
| 65 | 58 | add_option( 'easy_footnotes_options', $this->footnoteSettings ); |
| 66 | 59 | add_shortcode( 'note', array( $this, 'easy_footnote_shortcode' ) ); |
| 67 | 60 | add_shortcode( 'efn_note', array( $this, 'easy_footnote_shortcode' ) ); |
| 68 | - add_shortcode( 'efn_reset', array( $this, 'short_code_reset' ) ); | |
| 69 | 61 | add_filter( 'the_content', array( $this, 'easy_footnote_after_content' ), 20 ); |
| 70 | - | |
| 71 | - $this->footnoteOptions = get_option( 'easy_footnotes_options' ); | |
| 72 | - if ( isset( $this->footnoteOptions['reset_footnotes'] ) && $this->footnoteOptions['reset_footnotes'] || ( ! isset( $this->footnoteOptions[ 'combine_duplicate_footnotes' ] ) || $this->footnoteOptions[ 'combine_duplicate_footnotes' ] === false ) ) { | |
| 73 | - add_filter( 'the_content', array( $this, 'easy_footnote_reset' ), 999 ); | |
| 74 | - } | |
| 75 | - | |
| 62 | + add_filter( 'the_content', array( $this, 'easy_footnote_reset' ), 999 ); | |
| 76 | 63 | add_action( 'wp_enqueue_scripts', array( $this, 'register_qtip_scripts' ) ); |
| 77 | 64 | add_action( 'admin_menu', array( $this, 'easy_footnotes_admin_actions' ) ); |
| 78 | 65 | add_action( 'admin_enqueue_scripts', array( $this, 'easy_footnotes_admin_scripts' ) ); |
| 79 | - add_action( 'init', array($this, 'efn_load_textdomain') ); | |
| 80 | 66 | |
| 81 | 67 | $this->footnoteOptions = get_option( 'easy_footnotes_options' ); |
| 82 | 68 | } |
| 83 | 69 | |
| @@ -84,13 +70,13 @@ | ||
| 84 | 70 | /** |
| 85 | 71 | * Registering the scripts and styles used by jQuery qTip. |
| 86 | 72 | */ |
| 87 | 73 | public function register_qtip_scripts() { |
| 88 | - wp_register_script( 'imagesloaded', plugins_url( '/assets/qtip/imagesloaded.pkgd.min.js', __FILE__ ), array(), $this->version, true ); | |
| 89 | - wp_register_script( 'qtip', plugins_url( '/assets/qtip/jquery.qtip.min.js', __FILE__ ), array( 'jquery', 'imagesloaded' ), $this->version, true ); | |
| 90 | - wp_register_script( 'qtipcall', plugins_url( '/assets/qtip/jquery.qtipcall.js', __FILE__ ), array( 'jquery', 'qtip' ), $this->version, true ); | |
| 91 | - wp_register_style( 'qtipstyles', plugins_url( '/assets/qtip/jquery.qtip.min.css', __FILE__ ), array(), $this->version, false ); | |
| 92 | - wp_register_style( 'easyfootnotescss', plugins_url( '/assets/easy-footnotes.css', __FILE__ ), array(), $this->version, false ); | |
| 74 | + wp_register_script( 'imagesloaded', plugins_url( '/assets/qtip/imagesloaded.pkgd.min.js', __FILE__ ), array(), '3.1.8', true ); | |
| 75 | + wp_register_script( 'qtip', plugins_url( '/assets/qtip/jquery.qtip.min.js', __FILE__ ), array( 'jquery', 'imagesloaded' ), '3.0.3', true ); | |
| 76 | + wp_register_script( 'qtipcall', plugins_url( '/assets/qtip/jquery.qtipcall.js', __FILE__ ), array( 'jquery', 'qtip' ), '1.1.0', true ); | |
| 77 | + wp_register_style( 'qtipstyles', plugins_url( '/assets/qtip/jquery.qtip.min.css', __FILE__ ), array(), '3.0.3', false ); | |
| 78 | + wp_register_style( 'easyfootnotescss', plugins_url( '/assets/easy-footnotes.css', __FILE__ ), array(), '1.1.0', false ); | |
| 93 | 79 | } |
| 94 | 80 | |
| 95 | 81 | /** |
| 96 | 82 | * Create the Easy Footnotes shortcode. |
| @@ -111,12 +97,11 @@ | ||
| 111 | 97 | wp_enqueue_script( 'qtip' ); |
| 112 | 98 | wp_enqueue_script( 'qtipcall' ); |
| 113 | 99 | wp_enqueue_style( 'dashicons' ); |
| 114 | 100 | |
| 115 | - // Accept optional custom number attribute | |
| 116 | 101 | $atts = shortcode_atts( |
| 117 | 102 | array( |
| 118 | - 'num' => null | |
| 103 | + // Future home of shortcode atts. | |
| 119 | 104 | ), |
| 120 | 105 | $atts |
| 121 | 106 | ); |
| 122 | 107 | |
| @@ -122,63 +107,27 @@ | ||
| 122 | 107 | |
| 123 | 108 | $post_id = get_the_ID(); |
| 124 | 109 | |
| 125 | 110 | $content = do_shortcode( $content ); |
| 126 | - | |
| 127 | - $content_id = md5( preg_replace("/[^A-Za-z0-9 ]/", '', wp_strip_all_tags( html_entity_decode( $content ) ) ) ); | |
| 128 | 111 | |
| 129 | - if ( isset( $this->footnoteOptions[ 'combine_duplicate_footnotes' ] ) && $this->footnoteOptions[ 'combine_duplicate_footnotes' ] === true ) { | |
| 130 | - /** | |
| 131 | - * Search for existing footnote for removing duplicate | |
| 132 | - * Also add the same numbers to duplicate footnotes | |
| 133 | - */ | |
| 134 | - if (!isset($this->usedFootnoteNumbers) ) { | |
| 135 | - $this->usedFootnoteNumbers = array(); | |
| 136 | - } | |
| 137 | - if (!isset($this->footnoteLookup)) { | |
| 138 | - $this->footnoteLookup = array(); | |
| 139 | - } | |
| 140 | - } | |
| 112 | + $count = $this->footnoteCount; | |
| 141 | 113 | |
| 114 | + // Increment the counter. | |
| 115 | + $count++; | |
| 142 | 116 | |
| 143 | - // If a custom number is provided, use that number and mark it as used | |
| 144 | - if ( ! empty( $atts['num'] ) ) { | |
| 145 | - $footnote_number = intval( $atts['num'] ); | |
| 146 | - $this->usedFootnoteNumbers[] = $footnote_number; // Track custom number | |
| 147 | - $this->footnoteLookup[$content_id] = $footnote_number; | |
| 148 | - $this->footnotes[$footnote_number] = $content; | |
| 149 | - } elseif ( isset( $this->footnoteLookup[$content_id] ) ) { | |
| 150 | - if ( isset( $this->footnoteOptions[ 'combine_duplicate_footnotes' ] ) && $this->footnoteOptions[ 'combine_duplicate_footnotes' ] === true ) { | |
| 151 | - // Use existing footnote number for duplicate content | |
| 152 | - $footnote_number = $this->footnoteLookup[$content_id]; | |
| 153 | - } else { | |
| 154 | - $this->footnoteCount++; | |
| 155 | - $footnote_number = $this->footnoteCount; | |
| 156 | - $this->footnotes[$footnote_number] = $content; | |
| 157 | - } | |
| 117 | + // Set the footnoteCount (This whole process needs reworked). | |
| 118 | + $this->footnoteCount = $count; | |
| 119 | + | |
| 120 | + $this->easy_footnote_content( $content ); | |
| 121 | + | |
| 122 | + if ( ( is_singular() || $efn_show_on_front ) && is_main_query() ) { | |
| 123 | + $footnoteLink = '#easy-footnote-bottom-' . $this->footnoteCount . '-' . $post_id; | |
| 158 | 124 | } else { |
| 159 | - // Auto-increment for new footnotes, skipping used numbers | |
| 160 | - do { | |
| 161 | - $this->footnoteCount++; | |
| 162 | - } while ( in_array( $this->footnoteCount, $this->usedFootnoteNumbers ) ); | |
| 163 | - | |
| 164 | - $footnote_number = $this->footnoteCount; | |
| 165 | - $this->footnoteLookup[$content_id] = $footnote_number; | |
| 166 | - $this->usedFootnoteNumbers[] = $footnote_number; // Mark as used | |
| 167 | - $this->footnotes[$footnote_number] = $content; | |
| 125 | + $footnoteLink = get_permalink( get_the_ID() ) . '#easy-footnote-bottom-' . $this->footnoteCount . '-' . $post_id; | |
| 168 | 126 | } |
| 169 | 127 | |
| 170 | - // Generate the correct footnote link with the correct number | |
| 171 | - $footnoteLink = (is_singular() || $efn_show_on_front) && is_main_query() | |
| 172 | - ? '#easy-footnote-bottom-' . $footnote_number . '-' . $post_id | |
| 173 | - : get_permalink($post_id) . '#easy-footnote-bottom-' . $footnote_number . '-' . $post_id; | |
| 174 | - | |
| 175 | - // Now generate the footnote markup with the correct number and link | |
| 176 | - $footnoteContent = "<span id='easy-footnote-" . esc_attr($footnote_number) . '-' . $post_id | |
| 177 | - . "' class='easy-footnote-margin-adjust'></span><span class='easy-footnote'>" | |
| 178 | - . "<a href='" . esc_url($footnoteLink) . "' title='" . htmlspecialchars($content, ENT_QUOTES) | |
| 179 | - . "'><sup>" . esc_html($footnote_number) . "</sup></a></span>"; | |
| 180 | - | |
| 128 | + $footnoteContent = "<span id='easy-footnote-" . esc_attr( $this->footnoteCount ) . '-' . $post_id . "' class='easy-footnote-margin-adjust'></span><span class='easy-footnote'><a href='" . esc_url( $footnoteLink ) . "' title='" . htmlspecialchars( $content, ENT_QUOTES ) . "'><sup>" . esc_html( $this->footnoteCount ) . "</sup></a></span>"; | |
| 129 | + | |
| 181 | 130 | return $footnoteContent; |
| 182 | 131 | } |
| 183 | 132 | |
| 184 | 133 | /** |
| @@ -202,9 +151,9 @@ | ||
| 202 | 151 | return $content; |
| 203 | 152 | } |
| 204 | 153 | |
| 205 | 154 | if ( isset( $this->footnoteOptions['show_easy_footnote_on_front'] ) && $this->footnoteOptions['show_easy_footnote_on_front'] ) { |
| 206 | - $efn_show_on_front = is_front_page() || is_home(); | |
| 155 | + $efn_show_on_front = is_front_page(); | |
| 207 | 156 | } else { |
| 208 | 157 | $efn_show_on_front = false; |
| 209 | 158 | } |
| 210 | 159 | |
| @@ -211,44 +160,29 @@ | ||
| 211 | 160 | if ( ( is_singular() || $efn_show_on_front ) && is_main_query() ) { |
| 212 | 161 | $footnotesInsert = $this->footnotes; |
| 213 | 162 | |
| 214 | 163 | $footnoteCopy = ''; |
| 215 | - $efn_output = ''; | |
| 216 | 164 | |
| 217 | - $useLabel = isset( $this->footnoteOptions['useLabel'] ) ? $this->footnoteOptions['useLabel'] : false; | |
| 218 | - $efLabel = isset($this->footnoteOptions['footnoteLabel'] ) ? $this->footnoteOptions['footnoteLabel'] : __( 'Footnotes', 'easy-footnotes' ); | |
| 165 | + $useLabel = $this->footnoteOptions['useLabel']; | |
| 166 | + $efLabel = $this->footnoteOptions['footnoteLabel']; | |
| 219 | 167 | |
| 220 | 168 | $post_id = get_the_ID(); |
| 221 | 169 | |
| 222 | - // Create a new array to track used footnotes and their numbers | |
| 223 | - $footnote_number = 1; | |
| 224 | - | |
| 225 | - // sort footnotes according to numbers | |
| 226 | - ksort($footnotesInsert); | |
| 227 | - | |
| 228 | 170 | foreach ( $footnotesInsert as $count => $footnote ) { |
| 229 | - | |
| 230 | - if ( isset( $this->footnoteOptions[ 'combine_duplicate_footnotes' ] ) && $this->footnoteOptions[ 'combine_duplicate_footnotes' ] === true ) { | |
| 231 | - // If the footnote is already in the lookup, use its number | |
| 232 | - if ( isset( $this->footnoteLookup[$footnote] ) ) { | |
| 233 | - $count = $this->footnoteLookup[$footnote]; | |
| 234 | - } else { | |
| 235 | - // Skip custom numbers that were already used | |
| 236 | - while ( in_array( $footnote_number, $this->usedFootnoteNumbers ) ) { | |
| 237 | - $footnote_number++; | |
| 238 | - } | |
| 239 | - } | |
| 240 | - } | |
| 241 | - // Generate back-to-top link and the footnote item | |
| 242 | - $footnoteCopy .= '<li class="easy-footnote-single"><span id="easy-footnote-bottom-' . esc_attr( $count ) . '-' . $post_id . '" class="easy-footnote-margin-adjust"></span>' . wp_kses_post( $footnote ) . '<a class="easy-footnote-to-top" href="' . esc_url( '#easy-footnote-' . $count . '-' . $post_id ) . '"></a></li>'; | |
| 171 | + $footnoteCopy .= '<li class="easy-footnote-single"><span id="easy-footnote-bottom-' .esc_attr( $count ) . '-' . $post_id . '" class="easy-footnote-margin-adjust"></span>' . wp_kses_post( $footnote ) . '<a class="easy-footnote-to-top" href="' . esc_url( '#easy-footnote-' . $count . '-' . $post_id ) . '"></a></li>'; | |
| 243 | 172 | } |
| 244 | 173 | if ( ! empty( $footnotesInsert ) ) { |
| 245 | 174 | if ( true === $useLabel ) { |
| 246 | - $footnote_label = '<div class="easy-footnote-title"><h4>' . esc_html( $efLabel ) . '</h4></div>'; | |
| 175 | + $footnote_label = '<h4>' . esc_html( $efLabel ) . '</h4>'; | |
| 247 | 176 | // Filter for editing footnote label markup and output. |
| 248 | 177 | $footnote_label = apply_filters( 'efn_footnote_label', $footnote_label, $efLabel ); |
| 249 | 178 | |
| 250 | - $efn_output .= $footnote_label; | |
| 179 | + $efn_output = sprintf( | |
| 180 | + '<div class="easy-footnote-title"> | |
| 181 | + %s | |
| 182 | + </div>', | |
| 183 | + $footnote_label | |
| 184 | + ); | |
| 251 | 185 | } |
| 252 | 186 | |
| 253 | 187 | $footnote_content = ''; |
| 254 | 188 | |
| @@ -307,26 +241,10 @@ | ||
| 307 | 241 | /** |
| 308 | 242 | * Function for enqueuring EAsy Footnotes admin scripts. |
| 309 | 243 | */ |
| 310 | 244 | public function easy_footnotes_admin_scripts() { |
| 311 | - wp_enqueue_style( 'easy-footnotes-admin-styles', plugins_url( '/assets/easy-footnotes-admin.css', __FILE__ ), '', $this->version ); | |
| 312 | - wp_enqueue_script( 'easy-footnotes-admin-scripts', plugins_url( '/assets/js/easy-footnotes-admin.js', __FILE__ ), array( 'jquery' ), $this->version, true ); | |
| 245 | + wp_enqueue_style( 'easy-footnotes-admin-styles', plugins_url( '/assets/easy-footnotes-admin.css', __FILE__ ), '', '1.0.13' ); | |
| 246 | + wp_enqueue_script( 'easy-footnotes-admin-scripts', plugins_url( '/assets/js/easy-footnotes-admin.js', __FILE__ ), array( 'jquery' ), '1.0.1', true ); | |
| 313 | 247 | } |
| 314 | - | |
| 315 | - /** | |
| 316 | - * Load plugin textdomain easy-footnotes | |
| 317 | - */ | |
| 318 | - public function efn_load_textdomain() { | |
| 319 | - load_plugin_textdomain( 'easy-footnotes', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); | |
| 320 | - } | |
| 321 | - | |
| 322 | - /** | |
| 323 | - * Manually reset footnotes and counter | |
| 324 | - */ | |
| 325 | - public function short_code_reset() { | |
| 326 | - $this->footnoteCount = 0; | |
| 327 | - $this->footnotes = array(); | |
| 328 | - return ""; | |
| 329 | - } | |
| 330 | 248 | } |
| 331 | 249 | |
| 332 | 250 | $easyFootnotes = new easyFootnotes(); |