parent
7c0b05b59e
commit
205764f91a
13 changed files with 1637 additions and 1637 deletions
|
@ -30,15 +30,15 @@ class WYSIWYG {
|
|||
/**
|
||||
* Append a new Button to the WYSIWYG editor of Posts and Pages.
|
||||
*
|
||||
* @param string[] $p_arr_buttons Already-defined editor buttons.
|
||||
* @param string[] $buttons Already-defined editor buttons.
|
||||
* @return string[]
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Should this be `static`?
|
||||
*/
|
||||
public static function new_visual_editor_button( array $p_arr_buttons ): array {
|
||||
$p_arr_buttons[] = 'footnotes';
|
||||
return $p_arr_buttons;
|
||||
public static function new_visual_editor_button( array $buttons ): array {
|
||||
$buttons[] = 'footnotes';
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,24 +47,24 @@ class WYSIWYG {
|
|||
* @since 1.5.0
|
||||
*/
|
||||
public static function new_plain_text_editor_button(): void {
|
||||
$l_obj_template = new Includes\Template( \footnotes\includes\Template::C_STR_DASHBOARD, 'editor-button' );
|
||||
$template = new Includes\Template( \footnotes\includes\Template::DASHBOARD, 'editor-button' );
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $l_obj_template->get_content();
|
||||
echo $template->get_content();
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes the Plugins WYSIWYG editor script.
|
||||
*
|
||||
* @param string[] $p_arr_plugins Scripts to be included by the editor.
|
||||
* @param string[] $plugins Scripts to be included by the editor.
|
||||
* @return string[]
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Should this be `static`?
|
||||
*/
|
||||
public static function include_scripts( array $p_arr_plugins ): array {
|
||||
$p_arr_plugins['footnotes'] = plugins_url( '/../admin/js/wysiwyg-editor' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js', __FILE__ );
|
||||
return $p_arr_plugins;
|
||||
public static function include_scripts( array $plugins ): array {
|
||||
$plugins['footnotes'] = plugins_url( '/../admin/js/wysiwyg-editor' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js', __FILE__ );
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,16 +75,16 @@ class WYSIWYG {
|
|||
*/
|
||||
public static function ajax_callback(): void {
|
||||
// Get start and end tag for the footnotes short code.
|
||||
$l_str_starting_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_START );
|
||||
$l_str_ending_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_END );
|
||||
if ( 'userdefined' === $l_str_starting_tag || 'userdefined' === $l_str_ending_tag ) {
|
||||
$l_str_starting_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_START_USER_DEFINED );
|
||||
$l_str_ending_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_END_USER_DEFINED );
|
||||
$starting_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::FOOTNOTES_SHORT_CODE_START );
|
||||
$ending_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::FOOTNOTES_SHORT_CODE_END );
|
||||
if ( 'userdefined' === $starting_tag || 'userdefined' === $ending_tag ) {
|
||||
$starting_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::FOOTNOTES_SHORT_CODE_START_USER_DEFINED );
|
||||
$ending_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::FOOTNOTES_SHORT_CODE_END_USER_DEFINED );
|
||||
}
|
||||
echo wp_json_encode(
|
||||
array(
|
||||
'start' => htmlspecialchars( $l_str_starting_tag ),
|
||||
'end' => htmlspecialchars( $l_str_ending_tag ),
|
||||
'start' => htmlspecialchars( $starting_tag ),
|
||||
'end' => htmlspecialchars( $ending_tag ),
|
||||
)
|
||||
);
|
||||
exit;
|
||||
|
|
|
@ -49,7 +49,7 @@ abstract class Engine {
|
|||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected ?string $a_str_sub_page_hook = null;
|
||||
protected ?string $sub_page_hook = null;
|
||||
|
||||
/**
|
||||
* Stores all Sections for the child sub-page.
|
||||
|
@ -59,7 +59,7 @@ abstract class Engine {
|
|||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected array $a_arr_sections = array();
|
||||
protected array $sections = array();
|
||||
|
||||
/**
|
||||
* Returns a Priority index. Lower numbers have a higher priority.
|
||||
|
@ -114,10 +114,10 @@ abstract class Engine {
|
|||
* Returns an array describing a sub-page section.
|
||||
*
|
||||
* @access protected
|
||||
* @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 Whether a ‘Submit’ button should
|
||||
* @param string $id Unique ID suffix.
|
||||
* @param string $title Title of the section.
|
||||
* @param int $settings_container_index Settings Container index.
|
||||
* @param bool $has_submit_button Whether a ‘Submit’ button should
|
||||
* be displayed for this section. Default `true`.
|
||||
* @return array {
|
||||
* A dashboard section.
|
||||
|
@ -131,12 +131,12 @@ abstract class Engine {
|
|||
* @since 1.5.0
|
||||
* @todo Refactor sections into their own class?
|
||||
*/
|
||||
protected function add_section( string $p_str_id, string $p_str_title, int $p_int_settings_container_index, bool $p_bool_has_submit_button = true ): array {
|
||||
protected function add_section( string $id, string $title, int $settings_container_index, bool $has_submit_button = true ): array {
|
||||
return array(
|
||||
'id' => $this->plugin_name . '-' . $p_str_id,
|
||||
'title' => $p_str_title,
|
||||
'submit' => $p_bool_has_submit_button,
|
||||
'container' => $p_int_settings_container_index,
|
||||
'id' => $this->plugin_name . '-' . $id,
|
||||
'title' => $title,
|
||||
'submit' => $has_submit_button,
|
||||
'container' => $settings_container_index,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -144,10 +144,10 @@ abstract class Engine {
|
|||
* Returns an array describing a meta box.
|
||||
*
|
||||
* @access protected
|
||||
* @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.
|
||||
* @param string $section_id Parent section ID.
|
||||
* @param string $id Unique ID suffix.
|
||||
* @param string $title Title for the meta box.
|
||||
* @param string $callback_function_name Class method name for callback.
|
||||
* @return array {
|
||||
* A dashboard meta box.
|
||||
*
|
||||
|
@ -161,12 +161,12 @@ abstract class Engine {
|
|||
* @todo Refactor meta boxes into their own class?
|
||||
* @todo Pass actual functions rather than strings?
|
||||
*/
|
||||
protected function add_meta_box( string $p_str_section_id, string $p_str_id, string $p_str_title, string $p_str_callback_function_name ): array {
|
||||
protected function add_meta_box( string $section_id, string $id, string $title, string $callback_function_name ): array {
|
||||
return array(
|
||||
'parent' => $this->plugin_name . '-' . $p_str_section_id,
|
||||
'id' => $p_str_id,
|
||||
'title' => $p_str_title,
|
||||
'callback' => $p_str_callback_function_name,
|
||||
'parent' => $this->plugin_name . '-' . $section_id,
|
||||
'id' => $id,
|
||||
'title' => $title,
|
||||
'callback' => $callback_function_name,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -178,20 +178,20 @@ abstract class Engine {
|
|||
public function register_sub_page(): void {
|
||||
global $submenu;
|
||||
|
||||
if ( array_key_exists( plugin_basename( Init::C_STR_MAIN_MENU_SLUG ), $submenu ) ) {
|
||||
foreach ( $submenu[ plugin_basename( Init::C_STR_MAIN_MENU_SLUG ) ] as $l_arr_sub_menu ) {
|
||||
if ( plugin_basename( Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() ) === $l_arr_sub_menu[2] ) {
|
||||
remove_submenu_page( Init::C_STR_MAIN_MENU_SLUG, Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() );
|
||||
if ( array_key_exists( plugin_basename( Init::MAIN_MENU_SLUG ), $submenu ) ) {
|
||||
foreach ( $submenu[ plugin_basename( Init::MAIN_MENU_SLUG ) ] as $sub_menu ) {
|
||||
if ( plugin_basename( Init::MAIN_MENU_SLUG . $this->get_sub_page_slug() ) === $sub_menu[2] ) {
|
||||
remove_submenu_page( Init::MAIN_MENU_SLUG, Init::MAIN_MENU_SLUG . $this->get_sub_page_slug() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->a_str_sub_page_hook = add_submenu_page(
|
||||
Init::C_STR_MAIN_MENU_SLUG,
|
||||
$this->sub_page_hook = add_submenu_page(
|
||||
Init::MAIN_MENU_SLUG,
|
||||
$this->get_sub_page_title(),
|
||||
$this->get_sub_page_title(),
|
||||
'manage_options',
|
||||
Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug(),
|
||||
Init::MAIN_MENU_SLUG . $this->get_sub_page_slug(),
|
||||
fn() => $this->display_content()
|
||||
);
|
||||
}
|
||||
|
@ -202,16 +202,16 @@ abstract class Engine {
|
|||
* @since 1.5.0
|
||||
*/
|
||||
public function register_sections(): void {
|
||||
foreach ( $this->get_sections() as $l_arr_section ) {
|
||||
foreach ( $this->get_sections() as $section ) {
|
||||
// Append tab to the tab-array.
|
||||
$this->a_arr_sections[ $l_arr_section['id'] ] = $l_arr_section;
|
||||
$this->sections[ $section['id'] ] = $section;
|
||||
add_settings_section(
|
||||
$l_arr_section['id'],
|
||||
$section['id'],
|
||||
'',
|
||||
fn() => $this->description(),
|
||||
$l_arr_section['id']
|
||||
$section['id']
|
||||
);
|
||||
$this->register_meta_boxes( $l_arr_section['id'] );
|
||||
$this->register_meta_boxes( $section['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,21 +219,21 @@ abstract class Engine {
|
|||
* Registers all Meta boxes for a sub-page.
|
||||
*
|
||||
* @access private
|
||||
* @param string $p_str_parent_id Parent section unique ID.
|
||||
* @param string $parent_id Parent section unique ID.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private function register_meta_boxes( string $p_str_parent_id ): void {
|
||||
private function register_meta_boxes( string $parent_id ): void {
|
||||
// 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'] ) {
|
||||
foreach ( $this->get_meta_boxes() as $meta_box ) {
|
||||
if ( $parent_id !== $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,
|
||||
$parent_id . '-' . $meta_box['id'],
|
||||
$meta_box['title'],
|
||||
array( $this, $meta_box['callback'] ),
|
||||
$parent_id,
|
||||
'main'
|
||||
);
|
||||
}
|
||||
|
@ -262,33 +262,33 @@ abstract class Engine {
|
|||
*/
|
||||
public function display_content(): void {
|
||||
$this->append_scripts();
|
||||
$l_str_active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->a_arr_sections );
|
||||
$l_arr_active_section = $this->a_arr_sections[ $l_str_active_section_id ];
|
||||
$active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->sections );
|
||||
$active_section = $this->sections[ $active_section_id ];
|
||||
|
||||
// Store settings.
|
||||
$l_bool_settings_updated = false;
|
||||
$settings_updated = false;
|
||||
if ( array_key_exists( 'save-settings', $_POST ) && 'save' === $_POST['save-settings'] ) {
|
||||
unset( $_POST['save-settings'] );
|
||||
unset( $_POST['submit'] );
|
||||
$l_bool_settings_updated = $this->save_settings();
|
||||
$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 ) {
|
||||
foreach ( $this->sections as $id => $description ) {
|
||||
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' : '',
|
||||
Init::C_STR_MAIN_MENU_SLUG,
|
||||
$l_str_id,
|
||||
$l_arr_description['title']
|
||||
( $id === $active_section['id'] ) ? ' nav-tab-active' : '',
|
||||
Init::MAIN_MENU_SLUG,
|
||||
$id,
|
||||
$description['title']
|
||||
);
|
||||
}
|
||||
echo '</h2><br/>';
|
||||
|
||||
if ( $l_bool_settings_updated ) {
|
||||
if ( $settings_updated ) {
|
||||
echo sprintf( '<div id="message" class="updated">%s</div>', __( 'Settings saved', 'footnotes' ) );
|
||||
}
|
||||
|
||||
|
@ -296,11 +296,11 @@ abstract class Engine {
|
|||
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 );
|
||||
do_settings_sections( $active_section['id'] );
|
||||
do_meta_boxes( $active_section['id'], 'main', null );
|
||||
|
||||
// Add submit button to active section if defined.
|
||||
if ( $l_arr_active_section['submit'] ) {
|
||||
if ( $active_section['submit'] ) {
|
||||
submit_button();
|
||||
}
|
||||
echo '</form>';
|
||||
|
@ -311,7 +311,7 @@ abstract class Engine {
|
|||
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 "postboxes.add_postbox_toggles('" . $this->sub_page_hook . "');";
|
||||
echo '});';
|
||||
echo '</script>';
|
||||
}
|
||||
|
@ -328,15 +328,15 @@ abstract class Engine {
|
|||
* @todo Review nonce verification.
|
||||
*/
|
||||
private function save_settings(): bool {
|
||||
$l_arr_new_settings = array();
|
||||
$l_str_active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->a_arr_sections );
|
||||
$l_arr_active_section = $this->a_arr_sections[ $l_str_active_section_id ];
|
||||
$new_settings = array();
|
||||
$active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->sections );
|
||||
$active_section = $this->sections[ $active_section_id ];
|
||||
|
||||
foreach ( array_keys( Includes\Settings::instance()->get_defaults( $l_arr_active_section['container'] ) ) as $l_str_key ) {
|
||||
$l_arr_new_settings[ $l_str_key ] = array_key_exists( $l_str_key, $_POST ) ? wp_unslash( $_POST[ $l_str_key ] ) : '';
|
||||
foreach ( array_keys( Includes\Settings::instance()->get_defaults( $active_section['container'] ) ) as $key ) {
|
||||
$new_settings[ $key ] = array_key_exists( $key, $_POST ) ? wp_unslash( $_POST[ $key ] ) : '';
|
||||
}
|
||||
// Update settings.
|
||||
return Includes\Settings::instance()->save_options( $l_arr_active_section['container'], $l_arr_new_settings );
|
||||
return Includes\Settings::instance()->save_options( $active_section['container'], $new_settings );
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
|
||||
|
||||
|
@ -354,7 +354,7 @@ abstract class Engine {
|
|||
* Loads a specified setting.
|
||||
*
|
||||
* @access protected
|
||||
* @param string $p_str_setting_key_name Setting key.
|
||||
* @param string $setting_key_name Setting key.
|
||||
* @return array {
|
||||
* A configurable setting.
|
||||
*
|
||||
|
@ -367,41 +367,41 @@ abstract class Engine {
|
|||
* @since 2.5.11 Broken due to accidental removal of `esc_attr()` call.
|
||||
* @since 2.6.1 Restore `esc_attr()` call.
|
||||
*/
|
||||
protected function load_setting( string $p_str_setting_key_name ): array {
|
||||
protected function load_setting( string $setting_key_name ): array {
|
||||
// Get current section.
|
||||
reset( $this->a_arr_sections );
|
||||
$p_arr_return = array();
|
||||
$p_arr_return['id'] = $p_str_setting_key_name;
|
||||
$p_arr_return['name'] = $p_str_setting_key_name;
|
||||
$p_arr_return['value'] = esc_attr( Includes\Settings::instance()->get( $p_str_setting_key_name ) );
|
||||
return $p_arr_return;
|
||||
reset( $this->sections );
|
||||
$return = array();
|
||||
$return['id'] = $setting_key_name;
|
||||
$return['name'] = $setting_key_name;
|
||||
$return['value'] = esc_attr( Includes\Settings::instance()->get( $setting_key_name ) );
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a simple text inside a 'span' element.
|
||||
*
|
||||
* @access protected
|
||||
* @param string $p_str_text Message to be surrounded with `<span>` tags.
|
||||
* @param string $text Message to be surrounded with `<span>` tags.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Refactor HTML generation.
|
||||
*/
|
||||
protected function add_text( string $p_str_text ): string {
|
||||
return sprintf( '<span>%s</span>', $p_str_text );
|
||||
protected function add_text( string $text ): string {
|
||||
return sprintf( '<span>%s</span>', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTML tag for a 'label' element.
|
||||
*
|
||||
* @access protected
|
||||
* @param string $p_str_setting_name Settings key.
|
||||
* @param string $p_str_caption Label caption.
|
||||
* @param string $setting_name Settings key.
|
||||
* @param string $caption Label caption.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Refactor HTML generation.
|
||||
*/
|
||||
protected function add_label( string $p_str_setting_name, string $p_str_caption ): string {
|
||||
if ( empty( $p_str_caption ) ) {
|
||||
protected function add_label( string $setting_name, string $caption ): string {
|
||||
if ( empty( $caption ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -416,36 +416,36 @@ abstract class Engine {
|
|||
* {@link https://softwareengineering.stackexchange.com/questions/234546/colons-in-internationalized-ui
|
||||
* style guides}.
|
||||
*/
|
||||
return sprintf( '<label for="%s">%s</label>', $p_str_setting_name, $p_str_caption );
|
||||
return sprintf( '<label for="%s">%s</label>', $setting_name, $caption );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the HTML for a text 'input' element.
|
||||
*
|
||||
* @access protected
|
||||
* @param string $p_str_setting_name Setting key.
|
||||
* @param int $p_str_max_length Maximum length of the input. Default length 999 chars.
|
||||
* @param bool $p_bool_readonly Set the input to be read only. Default `false`.
|
||||
* @param bool $p_bool_hidden Set the input to be hidden. Default `false`.
|
||||
* @param string $setting_name Setting key.
|
||||
* @param int $max_length Maximum length of the input. Default length 999 chars.
|
||||
* @param bool $readonly Set the input to be read only. Default `false`.
|
||||
* @param bool $hidden Set the input to be hidden. Default `false`.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Refactor HTML generation.
|
||||
*/
|
||||
protected function add_text_box( string $p_str_setting_name, int $p_str_max_length = 999, bool $p_bool_readonly = false, bool $p_bool_hidden = false ): string {
|
||||
$l_str_style = '';
|
||||
protected function add_text_box( string $setting_name, int $max_length = 999, bool $readonly = false, bool $hidden = false ): string {
|
||||
$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;';
|
||||
$data = $this->load_setting( $setting_name );
|
||||
if ( $hidden ) {
|
||||
$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"' : ''
|
||||
$data['name'],
|
||||
$data['id'],
|
||||
$max_length,
|
||||
$style,
|
||||
$data['value'],
|
||||
$readonly ? 'readonly="readonly"' : ''
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -453,19 +453,19 @@ abstract class Engine {
|
|||
* Constructs the HTML for a checkbox 'input' element.
|
||||
*
|
||||
* @access protected
|
||||
* @param string $p_str_setting_name Setting key.
|
||||
* @param string $setting_name Setting key.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Refactor HTML generation.
|
||||
*/
|
||||
protected function add_checkbox( string $p_str_setting_name ): string {
|
||||
protected function add_checkbox( string $setting_name ): string {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
$data = $this->load_setting( $setting_name );
|
||||
return sprintf(
|
||||
'<input type="checkbox" name="%s" id="%s" %s/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
Includes\Convert::to_bool( $l_arr_data['value'] ) ? 'checked="checked"' : ''
|
||||
$data['name'],
|
||||
$data['id'],
|
||||
Includes\Convert::to_bool( $data['value'] ) ? 'checked="checked"' : ''
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -473,34 +473,34 @@ abstract class Engine {
|
|||
* Constructs the HTML for a 'select' element.
|
||||
*
|
||||
* @access protected
|
||||
* @param string $p_str_setting_name Setting key.
|
||||
* @param array $p_arr_options Possible options.
|
||||
* @param string $setting_name Setting key.
|
||||
* @param array $options Possible options.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Refactor HTML generation.
|
||||
*/
|
||||
protected function add_select_box( string $p_str_setting_name, array $p_arr_options ): string {
|
||||
protected function add_select_box( string $setting_name, array $options ): string {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
$l_str_options = '';
|
||||
$data = $this->load_setting( $setting_name );
|
||||
$options = '';
|
||||
|
||||
// Loop through all array keys.
|
||||
foreach ( $p_arr_options as $l_str_value => $l_str_caption ) {
|
||||
$l_str_options .= sprintf(
|
||||
foreach ( $options as $value => $caption ) {
|
||||
$options .= sprintf(
|
||||
'<option value="%s" %s>%s</option>',
|
||||
$l_str_value,
|
||||
$value,
|
||||
// Only check for equality, not identity, WRT backlink symbol arrows.
|
||||
// phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
|
||||
$l_str_value == $l_arr_data['value'] ? 'selected' : '',
|
||||
$value == $data['value'] ? 'selected' : '',
|
||||
// phpcs:enable WordPress.PHP.StrictComparisons.LooseComparison
|
||||
$l_str_caption
|
||||
$caption
|
||||
);
|
||||
}
|
||||
return sprintf(
|
||||
'<select name="%s" id="%s">%s</select>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_str_options
|
||||
$data['name'],
|
||||
$data['id'],
|
||||
$options
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -508,19 +508,19 @@ abstract class Engine {
|
|||
* Constructs the HTML for a 'textarea' element.
|
||||
*
|
||||
* @access protected
|
||||
* @param string $p_str_setting_name Setting key.
|
||||
* @param string $setting_name Setting key.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Refactor HTML generation.
|
||||
*/
|
||||
protected function add_textarea( $p_str_setting_name ): string {
|
||||
protected function add_textarea( $setting_name ): string {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
$data = $this->load_setting( $setting_name );
|
||||
return sprintf(
|
||||
'<textarea name="%s" id="%s">%s</textarea>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_arr_data['value']
|
||||
$data['name'],
|
||||
$data['id'],
|
||||
$data['value']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -529,20 +529,20 @@ abstract class Engine {
|
|||
* class.
|
||||
*
|
||||
* @access protected
|
||||
* @param string $p_str_setting_name Setting key.
|
||||
* @param string $setting_name Setting key.
|
||||
*
|
||||
* @since 1.5.6
|
||||
* @todo Refactor HTML generation.
|
||||
* @todo Use proper colorpicker element.
|
||||
*/
|
||||
protected function add_color_selection( string $p_str_setting_name ): string {
|
||||
protected function add_color_selection( string $setting_name ): string {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
$data = $this->load_setting( $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']
|
||||
$data['name'],
|
||||
$data['id'],
|
||||
$data['value']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -550,36 +550,36 @@ abstract class Engine {
|
|||
* Constructs the HTML for numeric 'input' element.
|
||||
*
|
||||
* @access protected
|
||||
* @param string $p_str_setting_name Setting key.
|
||||
* @param string $setting_name Setting key.
|
||||
* @param int $p_in_min Minimum value.
|
||||
* @param int $p_int_max Maximum value.
|
||||
* @param bool $p_bool_deci `true` if float, `false` if integer. Default `false`.
|
||||
* @param int $max Maximum value.
|
||||
* @param bool $deci `true` if float, `false` if integer. Default `false`.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Refactor HTML generation.
|
||||
*/
|
||||
protected function add_num_box( string $p_str_setting_name, int $p_in_min, int $p_int_max, bool $p_bool_deci = false ): string {
|
||||
protected function add_num_box( string $setting_name, int $p_in_min, int $max, bool $deci = false ): string {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
$data = $this->load_setting( $setting_name );
|
||||
|
||||
if ( $p_bool_deci ) {
|
||||
$l_str_value = number_format( floatval( $l_arr_data['value'] ), 1 );
|
||||
if ( $deci ) {
|
||||
$value = number_format( floatval( $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,
|
||||
$data['name'],
|
||||
$data['id'],
|
||||
$value,
|
||||
$p_in_min,
|
||||
$p_int_max
|
||||
$max
|
||||
);
|
||||
}
|
||||
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'],
|
||||
$data['name'],
|
||||
$data['id'],
|
||||
$data['value'],
|
||||
$p_in_min,
|
||||
$p_int_max
|
||||
$max
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class Init {
|
|||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
const C_STR_MAIN_MENU_SLUG = 'footnotes';
|
||||
const MAIN_MENU_SLUG = 'footnotes';
|
||||
|
||||
/**
|
||||
* Contains the settings page.
|
||||
|
@ -136,9 +136,9 @@ class Init {
|
|||
add_submenu_page(
|
||||
'options-general.php',
|
||||
'footnotes Settings',
|
||||
\footnotes\includes\Config::C_STR_PLUGIN_PUBLIC_NAME,
|
||||
\footnotes\includes\Config::PLUGIN_PUBLIC_NAME,
|
||||
'manage_options',
|
||||
self::C_STR_MAIN_MENU_SLUG,
|
||||
self::MAIN_MENU_SLUG,
|
||||
fn() => $this->settings_page->display_content()
|
||||
);
|
||||
$this->settings_page->register_sub_page();
|
||||
|
@ -151,58 +151,58 @@ class Init {
|
|||
* @since 1.5.0
|
||||
*/
|
||||
public function get_plugin_meta_information(): void {
|
||||
$l_str_plugin_name = null;
|
||||
$plugin_name = null;
|
||||
// TODO: add nonce verification?
|
||||
|
||||
// Get plugin internal name from POST data.
|
||||
if ( isset( $_POST['plugin'] ) ) {
|
||||
$l_str_plugin_name = wp_unslash( $_POST['plugin'] );
|
||||
$plugin_name = wp_unslash( $_POST['plugin'] );
|
||||
}
|
||||
|
||||
if ( empty( $l_str_plugin_name ) ) {
|
||||
if ( empty( $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';
|
||||
$url = 'https://api.wordpress.org/plugins/info/1.0/' . $plugin_name . '.json';
|
||||
// Call URL and collect data.
|
||||
$l_arr_response = wp_remote_get( $l_str_url );
|
||||
$response = wp_remote_get( $url );
|
||||
// Check if response is valid.
|
||||
if ( is_wp_error( $l_arr_response ) ) {
|
||||
if ( is_wp_error( $response ) ) {
|
||||
echo wp_json_encode( array( 'error' => 'Error receiving Plugin Information from WordPress.' ) );
|
||||
exit;
|
||||
}
|
||||
if ( ! array_key_exists( 'body', $l_arr_response ) ) {
|
||||
if ( ! array_key_exists( 'body', $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'];
|
||||
$response = $response['body'];
|
||||
// Get plugin object.
|
||||
$l_arr_plugin = json_decode( $l_str_response, true, 512, JSON_THROW_ON_ERROR );
|
||||
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 ) );
|
||||
$plugin = json_decode( $response, true, 512, JSON_THROW_ON_ERROR );
|
||||
if ( empty( $plugin ) ) {
|
||||
echo wp_json_encode( array( 'error' => 'Error reading Plugin meta information.<br/>URL: ' . $url . '<br/>Response: ' . $response ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
$l_int_num_ratings = array_key_exists( 'num_ratings', $l_arr_plugin ) ? (int) $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 );
|
||||
$num_ratings = array_key_exists( 'num_ratings', $plugin ) ? (int) $plugin['num_ratings'] : 0;
|
||||
$rating = array_key_exists( 'rating', $plugin ) ? floatval( $plugin['rating'] ) : 0.0;
|
||||
$stars = round( 5 * $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'] : '---',
|
||||
'PluginDescription' => array_key_exists( 'short_description', $plugin ) ? html_entity_decode( $plugin['short_description'] ) : 'Error reading Plugin information',
|
||||
'PluginAuthor' => array_key_exists( 'author', $plugin ) ? html_entity_decode( $plugin['author'] ) : 'unknown',
|
||||
'PluginRatingText' => $stars . ' ' . __( 'rating based on', 'footnotes' ) . ' ' . $num_ratings . ' ' . __( 'ratings', 'footnotes' ),
|
||||
'PluginRating1' => $stars >= 0.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating2' => $stars >= 1.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating3' => $stars >= 2.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating4' => $stars >= 3.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating5' => $stars >= 4.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating' => $num_ratings,
|
||||
'PluginLastUpdated' => array_key_exists( 'last_updated', $plugin ) ? $plugin['last_updated'] : 'unknown',
|
||||
'PluginDownloads' => array_key_exists( 'downloaded', $plugin ) ? $plugin['downloaded'] : '---',
|
||||
)
|
||||
);
|
||||
exit;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -55,7 +55,7 @@ class Config {
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_PLUGIN_PUBLIC_NAME = '<span class="footnotes_logo footnotes_logo_part1">foot</span><span class="footnotes_logo footnotes_logo_part2">notes</span>';
|
||||
const 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 use as a dashboard heading.
|
||||
|
@ -72,7 +72,7 @@ class Config {
|
|||
*
|
||||
* @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>';
|
||||
const 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 element for the ‘love’ symbol.
|
||||
|
@ -83,7 +83,7 @@ class Config {
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_LOVE_SYMBOL = '<span style="color:#ff6d3b; font-weight:bold;">♥</span>';
|
||||
const LOVE_SYMBOL = '<span style="color:#ff6d3b; font-weight:bold;">♥</span>';
|
||||
|
||||
/**
|
||||
* HTML element for the ‘love’ symbol used in dashboard heading
|
||||
|
@ -94,7 +94,7 @@ class Config {
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_LOVE_SYMBOL_HEADING = '<span class="footnotes_heart_heading">♥</span>';
|
||||
const LOVE_SYMBOL_HEADING = '<span class="footnotes_heart_heading">♥</span>';
|
||||
|
||||
/**
|
||||
* Shortcode to NOT display the ‘LOVE ME’ slug on certain pages.
|
||||
|
@ -105,5 +105,5 @@ class Config {
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_NO_LOVE_SLUG = '[[no footnotes: love]]';
|
||||
const NO_LOVE_SLUG = '[[no footnotes: love]]';
|
||||
}
|
||||
|
|
|
@ -22,27 +22,27 @@ class Convert {
|
|||
/**
|
||||
* Converts an integer into the user-defined counter style for the footnotes.
|
||||
*
|
||||
* @param int $p_int_index Index to be converted.
|
||||
* @param string $p_str_convert_style Counter style to use.
|
||||
* @param int $index Index to be converted.
|
||||
* @param string $convert_style Counter style to use.
|
||||
* @return string The index converted to the defined counter style.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function index( int $p_int_index, string $p_str_convert_style = 'arabic_plain' ): string {
|
||||
switch ( $p_str_convert_style ) {
|
||||
public static function index( int $index, string $convert_style = 'arabic_plain' ): string {
|
||||
switch ( $convert_style ) {
|
||||
case 'roman':
|
||||
return self::to_roman( $p_int_index, true );
|
||||
return self::to_roman( $index, true );
|
||||
case 'roman_low':
|
||||
return self::to_roman( $p_int_index, false );
|
||||
return self::to_roman( $index, false );
|
||||
case 'latin_high':
|
||||
return self::to_latin( $p_int_index, true );
|
||||
return self::to_latin( $index, true );
|
||||
case 'latin_low':
|
||||
return self::to_latin( $p_int_index, false );
|
||||
return self::to_latin( $index, false );
|
||||
case 'arabic_leading':
|
||||
return self::to_arabic_leading( $p_int_index );
|
||||
return self::to_arabic_leading( $index );
|
||||
case 'arabic_plain':
|
||||
default:
|
||||
return (string) $p_int_index;
|
||||
return (string) $index;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,63 +52,63 @@ class Convert {
|
|||
* This function works from values A–ZZ (meaning there is a limit of 676
|
||||
* gootnotes per Page).
|
||||
*
|
||||
* @param int $p_int_value Value to be converted.
|
||||
* @param bool $p_bool_upper_case Whether to convert the value to upper-case.
|
||||
* @param int $value Value to be converted.
|
||||
* @param bool $upper_case Whether to convert the value to upper-case.
|
||||
*
|
||||
* @since 1.0-gamma
|
||||
* @todo Replace with built-in char casting.
|
||||
*/
|
||||
private static function to_latin( int $p_int_value, bool $p_bool_upper_case ): string {
|
||||
private static function to_latin( int $value, bool $upper_case ): string {
|
||||
// Output string.
|
||||
$l_str_return = '';
|
||||
$l_int_offset = 0;
|
||||
$return = '';
|
||||
$offset = 0;
|
||||
// Check if the value is higher then 26 = Z.
|
||||
while ( $p_int_value > 26 ) {
|
||||
while ( $value > 26 ) {
|
||||
// Increase offset and reduce counter.
|
||||
$l_int_offset++;
|
||||
$p_int_value -= 26;
|
||||
$offset++;
|
||||
$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 );
|
||||
if ( $offset > 0 ) {
|
||||
$return = chr( $offset + 64 );
|
||||
}
|
||||
// Add the origin letter.
|
||||
$l_str_return .= chr( $p_int_value + 64 );
|
||||
$return .= chr( $value + 64 );
|
||||
// Return the latin character representing the integer.
|
||||
if ( $p_bool_upper_case ) {
|
||||
return strtoupper( $l_str_return );
|
||||
if ( $upper_case ) {
|
||||
return strtoupper( $return );
|
||||
}
|
||||
return strtolower( $l_str_return );
|
||||
return strtolower( $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an integer to a leading-0 integer.
|
||||
*
|
||||
* @param int $p_int_value Value to be converted.
|
||||
* @param int $value Value to be converted.
|
||||
* @return string Value with a leading zero.
|
||||
*
|
||||
* @since 1.0-gamma
|
||||
* @todo Replace with built-in string formatting.
|
||||
*/
|
||||
private static function to_arabic_leading( int $p_int_value ): string {
|
||||
private static function to_arabic_leading( int $value ): string {
|
||||
// Add a leading 0 if number lower then 10.
|
||||
if ( $p_int_value < 10 ) {
|
||||
return '0' . $p_int_value;
|
||||
if ( $value < 10 ) {
|
||||
return '0' . $value;
|
||||
}
|
||||
return $p_int_value;
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an integer to a Roman numeral.
|
||||
*
|
||||
* @param int $p_int_value Value to be converted.
|
||||
* @param bool $p_bool_upper_case Whether to convert the value to upper-case.
|
||||
* @param int $value Value to be converted.
|
||||
* @param bool $upper_case Whether to convert the value to upper-case.
|
||||
*
|
||||
* @since 1.0-gamma
|
||||
*/
|
||||
private static function to_roman( int $p_int_value, bool $p_bool_upper_case ): string {
|
||||
private static function to_roman( int $value, bool $upper_case ): string {
|
||||
// Table containing all necessary roman letters.
|
||||
$l_arr_roman_numerals = array(
|
||||
$roman_numerals = array(
|
||||
'M' => 1000,
|
||||
'CM' => 900,
|
||||
'D' => 500,
|
||||
|
@ -124,38 +124,38 @@ class Convert {
|
|||
'I' => 1,
|
||||
);
|
||||
// Return value.
|
||||
$l_str_return = '';
|
||||
$return = '';
|
||||
// Iterate through integer value until it is reduced to 0.
|
||||
while ( $p_int_value > 0 ) {
|
||||
foreach ( $l_arr_roman_numerals as $l_str_roman => $l_int_arabic ) {
|
||||
if ( $p_int_value >= $l_int_arabic ) {
|
||||
$p_int_value -= $l_int_arabic;
|
||||
$l_str_return .= $l_str_roman;
|
||||
while ( $value > 0 ) {
|
||||
foreach ( $roman_numerals as $roman => $arabic ) {
|
||||
if ( $value >= $arabic ) {
|
||||
$value -= $arabic;
|
||||
$return .= $roman;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Return roman letters as string.
|
||||
if ( $p_bool_upper_case ) {
|
||||
return strtoupper( $l_str_return );
|
||||
if ( $upper_case ) {
|
||||
return strtoupper( $return );
|
||||
}
|
||||
return strtolower( $l_str_return );
|
||||
return strtolower( $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string depending on its value to a boolean.
|
||||
*
|
||||
* @param string $p_str_value String to be converted to boolean.
|
||||
* @param string $value String to be converted to boolean.
|
||||
* @return bool Boolean value represented by the string.
|
||||
*
|
||||
* @since 1.0-beta
|
||||
* @todo Replace with built-in type casting.
|
||||
*/
|
||||
public static function to_bool( string $p_str_value ): bool {
|
||||
public static function to_bool( string $value ): bool {
|
||||
// Convert string to lower-case to make it easier.
|
||||
$p_str_value = strtolower( $p_str_value );
|
||||
$value = strtolower( $value );
|
||||
// Check if string seems to contain a "true" value.
|
||||
switch ( $p_str_value ) {
|
||||
switch ( $value ) {
|
||||
case 'checked':
|
||||
case 'yes':
|
||||
case 'true':
|
||||
|
@ -170,29 +170,29 @@ class Convert {
|
|||
/**
|
||||
* Get an HTML array short code depending on Arrow-Array key index.
|
||||
*
|
||||
* @param int $p_int_index Index representing the arrow. If empty, all arrows are specified.
|
||||
* @param int $index Index representing the arrow. If empty, all arrows are specified.
|
||||
* @return string|string[] Array of all arrows if index is empty, otherwise HTML tag of a specific arrow.
|
||||
*
|
||||
* @since 1.3.2
|
||||
* @todo Review.
|
||||
* @todo Single return type.
|
||||
*/
|
||||
public static function get_arrow( int $p_int_index = -1 ): string|array {
|
||||
public static function get_arrow( int $index = -1 ): string|array {
|
||||
// Define all possible arrows.
|
||||
$l_arr_arrows = array( '↑', '↥', '↟', '↩', '↲', '↵', '⇑', '⇡', '⇧', '↑' );
|
||||
$arrows = array( '↑', '↥', '↟', '↩', '↲', '↵', '⇑', '⇡', '⇧', '↑' );
|
||||
// Convert index to an integer.
|
||||
if ( ! is_int( $p_int_index ) ) {
|
||||
$p_int_index = (int) $p_int_index;
|
||||
if ( ! is_int( $index ) ) {
|
||||
$index = (int) $index;
|
||||
}
|
||||
// Return the whole arrow array.
|
||||
if ( $p_int_index < 0 ) {
|
||||
return $l_arr_arrows;
|
||||
if ( $index < 0 ) {
|
||||
return $arrows;
|
||||
}
|
||||
if ( $p_int_index > count( $l_arr_arrows ) ) {
|
||||
return $l_arr_arrows;
|
||||
if ( $index > count( $arrows ) ) {
|
||||
return $arrows;
|
||||
}
|
||||
// Return a single arrow.
|
||||
return $l_arr_arrows[ $p_int_index ];
|
||||
return $arrows[ $index ];
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_var_dump, WordPress.PHP.DevelopmentFunctions.error_log_print_r
|
||||
|
|
|
@ -32,7 +32,7 @@ class i18n {
|
|||
* Load the plugin text domain for translation.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @since 2.8.0 Rename from `load()` to `load_plugin_textdomain()`. Remove unused `$p_str_language_code` parameter.
|
||||
* @since 2.8.0 Rename from `load()` to `load_plugin_textdomain()`. Remove unused `$language_code` parameter.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -36,7 +36,7 @@ class Template {
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_DASHBOARD = 'admin/partials';
|
||||
const DASHBOARD = 'admin/partials';
|
||||
|
||||
/**
|
||||
* Directory name for public partials.
|
||||
|
@ -45,21 +45,21 @@ class Template {
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_PUBLIC = 'public/partials';
|
||||
const PUBLIC = 'public/partials';
|
||||
|
||||
/**
|
||||
* Contains the content of the template after initialize.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private ?string $a_str_original_content = '';
|
||||
private ?string $original_content = '';
|
||||
|
||||
/**
|
||||
* Contains the content of the template after initialize with replaced place holders.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private string $a_str_replaced_content = '';
|
||||
private string $replaced_content = '';
|
||||
|
||||
/**
|
||||
* Plugin Directory
|
||||
|
@ -74,22 +74,22 @@ class Template {
|
|||
* @since 1.5.0
|
||||
* @todo Refactor templating.
|
||||
*
|
||||
* @param string $p_str_file_type Template file type.
|
||||
* @param string $p_str_file_name Template file name inside the `partials/` directory, without the file extension.
|
||||
* @param string $p_str_extension (optional) Template file extension (default: 'html').
|
||||
* @param string $file_type Template file type.
|
||||
* @param string $file_name Template file name inside the `partials/` directory, without the file extension.
|
||||
* @param string $extension (optional) Template file extension (default: 'html').
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( string $p_str_file_type, string $p_str_file_name, string $p_str_extension = 'html' ) {
|
||||
public function __construct( string $file_type, string $file_name, string $extension = 'html' ) {
|
||||
// No template file type and/or file name set.
|
||||
if ( empty( $p_str_file_type ) ) {
|
||||
if ( empty( $file_type ) ) {
|
||||
return;
|
||||
}
|
||||
if ( empty( $p_str_file_name ) ) {
|
||||
if ( empty( $file_name ) ) {
|
||||
return;
|
||||
}
|
||||
$this->plugin_directory = plugin_dir_path( __DIR__ );
|
||||
|
||||
$template = $this->get_template( $p_str_file_type, $p_str_file_name, $p_str_extension );
|
||||
$template = $this->get_template( $file_type, $file_name, $extension );
|
||||
if ( $template ) {
|
||||
$this->process_template( $template );
|
||||
} else {
|
||||
|
@ -104,21 +104,21 @@ class Template {
|
|||
* @since 1.5.0
|
||||
* @todo Refactor templating.
|
||||
*
|
||||
* @param string[] $p_arr_placeholders Placeholders (key = placeholder, value = value).
|
||||
* @param string[] $placeholders Placeholders (key = placeholder, value = value).
|
||||
* @return bool `true` on Success, `false` if placeholders invalid.
|
||||
*/
|
||||
public function replace( array $p_arr_placeholders ): bool {
|
||||
public function replace( array $placeholders ): bool {
|
||||
// No placeholders set.
|
||||
if ( empty( $p_arr_placeholders ) ) {
|
||||
if ( empty( $placeholders ) ) {
|
||||
return false;
|
||||
}
|
||||
// Template content is empty.
|
||||
if ( empty( $this->a_str_replaced_content ) ) {
|
||||
if ( empty( $this->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 . ']]', (string) $l_str_value, $this->a_str_replaced_content );
|
||||
foreach ( $placeholders as $placeholder => $value ) {
|
||||
$this->replaced_content = str_replace( '[[' . $placeholder . ']]', (string) $value, $this->replaced_content );
|
||||
}
|
||||
// Success.
|
||||
return true;
|
||||
|
@ -133,7 +133,7 @@ class Template {
|
|||
* @return void
|
||||
*/
|
||||
public function reload() {
|
||||
$this->a_str_replaced_content = $this->a_str_original_content;
|
||||
$this->replaced_content = $this->original_content;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,7 +145,7 @@ class Template {
|
|||
* @return string Template content with replaced placeholders.
|
||||
*/
|
||||
public function get_content(): string {
|
||||
return $this->a_str_replaced_content;
|
||||
return $this->replaced_content;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,14 +159,14 @@ class Template {
|
|||
*/
|
||||
public function process_template( string $template ) {
|
||||
// phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
|
||||
$this->a_str_original_content = preg_replace( '#<!--.+?-->#s', '', file_get_contents( $template ) );
|
||||
$this->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->original_content = preg_replace( '#/\*\*.+?\*/#s', '', $this->original_content );
|
||||
$this->original_content = str_replace( "\n", '', $this->original_content );
|
||||
$this->original_content = str_replace( "\r", '', $this->original_content );
|
||||
$this->original_content = str_replace( "\t", ' ', $this->original_content );
|
||||
$this->original_content = preg_replace( '# +#', ' ', $this->original_content );
|
||||
$this->original_content = str_replace( ' >', '>', $this->original_content );
|
||||
$this->reload();
|
||||
}
|
||||
|
||||
|
@ -177,12 +177,12 @@ class Template {
|
|||
* @todo Refactor templating.
|
||||
* @todo Single return type.
|
||||
*
|
||||
* @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.
|
||||
* @param string $file_type The file type of the template.
|
||||
* @param string $file_name The file name of the template.
|
||||
* @param string $extension The file extension of the template.
|
||||
* @return string|bool `false` or the template path
|
||||
*/
|
||||
public function get_template( string $p_str_file_type, string $p_str_file_name, string $p_str_extension = 'html' ): string|bool {
|
||||
public function get_template( string $file_type, string $file_name, string $extension = 'html' ): string|bool {
|
||||
$located = false;
|
||||
|
||||
/*
|
||||
|
@ -195,7 +195,7 @@ class Template {
|
|||
*/
|
||||
$template_directory = apply_filters( '', 'footnotes/' );
|
||||
$custom_directory = apply_filters( 'custom_template_directory', 'footnotes-custom/' );
|
||||
$template_name = $p_str_file_type . '/' . $p_str_file_name . '.' . $p_str_extension;
|
||||
$template_name = $file_type . '/' . $file_name . '.' . $extension;
|
||||
|
||||
// Look in active theme.
|
||||
if ( file_exists( trailingslashit( get_stylesheet_directory() ) . $template_directory . $template_name ) ) {
|
||||
|
|
|
@ -61,7 +61,7 @@ class General {
|
|||
*
|
||||
* @var Parser $task The Plugin task.
|
||||
*/
|
||||
public ?Parser $a_obj_task = null;
|
||||
public ?Parser $task = null;
|
||||
|
||||
/**
|
||||
* Flag for using tooltips.
|
||||
|
@ -71,7 +71,7 @@ class General {
|
|||
*
|
||||
* @var bool $tooltips_enabled Whether tooltips are enabled or not.
|
||||
*/
|
||||
public static $a_bool_tooltips_enabled = false;
|
||||
public static $tooltips_enabled = false;
|
||||
|
||||
/**
|
||||
* Allows to determine whether alternative tooltips are enabled.
|
||||
|
@ -81,7 +81,7 @@ class General {
|
|||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $a_bool_alternative_tooltips_enabled = false;
|
||||
public static $alternative_tooltips_enabled = false;
|
||||
|
||||
/**
|
||||
* Allows to determine whether AMP compatibility mode is enabled.
|
||||
|
@ -91,7 +91,7 @@ class General {
|
|||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $a_bool_amp_enabled = false;
|
||||
public static $amp_enabled = false;
|
||||
|
||||
/**
|
||||
* Allows to determine the script mode among jQuery or plain JS.
|
||||
|
@ -101,7 +101,7 @@ class General {
|
|||
*
|
||||
* @var string ‘js’ to use plain JavaScript, ‘jquery’ to use jQuery.
|
||||
*/
|
||||
public static $a_str_script_mode = 'js';
|
||||
public static $script_mode = 'js';
|
||||
|
||||
/**
|
||||
* Initialize the class and set its properties.
|
||||
|
@ -118,10 +118,10 @@ class General {
|
|||
$this->load_dependencies();
|
||||
|
||||
// Set conditions re-used for stylesheet enqueuing and in class/task.php.
|
||||
self::$a_bool_amp_enabled = Includes\Convert::to_bool( Includes\Settings::instance()->get( Includes\Settings::C_STR_FOOTNOTES_AMP_COMPATIBILITY_ENABLE ) );
|
||||
self::$a_bool_tooltips_enabled = Includes\Convert::to_bool( Includes\Settings::instance()->get( Includes\Settings::C_STR_FOOTNOTES_MOUSE_OVER_BOX_ENABLED ) );
|
||||
self::$a_bool_alternative_tooltips_enabled = Includes\Convert::to_bool( Includes\Settings::instance()->get( Includes\Settings::C_STR_FOOTNOTES_MOUSE_OVER_BOX_ALTERNATIVE ) );
|
||||
self::$a_str_script_mode = Includes\Settings::instance()->get( Includes\Settings::C_STR_FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE );
|
||||
self::$amp_enabled = Includes\Convert::to_bool( Includes\Settings::instance()->get( Includes\Settings::FOOTNOTES_AMP_COMPATIBILITY_ENABLE ) );
|
||||
self::$tooltips_enabled = Includes\Convert::to_bool( Includes\Settings::instance()->get( Includes\Settings::FOOTNOTES_MOUSE_OVER_BOX_ENABLED ) );
|
||||
self::$alternative_tooltips_enabled = Includes\Convert::to_bool( Includes\Settings::instance()->get( Includes\Settings::FOOTNOTES_MOUSE_OVER_BOX_ALTERNATIVE ) );
|
||||
self::$script_mode = Includes\Settings::instance()->get( Includes\Settings::FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,7 +146,7 @@ class General {
|
|||
|
||||
$this->reference_container_widget = new Widget\Reference_Container( $this->plugin_name );
|
||||
|
||||
$this->a_obj_task = new Parser();
|
||||
$this->task = new Parser();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,53 +162,53 @@ class General {
|
|||
public function enqueue_styles(): void {
|
||||
if ( PRODUCTION_ENV ) {
|
||||
// Set tooltip mode for use in stylesheet name.
|
||||
if ( self::$a_bool_tooltips_enabled ) {
|
||||
if ( self::$tooltips_enabled ) {
|
||||
|
||||
if ( self::$a_bool_amp_enabled ) {
|
||||
$l_str_tooltip_mode_short = 'ampt';
|
||||
$l_str_tooltip_mode_long = 'amp-tooltips';
|
||||
if ( self::$amp_enabled ) {
|
||||
$tooltip_mode_short = 'ampt';
|
||||
$tooltip_mode_long = 'amp-tooltips';
|
||||
|
||||
} elseif ( self::$a_bool_alternative_tooltips_enabled ) {
|
||||
$l_str_tooltip_mode_short = 'altt';
|
||||
$l_str_tooltip_mode_long = 'alternative-tooltips';
|
||||
} elseif ( self::$alternative_tooltips_enabled ) {
|
||||
$tooltip_mode_short = 'altt';
|
||||
$tooltip_mode_long = 'alternative-tooltips';
|
||||
|
||||
} else {
|
||||
$l_str_tooltip_mode_short = 'jqtt';
|
||||
$l_str_tooltip_mode_long = 'jquery-tooltips';
|
||||
$tooltip_mode_short = 'jqtt';
|
||||
$tooltip_mode_long = 'jquery-tooltips';
|
||||
|
||||
}
|
||||
} else {
|
||||
$l_str_tooltip_mode_short = 'nott';
|
||||
$l_str_tooltip_mode_long = 'no-tooltips';
|
||||
$tooltip_mode_short = 'nott';
|
||||
$tooltip_mode_long = 'no-tooltips';
|
||||
}
|
||||
|
||||
// Set basic responsive page layout mode for use in stylesheet name.
|
||||
$l_str_page_layout_option = Includes\Settings::instance()->get( Includes\Settings::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT );
|
||||
switch ( $l_str_page_layout_option ) {
|
||||
$page_layout_option = Includes\Settings::instance()->get( Includes\Settings::FOOTNOTES_PAGE_LAYOUT_SUPPORT );
|
||||
switch ( $page_layout_option ) {
|
||||
case 'reference-container':
|
||||
$l_str_layout_mode = '1';
|
||||
$layout_mode = '1';
|
||||
break;
|
||||
case 'entry-content':
|
||||
$l_str_layout_mode = '2';
|
||||
$layout_mode = '2';
|
||||
break;
|
||||
case 'main-content':
|
||||
$l_str_layout_mode = '3';
|
||||
$layout_mode = '3';
|
||||
break;
|
||||
case 'none':
|
||||
default:
|
||||
$l_str_layout_mode = '0';
|
||||
$layout_mode = '0';
|
||||
break;
|
||||
}
|
||||
|
||||
// Enqueue the tailored united minified stylesheet.
|
||||
wp_enqueue_style(
|
||||
"footnotes-{$l_str_tooltip_mode_long}-pagelayout-{$l_str_page_layout_option}",
|
||||
plugin_dir_url( __FILE__ ) . "css/footnotes-{$l_str_tooltip_mode_short}brpl{$l_str_layout_mode}.min.css",
|
||||
"footnotes-{$tooltip_mode_long}-pagelayout-{$page_layout_option}",
|
||||
plugin_dir_url( __FILE__ ) . "css/footnotes-{$tooltip_mode_short}brpl{$layout_mode}.min.css",
|
||||
array(),
|
||||
( PRODUCTION_ENV ) ? $this->version : filemtime(
|
||||
plugin_dir_path(
|
||||
__FILE__
|
||||
) . "css/footnotes-{$l_str_tooltip_mode_short}brpl{$l_str_layout_mode}.min.css"
|
||||
) . "css/footnotes-{$tooltip_mode_short}brpl{$layout_mode}.min.css"
|
||||
),
|
||||
'all'
|
||||
);
|
||||
|
@ -247,15 +247,15 @@ class General {
|
|||
* After adding the alternative reference container, jQuery has become optional,
|
||||
* but still enabled by default.
|
||||
*/
|
||||
if ( ! self::$a_bool_amp_enabled ) {
|
||||
if ( ! self::$amp_enabled ) {
|
||||
|
||||
if ( 'jquery' === self::$a_str_script_mode || ( self::$a_bool_tooltips_enabled && ! self::$a_bool_alternative_tooltips_enabled ) ) {
|
||||
if ( 'jquery' === self::$script_mode || ( self::$tooltips_enabled && ! self::$alternative_tooltips_enabled ) ) {
|
||||
|
||||
wp_enqueue_script( 'jquery' );
|
||||
|
||||
}
|
||||
|
||||
if ( self::$a_bool_tooltips_enabled && ! self::$a_bool_alternative_tooltips_enabled ) {
|
||||
if ( self::$tooltips_enabled && ! self::$alternative_tooltips_enabled ) {
|
||||
/*
|
||||
* Enqueues the jQuery Tools library shipped with the plugin.
|
||||
*
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -77,11 +77,11 @@ abstract class Base extends \WP_Widget {
|
|||
* @since 1.5.0
|
||||
*/
|
||||
public function __construct() {
|
||||
$l_arr_widget_options = array(
|
||||
$widget_options = array(
|
||||
'classname' => __CLASS__,
|
||||
'description' => $this->get_description(),
|
||||
);
|
||||
$l_arr_control_options = array(
|
||||
$control_options = array(
|
||||
'id_base' => strtolower( $this->get_id() ),
|
||||
'width' => $this->get_widget_width(),
|
||||
);
|
||||
|
@ -89,8 +89,8 @@ abstract class Base extends \WP_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.
|
||||
$widget_options, // Optional Widget Options.
|
||||
$control_options // Optional Widget Control Options.
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -111,9 +111,9 @@ class Reference_Container extends Base {
|
|||
public function widget( $args, $instance ) {
|
||||
global $footnotes;
|
||||
// Reference container positioning is set to "widget area".
|
||||
if ( 'widget' === Includes\Settings::instance()->get( Includes\Settings::C_STR_REFERENCE_CONTAINER_POSITION ) ) {
|
||||
if ( 'widget' === Includes\Settings::instance()->get( Includes\Settings::REFERENCE_CONTAINER_POSITION ) ) {
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $footnotes->a_obj_task->reference_container();
|
||||
echo $footnotes->task->reference_container();
|
||||
// phpcs:enable
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue