PluginProbe
Easy Footnotes / 1.0.12
Easy Footnotes v1.0.12
trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.2 All 32 releases
← All changes | easy-footnotes.php +51 -36 1.0.71.0.12 View file →
@@ -2,18 +2,18 @@
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.7
6 + * Version: 1.0.12
7 7 * Author: Jason Yingling
8 8 * Author URI: http://jasonyingling.me
9 9 * License: GPL2
10 10 */
11 -
12 - /* Copyright 2015 Jason Yingling (email : [email protected])
13 11
12 + /* Copyright 2017 Jason Yingling (email : [email protected])
13 +
14 14 This program is free software; you can redistribute it and/or modify
15 - it under the terms of the GNU General Public License, version 2, as
15 + it under the terms of the GNU General Public License, version 2, as
16 16 published by the Free Software Foundation.
17 17
18 18 This program is distributed in the hope that it will be useful,
19 19 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -25,20 +25,20 @@
25 25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 26 */
27 27
28 28 class easyFootnotes {
29 -
29 +
30 30 // Add label option using add_option if it does not already exist
31 31 public $footnotes = array();
32 32 public $footnoteCount = 0;
33 33 public $prevPost;
34 -
34 +
35 35 public function __construct() {
36 36 $footnoteSettings = array(
37 37 'footnoteLabel' => 'Footnotes',
38 38 'useLabel' => false,
39 39 );
40 -
40 +
41 41 add_option('easy_footnotes_options', $footnoteSettings);
42 42 add_shortcode( 'note', array($this, 'easy_footnote_shortcode') );
43 43 add_filter('the_content', array($this, 'easy_footnote_after_content'), 20);
44 44 add_action('wp_enqueue_scripts', array($this, 'register_qtip_scripts'));
@@ -43,9 +43,9 @@
43 43 add_filter('the_content', array($this, 'easy_footnote_after_content'), 20);
44 44 add_action('wp_enqueue_scripts', array($this, 'register_qtip_scripts'));
45 45 add_action('admin_menu', array($this, 'easy_footnotes_admin_actions'));
46 46 }
47 -
47 +
48 48 public function register_qtip_scripts() {
49 49 wp_register_script( 'imagesloaded', plugins_url( '/assets/qtip/imagesloaded.pkgd.min.js' , __FILE__ ), null, false, true );
50 50 wp_register_script( 'qtip', plugins_url( '/assets/qtip/jquery.qtip.min.js' , __FILE__ ), array('jquery', 'imagesloaded'), false, true );
51 51 wp_register_script( 'qtipcall', plugins_url( '/assets/qtip/jquery.qtipcall.js' , __FILE__ ), array('jquery', 'qtip'), false, true );
@@ -51,9 +51,9 @@
51 51 wp_register_script( 'qtipcall', plugins_url( '/assets/qtip/jquery.qtipcall.js' , __FILE__ ), array('jquery', 'qtip'), false, true );
52 52 wp_register_style( 'qtipstyles', plugins_url( '/assets/qtip/jquery.qtip.min.css' , __FILE__ ), null, false, false );
53 53 wp_register_style( 'easyfootnotescss', plugins_url( '/assets/easy-footnotes.css' , __FILE__ ), null, false, false );
54 54 }
55 -
55 +
56 56 public function easy_footnote_shortcode($atts, $content = null) {
57 57 wp_enqueue_style( 'qtipstyles' );
58 58 wp_enqueue_style( 'easyfootnotescss' );
59 59 wp_enqueue_script( 'imagesloaded' );
@@ -59,82 +59,97 @@
59 59 wp_enqueue_script( 'imagesloaded' );
60 60 wp_enqueue_script( 'qtip' );
61 61 wp_enqueue_script( 'qtipcall' );
62 62 wp_enqueue_style( 'dashicons' );
63 -
63 +
64 64 extract (shortcode_atts(array(
65 65 ), $atts));
66 -
67 - $this->easy_footnote_count($this->footnoteCount, get_the_ID());
66 +
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 89 } else {
73 90 $footnoteLink = get_permalink(get_the_ID()).'#easy-footnote-bottom-'.$this->footnoteCount;
74 91 }
75 -
76 - $footnoteContent = "<span id='easy-footnote-".$this->footnoteCount."' class='easy-footnote-margin-adjust'></span><span class='easy-footnote'><a href='".$footnoteLink."' title='$content'><sup>$this->footnoteCount</sup></a></span>";
77 -
92 +
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>";
94 +
78 95 return $footnoteContent;
79 96 }
80 -
97 +
81 98 public function easy_footnote_content($content) {
82 99 $this->footnotes[$this->footnoteCount] = $content;
83 100
84 101 return $this->footnotes;
85 102 }
86 -
103 +
87 104 public function easy_footnote_count($count, $currentPost) {
88 105 if ($this->prevPost != $currentPost) {
89 106 $count = 0;
90 107 }
91 -
108 +
92 109 $this->prevPost = $currentPost;
93 -
110 +
94 111 $count++;
95 -
112 +
96 113 $this->footnoteCount = $count;
97 -
114 +
98 115 return $this->footnoteCount;
99 116 }
100 -
101 - // Calculate reading time by running it through the_content
117 +
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 }
121 -
122 -
138 +
139 +
123 140 }
124 141 return $content;
125 142 }
126 -
143 +
127 144 // Functions to create Reading Time admin pages
128 145 public function easy_footnotes_admin() {
129 146 include('easy-footnotes-admin.php');
130 147 }
131 -
148 +
132 149 public function easy_footnotes_admin_actions() {
133 150 add_options_page("Easy Footnotes Settings", "Easy Footnotes", "manage_options", "easy-footnotes-settings", array($this, "easy_footnotes_admin"));
134 151 }
135 -
152 +
136 153 }
137 154
138 155 $easyFootnotes = new easyFootnotes();
139 -
140 -?>