2021-04-26 22:57:04 +01:00
< ? php // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
2021-03-02 03:09:34 +00:00
/**
* Includes the core function of the Plugin - Search and Replace the Footnotes .
*
2021-05-01 21:34:46 +01:00
* @ package footnotes
* @ since 1.5 . 0
* @ since 2.0 . 5 Enable all hoooks by default .
* @ since 2.8 . 0 Rename file from `task.php` to `class-footnotes-parser.php` ,
2021-05-01 19:22:41 +01:00
* move from `class/` sub - directory to `public/` .
2021-03-02 03:09:34 +00:00
*/
2021-05-01 21:38:11 +01:00
2021-05-02 19:33:29 +01:00
declare ( strict_types = 1 );
2021-05-01 21:34:46 +01:00
namespace footnotes\general ;
2021-05-01 21:38:11 +01:00
2021-05-01 21:34:46 +01:00
use footnotes\includes as Includes ;
2021-03-02 03:09:34 +00:00
/**
2021-03-24 21:19:07 +00:00
* Searches and replaces the footnotes and generates the reference container .
2021-03-02 03:09:34 +00:00
*
2021-05-01 21:34:46 +01:00
* @ package footnotes
* @ since 1.5 . 0
* @ since 2.8 . 0 Rename class from `Footnotes_Task` to `Parser` .
2021-03-02 03:09:34 +00:00
*/
2021-05-01 21:34:46 +01:00
class Parser {
2021-03-02 03:09:34 +00:00
/**
2021-03-24 21:19:07 +00:00
* Contains all footnotes found in the searched content .
2021-03-02 03:09:34 +00:00
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
* @ var string []
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:55:38 +01:00
public static array $a_arr_footnotes = array ();
2021-03-02 03:09:34 +00:00
/**
* Flag if the display of 'LOVE FOOTNOTES' is allowed on the current public page .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:55:38 +01:00
public static bool $a_bool_allow_love_me = true ;
2021-03-02 03:09:34 +00:00
/**
* Prefix for the Footnote html element ID .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 8
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:55:38 +01:00
public static string $a_str_prefix = '' ;
2021-03-02 03:09:34 +00:00
/**
2021-03-03 18:58:03 +00:00
* Autoload a . k . a . infinite scroll , or archive view .
2021-03-02 03:09:34 +00:00
*
* As multiple posts are appended to each other , functions and fragment IDs must be disambiguated .
2021-03-03 18:58:03 +00:00
* post ID to make everything unique wrt infinite scroll and archive view .
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.0 . 6
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:55:38 +01:00
public static int $a_int_post_id = 0 ;
2021-03-02 03:09:34 +00:00
/**
2021-03-03 18:58:03 +00:00
* Multiple reference containers in content and widgets .
2021-03-02 03:09:34 +00:00
*
* This ID disambiguates multiple reference containers in a page
* as they may occur when the widget_text hook is active and the page
* is built with Elementor and has an accordion or similar toggle sections .
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.2 . 9
* @ var int Incremented every time after a reference container is inserted .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:55:38 +01:00
public static int $a_int_reference_container_id = 1 ;
2021-03-02 03:09:34 +00:00
/**
2021-03-24 21:19:07 +00:00
* Hard links for AMP compatibility .
2021-03-02 03:09:34 +00:00
*
2021-04-30 18:03:15 +01:00
* A property because used both in { @ see search ()} and { @ see reference_container ()} .
2021-03-02 03:09:34 +00:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.0 . 0
2021-03-03 18:58:03 +00:00
*/
2021-05-02 19:55:38 +01:00
public static bool $a_bool_hard_links_enabled = false ;
2021-03-02 03:09:34 +00:00
/**
2021-03-03 18:58:03 +00:00
* The referrer slug .
*
2021-05-01 21:34:46 +01:00
* @ since 2.3 . 0
* @ var string
2021-03-03 18:58:03 +00:00
*/
2021-04-19 12:15:17 +01:00
public static $a_str_referrer_link_slug = 'r' ;
2021-03-03 18:58:03 +00:00
/**
* The footnote slug .
*
2021-05-01 21:34:46 +01:00
* @ since 2.3 . 0
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ var string
2021-03-03 18:58:03 +00:00
*/
2021-04-19 12:15:17 +01:00
public static $a_str_footnote_link_slug = 'f' ;
2021-03-03 18:58:03 +00:00
/**
* The slug and identifier separator .
*
2021-05-01 21:34:46 +01:00
* @ since 2.3 . 0
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ var string
2021-03-03 18:58:03 +00:00
*/
2021-04-19 12:15:17 +01:00
private static $a_str_link_ids_separator = '+' ;
2021-03-03 18:58:03 +00:00
/**
2021-03-24 21:19:07 +00:00
* Contains the concatenated fragment ID base .
2021-03-03 18:58:03 +00:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.3 . 0
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ var string
2021-03-03 18:58:03 +00:00
*/
2021-04-19 12:15:17 +01:00
public static $a_str_post_container_id_compound = '' ;
2021-03-03 18:58:03 +00:00
/**
* Scroll offset .
2021-03-02 03:09:34 +00:00
*
* Websites may use high fixed headers not contracting at scroll .
* Scroll offset may now need to get into inline CSS .
* Hence it needs to be loaded twice , because priority levels may not match .
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.1 . 4
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:55:38 +01:00
public static int $a_int_scroll_offset = 34 ;
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
/*
2021-03-02 03:09:34 +00:00
* Optional link element for footnote referrers and backlinks
*
* Although widely used for that purpose , hyperlinks are disliked for footnote linking .
* Browsers may need to be prevented from logging these clicks in the browsing history ,
* as logging compromises the usability of the 'return to previous' button in browsers .
* For that purpose , and for scroll animation , this linking is performed by JavaScript .
*
* Link elements raise concerns , so that mitigating their proliferation may be desired .
*
* By contrast , due to an insufficiency in the CSS standard , coloring elements with the
* theme’ s link color requires real link elements and cannot be done with named colors ,
* as CSS does not support 'color: link|hover|active|visited' , after the pseudo - classes
* of the link element .
*
* Yet styling these elements with the link color is not universally preferred , so that
* the very presence of these link elements may need to be avoided .
2021-03-03 18:58:03 +00:00
*/
/**
* The span element name .
*
2021-05-01 21:34:46 +01:00
* @ since 2.3 . 0
* @ todo Remove .
2021-03-03 18:58:03 +00:00
*/
2021-05-02 19:55:38 +01:00
public static string $a_str_link_span = 'span' ;
2021-03-03 18:58:03 +00:00
/**
* The opening tag .
*
2021-05-01 21:34:46 +01:00
* @ since 2.3 . 0
* @ todo Remove .
2021-03-03 18:58:03 +00:00
*/
2021-05-02 19:55:38 +01:00
public static string $a_str_link_open_tag = '' ;
2021-03-03 18:58:03 +00:00
/**
* The closing tag .
*
2021-05-01 21:34:46 +01:00
* @ since 2.3 . 0
* @ todo Remove .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:55:38 +01:00
public static string $a_str_link_close_tag = '' ;
2021-05-01 19:22:41 +01:00
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Dedicated tooltip text .
2021-03-02 03:09:34 +00:00
*
* Tooltips can display another content than the footnote entry
* in the reference container . The trigger is a shortcode in
* the footnote text separating the tooltip text from the note .
* That is consistent with what WordPress does for excerpts .
*/
/**
2021-03-03 18:58:03 +00:00
* The tooltip delimiter shortcode .
*
2021-05-01 21:34:46 +01:00
* @ since 2.5 . 2
* @ var string
2021-03-03 18:58:03 +00:00
*/
2021-04-19 12:15:17 +01:00
public static $a_str_tooltip_shortcode = '[[/tooltip]]' ;
2021-03-03 18:58:03 +00:00
/**
* The tooltip delimiter shortcode length .
*
2021-05-01 21:34:46 +01:00
* @ since 2.5 . 2
2021-03-03 18:58:03 +00:00
*/
2021-05-02 19:55:38 +01:00
public static int $a_int_tooltip_shortcode_length = 12 ;
2021-03-03 18:58:03 +00:00
/**
* Whether to mirror the tooltip text in the reference container .
*
2021-05-01 21:34:46 +01:00
* @ since 2.5 . 2
2021-03-03 18:58:03 +00:00
*/
2021-05-02 19:55:38 +01:00
public static bool $a_bool_mirror_tooltip_text = false ;
2021-03-03 18:58:03 +00:00
/**
2021-03-28 12:41:33 +00:00
* Footnote delimiter start short code .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
* @ since 2.6 . 2 Move from constant to class property .
2021-03-28 12:41:33 +00:00
*/
2021-05-02 19:55:38 +01:00
public static string | int $a_str_start_tag = '' ;
2021-03-28 12:41:33 +00:00
/**
* Footnote delimiter end short code .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
* @ since 2.6 . 2 Move from constant to class property .
2021-03-28 12:41:33 +00:00
*/
2021-05-02 19:55:38 +01:00
public static string | int $a_str_end_tag = '' ;
2021-03-28 12:41:33 +00:00
/**
2021-04-30 18:03:15 +01:00
* Footnote delimiter start short code in RegEx format .
2021-03-28 12:41:33 +00:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.4 . 0
* @ since 2.6 . 2 Move from global constant to class property .
2021-03-28 12:41:33 +00:00
*/
2021-05-02 19:55:38 +01:00
public static ? string $a_str_start_tag_regex = '' ;
2021-03-28 12:41:33 +00:00
/**
2021-04-30 18:03:15 +01:00
* Footnote delimiter end short code in RegEx format .
2021-03-28 12:41:33 +00:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.4 . 0
* @ since 2.6 . 2 Move from global constant to class property .
2021-03-28 12:41:33 +00:00
*/
2021-05-02 19:55:38 +01:00
public static ? string $a_str_end_tag_regex = '' ;
2021-03-28 12:41:33 +00:00
/**
* Footnote delimiter syntax validation enabled .
2021-03-02 03:09:34 +00:00
*
* The algorithm first checks for balanced footnote opening and closing tag short codes .
* The first encountered error triggers the display of a warning below the post title .
*
* Unbalanced short codes have caused significant trouble because they are hard to detect .
2021-04-30 18:03:15 +01:00
* Any compiler or other tool reports syntax errors in the first place . Footnotes ' exception
2021-03-02 03:09:34 +00:00
* is considered a design flaw , and the feature is released as a bug fix after overdue 2.3 . 0
* released in urgency to provide AMP compat before 2021.
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.4 . 0
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:55:38 +01:00
public static bool $a_bool_syntax_error_flag = true ;
2021-03-02 03:09:34 +00:00
2021-04-26 22:57:04 +01:00
/**
* Initialize the class and set its properties .
*
2021-05-01 21:34:46 +01:00
* @ since 2.8 . 0
* @ todo Reorganise dependencies .
* @ todo Move call to `register_hooks()` to { @ see General } .
2021-04-26 22:57:04 +01:00
*/
public function __construct () {
// TODO: Reorg dependencies.
2021-05-02 19:47:58 +01:00
require_once plugin_dir_path ( __DIR__ ) . 'includes/class-config.php' ;
require_once plugin_dir_path ( __DIR__ ) . 'includes/class-convert.php' ;
require_once plugin_dir_path ( __DIR__ ) . 'includes/class-settings.php' ;
require_once plugin_dir_path ( __DIR__ ) . 'includes/class-template.php' ;
2021-04-26 23:04:20 +01:00
2021-05-01 21:34:46 +01:00
// TODO: Move to `General`.
2021-04-26 22:57:04 +01:00
$this -> register_hooks ();
}
2021-04-26 23:04:20 +01:00
2021-03-02 03:09:34 +00:00
/**
2021-04-19 12:24:26 +01:00
* Register WordPress hooks to replace Footnotes in the content of a public page .
2021-03-02 03:09:34 +00:00
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
* @ since 1.5 . 4 Add support for @ see 'the_post' hook .
* @ since 2.0 . 5 Enable all hooks by default .
* @ since 2.1 . 0 Remove @ see 'the_post' support .
* @ todo Move to { @ see General } .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function register_hooks () : void {
2021-03-03 18:58:03 +00:00
// Get values from settings.
2021-05-02 10:45:52 +01:00
$l_int_the_title_priority = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_EXPERT_LOOKUP_THE_TITLE_PRIORITY_LEVEL );
$l_int_the_content_priority = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL );
$l_int_the_excerpt_priority = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_EXPERT_LOOKUP_THE_EXCERPT_PRIORITY_LEVEL );
$l_int_widget_title_priority = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_EXPERT_LOOKUP_WIDGET_TITLE_PRIORITY_LEVEL );
$l_int_widget_text_priority = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_EXPERT_LOOKUP_WIDGET_TEXT_PRIORITY_LEVEL );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// PHP_INT_MAX can be set by -1.
2021-04-19 12:15:17 +01:00
$l_int_the_title_priority = ( - 1 === $l_int_the_title_priority ) ? PHP_INT_MAX : $l_int_the_title_priority ;
$l_int_the_content_priority = ( - 1 === $l_int_the_content_priority ) ? PHP_INT_MAX : $l_int_the_content_priority ;
$l_int_the_excerpt_priority = ( - 1 === $l_int_the_excerpt_priority ) ? PHP_INT_MAX : $l_int_the_excerpt_priority ;
$l_int_widget_title_priority = ( - 1 === $l_int_widget_title_priority ) ? PHP_INT_MAX : $l_int_widget_title_priority ;
$l_int_widget_text_priority = ( - 1 === $l_int_widget_text_priority ) ? PHP_INT_MAX : $l_int_widget_text_priority ;
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Append custom css to the header.
2021-05-02 10:45:52 +01:00
add_filter (
'wp_head' ,
2021-05-02 19:55:38 +01:00
fn () => $this -> footnotes_output_head (),
2021-05-02 10:45:52 +01:00
PHP_INT_MAX
);
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Append the love and share me slug to the footer.
2021-05-02 10:45:52 +01:00
add_filter (
'wp_footer' ,
2021-05-02 19:55:38 +01:00
fn () => $this -> footnotes_output_footer (),
2021-05-02 10:45:52 +01:00
PHP_INT_MAX
);
2021-03-02 03:09:34 +00:00
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_EXPERT_LOOKUP_THE_TITLE ) ) ) {
add_filter (
'the_title' ,
2021-05-02 19:55:38 +01:00
fn ( string $p_str_content ) : string => $this -> footnotes_in_title ( $p_str_content ),
2021-05-02 10:45:52 +01:00
$l_int_the_title_priority
);
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Configurable priority level for reference container relative positioning; default 98.
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_EXPERT_LOOKUP_THE_CONTENT ) ) ) {
add_filter (
'the_content' ,
2021-05-02 19:55:38 +01:00
fn ( string $p_str_content ) : string => $this -> footnotes_in_content ( $p_str_content ),
2021-05-02 10:45:52 +01:00
$l_int_the_content_priority
);
2021-03-02 03:09:34 +00:00
/**
2021-03-03 18:58:03 +00:00
* Hook for category pages .
2021-03-02 03:09:34 +00:00
*
2021-05-01 19:22:41 +01:00
* Category pages can have rich HTML content in a term description with
2021-04-30 18:03:15 +01:00
* article status .
2021-05-01 19:22:41 +01:00
* For this to happen , WordPress ' built - in partial HTML blocker needs to
2021-04-30 18:03:15 +01:00
* be disabled .
2021-05-01 19:22:41 +01:00
*
2021-03-02 03:09:34 +00:00
* @ link https :// docs . woocommerce . com / document / allow - html - in - term - category - tag - descriptions /
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.5 . 0
2021-03-02 03:09:34 +00:00
*/
2021-05-02 10:45:52 +01:00
add_filter (
'term_description' ,
2021-05-02 19:55:38 +01:00
fn ( string $p_str_content ) : string => $this -> footnotes_in_content ( $p_str_content ),
2021-05-02 10:45:52 +01:00
$l_int_the_content_priority
);
2021-03-02 03:09:34 +00:00
/**
2021-03-03 18:58:03 +00:00
* Hook for popup maker popups .
2021-03-02 03:09:34 +00:00
*
* - Bugfix : Hooks : support footnotes in Popup Maker popups , thanks to @ squatcher bug report .
*
* @ reporter @ squatcher
* @ link https :// wordpress . org / support / topic / footnotes - use - in - popup - maker /
2021-03-24 21:19:07 +00:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.5 . 1
2021-03-02 03:09:34 +00:00
*/
2021-05-02 10:45:52 +01:00
add_filter (
'pum_popup_content' ,
2021-05-02 19:55:38 +01:00
fn ( string $p_str_content ) : string => $this -> footnotes_in_content ( $p_str_content ),
2021-05-02 10:45:52 +01:00
$l_int_the_content_priority
);
2021-03-02 03:09:34 +00:00
}
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_EXPERT_LOOKUP_THE_EXCERPT ) ) ) {
2021-04-30 18:03:15 +01:00
/**
* Adds a filter to the excerpt hook .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0 The hook @ see 'get_the_excerpt' is filtered too .
* @ since 1.5 . 5 The hook @ see 'get_the_excerpt' is removed but not documented in changelog or docblock .
* @ since 2.6 . 2 The hook @ see 'get_the_excerpt' is readded when attempting to debug excerpt handling .
* @ since 2.6 . 6 The hook @ see 'get_the_excerpt' is removed again because it seems to cause issues in some themes .
2021-04-30 18:03:15 +01:00
*/
2021-05-02 10:45:52 +01:00
add_filter (
'the_excerpt' ,
2021-05-02 19:55:38 +01:00
fn ( string $p_str_excerpt ) : string => $this -> footnotes_in_excerpt ( $p_str_excerpt ),
2021-05-02 10:45:52 +01:00
$l_int_the_excerpt_priority
);
2021-03-02 03:09:34 +00:00
}
2021-04-14 23:10:29 +00:00
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_EXPERT_LOOKUP_WIDGET_TITLE ) ) ) {
2021-04-30 18:03:15 +01:00
/**
* TODO
*/
2021-05-02 10:45:52 +01:00
add_filter (
'widget_title' ,
2021-05-02 19:55:38 +01:00
fn ( string $p_str_content ) : string => $this -> footnotes_in_widget_title ( $p_str_content ),
2021-05-02 10:45:52 +01:00
$l_int_widget_title_priority
);
2021-03-02 03:09:34 +00:00
}
2021-04-14 23:10:29 +00:00
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_EXPERT_LOOKUP_WIDGET_TEXT ) ) ) {
2021-04-30 18:03:15 +01:00
/**
* TODO
*/
2021-05-02 10:45:52 +01:00
add_filter (
'widget_text' ,
2021-05-02 19:55:38 +01:00
fn ( string $p_str_content ) : string => $this -> footnotes_in_widget_text ( $p_str_content ),
2021-05-02 10:45:52 +01:00
$l_int_widget_text_priority
);
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Reset stored footnotes when displaying the header.
2021-04-19 12:15:17 +01:00
self :: $a_arr_footnotes = array ();
self :: $a_bool_allow_love_me = true ;
2021-03-02 03:09:34 +00:00
}
/**
* Outputs the custom css to the header of the public page .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
* @ todo Refactor to enqueue stylesheets properly in { @ see General } .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function footnotes_output_head () : void {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Insert start tag without switching out of PHP.
2021-03-02 03:09:34 +00:00
echo " \r \n <style type= \" text/css \" media= \" all \" > \r \n " ;
2021-03-24 21:19:07 +00:00
2021-04-30 18:03:15 +01:00
/*
2021-03-23 04:02:07 +00:00
* Enables CSS smooth scrolling .
2021-03-24 21:19:07 +00:00
*
2021-03-23 04:02:07 +00:00
* Native smooth scrolling only works in recent browsers .
*/
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_CSS_SMOOTH_SCROLLING ) ) ) {
2021-03-23 04:02:07 +00:00
echo " html { scroll-behavior: smooth;} \r \n " ;
}
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
/*
* Normalizes the referrers ' vertical alignment and font size .
2021-03-24 21:19:07 +00:00
*
2021-03-02 03:09:34 +00:00
* Cannot be included in external stylesheet , as it is only optional .
* The scope is variable too : referrers only , or all superscript elements .
*/
2021-05-02 10:45:52 +01:00
$l_str_normalize_superscript = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTE_REFERRERS_NORMAL_SUPERSCRIPT );
2021-04-19 12:15:17 +01:00
if ( 'no' !== $l_str_normalize_superscript ) {
if ( 'all' === $l_str_normalize_superscript ) {
2021-03-03 18:58:03 +00:00
echo 'sup {' ;
2021-03-02 03:09:34 +00:00
} else {
2021-03-03 18:58:03 +00:00
echo '.footnote_plugin_tooltip_text {' ;
2021-03-02 03:09:34 +00:00
}
echo " vertical-align: super; font-size: smaller; position: static;} \r \n " ;
}
2021-04-30 18:03:15 +01:00
// Reference container display on home page.
2021-05-02 10:45:52 +01:00
if ( ! Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_START_PAGE_ENABLE ) ) ) {
2021-03-03 18:58:03 +00:00
2021-03-02 03:09:34 +00:00
echo " .home .footnotes_reference_container { display: none; } \r \n " ;
}
2021-04-30 18:03:15 +01:00
// Reference container top and bottom margins.
2021-05-02 10:45:52 +01:00
$l_int_reference_container_top_margin = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_REFERENCE_CONTAINER_TOP_MARGIN );
$l_int_reference_container_bottom_margin = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_REFERENCE_CONTAINER_BOTTOM_MARGIN );
2021-03-03 18:58:03 +00:00
echo '.footnotes_reference_container {margin-top: ' ;
2021-04-19 12:15:17 +01:00
echo empty ( $l_int_reference_container_top_margin ) ? '0' : $l_int_reference_container_top_margin ;
2021-03-03 18:58:03 +00:00
echo 'px !important; margin-bottom: ' ;
2021-04-19 12:15:17 +01:00
echo empty ( $l_int_reference_container_bottom_margin ) ? '0' : $l_int_reference_container_bottom_margin ;
2021-03-02 03:09:34 +00:00
echo " px !important;} \r \n " ;
2021-04-30 18:03:15 +01:00
// Reference container label bottom border.
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_LABEL_BOTTOM_BORDER ) ) ) {
2021-03-03 18:58:03 +00:00
echo '.footnote_container_prepare > ' ;
2021-05-02 10:45:52 +01:00
echo Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_LABEL_ELEMENT );
2021-03-02 03:09:34 +00:00
echo " { border-bottom: 1px solid #aaaaaa !important;} \r \n " ;
}
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Reference container table row borders .
2021-03-02 03:09:34 +00:00
*
2021-03-24 21:19:07 +00:00
* Moving this internal CSS to external using `wp_add_inline_style()` is
* discouraged , because that screws up support , and it is pointless from
* a performance point of view . Moreover , that would cause cache busting
* issues as browsers won’ t reload these style sheets after settings are
* changed while the version string is not .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_ROW_BORDERS_ENABLE ) ) ) {
2021-03-03 18:58:03 +00:00
echo '.footnotes_table, .footnotes_plugin_reference_row {' ;
echo 'border: 1px solid #060606;' ;
2021-03-02 03:09:34 +00:00
echo " !important;} \r \n " ;
2021-03-03 18:58:03 +00:00
// Adapt left padding to the presence of a border.
echo '.footnote_plugin_index, .footnote_plugin_index_combi {' ;
2021-03-02 03:09:34 +00:00
echo " padding-left: 6px !important} \r \n " ;
}
2021-03-03 18:58:03 +00:00
// Ref container first column width and max-width.
2021-05-02 10:45:52 +01:00
$l_bool_column_width_enabled = Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_COLUMN_WIDTH_ENABLED ) );
$l_bool_column_max_width_enabled = Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_COLUMN_MAX_WIDTH_ENABLED ) );
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
if ( $l_bool_column_width_enabled || $l_bool_column_max_width_enabled ) {
2021-03-03 18:58:03 +00:00
echo '.footnote-reference-container { table-layout: fixed; }' ;
echo '.footnote_plugin_index, .footnote_plugin_index_combi {' ;
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
if ( $l_bool_column_width_enabled ) {
2021-05-02 10:45:52 +01:00
$l_int_column_width_scalar = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_BACKLINKS_COLUMN_WIDTH_SCALAR );
$l_str_column_width_unit = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_COLUMN_WIDTH_UNIT );
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
if ( ! empty ( $l_int_column_width_scalar ) ) {
2021-05-02 10:45:52 +01:00
if ( '%' === $l_str_column_width_unit && $l_int_column_width_scalar > 100 ) {
$l_int_column_width_scalar = 100 ;
2021-03-02 03:09:34 +00:00
}
} else {
2021-04-19 12:15:17 +01:00
$l_int_column_width_scalar = 0 ;
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
echo ' width: ' . $l_int_column_width_scalar . $l_str_column_width_unit . ' !important;' ;
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
if ( $l_bool_column_max_width_enabled ) {
2021-05-02 10:45:52 +01:00
$l_int_column_max_width_scalar = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_BACKLINKS_COLUMN_MAX_WIDTH_SCALAR );
$l_str_column_max_width_unit = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_COLUMN_MAX_WIDTH_UNIT );
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
if ( ! empty ( $l_int_column_max_width_scalar ) ) {
2021-05-02 10:45:52 +01:00
if ( '%' === $l_str_column_max_width_unit && $l_int_column_max_width_scalar > 100 ) {
$l_int_column_max_width_scalar = 100 ;
2021-03-02 03:09:34 +00:00
}
} else {
2021-04-19 12:15:17 +01:00
$l_int_column_max_width_scalar = 0 ;
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
echo ' max-width: ' . $l_int_column_max_width_scalar . $l_str_column_max_width_unit . ' !important;' ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
echo " } \r \n " ;
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
// Hard links scroll offset.
2021-05-02 10:45:52 +01:00
self :: $a_bool_hard_links_enabled = Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_HARD_LINKS_ENABLE ) );
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
// Correct hard links enabled status depending on AMP-compatible or alternative reference container enabled status.
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_amp_enabled || 'jquery' !== General :: $a_str_script_mode ) {
2021-04-19 12:15:17 +01:00
self :: $a_bool_hard_links_enabled = true ;
2021-03-02 03:09:34 +00:00
}
2021-05-02 10:45:52 +01:00
self :: $a_int_scroll_offset = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_SCROLL_OFFSET );
2021-04-19 12:15:17 +01:00
if ( self :: $a_bool_hard_links_enabled ) {
2021-03-03 18:58:03 +00:00
echo '.footnote_referrer_anchor, .footnote_item_anchor {bottom: ' ;
2021-04-19 12:15:17 +01:00
echo self :: $a_int_scroll_offset ;
2021-03-02 03:09:34 +00:00
echo " vh;} \r \n " ;
}
2021-04-30 18:03:15 +01:00
// Tooltips.
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_tooltips_enabled ) {
2021-03-02 03:09:34 +00:00
echo '.footnote_tooltip {' ;
2021-04-30 18:03:15 +01:00
// Tooltip appearance: Tooltip font size.
2021-03-02 03:09:34 +00:00
echo ' font-size: ' ;
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_MOUSE_OVER_BOX_FONT_SIZE_ENABLED ) ) ) {
echo Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_FLO_MOUSE_OVER_BOX_FONT_SIZE_SCALAR );
echo Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_MOUSE_OVER_BOX_FONT_SIZE_UNIT );
2021-03-02 03:09:34 +00:00
} else {
echo 'inherit' ;
}
echo ' !important;' ;
2021-04-30 18:03:15 +01:00
// Tooltip Text color.
2021-05-02 10:45:52 +01:00
$l_str_color = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_MOUSE_OVER_BOX_COLOR );
2021-04-19 12:15:17 +01:00
if ( ! empty ( $l_str_color ) ) {
printf ( ' color: %s !important;' , $l_str_color );
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
// Tooltip Background color.
2021-05-02 10:45:52 +01:00
$l_str_background = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_MOUSE_OVER_BOX_BACKGROUND );
2021-04-19 12:15:17 +01:00
if ( ! empty ( $l_str_background ) ) {
printf ( ' background-color: %s !important;' , $l_str_background );
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
// Tooltip Border width.
2021-05-02 10:45:52 +01:00
$l_int_border_width = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_MOUSE_OVER_BOX_BORDER_WIDTH );
if ( ! empty ( $l_int_border_width ) && ( int ) $l_int_border_width > 0 ) {
2021-04-19 12:15:17 +01:00
printf ( ' border-width: %dpx !important; border-style: solid !important;' , $l_int_border_width );
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
// Tooltip Border color.
2021-05-02 10:45:52 +01:00
$l_str_border_color = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_MOUSE_OVER_BOX_BORDER_COLOR );
2021-04-19 12:15:17 +01:00
if ( ! empty ( $l_str_border_color ) ) {
printf ( ' border-color: %s !important;' , $l_str_border_color );
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
// Tooltip Corner radius.
2021-05-02 10:45:52 +01:00
$l_int_border_radius = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_MOUSE_OVER_BOX_BORDER_RADIUS );
if ( ! empty ( $l_int_border_radius ) && ( int ) $l_int_border_radius > 0 ) {
2021-04-19 12:15:17 +01:00
printf ( ' border-radius: %dpx !important;' , $l_int_border_radius );
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
// Tooltip Shadow color.
2021-05-02 10:45:52 +01:00
$l_str_box_shadow_color = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_MOUSE_OVER_BOX_SHADOW_COLOR );
2021-04-19 12:15:17 +01:00
if ( ! empty ( $l_str_box_shadow_color ) ) {
printf ( ' -webkit-box-shadow: 2px 2px 11px %s;' , $l_str_box_shadow_color );
printf ( ' -moz-box-shadow: 2px 2px 11px %s;' , $l_str_box_shadow_color );
printf ( ' box-shadow: 2px 2px 11px %s;' , $l_str_box_shadow_color );
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
// Tooltip position, dimensions and timing.
2021-05-01 21:34:46 +01:00
if ( ! General :: $a_bool_alternative_tooltips_enabled && ! General :: $a_bool_amp_enabled ) {
2021-04-30 18:03:15 +01:00
/*
2021-03-17 15:51:49 +00:00
* Dimensions of jQuery tooltips .
*
2021-04-30 18:03:15 +01:00
* Position and timing of jQuery tooltips are script - defined .
2021-03-03 18:58:03 +00:00
*/
2021-05-02 10:45:52 +01:00
$l_int_max_width = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_MOUSE_OVER_BOX_MAX_WIDTH );
if ( ! empty ( $l_int_max_width ) && ( int ) $l_int_max_width > 0 ) {
2021-04-19 12:15:17 +01:00
printf ( ' max-width: %dpx !important;' , $l_int_max_width );
2021-03-02 03:09:34 +00:00
}
echo " } \r \n " ;
2021-03-17 15:51:49 +00:00
2021-03-02 03:09:34 +00:00
} else {
2021-04-30 18:03:15 +01:00
// AMP-compatible and alternative tooltips.
2021-03-02 03:09:34 +00:00
echo " } \r \n " ;
2021-04-30 18:03:15 +01:00
// Dimensions.
2021-05-02 10:45:52 +01:00
$l_int_alternative_tooltip_width = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_WIDTH );
2021-03-03 18:58:03 +00:00
echo '.footnote_tooltip.position {' ;
2021-03-18 18:00:42 +00:00
echo ' width: max-content; ' ;
2021-03-17 15:51:49 +00:00
2021-03-03 18:58:03 +00:00
// Set also as max-width wrt short tooltip shrinking.
2021-04-19 12:15:17 +01:00
echo ' max-width: ' . $l_int_alternative_tooltip_width . 'px;' ;
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
// Position.
2021-05-02 10:45:52 +01:00
$l_str_alternative_position = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_POSITION );
$l_int_offset_x = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_OFFSET_X );
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
if ( 'top left' === $l_str_alternative_position || 'bottom left' === $l_str_alternative_position ) {
2021-05-02 10:45:52 +01:00
echo ' right: ' . ( empty ( $l_int_offset_x ) ? 0 : $l_int_offset_x ) . 'px;' ;
2021-03-02 03:09:34 +00:00
} else {
2021-05-02 10:45:52 +01:00
echo ' left: ' . ( empty ( $l_int_offset_x ) ? 0 : $l_int_offset_x ) . 'px;' ;
2021-03-02 03:09:34 +00:00
}
2021-05-02 10:45:52 +01:00
$l_int_offset_y = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_OFFSET_Y );
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
if ( 'top left' === $l_str_alternative_position || 'top right' === $l_str_alternative_position ) {
2021-05-02 10:45:52 +01:00
echo ' bottom: ' . ( empty ( $l_int_offset_y ) ? 0 : $l_int_offset_y ) . 'px;' ;
2021-03-02 03:09:34 +00:00
} else {
2021-05-02 10:45:52 +01:00
echo ' top: ' . ( empty ( $l_int_offset_y ) ? 0 : $l_int_offset_y ) . 'px;' ;
2021-03-02 03:09:34 +00:00
}
echo " } \r \n " ;
2021-04-30 18:03:15 +01:00
// Timing.
2021-05-02 10:45:52 +01:00
$l_int_fade_in_delay = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_MOUSE_OVER_BOX_FADE_IN_DELAY );
$l_int_fade_in_delay = empty ( $l_int_fade_in_delay ) ? '0' : $l_int_fade_in_delay ;
$l_int_fade_in_duration = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_MOUSE_OVER_BOX_FADE_IN_DURATION );
$l_int_fade_in_duration = empty ( $l_int_fade_in_duration ) ? '0' : $l_int_fade_in_duration ;
$l_int_fade_out_delay = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_MOUSE_OVER_BOX_FADE_OUT_DELAY );
$l_int_fade_out_delay = empty ( $l_int_fade_out_delay ) ? '0' : $l_int_fade_out_delay ;
$l_int_fade_out_duration = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_MOUSE_OVER_BOX_FADE_OUT_DURATION );
$l_int_fade_out_duration = empty ( $l_int_fade_out_duration ) ? '0' : $l_int_fade_out_duration ;
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
/*
* AMP - compatible tooltips .
2021-03-17 15:51:49 +00:00
*
* To streamline internal CSS , immutable rules are in external stylesheet .
*/
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_amp_enabled ) {
2021-03-17 15:51:49 +00:00
echo 'span.footnote_referrer > span.footnote_tooltip {' ;
2021-04-19 12:15:17 +01:00
echo 'transition-delay: ' . $l_int_fade_out_delay . 'ms;' ;
echo 'transition-duration: ' . $l_int_fade_out_duration . 'ms;' ;
2021-03-17 15:51:49 +00:00
echo " } \r \n " ;
2021-03-16 22:57:27 +00:00
echo 'span.footnote_referrer:focus-within > span.footnote_tooltip, span.footnote_referrer:hover > span.footnote_tooltip {' ;
2021-04-19 12:15:17 +01:00
echo 'transition-delay: ' . $l_int_fade_in_delay . 'ms;' ;
echo 'transition-duration: ' . $l_int_fade_in_duration . 'ms;' ;
2021-03-17 15:51:49 +00:00
echo " } \r \n " ;
2021-04-30 18:03:15 +01:00
/*
2021-04-10 20:02:10 +01:00
* Alternative tooltips .
*
* To streamline internal CSS , immutable rules are in external stylesheet .
*/
2021-03-16 22:57:27 +00:00
} else {
2021-03-17 15:51:49 +00:00
echo '.footnote_tooltip.hidden {' ;
2021-04-19 12:15:17 +01:00
echo 'transition-delay: ' . $l_int_fade_out_delay . 'ms;' ;
echo 'transition-duration: ' . $l_int_fade_out_duration . 'ms;' ;
2021-03-17 15:51:49 +00:00
echo " } \r \n " ;
2021-03-17 02:22:27 +00:00
echo '.footnote_tooltip.shown {' ;
2021-04-19 12:15:17 +01:00
echo 'transition-delay: ' . $l_int_fade_in_delay . 'ms;' ;
echo 'transition-duration: ' . $l_int_fade_in_duration . 'ms;' ;
2021-03-17 15:51:49 +00:00
echo " } \r \n " ;
2021-03-16 22:57:27 +00:00
}
2021-03-02 03:09:34 +00:00
}
}
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Custom CSS .
2021-03-02 03:09:34 +00:00
*
* Set custom CSS to override settings , not conversely .
* Legacy Custom CSS is used until it’ s set to disappear after dashboard tab migration .
*/
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_CUSTOM_CSS_LEGACY_ENABLE ) ) ) {
echo Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_CUSTOM_CSS );
2021-03-03 18:58:03 +00:00
echo " \r \n " ;
2021-03-02 03:09:34 +00:00
}
2021-05-02 10:45:52 +01:00
echo Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_CUSTOM_CSS_NEW );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Insert end tag without switching out of PHP.
2021-03-02 03:09:34 +00:00
echo " \r \n </style> \r \n " ;
2021-04-30 18:03:15 +01:00
/*
2021-03-02 03:09:34 +00:00
* Alternative tooltip implementation relying on plain JS and CSS transitions .
*
2021-03-03 18:58:03 +00:00
* The script for alternative tooltips is printed formatted , not minified ,
* for transparency . It isn’ t indented though ( the PHP open tag neither ) .
2021-03-02 03:09:34 +00:00
*/
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_alternative_tooltips_enabled ) {
2021-03-03 18:58:03 +00:00
// Start internal script.
2021-03-02 03:09:34 +00:00
?>
< script content = " text/javascript " >
2021-03-03 18:58:03 +00:00
function footnote_tooltip_show ( footnote_tooltip_id ) {
document . getElementById ( footnote_tooltip_id ) . classList . remove ( 'hidden' );
document . getElementById ( footnote_tooltip_id ) . classList . add ( 'shown' );
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
function footnote_tooltip_hide ( footnote_tooltip_id ) {
document . getElementById ( footnote_tooltip_id ) . classList . remove ( 'shown' );
document . getElementById ( footnote_tooltip_id ) . classList . add ( 'hidden' );
2021-03-02 03:09:34 +00:00
}
</ script >
2021-02-26 14:40:23 +00:00
< ? php
2021-04-10 20:02:10 +01:00
// Indenting this PHP open tag would mess up the page source.
2021-03-24 21:19:07 +00:00
// End internal script.
2021-03-02 03:09:34 +00:00
};
}
/**
* Displays the 'LOVE FOOTNOTES' slug if enabled .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function footnotes_output_footer () : void {
2021-05-02 10:45:52 +01:00
if ( 'footer' === Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_POSITION ) ) {
2021-03-03 18:58:03 +00:00
echo $this -> reference_container ();
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Get setting for love and share this plugin.
2021-05-02 10:45:52 +01:00
$l_str_love_me_index = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_LOVE );
2021-03-03 18:58:03 +00:00
// Check if the admin allows to add a link to the footer.
2021-04-19 12:15:17 +01:00
if ( empty ( $l_str_love_me_index ) || 'no' === strtolower ( $l_str_love_me_index ) || ! self :: $a_bool_allow_love_me ) {
2021-03-02 03:09:34 +00:00
return ;
}
2021-03-03 18:58:03 +00:00
// Set a hyperlink to the word "footnotes" in the Love slug.
2021-05-02 10:45:52 +01:00
$l_str_linked_name = sprintf ( '<a href="https://wordpress.org/plugins/footnotes/" target="_blank" style="text-decoration:none;">%s</a>' , \footnotes\includes\Config :: C_STR_PLUGIN_PUBLIC_NAME );
2021-03-03 18:58:03 +00:00
// Get random love me text.
2021-04-19 12:15:17 +01:00
if ( 'random' === strtolower ( $l_str_love_me_index ) ) {
$l_str_love_me_index = 'text-' . wp_rand ( 1 , 7 );
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
switch ( $l_str_love_me_index ) {
2021-03-03 18:58:03 +00:00
// Options named wrt backcompat, simplest is default.
case 'text-1' :
/* Translators: 2: Link to plugin page 1: Love heart symbol */
2021-05-02 10:45:52 +01:00
$l_str_love_me_text = sprintf ( __ ( 'I %2$s %1$s' , 'footnotes' ), $l_str_linked_name , \footnotes\includes\Config :: C_STR_LOVE_SYMBOL );
2021-03-03 18:58:03 +00:00
break ;
case 'text-2' :
/* Translators: %s: Link to plugin page */
2021-04-19 12:15:17 +01:00
$l_str_love_me_text = sprintf ( __ ( 'This website uses the awesome %s plugin.' , 'footnotes' ), $l_str_linked_name );
2021-03-03 18:58:03 +00:00
break ;
case 'text-4' :
/* Translators: 1: Link to plugin page 2: Love heart symbol */
2021-05-02 10:45:52 +01:00
$l_str_love_me_text = sprintf ( '%1$s %2$s' , $l_str_linked_name , \footnotes\includes\Config :: C_STR_LOVE_SYMBOL );
2021-03-03 18:58:03 +00:00
break ;
case 'text-5' :
/* Translators: 1: Love heart symbol 2: Link to plugin page */
2021-05-02 10:45:52 +01:00
$l_str_love_me_text = sprintf ( '%1$s %2$s' , \footnotes\includes\Config :: C_STR_LOVE_SYMBOL , $l_str_linked_name );
2021-03-03 18:58:03 +00:00
break ;
case 'text-6' :
/* Translators: %s: Link to plugin page */
2021-04-19 12:15:17 +01:00
$l_str_love_me_text = sprintf ( __ ( 'This website uses %s.' , 'footnotes' ), $l_str_linked_name );
2021-03-03 18:58:03 +00:00
break ;
case 'text-7' :
/* Translators: %s: Link to plugin page */
2021-04-19 12:15:17 +01:00
$l_str_love_me_text = sprintf ( __ ( 'This website uses the %s plugin.' , 'footnotes' ), $l_str_linked_name );
2021-03-03 18:58:03 +00:00
break ;
case 'text-3' :
default :
/* Translators: %s: Link to plugin page */
2021-05-02 10:45:52 +01:00
$l_str_love_me_text = $l_str_linked_name ;
2021-03-03 18:58:03 +00:00
break ;
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
echo sprintf ( '<div style="text-align:center; color:#acacac;">%s</div>' , $l_str_love_me_text );
2021-03-02 03:09:34 +00:00
}
/**
* Replaces footnotes in the post / page title .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ param string $p_str_content Title .
* @ return string $p_str_content Title with replaced footnotes .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function footnotes_in_title ( string $p_str_content ) : string {
2021-03-03 18:58:03 +00:00
// Appends the reference container if set to "post_end".
2021-04-19 12:15:17 +01:00
return $this -> exec ( $p_str_content , false );
2021-03-02 03:09:34 +00:00
}
/**
* Replaces footnotes in the content of the current page / post .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
2021-04-14 23:10:29 +00:00
*
2021-05-01 21:34:46 +01:00
* @ param string $p_str_content Page / Post content .
* @ return string $p_str_content Content with replaced footnotes .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function footnotes_in_content ( string $p_str_content ) : string {
2021-03-19 23:58:23 +00:00
2021-05-02 10:45:52 +01:00
$l_str_ref_container_position = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_POSITION );
$l_str_footnote_section_shortcode = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTE_SECTION_SHORTCODE );
2021-04-19 12:15:17 +01:00
$l_int_footnote_section_shortcode_length = strlen ( $l_str_footnote_section_shortcode );
2021-04-14 23:10:29 +00:00
2021-05-02 19:58:40 +01:00
if ( ! str_contains ( $p_str_content , ( string ) $l_str_footnote_section_shortcode ) ) {
2021-04-14 23:10:29 +00:00
// phpcs:disable WordPress.PHP.YodaConditions.NotYoda
// Appends the reference container if set to "post_end".
2021-04-19 12:15:17 +01:00
return $this -> exec ( $p_str_content , 'post_end' === $l_str_ref_container_position );
2021-04-14 23:10:29 +00:00
// phpcs:enable WordPress.PHP.YodaConditions.NotYoda
} else {
2021-04-19 12:15:17 +01:00
$l_str_rest_content = $p_str_content ;
$l_arr_sections_raw = array ();
$l_arr_sections_processed = array ();
2021-04-14 23:10:29 +00:00
do {
2021-05-02 19:52:13 +01:00
$l_int_section_end = strpos ( $l_str_rest_content , ( string ) $l_str_footnote_section_shortcode );
2021-04-19 12:15:17 +01:00
$l_arr_sections_raw [] = substr ( $l_str_rest_content , 0 , $l_int_section_end );
$l_str_rest_content = substr ( $l_str_rest_content , $l_int_section_end + $l_int_footnote_section_shortcode_length );
2021-05-02 19:58:40 +01:00
} while ( str_contains ( $l_str_rest_content , ( string ) $l_str_footnote_section_shortcode ) );
2021-04-19 12:15:17 +01:00
$l_arr_sections_raw [] = $l_str_rest_content ;
foreach ( $l_arr_sections_raw as $l_str_section ) {
$l_arr_sections_processed [] = self :: exec ( $l_str_section , true );
2021-04-14 23:10:29 +00:00
}
2021-05-02 10:18:47 +01:00
return implode ( $l_arr_sections_processed );
2021-04-14 23:10:29 +00:00
}
2021-03-02 03:09:34 +00:00
}
/**
2021-04-14 23:10:29 +00:00
* Processes existing excerpt or replaces it with a new one generated on the basis of the post .
2021-03-02 03:09:34 +00:00
*
2021-04-14 23:10:29 +00:00
* The input was already the processed excerpt , no more footnotes to search .
* But issue #65 brought up that manual excerpts can include processable footnotes.
2021-04-30 18:03:15 +01:00
* Default 'manual' is fallback and is backwards - compatible with the initial setup .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ param string $p_str_excerpt Excerpt content .
* @ return string $p_str_excerpt Processed or new excerpt .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function footnotes_in_excerpt ( string $p_str_excerpt ) : string {
2021-05-02 10:45:52 +01:00
$l_str_excerpt_mode = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_IN_EXCERPT );
2021-04-14 23:10:29 +00:00
2021-04-19 12:15:17 +01:00
if ( 'yes' === $l_str_excerpt_mode ) {
return $this -> generate_excerpt_with_footnotes ( $p_str_excerpt );
2021-04-14 23:10:29 +00:00
2021-04-19 12:15:17 +01:00
} elseif ( 'no' === $l_str_excerpt_mode ) {
return $this -> generate_excerpt ( $p_str_excerpt );
2021-04-14 23:10:29 +00:00
} else {
2021-04-19 12:15:17 +01:00
return $this -> exec ( $p_str_excerpt );
2021-03-28 12:41:33 +00:00
}
}
/**
2021-03-31 00:49:17 +00:00
* Generates excerpt on the basis of the post .
2021-03-28 12:41:33 +00:00
*
2021-03-30 07:50:44 +00:00
* Applies full WordPress excerpt processing .
2021-05-01 19:22:41 +01:00
*
2021-03-28 12:41:33 +00:00
* @ link https :// developer . wordpress . org / reference / functions / wp_trim_excerpt /
2021-03-30 07:50:44 +00:00
* @ link https :// developer . wordpress . org / reference / functions / wp_trim_words /
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.6 . 2
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ param string $p_str_content The post .
* @ return string $p_str_content An excerpt of the post .
2021-03-28 12:41:33 +00:00
*/
2021-05-02 19:33:29 +01:00
public function generate_excerpt ( string $p_str_content ) : string {
2021-03-28 12:41:33 +00:00
2021-03-31 00:49:17 +00:00
// Discard existing excerpt and start on the basis of the post.
2021-04-19 12:15:17 +01:00
$p_str_content = get_the_content ( get_the_id () );
2021-03-28 12:41:33 +00:00
2021-04-01 06:48:43 +00:00
// Get footnote delimiter shortcodes and unify them.
2021-04-19 12:15:17 +01:00
$p_str_content = self :: unify_delimiters ( $p_str_content );
2021-03-28 12:41:33 +00:00
// Remove footnotes.
2021-04-19 12:15:17 +01:00
$p_str_content = preg_replace ( '#' . self :: $a_str_start_tag_regex . '.+?' . self :: $a_str_end_tag_regex . '#' , '' , $p_str_content );
2021-03-28 12:41:33 +00:00
// Apply WordPress excerpt processing.
2021-04-19 12:15:17 +01:00
$p_str_content = strip_shortcodes ( $p_str_content );
$p_str_content = excerpt_remove_blocks ( $p_str_content );
2021-03-30 07:50:44 +00:00
// Here the footnotes would be processed as part of WordPress content processing.
2021-04-19 12:15:17 +01:00
$p_str_content = apply_filters ( 'the_content' , $p_str_content );
2021-03-30 07:50:44 +00:00
// According to Advanced Excerpt, this is some kind of precaution against malformed CDATA in RSS feeds.
2021-04-19 12:15:17 +01:00
$p_str_content = str_replace ( ']]>' , ']]>' , $p_str_content );
2021-03-30 07:50:44 +00:00
2021-04-19 12:15:17 +01:00
$l_int_excerpt_length = ( int ) _x ( '55' , 'excerpt_length' );
$l_int_excerpt_length = ( int ) apply_filters ( 'excerpt_length' , $l_int_excerpt_length );
$l_str_excerpt_more = apply_filters ( 'excerpt_more' , ' […]' );
2021-03-30 07:50:44 +00:00
// Function wp_trim_words() calls wp_strip_all_tags() that wrecks the footnotes.
2021-04-19 12:15:17 +01:00
$p_str_content = wp_trim_words ( $p_str_content , $l_int_excerpt_length , $l_str_excerpt_more );
2021-03-30 07:50:44 +00:00
2021-04-19 12:15:17 +01:00
return $p_str_content ;
2021-03-30 07:50:44 +00:00
}
/**
2021-03-31 00:49:17 +00:00
* Generates excerpt with footnotes on the basis of the post .
2021-03-30 07:50:44 +00:00
*
* Does not apply full WordPress excerpt processing .
2021-05-01 19:22:41 +01:00
*
2021-03-30 07:50:44 +00:00
* @ see self :: generate_excerpt ()
* Uses information and some code from Advanced Excerpt .
* @ link https :// wordpress . org / plugins / advanced - excerpt /
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.6 . 3
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ param string $p_str_content The post .
* @ return string $p_str_content An excerpt of the post .
2021-03-30 07:50:44 +00:00
*/
2021-05-02 19:33:29 +01:00
public function generate_excerpt_with_footnotes ( string $p_str_content ) : string {
2021-03-30 07:50:44 +00:00
2021-03-31 00:49:17 +00:00
// Discard existing excerpt and start on the basis of the post.
2021-04-19 12:15:17 +01:00
$p_str_content = get_the_content ( get_the_id () );
2021-03-30 07:50:44 +00:00
2021-04-01 06:48:43 +00:00
// Get footnote delimiter shortcodes and unify them.
2021-04-19 12:15:17 +01:00
$p_str_content = self :: unify_delimiters ( $p_str_content );
2021-03-30 07:50:44 +00:00
// Apply WordPress excerpt processing.
2021-04-19 12:15:17 +01:00
$p_str_content = strip_shortcodes ( $p_str_content );
$p_str_content = excerpt_remove_blocks ( $p_str_content );
2021-03-30 07:50:44 +00:00
// But do not process footnotes at this point; do only this.
2021-04-19 12:15:17 +01:00
$p_str_content = str_replace ( ']]>' , ']]>' , $p_str_content );
2021-03-30 07:50:44 +00:00
// Prepare the excerpt length argument.
2021-04-19 12:15:17 +01:00
$l_int_excerpt_length = ( int ) _x ( '55' , 'excerpt_length' );
$l_int_excerpt_length = ( int ) apply_filters ( 'excerpt_length' , $l_int_excerpt_length );
2021-03-30 07:50:44 +00:00
// Prepare the Read-on string.
2021-04-19 12:15:17 +01:00
$l_str_excerpt_more = apply_filters ( 'excerpt_more' , ' […]' );
2021-03-30 07:50:44 +00:00
// Safeguard the footnotes.
2021-03-31 00:49:17 +00:00
preg_match_all (
2021-04-19 12:15:17 +01:00
'#' . self :: $a_str_start_tag_regex . '.+?' . self :: $a_str_end_tag_regex . '#' ,
$p_str_content ,
$p_arr_saved_footnotes
2021-03-31 00:49:17 +00:00
);
// Prevent the footnotes from altering the excerpt: previously hard-coded '5ED84D6'.
2021-05-02 19:55:38 +01:00
$l_int_placeholder = '@' . wp_rand ( 100_000_000 , 2_147_483_647 ) . '@' ;
2021-04-19 12:15:17 +01:00
$p_str_content = preg_replace (
'#' . self :: $a_str_start_tag_regex . '.+?' . self :: $a_str_end_tag_regex . '#' ,
$l_int_placeholder ,
$p_str_content
2021-03-31 00:49:17 +00:00
);
2021-03-30 07:50:44 +00:00
// Replace line breaking markup with a separator.
2021-04-19 12:15:17 +01:00
$l_str_separator = ' ' ;
$p_str_content = preg_replace ( '#<br *>#' , $l_str_separator , $p_str_content );
$p_str_content = preg_replace ( '#<br */>#' , $l_str_separator , $p_str_content );
$p_str_content = preg_replace ( '#<(p|li|div)[^>]*>#' , $l_str_separator , $p_str_content );
$p_str_content = preg_replace ( '#' . $l_str_separator . '#' , '' , $p_str_content , 1 );
$p_str_content = preg_replace ( '#</(p|li|div) *>#' , '' , $p_str_content );
$p_str_content = preg_replace ( '#[\r\n]#' , '' , $p_str_content );
2021-03-30 07:50:44 +00:00
// To count words like Advanced Excerpt does it.
2021-04-19 12:15:17 +01:00
$l_arr_tokens = array ();
$l_str_output = '' ;
$l_int_counter = 0 ;
2021-03-30 07:50:44 +00:00
// Tokenize into tags and words as in Advanced Excerpt.
2021-04-19 12:15:17 +01:00
preg_match_all ( '#(<[^>]+>|[^<>\s]+)\s*#u' , $p_str_content , $l_arr_tokens );
2021-03-30 07:50:44 +00:00
// Count words following one option of Advanced Excerpt.
2021-04-19 12:15:17 +01:00
foreach ( $l_arr_tokens [ 0 ] as $l_str_token ) {
2021-03-30 07:50:44 +00:00
2021-04-19 12:15:17 +01:00
if ( $l_int_counter >= $l_int_excerpt_length ) {
2021-03-30 07:50:44 +00:00
break ;
}
// If token is not a tag, increment word count.
2021-04-19 12:15:17 +01:00
if ( '<' !== $l_str_token [ 0 ] ) {
$l_int_counter ++ ;
2021-03-30 07:50:44 +00:00
}
// Append the token to the output.
2021-04-19 12:15:17 +01:00
$l_str_output .= $l_str_token ;
2021-03-30 07:50:44 +00:00
}
// Complete unbalanced markup, used by Advanced Excerpt.
2021-04-19 12:15:17 +01:00
$p_str_content = force_balance_tags ( $l_str_output );
2021-03-30 07:50:44 +00:00
// Readd footnotes in excerpt.
2021-04-19 12:15:17 +01:00
$l_int_index = 0 ;
while ( 0 !== preg_match ( '#' . $l_int_placeholder . '#' , $p_str_content ) ) {
$p_str_content = preg_replace (
'#' . $l_int_placeholder . '#' ,
$p_arr_saved_footnotes [ 0 ][ $l_int_index ],
$p_str_content ,
2021-03-31 13:29:10 +00:00
1
2021-03-31 00:49:17 +00:00
);
2021-04-19 12:15:17 +01:00
$l_int_index ++ ;
2021-03-30 07:50:44 +00:00
}
// Append the Read-on string as in wp_trim_words().
2021-04-19 12:15:17 +01:00
$p_str_content .= $l_str_excerpt_more ;
2021-03-30 07:50:44 +00:00
// Process readded footnotes without appending the reference container.
2021-04-19 12:15:17 +01:00
$p_str_content = self :: exec ( $p_str_content , false );
2021-03-30 07:50:44 +00:00
2021-04-19 12:15:17 +01:00
return $p_str_content ;
2021-03-30 07:50:44 +00:00
2021-03-02 03:09:34 +00:00
}
/**
* Replaces footnotes in the widget title .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ param string $p_str_content Widget content .
* @ return string $p_str_content Content with replaced footnotes .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function footnotes_in_widget_title ( string $p_str_content ) : string {
2021-03-03 18:58:03 +00:00
// Appends the reference container if set to "post_end".
2021-04-19 12:15:17 +01:00
return $this -> exec ( $p_str_content , false );
2021-03-02 03:09:34 +00:00
}
/**
* Replaces footnotes in the content of the current widget .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ param string $p_str_content Widget content .
* @ return string $p_str_content Content with replaced footnotes .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function footnotes_in_widget_text ( string $p_str_content ) : string {
2021-03-03 18:58:03 +00:00
// phpcs:disable WordPress.PHP.YodaConditions.NotYoda
// Appends the reference container if set to "post_end".
2021-05-02 10:45:52 +01:00
return $this -> exec ( $p_str_content , 'post_end' === Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_POSITION ) );
2021-03-03 18:58:03 +00:00
// phpcs:enable WordPress.PHP.YodaConditions.NotYoda
2021-03-02 03:09:34 +00:00
}
/**
* Replaces all footnotes that occur in the given content .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ param string $p_str_content Any string that may contain footnotes to be replaced .
* @ param bool $p_bool_output_references Appends the Reference Container to the output if set to true , default true .
* @ param bool $p_bool_hide_footnotes_text Hide footnotes found in the string .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function exec ( string $p_str_content , bool $p_bool_output_references = false , bool $p_bool_hide_footnotes_text = false ) : string {
2021-03-02 03:09:34 +00:00
2021-03-25 03:07:17 +00:00
// Process content.
2021-04-19 12:15:17 +01:00
$p_str_content = $this -> search ( $p_str_content , $p_bool_hide_footnotes_text );
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Reference container customized positioning through shortcode .
2021-03-02 03:09:34 +00:00
*/
2021-05-01 19:22:41 +01:00
2021-03-03 18:58:03 +00:00
// Append the reference container or insert at shortcode.
2021-05-02 10:45:52 +01:00
$l_str_reference_container_position_shortcode = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_POSITION_SHORTCODE );
2021-04-19 12:15:17 +01:00
if ( empty ( $l_str_reference_container_position_shortcode ) ) {
$l_str_reference_container_position_shortcode = '[[references]]' ;
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
if ( $p_bool_output_references ) {
2021-03-02 03:09:34 +00:00
2021-05-02 19:52:13 +01:00
if ( strpos ( $p_str_content , ( string ) $l_str_reference_container_position_shortcode ) ) {
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
$p_str_content = str_replace ( $l_str_reference_container_position_shortcode , $this -> reference_container (), $p_str_content );
2021-03-02 03:09:34 +00:00
} else {
2021-04-19 12:15:17 +01:00
$p_str_content .= $this -> reference_container ();
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Increment the container ID.
2021-04-19 12:15:17 +01:00
self :: $a_int_reference_container_id ++ ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Delete position shortcode should any remain.
2021-04-19 12:15:17 +01:00
$p_str_content = str_replace ( $l_str_reference_container_position_shortcode , '' , $p_str_content );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Take a look if the LOVE ME slug should NOT be displayed on this page/post, remove the short code if found.
2021-05-02 10:45:52 +01:00
if ( strpos ( $p_str_content , \footnotes\includes\Config :: C_STR_NO_LOVE_SLUG ) ) {
2021-04-19 12:15:17 +01:00
self :: $a_bool_allow_love_me = false ;
2021-05-02 10:45:52 +01:00
$p_str_content = str_replace ( \footnotes\includes\Config :: C_STR_NO_LOVE_SLUG , '' , $p_str_content );
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Return the content with replaced footnotes and optional reference container appended.
2021-04-19 12:15:17 +01:00
return $p_str_content ;
2021-03-02 03:09:34 +00:00
}
/**
2021-03-30 07:50:44 +00:00
* Brings the delimiters and unifies their various HTML escapement schemas .
2021-03-24 21:19:07 +00:00
*
2021-03-28 12:41:33 +00:00
* While the Classic Editor ( visual mode ) escapes both pointy brackets ,
* the Block Editor enforces balanced escapement only in code editor mode
* when the opening tag is already escaped . In visual mode , the Block Editor
* does not escape the greater - than sign .
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.1 . 14
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ param string $p_str_content The footnote , including delimiters .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function unify_delimiters ( string $p_str_content ) : string {
2021-03-02 03:09:34 +00:00
2021-03-25 03:07:17 +00:00
// Get footnotes start and end tag short codes.
2021-05-02 10:45:52 +01:00
$l_str_starting_tag = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_SHORT_CODE_START );
$l_str_ending_tag = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_SHORT_CODE_END );
2021-04-19 12:15:17 +01:00
if ( 'userdefined' === $l_str_starting_tag || 'userdefined' === $l_str_ending_tag ) {
2021-05-02 10:45:52 +01:00
$l_str_starting_tag = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_SHORT_CODE_START_USER_DEFINED );
$l_str_ending_tag = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_SHORT_CODE_END_USER_DEFINED );
2021-03-02 03:09:34 +00:00
}
2021-03-24 21:19:07 +00:00
2021-03-25 03:07:17 +00:00
// If any footnotes short code is empty, return the content without changes.
2021-04-19 12:15:17 +01:00
if ( empty ( $l_str_starting_tag ) || empty ( $l_str_ending_tag ) ) {
return $p_str_content ;
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
if ( preg_match ( '#[&"\'<>]#' , $l_str_starting_tag . $l_str_ending_tag ) ) {
2021-03-28 12:41:33 +00:00
2021-04-19 12:15:17 +01:00
$l_str_harmonized_start_tag = '{[(|fnote_stt|)]}' ;
$l_str_harmonized_end_tag = '{[(|fnote_end|)]}' ;
2021-03-25 03:07:17 +00:00
// Harmonize footnotes without escaping any HTML special characters in delimiter shortcodes.
// The footnote has been added in the Block Editor code editor (doesn’ t work in Classic Editor text mode).
2021-04-19 12:15:17 +01:00
$p_str_content = str_replace ( $l_str_starting_tag , $l_str_harmonized_start_tag , $p_str_content );
$p_str_content = str_replace ( $l_str_ending_tag , $l_str_harmonized_end_tag , $p_str_content );
2021-03-25 03:07:17 +00:00
// Harmonize footnotes while escaping HTML special characters in delimiter shortcodes.
// The footnote has been added in the Classic Editor visual mode.
2021-04-19 12:15:17 +01:00
$p_str_content = str_replace ( htmlspecialchars ( $l_str_starting_tag ), $l_str_harmonized_start_tag , $p_str_content );
$p_str_content = str_replace ( htmlspecialchars ( $l_str_ending_tag ), $l_str_harmonized_end_tag , $p_str_content );
2021-03-25 03:07:17 +00:00
// Harmonize footnotes while escaping HTML special characters except greater-than sign in delimiter shortcodes.
// The footnote has been added in the Block Editor visual mode.
2021-04-19 12:15:17 +01:00
$p_str_content = str_replace ( str_replace ( '>' , '>' , htmlspecialchars ( $l_str_starting_tag ) ), $l_str_harmonized_start_tag , $p_str_content );
$p_str_content = str_replace ( str_replace ( '>' , '>' , htmlspecialchars ( $l_str_ending_tag ) ), $l_str_harmonized_end_tag , $p_str_content );
2021-03-25 03:07:17 +00:00
2021-03-28 12:41:33 +00:00
// Assign the delimiter shortcodes.
2021-04-19 12:15:17 +01:00
self :: $a_str_start_tag = $l_str_harmonized_start_tag ;
self :: $a_str_end_tag = $l_str_harmonized_end_tag ;
2021-03-28 12:41:33 +00:00
2021-03-25 10:47:35 +00:00
// Assign the regex-conformant shortcodes.
2021-04-19 12:15:17 +01:00
self :: $a_str_start_tag_regex = '\{\[\(\|fnote_stt\|\)\]\}' ;
self :: $a_str_end_tag_regex = '\{\[\(\|fnote_end\|\)\]\}' ;
2021-03-25 03:07:17 +00:00
2021-03-25 10:47:35 +00:00
} else {
2021-03-28 12:41:33 +00:00
// Assign the delimiter shortcodes.
2021-04-19 12:15:17 +01:00
self :: $a_str_start_tag = $l_str_starting_tag ;
self :: $a_str_end_tag = $l_str_ending_tag ;
2021-03-28 12:41:33 +00:00
2021-03-25 10:47:35 +00:00
// Make shortcodes conform to regex syntax.
2021-04-19 12:15:17 +01:00
self :: $a_str_start_tag_regex = preg_replace ( '#([\(\)\{\}\[\]\|\*\.\?\!])#' , '\\\\$1' , self :: $a_str_start_tag );
self :: $a_str_end_tag_regex = preg_replace ( '#([\(\)\{\}\[\]\|\*\.\?\!])#' , '\\\\$1' , self :: $a_str_end_tag );
2021-03-25 03:07:17 +00:00
}
2021-04-19 12:15:17 +01:00
return $p_str_content ;
2021-03-28 12:41:33 +00:00
}
/**
* Replaces all footnotes in the given content and appends them to the static property .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
* @ todo Refactor to parse DOM rather than using RegEx .
2021-05-02 19:33:29 +01:00
* @ todo Decompose .
2021-03-28 12:41:33 +00:00
*
2021-05-01 21:34:46 +01:00
* @ param string $p_str_content Any content to be parsed for footnotes .
* @ param bool $p_bool_hide_footnotes_text Hide footnotes found in the string .
2021-03-28 12:41:33 +00:00
*/
2021-05-02 19:33:29 +01:00
public function search ( string $p_str_content , bool $p_bool_hide_footnotes_text ) : string {
2021-03-28 12:41:33 +00:00
2021-04-01 06:48:43 +00:00
// Get footnote delimiter shortcodes and unify them.
2021-04-19 12:15:17 +01:00
$p_str_content = self :: unify_delimiters ( $p_str_content );
2021-03-28 12:41:33 +00:00
2021-04-30 18:03:15 +01:00
/*
2021-03-25 03:07:17 +00:00
* Checks for balanced footnote delimiters ; delimiter syntax validation .
2021-03-02 03:09:34 +00:00
*
* If footnotes short codes are unbalanced , and syntax validation is not disabled ,
* prepend a warning to the content ; displays de facto beneath the post title .
*/
2021-05-01 19:22:41 +01:00
2021-03-25 03:07:17 +00:00
// If enabled.
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTE_SHORTCODE_SYNTAX_VALIDATION_ENABLE ) ) ) {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Apply different regex depending on whether start shortcode is double/triple opening parenthesis.
2021-04-19 12:15:17 +01:00
if ( '((' === self :: $a_str_start_tag || '(((' === self :: $a_str_start_tag ) {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// This prevents from catching a script containing e.g. a double opening parenthesis.
2021-04-19 12:15:17 +01:00
$l_str_validation_regex = '#' . self :: $a_str_start_tag_regex . '(((?!' . self :: $a_str_end_tag_regex . ')[^\{\}])*?)(' . self :: $a_str_start_tag_regex . '|$)#s' ;
2021-03-02 03:09:34 +00:00
} else {
2021-03-03 18:58:03 +00:00
// Catch all only if the start shortcode is not double/triple opening parenthesis, i.e. is unlikely to occur in scripts.
2021-04-19 12:15:17 +01:00
$l_str_validation_regex = '#' . self :: $a_str_start_tag_regex . '(((?!' . self :: $a_str_end_tag_regex . ').)*?)(' . self :: $a_str_start_tag_regex . '|$)#s' ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Check syntax and get error locations.
2021-04-19 12:15:17 +01:00
preg_match ( $l_str_validation_regex , $p_str_content , $p_arr_error_location );
if ( empty ( $p_arr_error_location ) ) {
self :: $a_bool_syntax_error_flag = false ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Prevent generating and inserting the warning multiple times.
2021-04-19 12:15:17 +01:00
if ( self :: $a_bool_syntax_error_flag ) {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Get plain text string for error location.
2021-04-19 12:15:17 +01:00
$l_str_error_spot_string = wp_strip_all_tags ( $p_arr_error_location [ 1 ] );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Limit string length to 300 characters.
2021-04-19 12:15:17 +01:00
if ( strlen ( $l_str_error_spot_string ) > 300 ) {
$l_str_error_spot_string = substr ( $l_str_error_spot_string , 0 , 299 ) . '…' ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Compose warning box.
2021-04-19 12:15:17 +01:00
$l_str_syntax_error_warning = '<div class="footnotes_validation_error"><p>' ;
$l_str_syntax_error_warning .= __ ( 'WARNING: unbalanced footnote start tag short code found.' , 'footnotes' );
$l_str_syntax_error_warning .= '</p><p>' ;
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Syntax validation setting in the dashboard under the General settings tab.
/* Translators: 1: General Settings 2: Footnote start and end short codes 3: Check for balanced shortcodes */
2021-04-19 12:15:17 +01:00
$l_str_syntax_error_warning .= sprintf ( __ ( 'If this warning is irrelevant, please disable the syntax validation feature in the dashboard under %1$s > %2$s > %3$s.' , 'footnotes' ), __ ( 'General settings' , 'footnotes' ), __ ( 'Footnote start and end short codes' , 'footnotes' ), __ ( 'Check for balanced shortcodes' , 'footnotes' ) );
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
$l_str_syntax_error_warning .= '</p><p>' ;
$l_str_syntax_error_warning .= __ ( 'Unbalanced start tag short code found before:' , 'footnotes' );
$l_str_syntax_error_warning .= '</p><p>“' ;
$l_str_syntax_error_warning .= $l_str_error_spot_string ;
$l_str_syntax_error_warning .= '”</p></div>' ;
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Prepend the warning box to the content.
2021-04-19 12:15:17 +01:00
$p_str_content = $l_str_syntax_error_warning . $p_str_content ;
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Checked, set flag to false to prevent duplicate warning.
2021-04-19 12:15:17 +01:00
self :: $a_bool_syntax_error_flag = false ;
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
return $p_str_content ;
2021-03-02 03:09:34 +00:00
}
}
2021-04-30 18:03:15 +01:00
/*
2021-03-19 23:58:23 +00:00
* Patch to allow footnotes in input field labels .
*
2021-05-01 19:22:41 +01:00
* When the HTML 'input' element 'value' attribute value is derived from
2021-04-30 18:03:15 +01:00
* 'label' , footnotes need to be removed in the value of 'value' .
2021-03-19 23:58:23 +00:00
*/
2021-04-19 12:15:17 +01:00
$l_str_value_regex = '#(<input [^>]+?value=["\'][^>]+?)' . self :: $a_str_start_tag_regex . '[^>]+?' . self :: $a_str_end_tag_regex . '#' ;
2021-03-19 23:58:23 +00:00
do {
2021-04-19 12:15:17 +01:00
$p_str_content = preg_replace ( $l_str_value_regex , '$1' , $p_str_content );
} while ( preg_match ( $l_str_value_regex , $p_str_content ) );
2021-03-19 23:58:23 +00:00
2021-04-30 18:03:15 +01:00
// Optionally moves footnotes outside at the end of the label element.
2021-05-02 10:45:52 +01:00
$l_str_label_issue_solution = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_LABEL_ISSUE_SOLUTION );
2021-03-23 04:02:07 +00:00
2021-04-19 12:15:17 +01:00
if ( 'move' === $l_str_label_issue_solution ) {
2021-03-23 04:02:07 +00:00
2021-04-19 12:15:17 +01:00
$l_str_move_regex = '#(<label ((?!</label).)+?)(' . self :: $a_str_start_tag_regex . '((?!</label).)+?' . self :: $a_str_end_tag_regex . ')(((?!</label).)*?</label>)#' ;
2021-03-23 04:02:07 +00:00
do {
2021-04-19 12:15:17 +01:00
$p_str_content = preg_replace ( $l_str_move_regex , '$1$5<span class="moved_footnote">$3</span>' , $p_str_content );
} while ( preg_match ( $l_str_move_regex , $p_str_content ) );
2021-03-23 04:02:07 +00:00
}
2021-04-30 18:03:15 +01:00
/*
2021-03-23 04:02:07 +00:00
* Optionally disconnects labels with footnotes from their input element .
*
2021-03-24 21:19:07 +00:00
* This option is discouraged because of accessibility issues .
2021-04-30 18:03:15 +01:00
* This only edits those labels ' ' for ' value that have footnotes ,
2021-03-23 04:02:07 +00:00
* but leaves all other labels ( those without footnotes ) alone .
* @ link https :// wordpress . org / support / topic / compatibility - issue - with - wpforms / #post-14212318
*/
2021-04-19 12:15:17 +01:00
if ( 'disconnect' === $l_str_label_issue_solution ) {
2021-03-23 04:02:07 +00:00
2021-04-19 12:15:17 +01:00
$l_str_disconnect_text = 'optionally-disconnected-from-input-field-to-prevent-toggling-while-clicking-footnote-referrer_' ;
2021-03-23 04:02:07 +00:00
2021-04-19 12:15:17 +01:00
$p_str_content = preg_replace (
'#(<label [^>]+?for=["\'])(((?!</label).)+' . self :: $a_str_start_tag_regex . ')#' ,
'$1' . $l_str_disconnect_text . '$2' ,
$p_str_content
2021-03-23 04:02:07 +00:00
);
}
2021-03-25 03:07:17 +00:00
// Post ID to make everything unique wrt infinite scroll and archive view.
2021-05-02 19:55:38 +01:00
self :: $a_int_post_id = ( int ) get_the_id ();
2021-03-28 12:41:33 +00:00
2021-04-30 18:03:15 +01:00
/*
2021-03-31 00:49:17 +00:00
* Empties the footnotes list every time Footnotes is run when the_content hook is called .
*
* Under certain circumstances , footnotes were duplicated , because the footnotes list was
* not emptied every time before the search algorithm was run . That happened eg when both
* the reference container resides in the widget area , and the YOAST SEO plugin is active
* and calls the hook the_content to generate the Open Graph description , while Footnotes
* is set to avoid missing out on the footnotes ( in the content ) by hooking in as soon as
* the_content is called , whereas at post end Footnotes seems to hook in the_content only
2021-04-30 18:03:15 +01:00
* the time it ' s the blog engine processing the post for display and appending the refs .
2021-03-31 00:49:17 +00:00
*
* Emptying the footnotes list only when the_content hook is called is ineffective
2021-04-30 18:03:15 +01:00
* when footnotes are processed in `generate_excerpt_with_footnotes()` .
2021-03-31 00:49:17 +00:00
* Footnotes duplication is prevented also when resetting the list here .
*/
2021-04-19 12:15:17 +01:00
self :: $a_arr_footnotes = array ();
2021-03-31 00:49:17 +00:00
2021-03-30 07:50:44 +00:00
// Resets the footnote number.
2021-04-19 12:15:17 +01:00
$l_int_footnote_index = 1 ;
2021-03-25 03:07:17 +00:00
// Contains the starting position for the lookup of a footnote.
2021-04-19 12:15:17 +01:00
$l_int_pos_start = 0 ;
2021-03-25 03:07:17 +00:00
2021-03-18 18:00:42 +00:00
/*
2021-03-16 19:41:08 +00:00
* Load footnote referrer template file .
*/
2021-03-19 23:58:23 +00:00
2021-03-31 00:49:17 +00:00
// Set to null in case all templates are unnecessary.
2021-04-19 12:15:17 +01:00
$l_obj_template = null ;
$l_obj_template_tooltip = null ;
2021-03-16 19:41:08 +00:00
// On the condition that the footnote text is not hidden.
2021-04-19 12:15:17 +01:00
if ( ! $p_bool_hide_footnotes_text ) {
2021-03-02 03:09:34 +00:00
2021-03-16 19:41:08 +00:00
// Whether AMP compatibility mode is enabled.
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_amp_enabled ) {
2021-03-16 19:41:08 +00:00
// Whether first clicking a referrer needs to expand the reference container.
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_COLLAPSE ) ) ) {
2021-03-16 19:41:08 +00:00
2021-04-26 11:42:17 +01:00
// Load 'public/partials/amp-footnote-expand.html'.
2021-05-02 10:45:52 +01:00
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'amp-footnote-expand' );
2021-03-16 19:41:08 +00:00
} else {
2021-04-26 11:42:17 +01:00
// Load 'public/partials/amp-footnote.html'.
2021-05-02 10:45:52 +01:00
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'amp-footnote' );
2021-03-16 19:41:08 +00:00
}
2021-05-01 21:34:46 +01:00
} elseif ( General :: $a_bool_alternative_tooltips_enabled ) {
2021-03-16 19:41:08 +00:00
2021-04-26 11:42:17 +01:00
// Load 'public/partials/footnote-alternative.html'.
2021-05-02 10:45:52 +01:00
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'footnote-alternative' );
2021-03-16 19:41:08 +00:00
2021-04-10 20:02:10 +01:00
// Else jQuery tooltips are enabled.
2021-03-02 03:09:34 +00:00
} else {
2021-03-16 19:41:08 +00:00
2021-04-26 11:42:17 +01:00
// Load 'public/partials/footnote.html'.
2021-05-02 10:45:52 +01:00
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'footnote' );
2021-03-02 03:09:34 +00:00
2021-03-18 18:00:42 +00:00
// Load tooltip inline script.
2021-05-02 10:45:52 +01:00
$l_obj_template_tooltip = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'tooltip' );
2021-03-02 03:09:34 +00:00
}
}
2021-03-03 18:58:03 +00:00
// Search footnotes short codes in the content.
2021-03-02 03:09:34 +00:00
do {
2021-03-03 18:58:03 +00:00
// Get first occurrence of the footnote start tag short code.
2021-04-19 12:15:17 +01:00
$i_int_len_content = strlen ( $p_str_content );
if ( $l_int_pos_start > $i_int_len_content ) {
$l_int_pos_start = $i_int_len_content ;
2021-03-03 18:58:03 +00:00
}
2021-04-19 12:15:17 +01:00
$l_int_pos_start = strpos ( $p_str_content , self :: $a_str_start_tag , $l_int_pos_start );
2021-03-03 18:58:03 +00:00
// No short code found, stop here.
2021-04-19 12:15:17 +01:00
if ( ! $l_int_pos_start ) {
2021-03-02 03:09:34 +00:00
break ;
}
2021-03-03 18:58:03 +00:00
// Get first occurrence of the footnote end tag short code.
2021-04-19 12:15:17 +01:00
$l_int_pos_end = strpos ( $p_str_content , self :: $a_str_end_tag , $l_int_pos_start );
2021-03-03 18:58:03 +00:00
// No short code found, stop here.
2021-04-19 12:15:17 +01:00
if ( ! $l_int_pos_end ) {
2021-03-02 03:09:34 +00:00
break ;
}
2021-03-03 18:58:03 +00:00
// Calculate the length of the footnote.
2021-04-19 12:15:17 +01:00
$l_int_length = $l_int_pos_end - $l_int_pos_start ;
2021-03-03 18:58:03 +00:00
// Get footnote text.
2021-04-19 12:15:17 +01:00
$l_str_footnote_text = substr ( $p_str_content , $l_int_pos_start + strlen ( self :: $a_str_start_tag ), $l_int_length - strlen ( self :: $a_str_start_tag ) );
2021-03-03 18:58:03 +00:00
// Get tooltip text if present.
2021-05-02 10:45:52 +01:00
self :: $a_str_tooltip_shortcode = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_TOOLTIP_EXCERPT_DELIMITER );
2021-04-19 12:15:17 +01:00
self :: $a_int_tooltip_shortcode_length = strlen ( self :: $a_str_tooltip_shortcode );
2021-05-02 19:52:13 +01:00
$l_int_tooltip_text_length = strpos ( $l_str_footnote_text , ( string ) self :: $a_str_tooltip_shortcode );
2021-05-02 10:45:52 +01:00
$l_bool_has_tooltip_text = ( bool ) $l_int_tooltip_text_length ;
$l_str_tooltip_text = $l_bool_has_tooltip_text ? substr ( $l_str_footnote_text , 0 , $l_int_tooltip_text_length ) : '' ;
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* URL line wrapping for Unicode non conformant browsers .
2021-03-02 03:09:34 +00:00
*
* Despite Unicode recommends to line - wrap URLs at slashes , and Firefox follows
* the Unicode standard , Chrome does not , making long URLs hang out of tooltips
* or extend reference containers , so that the end is hidden outside the window
* and may eventually be viewed after we scroll horizontally or zoom out . It is
* up to the web page to make URLs breaking anywhere by wrapping them in a span
* that is assigned appropriate CSS properties and values .
* @ see css / public . css
*
* The value of an href argument may have leading ( and trailing ) space .
* @ link https :// webmasters . stackexchange . com / questions / 93540 / are - spaces - in - href - valid
* Needs to replicate the relevant negative lookbehind at least with one and with two spaces .
* Note : The WordPress blog engine edits these values , cropping these leading / trailing spaces .
2021-04-30 18:03:15 +01:00
*
* TODO : Split into own method .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTE_URL_WRAP_ENABLED ) ) ) {
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
$l_str_footnote_text = preg_replace (
2021-03-02 03:09:34 +00:00
'#(?<![-\w\.!~\*\'\(\);]=[\'"])(?<![-\w\.!~\*\'\(\);]=[\'"] )(?<![-\w\.!~\*\'\(\);]=[\'"] )(?<![-\w\.!~\*\'\(\);]=)(?<!/)((ht|f)tps?://[^\\s<]+)#' ,
'<span class="footnote_url_wrap">$1</span>' ,
2021-04-19 12:15:17 +01:00
$l_str_footnote_text
2021-03-02 03:09:34 +00:00
);
}
2021-03-03 18:58:03 +00:00
// Text to be displayed instead of the footnote.
2021-04-19 12:15:17 +01:00
$l_str_footnote_replace_text = '' ;
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Whether hard links are enabled.
2021-04-19 12:15:17 +01:00
if ( self :: $a_bool_hard_links_enabled ) {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Get the configurable parts.
2021-05-02 10:45:52 +01:00
self :: $a_str_referrer_link_slug = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERRER_FRAGMENT_ID_SLUG );
self :: $a_str_footnote_link_slug = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTE_FRAGMENT_ID_SLUG );
self :: $a_str_link_ids_separator = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_HARD_LINK_IDS_SEPARATOR );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Streamline ID concatenation.
2021-04-19 12:15:17 +01:00
self :: $a_str_post_container_id_compound = self :: $a_str_link_ids_separator ;
self :: $a_str_post_container_id_compound .= self :: $a_int_post_id ;
self :: $a_str_post_container_id_compound .= self :: $a_str_link_ids_separator ;
self :: $a_str_post_container_id_compound .= self :: $a_int_reference_container_id ;
self :: $a_str_post_container_id_compound .= self :: $a_str_link_ids_separator ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Display the footnote referrers and the tooltips.
2021-04-19 12:15:17 +01:00
if ( ! $p_bool_hide_footnotes_text ) {
2021-05-02 10:45:52 +01:00
$l_int_index = Includes\Convert :: index ( $l_int_footnote_index , Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_COUNTER_STYLE ) );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Display only a truncated footnote text if option enabled.
2021-05-02 10:45:52 +01:00
$l_bool_enable_excerpt = Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_MOUSE_OVER_BOX_EXCERPT_ENABLED ) );
$l_int_max_length = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_MOUSE_OVER_BOX_EXCERPT_LENGTH );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Define excerpt text as footnote text by default.
2021-04-19 12:15:17 +01:00
$l_str_excerpt_text = $l_str_footnote_text ;
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Tooltip truncation .
2021-03-02 03:09:34 +00:00
*
* If the tooltip truncation option is enabled , it’ s done based on character count ,
* and a trailing incomplete word is cropped .
* This is equivalent to the WordPress default excerpt generation , i . e . without a
* custom excerpt and without a delimiter . But WordPress does word count , usually 55.
*/
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_tooltips_enabled && $l_bool_enable_excerpt ) {
2021-04-19 12:15:17 +01:00
$l_str_dummy_text = wp_strip_all_tags ( $l_str_footnote_text );
if ( is_int ( $l_int_max_length ) && strlen ( $l_str_dummy_text ) > $l_int_max_length ) {
$l_str_excerpt_text = substr ( $l_str_dummy_text , 0 , $l_int_max_length );
$l_str_excerpt_text = substr ( $l_str_excerpt_text , 0 , strrpos ( $l_str_excerpt_text , ' ' ) );
$l_str_excerpt_text .= ' … <' ;
$l_str_excerpt_text .= self :: $a_bool_hard_links_enabled ? 'a' : 'span' ;
$l_str_excerpt_text .= ' class="footnote_tooltip_continue" ' ;
2021-03-19 23:58:23 +00:00
2021-03-28 12:41:33 +00:00
// If AMP compatibility mode is enabled.
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_amp_enabled ) {
2021-03-28 12:41:33 +00:00
// If the reference container is also collapsed by default.
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_COLLAPSE ) ) ) {
2021-04-19 12:15:17 +01:00
$l_str_excerpt_text .= ' on="tap:footnote_references_container_' ;
$l_str_excerpt_text .= self :: $a_int_post_id . '_' . self :: $a_int_reference_container_id ;
$l_str_excerpt_text .= '.toggleClass(class=collapsed, force=false),footnotes_container_button_plus_' ;
$l_str_excerpt_text .= self :: $a_int_post_id . '_' . self :: $a_int_reference_container_id ;
$l_str_excerpt_text .= '.toggleClass(class=collapsed, force=true),footnotes_container_button_minus_' ;
$l_str_excerpt_text .= self :: $a_int_post_id . '_' . self :: $a_int_reference_container_id ;
$l_str_excerpt_text .= '.toggleClass(class=collapsed, force=false)"' ;
2021-03-28 12:41:33 +00:00
}
} else {
// Don’ t add onclick event in AMP compatibility mode.
2021-04-15 05:09:23 +01:00
// Reverted wrong linting.
2021-04-19 12:15:17 +01:00
$l_str_excerpt_text .= ' onclick="footnote_moveToReference_' . self :: $a_int_post_id ;
$l_str_excerpt_text .= '_' . self :: $a_int_reference_container_id ;
$l_str_excerpt_text .= '(\'footnote_plugin_reference_' . self :: $a_int_post_id ;
$l_str_excerpt_text .= '_' . self :: $a_int_reference_container_id ;
$l_str_excerpt_text .= " _ $l_int_index '); \" " ;
2021-03-28 12:41:33 +00:00
}
2021-03-03 18:58:03 +00:00
// If enabled, add the hard link fragment ID.
2021-04-19 12:15:17 +01:00
if ( self :: $a_bool_hard_links_enabled ) {
2021-03-03 18:58:03 +00:00
2021-04-19 12:15:17 +01:00
$l_str_excerpt_text .= ' href="#' ;
$l_str_excerpt_text .= self :: $a_str_footnote_link_slug ;
$l_str_excerpt_text .= self :: $a_str_post_container_id_compound ;
$l_str_excerpt_text .= $l_int_index ;
$l_str_excerpt_text .= '"' ;
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
$l_str_excerpt_text .= '>' ;
2021-03-02 03:09:34 +00:00
2021-05-01 19:22:41 +01:00
// Configurable read-on button label.
2021-05-02 10:45:52 +01:00
$l_str_excerpt_text .= Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_TOOLTIP_READON_LABEL );
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
$l_str_excerpt_text .= self :: $a_bool_hard_links_enabled ? '</a>' : '</span>' ;
2021-03-02 03:09:34 +00:00
}
}
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Referrers element superscript or baseline .
2021-03-02 03:09:34 +00:00
*
2021-03-24 21:19:07 +00:00
* Define the HTML element to use for the referrers .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_REFERRER_SUPERSCRIPT_TAGS ) ) ) {
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
$l_str_sup_span = 'sup' ;
2021-03-02 03:09:34 +00:00
} else {
2021-04-19 12:15:17 +01:00
$l_str_sup_span = 'span' ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Whether hard links are enabled.
2021-04-19 12:15:17 +01:00
if ( self :: $a_bool_hard_links_enabled ) {
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
self :: $a_str_link_span = 'a' ;
self :: $a_str_link_close_tag = '</a>' ;
// Self::$a_str_link_open_tag will be defined as needed.
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Compose hyperlink address (leading space is in template).
2021-04-19 12:15:17 +01:00
$l_str_footnote_link_argument = 'href="#' ;
$l_str_footnote_link_argument .= self :: $a_str_footnote_link_slug ;
$l_str_footnote_link_argument .= self :: $a_str_post_container_id_compound ;
$l_str_footnote_link_argument .= $l_int_index ;
$l_str_footnote_link_argument .= '" class="footnote_hard_link"' ;
2021-03-02 03:09:34 +00:00
2021-05-01 19:22:41 +01:00
/*
2021-03-02 03:09:34 +00:00
* Compose fragment ID anchor with offset , for use in reference container .
* Empty span , child of empty span , to avoid tall dotted rectangles in browser .
*/
2021-04-19 12:15:17 +01:00
$l_str_referrer_anchor_element = '<span class="footnote_referrer_base"><span id="' ;
$l_str_referrer_anchor_element .= self :: $a_str_referrer_link_slug ;
$l_str_referrer_anchor_element .= self :: $a_str_post_container_id_compound ;
$l_str_referrer_anchor_element .= $l_int_index ;
$l_str_referrer_anchor_element .= '" class="footnote_referrer_anchor"></span></span>' ;
2021-03-02 03:09:34 +00:00
} else {
2021-04-30 18:03:15 +01:00
/*
2021-03-02 03:09:34 +00:00
* Initialize hard link variables when hard links are disabled .
*
* If no hyperlink nor offset anchor is needed , initialize as empty .
*/
2021-04-19 12:15:17 +01:00
$l_str_footnote_link_argument = '' ;
$l_str_referrer_anchor_element = '' ;
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// The link element is set independently as it may be needed for styling.
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_LINK_ELEMENT_ENABLED ) ) ) {
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
self :: $a_str_link_span = 'a' ;
self :: $a_str_link_open_tag = '<a>' ;
self :: $a_str_link_close_tag = '</a>' ;
2021-03-02 03:09:34 +00:00
}
}
2021-03-03 18:58:03 +00:00
// Determine tooltip content.
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_tooltips_enabled ) {
2021-04-19 12:15:17 +01:00
$l_str_tooltip_content = $l_bool_has_tooltip_text ? $l_str_tooltip_text : $l_str_excerpt_text ;
2021-05-01 19:22:41 +01:00
2021-04-30 18:03:15 +01:00
/*
2021-04-18 00:23:19 +02:00
* Ensures paragraph separation
2021-04-18 00:26:44 +02:00
*
2021-04-18 00:23:19 +02:00
* Ensures that footnotes containing paragraph separators get displayed correctly .
2021-04-18 00:19:23 +02:00
*/
2021-04-17 23:28:05 +02:00
$l_arr_paragraph_splitters = array ( '#(</p *>|<p[^>]*>)#' , '#(</div *>|<div[^>]*>)#' );
2021-04-25 09:28:02 +01:00
$l_str_tooltip_content = preg_replace ( $l_arr_paragraph_splitters , '<br />' , $l_str_tooltip_content );
2021-03-02 03:09:34 +00:00
} else {
2021-04-19 12:15:17 +01:00
$l_str_tooltip_content = '' ;
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
// Determine shrink width if alternative tooltips are enabled.
2021-04-19 12:15:17 +01:00
$l_str_tooltip_style = '' ;
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_alternative_tooltips_enabled && General :: $a_bool_tooltips_enabled ) {
2021-04-19 12:15:17 +01:00
$l_int_tooltip_length = strlen ( wp_strip_all_tags ( $l_str_tooltip_content ) );
if ( $l_int_tooltip_length < 70 ) {
$l_str_tooltip_style = ' style="width: ' ;
$l_str_tooltip_style .= ( $l_int_tooltip_length * . 7 );
$l_str_tooltip_style .= 'em;"' ;
2021-03-02 03:09:34 +00:00
}
}
2021-04-26 11:42:17 +01:00
// Fill in 'public/partials/footnote.html'.
2021-04-19 12:15:17 +01:00
$l_obj_template -> replace (
2021-03-02 03:09:34 +00:00
array (
2021-04-19 12:15:17 +01:00
'link-span' => self :: $a_str_link_span ,
'post_id' => self :: $a_int_post_id ,
'container_id' => self :: $a_int_reference_container_id ,
'note_id' => $l_int_index ,
'hard-link' => $l_str_footnote_link_argument ,
'sup-span' => $l_str_sup_span ,
2021-05-02 10:45:52 +01:00
'before' => Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_STYLING_BEFORE ),
2021-04-19 12:15:17 +01:00
'index' => $l_int_index ,
2021-05-02 10:45:52 +01:00
'after' => Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_STYLING_AFTER ),
2021-04-19 12:15:17 +01:00
'anchor-element' => $l_str_referrer_anchor_element ,
'style' => $l_str_tooltip_style ,
'text' => $l_str_tooltip_content ,
2021-03-02 03:09:34 +00:00
)
);
2021-04-19 12:15:17 +01:00
$l_str_footnote_replace_text = $l_obj_template -> get_content ();
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Reset the template.
2021-04-19 12:15:17 +01:00
$l_obj_template -> reload ();
2021-03-02 03:09:34 +00:00
2021-03-19 23:58:23 +00:00
// If tooltips are enabled but neither AMP nor alternative are.
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_tooltips_enabled && ! General :: $a_bool_amp_enabled && ! General :: $a_bool_alternative_tooltips_enabled ) {
2021-03-02 03:09:34 +00:00
2021-05-02 10:45:52 +01:00
$l_int_offset_y = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_MOUSE_OVER_BOX_OFFSET_Y );
$l_int_offset_x = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_MOUSE_OVER_BOX_OFFSET_X );
$l_int_fade_in_delay = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_MOUSE_OVER_BOX_FADE_IN_DELAY );
$l_int_fade_in_duration = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_MOUSE_OVER_BOX_FADE_IN_DURATION );
$l_int_fade_out_delay = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_MOUSE_OVER_BOX_FADE_OUT_DELAY );
$l_int_fade_out_duration = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_MOUSE_OVER_BOX_FADE_OUT_DURATION );
2021-03-02 03:09:34 +00:00
2021-04-26 11:42:17 +01:00
// Fill in 'public/partials/tooltip.html'.
2021-04-19 12:15:17 +01:00
$l_obj_template_tooltip -> replace (
2021-03-02 03:09:34 +00:00
array (
2021-04-19 12:15:17 +01:00
'post_id' => self :: $a_int_post_id ,
'container_id' => self :: $a_int_reference_container_id ,
'note_id' => $l_int_index ,
2021-05-02 10:45:52 +01:00
'position' => Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_MOUSE_OVER_BOX_POSITION ),
'offset-y' => empty ( $l_int_offset_y ) ? 0 : $l_int_offset_y ,
'offset-x' => empty ( $l_int_offset_x ) ? 0 : $l_int_offset_x ,
'fade-in-delay' => empty ( $l_int_fade_in_delay ) ? 0 : $l_int_fade_in_delay ,
'fade-in-duration' => empty ( $l_int_fade_in_duration ) ? 0 : $l_int_fade_in_duration ,
'fade-out-delay' => empty ( $l_int_fade_out_delay ) ? 0 : $l_int_fade_out_delay ,
'fade-out-duration' => empty ( $l_int_fade_out_duration ) ? 0 : $l_int_fade_out_duration ,
2021-03-02 03:09:34 +00:00
)
);
2021-04-19 12:15:17 +01:00
$l_str_footnote_replace_text .= $l_obj_template_tooltip -> get_content ();
$l_obj_template_tooltip -> reload ();
2021-03-02 03:09:34 +00:00
}
}
2021-03-03 18:58:03 +00:00
// Replace the footnote with the template.
2021-04-19 12:15:17 +01:00
$p_str_content = substr_replace ( $p_str_content , $l_str_footnote_replace_text , $l_int_pos_start , $l_int_length + strlen ( self :: $a_str_end_tag ) );
2021-03-03 18:58:03 +00:00
// Add footnote only if not empty.
2021-04-19 12:15:17 +01:00
if ( ! empty ( $l_str_footnote_text ) ) {
2021-03-03 18:58:03 +00:00
// Set footnote to the output box at the end.
2021-04-19 12:15:17 +01:00
self :: $a_arr_footnotes [] = $l_str_footnote_text ;
2021-03-03 18:58:03 +00:00
// Increase footnote index.
2021-04-19 12:15:17 +01:00
$l_int_footnote_index ++ ;
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
/*
2021-04-13 08:18:07 +00:00
* Fixes a partial footnotes process outage happening when tooltips are truncated or disabled .
* Fixed a footnotes numbering bug happening under de facto rare circumstances .
2021-03-02 03:09:34 +00:00
*
* This assignment was overridden by another one , causing the algorithm to jump back
* near the post start to a position calculated as the sum of the length of the last
* footnote and the length of the last footnote replace text .
* A bug disturbing the order of the footnotes depending on the text before the first
* footnote , the length of the first footnote and the length of the templates for the
2021-04-13 08:18:07 +00:00
* footnote and the tooltip .
* Deleting both lines instead , to resume the search at the position where it left off ,
* would have prevented also the following bug .
*
* The origin of the bug was present since the beginning ( v1 . 0.0 ) .
* For v1 . 3.2 the wrong code was refactored but remained wrong ,
* and was unaffected by the v1 . 5.0 refactoring .
* The reason why the numbering disorder reverted to a partial process outage
* since 2.5 . 14 is that with this version , the plugin stopped processing the
* content multiple times , and started unifying the shortcodes instead , to fix
* the numbering disorder affecting delimiter shortcodes with pointy brackets
* and mixed escapement schemas .
2021-03-02 03:09:34 +00:00
*/
2021-03-03 18:58:03 +00:00
// Add offset to the new starting position.
2021-04-19 12:15:17 +01:00
$l_int_pos_start += strlen ( $l_str_footnote_replace_text );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
} while ( true );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Return content.
2021-04-19 12:15:17 +01:00
return $p_str_content ;
2021-03-02 03:09:34 +00:00
}
/**
* Generates the reference container .
*
2021-05-01 21:34:46 +01:00
* @ since 1.5 . 0
2021-03-02 03:09:34 +00:00
*/
2021-05-02 19:33:29 +01:00
public function reference_container () : string {
2021-03-02 03:09:34 +00:00
2021-05-02 19:49:31 +01:00
$l_str_use_backbutton_hint = null ;
2021-03-03 18:58:03 +00:00
// No footnotes have been replaced on this page.
2021-04-19 12:15:17 +01:00
if ( empty ( self :: $a_arr_footnotes ) ) {
2021-03-03 18:58:03 +00:00
return '' ;
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Footnote index backlink symbol .
2021-03-02 03:09:34 +00:00
*/
2021-05-01 19:22:41 +01:00
2021-03-24 21:19:07 +00:00
// If the backlink symbol is enabled.
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_ENABLE ) ) ) {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Get html arrow.
2021-05-02 10:45:52 +01:00
$l_str_arrow = Includes\Convert :: get_arrow ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_HYPERLINK_ARROW ) );
2021-03-03 18:58:03 +00:00
// Set html arrow to the first one if invalid index defined.
2021-04-19 12:15:17 +01:00
if ( is_array ( $l_str_arrow ) ) {
2021-05-01 21:34:46 +01:00
$l_str_arrow = Includes\Convert :: get_arrow ( 0 );
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Get user defined arrow.
2021-05-02 10:45:52 +01:00
$l_str_arrow_user_defined = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_HYPERLINK_ARROW_USER_DEFINED );
2021-04-19 12:15:17 +01:00
if ( ! empty ( $l_str_arrow_user_defined ) ) {
$l_str_arrow = $l_str_arrow_user_defined ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Wrap the arrow in a @media print { display:hidden } span.
2021-04-19 12:15:17 +01:00
$l_str_footnote_arrow = '<span class="footnote_index_arrow">' ;
$l_str_footnote_arrow .= $l_str_arrow . '</span>' ;
2021-03-02 03:09:34 +00:00
} else {
2021-03-03 18:58:03 +00:00
// If the backlink symbol isn’ t enabled, set it to empty.
2021-04-19 12:15:17 +01:00
$l_str_arrow = '' ;
$l_str_footnote_arrow = '' ;
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Backlink separator .
2021-03-02 03:09:34 +00:00
*
2021-03-24 21:19:07 +00:00
* Initially an appended comma was hard - coded in this algorithm for enumerations .
* The comma in enumerations is not universally preferred .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_SEPARATOR_ENABLED ) ) ) {
2021-03-03 18:58:03 +00:00
2021-04-19 12:15:17 +01:00
if ( empty ( $l_str_separator ) ) {
2021-03-03 18:58:03 +00:00
// If it is not, check which option is on.
2021-05-02 10:45:52 +01:00
$l_str_separator_option = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_SEPARATOR_OPTION );
2021-05-02 19:58:40 +01:00
$l_str_separator = match ( $l_str_separator_option ) {
'comma' => ',' ,
'semicolon' => ';' ,
'en_dash' => ' –' ,
default => Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_SEPARATOR_CUSTOM ),
};
2021-03-02 03:09:34 +00:00
}
} else {
2021-04-19 12:15:17 +01:00
$l_str_separator = '' ;
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Backlink terminator .
2021-03-02 03:09:34 +00:00
*
* Initially a dot was appended in the table row template .
*/
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_TERMINATOR_ENABLED ) ) ) {
2021-03-03 18:58:03 +00:00
2021-04-19 12:15:17 +01:00
if ( empty ( $l_str_terminator ) ) {
2021-03-03 18:58:03 +00:00
// If it is not, check which option is on.
2021-05-02 10:45:52 +01:00
$l_str_terminator_option = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_TERMINATOR_OPTION );
2021-05-02 19:58:40 +01:00
$l_str_terminator = match ( $l_str_terminator_option ) {
'period' => '.' ,
'parenthesis' => ')' ,
'colon' => ':' ,
default => Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_TERMINATOR_CUSTOM ),
};
2021-03-02 03:09:34 +00:00
}
} else {
2021-04-19 12:15:17 +01:00
$l_str_terminator = '' ;
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Line breaks .
2021-03-02 03:09:34 +00:00
*
* The backlinks of combined footnotes are generally preferred in an enumeration .
* But when few footnotes are identical , stacking the items in list form is better .
* Variable number length and proportional character width require explicit line breaks .
* Otherwise , an ordinary space character offering a line break opportunity is inserted .
*/
2021-05-02 10:45:52 +01:00
$l_str_line_break = Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_BACKLINKS_LINE_BREAKS_ENABLED ) ) ? '<br />' : ' ' ;
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Line breaks for source readability .
*
2021-03-02 03:09:34 +00:00
* For maintenance and support , table rows in the reference container should be
* separated by an empty line . So we add these line breaks for source readability .
2021-03-03 18:58:03 +00:00
* Before the first table row ( breaks between rows are ~ 200 lines below ) .
2021-03-02 03:09:34 +00:00
*/
2021-04-19 12:15:17 +01:00
$l_str_body = " \r \n \r \n " ;
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Reference container table row template load .
2021-04-26 17:15:48 +01:00
*/
2021-05-02 10:45:52 +01:00
$l_bool_combine_identical_footnotes = Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_COMBINE_IDENTICAL_FOOTNOTES ) );
2021-03-19 23:58:23 +00:00
2021-03-18 18:00:42 +00:00
// AMP compatibility requires a full set of AMP compatible table row templates.
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_amp_enabled ) {
2021-03-18 18:00:42 +00:00
// When combining identical footnotes is turned on, another template is needed.
2021-04-19 12:15:17 +01:00
if ( $l_bool_combine_identical_footnotes ) {
2021-03-18 18:00:42 +00:00
// The combining template allows for backlink clusters and supports cell clicking for single notes.
2021-05-02 10:45:52 +01:00
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'amp-reference-container-body-combi' );
} elseif ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_3COLUMN_LAYOUT_ENABLE ) ) ) {
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'amp-reference-container-body-3column' );
} elseif ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH ) ) ) {
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'amp-reference-container-body-switch' );
2021-03-18 18:00:42 +00:00
} else {
2021-03-02 03:09:34 +00:00
2021-03-18 18:00:42 +00:00
// Default is the standard template.
2021-05-02 10:45:52 +01:00
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'amp-reference-container-body' );
2021-03-18 18:00:42 +00:00
}
2021-05-02 10:45:52 +01:00
} elseif ( $l_bool_combine_identical_footnotes ) {
// The combining template allows for backlink clusters and supports cell clicking for single notes.
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'reference-container-body-combi' );
} elseif ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_3COLUMN_LAYOUT_ENABLE ) ) ) {
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'reference-container-body-3column' );
} elseif ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH ) ) ) {
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'reference-container-body-switch' );
2021-03-18 18:00:42 +00:00
} else {
2021-03-19 23:58:23 +00:00
2021-03-18 18:00:42 +00:00
// Default is the standard template.
2021-05-02 10:45:52 +01:00
$l_obj_template = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'reference-container-body' );
2021-03-18 18:00:42 +00:00
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Switch backlink symbol and footnote number .
2021-03-02 03:09:34 +00:00
*/
2021-05-02 10:45:52 +01:00
$l_bool_symbol_switch = Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH ) );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Loop through all footnotes found in the page.
2021-04-19 12:15:17 +01:00
$num_footnotes = count ( self :: $a_arr_footnotes );
for ( $l_int_index = 0 ; $l_int_index < $num_footnotes ; $l_int_index ++ ) {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Get footnote text.
2021-04-19 12:15:17 +01:00
$l_str_footnote_text = self :: $a_arr_footnotes [ $l_int_index ];
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// If footnote is empty, go to the next one;.
// With combine identicals turned on, identicals will be deleted and are skipped.
2021-04-19 12:15:17 +01:00
if ( empty ( $l_str_footnote_text ) ) {
2021-03-02 03:09:34 +00:00
continue ;
}
2021-03-03 18:58:03 +00:00
// Generate content of footnote index cell.
2021-04-19 12:15:17 +01:00
$l_int_first_footnote_index = ( $l_int_index + 1 );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Get the footnote index string and.
// Keep supporting legacy index placeholder.
2021-05-02 10:45:52 +01:00
$l_str_footnote_id = Includes\Convert :: index ( ( $l_int_index + 1 ), Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_COUNTER_STYLE ) );
2021-03-02 03:09:34 +00:00
/**
2021-03-03 18:58:03 +00:00
* Case of only one backlink per table row .
2021-03-02 03:09:34 +00:00
*
2021-03-03 18:58:03 +00:00
* If enabled , and for the case the footnote is single , compose hard link .
2021-03-02 03:09:34 +00:00
*/
2021-03-03 18:58:03 +00:00
// Define anyway.
2021-04-19 12:15:17 +01:00
$l_str_hard_link_address = '' ;
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
if ( self :: $a_bool_hard_links_enabled ) {
2021-04-30 18:03:15 +01:00
/*
2021-03-02 03:09:34 +00:00
* Use - Backbutton - Hint tooltip , optional and configurable .
*
* When hard links are enabled , clicks on the backlinks are logged in the browsing history .
* This tooltip hints to use the backbutton instead , so the history gets streamlined again .
* @ link https :// wordpress . org / support / topic / making - it - amp - compatible / #post-13837359
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.5 . 4
2021-03-02 03:09:34 +00:00
*/
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_BACKLINK_TOOLTIP_ENABLE ) ) ) {
2021-04-19 12:15:17 +01:00
$l_str_use_backbutton_hint = ' title="' ;
2021-05-02 10:45:52 +01:00
$l_str_use_backbutton_hint .= Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_BACKLINK_TOOLTIP_TEXT );
2021-04-19 12:15:17 +01:00
$l_str_use_backbutton_hint .= '"' ;
2021-03-02 03:09:34 +00:00
} else {
2021-04-19 12:15:17 +01:00
$l_str_use_backbutton_hint = '' ;
2021-03-02 03:09:34 +00:00
}
/**
* Compose fragment ID anchor with offset , for use in reference container .
* Empty span , child of empty span , to avoid tall dotted rectangles in browser .
*/
2021-04-19 12:15:17 +01:00
$l_str_footnote_anchor_element = '<span class="footnote_item_base"><span id="' ;
$l_str_footnote_anchor_element .= self :: $a_str_footnote_link_slug ;
$l_str_footnote_anchor_element .= self :: $a_str_post_container_id_compound ;
$l_str_footnote_anchor_element .= $l_str_footnote_id ;
$l_str_footnote_anchor_element .= '" class="footnote_item_anchor"></span></span>' ;
2021-03-03 18:58:03 +00:00
// Compose optional hard link address.
2021-05-02 10:45:52 +01:00
$l_str_hard_link_address = ' href="#' ;
$l_str_hard_link_address .= self :: $a_str_referrer_link_slug ;
$l_str_hard_link_address .= self :: $a_str_post_container_id_compound ;
$l_str_hard_link_address .= $l_str_footnote_id . '"' ;
$l_str_hard_link_address .= $l_str_use_backbutton_hint ;
2021-04-19 12:15:17 +01:00
self :: $a_str_link_open_tag = ' class="footnote_hard_back_link">' ;
2021-03-02 03:09:34 +00:00
} else {
2021-03-03 18:58:03 +00:00
// Define as empty, too.
2021-04-19 12:15:17 +01:00
$l_str_footnote_anchor_element = '' ;
2021-03-02 03:09:34 +00:00
}
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Support for combining identicals : compose enumerated backlinks .
2021-03-02 03:09:34 +00:00
*
* Prepare to have single footnotes , where the click event and
* optional hard link need to be set to cover the table cell ,
* for better usability and UX .
2021-04-30 18:03:15 +01:00
*
2021-05-01 21:34:46 +01:00
* @ since 2.1 . 1
2021-03-02 03:09:34 +00:00
*/
2021-05-01 19:22:41 +01:00
2021-03-03 18:58:03 +00:00
// Set a flag to check for the combined status of a footnote item.
2021-04-19 12:15:17 +01:00
$l_bool_flag_combined = false ;
2021-03-03 18:58:03 +00:00
// Set otherwise unused variables as empty to avoid screwing up the placeholder array.
2021-04-19 12:15:17 +01:00
$l_str_backlink_event = '' ;
$l_str_footnote_backlinks = '' ;
$l_str_footnote_reference = '' ;
2021-03-03 18:58:03 +00:00
2021-04-19 12:15:17 +01:00
if ( $l_bool_combine_identical_footnotes ) {
2021-03-03 18:58:03 +00:00
// ID, optional hard link address, and class.
2021-04-19 12:15:17 +01:00
$l_str_footnote_reference = '<' . self :: $a_str_link_span ;
$l_str_footnote_reference .= ' id="footnote_plugin_reference_' ;
$l_str_footnote_reference .= self :: $a_int_post_id ;
$l_str_footnote_reference .= '_' . self :: $a_int_reference_container_id ;
$l_str_footnote_reference .= " _ $l_str_footnote_id\ " " ;
if ( self :: $a_bool_hard_links_enabled ) {
$l_str_footnote_reference .= ' href="#' ;
$l_str_footnote_reference .= self :: $a_str_referrer_link_slug ;
$l_str_footnote_reference .= self :: $a_str_post_container_id_compound ;
$l_str_footnote_reference .= $l_str_footnote_id . '"' ;
$l_str_footnote_reference .= $l_str_use_backbutton_hint ;
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
$l_str_footnote_reference .= ' class="footnote_backlink"' ;
2021-03-03 18:58:03 +00:00
2021-03-19 23:58:23 +00:00
/*
* The click event goes in the table cell if footnote remains single .
*/
2021-05-01 19:22:41 +01:00
2021-04-19 12:15:17 +01:00
$l_str_backlink_event = ' onclick="footnote_moveToAnchor_' ;
2021-03-19 23:58:23 +00:00
2021-04-19 12:15:17 +01:00
$l_str_backlink_event .= self :: $a_int_post_id ;
$l_str_backlink_event .= '_' . self :: $a_int_reference_container_id ;
$l_str_backlink_event .= " ('footnote_plugin_tooltip_ " ;
$l_str_backlink_event .= self :: $a_int_post_id ;
$l_str_backlink_event .= '_' . self :: $a_int_reference_container_id ;
$l_str_backlink_event .= " _ $l_str_footnote_id '); \" " ;
2021-03-03 18:58:03 +00:00
// The dedicated template enumerating backlinks uses another variable.
2021-04-19 12:15:17 +01:00
$l_str_footnote_backlinks = $l_str_footnote_reference ;
2021-03-03 18:58:03 +00:00
// Append the click event right to the backlink item for enumerations;.
// Else it goes in the table cell.
2021-04-19 12:15:17 +01:00
$l_str_footnote_backlinks .= $l_str_backlink_event . '>' ;
$l_str_footnote_reference .= '>' ;
2021-03-03 18:58:03 +00:00
// Append the optional offset anchor for hard links.
2021-04-19 12:15:17 +01:00
if ( self :: $a_bool_hard_links_enabled ) {
$l_str_footnote_reference .= $l_str_footnote_anchor_element ;
$l_str_footnote_backlinks .= $l_str_footnote_anchor_element ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Continue both single note and notes cluster, depending on switch option status.
2021-04-19 12:15:17 +01:00
if ( $l_bool_symbol_switch ) {
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
$l_str_footnote_reference .= " $l_str_footnote_id $l_str_footnote_arrow " ;
$l_str_footnote_backlinks .= " $l_str_footnote_id $l_str_footnote_arrow " ;
2021-03-02 03:09:34 +00:00
} else {
2021-04-19 12:15:17 +01:00
$l_str_footnote_reference .= " $l_str_footnote_arrow $l_str_footnote_id " ;
$l_str_footnote_backlinks .= " $l_str_footnote_arrow $l_str_footnote_id " ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// If that is the only footnote with this text, we’ re almost done..
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Check if it isn't the last footnote in the array.
2021-04-19 12:15:17 +01:00
if ( $l_int_first_footnote_index < count ( self :: $a_arr_footnotes ) ) {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Get all footnotes that haven't passed yet.
2021-04-19 12:15:17 +01:00
$num_footnotes = count ( self :: $a_arr_footnotes );
for ( $l_int_check_index = $l_int_first_footnote_index ; $l_int_check_index < $num_footnotes ; $l_int_check_index ++ ) {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Check if a further footnote is the same as the actual one.
2021-04-19 12:15:17 +01:00
if ( self :: $a_arr_footnotes [ $l_int_check_index ] === $l_str_footnote_text ) {
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// If so, set the further footnote as empty so it won't be displayed later.
2021-04-19 12:15:17 +01:00
self :: $a_arr_footnotes [ $l_int_check_index ] = '' ;
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Set the flag to true for the combined status.
2021-04-19 12:15:17 +01:00
$l_bool_flag_combined = true ;
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Update the footnote ID.
2021-05-02 10:45:52 +01:00
$l_str_footnote_id = Includes\Convert :: index ( ( $l_int_check_index + 1 ), Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_COUNTER_STYLE ) );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Resume composing the backlinks enumeration.
2021-04-19 12:15:17 +01:00
$l_str_footnote_backlinks .= " $l_str_separator </ " ;
$l_str_footnote_backlinks .= self :: $a_str_link_span . '>' ;
$l_str_footnote_backlinks .= $l_str_line_break ;
$l_str_footnote_backlinks .= '<' . self :: $a_str_link_span ;
$l_str_footnote_backlinks .= ' id="footnote_plugin_reference_' ;
$l_str_footnote_backlinks .= self :: $a_int_post_id ;
$l_str_footnote_backlinks .= '_' . self :: $a_int_reference_container_id ;
$l_str_footnote_backlinks .= " _ $l_str_footnote_id\ " " ;
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Insert the optional hard link address.
2021-04-19 12:15:17 +01:00
if ( self :: $a_bool_hard_links_enabled ) {
$l_str_footnote_backlinks .= ' href="#' ;
$l_str_footnote_backlinks .= self :: $a_str_referrer_link_slug ;
$l_str_footnote_backlinks .= self :: $a_str_post_container_id_compound ;
$l_str_footnote_backlinks .= $l_str_footnote_id . '"' ;
$l_str_footnote_backlinks .= $l_str_use_backbutton_hint ;
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
$l_str_footnote_backlinks .= ' class="footnote_backlink"' ;
2021-03-19 23:58:23 +00:00
2021-04-15 05:09:23 +01:00
// Reverted wrong linting.
2021-04-19 12:15:17 +01:00
$l_str_footnote_backlinks .= ' onclick="footnote_moveToAnchor_' ;
2021-03-19 23:58:23 +00:00
2021-04-19 12:15:17 +01:00
$l_str_footnote_backlinks .= self :: $a_int_post_id ;
$l_str_footnote_backlinks .= '_' . self :: $a_int_reference_container_id ;
$l_str_footnote_backlinks .= " ('footnote_plugin_tooltip_ " ;
$l_str_footnote_backlinks .= self :: $a_int_post_id ;
$l_str_footnote_backlinks .= '_' . self :: $a_int_reference_container_id ;
$l_str_footnote_backlinks .= " _ $l_str_footnote_id '); \" > " ;
2021-03-03 18:58:03 +00:00
// Append the offset anchor for optional hard links.
2021-04-19 12:15:17 +01:00
if ( self :: $a_bool_hard_links_enabled ) {
$l_str_footnote_backlinks .= '<span class="footnote_item_base"><span id="' ;
$l_str_footnote_backlinks .= self :: $a_str_footnote_link_slug ;
$l_str_footnote_backlinks .= self :: $a_str_post_container_id_compound ;
$l_str_footnote_backlinks .= $l_str_footnote_id ;
$l_str_footnote_backlinks .= '" class="footnote_item_anchor"></span></span>' ;
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
$l_str_footnote_backlinks .= $l_bool_symbol_switch ? '' : $l_str_footnote_arrow ;
$l_str_footnote_backlinks .= $l_str_footnote_id ;
$l_str_footnote_backlinks .= $l_bool_symbol_switch ? $l_str_footnote_arrow : '' ;
2021-03-02 03:09:34 +00:00
}
}
}
2021-03-03 18:58:03 +00:00
// Append terminator and end tag.
2021-04-19 12:15:17 +01:00
$l_str_footnote_reference .= $l_str_terminator . '</' . self :: $a_str_link_span . '>' ;
$l_str_footnote_backlinks .= $l_str_terminator . '</' . self :: $a_str_link_span . '>' ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Line wrapping of URLs already fixed, see above.
// Get reference container item text if tooltip text goes separate.
2021-04-19 12:15:17 +01:00
$l_int_tooltip_text_length = strpos ( $l_str_footnote_text , self :: $a_str_tooltip_shortcode );
2021-05-02 10:45:52 +01:00
$l_bool_has_tooltip_text = ( bool ) $l_int_tooltip_text_length ;
2021-04-19 12:15:17 +01:00
if ( $l_bool_has_tooltip_text ) {
$l_str_not_tooltip_text = substr ( $l_str_footnote_text , ( $l_int_tooltip_text_length + self :: $a_int_tooltip_shortcode_length ) );
2021-05-02 10:45:52 +01:00
self :: $a_bool_mirror_tooltip_text = Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_TOOLTIP_EXCERPT_MIRROR_ENABLE ) );
2021-04-19 12:15:17 +01:00
if ( self :: $a_bool_mirror_tooltip_text ) {
$l_str_tooltip_text = substr ( $l_str_footnote_text , 0 , $l_int_tooltip_text_length );
2021-05-02 10:45:52 +01:00
$l_str_reference_text_introducer = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_TOOLTIP_EXCERPT_MIRROR_SEPARATOR );
2021-04-19 12:15:17 +01:00
$l_str_reference_text = $l_str_tooltip_text . $l_str_reference_text_introducer . $l_str_not_tooltip_text ;
2021-03-02 03:09:34 +00:00
} else {
2021-04-19 12:15:17 +01:00
$l_str_reference_text = $l_str_not_tooltip_text ;
2021-03-02 03:09:34 +00:00
}
} else {
2021-04-19 12:15:17 +01:00
$l_str_reference_text = $l_str_footnote_text ;
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Replace all placeholders in table row template.
2021-04-19 12:15:17 +01:00
$l_obj_template -> replace (
2021-03-02 03:09:34 +00:00
array (
2021-03-03 18:58:03 +00:00
// Placeholder used in all templates.
2021-04-19 12:15:17 +01:00
'text' => $l_str_reference_text ,
2021-03-03 18:58:03 +00:00
// Used in standard layout W/O COMBINED FOOTNOTES.
2021-04-19 12:15:17 +01:00
'post_id' => self :: $a_int_post_id ,
'container_id' => self :: $a_int_reference_container_id ,
2021-05-02 10:45:52 +01:00
'note_id' => Includes\Convert :: index ( $l_int_first_footnote_index , Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_COUNTER_STYLE ) ),
2021-04-19 12:15:17 +01:00
'link-start' => self :: $a_str_link_open_tag ,
'link-end' => self :: $a_str_link_close_tag ,
'link-span' => self :: $a_str_link_span ,
'terminator' => $l_str_terminator ,
'anchor-element' => $l_str_footnote_anchor_element ,
'hard-link' => $l_str_hard_link_address ,
2021-03-03 18:58:03 +00:00
// Used in standard layout WITH COMBINED IDENTICALS TURNED ON.
2021-04-19 12:15:17 +01:00
'pointer' => $l_bool_flag_combined ? '' : ' pointer' ,
'event' => $l_bool_flag_combined ? '' : $l_str_backlink_event ,
'backlinks' => $l_bool_flag_combined ? $l_str_footnote_backlinks : $l_str_footnote_reference ,
2021-03-03 18:58:03 +00:00
// Legacy placeholders for use in legacy layout templates.
2021-04-19 12:15:17 +01:00
'arrow' => $l_str_footnote_arrow ,
'index' => $l_str_footnote_id ,
2021-03-02 03:09:34 +00:00
)
);
2021-04-19 12:15:17 +01:00
$l_str_body .= $l_obj_template -> get_content ();
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Extra line breaks for page source readability.
2021-04-19 12:15:17 +01:00
$l_str_body .= " \r \n \r \n " ;
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
$l_obj_template -> reload ();
2021-03-02 03:09:34 +00:00
}
2021-03-03 18:58:03 +00:00
// Call again for robustness when priority levels don’ t match any longer.
2021-05-02 10:45:52 +01:00
self :: $a_int_scroll_offset = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_SCROLL_OFFSET );
2021-03-02 03:09:34 +00:00
2021-03-03 18:58:03 +00:00
// Streamline.
2021-05-02 10:45:52 +01:00
$l_bool_collapse_default = Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_COLLAPSE ) );
2021-03-02 03:09:34 +00:00
2021-04-30 18:03:15 +01:00
/*
2021-03-03 18:58:03 +00:00
* Reference container label .
2021-03-02 03:09:34 +00:00
*
* Themes may drop - cap a first letter of initial paragraphs , like this label .
* In case of empty label that would apply to the left half button character .
* Hence the point in setting an empty label to U + 202 F NARROW NO - BREAK SPACE .
*/
2021-05-02 10:45:52 +01:00
$l_str_reference_container_label = Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_NAME );
2021-03-02 03:09:34 +00:00
2021-03-16 19:41:08 +00:00
// Select the reference container template.
// Whether AMP compatibility mode is enabled.
2021-05-01 21:34:46 +01:00
if ( General :: $a_bool_amp_enabled ) {
2021-03-16 19:41:08 +00:00
// Whether the reference container is collapsed by default.
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_COLLAPSE ) ) ) {
2021-03-16 19:41:08 +00:00
2021-04-26 11:42:17 +01:00
// Load 'public/partials/amp-reference-container-collapsed.html'.
2021-05-02 10:45:52 +01:00
$l_obj_template_container = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'amp-reference-container-collapsed' );
2021-03-16 19:41:08 +00:00
} else {
2021-04-26 11:42:17 +01:00
// Load 'public/partials/amp-reference-container.html'.
2021-05-02 10:45:52 +01:00
$l_obj_template_container = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'amp-reference-container' );
2021-03-16 19:41:08 +00:00
}
2021-05-01 21:34:46 +01:00
} elseif ( 'js' === General :: $a_str_script_mode ) {
2021-03-20 20:48:54 +00:00
2021-04-26 11:42:17 +01:00
// Load 'public/partials/js-reference-container.html'.
2021-05-02 10:45:52 +01:00
$l_obj_template_container = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'js-reference-container' );
2021-03-20 20:48:54 +00:00
} else {
2021-03-02 03:09:34 +00:00
2021-04-26 11:42:17 +01:00
// Load 'public/partials/reference-container.html'.
2021-05-02 10:45:52 +01:00
$l_obj_template_container = new Includes\Template ( \footnotes\includes\Template :: C_STR_PUBLIC , 'reference-container' );
2021-03-20 20:48:54 +00:00
}
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
$l_int_scroll_offset = '' ;
$l_int_scroll_down_delay = '' ;
$l_int_scroll_down_duration = '' ;
$l_int_scroll_up_delay = '' ;
$l_int_scroll_up_duration = '' ;
2021-03-20 20:48:54 +00:00
2021-05-01 21:34:46 +01:00
if ( 'jquery' === General :: $a_str_script_mode ) {
2021-03-20 20:48:54 +00:00
2021-04-19 12:15:17 +01:00
$l_int_scroll_offset = ( self :: $a_int_scroll_offset / 100 );
2021-05-02 10:45:52 +01:00
$l_int_scroll_up_duration = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_SCROLL_DURATION );
2021-03-20 20:48:54 +00:00
2021-05-02 10:45:52 +01:00
if ( Includes\Convert :: to_bool ( Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_FOOTNOTES_SCROLL_DURATION_ASYMMETRICITY ) ) ) {
2021-03-20 20:48:54 +00:00
2021-05-02 10:45:52 +01:00
$l_int_scroll_down_duration = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_SCROLL_DOWN_DURATION );
2021-03-20 20:48:54 +00:00
} else {
2021-04-19 12:15:17 +01:00
$l_int_scroll_down_duration = $l_int_scroll_up_duration ;
2021-03-20 20:48:54 +00:00
}
2021-05-02 10:45:52 +01:00
$l_int_scroll_down_delay = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_SCROLL_DOWN_DELAY );
$l_int_scroll_up_delay = ( int ) Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_INT_FOOTNOTES_SCROLL_UP_DELAY );
2021-03-02 03:09:34 +00:00
}
2021-04-19 12:15:17 +01:00
$l_obj_template_container -> replace (
2021-03-02 03:09:34 +00:00
array (
2021-04-19 12:15:17 +01:00
'post_id' => self :: $a_int_post_id ,
'container_id' => self :: $a_int_reference_container_id ,
2021-05-02 10:45:52 +01:00
'element' => Includes\Settings :: instance () -> get ( \footnotes\includes\Settings :: C_STR_REFERENCE_CONTAINER_LABEL_ELEMENT ),
2021-04-19 12:15:17 +01:00
'name' => empty ( $l_str_reference_container_label ) ? ' ' : $l_str_reference_container_label ,
2021-05-02 10:45:52 +01:00
'button-style' => $l_bool_collapse_default ? '' : 'display: none;' ,
2021-04-19 12:15:17 +01:00
'style' => $l_bool_collapse_default ? 'display: none;' : '' ,
'caption' => ( empty ( $l_str_reference_container_label ) || ' ' === $l_str_reference_container_label ) ? 'References' : $l_str_reference_container_label ,
'content' => $l_str_body ,
'scroll-offset' => $l_int_scroll_offset ,
'scroll-down-delay' => $l_int_scroll_down_delay ,
'scroll-down-duration' => $l_int_scroll_down_duration ,
'scroll-up-delay' => $l_int_scroll_up_delay ,
'scroll-up-duration' => $l_int_scroll_up_duration ,
2021-03-02 03:09:34 +00:00
)
);
2021-03-03 18:58:03 +00:00
// Free all found footnotes if reference container will be displayed.
2021-04-19 12:15:17 +01:00
self :: $a_arr_footnotes = array ();
2021-03-02 03:09:34 +00:00
2021-04-19 12:15:17 +01:00
return $l_obj_template_container -> get_content ();
2021-03-02 03:09:34 +00:00
}
}