Skip to content

Commit

Permalink
fixing footnote counts. added setting to hide footnotes after content.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonyingling committed Apr 18, 2018
1 parent ab7bec3 commit 6d5ea9c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 27 deletions.
23 changes: 17 additions & 6 deletions easy-footnotes-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
} else {
$easyFootnoteCheck = false;
}

if (isset( $_POST['hide_easy_footnote_after_posts'] ) && $_POST['hide_easy_footnote_after_posts'] ) {
$hide_easy_footnote_after_posts = true;
} else {
$hide_easy_footnote_after_posts = false;
}

$updateOptions = array(
'footnoteLabel' => $easyFootnoteLabel,
'useLabel' => $easyFootnoteCheck,
'useLabel' => $easyFootnoteCheck,
'hide_easy_footnote_after_posts' => $hide_easy_footnote_after_posts,
);

update_option('easy_footnotes_options', $updateOptions);
Expand All @@ -23,20 +31,23 @@
//Normal page display
$easyFootnoteLabel = $footnoteOptions['footnoteLabel'];
$easyFootnoteCheck = $footnoteOptions['useLabel'];
$hide_easy_footnote_after_posts = $footnoteOptions['hide_easy_footnote_after_posts'];
}
?>

<div class="wrap">
<?php echo "<h2>" . esc_html__( 'Easy Footnotes Settings', 'easy_footnotes_trdom' ) . "</h2>"; ?>
<?php echo "<h2>" . esc_html__( 'Easy Footnotes Settings', 'easy_footnotes_trdom' ) . "</h2>"; ?>

<form name="easy_footnotes_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
<input type="hidden" name="easy_footnote_hidden" value="Y">
<?php echo "<h4>" . esc_html__( 'Easy Footnotes Settings', 'easy_footnotes_trdom' ) . "</h4>"; ?>
<?php echo "<h4>" . esc_html__( 'Easy Footnotes Settings', 'easy_footnotes_trdom' ) . "</h4>"; ?>
<p><?php esc_html_e("Want to add a label to your footnotes section at the bottom of your post? Just enter some text here and check the box and you're good to go."); ?></p>
<p><?php esc_html_e("Easy Footnotes Label: "); ?><input type="text" name="easy_footnotes_label" value="<?php echo esc_attr($easyFootnoteLabel); ?>" size="20"></p>

<p><?php esc_html_e("Insert Easy Footnotes Label: "); ?><input type="checkbox" name="easy_footnote_check" <?php checked($easyFootnoteCheck); ?> size="20"><?php esc_html_e(""); ?></p>

<p><?php esc_html_e("Hide Footnotes after post content: "); ?><input type="checkbox" name="hide_easy_footnote_after_posts" <?php checked($hide_easy_footnote_after_posts); ?> size="20"><?php esc_html_e(""); ?></p>

<p class="submit">
<input type="submit" name="Submit" value="<?php esc_attr_e('Update Options', 'easy_footnotes_trdom' ) ?>" />
</p>
Expand All @@ -47,12 +58,12 @@
</div>

<div class="efn-preview">
<a class="efn-theme-link" href="<?php echo esc_url( 'https://www.themes.pizza/utm_source=easy-footnotes&utm_medium=button&utm_campaign=efnupsell' ); ?>" target="_blank"><img src="<?php echo plugins_url( '/assets/zuul-wordpress-theme.jpg' , __FILE__ ); ?>" alt="Zuul WordPress Theme homepage in various color options" /></a>
<a class="efn-theme-link" href="<?php echo esc_url( 'https://www.themes.pizza/?utm_source=easy-footnotes&utm_medium=button&utm_campaign=efnupsell' ); ?>" target="_blank"><img src="<?php echo plugins_url( '/assets/zuul-wordpress-theme.jpg' , __FILE__ ); ?>" alt="Zuul WordPress Theme homepage in various color options" /></a>
<div class="efn-preview-copy">
<h2><?php echo __( 'Tasty WordPress Themes', 'easy-footnotes' ); ?></h2>
<p><?php printf( __( 'Love easy footnotes? Check out my premium themes now available on Themes.Pizza. Each theme is hand crafted from the finest ingredients with a specific purpose in mind. Need to start a side project / membership site? Try out <a href="%1s" target="_blank">Zuul</a>. Looking to establish yourself as an authoirty on a subject? Try out <a href="%2s" target="_blank">The Authority Pro</a>.', 'easy-footnotes' ), esc_url( 'https://www.themes.pizza/downloads/zuul-pro/utm_source=easy-footnotes&utm_medium=button&utm_campaign=efnupsell' ), esc_url( 'https://www.themes.pizza/downloads/the-authority-pro/utm_source=easy-footnotes&utm_medium=button&utm_campaign=efnupsell' ) ); ?></p>
<p><?php printf( __( 'Love easy footnotes? Check out my premium themes now available on Themes.Pizza. Each theme is hand crafted from the finest ingredients with a specific purpose in mind. Need to start a side project / membership site? Try out <a href="%1s" target="_blank">Zuul</a>. Looking to establish yourself as an authoirty on a subject? Try out <a href="%2s" target="_blank">The Authority Pro</a>.', 'easy-footnotes' ), esc_url( 'https://www.themes.pizza/downloads/zuul-pro/?utm_source=easy-footnotes&utm_medium=button&utm_campaign=efnupsell' ), esc_url( 'https://www.themes.pizza/downloads/the-authority-pro/?utm_source=easy-footnotes&utm_medium=button&utm_campaign=efnupsell' ) ); ?></p>
<p><?php echo __( 'All themes are 100% GPL. Use them on as many sites as you want and make something awesome! And for being a faithful Easy Footnotes user get 20% off with the code <strong>TASTYZA</strong>.', 'easy-footnotes' ); ?></p>
<a class="efn-theme-button" href="<?php echo esc_url( 'https://www.themes.pizza/utm_source=easy-footnotes&utm_medium=button&utm_campaign=efnupsell' ); ?>" target="_blank"><?php echo __( 'Shop Now', 'easy-footnotes' ); ?></a>
<a class="efn-theme-button" href="<?php echo esc_url( 'https://www.themes.pizza/?utm_source=easy-footnotes&utm_medium=button&utm_campaign=efnupsell' ); ?>" target="_blank"><?php echo __( 'Shop Now', 'easy-footnotes' ); ?></a>
</div>
</div>
</div>
54 changes: 35 additions & 19 deletions easy-footnotes.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/**
* Plugin Name: Easy Footnotes
* Plugin URI: http://jasonyingling.me/easy-footnotes-wordpress/
* Plugin URI: https://jasonyingling.me/easy-footnotes-wordpress/
* Description: Easily add footnotes to your posts with a simple shortcode.
* Version: 1.0.13
* Version: 1.0.16
* Author: Jason Yingling
* Author URI: http://jasonyingling.me
* Author URI: https://jasonyingling.me
* License: GPL2
*/

/* Copyright 2017 Jason Yingling (email : [email protected])
/* Copyright 2018 Jason Yingling (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
Expand All @@ -36,11 +36,13 @@ public function __construct() {
$footnoteSettings = array(
'footnoteLabel' => 'Footnotes',
'useLabel' => false,
'hide_easy_footnote_after_posts' => false
);

add_option('easy_footnotes_options', $footnoteSettings);
add_shortcode( 'note', array($this, 'easy_footnote_shortcode') );
add_filter('the_content', array($this, 'easy_footnote_after_content'), 20);
add_filter('the_content', array($this, 'easy_footnote_reset'), 999);
add_action('wp_enqueue_scripts', array($this, 'register_qtip_scripts'));
add_action('admin_menu', array($this, 'easy_footnotes_admin_actions'));
add_action( 'admin_enqueue_scripts', array($this, 'easy_footnotes_admin_scripts') );
Expand All @@ -65,17 +67,12 @@ public function easy_footnote_shortcode($atts, $content = null) {
extract (shortcode_atts(array(
), $atts));

// Get an array of all of the footnotes
$pattern = '/\[note\](.*?)\[\/note\]/';
preg_match_all( $pattern, get_the_content( get_the_ID() ), $shortcodes );
$post_id = get_the_ID();

// If the current content matches the first [note] set the count to 0. This prevents extra counting by themes using the_content
if ( isset( $shortcodes[1][0] ) && $content === $shortcodes[1][0] ) {
$count = 0;
} else {
$count = $this->footnoteCount;
}
$content = do_shortcode($content);

$count = $this->footnoteCount;

// Increment the counter
$count++;

Expand All @@ -86,12 +83,12 @@ public function easy_footnote_shortcode($atts, $content = null) {
$this->easy_footnote_content($content);

if (is_singular() && is_main_query()) {
$footnoteLink = '#easy-footnote-bottom-'.$this->footnoteCount;
$footnoteLink = '#easy-footnote-bottom-'.$this->footnoteCount.'-'.$post_id;;
} else {
$footnoteLink = get_permalink(get_the_ID()).'#easy-footnote-bottom-'.$this->footnoteCount;
$footnoteLink = get_permalink(get_the_ID()).'#easy-footnote-bottom-'.$this->footnoteCount.'-'.$post_id;
}

$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>";
$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>";

return $footnoteContent;
}
Expand All @@ -117,17 +114,25 @@ public function easy_footnote_count($count, $currentPost) {
}

public function easy_footnote_after_content($content) {

$footnoteOptions = get_option('easy_footnotes_options');

if ( isset($footnoteOptions['hide_easy_footnote_after_posts']) && $footnoteOptions['hide_easy_footnote_after_posts'] ) {
return $content;
}

if (is_singular() && is_main_query()) {
$footnotesInsert = $this->footnotes;

$footnoteCopy = '';

$footnoteOptions = get_option('easy_footnotes_options');
$useLabel = $footnoteOptions['useLabel'];
$efLabel = $footnoteOptions['footnoteLabel'];

$post_id = get_the_ID();

foreach ($footnotesInsert as $count => $footnote) {
$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>';
$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>';
}
if (!empty($footnotesInsert)) {
if ($useLabel === true) {
Expand All @@ -137,8 +142,19 @@ public function easy_footnote_after_content($content) {
}
}


}

return $content;
}

/**
* Reset the footnote count and footnote array each time the_content has been run.
*/
public function easy_footnote_reset($content) {
$this->footnoteCount = 0;

$this->footnotes = array();

return $content;
}

Expand Down
28 changes: 26 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: yingling017
Donate link: http://jasonyingling.me
Tags: footnotes, read, blogging, hover, tooltips, editing, endnotes, Formatting, writing, bibliography, notes, reference
Requires at least: 3.0.1
Tested up to: 4.9.1
Stable tag: 1.0.13
Tested up to: 4.9.5
Stable tag: 1.0.16
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -58,6 +58,18 @@ Maecenas sed diam eget risus varius blandit sit amet non magna. Integer posuere

== Changelog ==

= 1.0.16 =
* Fixing footnote counts for the last time! (Hopefully)
* Added post ID to footnote IDs to make them more unique
* New setting to hide the footnotes after content in Settings > Easy Footnotes
* Prep for a bigger update and beginning Gutenberg support

= 1.0.15 =
* Being a noob and not testing a link added in on settings page. It works now.

= 1.0.14 =
* CSS tweak in admin screen

= 1.0.13 =
* Fixing PHP notice on shortcode when content not found

Expand Down Expand Up @@ -143,3 +155,15 @@ Changing how footnotes are numbered to avoid duplicates caused by `the_content`

= 1.0.13 =
Fixing PHP notice on shortcode when content not found

= 1.0.14 =
CSS tweak in admin screen

= 1.0.15 =
Being a noob and not testing a link added in on settings page. It works now.

= 1.0.16 =
* Fixing footnote counts for the last time! (Hopefully)
* Added post ID to footnote IDs to make them more unique
* New setting to hide the footnotes after content in Settings > Easy Footnotes
* Prep for a bigger update and beginning Gutenberg support

0 comments on commit 6d5ea9c

Please sign in to comment.