PluginProbe
Easy Footnotes / 1.0.16
Easy Footnotes v1.0.16
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 +108 -33 1.0.41.0.16 View file →
@@ -1,19 +1,19 @@
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.4
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 -
12 - /* Copyright 2014 Jason Yingling (email : yingling017@gmail.com)
13 11
12 + /* Copyright 2018 Jason Yingling (email : yingling017@gmail.com)
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,19 +25,30 @@
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 public function __construct() {
36 + $footnoteSettings = array(
37 + 'footnoteLabel' => 'Footnotes',
38 + 'useLabel' => false,
39 + 'hide_easy_footnote_after_posts' => false
40 + );
41 +
42 + add_option('easy_footnotes_options', $footnoteSettings);
35 43 add_shortcode( 'note', array($this, 'easy_footnote_shortcode') );
36 - add_filter('the_content', array($this, 'easy_footnote_after_content'), 999);
44 + add_filter('the_content', array($this, 'easy_footnote_after_content'), 20);
45 + add_filter('the_content', array($this, 'easy_footnote_reset'), 999);
37 46 add_action('wp_enqueue_scripts', array($this, 'register_qtip_scripts'));
47 + add_action('admin_menu', array($this, 'easy_footnotes_admin_actions'));
48 + add_action( 'admin_enqueue_scripts', array($this, 'easy_footnotes_admin_scripts') );
38 49 }
39 -
50 +
40 51 public function register_qtip_scripts() {
41 52 wp_register_script( 'imagesloaded', plugins_url( '/assets/qtip/imagesloaded.pkgd.min.js' , __FILE__ ), null, false, true );
42 53 wp_register_script( 'qtip', plugins_url( '/assets/qtip/jquery.qtip.min.js' , __FILE__ ), array('jquery', 'imagesloaded'), false, true );
43 54 wp_register_script( 'qtipcall', plugins_url( '/assets/qtip/jquery.qtipcall.js' , __FILE__ ), array('jquery', 'qtip'), false, true );
@@ -43,9 +54,9 @@
43 54 wp_register_script( 'qtipcall', plugins_url( '/assets/qtip/jquery.qtipcall.js' , __FILE__ ), array('jquery', 'qtip'), false, true );
44 55 wp_register_style( 'qtipstyles', plugins_url( '/assets/qtip/jquery.qtip.min.css' , __FILE__ ), null, false, false );
45 56 wp_register_style( 'easyfootnotescss', plugins_url( '/assets/easy-footnotes.css' , __FILE__ ), null, false, false );
46 57 }
47 -
58 +
48 59 public function easy_footnote_shortcode($atts, $content = null) {
49 60 wp_enqueue_style( 'qtipstyles' );
50 61 wp_enqueue_style( 'easyfootnotescss' );
51 62 wp_enqueue_script( 'imagesloaded' );
@@ -51,51 +62,115 @@
51 62 wp_enqueue_script( 'imagesloaded' );
52 63 wp_enqueue_script( 'qtip' );
53 64 wp_enqueue_script( 'qtipcall' );
54 65 wp_enqueue_style( 'dashicons' );
55 -
66 +
56 67 extract (shortcode_atts(array(
57 68 ), $atts));
69 +
70 + $post_id = get_the_ID();
71 +
72 + $content = do_shortcode($content);
73 +
74 + $count = $this->footnoteCount;
58 75
59 - $this->easy_footnote_count($this->footnoteCount);
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());
60 83 $this->easy_footnote_content($content);
61 -
62 - $footnoteContent = "<span id='easy-footnote-".$this->footnoteCount."' class='easy-footnote-margin-adjust'></span><span class='easy-footnote'><a href='#easy-footnote-bottom-".$this->footnoteCount."' title='$content'><sup>$this->footnoteCount</sup></a></span>";
63 -
64 -
84 +
85 + if (is_singular() && is_main_query()) {
86 + $footnoteLink = '#easy-footnote-bottom-'.$this->footnoteCount.'-'.$post_id;;
87 + } else {
88 + $footnoteLink = get_permalink(get_the_ID()).'#easy-footnote-bottom-'.$this->footnoteCount.'-'.$post_id;
89 + }
90 +
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>";
92 +
65 93 return $footnoteContent;
66 94 }
67 -
95 +
68 96 public function easy_footnote_content($content) {
69 97 $this->footnotes[$this->footnoteCount] = $content;
70 98
71 99 return $this->footnotes;
72 100 }
73 -
74 - public function easy_footnote_count($count) {
101 +
102 + public function easy_footnote_count($count, $currentPost) {
103 + if ($this->prevPost != $currentPost) {
104 + $count = 0;
105 + }
106 +
107 + $this->prevPost = $currentPost;
108 +
75 109 $count++;
76 -
110 +
77 111 $this->footnoteCount = $count;
78 -
112 +
79 113 return $this->footnoteCount;
80 114 }
81 -
82 - // Calculate reading time by running it through the_content
115 +
83 116 public function easy_footnote_after_content($content) {
84 - if (is_single()) {
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 +
124 + if (is_singular() && is_main_query()) {
85 125 $footnotesInsert = $this->footnotes;
86 - global $footnoteCopy;
87 -
126 +
127 + $footnoteCopy = '';
128 +
129 + $useLabel = $footnoteOptions['useLabel'];
130 + $efLabel = $footnoteOptions['footnoteLabel'];
131 +
132 + $post_id = get_the_ID();
133 +
88 134 foreach ($footnotesInsert as $count => $footnote) {
89 - $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>';
90 136 }
91 -
92 - $content .= '<ol class="easy-footnotes-wrapper">'.$footnoteCopy.'</ol>';
137 + if (!empty($footnotesInsert)) {
138 + if ($useLabel === true) {
139 + $content .= '<div class="easy-footnote-title"><h4>'.esc_html($efLabel).'</h4></div><ol class="easy-footnotes-wrapper">'.$footnoteCopy.'</ol>';
140 + } else {
141 + $content .= '<ol class="easy-footnotes-wrapper">'.$footnoteCopy.'</ol>';
142 + }
143 + }
144 +
93 145 }
146 +
94 147 return $content;
95 148 }
96 -
149 +
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 +
158 + return $content;
159 + }
160 +
161 + // Functions to create Reading Time admin pages
162 + public function easy_footnotes_admin() {
163 + include('easy-footnotes-admin.php');
164 + }
165 +
166 + public function easy_footnotes_admin_actions() {
167 + add_options_page("Easy Footnotes Settings", "Easy Footnotes", "manage_options", "easy-footnotes-settings", array($this, "easy_footnotes_admin"));
168 + }
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 +
97 174 }
98 175
99 176 $easyFootnotes = new easyFootnotes();
100 -
101 -?>