| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Easy Footnotes |
| 4 |
* Plugin URI: http://jasonyingling.me/easy-footnotes-wordpress/ |
| 5 |
* Description: Easily add footnotes to your posts with a simple shortcode. |
| 6 |
* Version: 1.0.4 |
| 7 |
* Author: Jason Yingling |
| 8 |
* Author URI: http://jasonyingling.me |
| 9 |
* License: GPL2 |
| 10 |
*/ |
| 11 |
|
| 12 |
/* Copyright 2014 Jason Yingling (email : yingling017@gmail.com) |
| 13 |
|
| 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. |
| 17 |
|
| 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. |
| 22 |
|
| 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 |
| 26 |
*/ |
| 27 |
|
| 28 |
class easyFootnotes { |
| 29 |
|
| 30 |
// Add label option using add_option if it does not already exist |
| 31 |
public $footnotes = array(); |
| 32 |
public $footnoteCount = 0; |
| 33 |
|
| 34 |
public function __construct() { |
| 35 |
add_shortcode( 'note', array($this, 'easy_footnote_shortcode') ); |
| 36 |
add_filter('the_content', array($this, 'easy_footnote_after_content'), 999); |
| 37 |
add_action('wp_enqueue_scripts', array($this, 'register_qtip_scripts')); |
| 38 |
} |
| 39 |
|
| 40 |
public function register_qtip_scripts() { |
| 41 |
wp_register_script( 'imagesloaded', plugins_url( '/assets/qtip/imagesloaded.pkgd.min.js' , __FILE__ ), null, false, true ); |
| 42 |
wp_register_script( 'qtip', plugins_url( '/assets/qtip/jquery.qtip.min.js' , __FILE__ ), array('jquery', 'imagesloaded'), false, true ); |
| 43 |
wp_register_script( 'qtipcall', plugins_url( '/assets/qtip/jquery.qtipcall.js' , __FILE__ ), array('jquery', 'qtip'), false, true ); |
| 44 |
wp_register_style( 'qtipstyles', plugins_url( '/assets/qtip/jquery.qtip.min.css' , __FILE__ ), null, false, false ); |
| 45 |
wp_register_style( 'easyfootnotescss', plugins_url( '/assets/easy-footnotes.css' , __FILE__ ), null, false, false ); |
| 46 |
} |
| 47 |
|
| 48 |
public function easy_footnote_shortcode($atts, $content = null) { |
| 49 |
wp_enqueue_style( 'qtipstyles' ); |
| 50 |
wp_enqueue_style( 'easyfootnotescss' ); |
| 51 |
wp_enqueue_script( 'imagesloaded' ); |
| 52 |
wp_enqueue_script( 'qtip' ); |
| 53 |
wp_enqueue_script( 'qtipcall' ); |
| 54 |
wp_enqueue_style( 'dashicons' ); |
| 55 |
|
| 56 |
extract (shortcode_atts(array( |
| 57 |
), $atts)); |
| 58 |
|
| 59 |
$this->easy_footnote_count($this->footnoteCount); |
| 60 |
$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 |
|
| 65 |
return $footnoteContent; |
| 66 |
} |
| 67 |
|
| 68 |
public function easy_footnote_content($content) { |
| 69 |
$this->footnotes[$this->footnoteCount] = $content; |
| 70 |
|
| 71 |
return $this->footnotes; |
| 72 |
} |
| 73 |
|
| 74 |
public function easy_footnote_count($count) { |
| 75 |
$count++; |
| 76 |
|
| 77 |
$this->footnoteCount = $count; |
| 78 |
|
| 79 |
return $this->footnoteCount; |
| 80 |
} |
| 81 |
|
| 82 |
// Calculate reading time by running it through the_content |
| 83 |
public function easy_footnote_after_content($content) { |
| 84 |
if (is_single()) { |
| 85 |
$footnotesInsert = $this->footnotes; |
| 86 |
global $footnoteCopy; |
| 87 |
|
| 88 |
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>'; |
| 90 |
} |
| 91 |
|
| 92 |
$content .= '<ol class="easy-footnotes-wrapper">'.$footnoteCopy.'</ol>'; |
| 93 |
} |
| 94 |
return $content; |
| 95 |
} |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
$easyFootnotes = new easyFootnotes(); |
| 100 |
|
| 101 |
?> |