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:
Aricura 2014-07-31 10:17:38 +00:00
parent 0f3996338b
commit 3802249ec4
26 changed files with 2137 additions and 1651 deletions

396
classes/admin.php Normal file
View file

@ -0,0 +1,396 @@
<?php
/**
* Created by Stefan Herndler.
* User: Stefan
* Date: 15.05.14
* Time: 16:21
* Version: 1.0.7
* Since: 1.0
*/
// define class only once
if (!class_exists("MCI_Footnotes_Admin")) :
/**
* Class MCI_Footnotes_Admin
* @since 1.0
*/
class MCI_Footnotes_Admin {
// page hook for adding a new sub menu page to the settings
// @since 1.0
private $a_str_Pagehook = null;
// collection of settings values for this plugin
// @since 1.0
private $a_arr_Options = array();
// collection of tabs for the settings page of this plugin
// @since 1.0
private $a_arr_SettingsTabs = array();
// current active tab
public static $a_str_ActiveTab = null;
/**
* @constructor
* @since 1.0
*/
public function __construct() {
// include script and stylesheet functions
require_once(dirname(__FILE__) . "/../includes/wysiwyg-editor.php");
// load setting tabs
add_action('admin_init', array($this, 'Register'));
// register plugin in settings menu
add_action('admin_menu', array($this, 'RegisterMenu'));
}
/**
* register the settings field in the database for the "save" function
* called in class constructor @ admin_init
* @since 1.0
*/
public function Register() {
// register settings
register_setting(FOOTNOTES_SETTINGS_TAB_GENERAL, FOOTNOTES_SETTINGS_CONTAINER);
register_setting(FOOTNOTES_SETTINGS_TAB_CUSTOM, FOOTNOTES_SETTINGS_CONTAINER_CUSTOM);
// load tab 'general'
require_once(dirname( __FILE__ ) . "/tab_general.php");
new MCI_Footnotes_Tab_General($this->a_arr_SettingsTabs);
// load tab 'custom'
require_once(dirname( __FILE__ ) . "/tab_custom.php");
new MCI_Footnotes_Tab_Custom($this->a_arr_SettingsTabs);
// load tab 'how to'
require_once(dirname( __FILE__ ) . "/tab_howto.php");
new MCI_Footnotes_Tab_HowTo($this->a_arr_SettingsTabs);
}
/**
* sets the plugin's title for the admins settings menu
* called in class constructor @ admin_menu
* @since 1.0
*/
public function RegisterMenu() {
// current user needs the permission to update plugins for further access
if (!current_user_can('update_plugins')) {
return;
}
// Add a new sub menu to the standard Settings panel
$this->a_str_Pagehook = add_options_page(
FOOTNOTES_PLUGIN_PUBLIC_NAME,
FOOTNOTES_PLUGIN_PUBLIC_NAME,
'administrator',
FOOTNOTES_SETTINGS_PAGE_ID,
array($this, 'DisplaySettings')
);
}
/**
* Plugin Options page rendering goes here, checks
* for active tab and replaces key with the related
* settings key. Uses the plugin_options_tabs method
* to render the tabs.
* @since 1.0
*/
public function DisplaySettings() {
// load stylesheets and scripts
$this->LoadScriptsAndStylesheets();
// gets active tab, or if nothing set the "general" tab will be set to active
self::$a_str_ActiveTab = isset($_GET['tab']) ? $_GET['tab'] : FOOTNOTES_SETTINGS_TAB_GENERAL;
// outputs all tabs
echo '<div class="wrap">';
echo '<h2 class="nav-tab-wrapper">';
// iterate through all register tabs
foreach ($this->a_arr_SettingsTabs as $l_str_TabKey => $l_str_TabCaption) {
$l_str_Active = self::$a_str_ActiveTab == $l_str_TabKey ? 'nav-tab-active' : '';
echo '<a class="nav-tab ' . $l_str_Active . '" href="?page=' . FOOTNOTES_SETTINGS_PAGE_ID . '&tab=' . $l_str_TabKey . '">' . $l_str_TabCaption . '</a>';
}
echo '</h2>';
// outputs a form with the content of the current active tab
echo '<form method="post" action="options.php">';
wp_nonce_field('update-options');
settings_fields(self::$a_str_ActiveTab);
// outputs the settings field of the current active tab
do_settings_sections(self::$a_str_ActiveTab);
do_meta_boxes(self::$a_str_ActiveTab, 'main', NULL);
// adds a submit button to the current page
if (self::$a_str_ActiveTab != FOOTNOTES_SETTINGS_TAB_HOWTO) {
submit_button();
}
echo '</form>';
echo '</div>';
// output settings page specific javascript code
$this->OutputJavascript();
}
/**
* register and loads css and javascript files for settings
* @since 1.3
*/
private function LoadScriptsAndStylesheets() {
// register settings stylesheet
wp_register_style('footnote_settings_style', plugins_url('../css/settings.css', __FILE__));
// add settings stylesheet
wp_enqueue_style('footnote_settings_style');
// Needed to allow meta box layout and close functionality
wp_enqueue_script('postbox');
}
/**
* outputs page specific javascript code
* @since 1.0.7
*/
private function OutputJavascript() {
?>
<!-- Needed to allow meta box layout and close functionality. -->
<script type="text/javascript">
jQuery(document).ready(function ($) {
// close postboxes that should be closed
$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
// postboxes setup
postboxes.add_postbox_toggles('<?php echo $this->a_str_Pagehook; ?>');
jQuery('#<?php echo $this->getFieldID(FOOTNOTES_INPUT_PLACEHOLDER_START); ?>').on('change', function() {
var l_int_SelectedIndex = jQuery(this).prop("selectedIndex");
jQuery('#<?php echo $this->getFieldID(FOOTNOTES_INPUT_PLACEHOLDER_END); ?> option:eq(' + l_int_SelectedIndex + ')').prop('selected', true);
footnotes_Display_UserDefined_Placeholders();
});
jQuery('#<?php echo $this->getFieldID(FOOTNOTES_INPUT_PLACEHOLDER_END); ?>').on('change', function() {
var l_int_SelectedIndex = jQuery(this).prop("selectedIndex");
jQuery('#<?php echo $this->getFieldID(FOOTNOTES_INPUT_PLACEHOLDER_START); ?> option:eq(' + l_int_SelectedIndex + ')').prop('selected', true);
footnotes_Display_UserDefined_Placeholders();
});
footnotes_Display_UserDefined_Placeholders();
});
function footnotes_Display_UserDefined_Placeholders() {
if (jQuery('#<?php echo $this->getFieldID(FOOTNOTES_INPUT_PLACEHOLDER_START); ?>').val() == "userdefined") {
jQuery('#<?php echo $this->getFieldID(FOOTNOTES_INPUT_PLACEHOLDER_START_USERDEFINED); ?>').show();
jQuery('#<?php echo $this->getFieldID(FOOTNOTES_INPUT_PLACEHOLDER_END_USERDEFINED); ?>').show();
} else {
jQuery('#<?php echo $this->getFieldID(FOOTNOTES_INPUT_PLACEHOLDER_START_USERDEFINED); ?>').hide();
jQuery('#<?php echo $this->getFieldID(FOOTNOTES_INPUT_PLACEHOLDER_END_USERDEFINED); ?>').hide();
}
}
</script>
<?php
}
/**
* loads specific setting and returns an array with the keys [id, name, value]
* @since 1.0
* @param $p_str_FieldID
* @return array
*/
protected function LoadSetting($p_str_FieldID) {
// loads and filters the settings for this plugin
if (empty($this->a_arr_Options)) {
$this->a_arr_Options = MCI_Footnotes_getOptions(true);
}
$p_arr_Return = array();
$p_arr_Return["id"] = $this->getFieldID($p_str_FieldID);
$p_arr_Return["name"] = $this->getFieldName($p_str_FieldID);
$p_arr_Return["value"] = esc_attr($this->getFieldValue($p_str_FieldID));
return $p_arr_Return;
}
/**
* access settings field by name
* @since 1.0
* @param string $p_str_FieldName
* @return string
*/
protected function getFieldName($p_str_FieldName) {
// general setting
if (MCI_Footnotes_Admin::$a_str_ActiveTab == FOOTNOTES_SETTINGS_TAB_GENERAL) {
return sprintf('%s[%s]', FOOTNOTES_SETTINGS_CONTAINER, $p_str_FieldName);
// custom setting
} else if (MCI_Footnotes_Admin::$a_str_ActiveTab == FOOTNOTES_SETTINGS_TAB_CUSTOM) {
return sprintf('%s[%s]', FOOTNOTES_SETTINGS_CONTAINER_CUSTOM, $p_str_FieldName);
}
// undefined
return sprintf('%s[%s]', FOOTNOTES_SETTINGS_CONTAINER, $p_str_FieldName);
}
/**
* access settings field by id
* @since 1.0
* @param string $p_str_FieldID
* @return string
*/
protected function getFieldID($p_str_FieldID) {
return sprintf( '%s', $p_str_FieldID );
}
/**
* get settings field value
* @since 1.0
* @param string $p_str_Key
* @return string
*/
protected function getFieldValue($p_str_Key) {
return $this->a_arr_Options[$p_str_Key];
}
/**
* outputs a break to have a new line
* @since 1.0.7
*/
public function AddNewline() {
echo '<br/><br/>';
}
/**
* outputs a simple text
* @param string $p_str_Text
* @since 1.1.1
*/
public function AddText($p_str_Text) {
echo '<span>' . $p_str_Text . '</span>';
}
/**
* outputs a simple text with some highlight
* @param string $p_str_Text+
* @return string
* @since 1.1.1
*/
public function Highlight($p_str_Text) {
return '<b>' . $p_str_Text . '</b>';
}
/**
* outputs a label for a specific input/select box
* @param string $p_str_SettingsID
* @param string $p_str_Caption
* @param string $p_str_Styling
* @since 1.0.7
*/
public function AddLabel($p_str_SettingsID, $p_str_Caption, $p_str_Styling = "") {
// add styling tag if styling is set
if (!empty($p_str_Styling)) {
$p_str_Styling = ' style="' . $p_str_Styling . '"';
}
echo '<label for="' . $p_str_SettingsID . '"' . $p_str_Styling . '>' . $p_str_Caption . '</label>';
}
/**
* 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 bool $p_bool_Readonly [input is readonly] in version 1.1.1
* @param bool $p_bool_Hidden [input is hidden by default] in version 1.1.2
* @since 1.0-beta
* removed optional parameter for a label in version 1.0.7
*/
public function AddTextbox($p_str_SettingsID, $p_str_ClassName = "", $p_str_MaxLength = 0, $p_bool_Readonly = false, $p_bool_Hidden = false) {
// collect data for given settings field
$l_arr_Data = $this->LoadSetting($p_str_SettingsID);
// if input shall have a css class, add the style tag for it
if (!empty($p_str_ClassName)) {
$p_str_ClassName = 'class="' . $p_str_ClassName . '"';
}
// optional add a max length to the input field
if (!empty($p_str_MaxLength)) {
$p_str_MaxLength = ' maxlength="' . $p_str_MaxLength . '"';
}
if ($p_bool_Readonly) {
$p_bool_Readonly = ' readonly="readonly"';
}
if ($p_bool_Hidden) {
$p_bool_Hidden = ' style="display:none;"';
}
// outputs an input field type TEXT
echo '<input type="text" ' . $p_str_ClassName . $p_str_MaxLength . $p_bool_Readonly . $p_bool_Hidden . ' name="' . $l_arr_Data["name"] . '" id="' . $l_arr_Data["id"] . '" value="' . $l_arr_Data["value"] . '"/>';
}
/**
* outputs a input type=checkbox
* @param string $p_str_SettingsID [id of the settings field]
* @param string $p_str_ClassName [optional css class name]
* @since 1.0-beta
*/
public function AddCheckbox($p_str_SettingsID, $p_str_ClassName = "") {
require_once(dirname(__FILE__) . "/convert.php");
// collect data for given settings field
$l_arr_Data = $this->LoadSetting($p_str_SettingsID);
// if input shall have a css class, add the style tag for it
if (!empty($p_str_ClassName)) {
$p_str_ClassName = 'class="' . $p_str_ClassName . '"';
}
// lookup if the checkbox shall be pre-checked
$l_str_Checked = "";
if (MCI_Footnotes_Convert::toBool($l_arr_Data["value"])) {
$l_str_Checked = 'checked="checked"';
}
// outputs an input field type CHECKBOX
echo sprintf('<input type="checkbox" ' . $p_str_ClassName . ' name="' . $l_arr_Data["name"] . '" id="' . $l_arr_Data["id"] . '" %s/>', $l_str_Checked);
}
/**
* outputs a select box
* @param string $p_str_SettingsID [id of the settings field]
* @param array $p_arr_Options [array with options]
* @param string $p_str_ClassName [optional css class name]
* @since 1.0-beta
*/
public function AddSelect($p_str_SettingsID, $p_arr_Options, $p_str_ClassName = "") {
// collect data for given settings field
$l_arr_Data = $this->LoadSetting($p_str_SettingsID);
// if input shall have a css class, add the style tag for it
if (!empty($p_str_ClassName)) {
$p_str_ClassName = 'class="' . $p_str_ClassName . '"';
}
// select starting tag
$l_str_Output = '<select ' . $p_str_ClassName . ' name="' . $l_arr_Data["name"] . '" id="' . $l_arr_Data["id"] . '">';
// loop through all array keys
foreach ($p_arr_Options as $l_str_Value => $l_str_Caption) {
// add key as option value
$l_str_Output .= '<option value="' . $l_str_Value . '"';
// check if option value is set and has to be pre-selected
if ($l_arr_Data["value"] == $l_str_Value) {
$l_str_Output .= ' selected';
}
// write option caption and close option tag
$l_str_Output .= '>' . $l_str_Caption . '</option>';
}
// close select
$l_str_Output .= '</select>';
// outputs the SELECT field
echo $l_str_Output;
}
/**
* outputs a textarea
* @param string $p_str_SettingsID [id of the settings field]
* @param int $p_int_Rows [amount of rows]
* @param string $p_str_ClassName [css class name]
* @since 1.3
*/
public function AddTextarea($p_str_SettingsID, $p_int_Rows, $p_str_ClassName = "") {
// collect data for given settings field
$l_arr_Data = $this->LoadSetting($p_str_SettingsID);
// if input shall have a css class, add the style tag for it
if (!empty($p_str_ClassName)) {
$p_str_ClassName = 'class="' . $p_str_ClassName . '"';
}
// outputs an input field type TEXT
echo '<textarea ' . $p_str_ClassName . ' name="' . $l_arr_Data["name"] . '" id="' . $l_arr_Data["id"] . '" rows="'.$p_int_Rows.'">' . $l_arr_Data["value"] . '</textarea>';
}
}// class MCI_Footnotes_Admin
endif;

152
classes/convert.php Normal file
View file

@ -0,0 +1,152 @@
<?php
/**
* Created by Stefan Herndler.
* User: Stefan
* Date: 30.07.14 11:45
* Version: 1.0
* Since: 1.3
*/
// define class only once
if (!class_exists("MCI_Footnotes_Convert")) :
/**
* Class MCI_Footnotes_Convert
* @since 1.3
*/
class MCI_Footnotes_Convert {
/**
* 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
*/
public static function Index($p_int_Index, $p_str_ConvertStyle = "arabic_plain") {
switch ($p_str_ConvertStyle) {
case "romanic":
return self::toRomanic($p_int_Index);
case "latin_high":
return self::toLatin($p_int_Index, true);
case "latin_low":
return self::toLatin($p_int_Index, false);
case "arabic_leading":
return self::toArabicLeading($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
*/
private static function toLatin($p_int_Value, $p_bool_UpperCase) {
// decimal value of the starting ascii character
$l_int_StartingASCII = 65 - 1; // = A
// if lower-case, change decimal to lower-case "a"
if (!$p_bool_UpperCase) {
$l_int_StartingASCII = 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 front
if ($l_int_Offset > 0) {
$l_str_Return = chr($l_int_Offset + $l_int_StartingASCII);
}
// add the origin letter
$l_str_Return .= chr($p_int_Value + $l_int_StartingASCII);
// 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
*/
private static function toArabicLeading($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
*/
private static function toRomanic($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 = '';
// iterate 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;
}
/**
* converts a string depending on its value to a boolean
* @since 1.0-beta
* @param string $p_str_Value
* @return bool
*/
public static function toBool($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;
}
} // class MCI_Footnotes_Convert
endif;

View file

@ -8,52 +8,64 @@
* Since: 1.0
*/
// define class only once
if (!class_exists( "MCI_Footnotes" )) :
/**
* Class Class_Footnotes
* Class MCI_Footnotes
* @since 1.0
*/
class Class_Footnotes
{
/*
* object to the plugin's settings
* @since 1.0
*/
var $a_obj_Settings;
class MCI_Footnotes {
// object to the plugin settings
// @since 1.0
// @var MCI_Footnotes_Admin $a_obj_Settings
private $a_obj_Admin;
// replace task object
/** @var \MCI_Footnotes_Task $a_obj_Task */
public $a_obj_Task;
/**
* @constructor
* @since 1.0
*/
function __construct()
{
/* load settings only if current wordpress user is admin */
public function __construct() {
// load settings only if current WordPress user is admin
if (is_admin()) {
/* create a new instance of the class settings */
$this->a_obj_Settings = new Class_FootnotesSettings();
// load plugin settings
require_once(dirname( __FILE__ ) . "/admin.php");
$this->a_obj_Admin = new MCI_Footnotes_Admin();
}
// load plugin widget
require_once(dirname( __FILE__ ) . "/widget.php");
// register footnotes widget
add_action('widgets_init', create_function('', 'return register_widget("MCI_Footnotes_Widget");'));
// load public css and javascript files
add_action('init', array($this, 'LoadScriptsAndStylesheets'));
// adds javascript and stylesheets to the public page
add_action('wp_enqueue_scripts', array($this, 'LoadScriptsAndStylesheets'));
/* execute class function: init, admin_init and admin_menu */
add_action('init', array($this, 'init'));
add_action('admin_init', array($this, 'admin_init'));
add_action('admin_menu', array($this, 'admin_menu'));
// load plugin widget
require_once(dirname( __FILE__ ) . "/task.php");
$this->a_obj_Task = new MCI_Footnotes_Task();
$this->a_obj_Task->Register();
}
/**
* activates the plugin
* @since 1.0
*/
static function activate()
{
// unused
public static function activate() {
// unused
}
/**
* deactivates the plugin
* @since 1.0
*/
static function deactivate()
{
// unused
public static function deactivate() {
// unused
}
/**
@ -61,53 +73,44 @@ class Class_Footnotes
* updated file path in version 1.0.6
* @since 1.0
*/
static function uninstall()
{
/* uninstalling the plugin is only allowed for logged in users */
public static function uninstall() {
// uninstalling the plugin is only allowed for logged in users
if (!is_user_logged_in()) {
wp_die(__('You must be logged in to run this script.', FOOTNOTES_PLUGIN_NAME));
}
/* current user needs the permission to (un)install plugins */
// current user needs the permission to (un)install plugins
if (!current_user_can('install_plugins')) {
wp_die(__('You do not have permission to run this script.', FOOTNOTES_PLUGIN_NAME));
}
/*
* delete the settings container in the database
* @since 1.0.6
*/
delete_option(FOOTNOTE_SETTINGS_CONTAINER);
// delete the settings container in the database
// @since 1.0.6
delete_option(FOOTNOTES_SETTINGS_CONTAINER);
delete_option(FOOTNOTES_SETTINGS_CONTAINER_CUSTOM);
}
/**
* initialize function
* called in the class constructor
* @since 1.0
*/
function init()
{
// unused
}
/**
* load public styling and client function
* called in class constructor @ init
* @since 1.0
*/
public function LoadScriptsAndStylesheets() {
// register public stylesheets
wp_register_style('MCI_Footnotes_public_style_General', plugins_url('../css/footnotes.css', __FILE__));
wp_register_style('MCI_Footnotes_public_style_Tooltip', plugins_url('../css/tooltip.css', __FILE__));
wp_register_style('MCI_Footnotes_public_style_ReferenceContainer', plugins_url('../css/reference_container.css', __FILE__));
// add public stylesheets
wp_enqueue_style('MCI_Footnotes_public_style_General');
wp_enqueue_style('MCI_Footnotes_public_style_Tooltip');
wp_enqueue_style('MCI_Footnotes_public_style_ReferenceContainer');
/**
* do admin init stuff
* called in the class constructor
* @since 1.0
*/
function admin_init()
{
// unused
}
// 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());
}
/**
* do admin menu stuff
* called in the class constructor
* @since 1.0
*/
function admin_menu()
{
// unused
}
} // class MCI_Footnotes
} /* class Class_Footnotes */
endif;

View file

@ -1,626 +0,0 @@
<?php
/**
* Created by Stefan Herndler.
* User: Stefan
* Date: 15.05.14
* Time: 16:21
* Version: 1.0.7
* Since: 1.0
*/
/**
* Class Class_FootnotesSettings
* @since 1.0
*/
class Class_FootnotesSettings
{
/*
* attribute for default settings value
* updated default value for 'FOOTNOTE_INPUTFIELD_LOVE' to default: 'no' in version 1.0.6
* @since 1.0
*/
public static $a_arr_Default_Settings = array(
FOOTNOTE_INPUTFIELD_COMBINE_IDENTICAL => 'yes',
FOOTNOTE_INPUTFIELD_REFERENCES_LABEL => 'References',
FOOTNOTE_INPUTFIELD_COLLAPSE_REFERENCES => '',
FOOTNOTE_INPUTFIELD_PLACEHOLDER_START => '((',
FOOTNOTE_INPUTFIELD_PLACEHOLDER_END => '))',
FOOTNOTE_INPUTFIELD_SEARCH_IN_EXCERPT => 'yes',
FOOTNOTE_INPUTFIELD_LOVE => 'no',
FOOTNOTE_INPUTFIELD_COUNTER_STYLE => 'arabic_plain',
FOOTNOTE_INPUTFIELD_REFERENCE_CONTAINER_PLACE => 'post_end',
FOOTNOTE_INPUTFIELD_PLACEHOLDER_START_USERDEFINED => '',
FOOTNOTE_INPUTFIELD_PLACEHOLDER_END_USERDEFINED => ''
);
/*
* resulting pagehook for adding a new sub menu page to the settings
* @since 1.0
*/
var $a_str_Pagehook;
/*
* collection of settings values for this plugin
* @since 1.0
*/
var $a_arr_Options;
/*
* collection of tabs for the settings page of this plugin
* @since 1.0
*/
private $a_arr_SettingsTabs = array();
/**
* @constructor
* @since 1.0
*/
function __construct()
{
/* loads and filters the settings for this plugin */
$this->a_arr_Options = footnotes_filter_options(FOOTNOTE_SETTINGS_CONTAINER, self::$a_arr_Default_Settings, true);
/* execute class includes on action-even: init, admin_init and admin_menu */
add_action('init', array($this, 'LoadScriptsAndStylesheets'));
add_action('admin_init', array($this, 'RegisterSettings'));
add_action('admin_init', array($this, 'RegisterTab_General'));
add_action('admin_init', array($this, 'RegisterTab_HowTo'));
add_action('admin_menu', array($this, 'AddSettingsMenuPanel'));
}
/**
* initialize settings page, loads scripts and stylesheets needed for the layout
* called in class constructor @ init
* @since 1.0
*/
function LoadScriptsAndStylesheets()
{
/* register public stylesheet */
wp_register_style('footnote_public_style', plugins_url('../css/footnote.css', __FILE__));
/* add public stylesheet */
wp_enqueue_style('footnote_public_style');
}
/**
* register the settings field in the database for the "save" function
* called in class constructor @ admin_init
* @since 1.0
*/
function RegisterSettings()
{
register_setting(FOOTNOTE_SETTINGS_LABEL_GENERAL, FOOTNOTE_SETTINGS_CONTAINER);
}
/**
* sets the plugin's title for the admins settings menu
* called in class constructor @ admin_menu
* @since 1.0
*/
function AddSettingsMenuPanel()
{
/* current user needs the permission to update plugins for further access */
if (!current_user_can('update_plugins')) {
return;
}
/* submenu page title */
$l_str_PageTitle = FOOTNOTES_PLUGIN_PUBLIC_NAME;
/* submenu title */
$l_str_MenuTitle = FOOTNOTES_PLUGIN_PUBLIC_NAME;
/* Add a new submenu to the standard Settings panel */
$this->a_str_Pagehook = add_options_page($l_str_PageTitle, $l_str_MenuTitle, 'administrator', FOOTNOTES_SETTINGS_PAGE_ID, array($this, 'OutputSettingsPage'));
}
/**
* Plugin Options page rendering goes here, checks
* for active tab and replaces key with the related
* settings key. Uses the plugin_options_tabs method
* to render the tabs.
* @since 1.0
*/
function OutputSettingsPage()
{
/* add the jQuery plugin (already registered by WP) */
wp_enqueue_script('jquery');
/* register settings stylesheet */
wp_register_style('footnote_settings_style', plugins_url('../css/settings.css', __FILE__));
/* add settings stylesheet */
wp_enqueue_style('footnote_settings_style');
/* Needed to allow metabox layout and close functionality */
wp_enqueue_script('postbox');
/* add jquery tools to public page */
wp_enqueue_script('footnotes_public_script', plugins_url('../js/jquery.tools.min.js', __FILE__), array());
/* gets active tag, or if nothing set the "general" tab will be set to active */
$l_str_tab = isset($_GET['tab']) ? $_GET['tab'] : FOOTNOTE_SETTINGS_LABEL_GENERAL;
/* outputs all tabs */
echo '<div class="wrap">';
$this->OutputSettingsPageTabs();
/* outputs a form with the content of the current active tab */
echo '<form method="post" action="options.php">';
wp_nonce_field('update-options');
settings_fields($l_str_tab);
/* outputs the settings field of the current active tab */
do_settings_sections($l_str_tab);
do_meta_boxes($l_str_tab, 'main', NULL);
/* adds a submit button to the current page */
/*
* add submit button only if there are some settings on the current page
* @since version 1.0.7
*/
if ($l_str_tab == FOOTNOTE_SETTINGS_LABEL_GENERAL) {
submit_button();
}
echo '</form>';
echo '</div>';
/*
* output settings page specific javascript code
* @since 1.0.7
*/
$this->OutputJavascript();
}
/**
* Renders our tabs in the plugin options page,
* walks through the object's tabs array and prints
* them one by one. Provides the heading for the
* plugin_options_page method.
* @since 1.0
*/
function OutputSettingsPageTabs()
{
/* gets active tag, or if nothing set the "general" tab will be set to active */
$l_str_CurrentTab = isset($_GET['tab']) ? $_GET['tab'] : FOOTNOTE_SETTINGS_LABEL_GENERAL;
screen_icon();
echo '<h2 class="nav-tab-wrapper">';
foreach ($this->a_arr_SettingsTabs as $l_str_TabKey => $l_str_TabCaption) {
$active = $l_str_CurrentTab == $l_str_TabKey ? 'nav-tab-active' : '';
echo '<a class="nav-tab ' . $active . '" href="?page=' . FOOTNOTES_SETTINGS_PAGE_ID . '&tab=' . $l_str_TabKey . '">' . $l_str_TabCaption . '</a>';
}
echo '</h2>';
}
/**
* outputs page specific javascript code
* @since 1.0.7
*/
function OutputJavascript()
{
?>
<!-- Needed to allow metabox layout and close functionality. -->
<script type="text/javascript">
jQuery(document).ready(function ($) {
// close postboxes that should be closed
$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
// postboxes setup
postboxes.add_postbox_toggles('<?php echo $this->a_str_Pagehook; ?>');
jQuery('#<?php echo $this->getFieldID(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START); ?>').on('change', function() {
var l_int_SelectedIndex = jQuery(this).prop("selectedIndex");
jQuery('#<?php echo $this->getFieldID(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END); ?> option:eq(' + l_int_SelectedIndex + ')').prop('selected', true);
footnotes_Display_UserDefined_Placeholders();
});
jQuery('#<?php echo $this->getFieldID(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END); ?>').on('change', function() {
var l_int_SelectedIndex = jQuery(this).prop("selectedIndex");
jQuery('#<?php echo $this->getFieldID(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START); ?> option:eq(' + l_int_SelectedIndex + ')').prop('selected', true);
footnotes_Display_UserDefined_Placeholders();
});
footnotes_Display_UserDefined_Placeholders();
});
function footnotes_Display_UserDefined_Placeholders() {
if (jQuery('#<?php echo $this->getFieldID(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START); ?>').val() == "userdefined") {
jQuery('#<?php echo $this->getFieldID(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START_USERDEFINED); ?>').show();
jQuery('#<?php echo $this->getFieldID(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END_USERDEFINED); ?>').show();
} else {
jQuery('#<?php echo $this->getFieldID(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START_USERDEFINED); ?>').hide();
jQuery('#<?php echo $this->getFieldID(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END_USERDEFINED); ?>').hide();
}
}
</script>
<?php
}
/**
* loads specific setting and returns an array with the keys [id, name, value]
* @since 1.0
* @param $p_str_FieldID
* @return array
*/
protected function LoadSetting($p_str_FieldID)
{
$p_arr_Return = array();
$p_arr_Return["id"] = $this->getFieldID($p_str_FieldID);
$p_arr_Return["name"] = $this->getFieldName($p_str_FieldID);
$p_arr_Return["value"] = esc_attr($this->getFieldValue($p_str_FieldID));
return $p_arr_Return;
}
/**
* access settings field by name
* @since 1.0
* @param string $p_str_FieldName
* @return string
*/
protected function getFieldName($p_str_FieldName)
{
return sprintf('%s[%s]', FOOTNOTE_SETTINGS_CONTAINER, $p_str_FieldName);
//return sprintf( '%s', $p_str_FieldName );
}
/**
* access settings field by id
* @since 1.0
* @param string $p_str_FieldID
* @return string
*/
protected function getFieldID($p_str_FieldID)
{
//return sprintf('%s[%s]', FOOTNOTE_SETTINGS_CONTAINER, $p_str_FieldID);
return sprintf( '%s', $p_str_FieldID );
}
/**
* get settings field value
* @since 1.0
* @param string $p_str_Key
* @return string
*/
protected function getFieldValue($p_str_Key)
{
return $this->a_arr_Options[$p_str_Key];
}
/**
* outputs a break to have a new line
* @since 1.0.7
*/
function AddNewline()
{
echo '<br/><br/>';
}
/**
* outputs a simple text
* @param string $p_str_Text
* @since 1.1.1
*/
function AddText($p_str_Text)
{
echo '<span>' . $p_str_Text . '</span>';
}
/**
* outputs a label for a specific input/select box
* @param string $p_str_SettingsID
* @param string $p_str_Caption
* @param string $p_str_Styling
* @since 1.0.7
*/
function AddLabel($p_str_SettingsID, $p_str_Caption, $p_str_Styling = "")
{
/* add styling tag if styling is set */
if (!empty($p_str_Styling)) {
$p_str_Styling = ' style="' . $p_str_Styling . '"';
}
echo '<label for="' . $p_str_SettingsID . '"' . $p_str_Styling . '>' . $p_str_Caption . '</label>';
}
/**
* 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 bool $p_bool_Readonly [input is readonly] in version 1.1.1
* @param bool $p_bool_Hidden [input is hidden by default] in version 1.1.2
* @since 1.0-beta
* removed optional paremter for a label in version 1.0.7
*/
function AddTextbox($p_str_SettingsID, $p_str_ClassName = "", $p_str_MaxLength = 0, $p_bool_Readonly = false, $p_bool_Hidden = false)
{
/* collect data for given settings field */
$l_arr_Data = $this->LoadSetting($p_str_SettingsID);
/* if input shall have a css class, add the style tag for it */
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 . '"';
}
if ($p_bool_Readonly) {
$p_bool_Readonly = ' readonly="readonly"';
}
if ($p_bool_Hidden) {
$p_bool_Hidden = ' style="display:none;"';
}
/* outputs an input field type TEXT */
echo '<input type="text" ' . $p_str_ClassName . $p_str_MaxLength . $p_bool_Readonly . $p_bool_Hidden . ' name="' . $l_arr_Data["name"] . '" id="' . $l_arr_Data["id"] . '" value="' . $l_arr_Data["value"] . '"/>';
}
/**
* outputs a input type=checkbox
* @param string $p_str_SettingsID [id of the settings field]
* @param string $p_str_ClassName [optional css class name]
* @since 1.0-beta
*/
function AddCheckbox($p_str_SettingsID, $p_str_ClassName = "")
{
/* collect data for given settings field */
$l_arr_Data = $this->LoadSetting($p_str_SettingsID);
/* if input shall have a css class, add the style tag for it */
if (!empty($p_str_ClassName)) {
$p_str_ClassName = 'class="' . $p_str_ClassName . '"';
}
/* lookup if the checkbox shall be pre-checked */
$l_str_Checked = "";
if (footnotes_ConvertToBool($l_arr_Data["value"])) {
$l_str_Checked = 'checked="checked"';
}
/* outputs an input field type CHECKBOX */
echo sprintf('<input type="checkbox" ' . $p_str_ClassName . ' name="' . $l_arr_Data["name"] . '" id="' . $l_arr_Data["id"] . '" %s/>', $l_str_Checked);
}
/**
* outputs a select box
* @param string $p_str_SettingsID [id of the settings field]
* @param array $p_arr_Options [array with options]
* @param string $p_str_ClassName [optional css class name]
* @since 1.0-beta
*/
function AddSelectbox($p_str_SettingsID, $p_arr_Options, $p_str_ClassName = "")
{
/* collect data for given settings field */
$l_arr_Data = $this->LoadSetting($p_str_SettingsID);
/* if input shall have a css class, add the style tag for it */
if (!empty($p_str_ClassName)) {
$p_str_ClassName = 'class="' . $p_str_ClassName . '"';
}
/* select starting tag */
$l_str_Output = '<select ' . $p_str_ClassName . ' name="' . $l_arr_Data["name"] . '" id="' . $l_arr_Data["id"] . '">';
/* loop through all array keys */
foreach ($p_arr_Options as $l_str_Value => $l_str_Caption) {
/* add key as option value */
$l_str_Output .= '<option value="' . $l_str_Value . '"';
/* check if option value is set and has to be pre-selected */
if ($l_arr_Data["value"] == $l_str_Value) {
$l_str_Output .= ' selected';
}
/* write option caption and close option tag */
$l_str_Output .= '>' . $l_str_Caption . '</option>';
}
/* close select */
$l_str_Output .= '</select>';
/* outputs the SELECT field */
echo $l_str_Output;
}
/**
* initialize general settings tab
* called in class constructor @ admin_init
* @since 1.0
* changed layout of settings form settings fields to meta boxes in version 1.0.7
*/
function RegisterTab_General()
{
/* add tab to the tab array */
$this->a_arr_SettingsTabs[FOOTNOTE_SETTINGS_LABEL_GENERAL] = __("General", FOOTNOTES_PLUGIN_NAME);
/* register settings tab */
add_settings_section("Footnote_Secion_Settings_General", sprintf(__("%s Settings", FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME), array($this, 'RegisterTab_General_Description'), FOOTNOTE_SETTINGS_LABEL_GENERAL);
add_meta_box('Register_MetaBox_ReferenceContainer', __("References Container", FOOTNOTES_PLUGIN_NAME), array($this, 'Register_MetaBox_ReferenceContainer'), FOOTNOTE_SETTINGS_LABEL_GENERAL, 'main');
add_meta_box('Register_MetaBox_FootnoteStyling', sprintf(__("%s styling", FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME), array($this, 'Register_MetaBox_FootnoteStyling'), FOOTNOTE_SETTINGS_LABEL_GENERAL, 'main');
add_meta_box('Register_MetaBox_Love', FOOTNOTES_PLUGIN_PUBLIC_NAME . '&nbsp;' . FOOTNOTES_LOVE_SYMBOL, array($this, 'Register_MetaBox_Love'), FOOTNOTE_SETTINGS_LABEL_GENERAL, 'main');
add_meta_box('Register_MetaBox_Other', __("Other", FOOTNOTES_PLUGIN_NAME), array($this, 'Register_MetaBox_Other'), FOOTNOTE_SETTINGS_LABEL_GENERAL, 'main');
}
/**
* adds a desciption to the general settings tab
* called in RegisterTab_General
* @since 1.0
*/
function RegisterTab_General_Description()
{
// unused description
}
/**
* outputs a container for the reference container settings
* @since 1.0.7
*/
function Register_MetaBox_ReferenceContainer()
{
/* setting for 'reference label' */
$this->AddLabel(FOOTNOTE_INPUTFIELD_REFERENCES_LABEL, __("References label:", FOOTNOTES_PLUGIN_NAME));
$this->AddTextbox(FOOTNOTE_INPUTFIELD_REFERENCES_LABEL, "footnote_plugin_50");
$this->AddNewline();
/* setting for 'collapse reference container by default' */
$this->AddLabel(FOOTNOTE_INPUTFIELD_COLLAPSE_REFERENCES, __("Collapse references by default:", FOOTNOTES_PLUGIN_NAME));
$this->AddCheckbox(FOOTNOTE_INPUTFIELD_COLLAPSE_REFERENCES);
$this->AddNewline();
/*
* setting for 'placement of the reference container'
* @since 1.0.7
*/
$l_arr_Options = array(
"footer" => __("in the footer", FOOTNOTES_PLUGIN_NAME),
"post_end" => __("at the end of the post", FOOTNOTES_PLUGIN_NAME),
"widget" => __("in the widget area", FOOTNOTES_PLUGIN_NAME)
);
$this->AddLabel(FOOTNOTE_INPUTFIELD_REFERENCE_CONTAINER_PLACE, __("Where shall the reference container appear:", FOOTNOTES_PLUGIN_NAME));
$this->AddSelectbox(FOOTNOTE_INPUTFIELD_REFERENCE_CONTAINER_PLACE, $l_arr_Options, "footnote_plugin_50");
}
/**
* outputs a container for the styling of footnotes
* @since 1.0.7
*/
function Register_MetaBox_FootnoteStyling()
{
/* setting for 'combine identical footnotes' */
$l_arr_Options = array(
"yes" => __("Yes", FOOTNOTES_PLUGIN_NAME),
"no" => __("No", FOOTNOTES_PLUGIN_NAME)
);
$this->AddLabel(FOOTNOTE_INPUTFIELD_COMBINE_IDENTICAL, __("Combine identical footnotes:", FOOTNOTES_PLUGIN_NAME));
$this->AddSelectbox(FOOTNOTE_INPUTFIELD_COMBINE_IDENTICAL, $l_arr_Options, "footnote_plugin_50");
$this->AddNewline();
/* setting for 'footnote tag starts with' */
$l_arr_Options = array(
"((" => "((",
"<fn>" => htmlspecialchars("<fn>"),
"[ref]" => "[ref]",
"userdefined" => __('user defined', FOOTNOTES_PLUGIN_NAME)
);
$this->AddLabel(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START, __("Footnote tag starts with:", FOOTNOTES_PLUGIN_NAME));
$this->AddSelectbox(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START, $l_arr_Options, "footnote_plugin_15");
/* setting for 'footnote tag ends with' */
$l_arr_Options = array(
"))" => "))",
"</fn>" => htmlspecialchars("</fn>"),
"[/ref]" => "[/ref]",
"userdefined" => __('user defined', FOOTNOTES_PLUGIN_NAME)
);
$this->AddLabel(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END, __("and ends with:", FOOTNOTES_PLUGIN_NAME) . '&nbsp;&nbsp;&nbsp;', 'text-align: right;');
$this->AddSelectbox(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END, $l_arr_Options, "footnote_plugin_15");
$this->AddNewline();
/* user defined setting for 'footnote start and end tag' */
$this->AddLabel(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START_USERDEFINED, "");
$this->AddTextbox(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START_USERDEFINED, "footnote_plugin_15", 14, false, true);
$this->AddLabel(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END_USERDEFINED, "");
$this->AddTextbox(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END_USERDEFINED, "footnote_plugin_15", 14, false, true);
$this->AddNewline();
/* setting for 'footnotes counter style' */
$l_str_Space = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
$l_arr_Options = array(
"arabic_plain" => __("Arabic Numbers - Plain", FOOTNOTES_PLUGIN_NAME) . $l_str_Space . "1, 2, 3, 4, 5, ...",
"arabic_leading" => __("Arabic Numbers - Leading 0", FOOTNOTES_PLUGIN_NAME) . $l_str_Space . "01, 02, 03, 04, 05, ...",
"latin_low" => __("Latin Character - lower case", FOOTNOTES_PLUGIN_NAME) . $l_str_Space . "a, b, c, d, e, ...",
"latin_high" => __("Latin Character - upper case", FOOTNOTES_PLUGIN_NAME) . $l_str_Space . "A, B, C, D, E, ...",
"romanic" => __("Roman Numerals", FOOTNOTES_PLUGIN_NAME) . $l_str_Space . "I, II, III, IV, V, ..."
);
$this->AddLabel(FOOTNOTE_INPUTFIELD_COUNTER_STYLE, __('Counter style:', FOOTNOTES_PLUGIN_NAME));
$this->AddSelectbox(FOOTNOTE_INPUTFIELD_COUNTER_STYLE, $l_arr_Options, "footnote_plugin_50");
}
/**
* outputs other footnotes settings that doesn't match a special category
* @since 1.0.7
*/
function Register_MetaBox_Love()
{
/* setting for 'love and share this plugin in my footer' */
$l_arr_Options = array(
"text-1" => sprintf(__('I %s %s', FOOTNOTES_PLUGIN_NAME), FOOTNOTES_LOVE_SYMBOL, FOOTNOTES_PLUGIN_PUBLIC_NAME),
"text-2" => sprintf(__('this site uses the awesome %s Plugin', FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME),
"text-3" => sprintf(__('extra smooth %s', FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME),
"random" => __('random text', FOOTNOTES_PLUGIN_NAME),
"no" => sprintf(__("Don't display a %s %s text in my footer.", FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME, FOOTNOTES_LOVE_SYMBOL)
);
$this->AddLabel(FOOTNOTE_INPUTFIELD_LOVE, sprintf(__("Tell the world you're using %s:", FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME));
$this->AddSelectbox(FOOTNOTE_INPUTFIELD_LOVE, $l_arr_Options, "footnote_plugin_50");
$this->AddNewline();
/* no 'love me' on specific pages */
$this->AddText(sprintf(__("Don't tell the world you're using %s on specific pages by adding the following short code:", FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME));
$this->AddText("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
$this->AddText(FOOTNOTES_NO_SLUGME_PLUG);
}
/**
* outputs other footnotes settings that doesn't match a special category
* @since 1.0.7
*/
function Register_MetaBox_Other()
{
/* setting for 'search footnotes tag in excerpt' */
$l_arr_Options = array(
"yes" => __("Yes", FOOTNOTES_PLUGIN_NAME),
"no" => __("No", FOOTNOTES_PLUGIN_NAME)
);
$this->AddLabel(FOOTNOTE_INPUTFIELD_SEARCH_IN_EXCERPT, __('Allow footnotes on Summarized Posts:', FOOTNOTES_PLUGIN_NAME));
$this->AddSelectbox(FOOTNOTE_INPUTFIELD_SEARCH_IN_EXCERPT, $l_arr_Options, "footnote_plugin_50");
}
/**
* initialize howto settings tab
* called in class constructor @ admin_init
* @since 1.0
* changed layout of settings form settings fields to meta boxes in version 1.0.7
*/
function RegisterTab_HowTo()
{
/* add tab to the tab array */
$this->a_arr_SettingsTabs[FOOTNOTE_SETTINGS_LABEL_HOWTO] = __("HowTo", FOOTNOTES_PLUGIN_NAME);
/* register settings tab */
add_settings_section("Footnote_Secion_Settings_Howto", "&nbsp;", array($this, 'RegisterTab_HowTo_Description'), FOOTNOTE_SETTINGS_LABEL_HOWTO);
add_meta_box('Register_MetaBox_HowTo', __("Brief introduction in how to use the plugin", FOOTNOTES_PLUGIN_NAME), array($this, 'Register_MetaBox_HowTo'), FOOTNOTE_SETTINGS_LABEL_HOWTO, 'main');
}
/**
* adds a descrption to the HowTo settings tab
* called int RegisterTab_HowTo
* @since 1.0
* removed output of description in version 1.0.7
*/
function RegisterTab_HowTo_Description()
{
// unused
}
/**
* outputs the content of the HowTo settings tab
* @since 1.0
*/
function Register_MetaBox_HowTo()
{
$l_arr_Footnote_StartingTag = $this->LoadSetting(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START);
$l_arr_Footnote_EndingTag = $this->LoadSetting(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END);
if ($l_arr_Footnote_StartingTag["value"] == "userdefined" || $l_arr_Footnote_EndingTag["value"] == "userdefined") {
$l_arr_Footnote_StartingTag = $this->LoadSetting(FOOTNOTE_INPUTFIELD_PLACEHOLDER_START_USERDEFINED);
$l_arr_Footnote_EndingTag = $this->LoadSetting(FOOTNOTE_INPUTFIELD_PLACEHOLDER_END_USERDEFINED);
}
?>
<div style="text-align:center;">
<div class="footnote_placeholder_box_container">
<p>
<?php echo __("Start your footnote with the following shortcode:", FOOTNOTES_PLUGIN_NAME); ?>
<span
class="footnote_highlight_placeholder"><?php echo $l_arr_Footnote_StartingTag["value"]; ?></span>
</p>
<p>
<?php echo __("...and end your footnote with this shortcode:", FOOTNOTES_PLUGIN_NAME); ?>
<span
class="footnote_highlight_placeholder"><?php echo $l_arr_Footnote_EndingTag["value"]; ?></span>
</p>
<div class="footnote_placeholder_box_example">
<p>
<span
class="footnote_highlight_placeholder"><?php echo $l_arr_Footnote_StartingTag["value"] . __("example string", FOOTNOTES_PLUGIN_NAME) . $l_arr_Footnote_EndingTag["value"]; ?></span>
<?php echo __("will be displayed as:", FOOTNOTES_PLUGIN_NAME); ?>
&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo footnotes_replaceFootnotes($l_arr_Footnote_StartingTag["value"] . __("example string", FOOTNOTES_PLUGIN_NAME) . $l_arr_Footnote_EndingTag["value"], true, true); ?>
</p>
</div>
<p>
<?php echo sprintf(__("If you have any questions, please don't hesitate to %se-mail%s us.", FOOTNOTES_PLUGIN_NAME), '<a href="mailto:mci@cheret.co.uk" class="footnote_plugin">', '</a>'); ?>
</p>
</div>
</div>
<?php
}
} /* Class Class_FootnotesSettings */

View file

@ -1,51 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: Stefan
* Date: 24.05.14
* Time: 13:57
*/
class Class_FootnotesWidget extends WP_Widget {
/**
* @constructor
*/
function Class_FootnotesWidget() {
$widget_ops = array( 'classname' => 'Class_FootnotesWidget', 'description' => __('The widget defines the position of the reference container if set to "widget area".', FOOTNOTES_PLUGIN_NAME) );
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'footnotes_widget' );
$this->WP_Widget( 'footnotes_widget', FOOTNOTES_PLUGIN_NAME, $widget_ops, $control_ops );
}
/**
* widget form creation
* @param $instance
*/
function form($instance) {
echo __('The widget defines the position of the reference container if set to "widget area".', FOOTNOTES_PLUGIN_NAME);
}
/**
* widget update
* @param $new_instance
* @param $old_instance
*/
function update($new_instance, $old_instance) {
return $new_instance;
}
/**
* widget display
* @param $args
* @param $instance
*/
function widget($args, $instance) {
/* 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 == "widget") {
echo footnotes_OutputReferenceContainer();
}
}
}

77
classes/tab_custom.php Normal file
View file

@ -0,0 +1,77 @@
<?php
/**
* Created by Stefan Herndler.
* User: Stefan
* Date: 30.07.14 10:53
* Version: 1.0
* Since: 1.3
*/
// define class only once
if (!class_exists("MCI_Footnotes_Tab_Custom")) :
/**
* Class MCI_Footnotes_Tab_Custom
* @since 1.3
*/
class MCI_Footnotes_Tab_Custom extends MCI_Footnotes_Admin {
/**
* register the meta boxes for the tab
* @constructor
* @since 1.3
* @param array $p_arr_Tabs
*/
public function __construct(&$p_arr_Tabs) {
// add tab to the tab array
$p_arr_Tabs[FOOTNOTES_SETTINGS_TAB_CUSTOM] = __("Custom CSS", FOOTNOTES_PLUGIN_NAME);
// register settings tab
add_settings_section(
"MCI_Footnotes_Settings_Section_Custom",
"&nbsp;",
array($this, 'Description'),
FOOTNOTES_SETTINGS_TAB_CUSTOM
);
// help
add_meta_box(
'MCI_Footnotes_Tab_HowTo_Custom',
__("Add custom CSS to the public page", FOOTNOTES_PLUGIN_NAME),
array($this, 'CSS'),
FOOTNOTES_SETTINGS_TAB_CUSTOM,
'main'
);
}
/**
* output a description for the tab
* @since 1.3
*/
public function Description() {
// unused
}
/**
* @since 1.3
*/
public function CSS() {
$l_str_Separator = " &rArr; ";
// setting for 'reference label'
$this->AddLabel(FOOTNOTES_INPUT_CUSTOM_CSS, __("Add custom CSS:", FOOTNOTES_PLUGIN_NAME));
$this->AddTextarea(FOOTNOTES_INPUT_CUSTOM_CSS, 12, "footnote_plugin_100");
$this->AddNewline();
$this->AddText($this->Highlight(gettext("Available CSS classes to customize the footnotes and the reference container:")) . "<br/>");
echo "<blockquote>";
$this->AddText($this->Highlight(".footnote_plugin_tooltip_text") . $l_str_Separator . gettext("inline footnotes") . "<br/>");
$this->AddText($this->Highlight(".footnote_tooltip") . $l_str_Separator . gettext("inline footnotes, mouse over highlight box") . "<br/><br/>");
$this->AddText($this->Highlight(".footnote_plugin_index") . $l_str_Separator . gettext("reference container footnotes index") . "<br/>");
$this->AddText($this->Highlight(".footnote_plugin_link") . $l_str_Separator . gettext("reference container footnotes linked arrow") . "<br/>");
$this->AddText($this->Highlight(".footnote_plugin_text") . $l_str_Separator . gettext("reference container footnotes text"));
echo "</blockquote>";
}
} // class MCI_Footnotes_Tab_Custom
endif;

190
classes/tab_general.php Normal file
View file

@ -0,0 +1,190 @@
<?php
/**
* Created by Stefan Herndler.
* User: Stefan
* Date: 30.07.14 10:37
* Version: 1.0
* Since: 1.3
*/
// define class only once
if (!class_exists("MCI_Footnotes_Tab_General")) :
/**
* Class MCI_Footnotes_Tab_General
* @since 1.3
*/
class MCI_Footnotes_Tab_General extends MCI_Footnotes_Admin {
/**
* register the meta boxes for the tab
* @constructor
* @since 1.3
* @param array $p_arr_Tabs
*/
public function __construct(&$p_arr_Tabs) {
// add tab to the tab array
$p_arr_Tabs[FOOTNOTES_SETTINGS_TAB_GENERAL] = __("General", FOOTNOTES_PLUGIN_NAME);
// register settings tab
add_settings_section(
"MCI_Footnotes_Settings_Section_General",
sprintf(__("%s Settings", FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME),
array($this, 'Description'),
FOOTNOTES_SETTINGS_TAB_GENERAL
);
// reference container
add_meta_box(
'MCI_Footnotes_Tab_General_ReferenceContainer',
__("References Container", FOOTNOTES_PLUGIN_NAME),
array($this, 'ReferenceContainer'),
FOOTNOTES_SETTINGS_TAB_GENERAL,
'main'
);
// styling
add_meta_box(
'MCI_Footnotes_Tab_General_Styling',
sprintf(__("%s styling", FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME),
array($this, 'Styling'),
FOOTNOTES_SETTINGS_TAB_GENERAL,
'main'
);
// love
add_meta_box(
'MCI_Footnotes_Tab_General_Love',
FOOTNOTES_PLUGIN_PUBLIC_NAME . '&nbsp;' . FOOTNOTES_LOVE_SYMBOL,
array($this, 'Love'),
FOOTNOTES_SETTINGS_TAB_GENERAL,
'main'
);
// other
add_meta_box(
'MCI_Footnotes_Tab_General_Other',
__("Other", FOOTNOTES_PLUGIN_NAME),
array($this, 'Other'),
FOOTNOTES_SETTINGS_TAB_GENERAL,
'main'
);
}
/**
* output a description for the tab
* @since 1.3
*/
public function Description() {
// unused
}
/**
* output the setting fields for the reference container
* @since 1.3
*/
public function ReferenceContainer() {
// setting for 'reference label'
$this->AddLabel(FOOTNOTES_INPUT_REFERENCES_LABEL, __("References label:", FOOTNOTES_PLUGIN_NAME));
$this->AddTextbox(FOOTNOTES_INPUT_REFERENCES_LABEL, "footnote_plugin_50");
$this->AddNewline();
// setting for 'collapse reference container by default'
$this->AddLabel(FOOTNOTES_INPUT_COLLAPSE_REFERENCES, __("Collapse references by default:", FOOTNOTES_PLUGIN_NAME));
$this->AddCheckbox(FOOTNOTES_INPUT_COLLAPSE_REFERENCES);
$this->AddNewline();
// setting for 'placement of the reference container'
// @since 1.0.7
$l_arr_Options = array(
"footer" => __("in the footer", FOOTNOTES_PLUGIN_NAME),
"post_end" => __("at the end of the post", FOOTNOTES_PLUGIN_NAME),
"widget" => __("in the widget area", FOOTNOTES_PLUGIN_NAME)
);
$this->AddLabel(FOOTNOTES_INPUT_REFERENCE_CONTAINER_PLACE, __("Where shall the reference container appear:", FOOTNOTES_PLUGIN_NAME));
$this->AddSelect(FOOTNOTES_INPUT_REFERENCE_CONTAINER_PLACE, $l_arr_Options, "footnote_plugin_50");
}
/**
* output the setting fields for the footnotes styling
* @since 1.3
*/
public function Styling() {
// setting for 'combine identical footnotes'
$l_arr_Options = array(
"yes" => __("Yes", FOOTNOTES_PLUGIN_NAME),
"no" => __("No", FOOTNOTES_PLUGIN_NAME)
);
$this->AddLabel(FOOTNOTES_INPUT_COMBINE_IDENTICAL, __("Combine identical footnotes:", FOOTNOTES_PLUGIN_NAME));
$this->AddSelect(FOOTNOTES_INPUT_COMBINE_IDENTICAL, $l_arr_Options, "footnote_plugin_50");
$this->AddNewline();
// setting for 'footnote tag starts with'
$l_arr_Options = array(
"((" => "((",
"<fn>" => htmlspecialchars("<fn>"),
"[ref]" => "[ref]",
"userdefined" => __('user defined', FOOTNOTES_PLUGIN_NAME)
);
$this->AddLabel(FOOTNOTES_INPUT_PLACEHOLDER_START, __("Footnote tag starts with:", FOOTNOTES_PLUGIN_NAME));
$this->AddSelect(FOOTNOTES_INPUT_PLACEHOLDER_START, $l_arr_Options, "footnote_plugin_15");
// setting for 'footnote tag ends with'
$l_arr_Options = array(
"))" => "))",
"</fn>" => htmlspecialchars("</fn>"),
"[/ref]" => "[/ref]",
"userdefined" => __('user defined', FOOTNOTES_PLUGIN_NAME)
);
$this->AddLabel(FOOTNOTES_INPUT_PLACEHOLDER_END, __("and ends with:", FOOTNOTES_PLUGIN_NAME) . '&nbsp;&nbsp;&nbsp;', 'text-align: right;');
$this->AddSelect(FOOTNOTES_INPUT_PLACEHOLDER_END, $l_arr_Options, "footnote_plugin_15");
$this->AddNewline();
// user defined setting for 'footnote start and end tag'
$this->AddLabel(FOOTNOTES_INPUT_PLACEHOLDER_START_USERDEFINED, "");
$this->AddTextbox(FOOTNOTES_INPUT_PLACEHOLDER_START_USERDEFINED, "footnote_plugin_15", 14, false, true);
$this->AddLabel(FOOTNOTES_INPUT_PLACEHOLDER_END_USERDEFINED, "");
$this->AddTextbox(FOOTNOTES_INPUT_PLACEHOLDER_END_USERDEFINED, "footnote_plugin_15", 14, false, true);
$this->AddNewline();
// setting for 'footnotes counter style'
$l_str_Space = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
$l_arr_Options = array(
"arabic_plain" => __("Arabic Numbers - Plain", FOOTNOTES_PLUGIN_NAME) . $l_str_Space . "1, 2, 3, 4, 5, ...",
"arabic_leading" => __("Arabic Numbers - Leading 0", FOOTNOTES_PLUGIN_NAME) . $l_str_Space . "01, 02, 03, 04, 05, ...",
"latin_low" => __("Latin Character - lower case", FOOTNOTES_PLUGIN_NAME) . $l_str_Space . "a, b, c, d, e, ...",
"latin_high" => __("Latin Character - upper case", FOOTNOTES_PLUGIN_NAME) . $l_str_Space . "A, B, C, D, E, ...",
"romanic" => __("Roman Numerals", FOOTNOTES_PLUGIN_NAME) . $l_str_Space . "I, II, III, IV, V, ..."
);
$this->AddLabel(FOOTNOTES_INPUT_COUNTER_STYLE, __('Counter style:', FOOTNOTES_PLUGIN_NAME));
$this->AddSelect(FOOTNOTES_INPUT_COUNTER_STYLE, $l_arr_Options, "footnote_plugin_50");
}
/**
* output the setting fields to love and share the footnotes plugin
* @since 1.3
*/
public function Love() {
// setting for 'love and share this plugin in my footer'
$l_arr_Options = array(
"text-1" => sprintf(__('I %s %s', FOOTNOTES_PLUGIN_NAME), FOOTNOTES_LOVE_SYMBOL, FOOTNOTES_PLUGIN_PUBLIC_NAME),
"text-2" => sprintf(__('this site uses the awesome %s Plugin', FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME),
"text-3" => sprintf(__('extra smooth %s', FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME),
"random" => __('random text', FOOTNOTES_PLUGIN_NAME),
"no" => sprintf(__("Don't display a %s %s text in my footer.", FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME, FOOTNOTES_LOVE_SYMBOL)
);
$this->AddLabel(FOOTNOTES_INPUT_LOVE, sprintf(__("Tell the world you're using %s:", FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME));
$this->AddSelect(FOOTNOTES_INPUT_LOVE, $l_arr_Options, "footnote_plugin_50");
$this->AddNewline();
// no 'love me' on specific pages
$this->AddText(sprintf(__("Don't tell the world you're using %s on specific pages by adding the following short code:", FOOTNOTES_PLUGIN_NAME), FOOTNOTES_PLUGIN_PUBLIC_NAME));
$this->AddText("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
$this->AddText(FOOTNOTES_NO_SLUGME_PLUG);
}
/**
* output settings fields with no specific topic
* @since 1.3
*/
public function Other() {
// setting for 'search footnotes tag in excerpt'
$l_arr_Options = array(
"yes" => __("Yes", FOOTNOTES_PLUGIN_NAME),
"no" => __("No", FOOTNOTES_PLUGIN_NAME)
);
$this->AddLabel(FOOTNOTES_INPUT_SEARCH_IN_EXCERPT, __('Allow footnotes on Summarized Posts:', FOOTNOTES_PLUGIN_NAME));
$this->AddSelect(FOOTNOTES_INPUT_SEARCH_IN_EXCERPT, $l_arr_Options, "footnote_plugin_50");
}
} // class MCI_Footnotes_Tab_General
endif;

102
classes/tab_howto.php Normal file
View file

@ -0,0 +1,102 @@
<?php
/**
* Created by Stefan Herndler.
* User: Stefan
* Date: 30.07.14 10:53
* Version: 1.0
* Since: 1.3
*/
// define class only once
if (!class_exists("MCI_Footnotes_Tab_HowTo")) :
/**
* Class MCI_Footnotes_Tab_HowTo
* @since 1.3
*/
class MCI_Footnotes_Tab_HowTo extends MCI_Footnotes_Admin {
/**
* register the meta boxes for the tab
* @constructor
* @since 1.3
* @param array $p_arr_Tabs
*/
public function __construct(&$p_arr_Tabs) {
// add tab to the tab array
$p_arr_Tabs[FOOTNOTES_SETTINGS_TAB_HOWTO] = __("How to", FOOTNOTES_PLUGIN_NAME);
// register settings tab
add_settings_section(
"MCI_Footnotes_Settings_Section_HowTo",
"&nbsp;",
array($this, 'Description'),
FOOTNOTES_SETTINGS_TAB_HOWTO
);
// help
add_meta_box(
'MCI_Footnotes_Tab_HowTo_Help',
__("Brief introduction in how to use the plugin", FOOTNOTES_PLUGIN_NAME),
array($this, 'Help'),
FOOTNOTES_SETTINGS_TAB_HOWTO,
'main'
);
}
/**
* output a description for the tab
* @since 1.3
*/
public function Description() {
// unused
}
/**
* outputs the help box
* @since 1.3
*/
public function Help() {
global $g_obj_MCI_Footnotes;
// load footnotes starting and end tag
$l_arr_Footnote_StartingTag = $this->LoadSetting(FOOTNOTES_INPUT_PLACEHOLDER_START);
$l_arr_Footnote_EndingTag = $this->LoadSetting(FOOTNOTES_INPUT_PLACEHOLDER_END);
if ($l_arr_Footnote_StartingTag["value"] == "userdefined" || $l_arr_Footnote_EndingTag["value"] == "userdefined") {
// load user defined starting and end tag
$l_arr_Footnote_StartingTag = $this->LoadSetting(FOOTNOTES_INPUT_PLACEHOLDER_START_USERDEFINED);
$l_arr_Footnote_EndingTag = $this->LoadSetting(FOOTNOTES_INPUT_PLACEHOLDER_END_USERDEFINED);
}
$l_str_Example = $l_arr_Footnote_StartingTag["value"] . __("example string", FOOTNOTES_PLUGIN_NAME) . $l_arr_Footnote_EndingTag["value"];
?>
<div style="text-align:center;">
<div class="footnote_placeholder_box_container">
<p>
<?php echo __("Start your footnote with the following shortcode:", FOOTNOTES_PLUGIN_NAME); ?>
<span class="footnote_highlight_placeholder">
<?php echo $l_arr_Footnote_StartingTag["value"]; ?>
</span>
</p>
<p>
<?php echo __("...and end your footnote with this shortcode:", FOOTNOTES_PLUGIN_NAME); ?>
<span class="footnote_highlight_placeholder">
<?php echo $l_arr_Footnote_EndingTag["value"]; ?>
</span>
</p>
<div class="footnote_placeholder_box_example">
<p>
<span class="footnote_highlight_placeholder"><?php echo $l_str_Example; ?></span>
<?php echo __("will be displayed as:", FOOTNOTES_PLUGIN_NAME); ?>
&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo $g_obj_MCI_Footnotes->a_obj_Task->exec($l_str_Example, true); ?>
</p>
</div>
<p>
<?php echo sprintf(__("If you have any questions, please don't hesitate to %se-mail%s us.", FOOTNOTES_PLUGIN_NAME), '<a href="mailto:mci@cheret.co.uk" class="footnote_plugin">', '</a>'); ?>
</p>
</div>
</div>
<?php
}
} // class MCI_Footnotes_Tab_HowTo
endif;

365
classes/task.php Normal file
View file

@ -0,0 +1,365 @@
<?php
/**
* Created by Stefan Herndler.
* User: Stefan
* Date: 30.07.14 12:07
* Version: 1.0
* Since: 1.3
*/
// define class only once
if (!class_exists("MCI_Footnotes_Task")) :
/**
* Class MCI_Footnotes_Task
* @since 1.3
*/
class MCI_Footnotes_Task {
// array containing the settings
public $a_arr_Settings = array();
// bool admin allows the Love Me slug
public static $a_bool_AllowLoveMe = true;
// array containing all found footnotes
public static $a_arr_Footnotes = array();
/**
* @constructor
* @since 1.3
*/
public function __construct() {
require_once(dirname( __FILE__ ) . "/admin.php");
// load footnote settings
$this->a_arr_Settings = MCI_Footnotes_getOptions(false);
}
/**
* add WordPress hooks
* @since 1.3
*/
public function Register() {
// adds the custom css to the header
add_action('wp_head', array($this, "Header"));
// stops listening to the output and replaces the footnotes
add_action('get_footer', array($this, "Footer"));
// adds the love and share me slug to the footer
add_action('wp_footer', array($this, "Love"));
// moves these contents through the replacement function
add_filter('the_content', array($this, "Content"));
add_filter('the_excerpt', array($this, "Excerpt"));
add_filter('widget_title', array($this, "WidgetTitle"));
add_filter('widget_text', array($this, "WidgetText"));
}
/**
* outputs the custom css to the header
* @since 1.3
*/
public function Header() {
?>
<style type="text/css" media="screen"><?php echo $this->a_arr_Settings[FOOTNOTES_INPUT_CUSTOM_CSS]; ?></style>
<?php
}
/**
* replaces footnotes tags in the post content
* @since 1.3
* @param string $p_str_Content
* @return string
*/
public function Content($p_str_Content) {
// returns content
return $this->exec($p_str_Content, $this->a_arr_Settings[FOOTNOTES_INPUT_REFERENCE_CONTAINER_PLACE] == "post_end" ? true : false);
}
/**
* replaces footnotes tags in the post excerpt
* @since 1.3
* @param string $p_str_Content
* @return string
*/
public function Excerpt($p_str_Content) {
require_once(dirname( __FILE__ ) . "/convert.php");
// search in the excerpt only if activated
if (MCI_Footnotes_Convert::toBool($this->a_arr_Settings[FOOTNOTES_INPUT_SEARCH_IN_EXCERPT])) {
return $this->exec($p_str_Content, false);
}
// returns content
return $p_str_Content;
}
/**
* replaces footnotes tags in the widget title
* @since 1.3
* @param string $p_str_Content
* @return string
*/
public function WidgetTitle($p_str_Content) {
// returns content
return $p_str_Content;
}
/**
* replaces footnotes tags in the widget text
* @since 1.3
* @param string $p_str_Content
* @return string
*/
public function WidgetText($p_str_Content) {
// returns content
return $this->exec( $p_str_Content, $this->a_arr_Settings[FOOTNOTES_INPUT_REFERENCE_CONTAINER_PLACE] == "post_end" ? true : false);
}
/**
* outputs the reference container to the footer
* @since 1.3
*/
public function Footer() {
if ($this->a_arr_Settings[FOOTNOTES_INPUT_REFERENCE_CONTAINER_PLACE] == "footer") {
echo $this->ReferenceContainer();
}
}
/**
* output the love me slug in the footer
* @since 1.3
*/
public function Love() {
// get setting for love and share this plugin and convert it to boolean
$l_str_LoveMeText = $this->a_arr_Settings[FOOTNOTES_INPUT_LOVE];
// check if the admin allows to add a link to the footer
if (empty($l_str_LoveMeText) || strtolower($l_str_LoveMeText) == "no" || !self::$a_bool_AllowLoveMe) {
return;
}
// get random love me text
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]
* @return string
*/
public function exec($p_str_Content, $p_bool_OutputReferences = true) {
// replace all footnotes in the content
$p_str_Content = $this->Lookup($p_str_Content, true);
$p_str_Content = $this->Lookup($p_str_Content, false);
// add the reference list if set
if ($p_bool_OutputReferences) {
$p_str_Content = $p_str_Content . $this->ReferenceContainer();
}
// 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) {
self::$a_bool_AllowLoveMe = false;
$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
*/
public function Lookup($p_str_Content, $p_bool_ConvertHtmlChars = true) {
require_once(dirname( __FILE__ ) . "/convert.php");
// contains the index for the next footnote on this page
$l_int_FootnoteIndex = count(self::$a_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 = $this->a_arr_Settings[FOOTNOTES_INPUT_PLACEHOLDER_START];
// get footnote ending tag
$l_str_EndingTag = $this->a_arr_Settings[FOOTNOTES_INPUT_PLACEHOLDER_END];
// get footnote counter style
$l_str_CounterStyle = $this->a_arr_Settings[FOOTNOTES_INPUT_COUNTER_STYLE];
if ($l_str_StartingTag == "userdefined" || $l_str_EndingTag == "userdefined") {
// get user defined footnote starting tag
$l_str_StartingTag = $this->a_arr_Settings[FOOTNOTES_INPUT_PLACEHOLDER_START_USERDEFINED];
// get user defined footnote ending tag
$l_str_EndingTag = $this->a_arr_Settings[FOOTNOTES_INPUT_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 occurrence of a footnote starting tag
$l_int_PosStart = strpos($p_str_Content, $l_str_StartingTag, $l_int_PosStart);
// tag not found
if ($l_int_PosStart === false) {
break;
}
// get first occurrence of a footnote ending tag after the starting tag
$l_int_PosEnd = strpos($p_str_Content, $l_str_EndingTag, $l_int_PosStart);
// tag not found
if ($l_int_PosEnd === false) {
$l_int_PosStart++;
continue;
}
// 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 replacing string for the footnote
$l_str_ReplaceText = str_replace("[[FOOTNOTE INDEX]]", MCI_Footnotes_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
self::$a_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);
} 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
*/
public function ReferenceContainer() {
// no footnotes has been replaced on this page
if (empty(self::$a_arr_Footnotes)) {
return "";
}
require_once(dirname( __FILE__ ) . "/convert.php");
// get setting for combine identical footnotes and convert it to boolean
$l_bool_CombineIdentical = MCI_Footnotes_Convert::toBool($this->a_arr_Settings[FOOTNOTES_INPUT_COMBINE_IDENTICAL]);
// get setting for preferences label
$l_str_ReferencesLabel = $this->a_arr_Settings[FOOTNOTES_INPUT_REFERENCES_LABEL];
// get setting for collapse reference footnotes and convert it to boolean
$l_bool_CollapseReference = MCI_Footnotes_Convert::toBool($this->a_arr_Settings[FOOTNOTES_INPUT_COLLAPSE_REFERENCES]);
// get footnote counter style
$l_str_CounterStyle = $this->a_arr_Settings[FOOTNOTES_INPUT_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 = '&nbsp;&nbsp;&nbsp;[ <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="' . FOOTNOTES_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(self::$a_arr_Footnotes); $l_str_Index++) {
// get footnote text
$l_str_FootnoteText = self::$a_arr_Footnotes[$l_str_Index];
// if footnote 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 = MCI_Footnotes_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(self::$a_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(self::$a_arr_Footnotes); $l_str_CheckIndex++) {
// check if a further footnote is the same as the actual one
if ($l_str_FootnoteText == self::$a_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 .= ", " . MCI_Footnotes_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]]", MCI_Footnotes_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("#' . FOOTNOTES_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("#' . FOOTNOTES_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
self::$a_arr_Footnotes = array();
// return the output string
return $l_str_Output;
}
} // class MCI_Footnotes_Task
endif;

70
classes/widget.php Normal file
View file

@ -0,0 +1,70 @@
<?php
/**
* Created by PhpStorm.
* User: Stefan
* Date: 24.05.14
* Time: 13:57
*/
// define class only once
if (!class_exists("MCI_Footnotes_Widget")) :
/**
* Class MCI_Footnotes_Widget
* @since 1.0
*/
class MCI_Footnotes_Widget extends WP_Widget {
/**
* @constructor
*/
public function __construct() {
// set widget class and description
$l_arr_WidgetMeta = array(
'classname' => 'Class_FootnotesWidget',
'description' => __('The widget defines the position of the reference container if set to "widget area".', FOOTNOTES_PLUGIN_NAME)
);
// set widget layout information
$l_arr_WidgetLayout = array(
'width' => 300,
'height' => 350,
'id_base' => 'footnotes_widget'
);
// add widget to the list
$this->WP_Widget('footnotes_widget', FOOTNOTES_PLUGIN_NAME, $l_arr_WidgetMeta, $l_arr_WidgetLayout);
}
/**
* widget form creation
* @param $instance
* @return void
*/
public function form($instance) {
echo __('The widget defines the position of the reference container if set to "widget area".', FOOTNOTES_PLUGIN_NAME);
}
/**
* widget update
* @param $new_instance
* @param $old_instance
* @return mixed
*/
public function update($new_instance, $old_instance) {
return $new_instance;
}
/**
* widget display
* @param $args
* @param $instance
*/
public function widget($args, $instance) {
global $g_obj_MCI_Footnotes;
// reference container positioning is set to "widget area"
if ($g_obj_MCI_Footnotes->a_obj_Task->a_arr_Settings[FOOTNOTES_INPUT_REFERENCE_CONTAINER_PLACE] == "widget") {
echo $g_obj_MCI_Footnotes->a_obj_Task->ReferenceContainer();
}
}
} // class MCI_Footnotes_Widget
endif;