Skip to content

Commit

Permalink
Merge pull request with contributions from Mahjouba91
Browse files Browse the repository at this point in the history
Fixed php notices and reformatted code: at v1.2 now.
  • Loading branch information
vhbelvadi authored Apr 26, 2017
2 parents 1965cb8 + ce9b846 commit f427f64
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 102 deletions.
233 changes: 132 additions & 101 deletions footnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://vhbelvadi.com/footnotation
Description: A simple footnote plugin for Wordpress
Author: V.H. Belvadi
Version: 1.1
Version: 1.2
Author URI: http://vhbelvadi.com
Copyright (C) 2017 V.H. Belvadi
Expand All @@ -27,147 +27,178 @@
*/

/*
define('footnotation_localisation', 'footnotation');
if (function_exists('load_plugin_textdomain')) {
load_plugin_textdomain(footnotation_localisation, false, dirname(plugin_basename(__FILE__)).'/lang' );
load_plugin_textdomain('footnotation', false, dirname(plugin_basename(__FILE__)).'/lang' );
}
*/

add_action('admin_menu', 'footnotation_config_page');
add_action('wp_enqueue_scripts', 'footnotation_enqueue_scripts');
add_action( 'admin_menu', 'footnotation_config_page' );
add_action( 'wp_enqueue_scripts', 'footnotation_enqueue_scripts' );
add_action( 'wp_enqueue_scripts', 'footnotation_enqueue_styles' );

function footnotation_enqueue_styles() {
wp_enqueue_style( 'footnotation-styles', get_bloginfo('wpurl').'/'.PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)). '/footnotation-styles.css' );
wp_enqueue_style( 'footnotation-styles', get_bloginfo( 'wpurl' ) . '/' . PLUGINDIR . '/' . dirname( plugin_basename( __FILE__ ) ) . '/footnotation-styles.css' );
}

function footnotation_enqueue_scripts() {
if (is_admin()) return;

wp_enqueue_script('jquery');

wp_register_script('footnotation_script', get_bloginfo('wpurl').'/'.PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/footnotation.js', array('jquery'), '1.34');
wp_enqueue_script('footnotation_script');
if ( is_admin() ) {
return;
}

wp_enqueue_script( 'jquery' );

wp_register_script( 'footnotation_script', get_bloginfo( 'wpurl' ) . '/' . PLUGINDIR . '/' . dirname( plugin_basename( __FILE__ ) ) . '/footnotation.js', array( 'jquery' ), '1.34' );
wp_enqueue_script( 'footnotation_script' );
}

function footnotation_config_page() {
global $wpdb;
if ( function_exists('add_submenu_page') )
add_submenu_page('options-general.php',
__('Footnotation', footnotation_localisation),
__('Footnotation', footnotation_localisation),
'manage_options', __FILE__, 'footnotation_conf');
if ( function_exists( 'add_submenu_page' ) ) {
add_submenu_page( 'options-general.php',
__( 'Footnotation', 'footnotation' ),
__( 'Footnotation', 'footnotation' ),
'manage_options', __FILE__, 'footnotation_conf' );
}
}

function footnotation_conf() {
$options = get_option('footnotation');
$options = get_option( 'footnotation' );

if ( ! isset( $options['footnotation_collapse'] ) ) {
$options['footnotation_collapse'] = 0;
}

if (!isset($options['footnotation_collapse'])) $options['footnotation_collapse'] = 0;

$updated = false;
if ( isset($_POST['submit']) ) {
check_admin_referer('footnotation', 'footnotation-admin');
if (isset($_POST['footnotation_collapse'])) {
if ( isset( $_POST['submit'] ) ) {
check_admin_referer( 'footnotation', 'footnotation-admin' );

if ( isset( $_POST['footnotation_collapse'] ) ) {
$options['footnotation_collapse'] = 1;
} else {
$options['footnotation_collapse'] = 0;
}

if (isset($_POST['footnotation_single'])) {
if ( isset( $_POST['footnotation_single'] ) ) {
$options['footnotation_single'] = 1;
} else {
$options['footnotation_single'] = 0;
}
if (isset($_POST['footnotation_colour'])) {

if ( isset( $_POST['footnotation_colour'] ) ) {
$options['footnotation_colour'] = 1;
} else {
$options['footnotation_colour'] = 0;
}

update_option('footnotation', $options);
update_option( 'footnotation', $options );

$updated = true;
} else {
if ( ! isset( $options['footnotation_collapse'] ) ) {
$options['footnotation_collapse'] = 0;
}
if ( ! isset( $options['footnotation_single'] ) ) {
$options['footnotation_single'] = 0;
}
if ( ! isset( $options['footnotation_colour'] ) ) {
$options['footnotation_colour'] = 0;
}
}
?>
<div class="wrap">
<?php
if ($updated) {
echo "<div id='message' class='updated fade'><p>";
_e('Configuration updated.', footnotation_localisation);
echo "</p></div>";
}
?>
<h2><?php _e('Footnotation options', footnotation_localisation); ?></h2>
<form action="" method="post" id="footnotation-conf">
<br/>
<p>
<input id="footnotation_single" name="footnotation_single" type="checkbox" value="1"<?php if ($options['footnotation_single']==1) echo ' checked'; ?> />
<label for="footnotation_single"><?php _e('Show footnotes only on single posts or pages', footnotation_localisation); ?></label>
</p>

<p>
<input id="footnotation_collapse" name="footnotation_collapse" type="checkbox" value="1"<?php if ($options['footnotation_collapse']==1) echo ' checked'; ?> />
<label for="footnotation_collapse"><?php _e('Collapse footnotes until they are clicked on', footnotation_localisation); ?></label>
</p>

<p>
<input id="footnotation_colour" name="footnotation_colour" type="checkbox" value="1"<?php if ($options['footnotation_colour']==1) echo ' checked'; ?> />
<label for="footnotation_colour"><?php _e('Match footnote marker colour to surrounding text*', footnotation_localisation); ?></label>
</p>

<p>
<small>
<br/>
<hr/>
* Leave unchecked to use your theme’s default link colour.<br/>
<strong>NB</strong> If you are using a caching plugin, you may need to clear your cache for these options to take effect immediately.
</small>
</p>

<p class="submit" style="text-align: left"><?php wp_nonce_field('footnotation', 'footnotation-admin'); ?><input type="submit" name="submit" value="<?php _e('Save', footnotation_localisation); ?> &raquo;" /></p>
</form>
<?php
if ( $updated ) {
echo "<div id='message' class='updated fade'><p>";
_e( 'Configuration updated.', 'footnotation' );
echo "</p></div>";
}
?>
<h2><?php _e( 'Footnotation options', 'footnotation' ); ?></h2>
<form action="" method="post" id="footnotation-conf">
<br/>
<p>
<input id="footnotation_single" name="footnotation_single" type="checkbox"
value="1"<?php if ( $options['footnotation_single'] == 1 ) {
echo ' checked';
} ?> />
<label for="footnotation_single"><?php _e( 'Show footnotes only on single posts or pages', 'footnotation' ); ?></label>
</p>

<p>
<input id="footnotation_collapse" name="footnotation_collapse" type="checkbox"
value="1"<?php if ( $options['footnotation_collapse'] == 1 ) {
echo ' checked';
} ?> />
<label for="footnotation_collapse"><?php _e( 'Collapse footnotes until they are clicked on', 'footnotation' ); ?></label>
</p>

<p>
<input id="footnotation_colour" name="footnotation_colour" type="checkbox"
value="1"<?php if ( $options['footnotation_colour'] == 1 ) {
echo ' checked';
} ?> />
<label for="footnotation_colour"><?php _e( 'Match footnote marker colour to surrounding text*', 'footnotation' ); ?></label>
</p>

<p>
<small>
<br/>
<hr/>
* Leave unchecked to use your theme’s default link colour.<br/>
<strong>NB</strong> If you are using a caching plugin, you may need to clear your cache for these
options to take effect immediately.
</small>
</p>

<p class="submit" style="text-align: left"><?php wp_nonce_field( 'footnotation', 'footnotation-admin' ); ?>
<input type="submit" name="submit" value="<?php _e( 'Save', 'footnotation' ); ?> &raquo;"/></p>
</form>
</div>
<?php
}

// Converts footnote markup into actual footnotes
function footnotation_convert($content) {
$options = get_option('footnotation');
$collapse = 0;
$single = 0;
$colour = 0;
function footnotation_convert( $content ) {
$options = get_option( 'footnotation' );
$collapse = 0;
$single = 0;
$colour = 0;
$linksingle = false;
if (isset($options['footnotation_collapse'])) $collapse = $options['footnotation_collapse'];
if (isset($options['footnotation_single'])) $single = $options['footnotation_single'];
if (isset($options['footnotation_colour'])) $single = $options['footnotation_colour'];
if (!is_page() && !is_single() && $single) $linksingle = true;

if ( isset( $options['footnotation_collapse'] ) ) {
$collapse = $options['footnotation_collapse'];
}
if ( isset( $options['footnotation_single'] ) ) {
$single = $options['footnotation_single'];
}
if ( isset( $options['footnotation_colour'] ) ) {
$single = $options['footnotation_colour'];
}
if ( ! is_page() && ! is_single() && $single ) {
$linksingle = true;
}

$post_id = get_the_ID();

$n = 1;
$n = 1;
$notes = array();
if (preg_match_all('/\[(\d+\..*?)\]/s', $content, $matches)) {
foreach($matches[0] as $marker) {
$note = preg_replace('/\[\d+\.(.*?)\]/s', '\1', $marker);
$notes[$n] = $note;
if ( preg_match_all( '/\[(\d+\..*?)\]/s', $content, $matches ) ) {
foreach ( $matches[0] as $marker ) {
$note = preg_replace( '/\[\d+\.(.*?)\]/s', '\1', $marker );
$notes[ $n ] = $note;

$singleurl = '';
if ($linksingle) $singleurl = get_permalink();

if ($options['footnotation_colour']) {

$content = str_replace($marker, "<sup class='footnote footnoteblack'><a href='$singleurl#marker-$post_id-$n' id='markerref-$post_id-$n' onclick='return footnotation_show($post_id)'>$n</a></sup>", $content);
$n++;

if ( $linksingle ) {
$singleurl = get_permalink();
}
else
{

$content = str_replace($marker, "<sup class='footnote'><a href='$singleurl#marker-$post_id-$n' id='markerref-$post_id-$n' onclick='return footnotation_show($post_id)'>$n</a></sup>", $content);
$n++;

if ( $options['footnotation_colour'] ) {

$content = str_replace( $marker, "<sup class='footnote footnoteblack'><a href='$singleurl#marker-$post_id-$n' id='markerref-$post_id-$n' onclick='return footnotation_show($post_id)'>$n</a></sup>", $content );
$n ++;

} else {

$content = str_replace( $marker, "<sup class='footnote'><a href='$singleurl#marker-$post_id-$n' id='markerref-$post_id-$n' onclick='return footnotation_show($post_id)'>$n</a></sup>", $content );
$n ++;
}
}

Expand All @@ -177,29 +208,29 @@ function footnotation_convert($content) {
$content .= "\n\n";
// *****************************************************************************************************

if (!$linksingle) {
if ( ! $linksingle ) {
$content .= "<div class='footnotes' id='footnotes-$post_id'>";
$content .= "<div class='footnotedivider'></div>";
if ($collapse) {

if ( $collapse ) {
$content .= "<a href='#' onclick='return footnotation_togglevisible($post_id)' class='footnotetoggle'>";
$content .= "<span class='footnoteshow'>".sprintf(_n('Show %d footnote', 'Show %d footnotes', $n-1, footnotation_localisation), $n-1)."</span>";
$content .= "<span class='footnoteshow'>" . sprintf( _n( 'Show %d footnote', 'Show %d footnotes', $n - 1, 'footnotation' ), $n - 1 ) . "</span>";
$content .= "</a>";

$content .= "<ol style='display: none'>";
} else {
$content .= "<ol>";
}
for($i=1; $i<$n; $i++) {
for ( $i = 1; $i < $n; $i ++ ) {
$content .= "<li id='marker-$post_id-$i'>$notes[$i] <span class='returnkey'><a href='#markerref-$post_id-$i'>&#8629;</a></span></li>";
}
$content .= "</ol>";
$content .= "</div>";
}
}

return($content);
return ( $content );
}

add_action('the_content', 'footnotation_convert', 1);
add_action( 'the_content', 'footnotation_convert', 1 );
?>
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=== Footnotation ===
Contributors: vhbelvadi
Contributors: vhbelvadi, Mista-Flo
Donate link: http://vhbelvadi.com/footnotation/
Tags: essay, academic, footnotes, endnotes, post, writing, editing
Requires at least: 2.0
Expand Down

0 comments on commit f427f64

Please sign in to comment.