| @@ -1,16 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: Easy Footnotes |
| 4 | - * Plugin URI: http://jasonyingling.me/easy-footnotes-wordpress/ | |
| 4 | + * Plugin URI: https://jasonyingling.me/easy-footnotes-wordpress/ | |
| 5 | 5 | * Description: Easily add footnotes to your posts with a simple shortcode. |
| 6 | - * Version: 1.0.9 | |
| 6 | + * Version: 1.0.16 | |
| 7 | 7 | * Author: Jason Yingling |
| 8 | - * Author URI: http://jasonyingling.me | |
| 8 | + * Author URI: https://jasonyingling.me | |
| 9 | 9 | * License: GPL2 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | - /* Copyright 2017 Jason Yingling (email : yingling017@gmail.com) | |
| 12 | + /* Copyright 2018 Jason Yingling (email : yingling017@gmail.com) | |
| 13 | 13 | |
| 14 | 14 | This program is free software; you can redistribute it and/or modify |
| 15 | 15 | it under the terms of the GNU General Public License, version 2, as |
| 16 | 16 | published by the Free Software Foundation. |
| @@ -35,15 +35,18 @@ | ||
| 35 | 35 | public function __construct() { |
| 36 | 36 | $footnoteSettings = array( |
| 37 | 37 | 'footnoteLabel' => 'Footnotes', |
| 38 | 38 | 'useLabel' => false, |
| 39 | + 'hide_easy_footnote_after_posts' => false | |
| 39 | 40 | ); |
| 40 | 41 | |
| 41 | 42 | add_option('easy_footnotes_options', $footnoteSettings); |
| 42 | 43 | add_shortcode( 'note', array($this, 'easy_footnote_shortcode') ); |
| 43 | 44 | add_filter('the_content', array($this, 'easy_footnote_after_content'), 20); |
| 45 | + add_filter('the_content', array($this, 'easy_footnote_reset'), 999); | |
| 44 | 46 | add_action('wp_enqueue_scripts', array($this, 'register_qtip_scripts')); |
| 45 | 47 | add_action('admin_menu', array($this, 'easy_footnotes_admin_actions')); |
| 48 | + add_action( 'admin_enqueue_scripts', array($this, 'easy_footnotes_admin_scripts') ); | |
| 46 | 49 | } |
| 47 | 50 | |
| 48 | 51 | public function register_qtip_scripts() { |
| 49 | 52 | wp_register_script( 'imagesloaded', plugins_url( '/assets/qtip/imagesloaded.pkgd.min.js' , __FILE__ ), null, false, true ); |
| @@ -63,18 +66,30 @@ | ||
| 63 | 66 | |
| 64 | 67 | extract (shortcode_atts(array( |
| 65 | 68 | ), $atts)); |
| 66 | 69 | |
| 67 | - $this->easy_footnote_count($this->footnoteCount, get_the_ID()); | |
| 70 | + $post_id = get_the_ID(); | |
| 71 | + | |
| 72 | + $content = do_shortcode($content); | |
| 73 | + | |
| 74 | + $count = $this->footnoteCount; | |
| 75 | + | |
| 76 | + // Increment the counter | |
| 77 | + $count++; | |
| 78 | + | |
| 79 | + // Set the footnoteCount (This whole process needs reworked) | |
| 80 | + $this->footnoteCount = $count; | |
| 81 | + | |
| 82 | + //$this->easy_footnote_count($this->footnoteCount, get_the_ID()); | |
| 68 | 83 | $this->easy_footnote_content($content); |
| 69 | 84 | |
| 70 | 85 | if (is_singular() && is_main_query()) { |
| 71 | - $footnoteLink = '#easy-footnote-bottom-'.$this->footnoteCount; | |
| 86 | + $footnoteLink = '#easy-footnote-bottom-'.$this->footnoteCount.'-'.$post_id;; | |
| 72 | 87 | } else { |
| 73 | - $footnoteLink = get_permalink(get_the_ID()).'#easy-footnote-bottom-'.$this->footnoteCount; | |
| 88 | + $footnoteLink = get_permalink(get_the_ID()).'#easy-footnote-bottom-'.$this->footnoteCount.'-'.$post_id; | |
| 74 | 89 | } |
| 75 | 90 | |
| 76 | - $footnoteContent = "<span id='easy-footnote-".$this->footnoteCount."' class='easy-footnote-margin-adjust'></span><span class='easy-footnote'><a href='".$footnoteLink."' title='".htmlspecialchars($content, ENT_QUOTES)."'><sup>$this->footnoteCount</sup></a></span>"; | |
| 91 | + $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>"; | |
| 77 | 92 | |
| 78 | 93 | return $footnoteContent; |
| 79 | 94 | } |
| 80 | 95 | |
| @@ -97,31 +112,50 @@ | ||
| 97 | 112 | |
| 98 | 113 | return $this->footnoteCount; |
| 99 | 114 | } |
| 100 | 115 | |
| 101 | - // Calculate reading time by running it through the_content | |
| 102 | 116 | public function easy_footnote_after_content($content) { |
| 117 | + | |
| 118 | + $footnoteOptions = get_option('easy_footnotes_options'); | |
| 119 | + | |
| 120 | + if ( isset($footnoteOptions['hide_easy_footnote_after_posts']) && $footnoteOptions['hide_easy_footnote_after_posts'] ) { | |
| 121 | + return $content; | |
| 122 | + } | |
| 123 | + | |
| 103 | 124 | if (is_singular() && is_main_query()) { |
| 104 | 125 | $footnotesInsert = $this->footnotes; |
| 105 | - global $footnoteCopy; | |
| 106 | 126 | |
| 107 | - $footnoteOptions = get_option('easy_footnotes_options'); | |
| 127 | + $footnoteCopy = ''; | |
| 128 | + | |
| 108 | 129 | $useLabel = $footnoteOptions['useLabel']; |
| 109 | 130 | $efLabel = $footnoteOptions['footnoteLabel']; |
| 110 | 131 | |
| 132 | + $post_id = get_the_ID(); | |
| 133 | + | |
| 111 | 134 | foreach ($footnotesInsert as $count => $footnote) { |
| 112 | - $footnoteCopy .= '<li class="easy-footnote-single"><span id="easy-footnote-bottom-'.$count.'" class="easy-footnote-margin-adjust"></span>'.$footnote.'<a class="easy-footnote-to-top" href="#easy-footnote-'.$count.'"></a></li>'; | |
| 135 | + $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>'; | |
| 113 | 136 | } |
| 114 | 137 | if (!empty($footnotesInsert)) { |
| 115 | 138 | if ($useLabel === true) { |
| 116 | - $content .= '<div class="easy-footnote-title"><h4>'.$efLabel.'</h4></div><ol class="easy-footnotes-wrapper">'.$footnoteCopy.'</ol>'; | |
| 139 | + $content .= '<div class="easy-footnote-title"><h4>'.esc_html($efLabel).'</h4></div><ol class="easy-footnotes-wrapper">'.$footnoteCopy.'</ol>'; | |
| 117 | 140 | } else { |
| 118 | 141 | $content .= '<ol class="easy-footnotes-wrapper">'.$footnoteCopy.'</ol>'; |
| 119 | 142 | } |
| 120 | 143 | } |
| 121 | 144 | |
| 145 | + } | |
| 146 | + | |
| 147 | + return $content; | |
| 148 | + } | |
| 122 | 149 | |
| 123 | - } | |
| 150 | + /** | |
| 151 | + * Reset the footnote count and footnote array each time the_content has been run. | |
| 152 | + */ | |
| 153 | + public function easy_footnote_reset($content) { | |
| 154 | + $this->footnoteCount = 0; | |
| 155 | + | |
| 156 | + $this->footnotes = array(); | |
| 157 | + | |
| 124 | 158 | return $content; |
| 125 | 159 | } |
| 126 | 160 | |
| 127 | 161 | // Functions to create Reading Time admin pages |
| @@ -132,9 +166,11 @@ | ||
| 132 | 166 | public function easy_footnotes_admin_actions() { |
| 133 | 167 | add_options_page("Easy Footnotes Settings", "Easy Footnotes", "manage_options", "easy-footnotes-settings", array($this, "easy_footnotes_admin")); |
| 134 | 168 | } |
| 135 | 169 | |
| 170 | + public function easy_footnotes_admin_scripts() { | |
| 171 | + wp_enqueue_style( 'easy-footnotes-admin-styles', plugins_url( '/assets/easy-footnotes-admin.css' , __FILE__ ), '', '1.0.13' ); | |
| 172 | + } | |
| 173 | + | |
| 136 | 174 | } |
| 137 | 175 | |
| 138 | 176 | $easyFootnotes = new easyFootnotes(); |
| 139 | - | |
| 140 | -?> | |