Plugin Directory

Changeset 422017


Ignore:
Timestamp:
08/11/2011 06:38:06 AM (15 years ago)
Author:
fd
Message:

v1.3: Added option to collapse footnotes; added option to
only show footnotes on single post/page; add translation
file; added admin configuration page.

Location:
fd-footnotes/trunk
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • fd-footnotes/trunk/fdfootnotes.php

    r372708 r422017  
    55Description: Elegant and easy to use footnotes
    66Author: John Watson
    7 Version: 1.21
     7Version: 1.3
    88Author URI: http://flagrantdisregard.com
    99
     
    2727*/
    2828
     29define('FDFOOTNOTE_TEXTDOMAIN', 'fdfootnote');
     30
     31if (function_exists('load_plugin_textdomain')) {
     32    load_plugin_textdomain(FDFOOTNOTE_TEXTDOMAIN, false, dirname(plugin_basename(__FILE__)).'/languages' );
     33}
     34
     35add_action('admin_menu', 'fdfootnote_config_page');
     36add_action('wp_enqueue_scripts', 'fdfootnote_enqueue_scripts');
     37
     38function fdfootnote_enqueue_scripts() {
     39    if (is_admin()) return;
     40   
     41    wp_enqueue_script('jquery');
     42   
     43    wp_register_script('fdfootnote_script', get_bloginfo('wpurl').'/'.PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/fdfootnotes.js', array(), '1.3');
     44    wp_enqueue_script('fdfootnote_script');
     45}
     46
     47function fdfootnote_config_page() {
     48    global $wpdb;
     49    if ( function_exists('add_submenu_page') )
     50        add_submenu_page('options-general.php',
     51            __('Footnotes', FDFOOTNOTE_TEXTDOMAIN),
     52            __('Footnotes', FDFOOTNOTE_TEXTDOMAIN),
     53            'manage_options', __FILE__, 'fdfootnote_conf');
     54}
     55
     56function fdfootnote_conf() {
     57    $options = get_option('fdfootnote');
     58
     59    if (!isset($options['fdfootnote_collapse'])) $options['fdfootnote_collapse'] = 0;
     60   
     61    $updated = false;
     62    if ( isset($_POST['submit']) ) {
     63        check_admin_referer('fdfootnote', 'fdfootnote-admin');
     64       
     65        if (isset($_POST['fdfootnote_collapse'])) {
     66            $options['fdfootnote_collapse'] = 1;
     67        } else {
     68            $options['fdfootnote_collapse'] = 0;
     69        }
     70
     71        if (isset($_POST['fdfootnote_single'])) {
     72            $options['fdfootnote_single'] = 1;
     73        } else {
     74            $options['fdfootnote_single'] = 0;
     75        }
     76
     77        update_option('fdfootnote', $options);
     78
     79        $updated = true;
     80    }
     81    ?>
     82    <div class="wrap">
     83    <?php
     84    if ($updated) {
     85        echo "<div id='message' class='updated fade'><p>";
     86        _e('Configuration updated.', FDFOOTNOTE_TEXTDOMAIN);
     87        echo "</p></div>";
     88    }
     89    ?>
     90    <h2><?php _e('Footnotes Configuration', FDFOOTNOTE_TEXTDOMAIN); ?></h2>
     91    <form action="" method="post" id="fdfootnote-conf">
     92   
     93    <p>
     94        <input id="fdfootnote_single" name="fdfootnote_single" type="checkbox" value="1"<?php if ($options['fdfootnote_single']==1) echo ' checked'; ?> />
     95        <label for="fdfootnote_single"><?php _e('Only show footnotes on single post/page', FDFOOTNOTE_TEXTDOMAIN); ?></label>
     96    </p>
     97
     98    <p>
     99        <input id="fdfootnote_collapse" name="fdfootnote_collapse" type="checkbox" value="1"<?php if ($options['fdfootnote_collapse']==1) echo ' checked'; ?> />
     100        <label for="fdfootnote_collapse"><?php _e('Collapse footnotes until clicked', FDFOOTNOTE_TEXTDOMAIN); ?></label>
     101    </p>
     102
     103    <p class="submit" style="text-align: left"><?php wp_nonce_field('fdfootnote', 'fdfootnote-admin'); ?><input type="submit" name="submit" value="<?php _e('Save', FDFOOTNOTE_TEXTDOMAIN); ?> &raquo;" /></p>
     104    </form>
     105    </div>
     106    <?php
     107}
     108
    29109// Converts footnote markup into actual footnotes
    30110function fdfootnote_convert($content) {
     111    $options = get_option('fdfootnote');
     112    $collapse = 0;
     113    $single = 0;
     114    $linksingle = false;
     115    if (isset($options['fdfootnote_collapse'])) $collapse = $options['fdfootnote_collapse'];
     116    if (isset($options['fdfootnote_single'])) $single = $options['fdfootnote_single'];
     117    if (!is_page() && !is_single() && $single) $linksingle = true;
     118   
    31119    $post_id = get_the_ID();
    32120
     
    38126            $notes[$n] = $note;
    39127
    40             $content = str_replace($fn, "<sup class='footnote'><a href='#fn-$post_id-$n' id='fnref-$post_id-$n'>$n</a></sup>", $content);
     128            if ($linksingle) $singleurl = get_permalink();
     129           
     130            $content = str_replace($fn, "<sup class='footnote'><a href='$singleurl#fn-$post_id-$n' id='fnref-$post_id-$n' onclick='return fdfootnote_show($post_id)'>$n</a></sup>", $content);
    41131            $n++;
    42132        }
     
    48138        // *****************************************************************************************************
    49139
    50         $content .= "<div class='footnotes'>";
    51         $content .= "<div class='footnotedivider'></div>";
    52         $content .= "<ol>";
    53         for($i=1; $i<$n; $i++) {
    54             $content .= "<li id='fn-$post_id-$i'>$notes[$i] <span class='footnotereverse'><a href='#fnref-$post_id-$i'>&#8617;</a></span></li>";
     140        if (!$linksingle) {
     141            $content .= "<div class='footnotes' id='footnotes-$post_id'>";
     142            $content .= "<div class='footnotedivider'></div>";
     143           
     144            if ($collapse) {
     145                $content .= "<a href='#' onclick='return fdfootnote_togglevisible($post_id)' class='footnotetoggle'>";
     146                $content .= "<span class='footnoteshow'>".sprintf(_n('Show %d footnote', 'Show %d footnotes', $n-1, FDFOOTNOTE_TEXTDOMAIN), $n-1)."</span>";
     147                $content .= "</a>";
     148               
     149                $content .= "<ol style='display: none'>";
     150            } else {
     151                $content .= "<ol>";
     152            }
     153            for($i=1; $i<$n; $i++) {
     154                $content .= "<li id='fn-$post_id-$i'>$notes[$i] <span class='footnotereverse'><a href='#fnref-$post_id-$i'>&#8617;</a></span></li>";
     155            }
     156            $content .= "</ol>";
     157            $content .= "</div>";
    55158        }
    56         $content .= "</ol>";
    57         $content .= "</div>";
    58159    }
    59160
  • fd-footnotes/trunk/readme.txt

    r372708 r422017  
    44Tags: posts, writing, editing, footnotes, endnotes, formatting
    55Requires at least: 2.0
    6 Tested up to: 3.1.1
     6Tested up to: 3.2.1
    77Stable tag: trunk
    88
     
    3232*Note:* Do not include square brackets [] inside the footnotes themselves.
    3333
    34 *Note:* Footnote numbers dont need to be unique but it is recommended,
     34*Note:* Footnote numbers don't need to be unique but it is recommended,
    3535especially if the text is identical for multiple footnotes. If you have
    3636multiple footnotes with the exact same text and number then you’ll get weird
     
    3939== Installation ==
    4040
    41 1. Copy fdfootnotes.php into wp-content/plugins
     411. Copy the fd-footnotes directory into wp-content/plugins
    42421. Activate the plugin through the 'Plugins' menu in WordPress
    4343
     
    4848== Changelog ==
    4949
     50= 1.3 =
     51* Added option for collapsing footnotes into a single line until manually
     52  expanded.
     53* Added option to only show footnotes when viewing a single post/page.
     54* Added translation files. Send .po translation files to me for inclusion
     55  in future releasse. Thanks.
     56
    5057= 1.21 =
    5158* Fixed problem where sometimes WordPress would not correctly add the closing
Note: See TracChangeset for help on using the changeset viewer.