diff --git a/README.md b/README.md index c7a78ff..0e8c343 100755 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -footnotes -========= +![footnotes](https://raw.githubusercontent.com/media-competence-institute/footnotes/master/assets/footnotes.png) **footnotes** WordPress Plugin @@ -7,6 +6,7 @@ footnotes **footnotes** gives you the ability to display decently-formated footnotes on your WordPress Pages or Posts. + The syntax is based on the common DokuWiki syntax for footnotes. So, to include a footnote with the text "with a footnote," you use: Your awesome text((with a footnote)) diff --git a/classes/footnotes_settings.php b/classes/footnotes_settings.php index 32cc67c..499b5ac 100644 --- a/classes/footnotes_settings.php +++ b/classes/footnotes_settings.php @@ -21,7 +21,9 @@ class Class_FootnotesSettings public static $a_arr_Default_Settings = array( FOOTNOTE_INPUTFIELD_COMBINE_IDENTICAL => 'yes', FOOTNOTE_INPUTFIELD_REFERENCES_LABEL => 'References', - FOOTNOTE_INPUTFIELD_COLLAPSE_REFERENCES => '' + FOOTNOTE_INPUTFIELD_COLLAPSE_REFERENCES => '', + FOOTNOTE_INPUTFIELD_PLACEHOLDER_START => '((', + FOOTNOTE_INPUTFIELD_PLACEHOLDER_END => '))' ); /* * resulting pagehook for adding a new sub menu page to the settings @@ -45,10 +47,8 @@ class Class_FootnotesSettings */ function __construct() { - /* validates the settings of the plugin and replaces them with the default settings if invalid */ - add_option( FOOTNOTE_SETTINGS_CONTAINER, self::$a_arr_Default_Settings ); /* loads and filters the settings for this plugin */ - $this->a_arr_Options = footnotes_filter_options( FOOTNOTE_SETTINGS_CONTAINER ); + $this->a_arr_Options = footnotes_filter_options( FOOTNOTE_SETTINGS_CONTAINER, self::$a_arr_Default_Settings ); /* execute class includes on action-even: init, admin_init and admin_menu */ add_action( 'init', array( $this, 'LoadScriptsAndStylesheets' ) ); @@ -208,9 +208,11 @@ class Class_FootnotesSettings * outputs a input type=text * @param string $p_str_SettingsID [id of the settings field] * @param string $p_str_ClassName [css class name] + * @param int $p_str_MaxLength [max length for the input value] + * @param string $p_str_Label [label text] * @since 1.0-beta */ - function AddTextbox($p_str_SettingsID, $p_str_ClassName="") + function AddTextbox($p_str_SettingsID, $p_str_ClassName="", $p_str_MaxLength=0, $p_str_Label="") { /* collect data for given settings field */ $l_arr_Data = $this->LoadSetting( $p_str_SettingsID ); @@ -219,9 +221,17 @@ class Class_FootnotesSettings if (!empty($p_str_ClassName)) { $p_str_ClassName = 'class="' . $p_str_ClassName . '"'; } + /* optional add a maxlength to the input field */ + if (!empty($p_str_MaxLength)) { + $p_str_MaxLength = ' maxlength="'.$p_str_MaxLength.'"'; + } + /* optional add a label in front of the input field */ + if (!empty($p_str_Label)) { + echo ''; + } /* outputs an input field type TEXT */ - echo ''; + echo ''; } /** @@ -301,6 +311,7 @@ class Class_FootnotesSettings add_settings_field( 'Register_References_Label', __( "References label:", FOOTNOTES_PLUGIN_NAME ), array( $this, 'Register_References_Label' ), FOOTNOTE_SETTINGS_LABEL_GENERAL, $l_str_SectionName ); add_settings_field( 'Register_Collapse_References', __( "Collapse references by default:", FOOTNOTES_PLUGIN_NAME ), array( $this, 'Register_Collapse_References' ), FOOTNOTE_SETTINGS_LABEL_GENERAL, $l_str_SectionName ); add_settings_field( 'Register_Combine_Identical', __( "Combine identical footnotes:", FOOTNOTES_PLUGIN_NAME ), array( $this, 'Register_Combine_Identical' ), FOOTNOTE_SETTINGS_LABEL_GENERAL, $l_str_SectionName ); + add_settings_field( 'Register_Placeholder_Tags', __( "Footnote tag:", FOOTNOTES_PLUGIN_NAME ), array( $this, 'Register_Placeholder_Tags' ), FOOTNOTE_SETTINGS_LABEL_GENERAL, $l_str_SectionName ); } /** @@ -348,6 +359,20 @@ class Class_FootnotesSettings $this->AddSelectbox(FOOTNOTE_INPUTFIELD_COMBINE_IDENTICAL, $l_arr_Options, "footnote_plugin_25"); } + /** + * outputs the settings fields for the footnote starting and ending tag + * @since 1.0-gamma + */ + function Register_Placeholder_Tags() + { + /* add a textbox to the output */ + $this->AddTextbox(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START, "", 14, __( "starts with:", FOOTNOTES_PLUGIN_NAME )); + /* small space between the two input fields */ + echo '   '; + /* add a textbox to the output */ + $this->AddTextbox(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END, "", 14, __( "ends with:", FOOTNOTES_PLUGIN_NAME )); + } + /** * initialize howto settings tab * called in class constructor @ admin_init @@ -379,25 +404,27 @@ class Class_FootnotesSettings */ function Register_Howto_Box() { + $l_arr_Footnote_StartingTag = $this->LoadSetting(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START); + $l_arr_Footnote_EndingTag = $this->LoadSetting(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END); ?>

- +

- +

- +      - +

diff --git a/includes/defines.php b/includes/defines.php index 6ce803d..fcb8423 100644 --- a/includes/defines.php +++ b/includes/defines.php @@ -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 */ diff --git a/includes/plugin-settings.php b/includes/plugin-settings.php index 43625ec..415a0f1 100644 --- a/includes/plugin-settings.php +++ b/includes/plugin-settings.php @@ -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; diff --git a/includes/replacer.php b/includes/replacer.php index c2230e2..145b3ae 100644 --- a/includes/replacer.php +++ b/includes/replacer.php @@ -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 */ diff --git a/index.php b/index.php index 33daf4a..d1c3103 100755 --- a/index.php +++ b/index.php @@ -4,7 +4,7 @@ Plugin URI: http://www.herndler.org Description: simple adding footnotes to your pages Author: Mark Cheret, Stefan Herndler - Version: 1.0.2 + Version: 1.0.3 Author URI: http://www.cheret.de Text Domain: footnotes Domain Path: /languages @@ -47,6 +47,11 @@ require_once( dirname( __FILE__ ) . "/includes/scripts.php" ); /* include script and stylesheet functions */ require_once( dirname( __FILE__ ) . "/includes/replacer.php" ); +/* require plugin class */ +require_once( dirname( __FILE__ ) . "/classes/footnotes.php" ); +/* require plugin settings class */ +require_once( dirname( __FILE__ ) . "/classes/footnotes_settings.php" ); + /* calls the wordpress filter function to replace page content before displayed on public pages */ add_filter( 'the_content', 'footnotes_startReplacing' ); add_filter( 'the_excerpt', 'footnotes_DummyReplacing' ); @@ -68,11 +73,6 @@ if ( !function_exists( 'is_admin' ) ) { exit(); } -/* require plugin class */ -require_once( dirname( __FILE__ ) . "/classes/footnotes.php" ); -/* require plugin settings class */ -require_once( dirname( __FILE__ ) . "/classes/footnotes_settings.php" ); - /* action to locate language and load the wordpress-specific language file */ add_action( 'plugins_loaded', 'footnotes_load_language' ); diff --git a/languages/footnotes-de.mo b/languages/footnotes-de.mo index 3ef8d1d..c340cbc 100755 Binary files a/languages/footnotes-de.mo and b/languages/footnotes-de.mo differ diff --git a/languages/footnotes-de.po b/languages/footnotes-de.po index 6dba5bd..06cd63b 100755 --- a/languages/footnotes-de.po +++ b/languages/footnotes-de.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: footnotes\n" -"POT-Creation-Date: 2014-05-16 21:52+0100\n" -"PO-Revision-Date: 2014-05-16 21:53+0100\n" +"POT-Creation-Date: 2014-05-16 22:36+0100\n" +"PO-Revision-Date: 2014-05-16 22:37+0100\n" "Last-Translator: SHE \n" "Language-Team: SHE \n" "Language: de\n" @@ -18,59 +18,71 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Poedit-SearchPath-0: .\n" -#: classes/footnotes_settings.php:298 +#: classes/footnotes_settings.php:308 msgid "General" msgstr "Allgemein" -#: classes/footnotes_settings.php:300 includes/plugin-settings.php:22 +#: classes/footnotes_settings.php:310 includes/plugin-settings.php:22 msgid "Settings" msgstr "Einstellungen" -#: classes/footnotes_settings.php:301 +#: classes/footnotes_settings.php:311 msgid "References label:" msgstr "Überschrift \"Einzelnachweis\":" -#: classes/footnotes_settings.php:302 +#: classes/footnotes_settings.php:312 msgid "Collapse references by default:" msgstr "Verstecke Einzelnachweise standardmäßig:" -#: classes/footnotes_settings.php:303 +#: classes/footnotes_settings.php:313 msgid "Combine identical footnotes:" msgstr "Kombiniere meine Fußnoten:" -#: classes/footnotes_settings.php:344 +#: classes/footnotes_settings.php:314 +msgid "Footnote tag:" +msgstr "Fußzeile einbinden:" + +#: classes/footnotes_settings.php:355 msgid "Yes" msgstr "Ja" -#: classes/footnotes_settings.php:345 +#: classes/footnotes_settings.php:356 msgid "No" msgstr "Nein" -#: classes/footnotes_settings.php:360 classes/footnotes_settings.php:362 +#: classes/footnotes_settings.php:369 +msgid "starts with:" +msgstr "beginnt mit:" + +#: classes/footnotes_settings.php:373 +msgid "ends with:" +msgstr "endet mit:" + +#: classes/footnotes_settings.php:385 classes/footnotes_settings.php:387 msgid "HowTo" msgstr "Hilfe" -#: classes/footnotes_settings.php:373 +#: classes/footnotes_settings.php:398 msgid "This is a brief introduction in how to use the plugin." msgstr "Eine kurze Anleitung für die Verwendung des Plugins." -#: classes/footnotes_settings.php:386 +#: classes/footnotes_settings.php:413 msgid "Start your footnote with the following shortcode:" msgstr "Starten Sie eine Fußnote mit:" -#: classes/footnotes_settings.php:391 +#: classes/footnotes_settings.php:418 msgid "...and end your footnote with this shortcode:" msgstr "...und beenden Sie diese mit:" -#: classes/footnotes_settings.php:397 classes/footnotes_settings.php:400 +#: classes/footnotes_settings.php:424 classes/footnotes_settings.php:427 msgid "example string" msgstr "Beispieltext" -#: classes/footnotes_settings.php:398 +#: classes/footnotes_settings.php:425 msgid "will be displayed as:" msgstr "wird dargestellt als:" -#: classes/footnotes_settings.php:405 +#: classes/footnotes_settings.php:432 #, php-format msgid "If you have any questions, please don't hesitate to %smail us%s." msgstr "Bei Fragen können Sie uns gerne eine %se-Mail%s senden." diff --git a/languages/footnotes-en.mo b/languages/footnotes-en.mo index df8504a..6fa1a95 100755 Binary files a/languages/footnotes-en.mo and b/languages/footnotes-en.mo differ diff --git a/languages/footnotes-en.po b/languages/footnotes-en.po index d31da85..d8471f2 100755 --- a/languages/footnotes-en.po +++ b/languages/footnotes-en.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: footnotes\n" -"POT-Creation-Date: 2014-05-16 21:52+0100\n" -"PO-Revision-Date: 2014-05-16 21:52+0100\n" +"POT-Creation-Date: 2014-05-16 22:36+0100\n" +"PO-Revision-Date: 2014-05-16 22:36+0100\n" "Last-Translator: SHE \n" "Language-Team: SHE \n" "Language: en\n" @@ -18,59 +18,71 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Poedit-SearchPath-0: .\n" -#: classes/footnotes_settings.php:298 +#: classes/footnotes_settings.php:308 msgid "General" msgstr "General" -#: classes/footnotes_settings.php:300 includes/plugin-settings.php:22 +#: classes/footnotes_settings.php:310 includes/plugin-settings.php:22 msgid "Settings" msgstr "Settings" -#: classes/footnotes_settings.php:301 +#: classes/footnotes_settings.php:311 msgid "References label:" msgstr "References label:" -#: classes/footnotes_settings.php:302 +#: classes/footnotes_settings.php:312 msgid "Collapse references by default:" msgstr "Collapse references by default:" -#: classes/footnotes_settings.php:303 +#: classes/footnotes_settings.php:313 msgid "Combine identical footnotes:" msgstr "Combine identical footnotes:" -#: classes/footnotes_settings.php:344 +#: classes/footnotes_settings.php:314 +msgid "Footnote tag:" +msgstr "Footnote tag:" + +#: classes/footnotes_settings.php:355 msgid "Yes" msgstr "Yes" -#: classes/footnotes_settings.php:345 +#: classes/footnotes_settings.php:356 msgid "No" msgstr "No" -#: classes/footnotes_settings.php:360 classes/footnotes_settings.php:362 +#: classes/footnotes_settings.php:369 +msgid "starts with:" +msgstr "starts with:" + +#: classes/footnotes_settings.php:373 +msgid "ends with:" +msgstr "ends with:" + +#: classes/footnotes_settings.php:385 classes/footnotes_settings.php:387 msgid "HowTo" msgstr "HowTo" -#: classes/footnotes_settings.php:373 +#: classes/footnotes_settings.php:398 msgid "This is a brief introduction in how to use the plugin." msgstr "This is a brief introduction in how to use the plugin." -#: classes/footnotes_settings.php:386 +#: classes/footnotes_settings.php:413 msgid "Start your footnote with the following shortcode:" msgstr "Start your footnote with the following shortcode:" -#: classes/footnotes_settings.php:391 +#: classes/footnotes_settings.php:418 msgid "...and end your footnote with this shortcode:" msgstr "...and end your footnote with this shortcode:" -#: classes/footnotes_settings.php:397 classes/footnotes_settings.php:400 +#: classes/footnotes_settings.php:424 classes/footnotes_settings.php:427 msgid "example string" msgstr "example string" -#: classes/footnotes_settings.php:398 +#: classes/footnotes_settings.php:425 msgid "will be displayed as:" msgstr "will be displayed as:" -#: classes/footnotes_settings.php:405 +#: classes/footnotes_settings.php:432 #, php-format msgid "If you have any questions, please don't hesitate to %smail us%s." msgstr "If you have any questions, please don't hesitate to %smail us%s." diff --git a/readme.txt b/readme.txt index 1f963d2..211564b 100755 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Requires at least: 3.9 Tested up to: 3.9.1 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html -Stable tag: 1.0.2 +Stable Tag: 1.0.3 == Description == @@ -35,6 +35,11 @@ coming soon == Changelog == += 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) + = 1.0.2 = * New setting to collapse the reference container by default * Added link behind the footnotes to automatically jump to the reference container @@ -49,7 +54,7 @@ coming soon * Updated translations for EN and DE * Changed version number from 3 digits to 2 digits -= 1.0 = += 1.0.0 = * First development Version of the Plugin == Feedback ==