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 +82 -157 1.1.21.0.16 View file →
@@ -2,96 +2,62 @@
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 - * Version: 1.1.2
6 + * Version: 1.0.16
7 7 * Author: Jason Yingling
8 8 * Author URI: https://jasonyingling.me
9 9 * License: GPL2
10 - *
11 - * @package easy-footnotes
12 10 */
13 11
14 -/*
15 - Copyright 2018 Jason Yingling (email : yingling017@gmail.com)
12 + /* Copyright 2018 Jason Yingling (email : yingling017@gmail.com)
16 13
17 - This program is free software; you can redistribute it and/or modify
18 - it under the terms of the GNU General Public License, version 2, as
19 - published by the Free Software Foundation.
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
16 + published by the Free Software Foundation.
20 17
21 - This program is distributed in the hope that it will be useful,
22 - but WITHOUT ANY WARRANTY; without even the implied warranty of
23 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 - GNU General Public License for more details.
18 + This program is distributed in the hope that it will be useful,
19 + but WITHOUT ANY WARRANTY; without even the implied warranty of
20 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 + GNU General Public License for more details.
25 22
26 - You should have received a copy of the GNU General Public License
27 - along with this program; if not, write to the Free Software
28 - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 + You should have received a copy of the GNU General Public License
24 + along with this program; if not, write to the Free Software
25 + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 26 */
30 -/**
31 - * The Easy Footnotes class. In camel case. Because I didn't follow WPCS way back when.
32 - */
27 +
33 28 class easyFootnotes {
34 29
35 - /**
36 - * Add label option using add_option if it does not already exist.
37 - *
38 - * @var array $footnotes An array for the footnotes to be stored.
39 - */
40 - public $footnotes = array();
30 + // Add label option using add_option if it does not already exist
31 + public $footnotes = array();
41 32 public $footnoteCount = 0;
42 33 public $prevPost;
43 - public $footnoteOptions;
44 34
45 - private $footnoteSettings;
46 -
47 - /**
48 - * Constructing the initial plugin options, shortcodes, and hooks.
49 - */
50 35 public function __construct() {
51 - $this->footnoteSettings = array(
52 - 'footnoteLabel' => __( 'Footnotes', 'easy-footnotes' ),
53 - 'useLabel' => false,
54 - 'hide_easy_footnote_after_posts' => false,
55 - 'show_easy_footnote_on_front' => false,
36 + $footnoteSettings = array(
37 + 'footnoteLabel' => 'Footnotes',
38 + 'useLabel' => false,
39 + 'hide_easy_footnote_after_posts' => false
56 40 );
57 41
58 - add_option( 'easy_footnotes_options', $this->footnoteSettings );
59 - add_shortcode( 'note', array( $this, 'easy_footnote_shortcode' ) );
60 - add_shortcode( 'efn_note', array( $this, 'easy_footnote_shortcode' ) );
61 - add_filter( 'the_content', array( $this, 'easy_footnote_after_content' ), 20 );
62 - add_filter( 'the_content', array( $this, 'easy_footnote_reset' ), 999 );
63 - add_action( 'wp_enqueue_scripts', array( $this, 'register_qtip_scripts' ) );
64 - add_action( 'admin_menu', array( $this, 'easy_footnotes_admin_actions' ) );
65 - add_action( 'admin_enqueue_scripts', array( $this, 'easy_footnotes_admin_scripts' ) );
66 -
67 - $this->footnoteOptions = get_option( 'easy_footnotes_options' );
42 + add_option('easy_footnotes_options', $footnoteSettings);
43 + add_shortcode( 'note', array($this, 'easy_footnote_shortcode') );
44 + add_filter('the_content', array($this, 'easy_footnote_after_content'), 20);
45 + add_filter('the_content', array($this, 'easy_footnote_reset'), 999);
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') );
68 49 }
69 50
70 - /**
71 - * Registering the scripts and styles used by jQuery qTip.
72 - */
73 51 public function register_qtip_scripts() {
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 );
52 + wp_register_script( 'imagesloaded', plugins_url( '/assets/qtip/imagesloaded.pkgd.min.js' , __FILE__ ), null, false, true );
53 + wp_register_script( 'qtip', plugins_url( '/assets/qtip/jquery.qtip.min.js' , __FILE__ ), array('jquery', 'imagesloaded'), false, true );
54 + wp_register_script( 'qtipcall', plugins_url( '/assets/qtip/jquery.qtipcall.js' , __FILE__ ), array('jquery', 'qtip'), false, true );
55 + wp_register_style( 'qtipstyles', plugins_url( '/assets/qtip/jquery.qtip.min.css' , __FILE__ ), null, false, false );
56 + wp_register_style( 'easyfootnotescss', plugins_url( '/assets/easy-footnotes.css' , __FILE__ ), null, false, false );
79 57 }
80 58
81 - /**
82 - * Create the Easy Footnotes shortcode.
83 - *
84 - * @param array $atts Shortcode attributes.
85 - * @param string $content Content within the shortcode.
86 - */
87 - public function easy_footnote_shortcode( $atts, $content = null ) {
88 - if ( isset( $this->footnoteOptions['show_easy_footnote_on_front'] ) && $this->footnoteOptions['show_easy_footnote_on_front'] ) {
89 - $efn_show_on_front = is_front_page();
90 - } else {
91 - $efn_show_on_front = false;
92 - }
93 -
59 + public function easy_footnote_shortcode($atts, $content = null) {
94 60 wp_enqueue_style( 'qtipstyles' );
95 61 wp_enqueue_style( 'easyfootnotescss' );
96 62 wp_enqueue_script( 'imagesloaded' );
97 63 wp_enqueue_script( 'qtip' );
@@ -97,122 +63,95 @@
97 63 wp_enqueue_script( 'qtip' );
98 64 wp_enqueue_script( 'qtipcall' );
99 65 wp_enqueue_style( 'dashicons' );
100 66
101 - $atts = shortcode_atts(
102 - array(
103 - // Future home of shortcode atts.
104 - ),
105 - $atts
106 - );
67 + extract (shortcode_atts(array(
68 + ), $atts));
107 69
108 70 $post_id = get_the_ID();
109 71
110 - $content = do_shortcode( $content );
72 + $content = do_shortcode($content);
111 73
112 74 $count = $this->footnoteCount;
113 -
114 - // Increment the counter.
75 +
76 + // Increment the counter
115 77 $count++;
116 78
117 - // Set the footnoteCount (This whole process needs reworked).
79 + // Set the footnoteCount (This whole process needs reworked)
118 80 $this->footnoteCount = $count;
119 81
120 - $this->easy_footnote_content( $content );
82 + //$this->easy_footnote_count($this->footnoteCount, get_the_ID());
83 + $this->easy_footnote_content($content);
121 84
122 - if ( ( is_singular() || $efn_show_on_front ) && is_main_query() ) {
123 - $footnoteLink = '#easy-footnote-bottom-' . $this->footnoteCount . '-' . $post_id;
85 + if (is_singular() && is_main_query()) {
86 + $footnoteLink = '#easy-footnote-bottom-'.$this->footnoteCount.'-'.$post_id;;
124 87 } else {
125 - $footnoteLink = get_permalink( get_the_ID() ) . '#easy-footnote-bottom-' . $this->footnoteCount . '-' . $post_id;
88 + $footnoteLink = get_permalink(get_the_ID()).'#easy-footnote-bottom-'.$this->footnoteCount.'-'.$post_id;
126 89 }
127 90
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>";
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>";
129 92
130 93 return $footnoteContent;
131 94 }
132 95
133 - /**
134 - * The content of a particular footnote.
135 - *
136 - * @param string $content The content from a particular call of the shortcode.
137 - */
138 - public function easy_footnote_content( $content ) {
139 - $this->footnotes[ $this->footnoteCount ] = $content;
96 + public function easy_footnote_content($content) {
97 + $this->footnotes[$this->footnoteCount] = $content;
140 98
141 99 return $this->footnotes;
142 100 }
143 101
144 - /**
145 - * Display the list of footnotes after the post content.
146 - *
147 - * @param string $content The content of the current post.
148 - */
149 - public function easy_footnote_after_content( $content ) {
150 - if ( isset( $this->footnoteOptions['hide_easy_footnote_after_posts'] ) && $this->footnoteOptions['hide_easy_footnote_after_posts'] ) {
151 - return $content;
102 + public function easy_footnote_count($count, $currentPost) {
103 + if ($this->prevPost != $currentPost) {
104 + $count = 0;
152 105 }
153 106
154 - if ( isset( $this->footnoteOptions['show_easy_footnote_on_front'] ) && $this->footnoteOptions['show_easy_footnote_on_front'] ) {
155 - $efn_show_on_front = is_front_page();
156 - } else {
157 - $efn_show_on_front = false;
107 + $this->prevPost = $currentPost;
108 +
109 + $count++;
110 +
111 + $this->footnoteCount = $count;
112 +
113 + return $this->footnoteCount;
114 + }
115 +
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;
158 122 }
159 123
160 - if ( ( is_singular() || $efn_show_on_front ) && is_main_query() ) {
124 + if (is_singular() && is_main_query()) {
161 125 $footnotesInsert = $this->footnotes;
162 126
163 127 $footnoteCopy = '';
164 - $efn_output = '';
165 128
166 - $useLabel = isset( $this->footnoteOptions['useLabel'] ) ? $this->footnoteOptions['useLabel'] : false;
167 - $efLabel = isset($this->footnoteOptions['footnoteLabel'] ) ? $this->footnoteOptions['footnoteLabel'] : __( 'Footnotes', 'easy-footnotes' );
129 + $useLabel = $footnoteOptions['useLabel'];
130 + $efLabel = $footnoteOptions['footnoteLabel'];
168 131
169 132 $post_id = get_the_ID();
170 133
171 - foreach ( $footnotesInsert as $count => $footnote ) {
172 - $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>';
134 + foreach ($footnotesInsert as $count => $footnote) {
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>';
173 136 }
174 - if ( ! empty( $footnotesInsert ) ) {
175 - if ( true === $useLabel ) {
176 - $footnote_label = '<h4>' . esc_html( $efLabel ) . '</h4>';
177 - // Filter for editing footnote label markup and output.
178 - $footnote_label = apply_filters( 'efn_footnote_label', $footnote_label, $efLabel );
179 -
180 - $efn_output .= sprintf(
181 - '<div class="easy-footnote-title">
182 - %s
183 - </div>',
184 - $footnote_label
185 - );
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>';
186 142 }
143 + }
187 144
188 - $footnote_content = '';
189 -
190 - // Add filter before footnote list.
191 - $footnote_content = apply_filters( 'before_footnote', $footnote_content );
192 - $footnote_content .= '<ol class="easy-footnotes-wrapper">' . $footnoteCopy . '</ol>';
193 -
194 - // Add filter after footnote list.
195 - $footnote_content = apply_filters( 'after_footnote', $footnote_content );
196 -
197 - $efn_output .= $footnote_content;
198 -
199 - // Add filters for the entire footnote list output.
200 - $efn_output = apply_filters( 'efn_footnote_list_output', $efn_output );
201 -
202 - $content .= do_shortcode( $efn_output );
203 - }
204 145 }
205 -
146 +
206 147 return $content;
207 148 }
208 149
209 150 /**
210 151 * Reset the footnote count and footnote array each time the_content has been run.
211 - *
212 - * @param string $content The content of the post from the_content filter.
213 152 */
214 - public function easy_footnote_reset( $content ) {
153 + public function easy_footnote_reset($content) {
215 154 $this->footnoteCount = 0;
216 155
217 156 $this->footnotes = array();
218 157
@@ -218,34 +157,20 @@
218 157
219 158 return $content;
220 159 }
221 160
222 - /**
223 - * Include the easy-footnotes-admin.php file.
224 - */
161 + // Functions to create Reading Time admin pages
225 162 public function easy_footnotes_admin() {
226 - include 'easy-footnotes-admin.php';
163 + include('easy-footnotes-admin.php');
227 164 }
228 165
229 - /**
230 - * Function to add options page for Easy Footnote Settings.
231 - */
232 166 public function easy_footnotes_admin_actions() {
233 - add_options_page(
234 - __( 'Easy Footnotes Settings', 'easy-footnotes' ),
235 - __( 'Easy Footnotes', 'easy-footnotes' ),
236 - 'manage_options',
237 - 'easy-footnotes-settings',
238 - array( $this, 'easy_footnotes_admin' )
239 - );
167 + add_options_page("Easy Footnotes Settings", "Easy Footnotes", "manage_options", "easy-footnotes-settings", array($this, "easy_footnotes_admin"));
240 168 }
241 169
242 - /**
243 - * Function for enqueuring EAsy Footnotes admin scripts.
244 - */
245 170 public function easy_footnotes_admin_scripts() {
246 - wp_enqueue_style( 'easy-footnotes-admin-styles', plugins_url( '/assets/easy-footnotes-admin.css', __FILE__ ), '', '1.0.13' );
247 - wp_enqueue_script( 'easy-footnotes-admin-scripts', plugins_url( '/assets/js/easy-footnotes-admin.js', __FILE__ ), array( 'jquery' ), '1.0.1', true );
171 + wp_enqueue_style( 'easy-footnotes-admin-styles', plugins_url( '/assets/easy-footnotes-admin.css' , __FILE__ ), '', '1.0.13' );
248 172 }
173 +
249 174 }
250 175
251 176 $easyFootnotes = new easyFootnotes();