git-svn-id: https://plugins.svn.wordpress.org/footnotes/tags/2.1.3@2424470 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
pewgeuges 2020-11-24 11:01:34 +00:00
parent 0520655f1c
commit 9122e5b7ff
14 changed files with 685 additions and 527 deletions

View file

@ -16,8 +16,9 @@
* 2.1.1: combining identical footnotes: fixed dead links 2020-11-14T2233+0100
* 2.1.1: options fixing ref container layout and referrer vertical alignment 2020-11-16T2024+0100
* 2.1.1: option fixing ref container relative position 2020-11-17T0254+0100
* 2.1.2: options for the other hooks 2020-11-19T1849+0100
*
* Last modified 2020-11-18T0138+0100
* Last modified: 2020-11-24T0957+0100
*/
// If called directly, abort:
@ -64,28 +65,40 @@ class MCI_Footnotes_Task {
* @author Stefan Herndler
* @since 1.5.0
*
* Edited for v2.0.5 through v2.0.7 2020-11-02T0330+0100..2020-11-06T1344+0100
* Edited for:
* 2.0.5 through v2.0.7 changes to priority 2020-11-02T0330+0100..2020-11-06T1344+0100
* 2.1.1 add setting for the_content
* 2.1.2 add settings for 4 other hooks 2020-11-19T1248+0100
*
* Explicitly setting all priority to (default) "10" instead of lowest "PHP_INT_MAX",
* especially for the_content, makes the footnotes reference container display
* beneath the content and above other features added by other plugins.
* Setting the_content priority to "10" instead of PHP_INT_MAX i.e. 9223372036854775807
* makes the footnotes reference container display beneath the post and above other
* features added by other plugins, e.g. related post lists and social buttons.
* For YARPP to display related posts below the Footnotes reference container,
* priority needs to be at least 1200.
* Requested by users: <https://wordpress.org/support/topic/change-the-position-5/>
* Documentation: <https://codex.wordpress.org/Plugin_API/#Hook_in_your_Filter>
*
* But this change is suspected to cause issues and needs to be assessed!
* See <https://wordpress.org/support/topic/change-the-position-5/#post-13612697>
* Default remains PHP_INT_MAX.
* PHP_INT_MAX cannot be reset by leaving the number box empty. because browsers
* (WebKit) dont allow it, so we must resort to -1.
*/
public function registerHooks() {
// first compute values from settings:
// for now only the_content is supported for customization:
$p_int_TheContentPriority = MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_INT_EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL);
// PHP_INT_MAX can be set using the value -1:
if ( $p_int_TheContentPriority == -1 ) {
$p_int_TheContentPriority = PHP_INT_MAX;
}
// get values from settings:
$p_int_TheTitlePriority = intval(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_INT_EXPERT_LOOKUP_THE_TITLE_PRIORITY_LEVEL));
$p_int_TheContentPriority = intval(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_INT_EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL));
$p_int_TheExcerptPriority = intval(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_INT_EXPERT_LOOKUP_THE_EXCERPT_PRIORITY_LEVEL));
$p_int_WidgetTitlePriority = intval(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_INT_EXPERT_LOOKUP_WIDGET_TITLE_PRIORITY_LEVEL));
$p_int_WidgetTextPriority = intval(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_INT_EXPERT_LOOKUP_WIDGET_TEXT_PRIORITY_LEVEL));
// PHP_INT_MAX can be set by -1:
$p_int_TheTitlePriority = ($p_int_TheTitlePriority == -1) ? PHP_INT_MAX : $p_int_TheTitlePriority ;
$p_int_TheContentPriority = ($p_int_TheContentPriority == -1) ? PHP_INT_MAX : $p_int_TheContentPriority ;
$p_int_TheExcerptPriority = ($p_int_TheExcerptPriority == -1) ? PHP_INT_MAX : $p_int_TheExcerptPriority ;
$p_int_WidgetTitlePriority = ($p_int_WidgetTitlePriority == -1) ? PHP_INT_MAX : $p_int_WidgetTitlePriority;
$p_int_WidgetTextPriority = ($p_int_WidgetTextPriority == -1) ? PHP_INT_MAX : $p_int_WidgetTextPriority ;
// append custom css to the header
add_filter('wp_head', array($this, "wp_head"), PHP_INT_MAX);
@ -93,25 +106,30 @@ class MCI_Footnotes_Task {
add_filter('wp_footer', array($this, "wp_footer"), PHP_INT_MAX);
if (MCI_Footnotes_Convert::toBool(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_BOOL_EXPERT_LOOKUP_THE_TITLE))) {
add_filter('the_title', array($this, "the_title"), PHP_INT_MAX);
}
// SET PRIORITY LEVEL TO CUSTOM FOR PAGE LAYOUT; DEFAULT PHP_INT_MAX:
add_filter('the_title', array($this, "the_title"), $p_int_TheTitlePriority);
}
// custom priority level for reference container relative positioning; default PHP_INT_MAX:
if (MCI_Footnotes_Convert::toBool(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_BOOL_EXPERT_LOOKUP_THE_CONTENT))) {
add_filter('the_content', array($this, "the_content"), $p_int_TheContentPriority);
}
if (MCI_Footnotes_Convert::toBool(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_BOOL_EXPERT_LOOKUP_THE_EXCERPT))) {
add_filter('the_excerpt', array($this, "the_excerpt"), PHP_INT_MAX);
add_filter('the_excerpt', array($this, "the_excerpt"), $p_int_TheExcerptPriority);
}
if (MCI_Footnotes_Convert::toBool(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_BOOL_EXPERT_LOOKUP_WIDGET_TITLE))) {
add_filter('widget_title', array($this, "widget_title"), PHP_INT_MAX);
add_filter('widget_title', array($this, "widget_title"), $p_int_WidgetTitlePriority);
}
if (MCI_Footnotes_Convert::toBool(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_BOOL_EXPERT_LOOKUP_WIDGET_TEXT))) {
add_filter('widget_text', array($this, "widget_text"), PHP_INT_MAX);
add_filter('widget_text', array($this, "widget_text"), $p_int_WidgetTextPriority);
}
// DISABLED the_post HOOK 2020-11-08T1839+0100
// REMOVED the_post HOOK 2020-11-08T1839+0100
//
//
// reset stored footnotes when displaying the header
self::$a_arr_Footnotes = array();
self::$a_bool_AllowLoveMe = true;
@ -134,7 +152,6 @@ class MCI_Footnotes_Task {
?>
<style type="text/css" media="screen">
<?php
echo MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_CUSTOM_CSS);
if (!MCI_Footnotes_Convert::toBool(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_BOOL_REFERENCE_CONTAINER_START_PAGE_ENABLE))) {
echo "\r\n.home .footnotes_reference_container { display: none; }\r\n";
@ -142,22 +159,22 @@ class MCI_Footnotes_Task {
echo '.footnote_tooltip {';
if (!empty($l_str_Color)) {
printf(" color: %s;", $l_str_Color);
printf(" color: %s !important;", $l_str_Color);
}
if (!empty($l_str_Background)) {
printf(" background-color: %s;", $l_str_Background);
printf(" background-color: %s !important;", $l_str_Background);
}
if (!empty($l_int_BorderWidth) && intval($l_int_BorderWidth) > 0) {
printf(" border-width: %dpx; border-style: solid;", $l_int_BorderWidth);
printf(" border-width: %dpx !important; border-style: solid !important;", $l_int_BorderWidth);
}
if (!empty($l_str_BorderColor)) {
printf(" border-color: %s;", $l_str_BorderColor);
printf(" border-color: %s !important;", $l_str_BorderColor);
}
if (!empty($l_int_BorderRadius) && intval($l_int_BorderRadius) > 0) {
printf(" border-radius: %dpx;", $l_int_BorderRadius);
printf(" border-radius: %dpx !important;", $l_int_BorderRadius);
}
if (!empty($l_int_MaxWidth) && intval($l_int_MaxWidth) > 0) {
printf(" max-width: %dpx;", $l_int_MaxWidth);
printf(" max-width: %dpx !important;", $l_int_MaxWidth);
}
if (!empty($l_str_BoxShadowColor)) {
printf(" -webkit-box-shadow: 2px 2px 11px %s;", $l_str_BoxShadowColor);
@ -165,7 +182,11 @@ class MCI_Footnotes_Task {
printf(" box-shadow: 2px 2px 11px %s;", $l_str_BoxShadowColor);
}
echo '}';
?>
// set custom CSS to override settings, not conversely:
echo MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_CUSTOM_CSS);
?>
</style>
<?php
if (MCI_Footnotes_Convert::toBool(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_BOOL_FOOTNOTES_MOUSE_OVER_BOX_ALTERNATIVE))) {
@ -630,17 +651,24 @@ class MCI_Footnotes_Task {
$l_str_FootnoteId = $l_str_FootnoteIndex;
// The dedicated template enumerating backlinks uses a new placeholder:
// in case the footnote is unique:
$l_str_FootnoteReference = '<a id="footnote_plugin_reference_';
$l_str_FootnoteReference .= $l_int_PostId;
$l_str_FootnoteReference .= "_$l_str_FootnoteId\"";
$l_str_FootnoteReference .= ' class="footnote_backlink"';
$l_str_FootnoteBacklinks = '<a id="footnote_plugin_reference_';
$l_str_FootnoteBacklinks .= $l_int_PostId;
$l_str_FootnoteBacklinks .= "_$l_str_FootnoteId";
$l_str_FootnoteBacklinks .= '" class="footnote_backlink" ';
$l_str_FootnoteBacklinks .= 'onclick="footnote_moveToAnchor_' . $l_int_PostId;
$l_str_FootnoteBacklinks .= "('footnote_plugin_tooltip_$l_int_PostId";
$l_str_FootnoteBacklinks .= "_$l_str_FootnoteId');\">";
$l_str_FootnoteBacklinks .= $l_str_FootnoteArrow;
$l_str_FootnoteBacklinks .= $l_str_FootnoteId . '</a>';
// the click event goes in the table cell:
$l_str_BacklinkEvent = ' onclick="footnote_moveToAnchor_' . $l_int_PostId;
$l_str_BacklinkEvent .= "('footnote_plugin_tooltip_$l_int_PostId";
$l_str_BacklinkEvent .= "_$l_str_FootnoteId');\"";
// the dedicated template enumerating backlinks uses another variable:
$l_str_FootnoteBacklinks = $l_str_FootnoteReference;
$l_str_FootnoteBacklinks .= $l_str_BacklinkEvent;
// finish both single note and notes cluster:
$l_str_FootnoteReference .= ">$l_str_FootnoteArrow$l_str_FootnoteId</a>";
$l_str_FootnoteBacklinks .= ">$l_str_FootnoteArrow$l_str_FootnoteId</a>";
// If that is the only footnote with this text, were done.
@ -660,6 +688,9 @@ class MCI_Footnotes_Task {
// if so, set the further footnote as empty so it won't be displayed later:
self::$a_arr_Footnotes[$l_int_CheckIndex] = "";
// cancel the event altogether:
$l_str_BacklinkEvent = "";
// HERE GOES THE FRAGMENT IDENTIFIER AND THE BACKLINK TOO:
// add the footnote index to the actual index:
@ -667,16 +698,15 @@ class MCI_Footnotes_Task {
// update the footnote ID:
$l_str_FootnoteId = MCI_Footnotes_Convert::Index(($l_int_CheckIndex + 1), MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_FOOTNOTES_COUNTER_STYLE));
// keep on composing the backlinks enumeration:
// resume composing the backlinks enumeration:
$l_str_FootnoteBacklinks .= ', <a id="footnote_plugin_reference_';
$l_str_FootnoteBacklinks .= $l_int_PostId;
$l_str_FootnoteBacklinks .= "_$l_str_FootnoteId";
$l_str_FootnoteBacklinks .= '" class="footnote_backlink" ';
$l_str_FootnoteBacklinks .= 'onclick="footnote_moveToAnchor_' . $l_int_PostId;
$l_str_FootnoteBacklinks .= "('footnote_plugin_tooltip_$l_int_PostId";
$l_str_FootnoteBacklinks .= "_$l_str_FootnoteId');\">";
$l_str_FootnoteBacklinks .= $l_str_FootnoteArrow;
$l_str_FootnoteBacklinks .= $l_str_FootnoteId . '</a>';
$l_str_FootnoteBacklinks .= "_$l_str_FootnoteId');\"";
$l_str_FootnoteBacklinks .= ">$l_str_FootnoteArrow$l_str_FootnoteId</a>";
// this legacy is not used:
//$l_str_FootnoteIndex .= ', ' . MCI_Footnotes_Convert::Index(($l_int_CheckIndex + 1), MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_FOOTNOTES_COUNTER_STYLE));
@ -687,6 +717,8 @@ class MCI_Footnotes_Task {
// replace all placeholders in 'templates/public/reference-container-body.html'
// or in 'templates/public/reference-container-body-combi.html'
// or in 'templates/public/reference-container-body-3column.html'
// or in 'templates/public/reference-container-body-switch.html'
$l_obj_Template->replace(
array(
// placeholder used in all templates:
@ -697,7 +729,9 @@ class MCI_Footnotes_Task {
"id" => MCI_Footnotes_Convert::Index($l_int_FirstFootnoteIndex, MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_FOOTNOTES_COUNTER_STYLE)),
// used in standard layout WITH COMBINED IDENTICALS TURNED ON:
"backlinks" => $l_str_FootnoteBacklinks,
"pointer" => empty($l_str_BacklinkEvent) ? '' : ' pointer',
"event" => $l_str_BacklinkEvent,
"backlinks" => empty($l_str_BacklinkEvent) ? $l_str_FootnoteBacklinks : $l_str_FootnoteReference,
// Legacy placeholders for use in legacy layout templates:
"arrow" => $l_str_FootnoteArrow,