Changes for upcoming version 1.3.0
- Bugfix: Changed tooltip class to be unique - Bugfix: Changed superscript styling to not manipulate the line height - Bugfix: Changed styling of the footnotes text in the reference container to avoid line breaks - Updated: Reformatted code - Added: new settings tab for custom CSS settings git-svn-id: https://plugins.svn.wordpress.org/footnotes/trunk@957947 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
parent
0f3996338b
commit
3802249ec4
26 changed files with 2137 additions and 1651 deletions
|
@ -1,110 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by Stefan Herndler.
|
||||
* User: Stefan
|
||||
* Date: 17.05.14
|
||||
* Time: 00:16
|
||||
* Version: 1.0
|
||||
* Since: 1.0-gamma
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* converts a integer into the user-defined counter style for the footnotes
|
||||
* @since 1.0-gamma
|
||||
* @param int $p_int_Index
|
||||
* @param string $p_str_ConvertStyle [counter style]
|
||||
* @return string
|
||||
*/
|
||||
function footnote_convert_index($p_int_Index, $p_str_ConvertStyle = "arabic_plain")
|
||||
{
|
||||
switch ($p_str_ConvertStyle) {
|
||||
case "romanic":
|
||||
return footnote_convert_to_romanic($p_int_Index);
|
||||
case "latin_high":
|
||||
return footnote_convert_to_latin($p_int_Index, true);
|
||||
case "latin_low":
|
||||
return footnote_convert_to_latin($p_int_Index, false);
|
||||
case "arabic_leading":
|
||||
return footnote_convert_to_arabic_leading($p_int_Index);
|
||||
case "arabic_plain":
|
||||
default:
|
||||
return $p_int_Index;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* converts a integer into latin ascii characters, either lower or upper-case
|
||||
* function available from A to ZZ ( means 676 footnotes at 1 page possible)
|
||||
* @since 1.0-gamma
|
||||
* @param int $p_int_Value
|
||||
* @param bool $p_bool_UpperCase
|
||||
* @return string
|
||||
*/
|
||||
function footnote_convert_to_latin($p_int_Value, $p_bool_UpperCase)
|
||||
{
|
||||
/* decimal value of the starting ascii character */
|
||||
$l_int_StartinAscii = 65 - 1; // = A
|
||||
/* if lower-case, change decimal to lower-case "a" */
|
||||
if (!$p_bool_UpperCase) {
|
||||
$l_int_StartinAscii = 97 - 1; // = a
|
||||
}
|
||||
/* output string */
|
||||
$l_str_Return = "";
|
||||
$l_int_Offset = 0;
|
||||
/* check if the value is higher then 26 = Z */
|
||||
while ($p_int_Value > 26) {
|
||||
/* increase offset and reduce counter */
|
||||
$l_int_Offset++;
|
||||
$p_int_Value -= 26;
|
||||
}
|
||||
/* if offset set (more then Z), then add a new letter in fron */
|
||||
if ($l_int_Offset > 0) {
|
||||
$l_str_Return = chr($l_int_Offset + $l_int_StartinAscii);
|
||||
}
|
||||
/* add the origin letter */
|
||||
$l_str_Return .= chr($p_int_Value + $l_int_StartinAscii);
|
||||
/* return the latin character representing the integer */
|
||||
return $l_str_Return;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts a integer to a leading-0 integer
|
||||
* @since 1.0-gamma
|
||||
* @param int $p_int_Value
|
||||
* @return string
|
||||
*/
|
||||
function footnote_convert_to_arabic_leading($p_int_Value)
|
||||
{
|
||||
/* add a leading 0 if number lower then 10 */
|
||||
if ($p_int_Value < 10) {
|
||||
return "0" . $p_int_Value;
|
||||
}
|
||||
return $p_int_Value;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts a arabic integer value into a romanic letter value
|
||||
* @since 1.0-gamma
|
||||
* @param int $p_int_Value
|
||||
* @return string
|
||||
*/
|
||||
function footnote_convert_to_romanic($p_int_Value)
|
||||
{
|
||||
/* table containing all necessary romanic letters */
|
||||
$l_arr_RomanicLetters = array('M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1);
|
||||
/* return value */
|
||||
$l_str_Return = '';
|
||||
/* loop through integer value until it is reduced to 0 */
|
||||
while ($p_int_Value > 0) {
|
||||
foreach ($l_arr_RomanicLetters as $l_str_Romanic => $l_int_Arabic) {
|
||||
if ($p_int_Value >= $l_int_Arabic) {
|
||||
$p_int_Value -= $l_int_Arabic;
|
||||
$l_str_Return .= $l_str_Romanic;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* return romanic letters as string */
|
||||
return $l_str_Return;
|
||||
}
|
|
@ -8,70 +8,56 @@
|
|||
* Since: 1.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* PLUGIN PUBLIC NAME WITH STYLING
|
||||
* @since 1.0.7
|
||||
*/
|
||||
// PLUGIN INTERNAL NAME
|
||||
define("FOOTNOTES_PLUGIN_NAME", "footnotes");
|
||||
// PLUGIN PUBLIC NAME WITH STYLING
|
||||
// @since 1.0.7
|
||||
define("FOOTNOTES_PLUGIN_PUBLIC_NAME", '<span class="footnote_tag_styling footnote_tag_styling_1">foot</span><span class="footnote_tag_styling footnote_tag_styling_2">notes</span>');
|
||||
|
||||
/*
|
||||
* PLUGIN LOVE SYMBOL WITH STYLING
|
||||
* @since 1.2.2
|
||||
*/
|
||||
// PLUGIN PUBLIC NAME WITH STYLING AND LINK
|
||||
// @since 1.2.2
|
||||
define("FOOTNOTES_PLUGIN_PUBLIC_NAME_LINKED", '<a href="http://wordpress.org/plugins/footnotes/" target="_blank" style="text-decoration:none;">' . FOOTNOTES_PLUGIN_PUBLIC_NAME . '</a>');
|
||||
// PLUGIN LOVE SYMBOL WITH STYLING
|
||||
// @since 1.2.2
|
||||
define("FOOTNOTES_LOVE_SYMBOL", '<span style="color:#ff6d3b; font-weight:bold;">♥</span>');
|
||||
|
||||
/*
|
||||
* PLUGIN PUBLIC NAME WITH LINK
|
||||
* @since 1.2.2
|
||||
*/
|
||||
define("FOOTNOTES_PLUGIN_PUBLIC_NAME_LINKED", '<a href="http://wordpress.org/plugins/footnotes/" target="_blank" style="text-decoration:none;">' . FOOTNOTES_PLUGIN_PUBLIC_NAME . '</a>');
|
||||
|
||||
/* GENERAL PLUGIN CONSTANTS */
|
||||
define("FOOTNOTES_PLUGIN_NAME", "footnotes"); /* plugin's internal name */
|
||||
define("FOOTNOTE_SETTINGS_CONTAINER", "footnotes_storage"); /* database container where all footnote settings are stored */
|
||||
|
||||
/* PLUGIN SETTINGS PAGE */
|
||||
define("FOOTNOTES_SETTINGS_PAGE_ID", "footnotes"); /* plugin's setting page internal id */
|
||||
|
||||
/* PLUGIN SETTINGS PAGE TABS */
|
||||
define("FOOTNOTE_SETTINGS_LABEL_GENERAL", "footnotes_general_settings"); /* internal label for the plugin's settings tab */
|
||||
define("FOOTNOTE_SETTINGS_LABEL_HOWTO", "footnotes_howto"); /* internal label for the plugin's settings tab */
|
||||
|
||||
/* 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 */
|
||||
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 */
|
||||
define("FOOTNOTE_INPUTFIELD_SEARCH_IN_EXCERPT", "footnote_inputfield_search_in_excerpt"); /* id of input field for the "allow footnotes in the excerpt" setting */
|
||||
define("FOOTNOTE_INPUTFIELD_LOVE", "footnote_inputfield_love"); /* id of input field for "love and share this plugin" setting */
|
||||
define("FOOTNOTE_INPUTFIELD_COUNTER_STYLE", "footnote_inputfield_counter_style"); /* id of input field for "counter style of footnote index" setting */
|
||||
/*
|
||||
* id of input field "placement of reference container" setting
|
||||
* @since 1.0.7
|
||||
*/
|
||||
define("FOOTNOTE_INPUTFIELD_REFERENCE_CONTAINER_PLACE", "footnote_inputfield_reference_container_place");
|
||||
|
||||
/*
|
||||
* id of input field for 'user defined placeholder start and end tag
|
||||
* @since 1.1.2
|
||||
*/
|
||||
define("FOOTNOTE_INPUTFIELD_PLACEHOLDER_START_USERDEFINED", "footnote_inputfield_placeholder_start_user_defined");
|
||||
define("FOOTNOTE_INPUTFIELD_PLACEHOLDER_END_USERDEFINED", "footnote_inputfield_placeholder_end_user_defined");
|
||||
|
||||
|
||||
/* PLUGIN REFERENCES CONTAINER ID */
|
||||
define("FOOTNOTE_REFERENCES_CONTAINER_ID", "footnote_references_container"); /* id for the div surrounding the footnotes */
|
||||
|
||||
/* PLUGIN DIRECTORIES */
|
||||
// PLUGIN DIRECTORIES
|
||||
define("FOOTNOTES_PLUGIN_DIR_NAME", "footnotes");
|
||||
define("FOOTNOTES_LANGUAGE_DIR", dirname(__FILE__) . "/../languages/");
|
||||
define("FOOTNOTES_TEMPLATES_DIR", dirname(__FILE__) . "/../templates/");
|
||||
|
||||
/*
|
||||
* PLUGIN PLACEHOLDER TO NOT DISPLAY THE 'LOVE ME' SLUG
|
||||
* @since 1.1.1
|
||||
*/
|
||||
define("FOOTNOTES_NO_SLUGME_PLUG", "[[no footnotes: love]]");
|
||||
|
||||
define("FOOTNOTES_REFERENCE_CONTAINER_POSITION", "[[footnotes reference container position]]");
|
||||
// SETTINGS CONTAINER
|
||||
define("FOOTNOTES_SETTINGS_CONTAINER", "footnotes_storage"); // database container where all footnote settings are stored
|
||||
define("FOOTNOTES_SETTINGS_CONTAINER_CUSTOM", "footnotes_storage_custom"); // database container where all 'custom' settings are stored
|
||||
// PLUGIN SETTINGS PAGE
|
||||
define("FOOTNOTES_SETTINGS_PAGE_ID", "footnotes"); // plugins setting page internal id
|
||||
// PLUGIN SETTINGS PAGE TABS
|
||||
define("FOOTNOTES_SETTINGS_TAB_GENERAL", "footnotes_general_settings"); // internal label for the plugins general settings tab
|
||||
define("FOOTNOTES_SETTINGS_TAB_CUSTOM", "footnotes_custom_settings"); // internal label for the plugins custom settings tab
|
||||
define("FOOTNOTES_SETTINGS_TAB_HOWTO", "footnotes_howto_settings"); // internal label for the plugins how to tab
|
||||
|
||||
|
||||
// PLUGIN SETTINGS INPUT FIELDS
|
||||
define("FOOTNOTES_INPUT_COMBINE_IDENTICAL", "footnote_inputfield_combine_identical"); // id of input field for the combine identical setting
|
||||
define("FOOTNOTES_INPUT_REFERENCES_LABEL", "footnote_inputfield_references_label"); // id of input field for the references label setting
|
||||
define("FOOTNOTES_INPUT_COLLAPSE_REFERENCES", "footnote_inputfield_collapse_references"); // id of input field for the "collapse references" setting
|
||||
define("FOOTNOTES_INPUT_PLACEHOLDER_START", "footnote_inputfield_placeholder_start"); // id of input field for the "placeholder starting tag" setting
|
||||
define("FOOTNOTES_INPUT_PLACEHOLDER_END", "footnote_inputfield_placeholder_end"); // id of input field for the "placeholder ending tag" setting
|
||||
define("FOOTNOTES_INPUT_SEARCH_IN_EXCERPT", "footnote_inputfield_search_in_excerpt"); // id of input field for the "allow footnotes in the excerpt" setting
|
||||
define("FOOTNOTES_INPUT_LOVE", "footnote_inputfield_love"); // id of input field for "love and share this plugin" setting
|
||||
define("FOOTNOTES_INPUT_COUNTER_STYLE", "footnote_inputfield_counter_style"); // id of input field for "counter style of footnote index" setting
|
||||
define("FOOTNOTES_INPUT_REFERENCE_CONTAINER_PLACE", "footnote_inputfield_reference_container_place"); // id of input field "placement of reference container" setting
|
||||
define("FOOTNOTES_INPUT_PLACEHOLDER_START_USERDEFINED", "footnote_inputfield_placeholder_start_user_defined"); // id of input field for 'user defined placeholder start tag
|
||||
define("FOOTNOTES_INPUT_PLACEHOLDER_END_USERDEFINED", "footnote_inputfield_placeholder_end_user_defined"); // id of input field for 'user defined placeholder end tag
|
||||
define("FOOTNOTES_INPUT_CUSTOM_CSS", "footnote_inputfield_custom_css"); // if of input field for 'custom css' setting
|
||||
|
||||
|
||||
// PLUGIN REFERENCES CONTAINER ID
|
||||
define("FOOTNOTES_REFERENCES_CONTAINER_ID", "footnote_references_container"); // id for the div surrounding the footnotes
|
||||
define("FOOTNOTES_REFERENCE_CONTAINER_POSITION", "[[footnotes reference container position]]");
|
||||
|
||||
|
||||
// PLUGIN PLACEHOLDER TO NOT DISPLAY THE 'LOVE ME' SLUG
|
||||
// @since 1.1.1
|
||||
define("FOOTNOTES_NO_SLUGME_PLUG", "[[no footnotes: love]]");
|
|
@ -8,48 +8,48 @@
|
|||
* Since: 1.0
|
||||
*/
|
||||
|
||||
// action to locate language and load the WordPress-specific language file
|
||||
add_action('plugins_loaded', 'MCI_Footnotes_LoadLanguage');
|
||||
|
||||
/**
|
||||
* loads the langauge file including localization if exists
|
||||
* otherwise loads the langauge file without localization information
|
||||
* loads the language file including localization if exists
|
||||
* otherwise loads the language file without localization information
|
||||
* @since 1.0
|
||||
*/
|
||||
function footnotes_load_language()
|
||||
{
|
||||
/* read current wordpress langauge */
|
||||
function MCI_Footnotes_LoadLanguage() {
|
||||
// read current WordPress language
|
||||
$l_str_locale = apply_filters('plugin_locale', get_locale(), FOOTNOTES_PLUGIN_NAME);
|
||||
/* get only language code (removed localization code) */
|
||||
$l_str_languageCode = footnotes_getLanguageCode();
|
||||
// get only language code (removed localization code)
|
||||
$l_str_languageCode = MCI_Footnotes_getLanguageCode();
|
||||
|
||||
/* language file with localization exists */
|
||||
if ($l_bool_loaded = load_textdomain(FOOTNOTES_PLUGIN_NAME, FOOTNOTES_LANGUAGE_DIR . FOOTNOTES_PLUGIN_NAME . '-' . $l_str_locale . '.mo')) {
|
||||
|
||||
/* language file without localization exists */
|
||||
} else if ($l_bool_loaded = load_textdomain(FOOTNOTES_PLUGIN_NAME, FOOTNOTES_LANGUAGE_DIR . FOOTNOTES_PLUGIN_NAME . '-' . $l_str_languageCode . '.mo')) {
|
||||
|
||||
/* load default language file, nothing will happen: default language will be used (=english) */
|
||||
} else {
|
||||
load_textdomain(FOOTNOTES_PLUGIN_NAME, FOOTNOTES_LANGUAGE_DIR . FOOTNOTES_PLUGIN_NAME . '-en.mo');
|
||||
}
|
||||
// language file with localization exists
|
||||
$l_bool_loaded = load_textdomain(FOOTNOTES_PLUGIN_NAME, FOOTNOTES_LANGUAGE_DIR . FOOTNOTES_PLUGIN_NAME . '-' . $l_str_locale . '.mo');
|
||||
if (empty($l_bool_loaded)) {
|
||||
// language file without localization exists
|
||||
$l_bool_loaded = load_textdomain(FOOTNOTES_PLUGIN_NAME, FOOTNOTES_LANGUAGE_DIR . FOOTNOTES_PLUGIN_NAME . '-' . $l_str_languageCode . '.mo');
|
||||
if (empty($l_bool_loaded)) {
|
||||
// fallback to english
|
||||
load_textdomain(FOOTNOTES_PLUGIN_NAME, FOOTNOTES_LANGUAGE_DIR . FOOTNOTES_PLUGIN_NAME . '-en.mo');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* reads the wordpress langauge and returns only the language code lowercase
|
||||
* reads the WordPress language and returns only the language code lowercase
|
||||
* removes the localization code
|
||||
* @since 1.0
|
||||
* @return string (only the "en" from "en_US")
|
||||
*/
|
||||
function footnotes_getLanguageCode()
|
||||
{
|
||||
/* read current wordpress langauge */
|
||||
function MCI_Footnotes_getLanguageCode() {
|
||||
// read current WordPress language
|
||||
$l_str_locale = apply_filters('plugin_locale', get_locale(), FOOTNOTES_PLUGIN_NAME);
|
||||
/* check if wordpress language has a localization (e.g. "en_US" or "de_AT") */
|
||||
// check if WordPress language has a localization (e.g. "en_US" or "de_AT")
|
||||
if (strpos($l_str_locale, "_") !== false) {
|
||||
/* remove localization code */
|
||||
// remove localization code
|
||||
$l_arr_languageCode = explode("_", $l_str_locale);
|
||||
$l_str_languageCode = $l_arr_languageCode[0];
|
||||
return $l_str_languageCode;
|
||||
}
|
||||
/* return language code lowercase */
|
||||
// return language code lowercase
|
||||
return strtolower($l_str_locale);
|
||||
}
|
|
@ -8,95 +8,103 @@
|
|||
* Since: 1.0
|
||||
*/
|
||||
|
||||
// add link to the settings page in plugin main page
|
||||
$l_str_plugin_file = FOOTNOTES_PLUGIN_DIR_NAME . '/index.php';
|
||||
add_filter("plugin_action_links_{$l_str_plugin_file}", 'MCI_Footnotes_PluginLinks', 10, 2);
|
||||
|
||||
/**
|
||||
* add short links to the plugin main page
|
||||
* @since 1.0
|
||||
* @param array $links
|
||||
* @param mixed $file
|
||||
* @param array $p_arr_Links
|
||||
* @param string $p_str_File
|
||||
* @return array
|
||||
*/
|
||||
function footnotes_plugin_settings_link($links, $file)
|
||||
{
|
||||
/* add link to the footnotes plugin settings page */
|
||||
function MCI_Footnotes_PluginLinks($p_arr_Links, $p_str_File) {
|
||||
// add link to the footnotes plugin settings page
|
||||
$l_str_SettingsLink = '<a href="' . admin_url('options-general.php?page=' . FOOTNOTES_SETTINGS_PAGE_ID) . '">' . __('Settings', FOOTNOTES_PLUGIN_NAME) . '</a>';
|
||||
/* add link to the footnotes plugin support page on wordpress.org */
|
||||
// add link to the footnotes plugin support page on wordpress.org
|
||||
$l_str_SupportLink = '<a href="http://wordpress.org/support/plugin/footnotes" target="_blank">' . __('Support', FOOTNOTES_PLUGIN_NAME) . '</a>';
|
||||
|
||||
/* add defined links to the plugin main page */
|
||||
$links[] = $l_str_SupportLink;
|
||||
$links[] = $l_str_SettingsLink;
|
||||
// add defined links to the plugin main page
|
||||
$p_arr_Links[] = $l_str_SupportLink;
|
||||
$p_arr_Links[] = $l_str_SettingsLink;
|
||||
|
||||
/* return new links */
|
||||
return $links;
|
||||
// return new links
|
||||
return $p_arr_Links;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param bool $p_bool_ConvertHtmlChars
|
||||
* @return array
|
||||
*/
|
||||
function footnotes_filter_options($p_str_OptionsField, $p_arr_DefaultValues, $p_bool_ConvertHtmlChars = true)
|
||||
{
|
||||
$l_arr_Options = get_option($p_str_OptionsField);
|
||||
/* if no settings set yet return default values */
|
||||
if (empty($l_arr_Options)) {
|
||||
return $p_arr_DefaultValues;
|
||||
}
|
||||
/* loop through all keys in the array and filters them */
|
||||
foreach ($l_arr_Options as $l_str_Key => $l_str_Value) {
|
||||
/* removes special chars from the settings value */
|
||||
$l_str_Value = stripcslashes($l_str_Value);
|
||||
/* if set, convert html special chars */
|
||||
if ($p_bool_ConvertHtmlChars) {
|
||||
$l_str_Value = htmlspecialchars($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] = "";
|
||||
}
|
||||
}
|
||||
function MCI_Footnotes_getOptions($p_bool_ConvertHtmlChars = true) {
|
||||
// default settings for the 'general' settings container
|
||||
$l_arr_Default_General = array(
|
||||
FOOTNOTES_INPUT_COMBINE_IDENTICAL => 'yes',
|
||||
FOOTNOTES_INPUT_REFERENCES_LABEL => 'References',
|
||||
FOOTNOTES_INPUT_COLLAPSE_REFERENCES => '',
|
||||
FOOTNOTES_INPUT_PLACEHOLDER_START => '((',
|
||||
FOOTNOTES_INPUT_PLACEHOLDER_END => '))',
|
||||
FOOTNOTES_INPUT_SEARCH_IN_EXCERPT => 'yes',
|
||||
FOOTNOTES_INPUT_LOVE => 'no',
|
||||
FOOTNOTES_INPUT_COUNTER_STYLE => 'arabic_plain',
|
||||
FOOTNOTES_INPUT_REFERENCE_CONTAINER_PLACE => 'post_end',
|
||||
FOOTNOTES_INPUT_PLACEHOLDER_START_USERDEFINED => '',
|
||||
FOOTNOTES_INPUT_PLACEHOLDER_END_USERDEFINED => ''
|
||||
);
|
||||
// default settings for the 'custom' settings container
|
||||
$l_arr_Default_Custom = array(
|
||||
FOOTNOTES_INPUT_CUSTOM_CSS => ''
|
||||
);
|
||||
|
||||
// check if each key from the default values exist in return array
|
||||
foreach($p_arr_DefaultValues as $l_str_Key => $l_str_Value) {
|
||||
// if key not exists, add it with its default value
|
||||
if (!array_key_exists($l_str_Key, $l_arr_Options)) {
|
||||
$l_arr_Options[$l_str_Key] = $l_str_Value;
|
||||
}
|
||||
}
|
||||
/* returns the filtered array */
|
||||
return $l_arr_Options;
|
||||
$l_arr_General = MCI_Footnotes_ValidateOptions(get_option(FOOTNOTES_SETTINGS_CONTAINER), $l_arr_Default_General, $p_bool_ConvertHtmlChars);
|
||||
$l_arr_Custom = MCI_Footnotes_ValidateOptions(get_option(FOOTNOTES_SETTINGS_CONTAINER_CUSTOM), $l_arr_Default_Custom, $p_bool_ConvertHtmlChars);
|
||||
|
||||
return array_merge($l_arr_General, $l_arr_Custom);
|
||||
}
|
||||
|
||||
/**
|
||||
* converts a string depending on its value to a boolean
|
||||
* @since 1.0-beta
|
||||
* @param string $p_str_Value
|
||||
* @return bool
|
||||
* validate each option, fallback is the default value
|
||||
* @since 1.3
|
||||
* @param array $p_arr_Options
|
||||
* @param array $p_arr_Default
|
||||
* @param bool $p_bool_ConvertHtmlChars
|
||||
* @return array
|
||||
*/
|
||||
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;
|
||||
function MCI_Footnotes_ValidateOptions($p_arr_Options, $p_arr_Default, $p_bool_ConvertHtmlChars) {
|
||||
// if no settings set yet return default values
|
||||
if (empty($p_arr_Options)) {
|
||||
return $p_arr_Default;
|
||||
}
|
||||
// loop through all keys in the array and filters them
|
||||
foreach ($p_arr_Options as $l_str_Key => $l_str_Value) {
|
||||
// removes special chars from the settings value
|
||||
$l_str_Value = stripcslashes($l_str_Value);
|
||||
// if set, convert html special chars
|
||||
if ($p_bool_ConvertHtmlChars) {
|
||||
$l_str_Value = htmlspecialchars($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)) {
|
||||
$p_arr_Options[$l_str_Key] = $l_str_Value;
|
||||
// check if default value is defined
|
||||
} else if (array_key_exists($l_str_Key, $p_arr_Default)) {
|
||||
$p_arr_Options[$l_str_Key] = $p_arr_Default[$l_str_Key];
|
||||
} else {
|
||||
$p_arr_Options[$l_str_Key] = "";
|
||||
}
|
||||
}
|
||||
|
||||
// check if each key from the default values exist in return array
|
||||
foreach($p_arr_Default as $l_str_Key => $l_str_Value) {
|
||||
// if key not exists, add it with its default value
|
||||
if (!array_key_exists($l_str_Key, $p_arr_Options)) {
|
||||
$p_arr_Options[$l_str_Key] = $l_str_Value;
|
||||
}
|
||||
}
|
||||
// returns the filtered array
|
||||
return $p_arr_Options;
|
||||
}
|
|
@ -1,413 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by Stefan Herndler.
|
||||
* User: Stefan
|
||||
* Date: 15.05.14
|
||||
* Time: 16:21
|
||||
* Version: 1.1.1
|
||||
* Since: 1.0
|
||||
*/
|
||||
|
||||
/*
|
||||
* collection of all footnotes found on the current page
|
||||
* @since 1.0
|
||||
*/
|
||||
$g_arr_Footnotes = array();
|
||||
|
||||
/*
|
||||
* collection of all footnotes settings
|
||||
* @since 1.0-beta
|
||||
*/
|
||||
$g_arr_FootnotesSettings = array();
|
||||
|
||||
/*
|
||||
* flag to know íf the user wants to have NO 'love me' slug on the current page
|
||||
* @since 1.1.1
|
||||
*/
|
||||
$g_bool_NoLoveMeSlugOnCurrentPage = false;
|
||||
|
||||
/**
|
||||
* register all functions needed for the replacement in the wordpress core
|
||||
* @since 1.0-gamma
|
||||
*/
|
||||
function footnotes_RegisterReplacementFunctions()
|
||||
{
|
||||
/* 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, false);
|
||||
|
||||
/* stops listening to the output and replaces the footnotes */
|
||||
add_action('get_footer', 'footnotes_StopReplacing');
|
||||
|
||||
/* moves these contents through the replacement function */
|
||||
add_filter('the_content', 'footnotes_Replacer_Content');
|
||||
add_filter('the_excerpt', 'footnotes_Replacer_Excerpt');
|
||||
add_filter('widget_title', 'footnotes_Replacer_WidgetTitle');
|
||||
add_filter('widget_text', 'footnotes_Replacer_WidgetText');
|
||||
|
||||
/* adds the love and share me slug to the footer */
|
||||
add_action('wp_footer', 'footnotes_LoveAndShareMe');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* replacement action for the_excerpt
|
||||
* @param string $p_str_Content
|
||||
* @return string
|
||||
* @since 1.0.7
|
||||
*/
|
||||
function footnotes_Replacer_Content($p_str_Content)
|
||||
{
|
||||
/* access to the global settings collection */
|
||||
global $g_arr_FootnotesSettings;
|
||||
/* get setting for 'display reference container position' */
|
||||
$l_str_ReferenceContainerPosition = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_REFERENCE_CONTAINER_PLACE];
|
||||
/* returns content */
|
||||
return footnotes_replaceFootnotes($p_str_Content, $l_str_ReferenceContainerPosition == "post_end" ? true : false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* replacement action for the_excerpt
|
||||
* @param string $p_str_Content
|
||||
* @return string
|
||||
* @since 1.0.7
|
||||
*/
|
||||
function footnotes_Replacer_Excerpt($p_str_Content)
|
||||
{
|
||||
/* access to the global settings collection */
|
||||
global $g_arr_FootnotesSettings;
|
||||
/* get setting for accepting footnotes in the excerpt and convert it to boolean */
|
||||
$l_bool_SearchExcerpt = footnotes_ConvertToBool($g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_SEARCH_IN_EXCERPT]);
|
||||
/* search in the excerpt only if activated */
|
||||
if ($l_bool_SearchExcerpt) {
|
||||
return footnotes_replaceFootnotes($p_str_Content, false, false);
|
||||
}
|
||||
/* returns content */
|
||||
return $p_str_Content;
|
||||
}
|
||||
|
||||
/**
|
||||
* replacement action for widget_title
|
||||
* @param string $p_str_Content
|
||||
* @return string
|
||||
* @since 1.0.7
|
||||
*/
|
||||
function footnotes_Replacer_WidgetTitle($p_str_Content)
|
||||
{
|
||||
/* returns content */
|
||||
return $p_str_Content;
|
||||
}
|
||||
|
||||
/**
|
||||
* replacement action for widget_text
|
||||
* @param string $p_str_Content
|
||||
* @return string
|
||||
* @since 1.0.7
|
||||
*/
|
||||
function footnotes_Replacer_WidgetText($p_str_Content)
|
||||
{
|
||||
/* access to the global settings collection */
|
||||
global $g_arr_FootnotesSettings;
|
||||
/* get setting for 'display reference container position' */
|
||||
$l_str_ReferenceContainerPosition = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_REFERENCE_CONTAINER_PLACE];
|
||||
/* returns content */
|
||||
return footnotes_replaceFootnotes($p_str_Content, $l_str_ReferenceContainerPosition == "post_end" ? true : false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* stops buffering the output, automatically calls the ob_start() defined callback function
|
||||
* replaces all footnotes in the whole buffer and outputs it
|
||||
* @since 1.0
|
||||
* cleared the flag in version 1.0.7
|
||||
*/
|
||||
function footnotes_StopReplacing()
|
||||
{
|
||||
/* access to the global settings collection */
|
||||
global $g_arr_FootnotesSettings;
|
||||
/* get setting for 'display reference container position' */
|
||||
$l_str_ReferenceContainerPosition = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_REFERENCE_CONTAINER_PLACE];
|
||||
|
||||
if ($l_str_ReferenceContainerPosition == "footer") {
|
||||
echo footnotes_OutputReferenceContainer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* outputs a link to love and share this awesome plugin
|
||||
* @since 1.0-gamma
|
||||
*/
|
||||
function footnotes_LoveAndShareMe()
|
||||
{
|
||||
/* access to the global settings collection */
|
||||
global $g_arr_FootnotesSettings;
|
||||
global $g_bool_NoLoveMeSlugOnCurrentPage;
|
||||
/*
|
||||
* updated url to wordpress.org plugin page instead of the github page
|
||||
* also updated the font-style and translation the string "footnotes"
|
||||
* in version 1.0.6
|
||||
*/
|
||||
/*
|
||||
* changed replacement of public plugin name to use global styling setting
|
||||
* @since 1.0.7
|
||||
*/
|
||||
/* get setting for love and share this plugin and convert it to boolean */
|
||||
$l_str_LoveMeText = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_LOVE];
|
||||
/* check if the admin allows to add a link to the footer */
|
||||
if (!empty($l_str_LoveMeText) && strtolower($l_str_LoveMeText) != "no" && !$g_bool_NoLoveMeSlugOnCurrentPage) {
|
||||
if (strtolower($l_str_LoveMeText) == "random") {
|
||||
$l_str_LoveMeText = "text-" . rand(1,3);
|
||||
}
|
||||
|
||||
switch ($l_str_LoveMeText) {
|
||||
case "text-1":
|
||||
$l_str_LoveMeText = sprintf(__('I %s %s', FOOTNOTES_PLUGIN_NAME), FOOTNOTES_LOVE_SYMBOL, FOOTNOTES_PLUGIN_PUBLIC_NAME_LINKED);
|
||||
break;
|
||||
case "text-2":
|
||||
$l_str_LoveMeText = sprintf(__('this site uses the awesome %s Plugin', FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME_LINKED);
|
||||
break;
|
||||
case "text-3":
|
||||
default:
|
||||
$l_str_LoveMeText = sprintf(__('extra smooth %s', FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME_LINKED);
|
||||
break;
|
||||
}
|
||||
echo '<div style="text-align:center; color:#acacac;">' . $l_str_LoveMeText . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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]
|
||||
* @return string
|
||||
*/
|
||||
function footnotes_replaceFootnotes($p_str_Content, $p_bool_OutputReferences = true, $p_bool_ReplaceHtmlCharsSettings = 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, true);
|
||||
$p_str_Content = footnotes_getFromString($p_str_Content, false);
|
||||
|
||||
/* 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 = ' [ <a id="footnote_reference_container_collapse_button" style="cursor:pointer;" onclick="footnote_expand_collapse_reference_container();">+</a> ]';
|
||||
}
|
||||
|
||||
/* 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><span>' .$l_str_CollapseButtons . '</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");
|
||||
|
||||
/* loop through all footnotes found in the page */
|
||||
for ($l_str_Index = 0; $l_str_Index < count($g_arr_Footnotes); $l_str_Index++) {
|
||||
/* get footnote text */
|
||||
$l_str_FootnoteText = $g_arr_Footnotes[$l_str_Index];
|
||||
/* if fottnote is empty, get to the next one */
|
||||
if (empty($l_str_FootnoteText)) {
|
||||
continue;
|
||||
}
|
||||
/* get footnote index */
|
||||
$l_str_FirstFootnoteIndex = ($l_str_Index + 1);
|
||||
$l_str_FootnoteIndex = footnote_convert_index(($l_str_Index + 1), $l_str_CounterStyle);
|
||||
|
||||
/* check if it isn't the last footnote in the array */
|
||||
if ($l_str_FirstFootnoteIndex < count($g_arr_Footnotes) && $l_bool_CombineIdentical) {
|
||||
/* get all footnotes that I haven't passed yet */
|
||||
for ($l_str_CheckIndex = $l_str_FirstFootnoteIndex; $l_str_CheckIndex < count($g_arr_Footnotes); $l_str_CheckIndex++) {
|
||||
/* check if a further footnote is the same as the actual one */
|
||||
if ($l_str_FootnoteText == $g_arr_Footnotes[$l_str_CheckIndex] && !empty($g_arr_Footnotes[$l_str_CheckIndex])) {
|
||||
/* set the further footnote as empty so it won't be displayed later */
|
||||
$g_arr_Footnotes[$l_str_CheckIndex] = "";
|
||||
/* add the footnote index to the actual index */
|
||||
$l_str_FootnoteIndex .= ", " . footnote_convert_index(($l_str_CheckIndex + 1), $l_str_CounterStyle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* add the footnote to the output box */
|
||||
/*
|
||||
* added function to convert the counter style in the reference container (bugfix for the link to the footnote) in version 1.0.6
|
||||
*/
|
||||
$l_str_ReplaceText = str_replace("[[FOOTNOTE INDEX SHORT]]", footnote_convert_index($l_str_FirstFootnoteIndex, $l_str_CounterStyle), $l_str_FootnoteTemplate);
|
||||
$l_str_ReplaceText = str_replace("[[FOOTNOTE INDEX]]", $l_str_FootnoteIndex, $l_str_ReplaceText);
|
||||
$l_str_ReplaceText = str_replace("[[FOOTNOTE TEXT]]", $l_str_FootnoteText, $l_str_ReplaceText);
|
||||
$l_str_ReplaceText = preg_replace('@[\s]{2,}@',' ',$l_str_ReplaceText);
|
||||
/* 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(p_str_ID) {
|
||||
jQuery("#' . FOOTNOTE_REFERENCES_CONTAINER_ID . '").show();
|
||||
if (p_str_ID.length > 0) {
|
||||
jQuery(p_str_ID).focus();
|
||||
}
|
||||
}
|
||||
function footnote_expand_collapse_reference_container() {
|
||||
var l_obj_ReferenceContainer = jQuery("#' . FOOTNOTE_REFERENCES_CONTAINER_ID . '");
|
||||
if (l_obj_ReferenceContainer.is(":hidden")) {
|
||||
l_obj_ReferenceContainer.show();
|
||||
jQuery("#footnote_reference_container_collapse_button").text("-");
|
||||
} else {
|
||||
l_obj_ReferenceContainer.hide();
|
||||
jQuery("#footnote_reference_container_collapse_button").text("+");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
';
|
||||
|
||||
/* free all found footnotes if reference container will be displayed */
|
||||
$g_arr_Footnotes = array();
|
||||
|
||||
/* return the output string */
|
||||
return $l_str_Output;
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by Stefan Herndler.
|
||||
* User: Stefan
|
||||
* Date: 15.05.14
|
||||
* Time: 16:21
|
||||
* Version: 1.0
|
||||
* Since: 1.0
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* register and add the public stylesheet
|
||||
* @since 1.0
|
||||
*/
|
||||
function footnotes_add_public_stylesheet()
|
||||
{
|
||||
/* register public stylesheet */
|
||||
wp_register_style('footnotes_public_style', plugins_url('../css/footnote.css', __FILE__));
|
||||
/* add public stylesheet */
|
||||
wp_enqueue_style('footnotes_public_style');
|
||||
/* add the jQuery plugin (already registered by WP) */
|
||||
wp_enqueue_script('jquery');
|
||||
/* add jquery tools to public page */
|
||||
wp_enqueue_script('footnotes_public_script', plugins_url('../js/jquery.tools.min.js', __FILE__), array());
|
||||
}
|
||||
|
||||
/**
|
||||
* register and add the settings stylesheet
|
||||
* @since 1.0
|
||||
*/
|
||||
function footnotes_add_settings_stylesheet()
|
||||
{
|
||||
/* register settings stylesheet */
|
||||
wp_register_style('footnotes_settings_style', plugins_url('../css/settings.css', __FILE__));
|
||||
/* add settings stylesheet */
|
||||
wp_enqueue_style('footnotes_settings_style');
|
||||
}
|
|
@ -8,13 +8,24 @@
|
|||
* Since: 1.2.0
|
||||
*/
|
||||
|
||||
// add new button to the WYSIWYG - editor
|
||||
add_filter("mce_buttons", "MCI_Footnotes_wysiwyg_editor_functions");
|
||||
add_filter("mce_external_plugins", "MCI_Footnotes_wysiwyg_editor_buttons");
|
||||
// add new button to the plain text editor
|
||||
add_action("admin_print_footer_scripts", "MCI_Footnotes_text_editor_buttons");
|
||||
|
||||
// defines the callback function for the editor buttons
|
||||
add_action("wp_ajax_nopriv_footnotes_getTags", "MCI_Footnotes_wysiwyg_ajax_callback");
|
||||
add_action("wp_ajax_footnotes_getTags", "MCI_Footnotes_wysiwyg_ajax_callback");
|
||||
|
||||
|
||||
/**
|
||||
* adds a new button to the WYSIWYG editor for pages and posts
|
||||
* @param array $buttons
|
||||
* @return array
|
||||
* @since 1.2.0
|
||||
*/
|
||||
function footnotes_wysiwyg_editor_functions($buttons) {
|
||||
function MCI_Footnotes_wysiwyg_editor_functions($buttons) {
|
||||
array_push($buttons, FOOTNOTES_PLUGIN_NAME);
|
||||
return $buttons;
|
||||
}
|
||||
|
@ -25,7 +36,7 @@ function footnotes_wysiwyg_editor_functions($buttons) {
|
|||
* @return array
|
||||
* @since 1.2.0
|
||||
*/
|
||||
function footnotes_wysiwyg_editor_buttons($plugin_array) {
|
||||
function MCI_Footnotes_wysiwyg_editor_buttons($plugin_array) {
|
||||
$plugin_array[FOOTNOTES_PLUGIN_NAME] = plugins_url('/../js/wysiwyg-editor.js', __FILE__);
|
||||
return $plugin_array;
|
||||
}
|
||||
|
@ -34,16 +45,16 @@ function footnotes_wysiwyg_editor_buttons($plugin_array) {
|
|||
* adds a new button to the plain text editor for pages and posts
|
||||
* @since 1.2.0
|
||||
*/
|
||||
function footnotes_text_editor_buttons() {
|
||||
function MCI_Footnotes_text_editor_buttons() {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
/**
|
||||
* adds a tag in at the beginning and at the end of a selected text in the specific textarea
|
||||
* adds a tag in at the beginning and at the end of a selected text in the specific text area
|
||||
* @param string elementID
|
||||
* @param string openTag
|
||||
* @param string closeTag
|
||||
*/
|
||||
function footnotes_wrapText(elementID, openTag, closeTag) {
|
||||
function MCI_Footnotes_wrapText(elementID, openTag, closeTag) {
|
||||
var textArea = jQuery('#' + elementID);
|
||||
var len = textArea.val().length;
|
||||
var start = textArea[0].selectionStart;
|
||||
|
@ -55,13 +66,13 @@ function footnotes_text_editor_buttons() {
|
|||
/**
|
||||
* adds a new button to the plain text editor
|
||||
*/
|
||||
QTags.addButton( 'footnotes_quicktag_button', 'footnotes', footnotes_text_editor_callback );
|
||||
QTags.addButton( 'MCI_Footnotes_QuickTag_button', 'footnotes', MCI_Footnotes_text_editor_callback );
|
||||
/**
|
||||
* callback function when the button is clicked
|
||||
* executes a ajax call to get the start and end tag for the footnotes and
|
||||
* adds them in before and after the selected text
|
||||
*/
|
||||
function footnotes_text_editor_callback() {
|
||||
function MCI_Footnotes_text_editor_callback() {
|
||||
jQuery.ajax({
|
||||
type: 'POST',
|
||||
url: '/wp-admin/admin-ajax.php',
|
||||
|
@ -71,7 +82,7 @@ function footnotes_text_editor_buttons() {
|
|||
},
|
||||
success: function(data, textStatus, XMLHttpRequest){
|
||||
var l_arr_Tags = JSON.parse(data);
|
||||
footnotes_wrapText("content", l_arr_Tags['start'], l_arr_Tags['end']);
|
||||
MCI_Footnotes_wrapText("content", l_arr_Tags['start'], l_arr_Tags['end']);
|
||||
},
|
||||
error: function(MLHttpRequest, textStatus, errorThrown){
|
||||
}
|
||||
|
@ -86,23 +97,24 @@ function footnotes_text_editor_buttons() {
|
|||
* to get the start and end tag for the footnotes
|
||||
* echos the tags as json-string ("start" | "end")
|
||||
*/
|
||||
function footnotes_wysiwyg_ajax_callback() {
|
||||
require_once(dirname(__FILE__) . '/../includes/defines.php');
|
||||
require_once(dirname(__FILE__) . '/../includes/plugin-settings.php');
|
||||
function MCI_Footnotes_wysiwyg_ajax_callback() {
|
||||
require_once(dirname(__FILE__) . "/defines.php");
|
||||
require_once(dirname(__FILE__) . '/plugin-settings.php');
|
||||
require_once(dirname(__FILE__) . '/../classes/admin.php');
|
||||
|
||||
/* load footnote settings */
|
||||
$g_arr_FootnotesSettings = footnotes_filter_options(FOOTNOTE_SETTINGS_CONTAINER, Class_FootnotesSettings::$a_arr_Default_Settings, true);
|
||||
$g_arr_FootnotesSettings = MCI_Footnotes_getOptions(true);
|
||||
|
||||
/* get footnote starting tag */
|
||||
$l_str_StartingTag = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_PLACEHOLDER_START];
|
||||
$l_str_StartingTag = $g_arr_FootnotesSettings[FOOTNOTES_INPUT_PLACEHOLDER_START];
|
||||
/*get footnote ending tag */
|
||||
$l_str_EndingTag = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_PLACEHOLDER_END];
|
||||
$l_str_EndingTag = $g_arr_FootnotesSettings[FOOTNOTES_INPUT_PLACEHOLDER_END];
|
||||
|
||||
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];
|
||||
$l_str_StartingTag = $g_arr_FootnotesSettings[FOOTNOTES_INPUT_PLACEHOLDER_START_USERDEFINED];
|
||||
/*get user defined footnote ending tag */
|
||||
$l_str_EndingTag = $g_arr_FootnotesSettings[FOOTNOTE_INPUTFIELD_PLACEHOLDER_END_USERDEFINED];
|
||||
$l_str_EndingTag = $g_arr_FootnotesSettings[FOOTNOTES_INPUT_PLACEHOLDER_END_USERDEFINED];
|
||||
}
|
||||
|
||||
echo json_encode(array("start" => $l_str_StartingTag, "end" => $l_str_EndingTag));
|
||||
|
|
Reference in a new issue