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