Version 1.0.3
* New setting to use personal starting and ending tag for the footnotes * Updated translations for the new setting * Updated reading settings and fallback to default values (bugfix) git-svn-id: https://plugins.svn.wordpress.org/footnotes/trunk@917813 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
parent
ab368ba787
commit
5d475abfc3
11 changed files with 144 additions and 63 deletions
|
@ -23,10 +23,8 @@ define( "FOOTNOTE_SETTINGS_LABEL_HOWTO", "footnotes_howto" ); /* internal label
|
|||
define( "FOOTNOTE_INPUTFIELD_COMBINE_IDENTICAL", "footnote_inputfield_combine_identical" ); /* id of input field for the combine identical setting */
|
||||
define( "FOOTNOTE_INPUTFIELD_REFERENCES_LABEL", "footnote_inputfield_references_label" ); /* id of input field for the references label setting */
|
||||
define( "FOOTNOTE_INPUTFIELD_COLLAPSE_REFERENCES", "footnote_inputfield_collapse_references" ); /* id of input field for the "collapse references" setting */
|
||||
|
||||
/* PLUGIN DEFAULT PLACEHOLDER */
|
||||
define( "FOOTNOTE_PLACEHOLDER_START", "((" ); /* defines the default start tag for the placeholder */
|
||||
define( "FOOTNOTE_PLACEHOLDER_END", "))" ); /* defines the default end tag for the placeholder */
|
||||
define( "FOOTNOTE_INPUTFIELD_PLACEHOLDER_START", "footnote_inputfield_placeholder_start"); /* id of input field for the "placeholder starting tag" setting */
|
||||
define( "FOOTNOTE_INPUTFIELD_PLACEHOLDER_END", "footnote_inputfield_placeholder_end"); /* id of input field for the "placeholder ending tag" setting */
|
||||
|
||||
/* PLUGIN REFERENCES CONTAINER ID */
|
||||
define( "FOOTNOTE_REFERENCES_CONTAINER_ID", "footnote_references_container" ); /* id for the div surrounding the footnotes */
|
||||
|
|
|
@ -29,16 +29,28 @@ function footnotes_plugin_settings_link( $links, $file )
|
|||
|
||||
/**
|
||||
* reads a option field, filters the values and returns the filtered option array
|
||||
* fallback to default value since 1.0-gamma
|
||||
* @since 1.0
|
||||
* @param string $p_str_OptionsField
|
||||
* @param array $p_arr_DefaultValues
|
||||
* @return array
|
||||
*/
|
||||
function footnotes_filter_options( $p_str_OptionsField )
|
||||
function footnotes_filter_options( $p_str_OptionsField, $p_arr_DefaultValues )
|
||||
{
|
||||
$l_arr_Options = get_option( $p_str_OptionsField );
|
||||
/* loop through all keys in the array and filters them */
|
||||
foreach ( $l_arr_Options as $l_str_Key => $l_str_Value ) {
|
||||
$l_arr_Options[ $l_str_Key ] = stripcslashes( $l_str_Value );
|
||||
/* removes special chars from the settings value */
|
||||
$l_str_Value = stripcslashes( $l_str_Value );
|
||||
/* check if settings value is not empty, otherwise load the default value, or empty string if no default is defined */
|
||||
if (!empty($l_str_Value)) {
|
||||
$l_arr_Options[ $l_str_Key ] = stripcslashes( $l_str_Value );
|
||||
/* check if default value is defined */
|
||||
} else if (array_key_exists($l_str_Key, $p_arr_DefaultValues)) {
|
||||
$l_arr_Options[ $l_str_Key ] = $p_arr_DefaultValues[$l_str_Key];
|
||||
} else {
|
||||
$l_arr_Options[ $l_str_Key ] = "";
|
||||
}
|
||||
}
|
||||
/* returns the filtered array */
|
||||
return $l_arr_Options;
|
||||
|
|
|
@ -34,7 +34,7 @@ function footnotes_startReplacing( $p_str_Content )
|
|||
/* stop the output and move it to a buffer instead, defines a callback function */
|
||||
ob_start( "footnotes_replaceFootnotes" );
|
||||
/* load footnote settings */
|
||||
$g_arr_FootnotesSettings = footnotes_filter_options( FOOTNOTE_SETTINGS_CONTAINER );
|
||||
$g_arr_FootnotesSettings = footnotes_filter_options( FOOTNOTE_SETTINGS_CONTAINER, Class_FootnotesSettings::$a_arr_Default_Settings );
|
||||
/* return unchanged content */
|
||||
return $p_str_Content;
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ function footnotes_StopReplacing()
|
|||
|
||||
/**
|
||||
* 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]
|
||||
|
@ -73,6 +74,13 @@ function footnotes_replaceFootnotes( $p_str_Content, $p_bool_OutputReferences =
|
|||
{
|
||||
/* get access to the global array */
|
||||
global $g_arr_Footnotes;
|
||||
/* access to the global settings collection */
|
||||
global $g_arr_FootnotesSettings;
|
||||
/* check if settings are already loaded, otherwise load them */
|
||||
if (empty($g_arr_FootnotesSettings)) {
|
||||
/* load footnote settings */
|
||||
$g_arr_FootnotesSettings = footnotes_filter_options( FOOTNOTE_SETTINGS_CONTAINER, Class_FootnotesSettings::$a_arr_Default_Settings );
|
||||
}
|
||||
|
||||
/* replace all footnotes in the content */
|
||||
$p_str_Content = footnotes_getFromString( $p_str_Content );
|
||||
|
@ -89,6 +97,7 @@ function footnotes_replaceFootnotes( $p_str_Content, $p_bool_OutputReferences =
|
|||
|
||||
/**
|
||||
* 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
|
||||
* @return string
|
||||
|
@ -97,32 +106,38 @@ function footnotes_getFromString( $p_str_Content )
|
|||
{
|
||||
/* 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 = 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];
|
||||
|
||||
/* 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, FOOTNOTE_PLACEHOLDER_START, $l_int_PosStart );
|
||||
$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, FOOTNOTE_PLACEHOLDER_END, $l_int_PosStart );
|
||||
$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( FOOTNOTE_PLACEHOLDER_START ), $l_int_Length - strlen( FOOTNOTE_PLACEHOLDER_START ) );
|
||||
$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]]", $l_int_FootnoteIndex, $l_str_FootnoteTemplate );
|
||||
$l_str_ReplaceText = str_replace( "[[FOOTNOTE TEXT]]", $l_str_FootnoteText, $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( FOOTNOTE_PLACEHOLDER_END ) );
|
||||
$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 */
|
||||
|
|
Reference in a new issue