refactor: rename class/
to includes/
This commit is contained in:
parent
cd0c6bc295
commit
84c299a368
14 changed files with 27 additions and 498 deletions
73
src/includes/config.php
Normal file
73
src/includes/config.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
/**
|
||||
* Includes the Plugin Constants class to load all Plugin constant vars like Plugin name, etc.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @since 2.0.4 add Public Plugin name for dashboard heading
|
||||
*/
|
||||
|
||||
/**
|
||||
* Contains all Plugin Constants. Contains no Method or Property.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Config {
|
||||
/**
|
||||
* Internal Plugin name.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_PLUGIN_NAME = 'footnotes';
|
||||
|
||||
/**
|
||||
* Public Plugin name.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*
|
||||
* edited classes for v2.0.4
|
||||
*/
|
||||
const C_STR_PLUGIN_PUBLIC_NAME = '<span class="footnotes_logo footnotes_logo_part1">foot</span><span class="footnotes_logo footnotes_logo_part2">notes</span>';
|
||||
|
||||
/**
|
||||
* Public Plugin name for dashboard heading
|
||||
*
|
||||
* After properly displaying in dashboard headings until WPv5.4, the above started
|
||||
* in WPv5.5 being torn apart as if the headline was text-align:justify and not
|
||||
* the last line. That ugly display bug badly affected the plugin’s communication.
|
||||
* The only working solution found so far is using position:fixed in one heading
|
||||
* that isn’t translated, and dropping the logo in another, translatable heading.
|
||||
*
|
||||
* @since 2.0.4
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_PLUGIN_HEADING_NAME = '<span class="footnotes_logo_heading footnotes_logo_part1_heading">foot</span><span class="footnotes_logo_heading footnotes_logo_part2_heading">notes</span>';
|
||||
|
||||
/**
|
||||
* Html tag for the LOVE symbol.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_LOVE_SYMBOL = '<span style="color:#ff6d3b; font-weight:bold;">♥</span>';
|
||||
|
||||
/**
|
||||
* HTML code for the 'love' symbol used in dashboard heading
|
||||
*
|
||||
* @since 2.0.4
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_LOVE_SYMBOL_HEADING = '<span class="footnotes_heart_heading">♥</span>';
|
||||
|
||||
/**
|
||||
* Short code to DON'T display the 'LOVE ME' slug on certain pages.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_NO_LOVE_SLUG = '[[no footnotes: love]]';
|
||||
}
|
222
src/includes/convert.php
Normal file
222
src/includes/convert.php
Normal file
|
@ -0,0 +1,222 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
/**
|
||||
* Includes the Convert Class.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @since 2.2.0 add lowercase Roman
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts data types and Footnotes specific values.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Convert {
|
||||
|
||||
/**
|
||||
* Converts a integer into the user-defined counter style for the footnotes.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param int $p_int_index Index to be converted.
|
||||
* @param string $p_str_convert_style Style of the new/converted Index.
|
||||
* @return string Converted Index as string in the defined counter style.
|
||||
*
|
||||
* Edited:
|
||||
* @since 2.2.0 lowercase Roman numerals supported
|
||||
*/
|
||||
public static function index( $p_int_index, $p_str_convert_style = 'arabic_plain' ) {
|
||||
switch ( $p_str_convert_style ) {
|
||||
case 'romanic':
|
||||
return self::to_romanic( $p_int_index, true );
|
||||
case 'roman_low':
|
||||
return self::to_romanic( $p_int_index, false );
|
||||
case 'latin_high':
|
||||
return self::to_latin( $p_int_index, true );
|
||||
case 'latin_low':
|
||||
return self::to_latin( $p_int_index, false );
|
||||
case 'arabic_leading':
|
||||
return self::to_arabic_leading( $p_int_index );
|
||||
case 'arabic_plain':
|
||||
default:
|
||||
return $p_int_index;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an integer into latin ascii characters, either lower or upper-case.
|
||||
* Function available from A to ZZ ( means 676 footnotes at 1 page possible).
|
||||
*
|
||||
* @since 1.0-gamma
|
||||
* @param int $p_int_value Value/Index to be converted.
|
||||
* @param bool $p_bool_upper_case True to convert the value to upper case letter, otherwise to lower case.
|
||||
* @return string
|
||||
*/
|
||||
private static function to_latin( $p_int_value, $p_bool_upper_case ) {
|
||||
// Output string.
|
||||
$l_str_return = '';
|
||||
$l_int_offset = 0;
|
||||
// Check if the value is higher then 26 = Z.
|
||||
while ( $p_int_value > 26 ) {
|
||||
// Increase offset and reduce counter.
|
||||
$l_int_offset++;
|
||||
$p_int_value -= 26;
|
||||
}
|
||||
// If offset set (more then Z), then add a new letter in front.
|
||||
if ( $l_int_offset > 0 ) {
|
||||
$l_str_return = chr( $l_int_offset + 64 );
|
||||
}
|
||||
// Add the origin letter.
|
||||
$l_str_return .= chr( $p_int_value + 64 );
|
||||
// Return the latin character representing the integer.
|
||||
if ( $p_bool_upper_case ) {
|
||||
return strtoupper( $l_str_return );
|
||||
}
|
||||
return strtolower( $l_str_return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an integer to a leading-0 integer.
|
||||
*
|
||||
* @since 1.0-gamma
|
||||
* @param int $p_int_value Value/Index to be converted.
|
||||
* @return string Value with a leading zero.
|
||||
*/
|
||||
private static function to_arabic_leading( $p_int_value ) {
|
||||
// Add a leading 0 if number lower then 10.
|
||||
if ( $p_int_value < 10 ) {
|
||||
return '0' . $p_int_value;
|
||||
}
|
||||
return $p_int_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an integer to a romanic letter.
|
||||
*
|
||||
* @since 1.0-gamma
|
||||
* @param int $p_int_value Value/Index to be converted.
|
||||
* @param bool $p_bool_upper_case Whether to uppercase.
|
||||
* @return string
|
||||
*
|
||||
* Edited:
|
||||
* @since 2.2.0 optionally lowercase (code from Latin)
|
||||
*/
|
||||
private static function to_romanic( $p_int_value, $p_bool_upper_case ) {
|
||||
// Table containing all necessary romanic letters.
|
||||
$l_arr_romanic_letters = array(
|
||||
'M' => 1000,
|
||||
'CM' => 900,
|
||||
'D' => 500,
|
||||
'CD' => 400,
|
||||
'C' => 100,
|
||||
'XC' => 90,
|
||||
'L' => 50,
|
||||
'XL' => 40,
|
||||
'X' => 10,
|
||||
'IX' => 9,
|
||||
'V' => 5,
|
||||
'IV' => 4,
|
||||
'I' => 1,
|
||||
);
|
||||
// Return value.
|
||||
$l_str_return = '';
|
||||
// Iterate through integer value until it is reduced to 0.
|
||||
while ( $p_int_value > 0 ) {
|
||||
foreach ( $l_arr_romanic_letters as $l_str_romanic => $l_int_arabic ) {
|
||||
if ( $p_int_value >= $l_int_arabic ) {
|
||||
$p_int_value -= $l_int_arabic;
|
||||
$l_str_return .= $l_str_romanic;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Return romanic letters as string.
|
||||
if ( $p_bool_upper_case ) {
|
||||
return strtoupper( $l_str_return );
|
||||
}
|
||||
return strtolower( $l_str_return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string depending on its value to a boolean.
|
||||
*
|
||||
* @since 1.0-beta
|
||||
* @param string $p_str_value String to be converted to boolean.
|
||||
* @return bool Boolean representing the string.
|
||||
*/
|
||||
public static function to_bool( $p_str_value ) {
|
||||
// Convert string to lower-case to make it easier.
|
||||
$p_str_value = strtolower( $p_str_value );
|
||||
// Check if string seems to contain a "true" value.
|
||||
switch ( $p_str_value ) {
|
||||
case 'checked':
|
||||
case 'yes':
|
||||
case 'true':
|
||||
case 'on':
|
||||
case '1':
|
||||
return true;
|
||||
}
|
||||
// Nothing found that says "true", so we return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a html Array short code depending on Arrow-Array key index.
|
||||
*
|
||||
* @since 1.3.2
|
||||
* @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.
|
||||
*/
|
||||
public static function get_arrow( $p_int_index = -1 ) {
|
||||
// Define all possible arrows.
|
||||
$l_arr_arrows = array( '↑', '↥', '↟', '↩', '↲', '↵', '⇑', '⇡', '⇧', '↑' );
|
||||
// Convert index to an integer.
|
||||
if ( ! is_int( $p_int_index ) ) {
|
||||
$p_int_index = intval( $p_int_index );
|
||||
}
|
||||
// Return the whole arrow array.
|
||||
if ( $p_int_index < 0 || $p_int_index > count( $l_arr_arrows ) ) {
|
||||
return $l_arr_arrows;
|
||||
}
|
||||
// Return a single arrow.
|
||||
return $l_arr_arrows[ $p_int_index ];
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_var_dump
|
||||
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r
|
||||
/**
|
||||
* Displays a Variable.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param mixed $p_mixed_value The variable to display.
|
||||
* @return void
|
||||
*/
|
||||
public static function debug( $p_mixed_value ) {
|
||||
if ( empty( $p_mixed_value ) ) {
|
||||
var_dump( $p_mixed_value );
|
||||
|
||||
} elseif ( is_array( $p_mixed_value ) ) {
|
||||
printf( '<pre>' );
|
||||
print_r( $p_mixed_value );
|
||||
printf( '</pre>' );
|
||||
|
||||
} elseif ( is_object( $p_mixed_value ) ) {
|
||||
printf( '<pre>' );
|
||||
print_r( $p_mixed_value );
|
||||
printf( '</pre>' );
|
||||
|
||||
} elseif ( is_numeric( $p_mixed_value ) || is_int( $p_mixed_value ) ) {
|
||||
var_dump( $p_mixed_value );
|
||||
|
||||
} elseif ( is_date( $p_mixed_value ) ) {
|
||||
var_dump( $p_mixed_value );
|
||||
|
||||
} else {
|
||||
var_dump( $p_mixed_value );
|
||||
}
|
||||
echo '<br/>';
|
||||
}
|
||||
// phpcs:disable
|
||||
}
|
151
src/includes/dashboard/init.php
Normal file
151
src/includes/dashboard/init.php
Normal file
|
@ -0,0 +1,151 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
/**
|
||||
* Includes the Plugin settings menu.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__, 2) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/subpage-main.php';
|
||||
|
||||
/**
|
||||
* Handles the Settings interface of the Plugin.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Layout_Init {
|
||||
|
||||
/**
|
||||
* Slug for the Plugin main menu.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_MAIN_MENU_SLUG = 'footnotes';
|
||||
|
||||
/**
|
||||
* Plugin main menu name.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_MAIN_MENU_TITLE = 'ManFisher';
|
||||
|
||||
/**
|
||||
* Contains the settings layoutEngine
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var array
|
||||
*/
|
||||
private $settings_page;
|
||||
|
||||
/**
|
||||
* Class Constructor. Initializes all WordPress hooks for the Plugin Settings.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->settings_page = new Footnotes_Layout_Settings();
|
||||
|
||||
// Register hooks/actions.
|
||||
add_action( 'admin_menu', array( $this, 'register_options_submenu' ) );
|
||||
add_action( 'admin_init', array( $this, 'initialize_settings' ) );
|
||||
// Register AJAX callbacks for Plugin information.
|
||||
add_action( 'wp_ajax_nopriv_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
|
||||
add_action( 'wp_ajax_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the settings and initialises the settings page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function initialize_settings() {
|
||||
Footnotes_Settings::instance()->register_settings();
|
||||
$this->settings_page->register_sections();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the footnotes submenu page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @see http://codex.wordpress.org/Function_Reference/add_menu_page
|
||||
*/
|
||||
public function register_options_submenu() {
|
||||
add_submenu_page(
|
||||
'options-general.php',
|
||||
'footnotes Settings',
|
||||
self::C_STR_MAIN_MENU_SLUG,
|
||||
'manage_options',
|
||||
'footnotes',
|
||||
array( $this->settings_page, 'display_content' )
|
||||
);
|
||||
$this->settings_page->register_sub_page();
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
/**
|
||||
* AJAX call. returns a JSON string containing meta information about a specific WordPress Plugin.
|
||||
*
|
||||
* @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'] ) ) {
|
||||
$l_str_plugin_name = wp_unslash( $_POST['plugin'] );
|
||||
}
|
||||
|
||||
if ( empty( $l_str_plugin_name ) ) {
|
||||
echo wp_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 wp_json_encode( array( 'error' => 'Error receiving Plugin Information from WordPress.' ) );
|
||||
exit;
|
||||
}
|
||||
if ( ! array_key_exists( 'body', $l_arr_response ) ) {
|
||||
echo wp_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 wp_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 wp_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;
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
}
|
590
src/includes/dashboard/layout.php
Normal file
590
src/includes/dashboard/layout.php
Normal file
|
@ -0,0 +1,590 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* Includes Layout Engine for the admin dashboard.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @since 2.1.2 add versioning of settings.css for cache busting
|
||||
* @since 2.1.4 automate passing version number for cache busting
|
||||
* @since 2.1.4 optional step argument and support for floating in numbox
|
||||
* @since 2.1.6 fix punctuation-related localization issue in dashboard labels
|
||||
*
|
||||
* @since 2.5.5 Bugfix: Stylesheets: minify to shrink the carbon footprint, increase speed and implement best practice, thanks to @docteurfitness issue report.
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__, 2) . '/config.php';
|
||||
require_once dirname( __FILE__, 2) . '/convert.php';
|
||||
require_once dirname( __FILE__, 2) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/init.php';
|
||||
|
||||
/**
|
||||
* Layout Engine for the administration dashboard.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
abstract class Footnotes_Layout_Engine {
|
||||
|
||||
/**
|
||||
* Stores the Hook connection string for the child sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var null|string
|
||||
*/
|
||||
protected $a_str_sub_page_hook = null;
|
||||
|
||||
/**
|
||||
* Stores all Sections for the child sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var array
|
||||
*/
|
||||
protected $a_arr_sections = array();
|
||||
|
||||
/**
|
||||
* Returns a Priority index. Lower numbers have a higher Priority.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return int
|
||||
*/
|
||||
abstract public function get_priority();
|
||||
|
||||
/**
|
||||
* Returns the unique slug of the child sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function get_sub_page_slug();
|
||||
|
||||
/**
|
||||
* Returns the title of the child sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function get_sub_page_title();
|
||||
|
||||
/**
|
||||
* Returns an array of all registered sections for a sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function get_sections();
|
||||
|
||||
/**
|
||||
* Returns an array of all registered meta boxes.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function get_meta_boxes();
|
||||
|
||||
/**
|
||||
* Returns an array describing a sub page section.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_id Unique ID suffix.
|
||||
* @param string $p_str_title Title of the section.
|
||||
* @param int $p_int_settings_container_index Settings Container Index.
|
||||
* @param bool $p_bool_has_submit_button Should a Submit Button be displayed for this section, default: true.
|
||||
* @return array Array describing the section.
|
||||
*/
|
||||
protected function add_section( $p_str_id, $p_str_title, $p_int_settings_container_index, $p_bool_has_submit_button = true ) {
|
||||
return array(
|
||||
'id' => Footnotes_Config::C_STR_PLUGIN_NAME . '-' . $p_str_id,
|
||||
'title' => $p_str_title,
|
||||
'submit' => $p_bool_has_submit_button,
|
||||
'container' => $p_int_settings_container_index,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array describing a meta box.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_section_id Parent Section ID.
|
||||
* @param string $p_str_id Unique ID suffix.
|
||||
* @param string $p_str_title Title for the meta box.
|
||||
* @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.
|
||||
*/
|
||||
protected function add_meta_box( $p_str_section_id, $p_str_id, $p_str_title, $p_str_callback_function_name ) {
|
||||
return array(
|
||||
'parent' => Footnotes_Config::C_STR_PLUGIN_NAME . '-' . $p_str_section_id,
|
||||
'id' => $p_str_id,
|
||||
'title' => $p_str_title,
|
||||
'callback' => $p_str_callback_function_name,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function register_sub_page() {
|
||||
global $submenu;
|
||||
|
||||
if ( array_key_exists( plugin_basename( Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG ), $submenu ) ) {
|
||||
foreach ( $submenu[ plugin_basename( Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG ) ] as $l_arr_sub_menu ) {
|
||||
if ( plugin_basename( Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() ) === $l_arr_sub_menu[2] ) {
|
||||
remove_submenu_page( Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG, Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->a_str_sub_page_hook = add_submenu_page(
|
||||
Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG,
|
||||
$this->get_sub_page_title(),
|
||||
$this->get_sub_page_title(),
|
||||
'manage_options',
|
||||
Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug(),
|
||||
array( $this, 'display_content' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all sections for a sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function register_sections() {
|
||||
foreach ( $this->get_sections() as $l_arr_section ) {
|
||||
// Append tab to the tab-array.
|
||||
$this->a_arr_sections[ $l_arr_section['id'] ] = $l_arr_section;
|
||||
add_settings_section(
|
||||
$l_arr_section['id'],
|
||||
'',
|
||||
array( $this, 'Description' ),
|
||||
$l_arr_section['id']
|
||||
);
|
||||
$this->register_meta_boxes( $l_arr_section['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all Meta boxes for a sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_parent_id Parent section unique id.
|
||||
*/
|
||||
private function register_meta_boxes( $p_str_parent_id ) {
|
||||
// Iterate through each meta box.
|
||||
foreach ( $this->get_meta_boxes() as $l_arr_meta_box ) {
|
||||
if ( $p_str_parent_id !== $l_arr_meta_box['parent'] ) {
|
||||
continue;
|
||||
}
|
||||
add_meta_box(
|
||||
$p_str_parent_id . '-' . $l_arr_meta_box['id'],
|
||||
$l_arr_meta_box['title'],
|
||||
array( $this, $l_arr_meta_box['callback'] ),
|
||||
$p_str_parent_id,
|
||||
'main'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append javascript and css files for specific sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private function append_scripts() {
|
||||
wp_enqueue_script( 'postbox' );
|
||||
wp_enqueue_style( 'wp-color-picker' );
|
||||
wp_enqueue_script( 'wp-color-picker' );
|
||||
|
||||
/**
|
||||
* Registers and enqueues the dashboard stylesheet.
|
||||
*
|
||||
* - Bugfix: Stylesheets: minify to shrink the carbon footprint, increase speed and implement best practice, thanks to @docteurfitness issue report.
|
||||
*
|
||||
* @since 2.5.5
|
||||
*
|
||||
* @reporter @docteurfitness
|
||||
* @link https://wordpress.org/support/topic/simply-speed-optimisation/
|
||||
*
|
||||
* See the public stylesheet enqueuing:
|
||||
* @see class/init.php
|
||||
*
|
||||
* added version # after changes started to settings.css from 2.1.2 on.
|
||||
* automated update of version number for cache busting.
|
||||
* No need to use '-styles' in the handle, as '-css' is appended automatically.
|
||||
*/
|
||||
if ( true === PRODUCTION_ENV ) {
|
||||
|
||||
wp_register_style( 'mci-footnotes-admin', plugins_url( 'footnotes/css/settings.min.css' ), array(), C_STR_FOOTNOTES_VERSION );
|
||||
|
||||
} else {
|
||||
|
||||
wp_register_style( 'mci-footnotes-admin', plugins_url( 'footnotes/css/settings.css' ), array(), C_STR_FOOTNOTES_VERSION );
|
||||
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'mci-footnotes-admin' );
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
|
||||
/**
|
||||
* Displays the content of specific sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function display_content() {
|
||||
$this->append_scripts();
|
||||
|
||||
// TODO: add nonce verification.
|
||||
|
||||
// Get the current section.
|
||||
reset( $this->a_arr_sections );
|
||||
$l_str_active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : key( $this->a_arr_sections );
|
||||
$l_arr_active_section = $this->a_arr_sections[ $l_str_active_section_id ];
|
||||
|
||||
// Store settings.
|
||||
$l_bool_settings_updated = false;
|
||||
if ( array_key_exists( 'save-settings', $_POST ) ) {
|
||||
if ( 'save' === $_POST['save-settings'] ) {
|
||||
unset( $_POST['save-settings'] );
|
||||
unset( $_POST['submit'] );
|
||||
$l_bool_settings_updated = $this->save_settings();
|
||||
}
|
||||
}
|
||||
|
||||
// Display all sections and highlight the active section.
|
||||
echo '<div class="wrap">';
|
||||
echo '<h2 class="nav-tab-wrapper">';
|
||||
// Iterate through all register sections.
|
||||
foreach ( $this->a_arr_sections as $l_str_id => $l_arr_description ) {
|
||||
$l_str_tab_active = ( $l_str_id === $l_arr_active_section['id'] ) ? ' nav-tab-active' : '';
|
||||
echo sprintf(
|
||||
'<a class="nav-tab%s" href="?page=%s&t=%s">%s</a>',
|
||||
( $l_str_id === $l_arr_active_section['id'] ) ? ' nav-tab-active' : '',
|
||||
Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG,
|
||||
$l_str_id,
|
||||
$l_arr_description['title']
|
||||
);
|
||||
}
|
||||
echo '</h2><br/>';
|
||||
|
||||
if ( $l_bool_settings_updated ) {
|
||||
echo sprintf( '<div id="message" class="updated">%s</div>', __( 'Settings saved', 'footnotes' ) );
|
||||
}
|
||||
|
||||
// Form to submit the active section.
|
||||
echo '<!--suppress HtmlUnknownTarget --><form method="post" action="">';
|
||||
echo '<input type="hidden" name="save-settings" value="save" />';
|
||||
// Outputs the settings field of the active section.
|
||||
do_settings_sections( $l_arr_active_section['id'] );
|
||||
do_meta_boxes( $l_arr_active_section['id'], 'main', null );
|
||||
|
||||
// Add submit button to active section if defined.
|
||||
if ( $l_arr_active_section['submit'] ) {
|
||||
submit_button();
|
||||
}
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
|
||||
// Echo JavaScript for the expand/collapse function of the meta boxes.
|
||||
echo '<script type="text/javascript">';
|
||||
echo 'jQuery(document).ready(function ($) {';
|
||||
echo 'jQuery(".footnotes-color-picker").wpColorPicker();';
|
||||
echo "jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');";
|
||||
echo "postboxes.add_postbox_toggles('" . $this->a_str_sub_page_hook . "');";
|
||||
echo '});';
|
||||
echo '</script>';
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
|
||||
/**
|
||||
* Save all Plugin settings.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return bool
|
||||
*/
|
||||
private function save_settings() {
|
||||
$l_arr_new_settings = array();
|
||||
|
||||
// TODO: add nonce verification.
|
||||
|
||||
// Get current section.
|
||||
reset( $this->a_arr_sections );
|
||||
$l_str_active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : key( $this->a_arr_sections );
|
||||
$l_arr_active_section = $this->a_arr_sections[ $l_str_active_section_id ];
|
||||
|
||||
foreach ( Footnotes_Settings::instance()->get_defaults( $l_arr_active_section['container'] ) as $l_str_key => $l_mixed_value ) {
|
||||
if ( array_key_exists( $l_str_key, $_POST ) ) {
|
||||
$l_arr_new_settings[ $l_str_key ] = wp_unslash( $_POST[ $l_str_key ] );
|
||||
} else {
|
||||
// Setting is not defined in the POST array, define it to avoid the Default value.
|
||||
$l_arr_new_settings[ $l_str_key ] = '';
|
||||
}
|
||||
}
|
||||
// Update settings.
|
||||
return Footnotes_Settings::instance()->save_options( $l_arr_active_section['container'], $l_arr_new_settings );
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
|
||||
|
||||
/**
|
||||
* Output the Description of a section. May be overwritten in any section.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function description() {
|
||||
// Default no description will be displayed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads specific setting and returns an array with the keys [id, name, value].
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_setting_key_name Settings Array key name.
|
||||
* @return array Contains Settings ID, Settings Name and Settings Value.
|
||||
*
|
||||
* @since 2.5.11 Remove escapement function.
|
||||
* When refactoring the codebase after 2.5.8, all and every output was escaped.
|
||||
* After noticing that the plugin was broken, all escapement functions were removed.
|
||||
* @link https://github.com/markcheret/footnotes/pull/50/commits/25c3f2f12eb5de1079e9215bf624ec4289b095a5
|
||||
* @link https://github.com/markcheret/footnotes/pull/50#issuecomment-787624123
|
||||
* In that process, this instance of esc_attr() was removed too, so the plugin was
|
||||
* broken again.
|
||||
* @link https://github.com/markcheret/footnotes/pull/50/commits/25c3f2f12eb5de1079e9215bf624ec4289b095a5#diff-a8ed6e859c32a18fc10bbbad3b4dd8ce7f43f2378d29471c7638e314ab30f1bdL349-L354
|
||||
*
|
||||
* @since 2.5.15 To fix it, the data was escaped in add_select_box() instead.
|
||||
* @since 2.6.1 Restore esc_attr() in load_setting().
|
||||
* @see add_select_box()
|
||||
* This is the only instance of esc_|kses|sanitize in the pre-2.5.11 codebase.
|
||||
* Removing this did not fix the quotation mark backslash escapement bug.
|
||||
*/
|
||||
protected function load_setting( $p_str_setting_key_name ) {
|
||||
// Get current section.
|
||||
reset( $this->a_arr_sections );
|
||||
$p_arr_return = array();
|
||||
$p_arr_return['id'] = sprintf( '%s', $p_str_setting_key_name );
|
||||
$p_arr_return['name'] = sprintf( '%s', $p_str_setting_key_name );
|
||||
$p_arr_return['value'] = esc_attr( Footnotes_Settings::instance()->get( $p_str_setting_key_name ) );
|
||||
return $p_arr_return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a line break to start a new line.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
protected function add_newline() {
|
||||
return '<br/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a line break to have a space between two lines.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
protected function add_line_space() {
|
||||
return '<br/><br/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a simple text inside html <span> text.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_text Message to be surrounded with simple html tag (span).
|
||||
* @return string
|
||||
*/
|
||||
protected function add_text( $p_str_text ) {
|
||||
return sprintf( '<span>%s</span>', $p_str_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for an input/select label.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @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.
|
||||
* @return string
|
||||
*/
|
||||
protected function add_label( $p_str_setting_name, $p_str_caption ) {
|
||||
if ( empty( $p_str_caption ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove the colon causing localization issues with French, and with
|
||||
* languages not using punctuation at all, and with languages using other
|
||||
* punctuation marks instead of colon, e.g. Greek using a raised dot.
|
||||
* In French, colon is preceded by a space, forcibly non-breaking, and
|
||||
* narrow per new school.
|
||||
* Add colon to label strings for inclusion in localization. Colon after
|
||||
* label is widely preferred best practice, mandatory per
|
||||
* [style guides](https://softwareengineering.stackexchange.com/questions/234546/colons-in-internationalized-ui).
|
||||
*/
|
||||
return sprintf( '<label for="%s">%s</label>', $p_str_setting_name, $p_str_caption );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for an input [type = text].
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_setting_name Name of the Settings key to pre load the input field.
|
||||
* @param int $p_str_max_length 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_hidden Set the input to be hidden, default false.
|
||||
* @return string
|
||||
*/
|
||||
protected function add_text_box( $p_str_setting_name, $p_str_max_length = 999, $p_bool_readonly = false, $p_bool_hidden = false ) {
|
||||
$l_str_style = '';
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
if ( $p_bool_hidden ) {
|
||||
$l_str_style .= 'display:none;';
|
||||
}
|
||||
return sprintf(
|
||||
'<input type="text" name="%s" id="%s" maxlength="%d" style="%s" value="%s" %s/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$p_str_max_length,
|
||||
$l_str_style,
|
||||
$l_arr_data['value'],
|
||||
$p_bool_readonly ? 'readonly="readonly"' : ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for an input [type = checkbox].
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_setting_name Name of the Settings key to pre load the input field.
|
||||
* @return string
|
||||
*/
|
||||
protected function add_checkbox( $p_str_setting_name ) {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
return sprintf(
|
||||
'<input type="checkbox" name="%s" id="%s" %s/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
Footnotes_Convert::to_bool( $l_arr_data['value'] ) ? 'checked="checked"' : ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for a select box.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* - Bugfix: Dashboard: Referrers and tooltips: Backlink symbol: debug select box by reverting identity check to equality check, thanks to @lolzim bug report.
|
||||
*
|
||||
* @reporter @lolzim
|
||||
*
|
||||
* @since 2.5.13
|
||||
* @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.
|
||||
* @return string
|
||||
*
|
||||
* @since 2.5.15 Bugfix: Dashboard: General settings: Footnote start and end short codes: debug select box for shortcodes with pointy brackets.
|
||||
* @since 2.6.1 Restore esc_attr() in load_setting(), remove htmlspecialchars() here.
|
||||
*/
|
||||
protected function add_select_box( $p_str_setting_name, $p_arr_options ) {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
$l_str_options = '';
|
||||
|
||||
// Loop through all array keys.
|
||||
foreach ( $p_arr_options as $l_str_value => $l_str_caption ) {
|
||||
$l_str_options .= sprintf(
|
||||
'<option value="%s" %s>%s</option>',
|
||||
$l_str_value,
|
||||
// Only check for equality, not identity, WRT backlink symbol arrows.
|
||||
$l_str_value == $l_arr_data['value'] ? 'selected' : '',
|
||||
$l_str_caption
|
||||
);
|
||||
}
|
||||
return sprintf(
|
||||
'<select name="%s" id="%s">%s</select>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_str_options
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for a text area.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_setting_name Name of the Settings key to pre fill the text area.
|
||||
* @return string
|
||||
*/
|
||||
protected function add_textarea( $p_str_setting_name ) {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
return sprintf(
|
||||
'<textarea name="%s" id="%s">%s</textarea>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_arr_data['value']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for an input [type = text] with color selection class.
|
||||
*
|
||||
* @since 1.5.6
|
||||
* @param string $p_str_setting_name Name of the Settings key to pre load the input field.
|
||||
* @return string
|
||||
*/
|
||||
protected function add_color_selection( $p_str_setting_name ) {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
return sprintf(
|
||||
'<input type="text" name="%s" id="%s" class="footnotes-color-picker" value="%s"/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_arr_data['value']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for an input [type = num].
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @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_int_max Maximum value.
|
||||
* @param bool $p_bool_deci true if 0.1 steps and floating to string, false if integer (default).
|
||||
* @return string
|
||||
*
|
||||
* Edited:
|
||||
* @since 2.1.4 step argument and number_format() to allow decimals ..
|
||||
*/
|
||||
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.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
|
||||
if ( $p_bool_deci ) {
|
||||
$l_str_value = number_format( floatval( $l_arr_data['value'] ), 1 );
|
||||
return sprintf(
|
||||
'<input type="number" name="%s" id="%s" value="%s" step="0.1" min="%d" max="%d"/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_str_value,
|
||||
$p_in_min,
|
||||
$p_int_max
|
||||
);
|
||||
} else {
|
||||
return sprintf(
|
||||
'<input type="number" name="%s" id="%s" value="%d" min="%d" max="%d"/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_arr_data['value'],
|
||||
$p_in_min,
|
||||
$p_int_max
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
1406
src/includes/dashboard/subpage-main.php
Normal file
1406
src/includes/dashboard/subpage-main.php
Normal file
File diff suppressed because it is too large
Load diff
67
src/includes/hooks.php
Normal file
67
src/includes/hooks.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* Footnotes_Hooks class
|
||||
*
|
||||
* @package footnotes
|
||||
* @subpackage WPDashboard
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers all WordPress hooks and executes them on demand.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Hooks {
|
||||
|
||||
/**
|
||||
* Registers all WordPress hooks.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function register_hooks() {
|
||||
register_activation_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'Footnotes_Hooks', 'activate_plugin' ) );
|
||||
register_deactivation_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'Footnotes_Hooks', 'deactivate_plugin' ) );
|
||||
register_uninstall_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'Footnotes_Hooks', 'uninstall_plugin' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes when the Plugin is activated.
|
||||
*
|
||||
* Currently a no-op placeholder.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function activate_plugin() {
|
||||
// Currently unused.
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes when the Plugin is deactivated.
|
||||
*
|
||||
* Currently a no-op placeholder.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function deactivate_plugin() {
|
||||
// Currently unused.
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the Plugin links for display in the dashboard “Plugins” page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param array $plugin_links The WP-default set of links to display.
|
||||
* @return string[] The full set of links to display.
|
||||
*/
|
||||
public static function get_plugin_links( array $plugin_links ): array {
|
||||
// Append link to the WordPress Plugin page.
|
||||
$plugin_links[] = sprintf( '<a href="https://wordpress.org/support/plugin/footnotes" target="_blank">%s</a>', __( 'Support', 'footnotes' ) );
|
||||
// Append link to the settings page.
|
||||
$plugin_links[] = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=footnotes' ), __( 'Settings', 'footnotes' ) );
|
||||
// Append link to the PayPal donate function.
|
||||
$plugin_links[] = sprintf( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6Z6CZDW8PPBBJ" target="_blank">%s</a>', __( 'Donate', 'footnotes' ) );
|
||||
// Return new links.
|
||||
return $plugin_links;
|
||||
}
|
||||
}
|
99
src/includes/language.php
Normal file
99
src/includes/language.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
/**
|
||||
* Loads text domain of current or default language for localization.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @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.1.6 Bugfix: Localization: conform to WordPress plugin language file name scheme, thanks to @nikelaos bug report.
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__ ) . '/config.php';
|
||||
|
||||
/**
|
||||
* Loads text domain of current or default language for localization.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Language {
|
||||
|
||||
/**
|
||||
* Register WordPress Hook.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function register_hooks() {
|
||||
add_action( 'plugins_loaded', array( 'Footnotes_Language', 'load_text_domain' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the text domain for current WordPress language if exists.
|
||||
* Otherwise fallback "en_GB" will be loaded.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
*
|
||||
* - Bugfix: 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
|
||||
*
|
||||
* @contributor @matkus2
|
||||
* @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.
|
||||
* “Fatal error: Uncaught ArgumentCountError: Too few arguments to function apply_filters()”
|
||||
*
|
||||
* 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.
|
||||
* @link https://developer.wordpress.org/reference/functions/apply_filters/
|
||||
*
|
||||
* But apply_filters() is defined with a 3rd parameter (and w/o the first one) in
|
||||
* wp-includes/class-wp-hook.php:264, as public function apply_filters( $value, $args ).
|
||||
*
|
||||
* Taking it all together, probably the full function definition would be
|
||||
* public function apply_filters( $tag, $value, $args ).
|
||||
* In the case of get_locale(), $args is empty.
|
||||
*
|
||||
* The bug was lurking in WP. PHP 7.1 promoted the warning to an error.
|
||||
* @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
|
||||
*/
|
||||
public static function load_text_domain() {
|
||||
|
||||
// If language file with localization exists.
|
||||
if ( self::load( apply_filters( 'plugin_locale', get_locale(), '' ) ) ) {
|
||||
return;
|
||||
}
|
||||
// Else fall back to British English.
|
||||
self::load( 'en_GB' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific text domain.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @param string $p_str_language_code Language Code to load a specific text domain.
|
||||
* @return bool
|
||||
*
|
||||
*
|
||||
* - Bugfix: Localization: conform to WordPress plugin language file name scheme, thanks to @nikelaos bug report.
|
||||
*
|
||||
* @since 2.1.6
|
||||
*
|
||||
* @reporter @nikelaos
|
||||
* @link https://wordpress.org/support/topic/more-feature-ideas/
|
||||
*
|
||||
* That is done by using load_plugin_textdomain().
|
||||
* “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
|
||||
*/
|
||||
private static function load( $p_str_language_code ) {
|
||||
return load_plugin_textdomain(
|
||||
Footnotes_Config::C_STR_PLUGIN_NAME,
|
||||
false,
|
||||
Footnotes_Config::C_STR_PLUGIN_NAME . '/languages'
|
||||
);
|
||||
}
|
||||
}
|
1593
src/includes/settings.php
Normal file
1593
src/includes/settings.php
Normal file
File diff suppressed because it is too large
Load diff
2878
src/includes/task.php
Normal file
2878
src/includes/task.php
Normal file
File diff suppressed because it is too large
Load diff
233
src/includes/template.php
Normal file
233
src/includes/template.php
Normal file
|
@ -0,0 +1,233 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
/**
|
||||
* Includes the Template Engine to load and handle all Template files of the Plugin.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @since 2.2.6 Adding: Templates: support for custom templates in sibling folder, thanks to @misfist issue report.
|
||||
* @since 2.5.0 Adding: Templates: Enable template location stack, thanks to @misfist issue report and code contribution.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles each Template file for the Plugin Frontend (e.g. Settings Dashboard, Public pages, ...).
|
||||
* Loads a template file, replaces all Placeholders and returns the replaced file content.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Template {
|
||||
|
||||
/**
|
||||
* Directory name for dashboard partials.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_DASHBOARD = 'admin/partials';
|
||||
|
||||
/**
|
||||
* Directory name for public partials.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_PUBLIC = 'public/partials';
|
||||
|
||||
/**
|
||||
* Contains the content of the template after initialize.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
private $a_str_original_content = '';
|
||||
|
||||
/**
|
||||
* Contains the content of the template after initialize with replaced place holders.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
private $a_str_replaced_content = '';
|
||||
|
||||
/**
|
||||
* Plugin Directory
|
||||
*
|
||||
* @since 2.4.0d3
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $plugin_directory;
|
||||
|
||||
/**
|
||||
* Class Constructor. Reads and loads the template file without replace any placeholder.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_file_type Template file type (take a look on the Class constants).
|
||||
* @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).
|
||||
*
|
||||
* - Adding: Templates: support for custom templates in sibling folder, thanks to @misfist issue report.
|
||||
*
|
||||
* @since 2.2.6
|
||||
*
|
||||
* @reporter @misfist
|
||||
* @link https://wordpress.org/support/topic/template-override-filter/
|
||||
*/
|
||||
public function __construct( $p_str_file_type, $p_str_file_name, $p_str_extension = 'html' ) {
|
||||
// No template file type and/or file name set.
|
||||
if ( empty( $p_str_file_type ) || empty( $p_str_file_name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define plugin root path.
|
||||
*
|
||||
* @since 2.4.0d3
|
||||
*/
|
||||
$this->plugin_directory = plugin_dir_path( dirname( __FILE__ ) );
|
||||
|
||||
/**
|
||||
* Modularize functions.
|
||||
*
|
||||
* @since 2.4.0d3
|
||||
*/
|
||||
$template = $this->get_template( $p_str_file_type, $p_str_file_name, $p_str_extension );
|
||||
if ( $template ) {
|
||||
$this->process_template( $template );
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all placeholders specified in array.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param array $p_arr_placeholders Placeholders (key = placeholder, value = value).
|
||||
* @return bool True on Success, False if Placeholders invalid.
|
||||
*/
|
||||
public function replace( $p_arr_placeholders ) {
|
||||
// No placeholders set.
|
||||
if ( empty( $p_arr_placeholders ) ) {
|
||||
return false;
|
||||
}
|
||||
// Template content is empty.
|
||||
if ( empty( $this->a_str_replaced_content ) ) {
|
||||
return false;
|
||||
}
|
||||
// Iterate through each placeholder and replace it with its value.
|
||||
foreach ( $p_arr_placeholders as $l_str_placeholder => $l_str_value ) {
|
||||
$this->a_str_replaced_content = str_replace( '[[' . $l_str_placeholder . ']]', $l_str_value, $this->a_str_replaced_content );
|
||||
}
|
||||
// Success.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the original content of the template file.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function reload() {
|
||||
$this->a_str_replaced_content = $this->a_str_original_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of the template file with replaced placeholders.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string Template content with replaced placeholders.
|
||||
*/
|
||||
public function get_content() {
|
||||
return $this->a_str_replaced_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process template file.
|
||||
*
|
||||
* @since 2.4.0d3
|
||||
*
|
||||
* @param string $template The template to be processed.
|
||||
* @return void
|
||||
*
|
||||
* @since 2.0.3 Replace tab with a space.
|
||||
* @since 2.0.3 Replace 2 spaces with 1.
|
||||
* @since 2.0.4 Collapse multiple spaces.
|
||||
* @since 2.2.6 Delete a space before a closing pointy bracket.
|
||||
* @since 2.5.4 Collapse HTML comments and PHP/JS docblocks (only).
|
||||
*/
|
||||
public function process_template( $template ) {
|
||||
// phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
|
||||
$this->a_str_original_content = preg_replace( '#<!--.+?-->#s', '', file_get_contents( $template ) );
|
||||
// phpcs:enable
|
||||
$this->a_str_original_content = preg_replace( '#/\*\*.+?\*/#s', '', $this->a_str_original_content );
|
||||
$this->a_str_original_content = str_replace( "\n", '', $this->a_str_original_content );
|
||||
$this->a_str_original_content = str_replace( "\r", '', $this->a_str_original_content );
|
||||
$this->a_str_original_content = str_replace( "\t", ' ', $this->a_str_original_content );
|
||||
$this->a_str_original_content = preg_replace( '# +#', ' ', $this->a_str_original_content );
|
||||
$this->a_str_original_content = str_replace( ' >', '>', $this->a_str_original_content );
|
||||
$this->reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the template.
|
||||
*
|
||||
* - Adding: Templates: Enable template location stack, thanks to @misfist issue report and code contribution.
|
||||
*
|
||||
* @since 2.4.0d3 Contribution.
|
||||
* @since 2.5.0 Release.
|
||||
*
|
||||
* @contributor @misfist
|
||||
* @link https://wordpress.org/support/topic/template-override-filter/#post-13864301
|
||||
*
|
||||
* @param string $p_str_file_type The file type of the template.
|
||||
* @param string $p_str_file_name The file name of the template.
|
||||
* @param string $p_str_extension The file extension of the template.
|
||||
* @return mixed false | template path
|
||||
*/
|
||||
public function get_template( $p_str_file_type, $p_str_file_name, $p_str_extension = 'html' ) {
|
||||
$located = false;
|
||||
|
||||
/**
|
||||
* The directory can be changed.
|
||||
*
|
||||
* @usage to change location of templates to 'template_parts/footnotes/':
|
||||
* add_filter( 'mci_footnotes_template_directory', function( $directory ) {
|
||||
* return 'template_parts/footnotes/';
|
||||
* } );
|
||||
*/
|
||||
$template_directory = apply_filters( 'footnotes_template_directory', 'footnotes/' );
|
||||
$custom_directory = apply_filters( 'footnotes_custom_template_directory', 'footnotes-custom/' );
|
||||
$template_name = $p_str_file_type . '/' . $p_str_file_name . '.' . $p_str_extension;
|
||||
|
||||
/**
|
||||
* Look in active theme.
|
||||
*/
|
||||
if ( file_exists( trailingslashit( get_stylesheet_directory() ) . $template_directory . $template_name ) ) {
|
||||
$located = trailingslashit( get_stylesheet_directory() ) . $template_directory . $template_name;
|
||||
|
||||
/**
|
||||
* Look in parent theme in case active is child.
|
||||
*/
|
||||
} elseif ( file_exists( trailingslashit( get_template_directory() ) . $template_directory . $template_name ) ) {
|
||||
$located = trailingslashit( get_template_directory() ) . $template_directory . $template_name;
|
||||
|
||||
/**
|
||||
* Look in custom plugin directory.
|
||||
*/
|
||||
} elseif ( file_exists( trailingslashit( WP_PLUGIN_DIR ) . $custom_directory . 'templates/' . $template_name ) ) {
|
||||
$located = trailingslashit( WP_PLUGIN_DIR ) . $custom_directory . 'templates/' . $template_name;
|
||||
|
||||
/**
|
||||
* Fall back to the templates shipped with the plugin.
|
||||
*/
|
||||
} elseif ( file_exists( $this->plugin_directory . $template_name ) ) {
|
||||
$located = $this->plugin_directory . $template_name;
|
||||
}
|
||||
|
||||
return $located;
|
||||
}
|
||||
|
||||
}
|
86
src/includes/widgets/base.php
Normal file
86
src/includes/widgets/base.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
/**
|
||||
* Widget base.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @since 1.6.4 Update: replace deprecated function WP_Widget() with recommended __construct(), thanks to @dartiss code contribution.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base Class for all Plugin Widgets. Registers each Widget to WordPress.
|
||||
* The following Methods MUST be overwritten in each sub class:
|
||||
* **public function widget($args, $instance)** -> echo the Widget Content
|
||||
* **public function form($instance)** -> echo the Settings of the Widget
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
*/
|
||||
abstract class Footnotes_Widget_Base extends WP_Widget {
|
||||
|
||||
/**
|
||||
* Returns an unique ID as string used for the Widget Base ID.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function get_id();
|
||||
|
||||
/**
|
||||
* Returns the Public name of child Widget to be displayed in the Configuration page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function get_name();
|
||||
|
||||
/**
|
||||
* Returns the Description of the child widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function get_description();
|
||||
|
||||
/**
|
||||
* Returns the width of the Widget. Default width is 250 pixel.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return int
|
||||
*/
|
||||
protected function get_widget_width() {
|
||||
return 250;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Constructor. Registers the child Widget to WordPress.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* - Update: replace deprecated function WP_Widget() with recommended __construct(), thanks to @dartiss code contribution.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @contributor @dartiss
|
||||
* @link https://plugins.trac.wordpress.org/browser/footnotes/trunk/class/widgets/base.php?rev=1445720
|
||||
* “The called constructor method for WP_Widget in Footnotes_Widget_ReferenceContainer is deprecated since version 4.3.0! Use __construct() instead.”
|
||||
*/
|
||||
public function __construct() {
|
||||
$l_arr_widget_options = array(
|
||||
'classname' => __CLASS__,
|
||||
'description' => $this->get_description(),
|
||||
);
|
||||
$l_arr_control_options = array(
|
||||
'id_base' => strtolower( $this->get_id() ),
|
||||
'width' => $this->get_widget_width(),
|
||||
);
|
||||
// Registers the Widget.
|
||||
parent::__construct(
|
||||
strtolower( $this->get_id() ), // Unique ID for the widget, has to be lowercase.
|
||||
$this->get_name(), // Plugin name to be displayed.
|
||||
$l_arr_widget_options, // Optional Widget Options.
|
||||
$l_arr_control_options // Optional Widget Control Options.
|
||||
);
|
||||
}
|
||||
}
|
82
src/includes/widgets/reference-container.php
Normal file
82
src/includes/widgets/reference-container.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* Includes the Plugin Widget to put the Reference Container to the Widget area.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__, 2 ) . '/config.php';
|
||||
require_once dirname( __FILE__, 2 ) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/base.php';
|
||||
|
||||
/**
|
||||
* Registers a Widget to put the Reference Container to the widget area.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Widget_Reference_Container extends Footnotes_Widget_Base {
|
||||
|
||||
/**
|
||||
* Returns an unique ID as string used for the Widget Base ID.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
protected function get_id() {
|
||||
return 'footnotes_widget';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Public name of the Widget to be displayed in the Configuration page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
protected function get_name() {
|
||||
return Footnotes_Config::C_STR_PLUGIN_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Description of the child widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*
|
||||
* Edit: curly quotes 2.2.0
|
||||
*/
|
||||
protected function get_description() {
|
||||
return __( 'The widget defines the position of the reference container if set to “widget area”.', 'footnotes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the Settings of the Widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param mixed $instance The instance of the widget.
|
||||
* @return void
|
||||
*
|
||||
* Edit: curly quotes 2.2.0
|
||||
*/
|
||||
public function form( $instance ) {
|
||||
echo __( 'The widget defines the position of the reference container if set to “widget area”.', 'footnotes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the Content of the Widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param mixed $args The widget's arguments.
|
||||
* @param mixed $instance The instance of the widget.
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
global $footnotes;
|
||||
// Reference container positioning is set to "widget area".
|
||||
if ( 'widget' === Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_REFERENCE_CONTAINER_POSITION ) ) {
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $footnotes->a_obj_task->reference_container();
|
||||
// phpcs:enable
|
||||
}
|
||||
}
|
||||
}
|
107
src/includes/wysiwyg.php
Normal file
107
src/includes/wysiwyg.php
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
/**
|
||||
* Includes the Class to handle the WYSIWYG-Buttons.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__ ) . '/config.php';
|
||||
require_once dirname( __FILE__ ) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/template.php';
|
||||
|
||||
/**
|
||||
* Handles the WSYIWYG-Buttons.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_WYSIWYG {
|
||||
|
||||
/**
|
||||
* Registers Button hooks.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* - Bugfix: Editor buttons: debug button by reverting name change in PHP file while JS file and HTML template remained unsynced, thanks to @gova bug report.
|
||||
*
|
||||
* @reporter @gova
|
||||
* @link https://wordpress.org/support/topic/back-end-footnotes-not-working-400-bad-erro/
|
||||
*
|
||||
* @since 2.6.5
|
||||
* @return void
|
||||
*/
|
||||
public static function register_hooks() {
|
||||
add_filter( 'mce_buttons', array( 'Footnotes_WYSIWYG', 'new_visual_editor_button' ) );
|
||||
add_action( 'admin_print_footer_scripts', array( 'Footnotes_WYSIWYG', 'new_plain_text_editor_button' ) );
|
||||
|
||||
add_filter( 'mce_external_plugins', array( 'Footnotes_WYSIWYG', 'include_scripts' ) );
|
||||
|
||||
// phpcs:disable
|
||||
// 'footnotes_getTags' must match its instance in wysiwyg-editor.js.
|
||||
// 'footnotes_getTags' must match its instance in editor-button.html.
|
||||
add_action( 'wp_ajax_nopriv_footnotes_getTags', array( 'Footnotes_WYSIWYG', 'ajax_callback' ) );
|
||||
add_action( 'wp_ajax_footnotes_getTags', array( 'Footnotes_WYSIWYG', 'ajax_callback' ) );
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append a new Button to the WYSIWYG editor of Posts and Pages.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param array $p_arr_buttons pre defined Buttons from WordPress.
|
||||
* @return array
|
||||
*/
|
||||
public static function new_visual_editor_button( $p_arr_buttons ) {
|
||||
array_push( $p_arr_buttons, Footnotes_Config::C_STR_PLUGIN_NAME );
|
||||
return $p_arr_buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new button to the plain text editor.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function new_plain_text_editor_button() {
|
||||
$l_obj_template = new Footnotes_Template( Footnotes_Template::C_STR_DASHBOARD, 'editor-button' );
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $l_obj_template->get_content();
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes the Plugins WYSIWYG editor script.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param array $p_arr_plugins Scripts to be included to the editor.
|
||||
* @return array
|
||||
*/
|
||||
public static function include_scripts( $p_arr_plugins ) {
|
||||
$p_arr_plugins[ Footnotes_Config::C_STR_PLUGIN_NAME ] = plugins_url( '/../admin/js/wysiwyg-editor' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js', __FILE__ );
|
||||
return $p_arr_plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX Callback function when the Footnotes Button is clicked. Either in the Plain text or Visual editor.
|
||||
* Returns an JSON encoded array with the Footnotes start and end short code.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function ajax_callback() {
|
||||
// Get start and end tag for the footnotes short code.
|
||||
$l_str_starting_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START );
|
||||
$l_str_ending_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END );
|
||||
if ( 'userdefined' === $l_str_starting_tag || 'userdefined' === $l_str_ending_tag ) {
|
||||
$l_str_starting_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START_USER_DEFINED );
|
||||
$l_str_ending_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END_USER_DEFINED );
|
||||
}
|
||||
echo json_encode(
|
||||
array(
|
||||
'start' => htmlspecialchars( $l_str_starting_tag ),
|
||||
'end' => htmlspecialchars( $l_str_ending_tag ),
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
}
|
Reference in a new issue