' . $l_str_LoveMeText . ''; } } /** * replaces all footnotes in the given content * loading settings if not happened yet since 1.0-gamma * @since 1.0 * @param string $p_str_Content * @param bool $p_bool_OutputReferences [default: true] * @param bool $p_bool_ReplaceHtmlCharsSettings [ default: false] * @param bool $p_bool_ReplaceHtmlCharsContent [ default: false] * @return string */ function footnotes_replaceFootnotes($p_str_Content, $p_bool_OutputReferences = true, $p_bool_ReplaceHtmlCharsSettings = false, $p_bool_ReplaceHtmlCharsContent = false) { /* access to the global settings collection */ global $g_arr_FootnotesSettings; /* load footnote settings */ $g_arr_FootnotesSettings = footnotes_filter_options(FOOTNOTE_SETTINGS_CONTAINER, Class_FootnotesSettings::$a_arr_Default_Settings, $p_bool_ReplaceHtmlCharsSettings); /* replace all footnotes in the content */ $p_str_Content = footnotes_getFromString($p_str_Content, $p_bool_ReplaceHtmlCharsContent); /* add the reference list if set */ if ($p_bool_OutputReferences) { $p_str_Content = $p_str_Content . footnotes_OutputReferenceContainer(); } /* * checks if the user doesn't want to have a 'love me' on current page * @since 1.1.1 */ if (strpos($p_str_Content, FOOTNOTES_NO_SLUGME_PLUG) !== false) { global $g_bool_NoLoveMeSlugOnCurrentPage; $g_bool_NoLoveMeSlugOnCurrentPage = true; $p_str_Content = str_replace(FOOTNOTES_NO_SLUGME_PLUG, "", $p_str_Content); } /* return the replaced content */ return $p_str_Content; } /** * replace all footnotes in the given string and adds them to an array * using a personal starting and ending tag for the footnotes since 1.0-gamma * @since 1.0 * @param string $p_str_Content * @param bool $p_bool_ConvertHtmlChars * @return string */ function footnotes_getFromString($p_str_Content, $p_bool_ConvertHtmlChars = true) { /* get access to the global array to store footnotes */ global $g_arr_Footnotes; /* access to the global settings collection */ global $g_arr_FootnotesSettings; /* contains the index for the next footnote on this page */ $l_int_FootnoteIndex = count($g_arr_Footnotes) + 1; /* contains the starting position for the lookup of a footnote */ $l_int_PosStart = 0; /* contains the footnote template */ $l_str_FootnoteTemplate = file_get_contents(FOOTNOTES_TEMPLATES_DIR . "footnote.html"); /* get footnote starting tag */ $l_str_StartingTag = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_PLACEHOLDER_START]; /*get footnote ending tag */ $l_str_EndingTag = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_PLACEHOLDER_END]; /*get footnote counter style */ $l_str_CounterStyle = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_COUNTER_STYLE]; if ($l_str_StartingTag == "userdefined" || $l_str_EndingTag == "userdefined") { /* get user defined footnote starting tag */ $l_str_StartingTag = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_PLACEHOLDER_START_USERDEFINED]; /*get user defined footnote ending tag */ $l_str_EndingTag = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_PLACEHOLDER_END_USERDEFINED]; } /* decode html special chars */ if ($p_bool_ConvertHtmlChars) { $l_str_StartingTag = htmlspecialchars($l_str_StartingTag); $l_str_EndingTag = htmlspecialchars($l_str_EndingTag); } /* check for a footnote placeholder in the current page */ do { /* get first occurence of a footnote starting tag */ $l_int_PosStart = strpos($p_str_Content, $l_str_StartingTag, $l_int_PosStart); /* tag found */ if ($l_int_PosStart !== false) { /* get first occurence of a footnote ending tag after the starting tag */ $l_int_PosEnd = strpos($p_str_Content, $l_str_EndingTag, $l_int_PosStart); /* tag found */ if ($l_int_PosEnd !== false) { /* get length of footnote text */ $l_int_Length = $l_int_PosEnd - $l_int_PosStart; /* get text inside footnote */ $l_str_FootnoteText = substr($p_str_Content, $l_int_PosStart + strlen($l_str_StartingTag), $l_int_Length - strlen($l_str_StartingTag)); /* set replacer for the footnote */ $l_str_ReplaceText = str_replace("[[FOOTNOTE INDEX]]", footnote_convert_index($l_int_FootnoteIndex, $l_str_CounterStyle), $l_str_FootnoteTemplate); $l_str_ReplaceText = str_replace("[[FOOTNOTE TEXT]]", $l_str_FootnoteText, $l_str_ReplaceText); $l_str_ReplaceText = preg_replace('@[\s]{2,}@',' ',$l_str_ReplaceText); /* replace footnote in content */ $p_str_Content = substr_replace($p_str_Content, $l_str_ReplaceText, $l_int_PosStart, $l_int_Length + strlen($l_str_EndingTag)); /* set footnote to the output box at the end */ $g_arr_Footnotes[] = $l_str_FootnoteText; /* increase footnote index */ $l_int_FootnoteIndex++; /* add offset to the new starting position */ $l_int_PosStart += ($l_int_PosEnd - $l_int_PosStart); /* no ending tag found */ } else { $l_int_PosStart++; } /* no starting tag found */ } else { break; } } while (true); /* return content */ return $p_str_Content; } /** * looks through all footnotes that has been replaced in the current content and * adds a reference to the footnote at the end of the content * function to collapse the reference container since 1.0-beta * @since 1.0 * @return string */ function footnotes_OutputReferenceContainer() { /* get access to the global array to read footnotes */ global $g_arr_Footnotes; /* access to the global settings collection */ global $g_arr_FootnotesSettings; /* no footnotes has been replaced on this page */ if (empty($g_arr_Footnotes)) { /* return empty string */ return ""; } /* get setting for combine identical footnotes and convert it to boolean */ $l_bool_CombineIdentical = footnotes_ConvertToBool($g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_COMBINE_IDENTICAL]); /* get setting for preferences label */ $l_str_ReferencesLabel = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_REFERENCES_LABEL]; /* get setting for collapse reference footnotes and convert it to boolean */ $l_bool_CollapseReference = footnotes_ConvertToBool($g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_COLLAPSE_REFERENCES]); /*get footnote counter style */ $l_str_CounterStyle = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_COUNTER_STYLE]; /* * add expand/collapse buttons to the reference label if collapsed by default * @since 1.2.2 */ $l_str_CollapseButtons = ""; if ($l_bool_CollapseReference) { $l_str_CollapseButtons = ' [ + ]'; } /* output string, prepare it with the reference label as headline */ $l_str_Output = '
' . $l_str_ReferencesLabel . '' .$l_str_CollapseButtons . '