Version 1.0.2

* New setting to collapse the reference container by default
* Added link behind the footnotes to automatically jump to the reference container
* New function to easy output input fields for the settings page
* Updated translation for the new setting

git-svn-id: https://plugins.svn.wordpress.org/footnotes/trunk@917811 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
Aricura 2014-05-20 11:38:36 +00:00
parent 2e8614908f
commit ab368ba787
16 changed files with 655 additions and 60 deletions

View file

@ -4,7 +4,7 @@
* User: Stefan
* Date: 15.05.14
* Time: 16:21
* Version: 1.0
* Version: 1.0-beta
* Since: 1.0
*/
@ -22,11 +22,15 @@ define( "FOOTNOTE_SETTINGS_LABEL_HOWTO", "footnotes_howto" ); /* internal label
/* PLUGIN SETTINGS INPUT FIELDS */
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 */
/* PLUGIN REFERENCES CONTAINER ID */
define( "FOOTNOTE_REFERENCES_CONTAINER_ID", "footnote_references_container" ); /* id for the div surrounding the footnotes */
/* PLUGIN DIRECTORIES */
define( "FOOTNOTES_PLUGIN_DIR_NAME", "footnotes" );
define( "FOOTNOTES_LANGUAGE_DIR", dirname( __FILE__ ) . "/../languages/" );

View file

@ -4,7 +4,7 @@
* User: Stefan
* Date: 15.05.14
* Time: 16:21
* Version: 1.0
* Version: 1.0-beta
* Since: 1.0
*/
@ -33,7 +33,7 @@ function footnotes_plugin_settings_link( $links, $file )
* @param string $p_str_OptionsField
* @return array
*/
function footnote_filter_options( $p_str_OptionsField )
function footnotes_filter_options( $p_str_OptionsField )
{
$l_arr_Options = get_option( $p_str_OptionsField );
/* loop through all keys in the array and filters them */
@ -42,4 +42,26 @@ function footnote_filter_options( $p_str_OptionsField )
}
/* returns the filtered array */
return $l_arr_Options;
}
/**
* converts a string depending on its value to a boolean
* @since 1.0-beta
* @param string $p_str_Value
* @return bool
*/
function footnotes_ConvertToBool($p_str_Value) {
/* convert string to lower-case to make it easier */
$p_str_Value = strtolower($p_str_Value);
/* check if string seems to contain a "true" value */
switch($p_str_Value) {
case "checked":
case "yes":
case "true":
case "on":
case "1":
return true;
}
/* nothing found that says "true", so we return false */
return false;
}

View file

@ -14,6 +14,12 @@
*/
$g_arr_Footnotes = array();
/*
* collection of all footnotes settings
* @since 1.0-beta
*/
$g_arr_FootnotesSettings = array();
/**
* starts listening for footnotes to be replaced
* output will be buffered and not displayed
@ -23,7 +29,13 @@ $g_arr_Footnotes = array();
*/
function footnotes_startReplacing( $p_str_Content )
{
/* access to the global settings collection */
global $g_arr_FootnotesSettings;
/* 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 );
/* return unchanged content */
return $p_str_Content;
}
@ -35,6 +47,7 @@ function footnotes_startReplacing( $p_str_Content )
*/
function footnotes_DummyReplacing( $p_str_Content )
{
/* return unchanged content */
return $p_str_Content;
}
@ -45,6 +58,7 @@ function footnotes_DummyReplacing( $p_str_Content )
*/
function footnotes_StopReplacing()
{
/* calls the callback function defined in ob_start(); */
ob_end_flush();
}
@ -130,6 +144,9 @@ function footnotes_getFromString( $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
*/
@ -137,6 +154,8 @@ 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 ) ) {
@ -144,20 +163,22 @@ function footnotes_OutputReferenceContainer()
return "";
}
/* read settings */
$l_arr_Options = footnote_filter_options( FOOTNOTE_SETTINGS_CONTAINER );
/* get setting for combine identical footnotes */
$l_str_CombineIdentical = $l_arr_Options[ FOOTNOTE_INPUTFIELD_COMBINE_IDENTICAL ];
/* 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 = $l_arr_Options[ FOOTNOTE_INPUTFIELD_REFERENCES_LABEL ];
/* convert it from string to boolean */
$l_bool_CombineIdentical = false;
if ( $l_str_CombineIdentical == "yes" ) {
$l_bool_CombineIdentical = true;
}
$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 ]);
/* output string */
$l_str_Output = '<div class="footnote_container_prepare"><p><span>' . $l_str_ReferencesLabel . '</span></p></div>';
/* output string, prepare it with the reference label as headline */
$l_str_Output = '<div class="footnote_container_prepare"><p><span onclick="footnote_expand_reference_container();">' . $l_str_ReferencesLabel . '</span></p></div>';
/* add a box around the footnotes */
$l_str_Output .= '<div id="'.FOOTNOTE_REFERENCES_CONTAINER_ID.'"';
/* add class to hide the references by default, if the user wants it */
if ($l_bool_CollapseReference) {
$l_str_Output .= ' class="footnote_hide_box"';
}
$l_str_Output .= '>';
/* contains the footnote template */
$l_str_FootnoteTemplate = file_get_contents( FOOTNOTES_TEMPLATES_DIR . "container.html" );
@ -195,6 +216,17 @@ function footnotes_OutputReferenceContainer()
/* add the footnote container to the output */
$l_str_Output = $l_str_Output . $l_str_ReplaceText;
}
/* add closing tag for the div of the references container */
$l_str_Output = $l_str_Output . '</div>';
/* add a javascript to expand the reference container when clicking on a footnote or the reference label */
$l_str_Output .= '
<script type="text/javascript">
function footnote_expand_reference_container() {
jQuery("#'.FOOTNOTE_REFERENCES_CONTAINER_ID.'").show();
}
</script>
';
/* return the output string */
return $l_str_Output;
}

View file

@ -16,9 +16,9 @@
function footnotes_add_public_stylesheet()
{
/* register public stylesheet */
wp_register_style( 'footnote_public_style', plugins_url( '../css/footnote.css', __FILE__ ) );
wp_register_style( 'footnotes_public_style', plugins_url( '../css/footnote.css', __FILE__ ) );
/* add public stylesheet */
wp_enqueue_style( 'footnote_public_style' );
wp_enqueue_style( 'footnotes_public_style' );
}
/**
@ -28,7 +28,7 @@ function footnotes_add_public_stylesheet()
function footnotes_add_settings_stylesheet()
{
/* register settings stylesheet */
wp_register_style( 'footnote_settings_style', plugins_url( '../css/settings.css', __FILE__ ) );
wp_register_style( 'footnotes_settings_style', plugins_url( '../css/settings.css', __FILE__ ) );
/* add settings stylesheet */
wp_enqueue_style( 'footnote_settings_style' );
wp_enqueue_style( 'footnotes_settings_style' );
}