This commit is contained in:
Ben Goldsworthy 2021-02-21 09:50:23 +00:00
parent 81a41202bb
commit bb3b555148
13 changed files with 5243 additions and 5219 deletions

View file

@ -26,28 +26,28 @@ class MCI_Footnotes_Convert {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param int $p_int_Index Index to be converted. * @param int $p_int_index Index to be converted.
* @param string $p_str_ConvertStyle Style of the new/converted Index. * @param string $p_str_convert_style Style of the new/converted Index.
* @return string Converted Index as string in the defined counter style. * @return string Converted Index as string in the defined counter style.
* *
* Edited: * Edited:
* @since 2.2.0 lowercase Roman numerals supported * @since 2.2.0 lowercase Roman numerals supported
*/ */
public static function Index($p_int_Index, $p_str_ConvertStyle = "arabic_plain") { public static function Index( $p_int_index, $p_str_convert_style = 'arabic_plain' ) {
switch ($p_str_ConvertStyle) { switch ( $p_str_convert_style ) {
case "romanic": case 'romanic':
return self::toRomanic($p_int_Index, true); return self::to_romanic( $p_int_index, true );
case "roman_low": case 'roman_low':
return self::toRomanic($p_int_Index, false); return self::to_romanic( $p_int_index, false );
case "latin_high": case 'latin_high':
return self::toLatin($p_int_Index, true); return self::to_latin( $p_int_index, true );
case "latin_low": case 'latin_low':
return self::toLatin($p_int_Index, false); return self::to_latin( $p_int_index, false );
case "arabic_leading": case 'arabic_leading':
return self::toArabicLeading($p_int_Index); return self::to_arabic_leading( $p_int_index );
case "arabic_plain": case 'arabic_plain':
default: default:
return $p_int_Index; return $p_int_index;
} }
} }
@ -57,31 +57,31 @@ class MCI_Footnotes_Convert {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.0-gamma * @since 1.0-gamma
* @param int $p_int_Value Value/Index to be converted. * @param int $p_int_value Value/Index to be converted.
* @param bool $p_bool_UpperCase True to convert the value to upper case letter, otherwise to lower case. * @param bool $p_bool_upper_case True to convert the value to upper case letter, otherwise to lower case.
* @return string * @return string
*/ */
private static function toLatin($p_int_Value, $p_bool_UpperCase) { private static function to_latin( $p_int_value, $p_bool_upper_case ) {
// output string // Output string.
$l_str_Return = ""; $l_str_return = '';
$l_int_Offset = 0; $l_int_offset = 0;
// check if the value is higher then 26 = Z // Check if the value is higher then 26 = Z.
while ($p_int_Value > 26) { while ( $p_int_value > 26 ) {
// increase offset and reduce counter // Increase offset and reduce counter.
$l_int_Offset++; $l_int_offset++;
$p_int_Value -= 26; $p_int_value -= 26;
} }
// if offset set (more then Z), then add a new letter in front // If offset set (more then Z), then add a new letter in front.
if ($l_int_Offset > 0) { if ( $l_int_offset > 0 ) {
$l_str_Return = chr($l_int_Offset + 64); $l_str_return = chr( $l_int_offset + 64 );
} }
// add the origin letter // Add the origin letter.
$l_str_Return .= chr($p_int_Value + 64); $l_str_return .= chr( $p_int_value + 64 );
// return the latin character representing the integer // Return the latin character representing the integer.
if ($p_bool_UpperCase) { if ( $p_bool_upper_case ) {
return strtoupper($l_str_Return); return strtoupper( $l_str_return );
} }
return strtolower($l_str_Return); return strtolower( $l_str_return );
} }
/** /**
@ -89,15 +89,15 @@ class MCI_Footnotes_Convert {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.0-gamma * @since 1.0-gamma
* @param int $p_int_Value Value/Index to be converted. * @param int $p_int_value Value/Index to be converted.
* @return string Value with a leading zero. * @return string Value with a leading zero.
*/ */
private static function toArabicLeading($p_int_Value) { private static function to_arabic_leading( $p_int_value ) {
// add a leading 0 if number lower then 10 // Add a leading 0 if number lower then 10.
if ($p_int_Value < 10) { if ( $p_int_value < 10 ) {
return "0" . $p_int_Value; return '0' . $p_int_value;
} }
return $p_int_Value; return $p_int_value;
} }
/** /**
@ -105,15 +105,15 @@ class MCI_Footnotes_Convert {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.0-gamma * @since 1.0-gamma
* @param int $p_int_Value Value/Index to be converted. * @param int $p_int_value Value/Index to be converted.
* @return string * @return string
* *
* Edited: * Edited:
* @since 2.2.0 optionally lowercase (code from Latin) 2020-12-12T1538+0100 * @since 2.2.0 optionally lowercase (code from Latin) 2020-12-12T1538+0100
*/ */
private static function toRomanic($p_int_Value, $p_bool_UpperCase) { private static function to_romanic( $p_int_value, $p_bool_upper_case ) {
// table containing all necessary romanic letters // Table containing all necessary romanic letters.
$l_arr_RomanicLetters = array( $l_arr_romanic_letters = array(
'M' => 1000, 'M' => 1000,
'CM' => 900, 'CM' => 900,
'D' => 500, 'D' => 500,
@ -126,25 +126,25 @@ class MCI_Footnotes_Convert {
'IX' => 9, 'IX' => 9,
'V' => 5, 'V' => 5,
'IV' => 4, 'IV' => 4,
'I' => 1 'I' => 1,
); );
// return value // Return value.
$l_str_Return = ''; $l_str_return = '';
// iterate through integer value until it is reduced to 0 // Iterate through integer value until it is reduced to 0.
while ($p_int_Value > 0) { while ( $p_int_value > 0 ) {
foreach ($l_arr_RomanicLetters as $l_str_Romanic => $l_int_Arabic) { foreach ( $l_arr_romanic_letters as $l_str_romanic => $l_int_arabic ) {
if ($p_int_Value >= $l_int_Arabic) { if ( $p_int_value >= $l_int_arabic ) {
$p_int_Value -= $l_int_Arabic; $p_int_value -= $l_int_arabic;
$l_str_Return .= $l_str_Romanic; $l_str_return .= $l_str_romanic;
break; break;
} }
} }
} }
// return romanic letters as string // Return romanic letters as string.
if ($p_bool_UpperCase) { if ( $p_bool_upper_case ) {
return strtoupper($l_str_Return); return strtoupper( $l_str_return );
} }
return strtolower($l_str_Return); return strtolower( $l_str_return );
} }
/** /**
@ -152,22 +152,22 @@ class MCI_Footnotes_Convert {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.0-beta * @since 1.0-beta
* @param string $p_str_Value String to be converted to boolean. * @param string $p_str_value String to be converted to boolean.
* @return bool Boolean representing the string. * @return bool Boolean representing the string.
*/ */
public static function toBool($p_str_Value) { public static function to_bool( $p_str_value ) {
// convert string to lower-case to make it easier // Convert string to lower-case to make it easier.
$p_str_Value = strtolower($p_str_Value); $p_str_value = strtolower( $p_str_value );
// check if string seems to contain a "true" value // Check if string seems to contain a "true" value.
switch ($p_str_Value) { switch ( $p_str_value ) {
case "checked": case 'checked':
case "yes": case 'yes':
case "true": case 'true':
case "on": case 'on':
case "1": case '1':
return true; return true;
} }
// nothing found that says "true", so we return false // Nothing found that says "true", so we return false.
return false; return false;
} }
@ -176,22 +176,22 @@ class MCI_Footnotes_Convert {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.3.2 * @since 1.3.2
* @param int $p_int_Index Index representing the Arrow. If empty all Arrows are specified. * @param int $p_int_index Index representing the Arrow. If empty all Arrows are specified.
* @return array|string Array of all Arrows if Index is empty otherwise html tag of a specific arrow. * @return array|string Array of all Arrows if Index is empty otherwise html tag of a specific arrow.
*/ */
public static function getArrow($p_int_Index = -1) { public static function get_arrow( $p_int_index = -1 ) {
// define all possible arrows // Define all possible arrows.
$l_arr_Arrows = array("&#8593;", "&#8613;", "&#8607;", "&#8617;", "&#8626;", "&#8629;", "&#8657;", "&#8673;", "&#8679;", "&#65514;"); $l_arr_arrows = array( '&#8593;', '&#8613;', '&#8607;', '&#8617;', '&#8626;', '&#8629;', '&#8657;', '&#8673;', '&#8679;', '&#65514;' );
// convert index to an integer // Convert index to an integer.
if (!is_int($p_int_Index)) { if ( ! is_int( $p_int_index ) ) {
$p_int_Index = intval($p_int_Index); $p_int_index = intval( $p_int_index );
} }
// return the whole arrow array // Return the whole arrow array.
if ($p_int_Index < 0 || $p_int_Index > count($l_arr_Arrows)) { if ( $p_int_index < 0 || $p_int_index > count( $l_arr_arrows ) ) {
return $l_arr_Arrows; return $l_arr_arrows;
} }
// return a single arrow // Return a single arrow.
return $l_arr_Arrows[$p_int_Index]; return $l_arr_arrows[ $p_int_index ];
} }
/** /**
@ -201,29 +201,29 @@ class MCI_Footnotes_Convert {
* @since 1.5.0 * @since 1.5.0
* @param mixed $p_mixed_Value * @param mixed $p_mixed_Value
*/ */
public static function debug($p_mixed_Value) { public static function debug( $p_mixed_Value ) {
if (empty($p_mixed_Value)) { if ( empty( $p_mixed_Value ) ) {
var_dump($p_mixed_Value); var_dump( $p_mixed_Value );
} else if (is_array($p_mixed_Value)) { } else if ( is_array( $p_mixed_Value ) ) {
printf("<pre>"); printf( '<pre>' );
print_r($p_mixed_Value); print_r( $p_mixed_Value );
printf("</pre>"); printf( '</pre>' );
} else if (is_object($p_mixed_Value)) { } else if ( is_object( $p_mixed_Value ) ) {
printf("<pre>"); printf( '<pre>' );
print_r($p_mixed_Value); print_r( $p_mixed_Value );
printf("</pre>"); printf( '</pre>' );
} else if (is_numeric($p_mixed_Value) || is_int($p_mixed_Value)) { } else if ( is_numeric( $p_mixed_Value ) || is_int( $p_mixed_Value ) ) {
var_dump($p_mixed_Value); var_dump( $p_mixed_Value );
} else if (is_date($p_mixed_Value)) { } else if ( is_date( $p_mixed_Value ) ) {
var_dump($p_mixed_Value); var_dump( $p_mixed_Value );
} else { } else {
var_dump($p_mixed_Value); var_dump( $p_mixed_Value );
} }
echo "<br/>"; echo '<br/>';
} }
} }

View file

@ -0,0 +1,214 @@
<?php
/**
* Includes the Plugin settings menu.
*
* @filesource
* @package footnotes
* @author Stefan Herndler
* @since 1.5.0 12.09.14 10:26
*/
/**
* Handles the Settings interface of the Plugin.
*
* @author Stefan Herndler
* @since 1.5.0
*/
class MCI_Footnotes_Layout_Init {
/**
* Slug for the Plugin main menu.
*
* @since 1.5.0
* @var string
*/
const C_STR_MAIN_MENU_SLUG = 'mfmmf';
/**
* Plugin main menu name.
*
* @author Stefan Herndler
* @since 1.5.0
* @var string
*/
const C_STR_MAIN_MENU_TITLE = 'ManFisher';
/**
* Contains layout engine sub classes.
*
* @author Stefan Herndler
* @since 1.5.0
* @var array
*/
private $a_arr_sub_page_classes = array();
/**
* Class Constructor. Initializes all WordPress hooks for the Plugin Settings.
*
* @author Stefan Herndler
* @since 1.5.0
*/
public function __construct() {
// iterate through each class define in the current script.
foreach ( get_declared_classes() as $l_str_class_name ) {
// accept only child classes of the layout engine.
if ( is_subclass_of( $l_str_class_name, 'MCI_Footnotes_LayoutEngine' ) ) {
$l_obj_class = new $l_str_class_name();
// append new instance of the layout engine sub class.
$this->a_arr_sub_page_classes[ $l_obj_class->getPriority() ] = $l_obj_class;
}
}
ksort( $this->a_arr_sub_page_classes );
// register hooks/actions.
add_action( 'admin_init', array( $this, 'initialize_settings' ) );
add_action( 'admin_menu', array( $this, 'register_main_menu' ) );
// register AJAX callbacks for Plugin information.
add_action( 'wp_ajax_nopriv_footnotes_getPluginInfo', array( $this, 'get_plugin_meta_information' ) );
add_action( 'wp_ajax_footnotes_getPluginInfo', array( $this, 'get_plugin_meta_information' ) );
}
/**
* Initializes all sub pages and registers the settings.
*
* @author Stefan Herndler
* @since 1.5.0
*/
public function initialize_settings() {
MCI_Footnotes_Settings::instance()->RegisterSettings();
// iterate though each sub class of the layout engine and register their sections.
foreach ( $this->a_arr_sub_page_classes as $l_obj_layout_engine_sub_class ) {
$l_obj_layout_engine_sub_class->registerSections();
}
}
/**
* Registers the new main menu for the WordPress dashboard.
* Registers all sub menu pages for the new main menu.
*
* @author Stefan Herndler
* @since 1.5.0
* @see http://codex.wordpress.org/Function_Reference/add_menu_page
*/
public function register_main_menu() {
global $menu;
// iterate through each main menu.
foreach ( $menu as $l_arr_main_menu ) {
// iterate through each main menu attribute.
foreach ( $l_arr_main_menu as $l_str_attribute ) {
// main menu already added, append sub pages and stop.
if ( self::C_STR_MAIN_MENU_SLUG === $l_str_attribute ) {
$this->register_sub_pages();
return;
}
}
}
// add a new main menu page to the WordPress dashboard.
add_menu_page(
self::C_STR_MAIN_MENU_TITLE, // page title.
self::C_STR_MAIN_MENU_TITLE, // menu title.
'manage_options', // capability.
self::C_STR_MAIN_MENU_SLUG, // menu slug.
array( $this, 'display_other_plugins' ), // function.
plugins_url( 'footnotes/img/main-menu.png' ), // icon url.
null // position.
);
$this->register_sub_pages();
}
/**
* Registers all SubPages for this Plugin.
*
* @author Stefan Herndler
* @since 1.5.0
*/
private function register_sub_pages() {
// first registered sub menu page MUST NOT contain a unique slug suffix.
// iterate though each sub class of the layout engine and register their sub page.
foreach ( $this->a_arr_sub_page_classes as $l_obj_layout_engine_sub_class ) {
$l_obj_layout_engine_sub_class->register_sub_page();
}
}
/**
* Displays other Plugins from the developers.
*
* @author Stefan Herndler
* @since 1.5.0
*/
public function display_other_plugins() {
printf( '<br/><br/>' );
// load template file.
$l_obj_template = new MCI_Footnotes_Template( MCI_Footnotes_Template::C_STR_DASHBOARD, 'manfisher' );
echo wp_kses_post( $l_obj_template->getContent() );
printf( '<em>visit <a href="https://cheret.de/plugins/footnotes-2/" target="_blank">Mark Cheret</a></em>' );
printf( '<br/><br/>' );
printf( '</div>' );
}
/**
* AJAX call. returns a JSON string containing meta information about a specific WordPress Plugin.
*
* @author Stefan Herndler
* @since 1.5.0
*/
public function get_plugin_meta_information() {
// TODO: add nonce verification.
// get plugin internal name from POST data.
if ( isset( $_POST['plugin'] ) && 'true' === $_POST['plugin'] ) {
$l_str_plugin_name = wp_kses_post( wp_unslash( $_POST['plugin'] ) );
}
if ( empty( $l_str_plugin_name ) ) {
echo json_encode( array( 'error' => 'Plugin name invalid.' ) );
exit;
}
$l_str_url = 'https://api.wordpress.org/plugins/info/1.0/' . $l_str_plugin_name . '.json';
// call URL and collect data.
$l_arr_response = wp_remote_get( $l_str_url );
// check if response is valid.
if ( is_wp_error( $l_arr_response ) ) {
echo json_encode( array( 'error' => 'Error receiving Plugin Information from WordPress.' ) );
exit;
}
if ( ! array_key_exists( 'body', $l_arr_response ) ) {
echo json_encode( array( 'error' => 'Error reading WordPress API response message.' ) );
exit;
}
// get the body of the response.
$l_str_response = $l_arr_response['body'];
// get plugin object.
$l_arr_plugin = json_decode( $l_str_response, true );
if ( empty( $l_arr_plugin ) ) {
echo json_encode( array( 'error' => 'Error reading Plugin meta information.<br/>URL: ' . $l_str_url . '<br/>Response: ' . $l_str_response ) );
exit;
}
$l_int_num_ratings = array_key_exists( 'num_ratings', $l_arr_plugin ) ? intval( $l_arr_plugin['num_ratings'] ) : 0;
$l_int_rating = array_key_exists( 'rating', $l_arr_plugin ) ? floatval( $l_arr_plugin['rating'] ) : 0.0;
$l_int_stars = round( 5 * $l_int_rating / 100.0, 1 );
// return Plugin information as JSON encoded string.
echo json_encode(
array(
'error' => '',
'PluginDescription' => array_key_exists( 'short_description', $l_arr_plugin ) ? html_entity_decode( $l_arr_plugin['short_description'] ) : 'Error reading Plugin information',
'PluginAuthor' => array_key_exists( 'author', $l_arr_plugin ) ? html_entity_decode( $l_arr_plugin['author'] ) : 'unknown',
'PluginRatingText' => $l_int_stars . ' ' . __( 'rating based on', 'footnotes' ) . ' ' . $l_int_num_ratings . ' ' . __( 'ratings', 'footnotes' ),
'PluginRating1' => $l_int_stars >= 0.5 ? 'star-full' : 'star-empty',
'PluginRating2' => $l_int_stars >= 1.5 ? 'star-full' : 'star-empty',
'PluginRating3' => $l_int_stars >= 2.5 ? 'star-full' : 'star-empty',
'PluginRating4' => $l_int_stars >= 3.5 ? 'star-full' : 'star-empty',
'PluginRating5' => $l_int_stars >= 4.5 ? 'star-full' : 'star-empty',
'PluginRating' => $l_int_num_ratings,
'PluginLastUpdated' => array_key_exists( 'last_updated', $l_arr_plugin ) ? $l_arr_plugin['last_updated'] : 'unknown',
'PluginDownloads' => array_key_exists( 'downloaded', $l_arr_plugin ) ? $l_arr_plugin['downloaded'] : '---',
)
);
exit;
}
}

View file

@ -3,6 +3,7 @@
* Includes Layout Engine for the admin dashboard. * Includes Layout Engine for the admin dashboard.
* *
* @filesource * @filesource
* @package footnotes
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 12.09.14 10:56 * @since 1.5.0 12.09.14 10:56
* *
@ -32,7 +33,7 @@ abstract class MCI_Footnotes_LayoutEngine {
* @since 1.5.0 * @since 1.5.0
* @var null|string * @var null|string
*/ */
protected $a_str_SubPageHook = null; protected $a_str_sub_page_hook = null;
/** /**
* Stores all Sections for the child sub page. * Stores all Sections for the child sub page.
@ -41,7 +42,7 @@ abstract class MCI_Footnotes_LayoutEngine {
* @since 1.5.0 * @since 1.5.0
* @var array * @var array
*/ */
protected $a_arr_Sections = array(); protected $a_arr_sections = array();
/** /**
* Returns a Priority index. Lower numbers have a higher Priority. * Returns a Priority index. Lower numbers have a higher Priority.
@ -50,7 +51,7 @@ abstract class MCI_Footnotes_LayoutEngine {
* @since 1.5.0 * @since 1.5.0
* @return int * @return int
*/ */
abstract public function getPriority(); abstract public function get_priority();
/** /**
* Returns the unique slug of the child sub page. * Returns the unique slug of the child sub page.
@ -59,7 +60,7 @@ abstract class MCI_Footnotes_LayoutEngine {
* @since 1.5.0 * @since 1.5.0
* @return string * @return string
*/ */
abstract protected function getSubPageSlug(); abstract protected function get_sub_page_slug();
/** /**
* Returns the title of the child sub page. * Returns the title of the child sub page.
@ -68,7 +69,7 @@ abstract class MCI_Footnotes_LayoutEngine {
* @since 1.5.0 * @since 1.5.0
* @return string * @return string
*/ */
abstract protected function getSubPageTitle(); abstract protected function get_sub_page_title();
/** /**
* Returns an array of all registered sections for a sub page. * Returns an array of all registered sections for a sub page.
@ -77,7 +78,7 @@ abstract class MCI_Footnotes_LayoutEngine {
* @since 1.5.0 * @since 1.5.0
* @return array * @return array
*/ */
abstract protected function getSections(); abstract protected function get_sections();
/** /**
* Returns an array of all registered meta boxes. * Returns an array of all registered meta boxes.
@ -86,25 +87,25 @@ abstract class MCI_Footnotes_LayoutEngine {
* @since 1.5.0 * @since 1.5.0
* @return array * @return array
*/ */
abstract protected function getMetaBoxes(); abstract protected function get_meta_boxes();
/** /**
* Returns an array describing a sub page section. * Returns an array describing a sub page section.
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_ID Unique ID suffix. * @param string $p_str_id Unique ID suffix.
* @param string $p_str_Title Title of the section. * @param string $p_str_title Title of the section.
* @param int $p_int_SettingsContainerIndex Settings Container Index. * @param int $p_int_settings_container_index Settings Container Index.
* @param bool $p_bool_hasSubmitButton Should a Submit Button be displayed for this section, default: true. * @param bool $p_bool_has_submit_button Should a Submit Button be displayed for this section, default: true.
* @return array Array describing the section. * @return array Array describing the section.
*/ */
protected function addSection( $p_str_ID, $p_str_Title, $p_int_SettingsContainerIndex, $p_bool_hasSubmitButton = true ) { protected function add_section( $p_str_id, $p_str_title, $p_int_settings_container_index, $p_bool_has_submit_button = true ) {
return array( return array(
'id' => MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '-' . $p_str_ID, 'id' => MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '-' . $p_str_id,
'title' => $p_str_Title, 'title' => $p_str_title,
'submit' => $p_bool_hasSubmitButton, 'submit' => $p_bool_has_submit_button,
'container' => $p_int_SettingsContainerIndex, 'container' => $p_int_settings_container_index,
); );
} }
@ -113,18 +114,18 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_SectionID Parent Section ID. * @param string $p_str_section_id Parent Section ID.
* @param string $p_str_ID Unique ID suffix. * @param string $p_str_id Unique ID suffix.
* @param string $p_str_Title Title for the meta box. * @param string $p_str_title Title for the meta box.
* @param string $p_str_CallbackFunctionName Class method name for callback. * @param string $p_str_callback_function_name Class method name for callback.
* @return array meta box description to be able to append a meta box to the output. * @return array meta box description to be able to append a meta box to the output.
*/ */
protected function addMetaBox( $p_str_SectionID, $p_str_ID, $p_str_Title, $p_str_CallbackFunctionName ) { protected function add_meta_box( $p_str_section_id, $p_str_id, $p_str_title, $p_str_callback_function_name ) {
return array( return array(
'parent' => MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '-' . $p_str_SectionID, 'parent' => MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '-' . $p_str_section_id,
'id' => $p_str_ID, 'id' => $p_str_id,
'title' => $p_str_Title, 'title' => $p_str_title,
'callback' => $p_str_CallbackFunctionName, 'callback' => $p_str_callback_function_name,
); );
} }
@ -134,26 +135,26 @@ abstract class MCI_Footnotes_LayoutEngine {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
public function registerSubPage() { public function register_sub_page() {
global $submenu; global $submenu;
// any sub menu for our main menu exists // any sub menu for our main menu exists
if ( array_key_exists( plugin_basename( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG ), $submenu ) ) { if ( array_key_exists( plugin_basename( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG ), $submenu ) ) {
// iterate through all sub menu entries of the ManFisher main menu // iterate through all sub menu entries of the ManFisher main menu
foreach ( $submenu[ plugin_basename( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG ) ] as $l_arr_SubMenu ) { foreach ( $submenu[ plugin_basename( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG ) ] as $l_arr_sub_menu ) {
if ( $l_arr_SubMenu[2] == plugin_basename( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->getSubPageSlug() ) ) { if ( $l_arr_sub_menu[2] == plugin_basename( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() ) ) {
// remove that sub menu and add it again to move it to the bottom // remove that sub menu and add it again to move it to the bottom
remove_submenu_page( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG, MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->getSubPageSlug() ); remove_submenu_page( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG, MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() );
} }
} }
} }
$this->a_str_SubPageHook = add_submenu_page( $this->a_str_sub_page_hook = add_submenu_page(
MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG, // parent slug MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG, // parent slug
$this->getSubPageTitle(), // page title $this->get_sub_page_title(), // page title
$this->getSubPageTitle(), // menu title $this->get_sub_page_title(), // menu title
'manage_options', // capability 'manage_options', // capability
MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->getSubPageSlug(), // menu slug MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug(), // menu slug
array( $this, 'displayContent' ) // function array( $this, 'display_content' ) // function
); );
} }
@ -163,18 +164,18 @@ abstract class MCI_Footnotes_LayoutEngine {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
public function registerSections() { public function register_sections() {
// iterate through each section // iterate through each section
foreach ( $this->getSections() as $l_arr_Section ) { foreach ( $this->get_sections() as $l_arr_section ) {
// append tab to the tab-array // append tab to the tab-array
$this->a_arr_Sections[ $l_arr_Section['id'] ] = $l_arr_Section; $this->a_arr_sections[ $l_arr_section['id'] ] = $l_arr_section;
add_settings_section( add_settings_section(
$l_arr_Section['id'], // unique id $l_arr_section['id'], // unique id
'', // $l_arr_Section["title"], // title '', // $l_arr_section["title"], // title
array( $this, 'Description' ), // callback function for the description array( $this, 'Description' ), // callback function for the description
$l_arr_Section['id'] // parent sub page slug $l_arr_section['id'] // parent sub page slug
); );
$this->registerMetaBoxes( $l_arr_Section['id'] ); $this->register_meta_boxes( $l_arr_section['id'] );
} }
} }
@ -183,19 +184,19 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_ParentID Parent section unique id. * @param string $p_str_parent_iD Parent section unique id.
*/ */
private function registerMetaBoxes( $p_str_ParentID ) { private function register_meta_boxes( $p_str_parent_iD ) {
// iterate through each meta box // iterate through each meta box
foreach ( $this->getMetaBoxes() as $l_arr_MetaBox ) { foreach ( $this->get_meta_boxes() as $l_arr_meta_box ) {
if ( $l_arr_MetaBox['parent'] != $p_str_ParentID ) { if ( $l_arr_meta_box['parent'] != $p_str_parent_iD ) {
continue; continue;
} }
add_meta_box( add_meta_box(
$p_str_ParentID . '-' . $l_arr_MetaBox['id'], // unique id $p_str_parent_iD . '-' . $l_arr_meta_box['id'], // unique id
$l_arr_MetaBox['title'], // meta box title $l_arr_meta_box['title'], // meta box title
array( $this, $l_arr_MetaBox['callback'] ), // callback function to display (echo) the content array( $this, $l_arr_meta_box['callback'] ), // callback function to display (echo) the content
$p_str_ParentID, // post type = parent section id $p_str_parent_iD, // post type = parent section id
'main' // context 'main' // context
); );
} }
@ -207,7 +208,7 @@ abstract class MCI_Footnotes_LayoutEngine {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
private function appendScripts() { private function append_scripts() {
// enable meta boxes layout and close functionality // enable meta boxes layout and close functionality
wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'postbox' );
// add WordPress color picker layout // add WordPress color picker layout
@ -252,20 +253,20 @@ abstract class MCI_Footnotes_LayoutEngine {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
public function displayContent() { public function display_content() {
// register and enqueue scripts and styling // register and enqueue scripts and styling
$this->appendScripts(); $this->append_scripts();
// get current section // get current section
reset( $this->a_arr_Sections ); reset( $this->a_arr_sections );
$l_str_ActiveSectionID = isset( $_GET['t'] ) ? $_GET['t'] : key( $this->a_arr_Sections ); $l_str_active_section_iD = isset( $_GET['t'] ) ? $_GET['t'] : key( $this->a_arr_sections );
$l_arr_ActiveSection = $this->a_arr_Sections[ $l_str_ActiveSectionID ]; $l_arr_active_section = $this->a_arr_sections[ $l_str_active_section_iD ];
// store settings // store settings
$l_bool_SettingsUpdated = false; $l_bool_settings_updated = false;
if ( array_key_exists( 'save-settings', $_POST ) ) { if ( array_key_exists( 'save-settings', $_POST ) ) {
if ( $_POST['save-settings'] == 'save' ) { if ( $_POST['save-settings'] == 'save' ) {
unset( $_POST['save-settings'] ); unset( $_POST['save-settings'] );
unset( $_POST['submit'] ); unset( $_POST['submit'] );
$l_bool_SettingsUpdated = $this->saveSettings(); $l_bool_settings_updated = $this->save_settings();
} }
} }
@ -273,31 +274,31 @@ abstract class MCI_Footnotes_LayoutEngine {
echo '<div class="wrap">'; echo '<div class="wrap">';
echo '<h2 class="nav-tab-wrapper">'; echo '<h2 class="nav-tab-wrapper">';
// iterate through all register sections // iterate through all register sections
foreach ( $this->a_arr_Sections as $l_str_ID => $l_arr_Description ) { foreach ( $this->a_arr_sections as $l_str_id => $l_arr_description ) {
echo sprintf( echo sprintf(
'<a class="nav-tab%s" href="?page=%s&t=%s">%s</a>', '<a class="nav-tab%s" href="?page=%s&t=%s">%s</a>',
$l_arr_ActiveSection['id'] == $l_str_ID ? ' nav-tab-active' : '', $l_arr_active_section['id'] == $l_str_id ? ' nav-tab-active' : '',
MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->getSubPageSlug(), MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug(),
$l_str_ID, $l_str_id,
$l_arr_Description['title'] $l_arr_description['title']
); );
} }
echo '</h2><br/>'; echo '</h2><br/>';
if ( $l_bool_SettingsUpdated ) { if ( $l_bool_settings_updated ) {
echo sprintf( '<div id="message" class="updated">%s</div>', __( 'Settings saved', MCI_Footnotes_Config::C_STR_PLUGIN_NAME ) ); echo sprintf( '<div id="message" class="updated">%s</div>', __( 'Settings saved', MCI_Footnotes_Config::C_STR_PLUGIN_NAME ) );
} }
// form to submit the active section // form to submit the active section
echo '<!--suppress HtmlUnknownTarget --><form method="post" action="">'; echo '<!--suppress Html_unknown_target --><form method="post" action="">';
// settings_fields($l_arr_ActiveSection["container"]); // settings_fields($l_arr_active_section["container"]);
echo '<input type="hidden" name="save-settings" value="save" />'; echo '<input type="hidden" name="save-settings" value="save" />';
// outputs the settings field of the active section // outputs the settings field of the active section
do_settings_sections( $l_arr_ActiveSection['id'] ); do_settings_sections( $l_arr_active_section['id'] );
do_meta_boxes( $l_arr_ActiveSection['id'], 'main', null ); do_meta_boxes( $l_arr_active_section['id'], 'main', null );
// add submit button to active section if defined // add submit button to active section if defined
if ( $l_arr_ActiveSection['submit'] ) { if ( $l_arr_active_section['submit'] ) {
submit_button(); submit_button();
} }
// close the form to submit data // close the form to submit data
@ -306,10 +307,10 @@ abstract class MCI_Footnotes_LayoutEngine {
echo '</div>'; echo '</div>';
// output special javascript for the expand/collapse function of the meta boxes // output special javascript for the expand/collapse function of the meta boxes
echo '<script type="text/javascript">'; echo '<script type="text/javascript">';
echo 'jQuery(document).ready(function ($) {'; echo 'j_query(document).ready(function ($) {';
echo 'jQuery(".mfmmf-color-picker").wpColorPicker();'; echo 'j_query(".mfmmf-color-picker").wp_color_picker();';
echo "jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');"; echo "j_query('.if-js-closed').remove_class('if-js-closed').add_class('closed');";
echo "postboxes.add_postbox_toggles('" . $this->a_str_SubPageHook . "');"; echo "postboxes.add_postbox_toggles('" . $this->a_str_sub_page_hook . "');";
echo '});'; echo '});';
echo '</script>'; echo '</script>';
} }
@ -321,25 +322,25 @@ abstract class MCI_Footnotes_LayoutEngine {
* @since 1.5.0 * @since 1.5.0
* @return bool * @return bool
*/ */
private function saveSettings() { private function save_settings() {
$l_arr_newSettings = array(); $l_arr_new_settings = array();
// get current section // get current section
reset( $this->a_arr_Sections ); reset( $this->a_arr_sections );
$l_str_ActiveSectionID = isset( $_GET['t'] ) ? $_GET['t'] : key( $this->a_arr_Sections ); $l_str_active_section_iD = isset( $_GET['t'] ) ? $_GET['t'] : key( $this->a_arr_sections );
$l_arr_ActiveSection = $this->a_arr_Sections[ $l_str_ActiveSectionID ]; $l_arr_active_section = $this->a_arr_sections[ $l_str_active_section_iD ];
// iterate through each value that has to be in the specific container // iterate through each value that has to be in the specific container
foreach ( MCI_Footnotes_Settings::instance()->getDefaults( $l_arr_ActiveSection['container'] ) as $l_str_Key => $l_mixed_Value ) { foreach ( MCI_Footnotes_Settings::instance()->get_defaults( $l_arr_active_section['container'] ) as $l_str_key => $l_mixed_Value ) {
// setting is available in the POST array, use it // setting is available in the POST array, use it
if ( array_key_exists( $l_str_Key, $_POST ) ) { if ( array_key_exists( $l_str_key, $_POST ) ) {
$l_arr_newSettings[ $l_str_Key ] = $_POST[ $l_str_Key ]; $l_arr_new_settings[ $l_str_key ] = $_POST[ $l_str_key ];
} else { } else {
// setting is not defined in the POST array, define it to avoid the Default value // setting is not defined in the POST array, define it to avoid the Default value
$l_arr_newSettings[ $l_str_Key ] = ''; $l_arr_new_settings[ $l_str_key ] = '';
} }
} }
// update settings // update settings
return MCI_Footnotes_Settings::instance()->saveOptions( $l_arr_ActiveSection['container'], $l_arr_newSettings ); return MCI_Footnotes_Settings::instance()->save_options( $l_arr_active_section['container'], $l_arr_new_settings );
} }
/** /**
@ -357,17 +358,17 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_SettingKeyName Settings Array key name. * @param string $p_str_setting_key_name Settings Array key name.
* @return array Contains Settings ID, Settings Name and Settings Value. * @return array Contains Settings ID, Settings Name and Settings Value.
*/ */
protected function LoadSetting( $p_str_SettingKeyName ) { protected function Load_setting( $p_str_setting_key_name ) {
// get current section // get current section
reset( $this->a_arr_Sections ); reset( $this->a_arr_sections );
$p_arr_Return = array(); $p_arr_return = array();
$p_arr_Return['id'] = sprintf( '%s', $p_str_SettingKeyName ); $p_arr_return['id'] = sprintf( '%s', $p_str_setting_key_name );
$p_arr_Return['name'] = sprintf( '%s', $p_str_SettingKeyName ); $p_arr_return['name'] = sprintf( '%s', $p_str_setting_key_name );
$p_arr_Return['value'] = esc_attr( MCI_Footnotes_Settings::instance()->get( $p_str_SettingKeyName ) ); $p_arr_return['value'] = esc_attr( MCI_Footnotes_Settings::instance()->get( $p_str_setting_key_name ) );
return $p_arr_Return; return $p_arr_return;
} }
/** /**
@ -377,7 +378,7 @@ abstract class MCI_Footnotes_LayoutEngine {
* @since 1.5.0 * @since 1.5.0
* @return string * @return string
*/ */
protected function addNewline() { protected function add_newline() {
return '<br/>'; return '<br/>';
} }
@ -388,7 +389,7 @@ abstract class MCI_Footnotes_LayoutEngine {
* @since 1.5.0 * @since 1.5.0
* @return string * @return string
*/ */
protected function addLineSpace() { protected function add_line_space() {
return '<br/><br/>'; return '<br/><br/>';
} }
@ -397,11 +398,11 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_Text Message to be surrounded with simple html tag (span). * @param string $p_str_text Message to be surrounded with simple html tag (span).
* @return string * @return string
*/ */
protected function addText( $p_str_Text ) { protected function add_text( $p_str_text ) {
return sprintf( '<span>%s</span>', $p_str_Text ); return sprintf( '<span>%s</span>', $p_str_text );
} }
/** /**
@ -409,15 +410,15 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_SettingName Name of the Settings key to connect the Label with the input/select field. * @param string $p_str_setting_name Name of the Settings key to connect the Label with the input/select field.
* @param string $p_str_Caption Label caption. * @param string $p_str_caption Label caption.
* @return string * @return string
* *
* Edited 2020-12-01T0159+0100.. * Edited 2020-12-01T0159+0100..
* @since 2.1.6 no colon * @since 2.1.6 no colon
*/ */
protected function addLabel( $p_str_SettingName, $p_str_Caption ) { protected function add_label( $p_str_setting_name, $p_str_caption ) {
if ( empty( $p_str_Caption ) ) { if ( empty( $p_str_caption ) ) {
return ''; return '';
} }
// remove the colon causing localization issues with French, // remove the colon causing localization issues with French,
@ -429,7 +430,7 @@ abstract class MCI_Footnotes_LayoutEngine {
// Add colon to label strings for inclusion in localization. // Add colon to label strings for inclusion in localization.
// Colon after label is widely preferred best practice, mandatory per style guides. // Colon after label is widely preferred best practice, mandatory per style guides.
// <https://softwareengineering.stackexchange.com/questions/234546/colons-in-internationalized-ui> // <https://softwareengineering.stackexchange.com/questions/234546/colons-in-internationalized-ui>
return sprintf( '<label for="%s">%s</label>', $p_str_SettingName, $p_str_Caption ); return sprintf( '<label for="%s">%s</label>', $p_str_setting_name, $p_str_caption );
// ^ here deleted colon 2020-12-08T1546+0100 // ^ here deleted colon 2020-12-08T1546+0100
} }
@ -438,27 +439,27 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_SettingName Name of the Settings key to pre load the input field. * @param string $p_str_setting_name Name of the Settings key to pre load the input field.
* @param int $p_str_MaxLength Maximum length of the input, default 999 characters. * @param int $p_str_maxLength Maximum length of the input, default 999 characters.
* @param bool $p_bool_Readonly Set the input to be read only, default false. * @param bool $p_bool_readonly Set the input to be read only, default false.
* @param bool $p_bool_Hidden Set the input to be hidden, default false. * @param bool $p_bool_hidden Set the input to be hidden, default false.
* @return string * @return string
*/ */
protected function addTextBox( $p_str_SettingName, $p_str_MaxLength = 999, $p_bool_Readonly = false, $p_bool_Hidden = false ) { protected function add_text_box( $p_str_setting_name, $p_str_maxLength = 999, $p_bool_readonly = false, $p_bool_hidden = false ) {
$l_str_Style = ''; $l_str_style = '';
// collect data for given settings field // collect data for given settings field
$l_arr_Data = $this->LoadSetting( $p_str_SettingName ); $l_arr_data = $this->Load_setting( $p_str_setting_name );
if ( $p_bool_Hidden ) { if ( $p_bool_hidden ) {
$l_str_Style .= 'display:none;'; $l_str_style .= 'display:none;';
} }
return sprintf( return sprintf(
'<input type="text" name="%s" id="%s" maxlength="%d" style="%s" value="%s" %s/>', '<input type="text" name="%s" id="%s" maxlength="%d" style="%s" value="%s" %s/>',
$l_arr_Data['name'], $l_arr_data['name'],
$l_arr_Data['id'], $l_arr_data['id'],
$p_str_MaxLength, $p_str_maxLength,
$l_str_Style, $l_str_style,
$l_arr_Data['value'], $l_arr_data['value'],
$p_bool_Readonly ? 'readonly="readonly"' : '' $p_bool_readonly ? 'readonly="readonly"' : ''
); );
} }
@ -467,17 +468,17 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_SettingName Name of the Settings key to pre load the input field. * @param string $p_str_setting_name Name of the Settings key to pre load the input field.
* @return string * @return string
*/ */
protected function addCheckbox( $p_str_SettingName ) { protected function add_checkbox( $p_str_setting_name ) {
// collect data for given settings field // collect data for given settings field
$l_arr_Data = $this->LoadSetting( $p_str_SettingName ); $l_arr_data = $this->Load_setting( $p_str_setting_name );
return sprintf( return sprintf(
'<input type="checkbox" name="%s" id="%s" %s/>', '<input type="checkbox" name="%s" id="%s" %s/>',
$l_arr_Data['name'], $l_arr_data['name'],
$l_arr_Data['id'], $l_arr_data['id'],
MCI_Footnotes_Convert::toBool( $l_arr_Data['value'] ) ? 'checked="checked"' : '' MCI_Footnotes_Convert::to_bool( $l_arr_data['value'] ) ? 'checked="checked"' : ''
); );
} }
@ -486,29 +487,29 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_SettingName Name of the Settings key to pre select the current value. * @param string $p_str_setting_name Name of the Settings key to pre select the current value.
* @param array $p_arr_Options Possible options to be selected. * @param array $p_arr_options Possible options to be selected.
* @return string * @return string
*/ */
protected function addSelectBox( $p_str_SettingName, $p_arr_Options ) { protected function add_select_box( $p_str_setting_name, $p_arr_options ) {
// collect data for given settings field // collect data for given settings field
$l_arr_Data = $this->LoadSetting( $p_str_SettingName ); $l_arr_data = $this->Load_setting( $p_str_setting_name );
$l_str_Options = ''; $l_str_options = '';
/* loop through all array keys */ /* loop through all array keys */
foreach ( $p_arr_Options as $l_str_Value => $l_str_Caption ) { foreach ( $p_arr_options as $l_str_value => $l_str_caption ) {
$l_str_Options .= sprintf( $l_str_options .= sprintf(
'<option value="%s" %s>%s</option>', '<option value="%s" %s>%s</option>',
$l_str_Value, $l_str_value,
$l_arr_Data['value'] == $l_str_Value ? 'selected' : '', $l_arr_data['value'] == $l_str_value ? 'selected' : '',
$l_str_Caption $l_str_caption
); );
} }
return sprintf( return sprintf(
'<select name="%s" id="%s">%s</select>', '<select name="%s" id="%s">%s</select>',
$l_arr_Data['name'], $l_arr_data['name'],
$l_arr_Data['id'], $l_arr_data['id'],
$l_str_Options $l_str_options
); );
} }
@ -517,17 +518,17 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_SettingName Name of the Settings key to pre fill the text area. * @param string $p_str_setting_name Name of the Settings key to pre fill the text area.
* @return string * @return string
*/ */
protected function addTextArea( $p_str_SettingName ) { protected function add_text_area( $p_str_setting_name ) {
// collect data for given settings field // collect data for given settings field
$l_arr_Data = $this->LoadSetting( $p_str_SettingName ); $l_arr_data = $this->Load_setting( $p_str_setting_name );
return sprintf( return sprintf(
'<textarea name="%s" id="%s">%s</textarea>', '<textarea name="%s" id="%s">%s</textarea>',
$l_arr_Data['name'], $l_arr_data['name'],
$l_arr_Data['id'], $l_arr_data['id'],
$l_arr_Data['value'] $l_arr_data['value']
); );
} }
@ -536,17 +537,17 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.6 * @since 1.5.6
* @param string $p_str_SettingName Name of the Settings key to pre load the input field. * @param string $p_str_setting_name Name of the Settings key to pre load the input field.
* @return string * @return string
*/ */
protected function addColorSelection( $p_str_SettingName ) { protected function add_color_selection( $p_str_setting_name ) {
// collect data for given settings field // collect data for given settings field
$l_arr_Data = $this->LoadSetting( $p_str_SettingName ); $l_arr_data = $this->Load_setting( $p_str_setting_name );
return sprintf( return sprintf(
'<input type="text" name="%s" id="%s" class="mfmmf-color-picker" value="%s"/>', '<input type="text" name="%s" id="%s" class="mfmmf-color-picker" value="%s"/>',
$l_arr_Data['name'], $l_arr_data['name'],
$l_arr_Data['id'], $l_arr_data['id'],
$l_arr_Data['value'] $l_arr_data['value']
); );
} }
@ -555,37 +556,37 @@ abstract class MCI_Footnotes_LayoutEngine {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_SettingName Name of the Settings key to pre load the input field. * @param string $p_str_setting_name Name of the Settings key to pre load the input field.
* @param int $p_in_Min Minimum value. * @param int $p_in_Min Minimum value.
* @param int $p_int_Max Maximum value. * @param int $p_int_max Maximum value.
* @param bool $p_bool_Deci true if 0.1 steps and floating to string, false if integer (default) * @param bool $p_bool_deci true if 0.1 steps and floating to string, false if integer (default)
* @return string * @return string
* *
* Edited: * Edited:
* @since 2.1.4 step argument and number_format() to allow decimals 2020-12-03T0631+0100..2020-12-12T1110+0100 * @since 2.1.4 step argument and number_format() to allow decimals 2020-12-03T0631+0100..2020-12-12T1110+0100
*/ */
protected function addNumBox( $p_str_SettingName, $p_in_Min, $p_int_Max, $p_bool_Deci = false ) { protected function add_num_box( $p_str_setting_name, $p_in_Min, $p_int_max, $p_bool_deci = false ) {
// collect data for given settings field // collect data for given settings field
$l_arr_Data = $this->LoadSetting( $p_str_SettingName ); $l_arr_data = $this->Load_setting( $p_str_setting_name );
if ( $p_bool_Deci ) { if ( $p_bool_deci ) {
$l_str_Value = number_format( floatval( $l_arr_Data['value'] ), 1 ); $l_str_value = number_format( floatval( $l_arr_data['value'] ), 1 );
return sprintf( return sprintf(
'<input type="number" name="%s" id="%s" value="%s" step="0.1" min="%d" max="%d"/>', '<input type="number" name="%s" id="%s" value="%s" step="0.1" min="%d" max="%d"/>',
$l_arr_Data['name'], $l_arr_data['name'],
$l_arr_Data['id'], $l_arr_data['id'],
$l_str_Value, $l_str_value,
$p_in_Min, $p_in_Min,
$p_int_Max $p_int_max
); );
} else { } else {
return sprintf( return sprintf(
'<input type="number" name="%s" id="%s" value="%d" min="%d" max="%d"/>', '<input type="number" name="%s" id="%s" value="%d" min="%d" max="%d"/>',
$l_arr_Data['name'], $l_arr_data['name'],
$l_arr_Data['id'], $l_arr_data['id'],
$l_arr_Data['value'], $l_arr_data['value'],
$p_in_Min, $p_in_Min,
$p_int_Max $p_int_max
); );
} }
} }

View file

@ -1,212 +0,0 @@
<?php
/**
* Includes the Plugin settings menu.
*
* @filesource
* @author Stefan Herndler
* @since 1.5.0 12.09.14 10:26
*/
/**
* Handles the Settings interface of the Plugin.
*
* @author Stefan Herndler
* @since 1.5.0
*/
class MCI_Footnotes_Layout_Init {
/**
* Slug for the Plugin main menu.
*
* @author Stefan Herndler
* @since 1.5.0
* @var string
*/
const C_STR_MAIN_MENU_SLUG = 'mfmmf';
/**
* Plugin main menu name.
*
* @author Stefan Herndler
* @since 1.5.0
* @var string
*/
const C_STR_MAIN_MENU_TITLE = 'ManFisher';
/**
*
* @author Stefan Herndler
* @since 1.5.0
* @var array
*/
private $a_arr_SubPageClasses = array();
/**
* Class Constructor. Initializes all WordPress hooks for the Plugin Settings.
*
* @author Stefan Herndler
* @since 1.5.0
*/
public function __construct() {
// iterate through each class define in the current script
foreach ( get_declared_classes() as $l_str_ClassName ) {
// accept only child classes of the layout engine
if ( is_subclass_of( $l_str_ClassName, 'MCI_Footnotes_LayoutEngine' ) ) {
/** @var MCI_Footnotes_LayoutEngine $l_obj_Class */
$l_obj_Class = new $l_str_ClassName();
// append new instance of the layout engine sub class
$this->a_arr_SubPageClasses[ $l_obj_Class->getPriority() ] = $l_obj_Class;
}
}
ksort( $this->a_arr_SubPageClasses );
// register hooks/actions
add_action( 'admin_init', array( $this, 'initializeSettings' ) );
add_action( 'admin_menu', array( $this, 'registerMainMenu' ) );
// register AJAX callbacks for Plugin information
add_action( 'wp_ajax_nopriv_footnotes_getPluginInfo', array( $this, 'getPluginMetaInformation' ) );
add_action( 'wp_ajax_footnotes_getPluginInfo', array( $this, 'getPluginMetaInformation' ) );
}
/**
* Initializes all sub pages and registers the settings.
*
* @author Stefan Herndler
* @since 1.5.0
*/
public function initializeSettings() {
MCI_Footnotes_Settings::instance()->RegisterSettings();
// iterate though each sub class of the layout engine and register their sections
/** @var MCI_Footnotes_LayoutEngine $l_obj_LayoutEngineSubClass */
foreach ( $this->a_arr_SubPageClasses as $l_obj_LayoutEngineSubClass ) {
$l_obj_LayoutEngineSubClass->registerSections();
}
}
/**
* Registers the new main menu for the WordPress dashboard.
* Registers all sub menu pages for the new main menu.
*
* @author Stefan Herndler
* @since 1.5.0
* @see http://codex.wordpress.org/Function_Reference/add_menu_page
*/
public function registerMainMenu() {
global $menu;
// iterate through each main menu
foreach ( $menu as $l_arr_MainMenu ) {
// iterate through each main menu attribute
foreach ( $l_arr_MainMenu as $l_str_Attribute ) {
// main menu already added, append sub pages and stop
if ( $l_str_Attribute == self::C_STR_MAIN_MENU_SLUG ) {
$this->registerSubPages();
return;
}
}
}
// add a new main menu page to the WordPress dashboard
add_menu_page(
self::C_STR_MAIN_MENU_TITLE, // page title
self::C_STR_MAIN_MENU_TITLE, // menu title
'manage_options', // capability
self::C_STR_MAIN_MENU_SLUG, // menu slug
array( $this, 'displayOtherPlugins' ), // function
plugins_url( 'footnotes/img/main-menu.png' ), // icon url
null // position
);
$this->registerSubPages();
}
/**
* Registers all SubPages for this Plugin.
*
* @author Stefan Herndler
* @since 1.5.0
*/
private function registerSubPages() {
// first registered sub menu page MUST NOT contain a unique slug suffix
// iterate though each sub class of the layout engine and register their sub page
/** @var MCI_Footnotes_LayoutEngine $l_obj_LayoutEngineSubClass */
foreach ( $this->a_arr_SubPageClasses as $l_obj_LayoutEngineSubClass ) {
$l_obj_LayoutEngineSubClass->registerSubPage();
}
}
/**
* Displays other Plugins from the developers.
*
* @author Stefan Herndler
* @since 1.5.0
*/
public function displayOtherPlugins() {
printf( '<br/><br/>' );
// load template file
$l_obj_Template = new MCI_Footnotes_Template( MCI_Footnotes_Template::C_STR_DASHBOARD, 'manfisher' );
echo $l_obj_Template->getContent();
printf( '<em>visit <a href="https://cheret.de/plugins/footnotes-2/" target="_blank">Mark Cheret</a></em>' );
printf( '<br/><br/>' );
printf( '</div>' );
}
/**
* AJAX call. returns a JSON string containing meta information about a specific WordPress Plugin.
*
* @author Stefan Herndler
* @since 1.5.0
*/
public function getPluginMetaInformation() {
// get plugin internal name from POST data
$l_str_PluginName = array_key_exists( 'plugin', $_POST ) ? $_POST['plugin'] : null;
if ( empty( $l_str_PluginName ) ) {
echo json_encode( array( 'error' => 'Plugin name invalid.' ) );
exit;
}
$l_str_Url = 'https://api.wordpress.org/plugins/info/1.0/' . $l_str_PluginName . '.json';
// call URL and collect data
$l_arr_Response = wp_remote_get( $l_str_Url );
// check if response is valid
if ( is_wp_error( $l_arr_Response ) ) {
echo json_encode( array( 'error' => 'Error receiving Plugin Information from WordPress.' ) );
exit;
}
if ( ! array_key_exists( 'body', $l_arr_Response ) ) {
echo json_encode( array( 'error' => 'Error reading WordPress API response message.' ) );
exit;
}
// get the body of the response
$l_str_Response = $l_arr_Response['body'];
// get plugin object
$l_arr_Plugin = json_decode( $l_str_Response, true );
if ( empty( $l_arr_Plugin ) ) {
echo json_encode( array( 'error' => 'Error reading Plugin meta information.<br/>URL: ' . $l_str_Url . '<br/>Response: ' . $l_str_Response ) );
exit;
}
$l_int_NumRatings = array_key_exists( 'num_ratings', $l_arr_Plugin ) ? intval( $l_arr_Plugin['num_ratings'] ) : 0;
$l_int_Rating = array_key_exists( 'rating', $l_arr_Plugin ) ? floatval( $l_arr_Plugin['rating'] ) : 0.0;
$l_int_Stars = round( 5 * $l_int_Rating / 100.0, 1 );
// return Plugin information as JSON encoded string
echo json_encode(
array(
'error' => '',
'PluginDescription' => array_key_exists( 'short_description', $l_arr_Plugin ) ? html_entity_decode( $l_arr_Plugin['short_description'] ) : 'Error reading Plugin information',
'PluginAuthor' => array_key_exists( 'author', $l_arr_Plugin ) ? html_entity_decode( $l_arr_Plugin['author'] ) : 'unknown',
'PluginRatingText' => $l_int_Stars . ' ' . __( 'rating based on', MCI_Footnotes_Config::C_STR_PLUGIN_NAME ) . ' ' . $l_int_NumRatings . ' ' . __( 'ratings', MCI_Footnotes_Config::C_STR_PLUGIN_NAME ),
'PluginRating1' => $l_int_Stars >= 0.5 ? 'star-full' : 'star-empty',
'PluginRating2' => $l_int_Stars >= 1.5 ? 'star-full' : 'star-empty',
'PluginRating3' => $l_int_Stars >= 2.5 ? 'star-full' : 'star-empty',
'PluginRating4' => $l_int_Stars >= 3.5 ? 'star-full' : 'star-empty',
'PluginRating5' => $l_int_Stars >= 4.5 ? 'star-full' : 'star-empty',
'PluginRating' => $l_int_NumRatings,
'PluginLastUpdated' => array_key_exists( 'last_updated', $l_arr_Plugin ) ? $l_arr_Plugin['last_updated'] : 'unknown',
'PluginDownloads' => array_key_exists( 'downloaded', $l_arr_Plugin ) ? $l_arr_Plugin['downloaded'] : '---',
)
);
exit;
}
}

View file

@ -24,10 +24,10 @@ class MCI_Footnotes_Hooks {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
public static function registerHooks() { public static function register_hooks() {
register_activation_hook(dirname(__FILE__) . "/../footnotes.php", array("MCI_Footnotes_Hooks", "activatePlugin")); register_activation_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'MCI_Footnotes_Hooks', 'activate_plugin' ) );
register_deactivation_hook(dirname(__FILE__) . "/../footnotes.php", array("MCI_Footnotes_Hooks", "deactivatePlugin")); register_deactivation_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'MCI_Footnotes_Hooks', 'deactivate_plugin' ) );
register_uninstall_hook(dirname(__FILE__) . "/../footnotes.php", array("MCI_Footnotes_Hooks", "uninstallPlugin")); register_uninstall_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'MCI_Footnotes_Hooks', 'uninstall_plugin' ) );
} }
/** /**
@ -36,8 +36,8 @@ class MCI_Footnotes_Hooks {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
public static function activatePlugin() { public static function activate_plugin() {
// currently unused // Currently unused.
} }
/** /**
@ -46,8 +46,8 @@ class MCI_Footnotes_Hooks {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
public static function deactivatePlugin() { public static function deactivate_plugin() {
// currently unused // Currently unused.
} }
/** /**
@ -56,20 +56,20 @@ class MCI_Footnotes_Hooks {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* *
* Edit: ClearAll didnt actually work. * Edit: Clear_all didnt actually work.
* @since 2.2.0 this function is not called any longer when deleting the plugin * @since 2.2.0 this function is not called any longer when deleting the plugin
*/ */
public static function uninstallPlugin() { public static function uninstall_plugin() {
// WordPress User has to be logged in // WordPress User has to be logged in.
if (!is_user_logged_in()) { if ( ! is_user_logged_in() ) {
wp_die(__('You must be logged in to run this script.', MCI_Footnotes_Config::C_STR_PLUGIN_NAME)); wp_die( __( 'You must be logged in to run this script.', MCI_Footnotes_Config::C_STR_PLUGIN_NAME ) );
} }
// WordPress User needs the permission to (un)install plugins // WordPress User needs the permission to (un)install plugins.
if (!current_user_can('install_plugins')) { if ( ! current_user_can( 'install_plugins' ) ) {
wp_die(__('You do not have permission to run this script.', MCI_Footnotes_Config::C_STR_PLUGIN_NAME)); wp_die( __( 'You do not have permission to run this script.', MCI_Footnotes_Config::C_STR_PLUGIN_NAME ) );
} }
// deletes all settings and restore the default values // Deletes all settings and restore the default values.
// MCI_Footnotes_Settings::instance()->ClearAll(); // MCI_Footnotes_Settings::instance()->Clear_all();.
} }
/** /**
@ -77,18 +77,18 @@ class MCI_Footnotes_Hooks {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param array $p_arr_Links Current Links. * @param array $p_arr_links Current Links.
* @param string $p_str_PluginFileName Plugins init file name. * @param string $p_str_plugin_file_name Plugins init file name.
* @return array * @return array
*/ */
public static function PluginLinks($p_arr_Links, $p_str_PluginFileName) { public static function Plugin_links( $p_arr_links, $p_str_plugin_file_name ) {
// append link to the WordPress Plugin page // Append link to the WordPress Plugin page.
$p_arr_Links[] = sprintf('<a href="http://wordpress.org/support/plugin/footnotes" target="_blank">%s</a>', __('Support', MCI_Footnotes_Config::C_STR_PLUGIN_NAME)); $p_arr_links[] = sprintf( '<a href="http://wordpress.org/support/plugin/footnotes" target="_blank">%s</a>', __( 'Support', MCI_Footnotes_Config::C_STR_PLUGIN_NAME ) );
// append link to the Settings page // Append link to the Settings page.
$p_arr_Links[] = sprintf('<a href="%s">%s</a>', admin_url('admin.php?page=mfmmf-footnotes'), __('Settings', MCI_Footnotes_Config::C_STR_PLUGIN_NAME)); $p_arr_links[] = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=mfmmf-footnotes' ), __( 'Settings', MCI_Footnotes_Config::C_STR_PLUGIN_NAME ) );
// append link to the PlayPal Donate function // Append link to the Play_pal Donate function.
$p_arr_Links[] = sprintf('<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6Z6CZDW8PPBBJ" target="_blank">%s</a>', __('Donate', MCI_Footnotes_Config::C_STR_PLUGIN_NAME)); $p_arr_links[] = sprintf( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6Z6CZDW8PPBBJ" target="_blank">%s</a>', __( 'Donate', MCI_Footnotes_Config::C_STR_PLUGIN_NAME ) );
// return new links // Return new links.
return $p_arr_Links; return $p_arr_links;
} }
} }

View file

@ -6,22 +6,21 @@
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 12.09.14 10:56 * @since 1.5.0 12.09.14 10:56
* *
*
* @lastmodified 2021-02-19T2031+0100 * @lastmodified 2021-02-19T2031+0100
* *
* @since 1.6.5 Bugfix: Improve widgets registration, thanks to @felipelavinz code contribution. * @since 1.6.5 Bugfix: Improve widgets registration, thanks to @felipelavinz code contribution.
* @since 1.6.5 Update: Fix for deprecated PHP function create_function(), thanks to @psykonevro @daliasued bug reports, thanks to @felipelavinz code contribution. * @since 1.6.5 Update: Fix for deprecated PHP function create_function(), thanks to @psykonevro @daliasued bug reports, thanks to @felipelavinz code contribution.
* @since 2.0.0 Update: Tooltips: fix disabling bug by loading jQuery UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution. * @since 2.0.0 Update: Tooltips: fix disabling bug by loading j_query UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution.
* *
* @since 2.0.3 add versioning of public.css for cache busting 2020-10-29T1413+0100 * @since 2.0.3 add versioning of public.css for cache busting 2020-10-29T1413+0100
* @since 2.0.4 add jQuery UI from WordPress 2020-11-01T1902+0100 * @since 2.0.4 add j_query UI from WordPress 2020-11-01T1902+0100
* @since 2.1.4 automate passing version number for cache busting 2020-11-30T0646+0100 * @since 2.1.4 automate passing version number for cache busting 2020-11-30T0646+0100
* @since 2.1.4 optionally enqueue an extra stylesheet 2020-12-04T2231+0100 * @since 2.1.4 optionally enqueue an extra stylesheet 2020-12-04T2231+0100
* *
* @since 2.5.5 Update: Stylesheets: increase speed and energy efficiency by tailoring stylesheets to the needs of the instance, thanks to @docteurfitness design contribution. * @since 2.5.5 Update: Stylesheets: increase speed and energy efficiency by tailoring stylesheets to the needs of the instance, thanks to @docteurfitness design contribution.
* @since 2.5.5 Bugfix: Stylesheets: minify to shrink the carbon footprint, increase speed and implement best practice, thanks to @docteurfitness issue report. * @since 2.5.5 Bugfix: Stylesheets: minify to shrink the carbon footprint, increase speed and implement best practice, thanks to @docteurfitness issue report.
* @since 2.5.5 Bugfix: Libraries: optimize processes by loading external and internal scripts only if needed, thanks to @docteurfitness issue report. * @since 2.5.5 Bugfix: Libraries: optimize processes by loading external and internal scripts only if needed, thanks to @docteurfitness issue report.
* @since 2.5.6 Bugfix: Reference container: optional alternative expanding and collapsing without jQuery for use with hard links, thanks to @hopper87it @pkverma99 issue reports. * @since 2.5.6 Bugfix: Reference container: optional alternative expanding and collapsing without j_query for use with hard links, thanks to @hopper87it @pkverma99 issue reports.
*/ */
/** /**
@ -39,7 +38,7 @@ class MCI_Footnotes {
* @since 1.5.0 * @since 1.5.0
* @var null|MCI_Footnotes_Task * @var null|MCI_Footnotes_Task
*/ */
public $a_obj_Task = null; public $a_obj_task = null;
/** /**
* Template process and script / stylesheet load optimization. * Template process and script / stylesheet load optimization.
@ -58,11 +57,11 @@ class MCI_Footnotes {
* @var bool * @var bool
* *
* Streamline process depending on tooltip enabled status. * Streamline process depending on tooltip enabled status.
* Load tooltip inline script only if jQuery tooltips are enabled. * Load tooltip inline script only if j_query tooltips are enabled.
* Actual value depends on settings. * Actual value depends on settings.
*/ */
public static $a_bool_TooltipsEnabled = false; public static $a_bool_tooltips_enabled = false;
public static $a_bool_AlternativeTooltipsEnabled = false; public static $a_bool_alternative_tooltips_enabled = false;
/** /**
* Executes the Plugin. * Executes the Plugin.
@ -78,27 +77,27 @@ class MCI_Footnotes {
* @contributor @felipelavinz * @contributor @felipelavinz
* @link https://github.com/media-competence-institute/footnotes/commit/87173d2980c7ff90e12ffee94ca7153e11163793 * @link https://github.com/media-competence-institute/footnotes/commit/87173d2980c7ff90e12ffee94ca7153e11163793
* *
* @see self::initializeWidgets() * @see self::initialize_widgets()
*/ */
public function run() { public function run() {
// register language // Register language.
MCI_Footnotes_Language::registerHooks(); MCI_Footnotes_Language::register_hooks();
// register Button hooks // Register Button hooks.
MCI_Footnotes_WYSIWYG::registerHooks(); MCI_Footnotes_WYSIWYG::register_hooks();
// register general hooks // Register general hooks.
MCI_Footnotes_Hooks::registerHooks(); MCI_Footnotes_Hooks::register_hooks();
// initialize the Plugin Dashboard // Initialize the Plugin Dashboard.
$this->initializeDashboard(); $this->initialize_dashboard();
// initialize the Plugin Task // Initialize the Plugin Task.
$this->initializeTask(); $this->initialize_task();
// Register all Public Stylesheets and Scripts // Register all Public Stylesheets and Scripts.
add_action('init', array($this, 'registerPublic')); add_action( 'init', array( $this, 'register_public' ) );
// Enqueue all Public Stylesheets and Scripts // Enqueue all Public Stylesheets and Scripts.
add_action('wp_enqueue_scripts', array($this, 'registerPublic')); add_action( 'wp_enqueue_scripts', array( $this, 'register_public' ) );
// Register all Widgets of the Plugin. // Register all Widgets of the Plugin..
add_action('widgets_init', array($this, 'initializeWidgets')); add_action( 'widgets_init', array( $this, 'initialize_widgets' ) );
} }
/** /**
@ -129,10 +128,10 @@ class MCI_Footnotes {
* and use the bare register_widget() here. * and use the bare register_widget() here.
* @see self::run() * @see self::run()
* *
* Also, the visibility of initializeWidgets() is not private any longer. * Also, the visibility of initialize_widgets() is not private any longer.
*/ */
public function initializeWidgets() { public function initialize_widgets() {
register_widget( "MCI_Footnotes_Widget_ReferenceContainer" ); register_widget( 'MCI_Footnotes_Widget_Reference_container' );
} }
/** /**
@ -141,7 +140,7 @@ class MCI_Footnotes {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
private function initializeDashboard() { private function initialize_dashboard() {
new MCI_Footnotes_Layout_Init(); new MCI_Footnotes_Layout_Init();
} }
@ -151,9 +150,9 @@ class MCI_Footnotes {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
private function initializeTask() { private function initialize_task() {
$this->a_obj_Task = new MCI_Footnotes_Task(); $this->a_obj_task = new MCI_Footnotes_Task();
$this->a_obj_Task->registerHooks(); $this->a_obj_task->register_hooks();
} }
/** /**
@ -162,13 +161,13 @@ class MCI_Footnotes {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* *
* @since 2.0.0 Update: Tooltips: fix disabling bug by loading jQuery UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution. * @since 2.0.0 Update: Tooltips: fix disabling bug by loading j_query UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution.
* @since 2.0.3 add versioning of public.css for cache busting 2020-10-29T1413+0100 * @since 2.0.3 add versioning of public.css for cache busting 2020-10-29T1413+0100
* @since 2.0.4 add jQuery UI from WordPress 2020-11-01T1902+0100 * @since 2.0.4 add j_query UI from WordPress 2020-11-01T1902+0100
* @since 2.1.4 automate passing version number for cache busting 2020-11-30T0646+0100 * @since 2.1.4 automate passing version number for cache busting 2020-11-30T0646+0100
* @since 2.1.4 optionally enqueue an extra stylesheet 2020-12-04T2231+0100 * @since 2.1.4 optionally enqueue an extra stylesheet 2020-12-04T2231+0100
*/ */
public function registerPublic() { public function register_public() {
/** /**
* Enqueues external scripts. * Enqueues external scripts.
@ -181,82 +180,82 @@ class MCI_Footnotes {
* *
* The condition about tooltips was missing, only the not-alternative-tooltips part was present. * The condition about tooltips was missing, only the not-alternative-tooltips part was present.
*/ */
// set conditions re-used for stylesheet enqueuing: // Set conditions re-used for stylesheet enqueuing:.
self::$a_bool_TooltipsEnabled = MCI_Footnotes_Convert::toBool(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_BOOL_FOOTNOTES_MOUSE_OVER_BOX_ENABLED ) ); self::$a_bool_tooltips_enabled = MCI_Footnotes_Convert::to_bool( MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_BOOL_FOOTNOTES_MOUSE_OVER_BOX_ENABLED ) );
self::$a_bool_AlternativeTooltipsEnabled = MCI_Footnotes_Convert::toBool(MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_BOOL_FOOTNOTES_MOUSE_OVER_BOX_ALTERNATIVE ) ); self::$a_bool_alternative_tooltips_enabled = MCI_Footnotes_Convert::to_bool( MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_BOOL_FOOTNOTES_MOUSE_OVER_BOX_ALTERNATIVE ) );
$l_str_ScriptMode = MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE); $l_str_script_mode = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE );
/** /**
* Enqueues the jQuery library registered by WordPress. * Enqueues the j_query library registered by WordPress.
* *
* - Bugfix: Reference container: optional alternative expanding and collapsing without jQuery for use with hard links, thanks to @hopper87it @pkverma99 issue reports. * - Bugfix: Reference container: optional alternative expanding and collapsing without j_query for use with hard links, thanks to @hopper87it @pkverma99 issue reports.
* *
* @since 2.5.6 * @since 2.5.6
* *
* @reporter @hopper87it * @reporter @hopper87it
* @link https://wordpress.org/support/topic/footnotes-wp-rocket/ * @link https://wordpress.org/support/topic/footnotes-wp-rocket/
* *
* jQuery is also used for animated scrolling, so it was loaded by default. * j_query is also used for animated scrolling, so it was loaded by default.
* The function wp_enqueue_script() avoids loading the same library multiple times. * The function wp_enqueue_script() avoids loading the same library multiple times.
* After adding the alternative reference container, jQuery has become optional, * After adding the alternative reference container, j_query has become optional,
* but still enabled by default. * but still enabled by default.
*/ */
if ( $l_str_ScriptMode == 'jquery' || ( self::$a_bool_TooltipsEnabled && ! self::$a_bool_AlternativeTooltipsEnabled ) ) { if ( $l_str_script_mode == 'jquery' || ( self::$a_bool_tooltips_enabled && ! self::$a_bool_alternative_tooltips_enabled ) ) {
wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery' );
} }
if ( self::$a_bool_TooltipsEnabled && ! self::$a_bool_AlternativeTooltipsEnabled ) { if ( self::$a_bool_tooltips_enabled && ! self::$a_bool_alternative_tooltips_enabled ) {
/** /**
* Enqueues the jQuery Tools library shipped with the plugin. * Enqueues the j_query Tools library shipped with the plugin.
* *
* redacted jQuery.browser, completed minification; * redacted j_query.browser, completed minification;
* see full header in js/jquery.tools.js * see full header in js/jquery.tools.js
* added versioning 2020-11-18T2150+0100 * added versioning 2020-11-18T2150+0100
* not use '-js' in the handle, is appended automatically * not use '-js' in the handle, is appended automatically
*/ */
wp_enqueue_script( wp_enqueue_script(
'mci-footnotes-jquery-tools', 'mci-footnotes-jquery-tools',
plugins_url('footnotes/js/jquery.tools.min.js'), plugins_url( 'footnotes/js/jquery.tools.min.js' ),
array(), array(),
'1.2.7.redacted.2' '1.2.7.redacted.2'
); );
/** /**
* Registers jQuery UI from the JavaScript Content Delivery Network. * Registers j_query UI from the Java_script Content Delivery Network.
* *
* - Update: Tooltips: fix disabling bug by loading jQuery UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution. * - Update: Tooltips: fix disabling bug by loading j_query UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution.
* *
* @since 2.0.0 * @since 2.0.0
* Alternatively, fetch jQuery UI from cdnjs.cloudflare.com: * Alternatively, fetch j_query UI from cdnjs.cloudflare.com:
* @since 2.0.0 add jQueryUI from Cloudflare 2020-10-26T1907+0100 * @since 2.0.0 add j_query_uI from Cloudflare 2020-10-26T1907+0100
* Used to add jQuery UI following @vonpiernik: * Used to add j_query UI following @vonpiernik:
* <https://wordpress.org/support/topic/tooltip-hover-not-showing/#post-13456762>: * <https://wordpress.org/support/topic/tooltip-hover-not-showing/#post-13456762>:
* *
* *
* jQueryUI re-enables the tooltip infobox disabled when WPv5.5 was released. * j_query_uI re-enables the tooltip infobox disabled when WPv5.5 was released.
* *
* Updated for v2.0.4 by adding jQuery UI from WordPress following @check2020de: * Updated for v2.0.4 by adding j_query UI from WordPress following @check2020de:
* <https://wordpress.org/support/topic/gdpr-issue-with-jquery/> * <https://wordpress.org/support/topic/gdpr-issue-with-jquery/>
* See <https://wordpress.stackexchange.com/questions/273986/correct-way-to-enqueue-jquery-ui> * See <https://wordpress.stackexchange.com/questions/273986/correct-way-to-enqueue-jquery-ui>
* *
* This was enabled in Footnotes v2.0.0 through v2.0.3. * This was enabled in Footnotes v2.0.0 through v2.0.3.
* Re-added for 2.0.9d1 / 2.1.1d0 to look whether it can fix a broken tooltip display. 2020-11-07T1601+0100/2020-11-08T2246+0100 * Re-added for 2.0.9d1 / 2.1.1d0 to look whether it can fix a broken tooltip display. 2020-11-07T1601+0100/2020-11-08T2246+0100
*/ */
//wp_register_script( 'jQueryUI', 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js', null, null, false ); // in header 2020-11-09T2003+0100 // Wp_register_script( 'j_query_uI', 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js', null, null, false ); // In header 2020-11-09T2003+0100.
//wp_enqueue_script( 'jQueryUI' ); // Wp_enqueue_script( 'j_query_uI' );.
/** /**
* This is then needed instead of the above first instance: * This is then needed instead of the above first instance:
* Add jQuery Tools and finish adding jQueryUI: 2020-11-08T1638+0100/2020-11-08T2246+0100 * Add j_query Tools and finish adding j_query_uI: 2020-11-08T1638+0100/2020-11-08T2246+0100
*/ */
//wp_enqueue_script('mci-footnotes-js-jquery-tools', plugins_url('../js/jquery.tools.min.js', __FILE__), ['jQueryUI']); // Wp_enqueue_script('mci-footnotes-js-jquery-tools', plugins_url('../js/jquery.tools.min.js', __FILE__), ['j_query_uI']);.
/** /**
* Enqueues some jQuery UI libraries registered by WordPress. * Enqueues some j_query UI libraries registered by WordPress.
* *
* @since 2.0.4 add jQuery UI from WordPress 2020-11-01T1902+0100 * @since 2.0.4 add j_query UI from WordPress 2020-11-01T1902+0100
* If alternative tooltips are enabled, these libraries are not needed. * If alternative tooltips are enabled, these libraries are not needed.
*/ */
wp_enqueue_script( 'jquery-ui-core' ); wp_enqueue_script( 'jquery-ui-core' );
@ -308,34 +307,43 @@ class MCI_Footnotes {
* The media scope argument 'all' is the default. * The media scope argument 'all' is the default.
* No need to use '-css' in the handle, as this is appended automatically. * No need to use '-css' in the handle, as this is appended automatically.
*/ */
// set tooltip mode for use in stylesheet name: // Set tooltip mode for use in stylesheet name:.
if ( self::$a_bool_TooltipsEnabled ) { if ( self::$a_bool_tooltips_enabled ) {
if ( self::$a_bool_AlternativeTooltipsEnabled ) { if ( self::$a_bool_alternative_tooltips_enabled ) {
$l_str_TooltipMode = 'al'; $l_str_tooltip_mode = 'al';
$l_str_TComplement = 'ternative-tooltips'; $l_str_tcomplement = 'ternative-tooltips';
} else { } else {
$l_str_TooltipMode = 'jq'; $l_str_tooltip_mode = 'jq';
$l_str_TComplement = 'uery-tooltips'; $l_str_tcomplement = 'uery-tooltips';
} }
} else { } else {
$l_str_TooltipMode = 'no'; $l_str_tooltip_mode = 'no';
$l_str_TComplement = '-tooltips'; $l_str_tcomplement = '-tooltips';
} }
// set basic responsive page layout mode for use in stylesheet name: // Set basic responsive page layout mode for use in stylesheet name:.
$l_str_PageLayoutOption = MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT); $l_str_page_layout_option = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT );
switch ( $l_str_PageLayoutOption ) { switch ( $l_str_page_layout_option ) {
case "reference-container": $l_str_LayoutMode = '1'; break; case 'reference-container':
case "entry-content" : $l_str_LayoutMode = '2'; break; $l_str_layout_mode = '1';
case "main-content" : $l_str_LayoutMode = '3'; break; break;
case "none": default: $l_str_LayoutMode = '0'; break; case 'entry-content':
$l_str_layout_mode = '2';
break;
case 'main-content':
$l_str_layout_mode = '3';
break;
case 'none':
default:
$l_str_layout_mode = '0';
break;
} }
// enqueue the tailored united minified stylesheet: // Enqueue the tailored united minified stylesheet:.
wp_enqueue_style( wp_enqueue_style(
'mci-footnotes-' . $l_str_TooltipMode . $l_str_TComplement . '-pagelayout-' . $l_str_PageLayoutOption, 'mci-footnotes-' . $l_str_tooltip_mode . $l_str_tcomplement . '-pagelayout-' . $l_str_page_layout_option,
plugins_url( plugins_url(
MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '/css/footnotes-' . $l_str_TooltipMode . 'ttbrpl' . $l_str_LayoutMode . '.min.css' MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '/css/footnotes-' . $l_str_tooltip_mode . 'ttbrpl' . $l_str_layout_mode . '.min.css'
), ),
array(), array(),
C_STR_FOOTNOTES_VERSION, C_STR_FOOTNOTES_VERSION,
@ -356,12 +364,12 @@ class MCI_Footnotes {
wp_enqueue_style( 'mci-footnotes-tooltips', plugins_url( MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-tooltips.css' ), array(), C_STR_FOOTNOTES_VERSION ); wp_enqueue_style( 'mci-footnotes-tooltips', plugins_url( MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-tooltips.css' ), array(), C_STR_FOOTNOTES_VERSION );
wp_enqueue_style( 'mci-footnotes-alternative', plugins_url( MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-tooltips-alternative.css' ), array(), C_STR_FOOTNOTES_VERSION ); wp_enqueue_style( 'mci-footnotes-alternative', plugins_url( MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-tooltips-alternative.css' ), array(), C_STR_FOOTNOTES_VERSION );
$l_str_PageLayoutOption = MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT); $l_str_page_layout_option = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT );
if ($l_str_PageLayoutOption != 'none') { if ( $l_str_page_layout_option != 'none' ) {
wp_enqueue_style( wp_enqueue_style(
'mci-footnotes-layout-' . $l_str_PageLayoutOption, 'mci-footnotes-layout-' . $l_str_page_layout_option,
plugins_url( plugins_url(
MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-layout-' . $l_str_PageLayoutOption . '.css' MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-layout-' . $l_str_page_layout_option . '.css'
), ),
array(), array(),
C_STR_FOOTNOTES_VERSION, C_STR_FOOTNOTES_VERSION,

View file

@ -6,7 +6,6 @@
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 14.09.14 17:47 * @since 1.5.0 14.09.14 17:47
* *
*
* @lastmodified 2021-02-18T2028+0100 * @lastmodified 2021-02-18T2028+0100
* *
* @since 2.0.0 Bugfix: Localization: correct function call apply_filters() with all required arguments after PHP 7.1 promoted warning to error, thanks to @matkus2 bug report and code contribution. * @since 2.0.0 Bugfix: Localization: correct function call apply_filters() with all required arguments after PHP 7.1 promoted warning to error, thanks to @matkus2 bug report and code contribution.
@ -27,8 +26,8 @@ class MCI_Footnotes_Language {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
public static function registerHooks() { public static function register_hooks() {
add_action('plugins_loaded', array("MCI_Footnotes_Language", "loadTextDomain")); add_action( 'plugins_loaded', array( 'MCI_Footnotes_Language', 'load_text_domain' ) );
} }
/** /**
@ -48,7 +47,7 @@ class MCI_Footnotes_Language {
* @link https://wordpress.org/support/topic/error-missing-parameter-if-using-php-7-1-or-later/ * @link https://wordpress.org/support/topic/error-missing-parameter-if-using-php-7-1-or-later/
* *
* Add 3rd (empty) argument in apply_filters() to prevent PHP from throwing an error: * Add 3rd (empty) argument in apply_filters() to prevent PHP from throwing an error:
* “Fatal error: Uncaught ArgumentCountError: Too few arguments to function apply_filters() * “Fatal error: Uncaught Argument_count_error: Too few arguments to function apply_filters()
* *
* Yet get_locale() is defined w/o parameters in wp-includes/l10n.php:30, and * Yet get_locale() is defined w/o parameters in wp-includes/l10n.php:30, and
* apply_filters() is defined as apply_filters( $tag, $value ) in wp-includes/plugin.php:181. * apply_filters() is defined as apply_filters( $tag, $value ) in wp-includes/plugin.php:181.
@ -65,14 +64,14 @@ class MCI_Footnotes_Language {
* @link https://www.php.net/manual/en/migration71.incompatible.php * @link https://www.php.net/manual/en/migration71.incompatible.php
* @link https://www.php.net/manual/en/migration71.incompatible.php#migration71.incompatible.too-few-arguments-exception * @link https://www.php.net/manual/en/migration71.incompatible.php#migration71.incompatible.too-few-arguments-exception
*/ */
public static function loadTextDomain() { public static function load_text_domain() {
// if language file with localization exists: // If language file with localization exists:.
if ( self::load( apply_filters( 'plugin_locale', get_locale(), '' ) ) ) { if ( self::load( apply_filters( 'plugin_locale', get_locale(), '' ) ) ) {
return; return;
} }
// else fall back to British English: // Else fall back to British English:.
self::load( "en_GB" ); self::load( 'en_GB' );
} }
/** /**
@ -80,7 +79,7 @@ class MCI_Footnotes_Language {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.1 * @since 1.5.1
* @param string $p_str_LanguageCode Language Code to load a specific text domain. * @param string $p_str_language_code Language Code to load a specific text domain.
* @return bool * @return bool
* *
* *
@ -96,12 +95,12 @@ class MCI_Footnotes_Language {
* “The .mo file should be named based on the text domain with a dash, and then the locale exactly. * “The .mo file should be named based on the text domain with a dash, and then the locale exactly.
* @see wp-includes/l10n.php:857 * @see wp-includes/l10n.php:857
*/ */
private static function load($p_str_LanguageCode) { private static function load( $p_str_language_code ) {
return load_plugin_textdomain( return load_plugin_textdomain(
MCI_Footnotes_Config::C_STR_PLUGIN_NAME, MCI_Footnotes_Config::C_STR_PLUGIN_NAME,
// This argument only fills the gap left by a deprecated argument (since WP2.7): // This argument only fills the gap left by a deprecated argument (since WP2.7):.
false, false,
// The plugin basedir is provided; trailing slash would be clipped: // The plugin basedir is provided; trailing slash would be clipped:.
MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '/languages' MCI_Footnotes_Config::C_STR_PLUGIN_NAME . '/languages'
); );
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,6 @@
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 14.09.14 10:58 * @since 1.5.0 14.09.14 10:58
* *
*
* @lastmodified 2021-02-18T2024+0100 * @lastmodified 2021-02-18T2024+0100
* *
* @since 2.0.3 prettify reference container template * @since 2.0.3 prettify reference container template
@ -45,7 +44,7 @@ class MCI_Footnotes_Template {
* @since 1.5.0 * @since 1.5.0
* @var string * @var string
*/ */
const C_STR_DASHBOARD = "dashboard"; const C_STR_DASHBOARD = 'dashboard';
/** /**
* Directory name for public templates. * Directory name for public templates.
@ -54,7 +53,7 @@ class MCI_Footnotes_Template {
* @since 1.5.0 * @since 1.5.0
* @var string * @var string
*/ */
const C_STR_PUBLIC = "public"; const C_STR_PUBLIC = 'public';
/** /**
* Contains the content of the template after initialize. * Contains the content of the template after initialize.
@ -63,7 +62,7 @@ class MCI_Footnotes_Template {
* @since 1.5.0 * @since 1.5.0
* @var string * @var string
*/ */
private $a_str_OriginalContent = ""; private $a_str_original_content = '';
/** /**
* Contains the content of the template after initialize with replaced place holders. * Contains the content of the template after initialize with replaced place holders.
@ -72,7 +71,7 @@ class MCI_Footnotes_Template {
* @since 1.5.0 * @since 1.5.0
* @var string * @var string
*/ */
private $a_str_ReplacedContent = ""; private $a_str_replaced_content = '';
/** /**
* Plugin Directory * Plugin Directory
@ -89,10 +88,9 @@ class MCI_Footnotes_Template {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_FileType Template file type (take a look on the Class constants). * @param string $p_str_file_type Template file type (take a look on the Class constants).
* @param string $p_str_FileName Template file name inside the Template directory without the file extension. * @param string $p_str_file_name Template file name inside the Template directory without the file extension.
* @param string $p_str_Extension Optional Template file extension (default: html) * @param string $p_str_extension Optional Template file extension (default: html)
*
* *
* @since 2.2.6 support for custom templates 2020-12-19T0606+0100 * @since 2.2.6 support for custom templates 2020-12-19T0606+0100
* @link https://wordpress.org/support/topic/template-override-filter/ * @link https://wordpress.org/support/topic/template-override-filter/
@ -100,9 +98,9 @@ class MCI_Footnotes_Template {
* @since 2.4.0 look for custom template in the active theme first, thanks to @misfist * @since 2.4.0 look for custom template in the active theme first, thanks to @misfist
* @link https://wordpress.org/support/topic/template-override-filter/#post-13846598 * @link https://wordpress.org/support/topic/template-override-filter/#post-13846598
*/ */
public function __construct($p_str_FileType, $p_str_FileName, $p_str_Extension = "html") { public function __construct( $p_str_file_type, $p_str_file_name, $p_str_extension = 'html' ) {
// no template file type and/or file name set // No template file type and/or file name set.
if (empty($p_str_FileType) || empty($p_str_FileName)) { if ( empty( $p_str_file_type ) || empty( $p_str_file_name ) ) {
return; return;
} }
@ -122,7 +120,7 @@ class MCI_Footnotes_Template {
* *
* @author Patrizia Lutz @misfist * @author Patrizia Lutz @misfist
*/ */
if( $template = $this->get_template( $p_str_FileType, $p_str_FileName, $p_str_Extension ) ) { if ( $template = $this->get_template( $p_str_file_type, $p_str_file_name, $p_str_extension ) ) {
$this->process_template( $template ); $this->process_template( $template );
} else { } else {
return; return;
@ -135,23 +133,23 @@ class MCI_Footnotes_Template {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param array $p_arr_Placeholders Placeholders (key = placeholder, value = value). * @param array $p_arr_placeholders Placeholders (key = placeholder, value = value).
* @return bool True on Success, False if Placeholders invalid. * @return bool True on Success, False if Placeholders invalid.
*/ */
public function replace($p_arr_Placeholders) { public function replace( $p_arr_placeholders ) {
// no placeholders set // No placeholders set.
if (empty($p_arr_Placeholders)) { if ( empty( $p_arr_placeholders ) ) {
return false; return false;
} }
// template content is empty // Template content is empty.
if (empty($this->a_str_ReplacedContent)) { if ( empty( $this->a_str_replaced_content ) ) {
return false; return false;
} }
// iterate through each placeholder and replace it with its value // Iterate through each placeholder and replace it with its value.
foreach($p_arr_Placeholders as $l_str_Placeholder => $l_str_Value) { foreach ( $p_arr_placeholders as $l_str_placeholder => $l_str_value ) {
$this->a_str_ReplacedContent = str_replace("[[" . $l_str_Placeholder . "]]", $l_str_Value, $this->a_str_ReplacedContent); $this->a_str_replaced_content = str_replace( '[[' . $l_str_placeholder . ']]', $l_str_value, $this->a_str_replaced_content );
} }
// success // Success.
return true; return true;
} }
@ -162,7 +160,7 @@ class MCI_Footnotes_Template {
* @since 1.5.0 * @since 1.5.0
*/ */
public function reload() { public function reload() {
$this->a_str_ReplacedContent = $this->a_str_OriginalContent; $this->a_str_replaced_content = $this->a_str_original_content;
} }
/** /**
@ -172,8 +170,8 @@ class MCI_Footnotes_Template {
* @since 1.5.0 * @since 1.5.0
* @return string Template content with replaced placeholders. * @return string Template content with replaced placeholders.
*/ */
public function getContent() { public function get_content() {
return $this->a_str_ReplacedContent; return $this->a_str_replaced_content;
} }
/** /**
@ -186,7 +184,6 @@ class MCI_Footnotes_Template {
* @param string $template * @param string $template
* @return void * @return void
* *
*
* @since 2.0.3 replace tab with a space * @since 2.0.3 replace tab with a space
* @since 2.0.3 replace 2 spaces with 1 * @since 2.0.3 replace 2 spaces with 1
* @since 2.0.4 collapse multiple spaces * @since 2.0.4 collapse multiple spaces
@ -194,13 +191,13 @@ class MCI_Footnotes_Template {
* @since 2.5.4 collapse HTML comments and PHP/JS docblocks (only) * @since 2.5.4 collapse HTML comments and PHP/JS docblocks (only)
*/ */
public function process_template( $template ) { public function process_template( $template ) {
$this->a_str_OriginalContent = preg_replace( '#<!--.+?-->#s', "", file_get_contents( $template ) ); $this->a_str_original_content = preg_replace( '#<!--.+?-->#s', '', file_get_contents( $template ) );
$this->a_str_OriginalContent = preg_replace( '#/\*\*.+?\*/#s', "", $this->a_str_OriginalContent ); $this->a_str_original_content = preg_replace( '#/\*\*.+?\*/#s', '', $this->a_str_original_content );
$this->a_str_OriginalContent = str_replace( "\n", "", $this->a_str_OriginalContent ); $this->a_str_original_content = str_replace( "\n", '', $this->a_str_original_content );
$this->a_str_OriginalContent = str_replace( "\r", "", $this->a_str_OriginalContent ); $this->a_str_original_content = str_replace( "\r", '', $this->a_str_original_content );
$this->a_str_OriginalContent = str_replace( "\t", " ", $this->a_str_OriginalContent ); $this->a_str_original_content = str_replace( "\t", ' ', $this->a_str_original_content );
$this->a_str_OriginalContent = preg_replace( '# +#', " ", $this->a_str_OriginalContent ); $this->a_str_original_content = preg_replace( '# +#', ' ', $this->a_str_original_content );
$this->a_str_OriginalContent = str_replace( " >", ">", $this->a_str_OriginalContent ); $this->a_str_original_content = str_replace( ' >', '>', $this->a_str_original_content );
$this->reload(); $this->reload();
} }
@ -211,16 +208,17 @@ class MCI_Footnotes_Template {
* *
* @since 2.4.0d3 * @since 2.4.0d3
* *
* @param string $p_str_FileType * @param string $p_str_file_type
* @param string $p_str_FileName * @param string $p_str_file_name
* @param string $p_str_Extension * @param string $p_str_extension
* @return mixed false | template path * @return mixed false | template path
*/ */
public function get_template( $p_str_FileType, $p_str_FileName, $p_str_Extension = "html" ) { public function get_template( $p_str_file_type, $p_str_file_name, $p_str_extension = 'html' ) {
$located = false; $located = false;
/** /**
* The directory change be modified * The directory change be modified
*
* @usage to change location of templates to `template_parts/footnotes/': * @usage to change location of templates to `template_parts/footnotes/':
* add_filter( 'mci_footnotes_template_directory', function( $directory ) { * add_filter( 'mci_footnotes_template_directory', function( $directory ) {
* return 'template_parts/footnotes/; * return 'template_parts/footnotes/;
@ -228,7 +226,7 @@ class MCI_Footnotes_Template {
*/ */
$template_directory = apply_filters( 'mci_footnotes_template_directory', 'footnotes/templates/' ); $template_directory = apply_filters( 'mci_footnotes_template_directory', 'footnotes/templates/' );
$custom_directory = apply_filters( 'mci_footnotes_custom_template_directory', 'footnotes-custom/' ); $custom_directory = apply_filters( 'mci_footnotes_custom_template_directory', 'footnotes-custom/' );
$template_name = $p_str_FileType . '/' . $p_str_FileName . '.' . $p_str_Extension; $template_name = $p_str_file_type . '/' . $p_str_file_name . '.' . $p_str_extension;
/** /**
* Look in active (child) theme * Look in active (child) theme
@ -258,4 +256,4 @@ class MCI_Footnotes_Template {
return $located; return $located;
} }
} // end of class } // End of class.

View file

@ -14,14 +14,14 @@
*/ */
class MCI_Footnotes_WYSIWYG { class MCI_Footnotes_WYSIWYG {
public static function registerHooks() { public static function register_hooks() {
add_filter("mce_buttons", array("MCI_Footnotes_WYSIWYG", "newVisualEditorButton")); add_filter( 'mce_buttons', array( 'MCI_Footnotes_WYSIWYG', 'new_visual_editor_button' ) );
add_action("admin_print_footer_scripts", array("MCI_Footnotes_WYSIWYG", "newPlainTextEditorButton")); add_action( 'admin_print_footer_scripts', array( 'MCI_Footnotes_WYSIWYG', 'new_plain_text_editor_button' ) );
add_filter("mce_external_plugins", array("MCI_Footnotes_WYSIWYG", "includeScripts")); add_filter( 'mce_external_plugins', array( 'MCI_Footnotes_WYSIWYG', 'include_scripts' ) );
add_action("wp_ajax_nopriv_footnotes_getTags", array("MCI_Footnotes_WYSIWYG", "ajaxCallback")); add_action( 'wp_ajax_nopriv_footnotes_get_tags', array( 'MCI_Footnotes_WYSIWYG', 'ajax_callback' ) );
add_action("wp_ajax_footnotes_getTags", array("MCI_Footnotes_WYSIWYG", "ajaxCallback")); add_action( 'wp_ajax_footnotes_get_tags', array( 'MCI_Footnotes_WYSIWYG', 'ajax_callback' ) );
} }
@ -30,12 +30,12 @@ class MCI_Footnotes_WYSIWYG {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param array $p_arr_Buttons pre defined Buttons from WordPress. * @param array $p_arr_buttons pre defined Buttons from WordPress.
* @return array * @return array
*/ */
public static function newVisualEditorButton($p_arr_Buttons) { public static function new_visual_editor_button( $p_arr_buttons ) {
array_push($p_arr_Buttons, MCI_Footnotes_Config::C_STR_PLUGIN_NAME); array_push( $p_arr_buttons, MCI_Footnotes_Config::C_STR_PLUGIN_NAME );
return $p_arr_Buttons; return $p_arr_buttons;
} }
/** /**
@ -44,9 +44,9 @@ class MCI_Footnotes_WYSIWYG {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
public static function newPlainTextEditorButton() { public static function new_plain_text_editor_button() {
$l_obj_Template = new MCI_Footnotes_Template(MCI_Footnotes_Template::C_STR_DASHBOARD, "editor-button"); $l_obj_template = new MCI_Footnotes_Template( MCI_Footnotes_Template::C_STR_DASHBOARD, 'editor-button' );
echo $l_obj_Template->getContent(); echo $l_obj_template->get_content();
} }
/** /**
@ -54,12 +54,12 @@ class MCI_Footnotes_WYSIWYG {
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param array $p_arr_Plugins Scripts to be included to the editor. * @param array $p_arr_plugins Scripts to be included to the editor.
* @return array * @return array
*/ */
public static function includeScripts($p_arr_Plugins) { public static function include_scripts( $p_arr_plugins ) {
$p_arr_Plugins[MCI_Footnotes_Config::C_STR_PLUGIN_NAME] = plugins_url('/../js/wysiwyg-editor.js', __FILE__); $p_arr_plugins[ MCI_Footnotes_Config::C_STR_PLUGIN_NAME ] = plugins_url( '/../js/wysiwyg-editor.js', __FILE__ );
return $p_arr_Plugins; return $p_arr_plugins;
} }
/** /**
@ -69,15 +69,20 @@ class MCI_Footnotes_WYSIWYG {
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
*/ */
public static function ajaxCallback() { public static function ajax_callback() {
// get start and end tag for the footnotes short code // Get start and end tag for the footnotes short code.
$l_str_StartingTag = MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START); $l_str_starting_tag = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START );
$l_str_EndingTag = MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END); $l_str_ending_tag = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END );
if ($l_str_StartingTag == "userdefined" || $l_str_EndingTag == "userdefined") { if ( $l_str_starting_tag == 'userdefined' || $l_str_ending_tag == 'userdefined' ) {
$l_str_StartingTag = MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START_USER_DEFINED); $l_str_starting_tag = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START_USER_DEFINED );
$l_str_EndingTag = MCI_Footnotes_Settings::instance()->get(MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END_USER_DEFINED); $l_str_ending_tag = MCI_Footnotes_Settings::instance()->get( MCI_Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END_USER_DEFINED );
} }
echo json_encode(array("start" => htmlspecialchars($l_str_StartingTag), "end" => htmlspecialchars($l_str_EndingTag))); echo json_encode(
array(
'start' => htmlspecialchars( $l_str_starting_tag ),
'end' => htmlspecialchars( $l_str_ending_tag ),
)
);
exit; exit;
} }
} }

View file

@ -49,16 +49,16 @@ define( 'C_STR_FOOTNOTES_VERSION', '2.5.6d4' );
*/ */
// Get all common classes and functions // Get all common classes and functions
require_once(dirname(__FILE__) . "/includes.php"); require_once( dirname( __FILE__ ) . '/includes.php' );
// add Plugin Links to the "installed plugins" page // add Plugin Links to the "installed plugins" page
$l_str_plugin_file = 'footnotes/footnotes.php'; $l_str_plugin_file = 'footnotes/footnotes.php';
add_filter("plugin_action_links_{$l_str_plugin_file}", array("MCI_Footnotes_Hooks", "PluginLinks"), 10, 2); add_filter( "plugin_action_links_{$l_str_plugin_file}", array( 'MCI_Footnotes_Hooks', 'Plugin_links' ), 10, 2 );
// initialize the Plugin // initialize the Plugin
$g_obj_MCI_Footnotes = new MCI_Footnotes(); $g_obj_mcI_Footnotes = new MCI_Footnotes();
// run the Plugin // run the Plugin
$g_obj_MCI_Footnotes->run(); $g_obj_mcI_Footnotes->run();
/** /**
* Sets the stylesheet enqueuing mode for production. * Sets the stylesheet enqueuing mode for production.

View file

@ -12,26 +12,26 @@
* *
* @author Stefan Herndler * @author Stefan Herndler
* @since 1.5.0 * @since 1.5.0
* @param string $p_str_Directory Absolute Directory path to lookup for *.php files * @param string $p_str_directory Absolute Directory path to lookup for *.php files
*/ */
function MCI_Footnotes_requirePhpFiles($p_str_Directory) { function MCI_Footnotes_require_php_files( $p_str_directory ) {
// append slash at the end of the Directory if not exist // append slash at the end of the Directory if not exist
if (substr($p_str_Directory, -1) != "/") { if ( substr( $p_str_directory, -1 ) != '/' ) {
$p_str_Directory .= "/"; $p_str_directory .= '/';
} }
// get all PHP files inside Directory // get all PHP files inside Directory
$l_arr_Files = scandir($p_str_Directory); $l_arr_files = scandir( $p_str_directory );
// iterate through each class // iterate through each class
foreach ($l_arr_Files as $l_str_FileName) { foreach ( $l_arr_files as $l_str_file_name ) {
// skip all non *.php files // skip all non *.php files
if (strtolower(substr($l_str_FileName, -4)) != ".php") { if ( strtolower( substr( $l_str_file_name, -4 ) ) != '.php' ) {
continue; continue;
} }
/** @noinspection PhpIncludeInspection */ /** @noinspection Php_include_inspection */
require_once($p_str_Directory . $l_str_FileName); require_once( $p_str_directory . $l_str_file_name );
} }
} }
MCI_Footnotes_requirePhpFiles(dirname(__FILE__) . "/class"); MCI_Footnotes_require_php_files( dirname( __FILE__ ) . '/class' );
MCI_Footnotes_requirePhpFiles(dirname(__FILE__) . "/class/dashboard"); MCI_Footnotes_require_php_files( dirname( __FILE__ ) . '/class/dashboard' );
MCI_Footnotes_requirePhpFiles(dirname(__FILE__) . "/class/widgets"); MCI_Footnotes_require_php_files( dirname( __FILE__ ) . '/class/widgets' );