| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: Easy Footnotes |
| 4 | 4 | * Plugin URI: http://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.12 | |
| 7 | 7 | * Author: Jason Yingling |
| 8 | 8 | * Author URI: http://jasonyingling.me |
| 9 | 9 | * License: GPL2 |
| 10 | 10 | */ |
| @@ -63,9 +63,26 @@ | ||
| 63 | 63 | |
| 64 | 64 | extract (shortcode_atts(array( |
| 65 | 65 | ), $atts)); |
| 66 | 66 | |
| 67 | - $this->easy_footnote_count($this->footnoteCount, get_the_ID()); | |
| 67 | + // Get an array of all of the footnotes | |
| 68 | + $pattern = '/\[note\](.*?)\[\/note\]/'; | |
| 69 | + preg_match_all( $pattern, get_the_content(get_the_ID()), $shortcodes ); | |
| 70 | + | |
| 71 | + // If the current content matches the first [note] set the count to 0. This prevents extra counting by themes using the_content | |
| 72 | + if ( $content === $shortcodes[1][0] ) { | |
| 73 | + $count = 0; | |
| 74 | + } else { | |
| 75 | + $count = $this->footnoteCount; | |
| 76 | + } | |
| 77 | + | |
| 78 | + // Increment the counter | |
| 79 | + $count++; | |
| 80 | + | |
| 81 | + // Set the footnoteCount (This whole process needs reworked) | |
| 82 | + $this->footnoteCount = $count; | |
| 83 | + | |
| 84 | + //$this->easy_footnote_count($this->footnoteCount, get_the_ID()); | |
| 68 | 85 | $this->easy_footnote_content($content); |
| 69 | 86 | |
| 70 | 87 | if (is_singular() && is_main_query()) { |
| 71 | 88 | $footnoteLink = '#easy-footnote-bottom-'.$this->footnoteCount; |
| @@ -72,9 +89,9 @@ | ||
| 72 | 89 | } else { |
| 73 | 90 | $footnoteLink = get_permalink(get_the_ID()).'#easy-footnote-bottom-'.$this->footnoteCount; |
| 74 | 91 | } |
| 75 | 92 | |
| 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>"; | |
| 93 | + $footnoteContent = "<span id='easy-footnote-".esc_attr($this->footnoteCount)."' 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 | 94 | |
| 78 | 95 | return $footnoteContent; |
| 79 | 96 | } |
| 80 | 97 | |
| @@ -97,24 +114,24 @@ | ||
| 97 | 114 | |
| 98 | 115 | return $this->footnoteCount; |
| 99 | 116 | } |
| 100 | 117 | |
| 101 | - // Calculate reading time by running it through the_content | |
| 102 | 118 | public function easy_footnote_after_content($content) { |
| 103 | 119 | if (is_singular() && is_main_query()) { |
| 104 | 120 | $footnotesInsert = $this->footnotes; |
| 105 | - global $footnoteCopy; | |
| 106 | 121 | |
| 122 | + $footnoteCopy = ''; | |
| 123 | + | |
| 107 | 124 | $footnoteOptions = get_option('easy_footnotes_options'); |
| 108 | 125 | $useLabel = $footnoteOptions['useLabel']; |
| 109 | 126 | $efLabel = $footnoteOptions['footnoteLabel']; |
| 110 | 127 | |
| 111 | 128 | 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>'; | |
| 129 | + $footnoteCopy .= '<li class="easy-footnote-single"><span id="easy-footnote-bottom-'.esc_attr($count).'" class="easy-footnote-margin-adjust"></span>'.wp_kses_post($footnote).'<a class="easy-footnote-to-top" href="'.esc_url('#easy-footnote-'.$count).'"></a></li>'; | |
| 113 | 130 | } |
| 114 | 131 | if (!empty($footnotesInsert)) { |
| 115 | 132 | if ($useLabel === true) { |
| 116 | - $content .= '<div class="easy-footnote-title"><h4>'.$efLabel.'</h4></div><ol class="easy-footnotes-wrapper">'.$footnoteCopy.'</ol>'; | |
| 133 | + $content .= '<div class="easy-footnote-title"><h4>'.esc_html($efLabel).'</h4></div><ol class="easy-footnotes-wrapper">'.$footnoteCopy.'</ol>'; | |
| 117 | 134 | } else { |
| 118 | 135 | $content .= '<ol class="easy-footnotes-wrapper">'.$footnoteCopy.'</ol>'; |
| 119 | 136 | } |
| 120 | 137 | } |
| @@ -135,6 +152,4 @@ | ||
| 135 | 152 | |
| 136 | 153 | } |
| 137 | 154 | |
| 138 | 155 | $easyFootnotes = new easyFootnotes(); |
| 139 | - | |
| 140 | -?> | |