Merge pull request #106 from markcheret/relocate-plugin

refactor: relocate Plugin settings
This commit is contained in:
Mark Cheret 2021-04-16 23:54:51 +02:00 committed by GitHub
commit e06535852b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 23 additions and 2613 deletions

View file

@ -20,7 +20,7 @@ class MCI_Footnotes_Layout_Init {
* @since 1.5.0
* @var string
*/
const C_STR_MAIN_MENU_SLUG = 'mfmmf';
const C_STR_MAIN_MENU_SLUG = 'footnotes';
/**
* Plugin main menu name.
@ -31,12 +31,12 @@ class MCI_Footnotes_Layout_Init {
const C_STR_MAIN_MENU_TITLE = 'ManFisher';
/**
* Contains layout engine sub classes.
* Contains the settings layoutEngine
*
* @since 1.5.0
* @var array
*/
private $a_arr_sub_page_classes = array();
private $settings_page;
/**
* Class Constructor. Initializes all WordPress hooks for the Plugin Settings.
@ -44,100 +44,42 @@ class MCI_Footnotes_Layout_Init {
* @since 1.5.0
*/
public function __construct() {
foreach ( get_declared_classes() as $l_str_class_name ) {
if ( is_subclass_of( $l_str_class_name, 'MCI_Footnotes_Layout_Engine' ) ) {
$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->get_priority() ] = $l_obj_class;
}
}
ksort( $this->a_arr_sub_page_classes );
$this->settings_page = new MCI_Footnotes_Layout_Settings();
// Register hooks/actions.
add_action( 'admin_menu', array( $this, 'register_options_submenu' ) );
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_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
add_action( 'wp_ajax_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
}
/**
* Initializes all sub pages and registers the settings.
* Registers the settings and initialises the settings page.
*
* @since 1.5.0
*/
public function initialize_settings() {
MCI_Footnotes_Settings::instance()->register_settings();
// 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->register_sections();
}
$this->settings_page->register_sections();
}
/**
* Registers the new main menu for the WordPress dashboard.
* Registers all sub menu pages for the new main menu.
* Registers the footnotes submenu page.
*
* @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 ) {
// 3terate 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.
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->register_sub_pages();
}
/**
* Registers all SubPages for this Plugin.
*
* @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.
*
* @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' );
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
echo $l_obj_template->get_content();
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
printf( '<em>visit <a href="https://cheret.org/footnotes/" target="_blank">Mark Cheret</a></em>' );
printf( '<br/><br/>' );
printf( '</div>' );
$this->settings_page->register_sub_page();
}
// phpcs:disable WordPress.Security.NonceVerification.Missing

View file

@ -257,7 +257,7 @@ abstract class MCI_Footnotes_Layout_Engine {
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' : '',
MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug(),
MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG,
$l_str_id,
$l_arr_description['title']
);
@ -285,7 +285,7 @@ abstract class MCI_Footnotes_Layout_Engine {
// Echo JavaScript for the expand/collapse function of the meta boxes.
echo '<script type="text/javascript">';
echo 'jQuery(document).ready(function ($) {';
echo 'jQuery(".mfmmf-color-picker").wpColorPicker();';
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 '});';
@ -536,7 +536,7 @@ abstract class MCI_Footnotes_Layout_Engine {
// 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="mfmmf-color-picker" value="%s"/>',
'<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']

View file

@ -1,146 +0,0 @@
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.EscapeOutput.OutputNotEscaped
/**
* Includes the Plugin Class to display Diagnostics.
*
* @filesource
* @package footnotes
* @since 1.5.0
*/
/**
* Displays Diagnostics of the web server, PHP and WordPress.
*
* @since 1.5.0
*/
class MCI_Footnotes_Layout_Diagnostics extends MCI_Footnotes_Layout_Engine {
/**
* Returns a Priority index. Lower numbers have a higher Priority.
*
* @since 1.5.0
* @return int
*/
public function get_priority() {
return 999;
}
/**
* Returns the unique slug of the sub page.
*
* @since 1.5.0
* @return string
*/
protected function get_sub_page_slug() {
return '-diagnostics';
}
/**
* Returns the title of the sub page.
*
* @since 1.5.0
* @return string
*/
protected function get_sub_page_title() {
return __( 'Diagnostics', 'footnotes' );
}
/**
* Returns an array of all registered sections for the sub page.
*
* @since 1.5.0
* @return array
*/
protected function get_sections() {
return array(
$this->add_section( 'diagnostics', __( 'Diagnostics', 'footnotes' ), null, false ),
);
}
/**
* Returns an array of all registered meta boxes for each section of the sub page.
*
* @since 1.5.0
* @return array
*/
protected function get_meta_boxes() {
return array(
$this->add_meta_box( 'diagnostics', 'diagnostics', __( 'Displays information about the web server, PHP and WordPress', 'footnotes' ), 'Diagnostics' ),
);
}
/**
* Displays a diagnostics about the web server, php and WordPress.
*
* @since 1.5.0
*/
public function Diagnostics() {
global $wp_version;
$l_str_php_extensions = '';
// Iterate through each PHP extension.
foreach ( get_loaded_extensions() as $l_int_index => $l_str_extension ) {
if ( $l_int_index > 0 ) {
$l_str_php_extensions .= ' | ';
}
$l_str_php_extensions .= $l_str_extension . ' ' . phpversion( $l_str_extension );
}
$l_obj_current_theme = wp_get_theme();
$l_str_wordpress_plugins = '';
// Iterate through each installed WordPress Plugin.
foreach ( get_plugins() as $l_arr_plugin ) {
$l_str_wordpress_plugins .= '<tr>';
$l_str_wordpress_plugins .= '<td>' . $l_arr_plugin['Name'] . '</td>';
// phpcs:disable Generic.Strings.UnnecessaryStringConcat.Found
$l_str_wordpress_plugins .= '<td>' . $l_arr_plugin['Version'] . ' [' . $l_arr_plugin['PluginURI'] . ']' . '</td>';
// phpcs:enable Generic.Strings.UnnecessaryStringConcat.Found
$l_str_wordpress_plugins .= '</tr>';
}
// Load template file.
$l_obj_template = new MCI_Footnotes_Template( MCI_Footnotes_Template::C_STR_DASHBOARD, 'diagnostics' );
if ( ! isset( $_SERVER['SERVER_NAME'] ) ) {
die;
} else {
$l_str_server_name = wp_unslash( $_SERVER['SERVER_NAME'] );
}
if ( ! isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
die;
} else {
$l_str_http_user_agent = wp_unslash( $_SERVER['HTTP_USER_AGENT'] );
}
// Replace all placeholders.
$l_obj_template->replace(
array(
'label-server' => __( 'Server name', 'footnotes' ),
'server' => $l_str_server_name,
'label-php' => __( 'PHP version', 'footnotes' ),
'php' => phpversion(),
'label-user-agent' => __( 'User agent', 'footnotes' ),
'user-agent' => $l_str_http_user_agent,
'label-max-execution-time' => __( 'Max execution time', 'footnotes' ),
'max-execution-time' => ini_get( 'max_execution_time' ) . ' ' . __( 'seconds', 'footnotes' ),
'label-memory-limit' => __( 'Memory limit', 'footnotes' ),
'memory-limit' => ini_get( 'memory_limit' ),
'label-php-extensions' => __( 'PHP extensions', 'footnotes' ),
'php-extensions' => $l_str_php_extensions,
'label-wordpress' => __( 'WordPress version', 'footnotes' ),
'wordpress' => $wp_version,
'label-theme' => __( 'Active Theme', 'footnotes' ),
'theme' => $l_obj_current_theme->get( 'Name' ) . ' ' . $l_obj_current_theme->get( 'Version' ) . ', ' . $l_obj_current_theme->get( 'Author' ) . ' [' . $l_obj_current_theme->get( 'AuthorURI' ) . ']',
'plugins' => $l_str_wordpress_plugins,
)
);
// Display template with replaced placeholders.
echo $l_obj_template->get_content();
}
}

View file

@ -75,7 +75,7 @@ class MCI_Footnotes_Hooks {
// Append link to the WordPress Plugin page.
$p_arr_links[] = sprintf( '<a href="https://wordpress.org/support/plugin/footnotes" target="_blank">%s</a>', __( 'Support', 'footnotes' ) );
// Append link to the settings page.
$p_arr_links[] = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=mfmmf-footnotes' ), __( 'Settings', 'footnotes' ) );
$p_arr_links[] = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=footnotes' ), __( 'Settings', 'footnotes' ) );
// Append link to the PayPal 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', 'footnotes' ) );
// Return new links.

View file

@ -1,585 +0,0 @@
<?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.
*/
/**
* Layout Engine for the administration dashboard.
*
* @since 1.5.0
*/
abstract class MCI_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' => MCI_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' => MCI_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( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG ), $submenu ) ) {
foreach ( $submenu[ plugin_basename( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG ) ] as $l_arr_sub_menu ) {
if ( plugin_basename( MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() ) === $l_arr_sub_menu[2] ) {
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_sub_page_hook = add_submenu_page(
MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG,
$this->get_sub_page_title(),
$this->get_sub_page_title(),
'manage_options',
MCI_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.
*/
wp_register_style(
'mci-footnotes-admin',
plugins_url( 'footnotes/css/settings' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.css' ),
array(),
( PRODUCTION_ENV ) ? C_STR_PACKAGE_VERSION : filemtime(
plugin_dir_path(
dirname( __FILE__, 2 )
) . 'css/settings' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.css'
)
);
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' : '',
MCI_Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_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(".mfmmf-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 ( MCI_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 MCI_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'] = MCI_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'],
MCI_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="mfmmf-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
*
* @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
);
}
}
}

View file

@ -1,146 +0,0 @@
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.EscapeOutput.OutputNotEscaped
/**
* Includes the Plugin Class to display Diagnostics.
*
* @filesource
* @package footnotes
* @since 1.5.0
*/
/**
* Displays Diagnostics of the web server, PHP and WordPress.
*
* @since 1.5.0
*/
class MCI_Footnotes_Layout_Diagnostics extends MCI_Footnotes_Layout_Engine {
/**
* Returns a Priority index. Lower numbers have a higher Priority.
*
* @since 1.5.0
* @return int
*/
public function get_priority() {
return 999;
}
/**
* Returns the unique slug of the sub page.
*
* @since 1.5.0
* @return string
*/
protected function get_sub_page_slug() {
return '-diagnostics';
}
/**
* Returns the title of the sub page.
*
* @since 1.5.0
* @return string
*/
protected function get_sub_page_title() {
return __( 'Diagnostics', 'footnotes' );
}
/**
* Returns an array of all registered sections for the sub page.
*
* @since 1.5.0
* @return array
*/
protected function get_sections() {
return array(
$this->add_section( 'diagnostics', __( 'Diagnostics', 'footnotes' ), null, false ),
);
}
/**
* Returns an array of all registered meta boxes for each section of the sub page.
*
* @since 1.5.0
* @return array
*/
protected function get_meta_boxes() {
return array(
$this->add_meta_box( 'diagnostics', 'diagnostics', __( 'Displays information about the web server, PHP and WordPress', 'footnotes' ), 'Diagnostics' ),
);
}
/**
* Displays a diagnostics about the web server, php and WordPress.
*
* @since 1.5.0
*/
public function Diagnostics() {
global $wp_version;
$l_str_php_extensions = '';
// Iterate through each PHP extension.
foreach ( get_loaded_extensions() as $l_int_index => $l_str_extension ) {
if ( $l_int_index > 0 ) {
$l_str_php_extensions .= ' | ';
}
$l_str_php_extensions .= $l_str_extension . ' ' . phpversion( $l_str_extension );
}
$l_obj_current_theme = wp_get_theme();
$l_str_wordpress_plugins = '';
// Iterate through each installed WordPress Plugin.
foreach ( get_plugins() as $l_arr_plugin ) {
$l_str_wordpress_plugins .= '<tr>';
$l_str_wordpress_plugins .= '<td>' . $l_arr_plugin['Name'] . '</td>';
// phpcs:disable Generic.Strings.UnnecessaryStringConcat.Found
$l_str_wordpress_plugins .= '<td>' . $l_arr_plugin['Version'] . ' [' . $l_arr_plugin['PluginURI'] . ']' . '</td>';
// phpcs:enable Generic.Strings.UnnecessaryStringConcat.Found
$l_str_wordpress_plugins .= '</tr>';
}
// Load template file.
$l_obj_template = new MCI_Footnotes_Template( MCI_Footnotes_Template::C_STR_DASHBOARD, 'diagnostics' );
if ( ! isset( $_SERVER['SERVER_NAME'] ) ) {
die;
} else {
$l_str_server_name = wp_unslash( $_SERVER['SERVER_NAME'] );
}
if ( ! isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
die;
} else {
$l_str_http_user_agent = wp_unslash( $_SERVER['HTTP_USER_AGENT'] );
}
// Replace all placeholders.
$l_obj_template->replace(
array(
'label-server' => __( 'Server name', 'footnotes' ),
'server' => $l_str_server_name,
'label-php' => __( 'PHP version', 'footnotes' ),
'php' => phpversion(),
'label-user-agent' => __( 'User agent', 'footnotes' ),
'user-agent' => $l_str_http_user_agent,
'label-max-execution-time' => __( 'Max execution time', 'footnotes' ),
'max-execution-time' => ini_get( 'max_execution_time' ) . ' ' . __( 'seconds', 'footnotes' ),
'label-memory-limit' => __( 'Memory limit', 'footnotes' ),
'memory-limit' => ini_get( 'memory_limit' ),
'label-php-extensions' => __( 'PHP extensions', 'footnotes' ),
'php-extensions' => $l_str_php_extensions,
'label-wordpress' => __( 'WordPress version', 'footnotes' ),
'wordpress' => $wp_version,
'label-theme' => __( 'Active Theme', 'footnotes' ),
'theme' => $l_obj_current_theme->get( 'Name' ) . ' ' . $l_obj_current_theme->get( 'Version' ) . ', ' . $l_obj_current_theme->get( 'Author' ) . ' [' . $l_obj_current_theme->get( 'AuthorURI' ) . ']',
'plugins' => $l_str_wordpress_plugins,
)
);
// Display template with replaced placeholders.
echo $l_obj_template->get_content();
}
}

View file

@ -1,206 +0,0 @@
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
/**
* Includes the Plugin settings menu.
*
* @filesource
* @package footnotes
* @since 1.5.0
*/
/**
* Handles the Settings interface of the Plugin.
*
* @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.
*
* @since 1.5.0
* @var string
*/
const C_STR_MAIN_MENU_TITLE = 'ManFisher';
/**
* Contains layout engine sub classes.
*
* @since 1.5.0
* @var array
*/
private $a_arr_sub_page_classes = array();
/**
* Class Constructor. Initializes all WordPress hooks for the Plugin Settings.
*
* @since 1.5.0
*/
public function __construct() {
foreach ( get_declared_classes() as $l_str_class_name ) {
if ( is_subclass_of( $l_str_class_name, 'MCI_Footnotes_Layout_Engine' ) ) {
$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->get_priority() ] = $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_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
add_action( 'wp_ajax_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
}
/**
* Initializes all sub pages and registers the settings.
*
* @since 1.5.0
*/
public function initialize_settings() {
MCI_Footnotes_Settings::instance()->register_settings();
// 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->register_sections();
}
}
/**
* Registers the new main menu for the WordPress dashboard.
* Registers all sub menu pages for the new main menu.
*
* @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 ) {
// 3terate 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.
*
* @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.
*
* @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' );
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
echo $l_obj_template->get_content();
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
printf( '<em>visit <a href="https://cheret.org/footnotes/" target="_blank">Mark Cheret</a></em>' );
printf( '<br/><br/>' );
printf( '</div>' );
}
// 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
}

File diff suppressed because it is too large Load diff

View file

@ -36,12 +36,12 @@ done
#then
# RULESET="$PROJECT/phpcs.xml.dist"
#else
RULESETS=("WordPress" "PHPCompatibilityWP")
#
#fi
if [ "$FILES" != "" ]
then
for RULESET in $RULESETS; do
for RULESET in WordPress PHPCompatibilityWP; do
echo "Checking Code Standard Compliance, using $RULESET as ruleset standard..."
./vendor/bin/phpcs --standard="$RULESET" --runtime-set testVersion 7.0- --colors --encoding=utf-8 -n -p $FILES
if [ $? != 0 ]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -1,37 +0,0 @@
<table class="diagnostics widefat fixed">
<tbody>
<tr>
<td>[[label-server]]</td>
<td>[[server]]</td>
</tr>
<tr>
<td>[[label-php]]</td>
<td>[[php]]</td>
</tr>
<tr>
<td>[[label-user-agent]]</td>
<td>[[user-agent]]</td>
</tr>
<tr>
<td>[[label-max-execution-time]]</td>
<td>[[max-execution-time]]</td>
</tr>
<tr>
<td>[[label-memory-limit]]</td>
<td>[[memory-limit]]</td>
</tr>
<tr>
<td>[[label-php-extensions]]</td>
<td>[[php-extensions]]</td>
</tr>
<tr>
<td>[[label-wordpress]]</td>
<td>[[wordpress]]</td>
</tr>
<tr>
<td>[[label-theme]]</td>
<td>[[theme]]</td>
</tr>
[[plugins]]
</tbody>
</table>

View file

@ -1,11 +0,0 @@
<h1 style="margin: 0 0 18px; color: rgb(64, 64, 64); line-height: 36px; font-size: 30px; ">ManFisher</h1>
<div style="-webkit-print-color-adjust: exact; margin-right: 10px; padding:14px; border: 1px solid #444; background-color: #fefefe; color: rgb(115, 115, 115); font-family: 'Helvetica Neue', Helvetica, 'Hiragino Sans GB', Arial, sans-serif;">
<p style="margin: 0 0 9px; font-size: 13px; line-height: 18px;">a note from the mastermind behind footnotes</p>
<h2 style="margin: 0; color: rgb(64, 64, 64); line-height: 36px; font-size: 24px; ">Ideology</h2>
<p style="margin: 0 0 9px; font-size: 13px; line-height: 18px;">You know WordPress is a great community effort and boatloads of people are involved and spending their spare time to freely (free as in money) contribute to WordPress as a platform or at the very core. Our aim as developers and those gravitating around developer's halos is to give back to the community with our own ideas which we think are great and well worth our whiles to put our own time into. For some of us, it would be a huge honour to serve the WordPress core developer team.</p>
<h2 style="margin: 0;color: rgb(64, 64, 64); line-height: 36px; font-size: 24px; ">the ManFisher menu</h2>
<p style="margin: 0 0 9px; font-size: 13px; line-height: 18px;">Will soon disappear as the company name changed and I believe it's overbearing to have that menu for such a simple function as footnotes</p>
</div>