Skip to content

Commit

Permalink
Better Footnotes v1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nash-ye committed Jun 7, 2020
1 parent bc1bf87 commit 1b05e32
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 1,479 deletions.
Binary file modified locales/better-footnotes-ar.mo
Binary file not shown.
1,464 changes: 23 additions & 1,441 deletions locales/better-footnotes-ar.po

Large diffs are not rendered by default.

37 changes: 23 additions & 14 deletions locales/better-footnotes.pot
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
msgid ""
msgstr ""
"Project-Id-Version: Better Footnotes v1.2\n"
"Project-Id-Version: Better Footnotes v1.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-05-24 23:53+0300\n"
"PO-Revision-Date: 2020-05-24 23:53+0300\n"
"POT-Creation-Date: 2020-06-08 01:31+0300\n"
"PO-Revision-Date: 2020-06-08 01:31+0300\n"
"Last-Translator: \n"
"Language-Team: Nashwan Doaqan <nashwan.doaqan@gmail.com>\n"
"Language: en\n"
Expand Down Expand Up @@ -31,42 +31,54 @@ msgid "You do not have sufficient permissions to access this page."
msgstr ""

#: src/BetterFootnotes/src/Admin.php:93
msgid "Strings"
msgid "General"
msgstr ""

#: src/BetterFootnotes/src/Admin.php:100
msgid "Footnote Symbol"
msgid "Auto Append"
msgstr ""

#: src/BetterFootnotes/src/Admin.php:113
msgid "Scrolling"
msgid "Strings"
msgstr ""

#: src/BetterFootnotes/src/Admin.php:120
msgid "Footnote Symbol"
msgstr ""

#: src/BetterFootnotes/src/Admin.php:133
msgid "Scrolling"
msgstr ""

#: src/BetterFootnotes/src/Admin.php:140
msgid "Footnotes Scroll Gap"
msgstr ""

#: src/BetterFootnotes/src/Admin.php:132
#: src/BetterFootnotes/src/Admin.php:152
msgid "Footnotes Scroll Speed"
msgstr ""

#: src/BetterFootnotes/src/Admin.php:172
#: src/BetterFootnotes/src/Admin.php:194
msgid "Symbol used for non-numeric footnotes."
msgstr ""

#: src/BetterFootnotes/src/Admin.php:177
#: src/BetterFootnotes/src/Admin.php:199
msgid "Append the footnotes list to post content automatically."
msgstr ""

#: src/BetterFootnotes/src/Admin.php:205
msgid ""
"Use this if you have a fixed component on top of the viewport of your site. "
"This can be dynamically set (see documentation)."
msgstr ""

#: src/BetterFootnotes/src/Admin.php:182
#: src/BetterFootnotes/src/Admin.php:210
msgid ""
"Adjusts the scroll animation speed when a footnote is clicked. (0 For no "
"animation)."
msgstr ""

#: src/BetterFootnotes/src/Main.php:154
#: src/BetterFootnotes/src/Main.php:156
msgid "References"
msgstr ""

Expand Down Expand Up @@ -841,9 +853,6 @@ msgstr ""
#~ msgid "Product Info"
#~ msgstr "معلومات المنتج"

#~ msgid "General"
#~ msgstr "عام"

#~ msgid "Mobile Model"
#~ msgstr "الطراز"

Expand Down
4 changes: 2 additions & 2 deletions main.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* Plugin Name: Better Footnotes
* Description: Simple yet powerful footnotes integration on your WordPress site.
* Version: 1.2
* Version: 1.3
* Author: Nashwan Doaqan
* Author URI: https://profiles.wordpress.org/alex-ye/
* Text Domain: better-footnotes
Expand All @@ -17,7 +17,7 @@
* @var float
* @since 1.0
*/
define('BetterFootnotes\PLUGIN_VERSION', '1.2');
define('BetterFootnotes\PLUGIN_VERSION', '1.3');

/**
* Plugin's codename.
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
=== Better Footnotes ===
Contributors: alex-ye
Tags: footnote, footnotes, bibliography, references
Tags: footnote, footnotes, bibliography, references, notes
Requires at least: 4.0
Tested up to: 5.4.1
Requires PHP: 7.0
Stable tag: 1.2
Stable tag: 1.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Donate link: https://www.patreon.com/nash1ye
Expand Down Expand Up @@ -53,6 +53,9 @@ Developers can contribute to the source code on the [Github Repository](https://

== Changelog ==

= 1.3 =
* Add "Auto Append" setting.

= 1.2 =
* Add TinyMCE footnote button.
* Add "BetterFootnotes\footnoteContent" filter.
Expand All @@ -66,4 +69,4 @@ Developers can contribute to the source code on the [Github Repository](https://
* Switch to a client-side engine to render the footnotes.

= 1.0 =
* The Initial version.
* The Initial version.
50 changes: 39 additions & 11 deletions src/BetterFootnotes/src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ public function registerSettingsFields()
{
register_setting('bfn_opts', 'bfn_opts', [$this, 'validateSettingsField']);

// General
add_settings_section(
'bfn_general',
__('General', 'better-footnotes'),
[$this, 'renderSettingsSection'],
'better_footnotes'
);

add_settings_field(
'auto_append',
__('Auto Append', 'better-footnotes'),
[$this, 'renderSettingsField'],
'better_footnotes',
'bfn_general',
[
'id' => 'bfn_auto_append',
'name' => 'auto_append',
]
);

// Strings
add_settings_section(
'bfn_strings',
Expand All @@ -102,8 +122,8 @@ public function registerSettingsFields()
'better_footnotes',
'bfn_strings',
[
'name' => 'footnote_symbol',
'label_for' => 'bfn_footnote_symbol',
'id' => 'bfn_footnote_symbol',
'name' => 'footnote_symbol',
]
);

Expand All @@ -122,8 +142,8 @@ public function registerSettingsFields()
'better_footnotes',
'bfn_scrolling',
[
'name' => 'scroll_gap',
'label_for' => 'bfn_scroll_gap',
'id' => 'bfn_scroll_gap',
'name' => 'scroll_gap',
]
);

Expand All @@ -134,8 +154,8 @@ public function registerSettingsFields()
'better_footnotes',
'bfn_scrolling',
[
'name' => 'scroll_speed',
'label_for' => 'bfn_scroll_speed',
'id' => 'bfn_scroll_speed',
'name' => 'scroll_speed',
]
);
}
Expand All @@ -160,24 +180,32 @@ public function renderSettingsField($args)
{
$args = array_merge(
[
'name' => '',
'label_for' => '',
'id' => '',
'name' => '',
],
$args
);

$fieldName = sprintf('bfn_opts[%s]', $args['name']);

if ('footnote_symbol' === $args['name']) : ?>
<input type="text" id="<?php echo esc_attr($args['label_for']) ?>" name="bfn_opts[footnote_symbol]" value="<?php echo esc_attr(Options::getOption('footnote_symbol')) ?>" class="regular-text">
<input type="text" id="<?php echo esc_attr($args['id']) ?>" name="<?php echo esc_attr($fieldName) ?>" value="<?php echo esc_attr(Options::getOption($args['name'])) ?>" class="regular-text">
<br>
<span class="description"><?php esc_html_e('Symbol used for non-numeric footnotes.', 'better-footnotes') ?></span>

<?php elseif ('auto_append' === $args['name']) : ?>
<label>
<input type="checkbox" id="<?php echo esc_attr($args['id']) ?>" name="<?php echo esc_attr($fieldName) ?>" value="y" <?php checked('y', Options::getOption($args['name'])) ?>>
<?php esc_html_e('Append the footnotes list to post content automatically.', 'better-footnotes') ?>
</label>

<?php elseif ('scroll_gap' === $args['name']) : ?>
<input type="number" id="<?php echo esc_attr($args['label_for']) ?>" name="bfn_opts[scroll_gap]" value="<?php echo esc_attr(Options::getOption('scroll_gap')) ?>" class="regular-text">
<input type="number" id="<?php echo esc_attr($args['id']) ?>" name="<?php echo esc_attr($fieldName) ?>" value="<?php echo esc_attr(Options::getOption($args['name'])) ?>" class="regular-text">
<br>
<span class="description"><?php esc_html_e('Use this if you have a fixed component on top of the viewport of your site. This can be dynamically set (see documentation).', 'better-footnotes') ?></span>

<?php elseif ('scroll_speed' === $args['name']) : ?>
<input type="number" id="<?php echo esc_attr($args['label_for']) ?>" name="bfn_opts[scroll_speed]" value="<?php echo esc_attr(Options::getOption('scroll_speed')) ?>" class="regular-text">
<input type="number" id="<?php echo esc_attr($args['id']) ?>" name="<?php echo esc_attr($fieldName) ?>" value="<?php echo esc_attr(Options::getOption($args['name'])) ?>" class="regular-text">
<br>
<span class="description"><?php esc_html_e('Adjusts the scroll animation speed when a footnote is clicked. (0 For no animation).', 'better-footnotes') ?></span>
<?php endif;
Expand Down
37 changes: 29 additions & 8 deletions src/BetterFootnotes/src/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function setupHooks()
add_action('wp_enqueue_scripts', [$this, 'registerScripts']);
add_action('wp_enqueue_scripts', [$this, 'enqueueScripts']);

add_filter('the_content', [$this, 'appendFootnotesListToPostContent'], 5);

add_filter('mce_external_languages', [$this, 'filterMceExternalLanguages']);
add_filter('mce_external_plugins', [$this, 'filterMceExternalPlugins']);
add_filter('mce_buttons', [$this, 'filterMceButtons']);
Expand Down Expand Up @@ -154,25 +156,23 @@ public function shortcodeFootnotes($atts)
'title' => __('References', 'better-footnotes'),
'title_tag' => 'h3',
'container' => '',
'post_id' => 0,
],
$atts,
'bfn_footnotes'
);

$atts['post_id'] = (int) $atts['post_id'];
$post = get_post();

if (empty($post)) {
return $output;
}

$atts['title_tag'] = sanitize_html_class($atts['title_tag']);
$atts['container'] = sanitize_html_class($atts['container']);
if (empty($atts['title_tag'])) {
$atts['title_tag'] = 'h3';
}

$post = get_post($atts['post_id']);

if (empty($post)) {
return $output;
}

$output .= '<div id="bfn-footnotes-' . esc_attr($post->ID) . '" class="bfn-footnotes" data-post-id="' . esc_attr($post->ID) . '" data-container="'. esc_attr($atts['container']) .'" style="display: none;">';
if (! empty($atts['title'])) {
$output .= "<{$atts['title_tag']} class='bfn-footnotes-title'>" . $atts['title'] . "</{$atts['title_tag']}>";
Expand All @@ -183,6 +183,27 @@ public function shortcodeFootnotes($atts)
return $output;
}

/**
* Append footnotes list to post content.
*
* @return string
* @since 1.3
*/
public function appendFootnotesListToPostContent($content)
{
$append = ('y' === Options::getOption('auto_append'));

if (! $append) {
return $content;
}

if ($content && has_shortcode($content, 'footnote')) {
$content .= '[footnotes]';
}

return $content;
}

/**
* Add plugin's TinyMCE add-on translations.
*
Expand Down
1 change: 1 addition & 0 deletions src/BetterFootnotes/src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static function getOptions()
{
$defaults = [
'footnote_symbol' => '&sect;',
'auto_append' => 'n',
'scroll_gap' => 0,
'scroll_speed' => 350,
];
Expand Down

0 comments on commit 1b05e32

Please sign in to comment.