diff --git a/src/admin/class-footnotes-admin.php b/src/admin/class-footnotes-admin.php new file mode 100644 index 0000000..687b7c2 --- /dev/null +++ b/src/admin/class-footnotes-admin.php @@ -0,0 +1,137 @@ +plugin_name = $plugin_name; + $this->version = $version; + + $this->load_dependencies(); + + } + + /** + * Load the required admin-specific dependencies. + * + * Include the following files that provide the admin-specific functionality + * of this plugin: + * + * - `Footnotes_WYSIWYG`. TODO + * - `Footnotes_Layout_Settings`. TODO + * + * @since 2.8.0 + * @access private + */ + private function load_dependencies() { + // TODO: neaten up and document once placements and names are settled. + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-footnotes-wysiwyg.php'; + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/layout/class-footnotes-layout-init.php'; + + new Footnotes_Layout_Init(); + } + + /** + * Register the stylesheets for the admin area. + * + * @since 2.8.0 + */ + public function enqueue_styles() { + + wp_enqueue_style( + $this->plugin_name, + plugin_dir_url( __FILE__ ) . 'css/settings' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.css', + array(), + ( PRODUCTION_ENV ) ? $this->version : filemtime( + plugin_dir_path( + dirname( __FILE__ ) + ) . 'css/settings.css' + ), + 'all' + ); + } + + /** + * Register the JavaScript for the admin area. + * + * @since 2.8.0 + */ + public function enqueue_scripts() { + + wp_enqueue_script( + $this->plugin_name, + plugin_dir_url( __FILE__ ) . 'js/wysiwyg-editor' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js', + array(), + ( PRODUCTION_ENV ) ? $this->version : filemtime( + plugin_dir_path( + dirname( __FILE__ ) + ) . 'js/wysiwyg-editor.js' + ), + false + ); + + } + + /** + * Appends the Plugin links for display in the dashboard Plugins page. + * + * @since 1.5.0 + * @since 2.8.0 Moved into `Footnote_Admin` class. + * @param array $plugin_links The WP-default set of links to display. + * @return string[] The full set of links to display. + */ + public static function get_plugin_links( array $plugin_links ): array { + // Append link to the WordPress Plugin page. + $plugin_links[] = sprintf( '%s', __( 'Support', 'footnotes' ) ); + // Append link to the settings page. + $plugin_links[] = sprintf( '%s', admin_url( 'options-general.php?page=footnotes' ), __( 'Settings', 'footnotes' ) ); + // Append link to the PayPal donate function. + $plugin_links[] = sprintf( '%s', __( 'Donate', 'footnotes' ) ); + // Return new links. + return $plugin_links; + } + +} + diff --git a/src/includes/wysiwyg.php b/src/admin/class-footnotes-wysiwyg.php similarity index 88% rename from src/includes/wysiwyg.php rename to src/admin/class-footnotes-wysiwyg.php index 7be3623..d45ae4d 100644 --- a/src/includes/wysiwyg.php +++ b/src/admin/class-footnotes-wysiwyg.php @@ -1,15 +1,16 @@ -run(); - - // Add the links to the dashboard plugins page. - // TODO: Move this somewhere more appropriate. - add_filter( 'plugin_action_links_footnotes/footnotes.php', array( 'Footnotes_Hooks', 'get_plugin_links' ), 10, 2 ); } run_footnotes(); diff --git a/src/includes/config.php b/src/includes/class-footnotes-config.php similarity index 96% rename from src/includes/config.php rename to src/includes/class-footnotes-config.php index 990fc3e..192cfc8 100644 --- a/src/includes/config.php +++ b/src/includes/class-footnotes-config.php @@ -1,4 +1,4 @@ -actions = array(); + $this->filters = array(); + + } + + /** + * Add a new action to the collection to be registered with WordPress. + * + * @since 2.8.0 + * @param string $hook The name of the WordPress action that is being registered. + * @param object $component A reference to the instance of the object on which the action is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority Optional. The priority at which the function should be fired. Default is 10. + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. + */ + public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { + $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); + } + + /** + * Add a new filter to the collection to be registered with WordPress. + * + * @since 2.8.0 + * @param string $hook The name of the WordPress filter that is being registered. + * @param object $component A reference to the instance of the object on which the filter is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority Optional. The priority at which the function should be fired. Default is 10. + * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. + */ + public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { + $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); + } + + /** + * Initializes all Widgets of the Plugin. + * + * @since 1.5.0 + * @since 2.8.0 Moved to `Footnotes_Loader` class. + */ + public function initialize_widgets() { + // TODO: This probably shouldn't be necessary here. + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/widget/class-footnotes-widget-reference-container.php'; + + register_widget( 'Footnotes_Widget_Reference_Container' ); + } + + /** + * A utility function that is used to register the actions and hooks into a single + * collection. + * + * @since 2.8.0 + * @access private + * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). + * @param string $hook The name of the WordPress filter that is being registered. + * @param object $component A reference to the instance of the object on which the filter is defined. + * @param string $callback The name of the function definition on the $component. + * @param int $priority The priority at which the function should be fired. + * @param int $accepted_args The number of arguments that should be passed to the $callback. + * @return array The collection of actions and filters registered with WordPress. + */ + private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { + + $hooks[] = array( + 'hook' => $hook, + 'component' => $component, + 'callback' => $callback, + 'priority' => $priority, + 'accepted_args' => $accepted_args, + ); + + return $hooks; + + } + + /** + * Register the filters and actions with WordPress. + * + * @since 2.8.0 + */ + public function run() { + + foreach ( $this->filters as $hook ) { + add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); + } + + foreach ( $this->actions as $hook ) { + add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); + } + + add_action( 'widgets_init', array( $this, 'initialize_widgets' ) ); + + } + +} diff --git a/src/includes/settings.php b/src/includes/class-footnotes-settings.php similarity index 99% rename from src/includes/settings.php rename to src/includes/class-footnotes-settings.php index 62c2dfa..1eb7f3f 100644 --- a/src/includes/settings.php +++ b/src/includes/class-footnotes-settings.php @@ -1,4 +1,4 @@ -version = C_STR_FOOTNOTES_VERSION; + } else { + $this->version = '0.0.0'; + } + $this->plugin_name = 'footnotes'; + + $this->load_dependencies(); + $this->set_locale(); + $this->define_admin_hooks(); + $this->define_public_hooks(); + + } + + /** + * Load the required dependencies for this plugin. + * + * Include the following files that make up the plugin: + * + * - Footnotes_Loader. Orchestrates the hooks of the plugin. + * - Footnotes_i18n. Defines internationalization functionality. + * - Footnotes_Admin. Defines all hooks for the admin area. + * - Footnotes_Public. Defines all hooks for the public side of the site. + * + * Create an instance of the loader which will be used to register the hooks + * with WordPress. + * + * @since 2.8.0 + * @access private + */ + private function load_dependencies() { + + /** + * The class responsible for orchestrating the actions and filters of the + * core plugin. + */ + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-loader.php'; + + /** + * The class responsible for defining internationalization functionality + * of the plugin. + */ + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-i18n.php'; + // TODO: neaten up and document once placements and names are settled. + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-config.php'; + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-convert.php'; + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-settings.php'; + + /** + * The class responsible for defining all actions that occur in the admin area. + */ + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-footnotes-admin.php'; + + /** + * The class responsible for defining all actions that occur in the public-facing + * side of the site. + */ + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-footnotes-public.php'; + + $this->loader = new Footnotes_Loader(); + + } + + /** + * Define the locale for this plugin for internationalization. + * + * Uses the `Footnotes_i18n` class in order to set the domain and to register the hook + * with WordPress. + * + * @since 2.8.0 + * @access private + */ + private function set_locale() { + + $plugin_i18n = new Footnotes_i18n(); + + $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); + + } + + /** + * Register all of the hooks related to the admin area functionality + * of the plugin. + * + * @since 2.8.0 + * @access private + */ + private function define_admin_hooks() { + + $plugin_admin = new Footnotes_Admin( $this->get_plugin_name(), $this->get_version() ); + + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); + + $this->loader->add_filter( 'admin_get_plugin_links', $plugin_admin, 'get_plugin_links', 10, 1 ); + + } + + /** + * Register all of the hooks related to the public-facing functionality + * of the plugin. + * + * @since 2.8.0 + * @access private + */ + private function define_public_hooks() { + + $plugin_public = new Footnotes_Public( $this->get_plugin_name(), $this->get_version() ); + + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); + } + + /** + * Run the loader to execute all of the hooks with WordPress. * * @since 1.5.0 - * @var Task $task The Plugin task. - */ - public $a_obj_task = null; - - /** - * Flag for using tooltips. - * - * @since 2.4.0 - * - * @var bool $tooltips_enabled Whether tooltips are enabled or not. - */ - public static $a_bool_tooltips_enabled = false; - - /** - * Allows to determine whether alternative tooltips are enabled. - * - * - Bugfix: Tooltips: optional alternative JS implementation with CSS transitions to fix configuration-related outage, thanks to @andreasra feedback. - * - * @since 2.1.1 - * - * @reporter @andreasra - * @link https://wordpress.org/support/topic/footnotes-appearing-in-header/page/2/#post-13632566 - * - * @since 2.4.0 - * @contributor Patrizia Lutz @misfist - * @var bool - */ - public static $a_bool_alternative_tooltips_enabled = false; - - /** - * Allows to determine whether AMP compatibility mode is enabled. - * - * - Adding: Tooltips: make display work purely by style rules for AMP compatibility, thanks to @milindmore22 code contribution. - * - Bugfix: Tooltips: enable accessibility by keyboard navigation, thanks to @westonruter code contribution. - * - Adding: Reference container: get expanding and collapsing to work also in AMP compatibility mode, thanks to @westonruter code contribution. - * - * @since 2.5.11 (draft) - * @since 2.6.0 (release) - * - * @contributor @milindmore22 - * @link https://github.com/ampproject/amp-wp/issues/5913#issuecomment-785306933 - * - * @contributor @westonruter - * @link https://github.com/ampproject/amp-wp/issues/5913#issuecomment-785419655 - * @link https://github.com/markcheret/footnotes/issues/48#issuecomment-799580854 - * @link https://github.com/markcheret/footnotes/issues/48#issuecomment-799582394 - * - * @var bool - */ - public static $a_bool_amp_enabled = false; - - /** - * Allows to determine the script mode among jQuery or plain JS. - * - * - Bugfix: Reference container: optional alternative expanding and collapsing without jQuery for use with hard links, thanks to @hopper87it @pkverma99 issue reports. - * - * @since 2.5.6 - * - * @reporter @hopper87it - * @link https://wordpress.org/support/topic/footnotes-wp-rocket/ - * - * @reporter @pkverma99 - * @link https://wordpress.org/support/topic/footnotes-wp-rocket/#post-14076188 - * - * @var str 'js' Plain JavaScript. - * 'jquery' Use jQuery libraries. - */ - public static $a_str_script_mode = 'js'; - - /** - * Executes the Plugin. - * - * @since 1.5.0 - * - * - Bugfix: Improve widgets registration, thanks to @felipelavinz code contribution. - * - * @since 1.6.5 - * - * @contributor @felipelavinz - * @link https://github.com/benleyjyc/footnotes/commit/87173d2980c7ff90e12ffee94ca7153e11163793 - * @link https://github.com/media-competence-institute/footnotes/commit/87173d2980c7ff90e12ffee94ca7153e11163793 * * @see self::initialize_widgets() */ public function run() { - // Register language. - Footnotes_Language::register_hooks(); - // Register Button hooks. - Footnotes_WYSIWYG::register_hooks(); - // Register general hooks. - Footnotes_Hooks::register_hooks(); - - // Initialize the Plugin Dashboard. - $this->initialize_dashboard(); - // Initialize the Plugin Task. - $this->initialize_task(); - - // Register all Public Stylesheets and Scripts. - add_action( 'init', array( $this, 'register_public' ) ); - // Enqueue all Public Stylesheets and Scripts. - add_action( 'wp_enqueue_scripts', array( $this, 'register_public' ) ); - // Register all Widgets of the Plugin.. - add_action( 'widgets_init', array( $this, 'initialize_widgets' ) ); + $this->loader->run(); } /** - * Initializes all Widgets of the Plugin. + * The name of the plugin used to uniquely identify it within the context of + * WordPress and to define internationalization functionality. * - * @since 1.5.0 - * - * - Update: Fix for deprecated PHP function create_function(), thanks to @psykonevro @daliasued bug reports, thanks to @felipelavinz code contribution - * - * @since 1.6.5 - * - * @contributor @felipelavinz - * @link https://github.com/media-competence-institute/footnotes/commit/87173d2980c7ff90e12ffee94ca7153e11163793 - * - * @reporter @psykonevro - * @link https://wordpress.org/support/topic/bug-function-create_function-is-deprecated/ - * @link https://wordpress.org/support/topic/deprecated-function-create_function-14/ - * - * @reporter @daliasued - * @link https://wordpress.org/support/topic/deprecated-function-create_function-14/#post-13312853 - * - * create_function() was deprecated in PHP 7.2.0 and removed in PHP 8.0.0. - * @link https://www.php.net/manual/en/function.create-function.php - * - * The fix is to move add_action() above into run(), - * and use the bare register_widget() here. - * @see self::run() - * - * Also, the visibility of initialize_widgets() is not private any longer. + * @since 1.0.0 + * @return string The name of the plugin. */ - public function initialize_widgets() { - register_widget( 'Footnotes_Widget_Reference_Container' ); + public function get_plugin_name() { + return $this->plugin_name; } /** - * Initializes the Dashboard of the Plugin and loads them. + * The reference to the class that orchestrates the hooks with the plugin. * - * @since 1.5.0 + * @since 1.0.0 + * @return Footnotes_Loader Orchestrates the hooks of the plugin. */ - private function initialize_dashboard() { - new Footnotes_Layout_Init(); + public function get_loader() { + return $this->loader; } /** - * Initializes the Plugin Task and registers the Task hooks. + * Retrieve the version number of the plugin. * - * @since 1.5.0 + * @since 1.0.0 + * @return string The version number of the plugin. */ - private function initialize_task() { - $this->a_obj_task = new Footnotes_Task(); - $this->a_obj_task->register_hooks(); - } - - /** - * Registers and enqueues scripts and stylesheets to the public pages. - * - * @since 1.5.0 - * - * @since 2.0.0 Update: Tooltips: fix disabling bug by loading jQuery UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution. - * @since 2.0.3 add versioning of public.css for cache busting - * @since 2.0.4 add jQuery UI from WordPress - * @since 2.1.4 automate passing version number for cache busting - * @since 2.1.4 optionally enqueue an extra stylesheet - */ - public function register_public() { - - /** - * Enqueues external scripts. - * - * - Bugfix: Libraries: optimize processes by loading external and internal scripts only if needed, thanks to @docteurfitness issue report. - * - * @since 2.5.5 - * @reporter @docteurfitness - * @link https://wordpress.org/support/topic/simply-speed-optimisation/ - * - * The condition about tooltips was missing, only the not-alternative-tooltips part was present. - */ - // Set conditions re-used for stylesheet enqueuing and in class/task.php. - self::$a_bool_amp_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_AMP_COMPATIBILITY_ENABLE ) ); - self::$a_bool_tooltips_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_MOUSE_OVER_BOX_ENABLED ) ); - self::$a_bool_alternative_tooltips_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_MOUSE_OVER_BOX_ALTERNATIVE ) ); - self::$a_str_script_mode = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE ); - - /** - * Enqueues the jQuery library registered by WordPress. - * - * - Bugfix: Reference container: optional alternative expanding and collapsing without jQuery for use with hard links, thanks to @hopper87it @pkverma99 issue reports. - * - * @since 2.5.6 - * - * @reporter @hopper87it - * @link https://wordpress.org/support/topic/footnotes-wp-rocket/ - * - * jQuery is also used for animated scrolling, so it was loaded by default. - * The function wp_enqueue_script() avoids loading the same library multiple times. - * After adding the alternative reference container, jQuery has become optional, - * but still enabled by default. - */ - if ( ! self::$a_bool_amp_enabled ) { - - if ( 'jquery' === self::$a_str_script_mode || ( self::$a_bool_tooltips_enabled && ! self::$a_bool_alternative_tooltips_enabled ) ) { - - wp_enqueue_script( 'jquery' ); - - } - - if ( self::$a_bool_tooltips_enabled && ! self::$a_bool_alternative_tooltips_enabled ) { - - /** - * Enqueues the jQuery Tools library shipped with the plugin. - * - * Redacted jQuery.browser, completed minification; - * see full header in js/jquery.tools.js. - * - * Add versioning. - * - * @since 2.1.2 - * - * No '-js' in the handle, is appended automatically. - * - * Deferring to the footer breaks jQuery tooltip display. - */ - wp_enqueue_script( - 'footnotes-jquery-tools', - plugins_url( 'footnotes/public/js/jquery.tools' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js' ), - array(), - '1.2.7.redacted.2', - false - ); - - /** - * Enqueues some jQuery UI libraries registered by WordPress. - * - * - Update: Tooltips: fix disabling bug by loading jQuery UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution. - * - * @since 2.0.0 - * - * @reporter @rajinderverma - * @link https://wordpress.org/support/topic/tooltip-hover-not-showing/ - * - * @reporter @ericcorbett2 - * @link https://wordpress.org/support/topic/tooltip-hover-not-showing/#post-13324142 - * - * @reporter @honlapdavid - * @link https://wordpress.org/support/topic/tooltip-hover-not-showing/#post-13355421 - * - * @reporter @mmallett - * @link https://wordpress.org/support/topic/tooltip-hover-not-showing/#post-13445437 - * - * Fetch jQuery UI from cdnjs.cloudflare.com. - * @since 2.0.0 - * @contributor @vonpiernik - * @link https://wordpress.org/support/topic/tooltip-hover-not-showing/#post-13456762 - * - * jQueryUI re-enables the tooltip infobox disabled when WPv5.5 was released. * @since 2.1.2 - * - * - Update: Libraries: Load jQuery UI from WordPress, thanks to @check2020de issue report. - * - * @since 2.0.4 - * @reporter @check2020de - * @link https://wordpress.org/support/topic/gdpr-issue-with-jquery/ - * @link https://wordpress.stackexchange.com/questions/273986/correct-way-to-enqueue-jquery-ui - * - * If alternative tooltips are enabled, these libraries are not needed. - */ - wp_enqueue_script( 'jquery-ui-core' ); - wp_enqueue_script( 'jquery-ui-widget' ); - wp_enqueue_script( 'jquery-ui-position' ); - wp_enqueue_script( 'jquery-ui-tooltip' ); - - } - } - - /** - * Enables enqueuing a new-scheme stylesheet. - * - * @since 2.5.5 - * - * Enables enqueuing the formatted individual stylesheets if false. - * WARNING: This facility is designed for development and must NOT be used in production. - * - * The Boolean may be set at the bottom of the plugin’s main PHP file. - * @see footnotes.php - */ - if ( PRODUCTION_ENV ) { - - /** - * Enqueues a minified united external stylesheet in production. - * - * - Update: Stylesheets: increase speed and energy efficiency by tailoring stylesheets to the needs of the instance, thanks to @docteurfitness design contribution. - * - Bugfix: Stylesheets: minify to shrink the carbon footprint, increase speed and implement best practice, thanks to @docteurfitness issue report. - * - * @since 2.5.5 - * - * @contributor @docteurfitness - * @link https://wordpress.org/support/topic/simply-speed-optimisation/ - * - * @reporter @docteurfitness - * @link https://wordpress.org/support/topic/simply-speed-optimisation/ - * - * The dashboard stylesheet is minified as-is. - * @see class/dashboard/layout.php - * - * @since 2.0.3 add versioning of public.css for cache busting. - * Plugin version number is needed for busting browser caches after each plugin update. - * - * @since 2.1.4 automate passing version number for cache busting. - * The constant C_STR_FOOTNOTES_VERSION is defined at start of footnotes.php. - * - * The media scope argument 'all' is the default. - * No need to use '-css' in the handle, as this is appended automatically. - */ - // Set tooltip mode for use in stylesheet name. - if ( self::$a_bool_tooltips_enabled ) { - - if ( self::$a_bool_amp_enabled ) { - $l_str_tooltip_mode_short = 'ampt'; - $l_str_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'; - - } else { - $l_str_tooltip_mode_short = 'jqtt'; - $l_str_tooltip_mode_long = 'jquery-tooltips'; - - } - } else { - $l_str_tooltip_mode_short = 'nott'; - $l_str_tooltip_mode_long = 'no-tooltips'; - } - - // Set basic responsive page layout mode for use in stylesheet name. - $l_str_page_layout_option = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT ); - switch ( $l_str_page_layout_option ) { - case 'reference-container': - $l_str_layout_mode = '1'; - break; - case 'entry-content': - $l_str_layout_mode = '2'; - break; - case 'main-content': - $l_str_layout_mode = '3'; - break; - case 'none': - default: - $l_str_layout_mode = '0'; - break; - } - - // Enqueue the tailored united minified stylesheet. - wp_enqueue_style( - 'footnotes-' . $l_str_tooltip_mode_long . '-pagelayout-' . $l_str_page_layout_option, - plugins_url( - Footnotes_Config::C_STR_PLUGIN_NAME . '/css/footnotes-' . $l_str_tooltip_mode_short . 'brpl' . $l_str_layout_mode . '.min.css' - ), - array(), - C_STR_FOOTNOTES_VERSION, - 'all' - ); - - } else { - - /** - * Enqueues external stylesheets, ONLY in development now. - * - * @since 2.1.4 optionally enqueue an extra stylesheet. - * - * This optional layout fix is useful by lack of layout support. - */ - wp_enqueue_style( - 'footnotes-common', - plugins_url( Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-common.css' ), - array(), - filemtime( - plugin_dir_path( - dirname( __FILE__, 1 ) - ) . 'css/dev-common.css' - ) - ); - wp_enqueue_style( - 'footnotes-tooltips', - plugins_url( Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-tooltips.css' ), - array(), - filemtime( - plugin_dir_path( - dirname( __FILE__, 1 ) - ) . 'css/dev-tooltips.css' - ) - ); - - if ( self::$a_bool_amp_enabled ) { - wp_enqueue_style( - 'footnotes-amp', - plugins_url( Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-amp-tooltips.css' ), - array(), - filemtime( - plugin_dir_path( - dirname( __FILE__, 1 ) - ) . 'css/dev-amp-tooltips.css' - ) - ); - } - - if ( self::$a_bool_alternative_tooltips_enabled ) { - wp_enqueue_style( - 'footnotes-alternative', - plugins_url( Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-tooltips-alternative.css' ), - array(), - filemtime( - plugin_dir_path( - dirname( __FILE__, 1 ) - ) . 'css/dev-tooltips-alternative.css' - ) - ); - } - - $l_str_page_layout_option = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT ); - if ( 'none' !== $l_str_page_layout_option ) { - wp_enqueue_style( - 'footnotes-layout-' . $l_str_page_layout_option, - plugins_url( - Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-layout-' . $l_str_page_layout_option . '.css' - ), - array(), - filemtime( - plugin_dir_path( - dirname( __FILE__, 1 ) - ) . 'css/dev-layout-' . $l_str_page_layout_option . '.css' - ), - 'all' - ); - } - } + public function get_version() { + return $this->version; } } diff --git a/src/includes/hooks.php b/src/includes/hooks.php deleted file mode 100644 index fdc321c..0000000 --- a/src/includes/hooks.php +++ /dev/null @@ -1,67 +0,0 @@ -%s', __( 'Support', 'footnotes' ) ); - // Append link to the settings page. - $plugin_links[] = sprintf( '%s', admin_url( 'options-general.php?page=footnotes' ), __( 'Settings', 'footnotes' ) ); - // Append link to the PayPal donate function. - $plugin_links[] = sprintf( '%s', __( 'Donate', 'footnotes' ) ); - // Return new links. - return $plugin_links; - } -} diff --git a/src/includes/language.php b/src/includes/language.php deleted file mode 100644 index 56696cc..0000000 --- a/src/includes/language.php +++ /dev/null @@ -1,99 +0,0 @@ -plugin_name = $plugin_name; + $this->version = $version; + + $this->load_dependencies(); + + // Set conditions re-used for stylesheet enqueuing and in class/task.php. + self::$a_bool_amp_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_AMP_COMPATIBILITY_ENABLE ) ); + self::$a_bool_tooltips_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_MOUSE_OVER_BOX_ENABLED ) ); + self::$a_bool_alternative_tooltips_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_MOUSE_OVER_BOX_ALTERNATIVE ) ); + self::$a_str_script_mode = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE ); + } + + /** + * Load the required public-facing dependencies. + * + * Include the following files that provide the public-facing functionality + * of this plugin: + * + * - `Footnotes_Task`. TODO + * - `Footnotes_Widget_Reference_Container`. TODO + * + * @since 2.8.0 + * @access private + */ + private function load_dependencies() { + // TODO: neaten up and document once placements and names are settled. + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-config.php'; + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-settings.php'; + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-convert.php'; + + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-footnotes-task.php'; + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/widget/class-footnotes-widget-base.php'; + + $this->a_obj_task = new Footnotes_Task(); + } + + /** + * Register the stylesheets for the public-facing side of the site. + * + * @since 2.8.0 + */ + public function enqueue_styles() { + /** + * Enables enqueuing a new-scheme stylesheet. + * + * Enables enqueuing the formatted individual stylesheets if false. + * WARNING: This facility is designed for development and must NOT be used in production. + * + * The Boolean may be set at the bottom of the plugin's main PHP file. + * + * @see footnotes.php + * + * @since 2.5.5 + * @since 2.8.0 Moved into `Footnotes_Public` class. + */ + if ( PRODUCTION_ENV ) { + + /** + * Enqueues a minified united external stylesheet in production. + * + * The media scope argument 'all' is the default. + * No need to use '-css' in the handle, as this is appended automatically. + * + * @since 2.5.5 + * @since 2.8.0 Moved into `Footnotes_Public` class. + */ + // Set tooltip mode for use in stylesheet name. + if ( self::$a_bool_tooltips_enabled ) { + + if ( self::$a_bool_amp_enabled ) { + $l_str_tooltip_mode_short = 'ampt'; + $l_str_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'; + + } else { + $l_str_tooltip_mode_short = 'jqtt'; + $l_str_tooltip_mode_long = 'jquery-tooltips'; + + } + } else { + $l_str_tooltip_mode_short = 'nott'; + $l_str_tooltip_mode_long = 'no-tooltips'; + } + + // Set basic responsive page layout mode for use in stylesheet name. + $l_str_page_layout_option = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT ); + switch ( $l_str_page_layout_option ) { + case 'reference-container': + $l_str_layout_mode = '1'; + break; + case 'entry-content': + $l_str_layout_mode = '2'; + break; + case 'main-content': + $l_str_layout_mode = '3'; + break; + case 'none': + default: + $l_str_layout_mode = '0'; + break; + } + + // Enqueue the tailored united minified stylesheet. + 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", + array(), + ( PRODUCTION_ENV ) ? $this->version : filemtime( + plugin_dir_path( + dirname( __FILE__ ) + ) . "css/footnotes-{$l_str_tooltip_mode_short}brpl{$l_str_layout_mode}.min.css" + ), + 'all' + ); + } + } + + /** + * Register the JavaScript for the public-facing side of the site. + * + * @since 2.8.0 + */ + public function enqueue_scripts() { + /** + * Enqueues the jQuery library registered by WordPress. + * + * As jQuery is also used for animated scrolling, it was loaded by default. + * The function `wp_enqueue_script()` avoids loading the same library multiple times. + * After adding the alternative reference container, jQuery has become optional, + * but still enabled by default. + * + * @since 2.5.6 + * @since 2.8.0 Moved into `Footnotes_Public` class. + */ + if ( ! self::$a_bool_amp_enabled ) { + + if ( 'jquery' === self::$a_str_script_mode || ( self::$a_bool_tooltips_enabled && ! self::$a_bool_alternative_tooltips_enabled ) ) { + + wp_enqueue_script( 'jquery' ); + + } + + if ( self::$a_bool_tooltips_enabled && ! self::$a_bool_alternative_tooltips_enabled ) { + /** + * Enqueues the jQuery Tools library shipped with the plugin. + * + * Redacted jQuery.browser, completed minification; + * see full header in `public/js/jquery.tools.js`. + * No '-js' in the handle, is appended automatically. + * Deferring to the footer breaks jQuery tooltip display. + * + * Add versioning. + * + * @since 2.1.2 + * @since 2.8.0 Moved into `Footnotes_Public` class. + */ + wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/jquery.tools' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js', array(), '1.2.7.redacted.2', false ); + + /** + * Enqueues some jQuery UI libraries registered by WordPress. + * + * If alternative tooltips are enabled, these libraries are not needed. + * + * @since 2.0.0 + * @since 2.8.0 Moved into `Footnotes_Public` class. + */ + wp_enqueue_script( 'jquery-ui-core' ); + wp_enqueue_script( 'jquery-ui-widget' ); + wp_enqueue_script( 'jquery-ui-position' ); + wp_enqueue_script( 'jquery-ui-tooltip' ); + + } + } + + } + +} + diff --git a/src/includes/task.php b/src/public/class-footnotes-task.php similarity index 98% rename from src/includes/task.php rename to src/public/class-footnotes-task.php index 9e10d1e..818e689 100644 --- a/src/includes/task.php +++ b/src/public/class-footnotes-task.php @@ -1,4 +1,4 @@ -register_hooks(); + } + /** * Register WordPress hooks to replace Footnotes in the content of a public page. * @@ -421,7 +427,6 @@ class Footnotes_Task { * @since 2.5.1 Bugfix: Hooks: support footnotes in Popup Maker popups, thanks to @squatcher bug report. */ public function register_hooks() { - // Get values from settings. $l_int_the_title_priority = intval( Footnotes_Settings::instance()->get( Footnotes_Settings::C_INT_EXPERT_LOOKUP_THE_TITLE_PRIORITY_LEVEL ) ); $l_int_the_content_priority = intval( Footnotes_Settings::instance()->get( Footnotes_Settings::C_INT_EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL ) ); @@ -762,7 +767,7 @@ class Footnotes_Task { self::$a_bool_hard_links_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_HARD_LINKS_ENABLE ) ); // Correct hard links enabled status depending on AMP compatible or alternative reference container enabled status. - if ( Footnotes::$a_bool_amp_enabled || 'jquery' !== Footnotes::$a_str_script_mode ) { + if ( Footnotes_Public::$a_bool_amp_enabled || 'jquery' !== Footnotes_Public::$a_str_script_mode ) { self::$a_bool_hard_links_enabled = true; } @@ -776,7 +781,7 @@ class Footnotes_Task { /* * Tooltips. */ - if ( Footnotes::$a_bool_tooltips_enabled ) { + if ( Footnotes_Public::$a_bool_tooltips_enabled ) { echo '.footnote_tooltip {'; /** @@ -856,7 +861,7 @@ class Footnotes_Task { * * @since 2.2.5 */ - if ( ! Footnotes::$a_bool_alternative_tooltips_enabled && ! Footnotes::$a_bool_amp_enabled ) { + if ( ! Footnotes_Public::$a_bool_alternative_tooltips_enabled && ! Footnotes_Public::$a_bool_amp_enabled ) { /** * Dimensions of jQuery tooltips. @@ -932,7 +937,7 @@ class Footnotes_Task { * * @see dev-amp-tooltips.css. */ - if ( Footnotes::$a_bool_amp_enabled ) { + if ( Footnotes_Public::$a_bool_amp_enabled ) { echo 'span.footnote_referrer > span.footnote_tooltip {'; echo 'transition-delay: ' . $l_int_fade_out_delay . 'ms;'; @@ -997,7 +1002,7 @@ class Footnotes_Task { * The script for alternative tooltips is printed formatted, not minified, * for transparency. It isn’t indented though (the PHP open tag neither). */ - if ( Footnotes::$a_bool_alternative_tooltips_enabled ) { + if ( Footnotes_Public::$a_bool_alternative_tooltips_enabled ) { // Start internal script. ?> @@ -1727,7 +1732,7 @@ class Footnotes_Task { if ( ! $p_bool_hide_footnotes_text ) { // Whether AMP compatibility mode is enabled. - if ( Footnotes::$a_bool_amp_enabled ) { + if ( Footnotes_Public::$a_bool_amp_enabled ) { // Whether first clicking a referrer needs to expand the reference container. if ( Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_REFERENCE_CONTAINER_COLLAPSE ) ) ) { @@ -1740,7 +1745,7 @@ class Footnotes_Task { // Load 'public/partials/amp-footnote.html'. $l_obj_template = new Footnotes_Template( Footnotes_Template::C_STR_PUBLIC, 'amp-footnote' ); } - } elseif ( Footnotes::$a_bool_alternative_tooltips_enabled ) { + } elseif ( Footnotes_Public::$a_bool_alternative_tooltips_enabled ) { // Load 'public/partials/footnote-alternative.html'. $l_obj_template = new Footnotes_Template( Footnotes_Template::C_STR_PUBLIC, 'footnote-alternative' ); @@ -1964,7 +1969,7 @@ class Footnotes_Task { * This is equivalent to the WordPress default excerpt generation, i.e. without a * custom excerpt and without a delimiter. But WordPress does word count, usually 55. */ - if ( Footnotes::$a_bool_tooltips_enabled && $l_bool_enable_excerpt ) { + if ( Footnotes_Public::$a_bool_tooltips_enabled && $l_bool_enable_excerpt ) { $l_str_dummy_text = wp_strip_all_tags( $l_str_footnote_text ); if ( is_int( $l_int_max_length ) && strlen( $l_str_dummy_text ) > $l_int_max_length ) { $l_str_excerpt_text = substr( $l_str_dummy_text, 0, $l_int_max_length ); @@ -1974,7 +1979,7 @@ class Footnotes_Task { $l_str_excerpt_text .= ' class="footnote_tooltip_continue" '; // If AMP compatibility mode is enabled. - if ( Footnotes::$a_bool_amp_enabled ) { + if ( Footnotes_Public::$a_bool_amp_enabled ) { // If the reference container is also collapsed by default. if ( Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_REFERENCE_CONTAINER_COLLAPSE ) ) ) { @@ -2097,7 +2102,7 @@ class Footnotes_Task { } // Determine tooltip content. - if ( Footnotes::$a_bool_tooltips_enabled ) { + if ( Footnotes_Public::$a_bool_tooltips_enabled ) { $l_str_tooltip_content = $l_bool_has_tooltip_text ? $l_str_tooltip_text : $l_str_excerpt_text; /** * Ensures paragraph separation @@ -2119,7 +2124,7 @@ class Footnotes_Task { * @since 2.5.6 */ $l_str_tooltip_style = ''; - if ( Footnotes::$a_bool_alternative_tooltips_enabled && Footnotes::$a_bool_tooltips_enabled ) { + if ( Footnotes_Public::$a_bool_alternative_tooltips_enabled && Footnotes_Public::$a_bool_tooltips_enabled ) { $l_int_tooltip_length = strlen( wp_strip_all_tags( $l_str_tooltip_content ) ); if ( $l_int_tooltip_length < 70 ) { $l_str_tooltip_style = ' style="width: '; @@ -2151,7 +2156,7 @@ class Footnotes_Task { $l_obj_template->reload(); // If tooltips are enabled but neither AMP nor alternative are. - if ( Footnotes::$a_bool_tooltips_enabled && ! Footnotes::$a_bool_amp_enabled && ! Footnotes::$a_bool_alternative_tooltips_enabled ) { + if ( Footnotes_Public::$a_bool_tooltips_enabled && ! Footnotes_Public::$a_bool_amp_enabled && ! Footnotes_Public::$a_bool_alternative_tooltips_enabled ) { $l_int_offset_y = intval( Footnotes_Settings::instance()->get( Footnotes_Settings::C_INT_FOOTNOTES_MOUSE_OVER_BOX_OFFSET_Y ) ); $l_int_offset_x = intval( Footnotes_Settings::instance()->get( Footnotes_Settings::C_INT_FOOTNOTES_MOUSE_OVER_BOX_OFFSET_X ) ); @@ -2418,7 +2423,7 @@ class Footnotes_Task { $l_bool_combine_identical_footnotes = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_COMBINE_IDENTICAL_FOOTNOTES ) ); // AMP compatibility requires a full set of AMP compatible table row templates. - if ( Footnotes::$a_bool_amp_enabled ) { + if ( Footnotes_Public::$a_bool_amp_enabled ) { // When combining identical footnotes is turned on, another template is needed. if ( $l_bool_combine_identical_footnotes ) { @@ -2802,7 +2807,7 @@ class Footnotes_Task { // Select the reference container template. // Whether AMP compatibility mode is enabled. - if ( Footnotes::$a_bool_amp_enabled ) { + if ( Footnotes_Public::$a_bool_amp_enabled ) { // Whether the reference container is collapsed by default. if ( Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_REFERENCE_CONTAINER_COLLAPSE ) ) ) { @@ -2815,7 +2820,7 @@ class Footnotes_Task { // Load 'public/partials/amp-reference-container.html'. $l_obj_template_container = new Footnotes_Template( Footnotes_Template::C_STR_PUBLIC, 'amp-reference-container' ); } - } elseif ( 'js' === Footnotes::$a_str_script_mode ) { + } elseif ( 'js' === Footnotes_Public::$a_str_script_mode ) { // Load 'public/partials/js-reference-container.html'. $l_obj_template_container = new Footnotes_Template( Footnotes_Template::C_STR_PUBLIC, 'js-reference-container' ); @@ -2832,7 +2837,7 @@ class Footnotes_Task { $l_int_scroll_up_delay = ''; $l_int_scroll_up_duration = ''; - if ( 'jquery' === Footnotes::$a_str_script_mode ) { + if ( 'jquery' === Footnotes_Public::$a_str_script_mode ) { $l_int_scroll_offset = ( self::$a_int_scroll_offset / 100 ); $l_int_scroll_up_duration = intval( Footnotes_Settings::instance()->get( Footnotes_Settings::C_INT_FOOTNOTES_SCROLL_DURATION ) ); diff --git a/src/includes/widgets/base.php b/src/public/widget/class-footnotes-widget-base.php similarity index 97% rename from src/includes/widgets/base.php rename to src/public/widget/class-footnotes-widget-base.php index f27eacc..9dded2a 100644 --- a/src/includes/widgets/base.php +++ b/src/public/widget/class-footnotes-widget-base.php @@ -1,4 +1,4 @@ -