diff --git a/bootstrap/define.php b/bootstrap/define.php index 5ae5a474..dfceb0c5 100644 --- a/bootstrap/define.php +++ b/bootstrap/define.php @@ -22,6 +22,13 @@ * along with this program. If not, see . */ +/** + * Tells the world the plugin is present and to be used. + * + * @since 2.4.1 + */ +define( 'TSF_EXTENSION_MANAGER_PRESENT', true ); + /** * NOTE: * The definable constants should be defined in `wp-config.php`. diff --git a/bootstrap/envtest.php b/bootstrap/envtest.php index 6f8c3797..8e93eaf8 100644 --- a/bootstrap/envtest.php +++ b/bootstrap/envtest.php @@ -42,6 +42,7 @@ * @since 2.1.0 Now requires WordPress 4.8+, from 4.7+. * @since 2.2.0 1. Now requires WordPress 4.9+, from 4.7+. * 2. Now requires PHP 5.6+, from 5.5+. + * @since 2.4.1 Now requires WordPress 5.1+, from 4.9+. * @access private * @link http://php.net/eol.php * @link https://codex.wordpress.org/WordPress_Versions @@ -67,7 +68,7 @@ function tsf_extension_manager_pre_boot_test() { $requirements = array( 'php' => 50605, - 'wp' => '4.9-dev', + 'wp' => '5.1-dev', ); // phpcs:disable, Generic.Formatting.MultipleStatementAlignment, WordPress.WhiteSpace.PrecisionAlignment @@ -114,7 +115,7 @@ function tsf_extension_manager_pre_boot_test() { case 2: //* WordPress requirements not met. - $requirement = 'WordPress 4.9 or later'; + $requirement = 'WordPress 5.1 or later'; $issue = 'WordPress version'; $version = $GLOBALS['wp_version']; $subtitle = 'WordPress Requirements'; diff --git a/bootstrap/load.php b/bootstrap/load.php index b40fae69..3dcd955d 100644 --- a/bootstrap/load.php +++ b/bootstrap/load.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager; -defined( 'TSF_EXTENSION_MANAGER_PLUGIN_BASE_FILE' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PLUGIN_BASE_FILE' ) or die; /** * The SEO Framework - Extension Manager plugin @@ -66,7 +66,7 @@ function _init_locale( $ignore = false ) { */ function _protect_options() { - defined( 'PHP_INT_MIN' ) or define( 'PHP_INT_MIN', ~ PHP_INT_MAX ); + \defined( 'PHP_INT_MIN' ) or \define( 'PHP_INT_MIN', ~ PHP_INT_MAX ); $current_options = (array) \get_option( TSF_EXTENSION_MANAGER_SITE_OPTIONS, [] ); @@ -125,7 +125,7 @@ function _pre_execute_protect_option( $new_value, $old_value, $option ) { */ function _init_tsf_extension_manager() { - //* Cache the class object. Do not run everything more than once. + // Cache the class object. Do not run everything more than once. static $tsf_extension_manager = null; if ( $tsf_extension_manager ) @@ -152,7 +152,7 @@ function _init_tsf_extension_manager() { $tsf_extension_manager = new LoadFront; } - //* Initialize extensions. + // Initialize extensions. $tsf_extension_manager->_init_extensions(); /** @@ -182,7 +182,7 @@ function _init_tsf_extension_manager() { */ function _register_autoloader() { - //* Prevent overriding of security classes by checking their existence. + // Prevent overriding of security classes by checking their existence. $integrity_classes = [ '\TSF_Extension_Manager\Core', '\TSF_Extension_Manager\Secure_Abstract', diff --git a/bootstrap/update.php b/bootstrap/update.php index 78549af5..d1baeccc 100644 --- a/bootstrap/update.php +++ b/bootstrap/update.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager; -defined( 'TSF_EXTENSION_MANAGER_PLUGIN_BASE_FILE' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PLUGIN_BASE_FILE' ) or die; \add_action( 'tsfem_needs_the_seo_framework', __NAMESPACE__ . '\\_prepare_tsf_installer' ); /** @@ -157,12 +157,12 @@ function _check_external_blocking() { if ( ! \current_user_can( 'update_plugins' ) ) return; - if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && true === WP_HTTP_BLOCK_EXTERNAL ) { + if ( \defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && true === WP_HTTP_BLOCK_EXTERNAL ) { $parsed_url = \wp_parse_url( TSF_EXTENSION_MANAGER_DL_URI ); $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : ''; - if ( ! defined( 'WP_ACCESSIBLE_HOSTS' ) || false === stristr( WP_ACCESSIBLE_HOSTS, $host ) ) { + if ( ! \defined( 'WP_ACCESSIBLE_HOSTS' ) || false === stristr( WP_ACCESSIBLE_HOSTS, $host ) ) { $notice = \the_seo_framework()->convert_markdown( sprintf( /* translators: Markdown. %s = Update API URL */ diff --git a/bootstrap/upgrade.php b/bootstrap/upgrade.php index cdd9d14f..d206c784 100644 --- a/bootstrap/upgrade.php +++ b/bootstrap/upgrade.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager; -defined( 'TSF_EXTENSION_MANAGER_DB_VERSION' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_DB_VERSION' ) or die; /** * The SEO Framework - Extension Manager plugin @@ -38,10 +38,9 @@ */ function _do_critical_core_upgrade( Upgrader $upgrader ) { + // phpcs:disable -- Example with unused variable. $version = $upgrader->get_current_version( 'core' ); - // phpcs:disable - // Example: // if ( $version < 1500 ) { // $upgrader->_register_upgrade( 'core', '1500', function( $version ) { return (bool) $success; } ); diff --git a/bootstrap/upgrader.class.php b/bootstrap/upgrader.class.php index ac5196b4..08774a84 100644 --- a/bootstrap/upgrader.class.php +++ b/bootstrap/upgrader.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager; -defined( 'TSF_EXTENSION_MANAGER_DB_VERSION' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_DB_VERSION' ) or die; /** * The SEO Framework - Extension Manager plugin diff --git a/extensions/essentials/articles/trunk/articles.php b/extensions/essentials/articles/trunk/articles.php index f09f2fbf..ea5160f1 100644 --- a/extensions/essentials/articles/trunk/articles.php +++ b/extensions/essentials/articles/trunk/articles.php @@ -16,7 +16,7 @@ * Extension Menu Slug: theseoframework-extension-settings */ -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; /** * Articles extension for The SEO Framework @@ -41,7 +41,7 @@ * @since 1.0.0 * NOTE: The presence does NOT guarantee the extension is loaded!!! */ -define( 'TSFEM_E_ARTICLES_VERSION', '2.1.0' ); +\define( 'TSFEM_E_ARTICLES_VERSION', '2.1.0' ); /** * The extension database version. @@ -49,35 +49,35 @@ * @since ?.?.? * @ignore */ -// define( 'TSFEM_E_ARTICLES_DB_VERSION', '1000' ); +// \define( 'TSFEM_E_ARTICLES_DB_VERSION', '1000' ); /** * The extension file, absolute unix path. * * @since 1.1.0 */ -define( 'TSFEM_E_ARTICLES_BASE_FILE', __FILE__ ); +\define( 'TSFEM_E_ARTICLES_BASE_FILE', __FILE__ ); /** * The extension map URL. Used for calling browser files. * * @since 2.2.0 */ -define( 'TSFEM_E_ARTICLES_DIR_URL', \TSF_Extension_Manager\extension_dir_url( TSFEM_E_ARTICLES_BASE_FILE ) ); +\define( 'TSFEM_E_ARTICLES_DIR_URL', \TSF_Extension_Manager\extension_dir_url( TSFEM_E_ARTICLES_BASE_FILE ) ); /** * The extension file relative to the plugins dir. * * @since 1.2.0 */ -define( 'TSFEM_E_ARTICLES_DIR_PATH', \TSF_Extension_Manager\extension_dir_path( TSFEM_E_ARTICLES_BASE_FILE ) ); +\define( 'TSFEM_E_ARTICLES_DIR_PATH', \TSF_Extension_Manager\extension_dir_path( TSFEM_E_ARTICLES_BASE_FILE ) ); /** * The plugin class map absolute path. * * @since 1.2.0 */ -define( 'TSFEM_E_ARTICLES_PATH_CLASS', TSFEM_E_ARTICLES_DIR_PATH . 'inc' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR ); +\define( 'TSFEM_E_ARTICLES_PATH_CLASS', TSFEM_E_ARTICLES_DIR_PATH . 'inc' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR ); /** * Verify integrity and sets up autoloader. diff --git a/extensions/essentials/articles/trunk/inc/classes/admin.class.php b/extensions/essentials/articles/trunk/inc/classes/admin.class.php index 558c6674..30cea437 100644 --- a/extensions/essentials/articles/trunk/inc/classes/admin.class.php +++ b/extensions/essentials/articles/trunk/inc/classes/admin.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Articles; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; diff --git a/extensions/essentials/articles/trunk/inc/classes/core.class.php b/extensions/essentials/articles/trunk/inc/classes/core.class.php index c12db2a8..763e21c7 100644 --- a/extensions/essentials/articles/trunk/inc/classes/core.class.php +++ b/extensions/essentials/articles/trunk/inc/classes/core.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Articles; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; diff --git a/extensions/essentials/articles/trunk/inc/classes/front.class.php b/extensions/essentials/articles/trunk/inc/classes/front.class.php index b1f2c712..67715328 100644 --- a/extensions/essentials/articles/trunk/inc/classes/front.class.php +++ b/extensions/essentials/articles/trunk/inc/classes/front.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Articles; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; @@ -91,10 +91,10 @@ public function _init_articles_output() { if ( empty( $settings[ $post_type ]['enabled'] ) ) return; if ( $this->is_amp() ) { - //* Initialize output in The SEO Framework's front-end AMP meta object. + // Initialize output in The SEO Framework's front-end AMP meta object. \add_filter( 'the_seo_framework_amp_pro', [ $this, '_articles_hook_amp_output' ] ); } else { - //* Initialize output in The SEO Framework's front-end meta object. + // Initialize output in The SEO Framework's front-end meta object. \add_filter( 'the_seo_framework_after_output', [ $this, '_articles_hook_output' ] ); } } @@ -131,7 +131,7 @@ private function is_amp() { if ( function_exists( '\\is_amp_endpoint' ) ) { $is_amp = \is_amp_endpoint(); - } elseif ( defined( 'AMP_QUERY_VAR' ) ) { + } elseif ( \defined( 'AMP_QUERY_VAR' ) ) { $is_amp = \get_query_var( AMP_QUERY_VAR, false ) !== false; } else { $is_amp = false; @@ -277,7 +277,7 @@ public function _get_articles_json_output() { if ( ! $this->is_json_valid() ) return ''; - //* Build data, fetch it later. + // Build data, fetch it later. array_filter( array_filter( $data ), [ $this, 'build_article_data' ] ); /** diff --git a/extensions/essentials/articles/trunk/inc/classes/sitemap.class.php b/extensions/essentials/articles/trunk/inc/classes/sitemap.class.php index 96a29c89..ecdedbd8 100644 --- a/extensions/essentials/articles/trunk/inc/classes/sitemap.class.php +++ b/extensions/essentials/articles/trunk/inc/classes/sitemap.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Articles; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; diff --git a/extensions/essentials/articles/trunk/inc/classes/sitemapbuilder.class.php b/extensions/essentials/articles/trunk/inc/classes/sitemapbuilder.class.php index 58f5ac2b..e961cab6 100644 --- a/extensions/essentials/articles/trunk/inc/classes/sitemapbuilder.class.php +++ b/extensions/essentials/articles/trunk/inc/classes/sitemapbuilder.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Articles; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; diff --git a/extensions/essentials/articles/trunk/views/inpost/inpost.php b/extensions/essentials/articles/trunk/views/inpost/inpost.php index 57aab7af..9ec0f55c 100644 --- a/extensions/essentials/articles/trunk/views/inpost/inpost.php +++ b/extensions/essentials/articles/trunk/views/inpost/inpost.php @@ -3,6 +3,7 @@ * @package TSF_Extension_Manager\Extension\Articles\Views * @subpackage TSF_Extension_Manager\Inpost\Structure; */ + namespace TSF_Extension_Manager\Extension\Articles; /** @@ -11,7 +12,7 @@ use \TSF_Extension_Manager\InpostGUI as InpostGUI; use \TSF_Extension_Manager\InpostHTML as InpostHTML; -defined( 'ABSPATH' ) and InpostGUI::verify( $_secret ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) and InpostGUI::verify( $_secret ) or die; create_type_field :; $type_title = sprintf( '
%s
', $post_meta['type']['label']['title'] ); diff --git a/extensions/essentials/articles/trunk/views/list/bulkedit.php b/extensions/essentials/articles/trunk/views/list/bulkedit.php index 248a5fe0..9d610f06 100644 --- a/extensions/essentials/articles/trunk/views/list/bulkedit.php +++ b/extensions/essentials/articles/trunk/views/list/bulkedit.php @@ -14,14 +14,14 @@ // phpcs:disable, VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- includes. // phpcs:disable, WordPress.WP.GlobalVariablesOverride -- This isn't the global scope. -defined( 'ABSPATH' ) and ListEdit::verify( $_secret ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) and ListEdit::verify( $_secret ) or die; // NOTE: 'type' is the option name, confusingly so. ?>
diff --git a/extensions/essentials/articles/trunk/views/list/quickedit.php b/extensions/essentials/articles/trunk/views/list/quickedit.php index 3726e9ac..ba64e2d8 100644 --- a/extensions/essentials/articles/trunk/views/list/quickedit.php +++ b/extensions/essentials/articles/trunk/views/list/quickedit.php @@ -14,14 +14,14 @@ // phpcs:disable, VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- includes. // phpcs:disable, WordPress.WP.GlobalVariablesOverride -- This isn't the global scope. -defined( 'ABSPATH' ) and ListEdit::verify( $_secret ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) and ListEdit::verify( $_secret ) or die; // NOTE: 'type' is the option name, confusingly so. ?>
diff --git a/extensions/essentials/articles/trunk/views/sitemap/news.php b/extensions/essentials/articles/trunk/views/sitemap/news.php index aa0bb374..3316f7f4 100644 --- a/extensions/essentials/articles/trunk/views/sitemap/news.php +++ b/extensions/essentials/articles/trunk/views/sitemap/news.php @@ -1,6 +1,6 @@ _init_early_extension_autoloader( TSFEM_E_CORD_PATH_CLASS, 'Cord', $_instance, $bits ) ) return; +// phpcs:disable -- @ignore // if ( TSFEM_E_CORD_DB_VERSION > \tsf_extension_manager_db_version( 'cord' ) ) { // require TSFEM_E_CORD_DIR_PATH . 'upgrade.php'; // } +// phpcs:enable \add_action( 'plugins_loaded', __NAMESPACE__ . '\\_cord_init', 11 ); /** diff --git a/extensions/essentials/cord/trunk/inc/classes/admin.class.php b/extensions/essentials/cord/trunk/inc/classes/admin.class.php index 4aa9d9dc..11d56596 100644 --- a/extensions/essentials/cord/trunk/inc/classes/admin.class.php +++ b/extensions/essentials/cord/trunk/inc/classes/admin.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Cord; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; diff --git a/extensions/essentials/cord/trunk/inc/classes/core.class.php b/extensions/essentials/cord/trunk/inc/classes/core.class.php index 518de9c2..e212d559 100644 --- a/extensions/essentials/cord/trunk/inc/classes/core.class.php +++ b/extensions/essentials/cord/trunk/inc/classes/core.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Cord; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; diff --git a/extensions/essentials/cord/trunk/inc/classes/front.class.php b/extensions/essentials/cord/trunk/inc/classes/front.class.php index 033348ce..d1012f57 100644 --- a/extensions/essentials/cord/trunk/inc/classes/front.class.php +++ b/extensions/essentials/cord/trunk/inc/classes/front.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Cord; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; diff --git a/extensions/essentials/focus/trunk/focus.php b/extensions/essentials/focus/trunk/focus.php index a4f62a20..6125f2ad 100644 --- a/extensions/essentials/focus/trunk/focus.php +++ b/extensions/essentials/focus/trunk/focus.php @@ -15,7 +15,7 @@ * Extension License: GPLv3 */ -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; /** * Focus extension for The SEO Framework @@ -40,35 +40,35 @@ * @since 1.0.0 * NOTE: The presence does NOT guarantee the extension is loaded!!! */ -define( 'TSFEM_E_FOCUS_VERSION', '1.4.0' ); +\define( 'TSFEM_E_FOCUS_VERSION', '1.4.0' ); /** * The extension file, absolute unix path. * * @since 1.0.0 */ -define( 'TSFEM_E_FOCUS_BASE_FILE', __FILE__ ); +\define( 'TSFEM_E_FOCUS_BASE_FILE', __FILE__ ); /** * The extension map URL. Used for calling browser files. * * @since 1.0.0 */ -define( 'TSFEM_E_FOCUS_DIR_URL', \TSF_Extension_Manager\extension_dir_url( TSFEM_E_FOCUS_BASE_FILE ) ); +\define( 'TSFEM_E_FOCUS_DIR_URL', \TSF_Extension_Manager\extension_dir_url( TSFEM_E_FOCUS_BASE_FILE ) ); /** * The extension file relative to the plugins dir. * * @since 1.0.0 */ -define( 'TSFEM_E_FOCUS_DIR_PATH', \TSF_Extension_Manager\extension_dir_path( TSFEM_E_FOCUS_BASE_FILE ) ); +\define( 'TSFEM_E_FOCUS_DIR_PATH', \TSF_Extension_Manager\extension_dir_path( TSFEM_E_FOCUS_BASE_FILE ) ); /** * The plugin class map absolute path. * * @since 1.0.0 */ -define( 'TSFEM_E_FOCUS_PATH_CLASS', TSFEM_E_FOCUS_DIR_PATH . 'inc' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR ); +\define( 'TSFEM_E_FOCUS_PATH_CLASS', TSFEM_E_FOCUS_DIR_PATH . 'inc' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR ); /** * Verify integrity and sets up autoloader. diff --git a/extensions/essentials/focus/trunk/inc/classes/admin.class.php b/extensions/essentials/focus/trunk/inc/classes/admin.class.php index 4c67a778..c05a8d88 100644 --- a/extensions/essentials/focus/trunk/inc/classes/admin.class.php +++ b/extensions/essentials/focus/trunk/inc/classes/admin.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Focus; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; diff --git a/extensions/essentials/focus/trunk/inc/classes/ajax.class.php b/extensions/essentials/focus/trunk/inc/classes/ajax.class.php index a068a33a..96d8465e 100644 --- a/extensions/essentials/focus/trunk/inc/classes/ajax.class.php +++ b/extensions/essentials/focus/trunk/inc/classes/ajax.class.php @@ -5,14 +5,14 @@ namespace TSF_Extension_Manager\Extension\Focus; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; /** * Verify integrity and sets up API secret. * * @since 1.0.0 */ -define( +\define( 'TSFEM_E_FOCUS_AJAX_API_ACCESS_KEY', \tsf_extension_manager()->_init_final_static_extension_api_access( __NAMESPACE__ . '\\Ajax', $_instance, $bits ) ?: false ); @@ -79,7 +79,7 @@ public static function _init( Admin $_admin ) { */ $instance->error_notice_option = 'tsfem_e_focus_ajax_error_notice_option'; - //* AJAX definition getter listener. + // AJAX definition getter listener. \add_action( 'wp_ajax_tsfem_e_focus_get_lexicalforms', [ $instance, '_get_lexicalforms' ] ); \add_action( 'wp_ajax_tsfem_e_focus_get_inflections', [ $instance, '_get_inflections' ] ); \add_action( 'wp_ajax_tsfem_e_focus_get_synonyms', [ $instance, '_get_synonyms' ] ); diff --git a/extensions/essentials/focus/trunk/inc/classes/core.class.php b/extensions/essentials/focus/trunk/inc/classes/core.class.php index 94122c31..7dd9617f 100644 --- a/extensions/essentials/focus/trunk/inc/classes/core.class.php +++ b/extensions/essentials/focus/trunk/inc/classes/core.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Focus; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; diff --git a/extensions/essentials/focus/trunk/inc/classes/scoring.class.php b/extensions/essentials/focus/trunk/inc/classes/scoring.class.php index 2021a24c..cda3d31c 100644 --- a/extensions/essentials/focus/trunk/inc/classes/scoring.class.php +++ b/extensions/essentials/focus/trunk/inc/classes/scoring.class.php @@ -5,7 +5,7 @@ namespace TSF_Extension_Manager\Extension\Focus; -defined( 'ABSPATH' ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) or die; if ( \tsf_extension_manager()->_has_died() or false === ( \tsf_extension_manager()->_verify_instance( $_instance, $bits[1] ) or \tsf_extension_manager()->_maybe_die() ) ) return; diff --git a/extensions/essentials/focus/trunk/lib/js/tsfem-focus-inpost.min.js b/extensions/essentials/focus/trunk/lib/js/tsfem-focus-inpost.min.js index df4dc14e..66c94a1c 100644 --- a/extensions/essentials/focus/trunk/lib/js/tsfem-focus-inpost.min.js +++ b/extensions/essentials/focus/trunk/lib/js/tsfem-focus-inpost.min.js @@ -1 +1 @@ -'use strict';window.tsfem_e_focus_inpost=function(e){const t=tsfem_e_focusInpostL10n,n="#tsfem-e-focus-analysis-notification-area";let s={},a={},o={};const l=e=>(/.*\[[0-9]+\]/.exec(e)||"")[0],r=(e,t)=>e+"["+t+"]",d=(e,t)=>document.getElementById(e+"["+t+"]"),c=e=>(Object.keys(e).sort((e,t)=>Object.keys(e)[0]-Object.keys(t)[0]),e),f=(e,t)=>{if(!e||e!==Object(e))return;let n=s;t=!!t;let a,i;for(let s in e)for(let o in a=e[s],n[s]||(n[s]={}),a)if(i=a[o],n[s][i]||(n[s][i]=[]),t){let e=Object.values(n[s][i]);if(-1e!==o);s=n},u=e=>{const t=s;let n=a,i={},o=!1,l="",r=[];const d=e=>{i=t[e],o=!1,l="",r=[],"undefined"!=typeof i.dominate&&i.dominate.forEach(e=>{document.querySelector(e)&&(o=!0,l=e)}),o||"undefined"==typeof i.append||i.append.forEach(e=>{document.querySelector(e)&&r.push(e)}),o?n[e]=[l]:r.length?n[e]=r:c(e)},c=e=>{delete n[e]};if(e)"undefined"==typeof t[e]?c(e):d(e);else{for(var f in t)d(f)}a=n};let y={};const p=n=>{let s=l(n.id),i="e_focus_pw_"+e(n).data("assessment-type")+"_"+s,o=n.querySelector(".tsfem-e-focus-assessment-rating");if(tsfem_inpost.isWorkerBusy(i))return i in y&&clearTimeout(y[i]),void(y[i]=setTimeout(()=>p(n),2e3));delete y[i],tsfem_inpost.occupyWorker(i),tsfem_inpost.setIconClass(o,"loading");let r,d=D(s).get("inflections"),c=D(s).get("synonyms"),f=e(n).data("scores"),u=0,h=0,v=0,x=0,b=0,w=f.assessment.regex;w!==Object(w)&&(w=[w]);const k=n=>{let s=document.querySelector(n),a=e.Deferred();return(r="undefined"==typeof s.value?"":s.value,r.length||(r=s.innerHTML),!r.length)?a.resolve():(setTimeout(async()=>{await(tsfem_inpost.getWorker(i)||tsfem_inpost.spawnWorker(t.scripts.parserWorker,i)),e.when(tsfem_inpost.tellWorker(i,{regex:w,inflections:d,synonyms:c,content:r,assess:{getCharCount:"p"===f.scoring.type}})).done(e=>{u=e.inflectionCount,h=e.synonymCount,v=e.inflectionCharCount,x=e.synonymCharCount,b=e.contentCharCount,a.resolve()}).fail(()=>{a.reject()})}),a.promise())},_=()=>{let e=f.scoring,t=0,s=0;const a=(e,t)=>t>e?e:t,i=(e,t)=>Math.floor(t/e.per)*e.score,l=(e,t)=>t*(e/100),r=(e,t)=>100*(t/e),d=(e,t)=>t/e.threshold*f.maxScore;switch(e.type){case"n":u&&(s+=i(e.keyword,a(e.keyword.max,u))),h&&(s+=i(e.synonym,a(e.synonym.max,h)));break;case"p":b&&(v&&(t+=r(b,l(e.keyword.weight,v))),x&&(t+=r(b,l(e.synonym.weight,x)))),s=d(e,t);}let c=document.querySelector("input[name=\""+n.id+"\"]");c&&(c.value=s);let y=n.querySelector(".tsfem-e-focus-assessment-description"),p=g(f.phrasing,s);y.innerHTML===p?(tsfem_inpost.setIconClass(o,m(f.rating,s)),y.style.opacity="1",y.style.willChange="auto"):(y.style.willChange="contents, opacity",y.style.opacity="0",y.innerHTML=p,tsfem_inpost.setIconClass(o,m(f.rating,s)),tsfem_inpost.fadeIn(y),y.style.willChange="auto")},C=()=>{let e=document.querySelector("input[name=\""+n.id+"\"]");e&&(e.value=0);let s=n.querySelector(".tsfem-e-focus-assessment-description"),a=t.i18n.parseFailure;s.innerHTML===a?(tsfem_inpost.setIconClass(o,m(-1,-1)),s.style.opacity="1",s.style.willChange="auto"):(s.style.willChange="contents, opacity",s.style.opacity="0",s.innerHTML=a,tsfem_inpost.setIconClass(o,m(-1,-1)),tsfem_inpost.fadeIn(s),s.style.willChange="auto")};e.when(tsfem_inpost.promiseLoop(a[f.assessment.content],k,5,3e4)).done(()=>{_(),tsfem_inpost.freeWorker(i)}).fail(()=>{C(),tsfem_inpost.despawnWorker(i)})},g=(e,t)=>{let n;for(let s in e=c(e),e)if(isFinite(s)&&!isNaN(parseFloat(s)))if(s<=t)n=e[s];else break;return n?n:e[Object.keys(e)[0]]||""},m=(e,t)=>{let n=g(e,t).toString(),s={"-1":"error",0:"unknown",1:"bad",2:"warning",3:"okay",4:"good"};return"undefined"!=typeof s[n]&&s[n]||s["-1"]},h=s=>{let a=d(s,"keyword").value,i=d(s,"lexical_form");if(!i instanceof HTMLInputElement)return;P(s).to("loading");const o=e=>{let n=d(s,"lexical_selector"),a=d(s,"lexical_data"),o=Object.values(JSON.parse(t.defaultLexicalForm));e.length&&(e.forEach(e=>{e.inflection&&e.category&&o.push({value:e.inflection,category:e.category,name:e.category+": "+e.inflection})}),_(s).to("enabled"));let l=o.length&&JSON.stringify(o)||t.defaultLexicalForm;i.value="",a instanceof HTMLInputElement&&(a.value=l),n instanceof HTMLSelectElement&&(x(s,l),n.disabled=!1,n.selectedIndex=0)};e.when(((s,a)=>{let i={method:"POST",url:ajaxurl,dataType:"json",data:{action:"tsfem_e_focus_get_lexicalforms",nonce:t.nonce,post_ID:tsfem_inpost.postID,args:{keyword:a,language:t.language}},timeout:15e3,async:!0},o=e.Deferred();return tsfem_inpost.doAjax(o,i,{noticeArea:n,premium:!0}),o.promise()})(s,a)).done(e=>{o(e.forms)}).fail(()=>{v(s,"lexical")}).always(()=>{P(s).to("edit")})},v=(e,n)=>{const s=()=>{let n=d(e,"lexical_form"),s=d(e,"lexical_selector"),a=d(e,"lexical_data");n instanceof HTMLInputElement&&(n.value=""),a instanceof HTMLInputElement&&(a.value=t.defaultLexicalForm),s instanceof HTMLSelectElement&&(s.disabled=!0,s.selectedIndex=0,s.dataset.prev=0,x(e,t.defaultLexicalForm)),P(e).to("unchecked")},a=()=>{let t=d(e,"definition_dropdown"),n=d(e,"definition_selection");t instanceof HTMLSelectElement&&(t.selectedIndex=0,t.innerHTML="",document.querySelector("[data-for=\""+t.id+"\"]").innerHTML=""),n instanceof HTMLInputElement&&(n.value=""),D(e).clearCache()},i=()=>{let t=d(e,"inflections"),n=t&&t.querySelector(".tsfem-e-focus-subject-selection"),s=d(e,"inflection_data"),a=d(e,"active_inflections");n instanceof Element&&(n.innerHTML=""),s instanceof HTMLInputElement&&(s.value=""),a instanceof HTMLInputElement&&(a.value=""),D(e).clearCache("inflections")},o=()=>{let t=d(e,"synonyms"),n=t&&t.querySelector(".tsfem-e-focus-subject-selection"),s=d(e,"synonym_data"),a=d(e,"active_synonyms");n instanceof Element&&(n.innerHTML=""),s instanceof HTMLInputElement&&(s.value=""),a instanceof HTMLInputElement&&(a.value=""),D(e).clearCache("synonyms"),tsfem_inpost.isPremium&&O(e)},l=()=>{d(e,"scores").querySelectorAll("input").forEach(e=>e.value=0)};switch(n){case"lexical":s(),a();break;case"definition":a();break;case"inflections":i();break;case"synonyms":o();break;case"ratings":l();break;default:s(),a(),i(),o(),l();}},x=(e,t)=>{let n=d(e,"lexical_selector");for(let s=n.options.length;s--;)n.remove(s);let s=document.createElement("option"),a=JSON.parse(t);if(a)for(let e in a)s=s.cloneNode(),s.value=tsfem_inpost.escapeStr(e),s.innerHTML=tsfem_inpost.escapeStr(a[e].name),n.appendChild(s)};let b={};const w=s=>{let a=s.data.idPrefix,i=d(a,"lexical_selector"),o=d(a,"lexical_form"),l=d(a,"lexical_data");const r=s=>{let a,i=e.Deferred();if("inflections"===s?a="tsfem_e_focus_get_inflections":"synonyms"==s&&(a="tsfem_e_focus_get_synonyms"),!a)return i.reject(),i.promise();let r={method:"POST",url:ajaxurl,dataType:"json",data:{action:a,nonce:t.nonce,post_ID:tsfem_inpost.postID,args:{form:JSON.parse(l.value)[o.value],language:t.language}},timeout:15e3,async:!0};return tsfem_inpost.doAjax(i,r,{noticeArea:n,premium:!0}),i.promise()},c=()=>r("inflections"),f=()=>r("synonyms"),u=e=>{o.value=e,i.value=e,i.selectedIndex=+e},y=()=>{let n=e.Deferred();return t.languageSupported.inflections?(e.when(c()).done(e=>{e.inflections.length?(v(a,"inflections"),d(a,"inflection_data").value=JSON.stringify([{inflections:e.inflections}]),n.resolve()):n.reject()}).fail(e=>{switch(e){case 1100302:case 1100306:case 1100303:case 1100304:case 1100305:case 1100308:break;default:return void n.reject();}let t=d(a,"keyword").value.toLowerCase(),s=o.value,i=l.value,r="",c=[];if(r=JSON.parse(i)[s].value.toLowerCase(),c.push(t),t!==r)c.push(r);else return void n.reject();v(a,"inflections"),d(a,"inflection_data").value=JSON.stringify([{inflections:c}]),n.resolve()}),n.promise()):(n.reject(),n.promise())},p=()=>{let n=e.Deferred();return t.languageSupported.synonyms?(e.when(f()).done(e=>{e.synonyms.length?(v(a,"definition"),v(a,"synonyms"),d(a,"synonym_data").value=JSON.stringify(e.synonyms),n.resolve()):n.reject()}).fail(e=>{1100202===e||1100205===e?(v(a,"definition"),v(a,"synonyms"),n.reject()):n.reject()}),n.promise()):(n.reject(),n.promise())};(()=>{P(a).to("loading"),clearTimeout(b[a]),b[a]=setTimeout(()=>{if(i.dataset.prev==i.value)P(a).to("edit");else if(u(i.value),+i.value){let t,n,s=e.Deferred(),o=e.Deferred();e.when(t=y()).always(()=>s.resolve()),setTimeout(()=>{e.when(n=p()).always(()=>o.resolve())},100),e.when(s,o).done(()=>{[t.state(),n.state()].includes("resolved")?(i.dataset.prev=i.value,"resolved"===t.state()?"resolved"!==n.state()&&(v(a,"definition"),v(a,"synonyms")):v(a,"inflections"),k(a),O(a),P(a).to("enabled, edit, checked")):(u(i.dataset.prev||0),P(a).to("edit"))})}else i.dataset.prev=i.value,P(a).to("unchecked, disabled, edit"),v(a,"definition"),v(a,"inflections"),v(a,"synonyms")},1500)})()},k=n=>{let s=d(n,"synonym_data"),a=s.value&&JSON.parse(s.value)||{},i=d(n,"definition_dropdown"),o=d(n,"definition_selection"),l=i.cloneNode(!0);for(let e=l.options.length;e--;)l.remove(e);let r=document.createElement("option");for(let e=0;e{const n=n=>{e(n).off("change.tsfemInpostLexical").on("change.tsfemInpostLexical",{idPrefix:t},w)},s=t=>{e(t).off("change.tsfemInpostLexical")};return{to:e=>{let a=d(t,"lexical_selector");if(!(!a instanceof HTMLSelectElement))switch(e){case"enabled":n(a);break;default:case"disabled":s(a);}}}},C=e=>{let t=d(e,"scores"),n=t&&t.querySelectorAll(".tsfem-e-focus-assessment-wrap");if(L(e).to("disabled"),!n||n!==Object(n))E(e).to("error");else{E(e).to("enabled");for(let e=n.length;e--;)S(n[e]);K(e),L(e).to("enabled")}};let I={};const L=e=>({to:n=>{switch(n){case"disabled":e in I&&(clearInterval(I[e]),delete I[e]);break;case"enabled":L(e).to("disabled"),4999K(e),t.settings.analysisInterval));break;default:}}}),S=t=>{let n=l(t.id),s=d(n,"keyword").value;if(!s)return;let i,o,r,c,f;o=t.querySelector(".tsfem-e-focus-assessment-rating"),tsfem_inpost.setIconClass(o,"loading"),r=!0,f="undefined"!=typeof t.dataset.assess&&!+t.dataset.assess,i=e(t).data("scores"),i&&i.hasOwnProperty("assessment")&&"undefined"!=typeof a[i.assessment.content]&&(t.dataset.assess=1,F(t,i.assessment.content),r=!1),r?(tsfem_inpost.setIconClass(o,"unknown"),t.dataset.assess=0,c=document.getElementsByName(t.id),c&&c[0]&&(c[0].value=0),tsfem_inpost.fadeOut(t,250)):f&&tsfem_inpost.fadeIn(t,250)},E=t=>{let n=e(d(t,"content")),s=[".tsfem-e-focus-scores-wrap",".tsfem-e-focus-no-keyword-wrap",".tsfem-e-focus-something-wrong-wrap"];const a=e=>{s.splice(s.indexOf(e),1),n.find(s.join(", ")).fadeOut(150,()=>{setTimeout(()=>{n.find(e).fadeIn(250)},150)})};return{to:e=>{let t;switch(e){case"disabled":t=".tsfem-e-focus-no-keyword-wrap";break;case"enabled":t=".tsfem-e-focus-scores-wrap";break;default:case"error":t=".tsfem-e-focus-something-wrong-wrap";}a(t)}}},P=t=>({to:n=>{let s=d(t,"subject_edit");if(!s||!s instanceof HTMLInputElement)return;let a=document.querySelector("label[for=\""+s.id+"\"]"),i=s.parentNode,o="tsfem-e-focus-edit-subject-button-wrap-disabled";n.split(",").forEach(t=>{switch(t.trim()){case"checked":s.checked||(s.checked=!0,e(s).trigger("change"));break;case"unchecked":s.checked&&(s.checked=!1,e(s).trigger("change"));break;case"loading":a&&tsfem_inpost.setIconClass(a,"loading");break;case"edit":a&&tsfem_inpost.setIconClass(a,"edit");break;case"enabled":s.disabled=!1,i.classList.toggle(o,!1);break;case"disabled":s.disabled=!0,i.classList.toggle(o,!0);break;default:}})}}),j=()=>{e(".tsfem-e-focus-collapse-header").off("dblclick.tsfem-e-focus").on("dblclick.tsfem-e-focus",t=>{if(!tsfem_inpost.isActionableElement(t.target)){let n=e(t.target).closest(".tsfem-e-focus-collapse-wrap"),s=l(n.attr("id")),a=d(s,"collapser");a instanceof HTMLInputElement&&(a.checked=!a.checked)}})},T=()=>{let n={},s=1500,a=3,i={},o={},r=s/(100*a);!0&&(r*=1.175);const c=(e,t)=>{t.style.width=++i[e]/a+"%"},f=(e,t)=>{i[e]=0,t.style.width="0%"};let u=e(".tsfem-e-focus-keyword-entry");const y=n=>{let s=n.target,a=s.value.trim().replace(/[\s\t\r\n]+/g," ")||"",i=s.dataset.prev||"";if(n.target.value=a,a!==i){let i=l(n.target.id);return s.dataset.prev=a,v(i),P(i).to("disabled, edit"),L(i).to("disabled"),e(d(i,"scores")).find(".tsfem-e-focus-assessment-description").css("opacity","0"),a.length?void(tsfem_inpost.isPremium&&t.languageSupported.any&&h(i),C(i)):(E(i).to("disabled"),void _(i).to("disabled"))}};u.off("input.tsfem-e-focus").on("input.tsfem-e-focus",t=>{let a=l(t.target.id),i=d(a,"content").querySelector(".tsfem-e-focus-content-loader-bar"),u=d(a,"collapser");u.checked&&(u.checked=!1,e(u).trigger("change")),clearInterval(o[a]),clearTimeout(n[a]),f(a,i),o[a]=setInterval(()=>c(a,i),r),n[a]=setTimeout(()=>{clearInterval(o[a]),y(t),f(a,i)},s)}),u.each((e,t)=>{if(!t.value.length){let e=l(t.id);v(e)}})},q=()=>{const t=t=>{let n,s,a,i,o=t.target,r=0,c="",f=0,u="",y=t.data&&t.data.change||!1;if("undefined"!=typeof o.dataset.for&&(n=o.dataset.for),!n)return!1;if(s=document.getElementById(n),i=l(n),a=d(i,"definition_selection"),!s)return!1;r=s.value,c=o.innerHTML;const p=()=>{o.innerHTML=u,s.value=f,a.value=f,+f!=+r&&(d(i,"active_synonyms").value="",O(i)),b()},g=()=>{e(o).hide(),e(s).slideDown(200).focus()},m=()=>{e(s).blur().hide(),e(o).fadeIn(300)},h=e=>{v(e.target),+f==+r&&b()||p()},v=e=>{f=e.value,u=e.options[e.selectedIndex].text},x=t=>{let n=e(t.target).closest(s);1>n.length&&b()},b=()=>(_(),m(),!0),w=()=>{v(s),p()},k=()=>{s.addEventListener("blur",b),s.addEventListener("change",h),window.addEventListener("click",x),y&&w()},_=()=>{s.removeEventListener("blur",b),s.removeEventListener("change",h),window.removeEventListener("click",x)};g(),setTimeout(k,10)};let n="click.tsfem-e-focus-definition-editor",s="keypress.tsfem-e-focus-definition-editor",a="set-tsfem-e-focus-definition";e(".tsfem-e-focus-definition-editor").off(n).on(n,t).off(s).on(s,e=>{32==e.which&&(e.preventDefault(),t(e))}).off(a).on(a,{change:1},t);let i="change.tsfem-e-focus-edit-subject-toggle";e(".tsfem-e-focus-edit-subject-checkbox").off(i).on(i,e=>{const t=l(e.target.id);let n=d(t,"edit"),s=d(t,"evaluate"),a=d(t,"collapser");a.checked?(e.target.checked=!0,s.style.display="none",s.style.opacity=0,n.style.display=null,n.style.opacity=1,a.checked=!1):e.target.checked?tsfem_inpost.fadeOut(s,150,{cb:()=>{tsfem_inpost.fadeIn(n,250),e.target.checked=!0},promise:!1}):tsfem_inpost.fadeOut(n,150,{cb:()=>{tsfem_inpost.fadeIn(s,250),e.target.checked=!1},promise:!1})})};let A={};const M=()=>{const t=e=>(/\[([0-9]+)\]$/.exec(e)||"")[1],n=e=>{let n=d(e,"inflections"),s=n.querySelectorAll("input:checked"),a=[];s.forEach(e=>{a.push(t(e.id))}),d(e,"active_inflections").value=a.join(),D(e).clearCache("inflections"),K(e)},s=e=>{let n=d(e,"synonyms"),s=n.querySelectorAll("input:checked"),a=[];s.forEach(e=>{a.push(t(e.id))}),d(e,"active_synonyms").value=a.join(),D(e).clearCache("synonyms"),K(e)},a=e=>{const t=e.data.idPrefix,a=e.data.type,i=t+a;clearTimeout(A[i]),A[i]=setTimeout(()=>{"inflections"===a?n(t):"synonyms"===a?s(t):void 0},1500)},i=(t,n)=>{e(d(t,n)).find("input").off("change.tsfem-e-focus").on("change.tsfem-e-focus",{idPrefix:t,type:n},a)};let o="tsfem-e-focus-updated-subject.tsfem-e-focus";e(window).off(o).on(o,(e,t)=>{if(!t||!t.idPrefix)return;const a=t.idPrefix,o=d(a,"inflection_data"),l=d(a,"synonym_data"),c=d(a,"definition_selection"),f=d(a,"inflections"),u=d(a,"synonyms"),y=f.querySelector(".tsfem-e-focus-subject-selection"),p=u.querySelector(".tsfem-e-focus-subject-selection"),g=wp.template("tsfem-e-focus-subject-item");let m=o.value&&JSON.parse(o.value),h=m&&m[0]&&m[0].inflections||[],v=l.value&&JSON.parse(l.value),x=v&&v[+c.value]&&v[+c.value].synonyms||[];y.style.opacity=0,p.style.opacity=0;let b=d(a,"active_inflections").value.split(","),w=d(a,"active_synonyms").value.split(","),k=d(a,"keyword").value.toLowerCase(),_="",C=r(a,"inflection"),I=!1;for(let n in h)I=h[n]===k,_+=g({id:r(C,n),value:h[n],checked:I||-1{e(window).trigger("tsfem-e-focus-updated-subject",[{idPrefix:t}])};let H={};const D=e=>{H.hasOwnProperty(e)||(H[e]={inflections:void 0,synonyms:void 0});const t=()=>{let t=[],n=d(e,"keyword").value;const s=d(e,"active_inflections");if(s instanceof HTMLInputElement&&s.value){let n=d(e,"inflection_data").value,a=JSON.parse(n)[0].inflections;s.value.split(",").forEach(e=>{t.push(a[+e])})}return-1===t.indexOf(n)&&t.push(n),H[e].inflections=t},n=()=>{let t=[];const n=d(e,"active_synonyms"),s=d(e,"definition_selection");if(n instanceof HTMLInputElement&&n.value){let a=d(e,"synonym_data").value,o=JSON.parse(a)[+s.value].synonyms;n.value.split(",").forEach(e=>{t.push(o[+e])})}return H[e].synonyms=t},s=s=>{if(void 0!==H[e][s])return H[e][s];return"inflections"===s?t():"synonyms"===s?n():{inflections:t(),synonyms:n()}},a=t=>{t?delete H[e][t]:delete H[e]};return{get:e=>s(e),clearCache:e=>a(e)}},B=(e,t)=>{if("undefined"!=typeof o[e]){t=t||"unknown";for(let n=o[e].length;n--;)tsfem_inpost.setIconClass(document.getElementById(o[e][n]).querySelector(".tsfem-e-focus-assessment-rating"),t)}},F=(e,t)=>{let n=o;n&&n===Object(n)||(n=[]),n[t]&&n[t]===Object(n[t])||(n[t]=[]),e.id&&("undefined"==typeof a[t]?delete n[t][e.id]:0>n[t].indexOf(e.id)&&n[t].push(e.id)),o=n};let W={},U={};const N=t=>{const n=e=>{tsfem_inpost.promiseLoop(o[e],e=>{let t=l(e),n=d(t,"keyword"),s=n.value||"";if(!s.length)return;let a=document.getElementById(e),i=a.querySelector(".tsfem-e-focus-assessment-rating");tsfem_inpost.setIconClass(i,"loading"),setTimeout(()=>p(a),150)})},s=e=>{"undefined"==typeof o[e.data.type]||(clearTimeout(W[e.data.type]),!U[e.data.type]&&(setTimeout(()=>tsfem_inpost.setIconClass(document.querySelectorAll("[data-assessment-type=\""+e.data.type+"\"] .tsfem-e-focus-assessment-rating"),"unknown"),0),U[e.data.type]=!0),W[e.data.type]=setTimeout(()=>{n(e.data.type),U[e.data.type]=!1},1500))},i=t=>{let n=R(t).get("names");e(a[t].join(", ")).off(n).on(n,{type:t},s)};if(t)"undefined"!=typeof a[t]&&i(t);else for(let e in a)"undefined"!=typeof a[e]&&i(e)};let G={};const K=t=>{t=t||0,clearTimeout(G[t]),G[t]=setTimeout(()=>{if(t){let e=d(t,"scores"),n=e&&e.querySelectorAll(".tsfem-e-focus-assessment-wrap[data-assess=\"1\"]");n instanceof NodeList&&n.length?tsfem_inpost.promiseLoop(n,e=>p(e),150):E(t).to("error")}else{for(var n in a)e(a[n].join(", ")).trigger(R(n).get("trigger"))}},1e3)},R=e=>{const t=["tsfem-e-focus.analysis-"+e,"input.tsfem-e-focus-"+e,"change.tsfem-e-focus-"+e];return{get:e=>"names"===e?t.join(" "):"trigger"===e?t[0]:t}},z=()=>{let t=e(document),n=document.getElementById("tsf-gutenberg-data-holder");if(!n)return;const s=e=>`tsfem-focus-gbc-${e}`,a=e=>document.getElementById(s(e)),i=(e,n)=>{o(e),setTimeout(()=>{u(n),N(n)}),t.trigger(`tsfem-focus-gutenberg-${e}-store-set`)},o=e=>{if(!a(e)){let t=document.createElement("div");t.id=s(e),t.style.display="none",n.appendChild(t)}},l=(e,t)=>{a(e).innerHTML=t},r=(t,n)=>{e("#"+s(t)).trigger(R(n).get("trigger"))};t.on("tsf-updated-gutenberg-title",(e,t)=>{l("title",t),r("title","pageTitle")}),i("title","pageTitle"),t.on("tsf-updated-gutenberg-link",(e,t)=>{l("link",t),r("link","pageUrl")}),i("link","pageUrl");const d=e=>{l("content",e),r("content","pageContent")};t.on("tsf-updated-gutenberg-content",(e,t)=>{let n=lodash.debounce(d,500),s=!1,a=wp.data.select("core/block-editor")||wp.data.select("core/editor");"function"==typeof a.isTyping&&(s=a.isTyping()),s?(B("pageContent","unknown"),n(t)):(n.cancel(),d(t))}),i("content","pageContent")},J=()=>{const n=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;(()=>{if("undefined"==typeof t.focusElements.pageUrl)return;let s=document.getElementById("edit-slug-box");if(!s||!s instanceof HTMLElement)return;const a=()=>{let e=document.querySelectorAll(".tsfem-e-focus-assessment-wrap[data-assessment-type=\"url\"][data-assess=\"0\"]");e instanceof NodeList&&e.length&&(u("pageUrl"),N("pageUrl"),e.forEach(e=>S(e)))};new n(()=>{a(),N("pageUrl"),e("#sample-permalink").trigger(R("pageUrl").get("trigger"))}).observe(s,{childList:!0,subtree:!0})})(),(()=>{if("undefined"==typeof tinyMCE||"function"!=typeof tinyMCE.on)return;let t=!1;tinyMCE.on("addEditor",n=>{if(t)return;if("content"!==n.editor.id)return;t=!0,u("pageContent"),N("pageContent");let s={},a=tinyMCE.get("content"),i=!1,o=!1;a.on("Dirty",()=>{o||(B("pageContent","unknown"),o=!0)}),a.on("GetContent",()=>{clearTimeout(s.GetContent),!i&&a.isDirty()&&(B("pageContent","loading"),i=!0,o=!1),s.GetContent=setTimeout(()=>{a.isDirty()||e("#content").trigger(R("pageContent").get("trigger")),i=!1,o=!1},1e3)})})})()},Q=()=>{t.isGutenbergPage?z():J()},V=()=>{let e=document.querySelectorAll(".tsfem-e-focus-collapse-wrap");for(let n=e.length;n--;){let s=l(e[n].id),a=d(s,"keyword");if(a.value.length){if(a.dataset.prev=a.value,tsfem_inpost.isPremium&&t.languageSupported.any){let e=d(s,"lexical_selector");e.dataset.prev=e.value,1{if(Q(),t.hasOwnProperty("focusElements")&&(f(t.focusElements,!0),u(),N()),0===Object.keys(a).length){let e=document.getElementById("tsfem-e-focus-analysis-wrap");if(e instanceof Element){let t=e.querySelector(".tsf-flex-setting-input");t instanceof Element&&(t.innerHTML=wp.template("tsfem-e-focus-nofocus")())}return}j(),T(),tsfem_inpost.isPremium&&t.languageSupported.any&&(q(),M()),V()},Y=()=>{e(".tsfem-e-focus-enable-if-js").removeAttr("disabled"),e(".tsfem-e-focus-disable-if-js").attr("disabled","disabled"),e(".tsfem-e-focus-requires-javascript").removeClass("tsfem-e-focus-requires-javascript")};return Object.assign({load:()=>{document.body.addEventListener("tsf-onload",Y),document.body.addEventListener("tsf-ready",X)}},{focusRegistry:s,activeFocusAreas:a,activeAssessments:o,updateFocusRegistry:f,updateActiveFocusAreas:u,resetAnalysisChangeListeners:N,triggerAllAnalysis:K,analysisChangeEvents:R,getSubIdPrefix:l,getSubElementById:d,setAllRatersOf:B})}(jQuery),window.tsfem_e_focus_inpost.load(); +'use strict';window.tsfem_e_focus_inpost=function(e){const t=tsfem_e_focusInpostL10n,n="#tsfem-e-focus-analysis-notification-area";let s={},a={},o={};const l=e=>(/.*\[[0-9]+\]/.exec(e)||"")[0],r=(e,t)=>e+"["+t+"]",d=(e,t)=>document.getElementById(e+"["+t+"]"),c=e=>(Object.keys(e).sort((e,t)=>Object.keys(e)[0]-Object.keys(t)[0]),e),f=(e,t)=>{if(!e||e!==Object(e))return;let n=s;t=!!t;let a,i;for(let s in e)for(let o in a=e[s],n[s]||(n[s]={}),a)if(i=a[o],n[s][i]||(n[s][i]=[]),t){let e=Object.values(n[s][i]);if(-1e!==o);s=n},u=e=>{const t=s;let n=a,i={},o=!1,l="",r=[];const d=e=>{i=t[e],o=!1,l="",r=[],"undefined"!=typeof i.dominate&&i.dominate.forEach(e=>{document.querySelector(e)&&(o=!0,l=e)}),o||"undefined"==typeof i.append||i.append.forEach(e=>{document.querySelector(e)&&r.push(e)}),o?n[e]=[l]:r.length?n[e]=r:c(e)},c=e=>{delete n[e]};if(e)"undefined"==typeof t[e]?c(e):d(e);else{for(var f in t)d(f)}a=n};let y={};const p=n=>{let s=l(n.id),i="e_focus_pw_"+e(n).data("assessment-type")+"_"+s,o=n.querySelector(".tsfem-e-focus-assessment-rating");if(tsfem_inpost.isWorkerBusy(i))return i in y&&clearTimeout(y[i]),void(y[i]=setTimeout(()=>p(n),2e3));delete y[i],tsfem_inpost.occupyWorker(i),tsfem_inpost.setIconClass(o,"loading");let r,d=D(s).get("inflections"),c=D(s).get("synonyms"),f=e(n).data("scores"),u=0,h=0,v=0,x=0,b=0,w=f.assessment.regex;w!==Object(w)&&(w=[w]);const k=n=>{let s=document.querySelector(n),a=e.Deferred();return(r="undefined"==typeof s.value?"":s.value,r.length||(r=s.innerHTML),!r.length)?a.resolve():(setTimeout(async()=>{await(tsfem_inpost.getWorker(i)||tsfem_inpost.spawnWorker(t.scripts.parserWorker,i)),e.when(tsfem_inpost.tellWorker(i,{regex:w,inflections:d,synonyms:c,content:r,assess:{getCharCount:"p"===f.scoring.type}})).done(e=>{u=e.inflectionCount,h=e.synonymCount,v=e.inflectionCharCount,x=e.synonymCharCount,b=e.contentCharCount,a.resolve()}).fail(()=>{a.reject()})}),a.promise())},_=()=>{let e=f.scoring,t=0,s=0;const a=(e,t)=>t>e?e:t,i=(e,t)=>Math.floor(t/e.per)*e.score,l=(e,t)=>t*(e/100),r=(e,t)=>100*(t/e),d=(e,t)=>t/e.threshold*f.maxScore;switch(e.type){case"n":u&&(s+=i(e.keyword,a(e.keyword.max,u))),h&&(s+=i(e.synonym,a(e.synonym.max,h)));break;case"p":b&&(v&&(t+=r(b,l(e.keyword.weight,v))),x&&(t+=r(b,l(e.synonym.weight,x)))),s=d(e,t);}let c=document.querySelector("input[name=\""+n.id+"\"]");c&&(c.value=s);let y=n.querySelector(".tsfem-e-focus-assessment-description"),p=g(f.phrasing,s);y.innerHTML===p?(tsfem_inpost.setIconClass(o,m(f.rating,s)),y.style.opacity="1",y.style.willChange="auto"):(y.style.willChange="contents, opacity",y.style.opacity="0",y.innerHTML=p,tsfem_inpost.setIconClass(o,m(f.rating,s)),tsfem_inpost.fadeIn(y),y.style.willChange="auto")},C=()=>{let e=document.querySelector("input[name=\""+n.id+"\"]");e&&(e.value=0);let s=n.querySelector(".tsfem-e-focus-assessment-description"),a=t.i18n.parseFailure;s.innerHTML===a?(tsfem_inpost.setIconClass(o,m(-1,-1)),s.style.opacity="1",s.style.willChange="auto"):(s.style.willChange="contents, opacity",s.style.opacity="0",s.innerHTML=a,tsfem_inpost.setIconClass(o,m(-1,-1)),tsfem_inpost.fadeIn(s),s.style.willChange="auto")};e.when(tsfem_inpost.promiseLoop(a[f.assessment.content],k,5,3e4)).done(()=>{_(),tsfem_inpost.freeWorker(i)}).fail(()=>{C(),tsfem_inpost.despawnWorker(i)})},g=(e,t)=>{let n;for(let s in e=c(e),e)if(isFinite(s)&&!isNaN(parseFloat(s)))if(s<=t)n=e[s];else break;return n?n:e[Object.keys(e)[0]]||""},m=(e,t)=>{let n=g(e,t).toString(),s={"-1":"error",0:"unknown",1:"bad",2:"warning",3:"okay",4:"good"};return"undefined"!=typeof s[n]&&s[n]||s["-1"]},h=s=>{let a=d(s,"keyword").value,i=d(s,"lexical_form");if(!i instanceof HTMLInputElement)return;P(s).to("loading");const o=e=>{let n=d(s,"lexical_selector"),a=d(s,"lexical_data"),o=Object.values(JSON.parse(t.defaultLexicalForm));e.length&&(e.forEach(e=>{e.inflection&&e.category&&o.push({value:e.inflection,category:e.category,name:e.category+": "+e.inflection})}),_(s).to("enabled"));let l=o.length&&JSON.stringify(o)||t.defaultLexicalForm;i.value="",a instanceof HTMLInputElement&&(a.value=l),n instanceof HTMLSelectElement&&(x(s,l),n.disabled=!1,n.selectedIndex=0)};e.when(((s,a)=>{let i={method:"POST",url:ajaxurl,dataType:"json",data:{action:"tsfem_e_focus_get_lexicalforms",nonce:t.nonce,post_ID:tsfem_inpost.postID,args:{keyword:a,language:t.language}},timeout:15e3,async:!0},o=e.Deferred();return tsfem_inpost.doAjax(o,i,{noticeArea:n,premium:!0}),o.promise()})(s,a)).done(e=>{o(e.forms)}).fail(()=>{v(s,"lexical")}).always(()=>{P(s).to("edit")})},v=(e,n)=>{const s=()=>{let n=d(e,"lexical_form"),s=d(e,"lexical_selector"),a=d(e,"lexical_data");n instanceof HTMLInputElement&&(n.value=""),a instanceof HTMLInputElement&&(a.value=t.defaultLexicalForm),s instanceof HTMLSelectElement&&(s.disabled=!0,s.selectedIndex=0,s.dataset.prev=0,x(e,t.defaultLexicalForm)),P(e).to("unchecked")},a=()=>{let t=d(e,"definition_dropdown"),n=d(e,"definition_selection");t instanceof HTMLSelectElement&&(t.selectedIndex=0,t.innerHTML="",document.querySelector("[data-for=\""+t.id+"\"]").innerHTML=""),n instanceof HTMLInputElement&&(n.value=""),D(e).clearCache()},i=()=>{let t=d(e,"inflections"),n=t&&t.querySelector(".tsfem-e-focus-subject-selection"),s=d(e,"inflection_data"),a=d(e,"active_inflections");n instanceof Element&&(n.innerHTML=""),s instanceof HTMLInputElement&&(s.value=""),a instanceof HTMLInputElement&&(a.value=""),D(e).clearCache("inflections")},o=()=>{let t=d(e,"synonyms"),n=t&&t.querySelector(".tsfem-e-focus-subject-selection"),s=d(e,"synonym_data"),a=d(e,"active_synonyms");n instanceof Element&&(n.innerHTML=""),s instanceof HTMLInputElement&&(s.value=""),a instanceof HTMLInputElement&&(a.value=""),D(e).clearCache("synonyms"),tsfem_inpost.isPremium&&O(e)},l=()=>{d(e,"scores").querySelectorAll("input").forEach(e=>e.value=0)};switch(n){case"lexical":s(),a();break;case"definition":a();break;case"inflections":i();break;case"synonyms":o();break;case"ratings":l();break;default:s(),a(),i(),o(),l();}},x=(e,t)=>{let n=d(e,"lexical_selector");for(let s=n.options.length;s--;)n.remove(s);let s=document.createElement("option"),a=JSON.parse(t);if(a)for(let e in a)s=s.cloneNode(),s.value=tsfem_inpost.escapeStr(e),s.innerHTML=tsfem_inpost.escapeStr(a[e].name),n.appendChild(s)};let b={};const w=s=>{let a=s.data.idPrefix,i=d(a,"lexical_selector"),o=d(a,"lexical_form"),l=d(a,"lexical_data");const r=s=>{let a,i=e.Deferred();if("inflections"===s?a="tsfem_e_focus_get_inflections":"synonyms"==s&&(a="tsfem_e_focus_get_synonyms"),!a)return i.reject(),i.promise();let r={method:"POST",url:ajaxurl,dataType:"json",data:{action:a,nonce:t.nonce,post_ID:tsfem_inpost.postID,args:{form:JSON.parse(l.value)[o.value],language:t.language}},timeout:15e3,async:!0};return tsfem_inpost.doAjax(i,r,{noticeArea:n,premium:!0}),i.promise()},c=()=>r("inflections"),f=()=>r("synonyms"),u=e=>{o.value=e,i.value=e,i.selectedIndex=+e},y=()=>{let n=e.Deferred();return t.languageSupported.inflections?(e.when(c()).done(e=>{e.inflections.length?(v(a,"inflections"),d(a,"inflection_data").value=JSON.stringify([{inflections:e.inflections}]),n.resolve()):n.reject()}).fail(e=>{switch(e){case 1100302:case 1100306:case 1100303:case 1100304:case 1100305:case 1100308:break;default:return void n.reject();}let t=d(a,"keyword").value.toLowerCase(),s=o.value,i=l.value,r="",c=[];if(r=JSON.parse(i)[s].value.toLowerCase(),c.push(t),t!==r)c.push(r);else return void n.reject();v(a,"inflections"),d(a,"inflection_data").value=JSON.stringify([{inflections:c}]),n.resolve()}),n.promise()):(n.reject(),n.promise())},p=()=>{let n=e.Deferred();return t.languageSupported.synonyms?(e.when(f()).done(e=>{e.synonyms.length?(v(a,"definition"),v(a,"synonyms"),d(a,"synonym_data").value=JSON.stringify(e.synonyms),n.resolve()):n.reject()}).fail(e=>{1100202===e||1100205===e?(v(a,"definition"),v(a,"synonyms"),n.reject()):n.reject()}),n.promise()):(n.reject(),n.promise())};(()=>{P(a).to("loading"),clearTimeout(b[a]),b[a]=setTimeout(()=>{if(i.dataset.prev==i.value)P(a).to("edit");else if(u(i.value),+i.value){let t,n,s=e.Deferred(),o=e.Deferred();e.when(t=y()).always(()=>s.resolve()),setTimeout(()=>{e.when(n=p()).always(()=>o.resolve())},100),e.when(s,o).done(()=>{[t.state(),n.state()].includes("resolved")?(i.dataset.prev=i.value,"resolved"===t.state()?"resolved"!==n.state()&&(v(a,"definition"),v(a,"synonyms")):v(a,"inflections"),k(a),O(a),P(a).to("enabled, edit, checked")):(u(i.dataset.prev||0),P(a).to("edit"))})}else i.dataset.prev=i.value,P(a).to("unchecked, disabled, edit"),v(a,"definition"),v(a,"inflections"),v(a,"synonyms")},1500)})()},k=n=>{let s=d(n,"synonym_data"),a=s.value&&JSON.parse(s.value)||{},i=d(n,"definition_dropdown"),o=d(n,"definition_selection"),l=i.cloneNode(!0);for(let e=l.options.length;e--;)l.remove(e);let r=document.createElement("option");for(let e=0;e{const n=n=>{e(n).off("change.tsfemInpostLexical").on("change.tsfemInpostLexical",{idPrefix:t},w)},s=t=>{e(t).off("change.tsfemInpostLexical")};return{to:e=>{let a=d(t,"lexical_selector");if(!(!a instanceof HTMLSelectElement))switch(e){case"enabled":n(a);break;default:case"disabled":s(a);}}}},C=e=>{let t=d(e,"scores"),n=t&&t.querySelectorAll(".tsfem-e-focus-assessment-wrap");if(L(e).to("disabled"),!n||n!==Object(n))E(e).to("error");else{E(e).to("enabled");for(let e=n.length;e--;)S(n[e]);K(e),L(e).to("enabled")}};let I={};const L=e=>({to:n=>{switch(n){case"disabled":e in I&&(clearInterval(I[e]),delete I[e]);break;case"enabled":L(e).to("disabled"),4999K(e),t.settings.analysisInterval));break;default:}}}),S=t=>{let n=l(t.id),s=d(n,"keyword").value;if(!s)return;let i,o,r,c,f;o=t.querySelector(".tsfem-e-focus-assessment-rating"),tsfem_inpost.setIconClass(o,"loading"),r=!0,f="undefined"!=typeof t.dataset.assess&&!+t.dataset.assess,i=e(t).data("scores"),i&&i.hasOwnProperty("assessment")&&"undefined"!=typeof a[i.assessment.content]&&(t.dataset.assess=1,F(t,i.assessment.content),r=!1),r?(tsfem_inpost.setIconClass(o,"unknown"),t.dataset.assess=0,c=document.getElementsByName(t.id),c&&c[0]&&(c[0].value=0),tsfem_inpost.fadeOut(t,250)):f&&tsfem_inpost.fadeIn(t,250)},E=t=>{let n=e(d(t,"content")),s=[".tsfem-e-focus-scores-wrap",".tsfem-e-focus-no-keyword-wrap",".tsfem-e-focus-something-wrong-wrap"];const a=e=>{s.splice(s.indexOf(e),1),n.find(s.join(", ")).fadeOut(150,()=>{setTimeout(()=>{n.find(e).fadeIn(250)},150)})};return{to:e=>{let t;switch(e){case"disabled":t=".tsfem-e-focus-no-keyword-wrap";break;case"enabled":t=".tsfem-e-focus-scores-wrap";break;default:case"error":t=".tsfem-e-focus-something-wrong-wrap";}a(t)}}},P=t=>({to:n=>{let s=d(t,"subject_edit");if(!s||!s instanceof HTMLInputElement)return;let a=document.querySelector("label[for=\""+s.id+"\"]"),i=s.parentNode,o="tsfem-e-focus-edit-subject-button-wrap-disabled";n.split(",").forEach(t=>{switch(t.trim()){case"checked":s.checked||(s.checked=!0,e(s).trigger("change"));break;case"unchecked":s.checked&&(s.checked=!1,e(s).trigger("change"));break;case"loading":a&&tsfem_inpost.setIconClass(a,"loading");break;case"edit":a&&tsfem_inpost.setIconClass(a,"edit");break;case"enabled":s.disabled=!1,i.classList.toggle(o,!1);break;case"disabled":s.disabled=!0,i.classList.toggle(o,!0);break;default:}})}}),j=()=>{const t=t=>{if(!tsfem_inpost.isActionableElement(t.target)){let n=e(t.target).closest(".tsfem-e-focus-collapse-wrap"),s=l(n.attr("id")),a=d(s,"collapser");a instanceof HTMLInputElement&&(a.checked=!a.checked)}};document.querySelectorAll(".tsfem-e-focus-collapse-header").forEach(e=>{e.addEventListener("dblclick",t)})},T=()=>{let n={},s=1500,a=3,i={},o={},r=s/(100*a);!0&&(r*=1.175);const c=(e,t)=>{t.style.width=++i[e]/a+"%"},f=(e,t)=>{i[e]=0,t.style.width="0%"};let u=document.querySelectorAll(".tsfem-e-focus-keyword-entry");const y=n=>{let s=n.target,a=s.value.trim().replace(/[\s\t\r\n]+/g," ")||"",i=s.dataset.prev||"";if(n.target.value=a,a!==i){let i=l(n.target.id);return s.dataset.prev=a,v(i),P(i).to("disabled, edit"),L(i).to("disabled"),e(d(i,"scores")).find(".tsfem-e-focus-assessment-description").css("opacity","0"),a.length?void(tsfem_inpost.isPremium&&t.languageSupported.any&&h(i),C(i)):(E(i).to("disabled"),void _(i).to("disabled"))}},p=t=>{let a=l(t.target.id),i=d(a,"content").querySelector(".tsfem-e-focus-content-loader-bar"),u=d(a,"collapser");u.checked&&(u.checked=!1,e(u).trigger("change")),clearInterval(o[a]),clearTimeout(n[a]),f(a,i),o[a]=setInterval(()=>c(a,i),r),n[a]=setTimeout(()=>{clearInterval(o[a]),y(t),f(a,i)},s)};u.forEach(e=>{e.addEventListener("input",p),e.value.length||v(l(e.id))})},q=()=>{const t=t=>{let n,s,a,i,o=t.target,r=0,c="",f=0,u="",y=t.data&&t.data.change||!1;if("undefined"!=typeof o.dataset.for&&(n=o.dataset.for),!n)return!1;if(s=document.getElementById(n),i=l(n),a=d(i,"definition_selection"),!s)return!1;r=s.value,c=o.innerHTML;const p=()=>{o.innerHTML=u,s.value=f,a.value=f,+f!=+r&&(d(i,"active_synonyms").value="",O(i)),b()},g=()=>{e(o).hide(),e(s).slideDown(200).focus()},m=()=>{e(s).blur().hide(),e(o).fadeIn(300)},h=e=>{v(e.target),+f==+r&&b()||p()},v=e=>{f=e.value,u=e.options[e.selectedIndex].text},x=t=>{let n=e(t.target).closest(s);1>n.length&&b()},b=()=>(_(),m(),!0),w=()=>{v(s),p()},k=()=>{s.addEventListener("blur",b),s.addEventListener("change",h),window.addEventListener("click",x),y&&w()},_=()=>{s.removeEventListener("blur",b),s.removeEventListener("change",h),window.removeEventListener("click",x)};g(),setTimeout(k,10)};let n="click.tsfem-e-focus-definition-editor",s="keypress.tsfem-e-focus-definition-editor",a="set-tsfem-e-focus-definition";e(".tsfem-e-focus-definition-editor").off(n).on(n,t).off(s).on(s,e=>{32==e.which&&(e.preventDefault(),t(e))}).off(a).on(a,{change:1},t);let i="change.tsfem-e-focus-edit-subject-toggle";e(".tsfem-e-focus-edit-subject-checkbox").off(i).on(i,e=>{const t=l(e.target.id);let n=d(t,"edit"),s=d(t,"evaluate"),a=d(t,"collapser");a.checked?(e.target.checked=!0,s.style.display="none",s.style.opacity=0,n.style.display=null,n.style.opacity=1,a.checked=!1):e.target.checked?tsfem_inpost.fadeOut(s,150,{cb:()=>{tsfem_inpost.fadeIn(n,250),e.target.checked=!0},promise:!1}):tsfem_inpost.fadeOut(n,150,{cb:()=>{tsfem_inpost.fadeIn(s,250),e.target.checked=!1},promise:!1})})};let A={};const M=()=>{const t=e=>(/\[([0-9]+)\]$/.exec(e)||"")[1],n=e=>{let n=d(e,"inflections"),s=n.querySelectorAll("input:checked"),a=[];s.forEach(e=>{a.push(t(e.id))}),d(e,"active_inflections").value=a.join(),D(e).clearCache("inflections"),K(e)},s=e=>{let n=d(e,"synonyms"),s=n.querySelectorAll("input:checked"),a=[];s.forEach(e=>{a.push(t(e.id))}),d(e,"active_synonyms").value=a.join(),D(e).clearCache("synonyms"),K(e)},a=e=>{const t=e.data.idPrefix,a=e.data.type,i=t+a;clearTimeout(A[i]),A[i]=setTimeout(()=>{"inflections"===a?n(t):"synonyms"===a?s(t):void 0},1500)},i=(t,n)=>{e(d(t,n)).find("input").off("change.tsfem-e-focus").on("change.tsfem-e-focus",{idPrefix:t,type:n},a)};let o="tsfem-e-focus-updated-subject.tsfem-e-focus";e(window).off(o).on(o,(e,t)=>{if(!t||!t.idPrefix)return;const a=t.idPrefix,o=d(a,"inflection_data"),l=d(a,"synonym_data"),c=d(a,"definition_selection"),f=d(a,"inflections"),u=d(a,"synonyms"),y=f.querySelector(".tsfem-e-focus-subject-selection"),p=u.querySelector(".tsfem-e-focus-subject-selection"),g=wp.template("tsfem-e-focus-subject-item");let m=o.value&&JSON.parse(o.value),h=m&&m[0]&&m[0].inflections||[],v=l.value&&JSON.parse(l.value),x=v&&v[+c.value]&&v[+c.value].synonyms||[];y.style.opacity=0,p.style.opacity=0;let b=d(a,"active_inflections").value.split(","),w=d(a,"active_synonyms").value.split(","),k=d(a,"keyword").value.toLowerCase(),_="",C=r(a,"inflection"),I=!1;for(let n in h)I=h[n]===k,_+=g({id:r(C,n),value:h[n],checked:I||-1{e(window).trigger("tsfem-e-focus-updated-subject",[{idPrefix:t}])};let H={};const D=e=>{H.hasOwnProperty(e)||(H[e]={inflections:void 0,synonyms:void 0});const t=()=>{let t=[],n=d(e,"keyword").value;const s=d(e,"active_inflections");if(s instanceof HTMLInputElement&&s.value){let n=d(e,"inflection_data").value,a=JSON.parse(n)[0].inflections;s.value.split(",").forEach(e=>{t.push(a[+e])})}return-1===t.indexOf(n)&&t.push(n),H[e].inflections=t},n=()=>{let t=[];const n=d(e,"active_synonyms"),s=d(e,"definition_selection");if(n instanceof HTMLInputElement&&n.value){let a=d(e,"synonym_data").value,o=JSON.parse(a)[+s.value].synonyms;n.value.split(",").forEach(e=>{t.push(o[+e])})}return H[e].synonyms=t},s=s=>{if(void 0!==H[e][s])return H[e][s];return"inflections"===s?t():"synonyms"===s?n():{inflections:t(),synonyms:n()}},a=t=>{t?delete H[e][t]:delete H[e]};return{get:e=>s(e),clearCache:e=>a(e)}},B=(e,t)=>{if("undefined"!=typeof o[e]){t=t||"unknown";for(let n=o[e].length;n--;)tsfem_inpost.setIconClass(document.getElementById(o[e][n]).querySelector(".tsfem-e-focus-assessment-rating"),t)}},F=(e,t)=>{let n=o;n&&n===Object(n)||(n=[]),n[t]&&n[t]===Object(n[t])||(n[t]=[]),e.id&&("undefined"==typeof a[t]?delete n[t][e.id]:0>n[t].indexOf(e.id)&&n[t].push(e.id)),o=n};let W={},U={};const N=t=>{const n=e=>{tsfem_inpost.promiseLoop(o[e],e=>{let t=l(e),n=d(t,"keyword"),s=n.value||"";if(!s.length)return;let a=document.getElementById(e),i=a.querySelector(".tsfem-e-focus-assessment-rating");tsfem_inpost.setIconClass(i,"loading"),setTimeout(()=>p(a),150)})},s=e=>{"undefined"==typeof o[e.data.type]||(clearTimeout(W[e.data.type]),!U[e.data.type]&&(setTimeout(()=>tsfem_inpost.setIconClass(document.querySelectorAll("[data-assessment-type=\""+e.data.type+"\"] .tsfem-e-focus-assessment-rating"),"unknown"),0),U[e.data.type]=!0),W[e.data.type]=setTimeout(()=>{n(e.data.type),U[e.data.type]=!1},1500))},i=t=>{let n=R(t).get("names");e(a[t].join(", ")).off(n).on(n,{type:t},s)};if(t)"undefined"!=typeof a[t]&&i(t);else for(let e in a)"undefined"!=typeof a[e]&&i(e)};let G={};const K=t=>{t=t||0,clearTimeout(G[t]),G[t]=setTimeout(()=>{if(t){let e=d(t,"scores"),n=e&&e.querySelectorAll(".tsfem-e-focus-assessment-wrap[data-assess=\"1\"]");n instanceof NodeList&&n.length?tsfem_inpost.promiseLoop(n,e=>p(e),150):E(t).to("error")}else{for(var n in a)e(a[n].join(", ")).trigger(R(n).get("trigger"))}},1e3)},R=e=>{const t=["tsfem-e-focus.analysis-"+e,"input.tsfem-e-focus-"+e,"change.tsfem-e-focus-"+e];return{get:e=>"names"===e?t.join(" "):"trigger"===e?t[0]:t}},z=()=>{let t=e(document),n=document.getElementById("tsf-gutenberg-data-holder");if(!n)return;const s=e=>`tsfem-focus-gbc-${e}`,a=e=>document.getElementById(s(e)),i=(e,t)=>{o(e),setTimeout(()=>{u(t),N(t)}),document.dispatchEvent(new CustomEvent(`tsfem-focus-gutenberg-${e}-store-set`))},o=e=>{if(!a(e)){let t=document.createElement("div");t.id=s(e),t.style.display="none",n.appendChild(t)}},l=(e,t)=>{a(e).innerHTML=t},r=(t,n)=>{e("#"+s(t)).trigger(R(n).get("trigger"))};t.on("tsf-updated-gutenberg-title",(e,t)=>{l("title",t),r("title","pageTitle")}),i("title","pageTitle"),t.on("tsf-updated-gutenberg-link",(e,t)=>{l("link",t),r("link","pageUrl")}),i("link","pageUrl");const d=e=>{l("content",e),r("content","pageContent")};t.on("tsf-updated-gutenberg-content",(e,t)=>{let n=lodash.debounce(d,500),s=!1,a=wp.data.select("core/block-editor")||wp.data.select("core/editor");"function"==typeof a.isTyping&&(s=a.isTyping()),s?(B("pageContent","unknown"),n(t)):(n.cancel(),d(t))}),i("content","pageContent")},J=()=>{const n=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;(()=>{if("undefined"==typeof t.focusElements.pageUrl)return;let s=document.getElementById("edit-slug-box");if(!s||!s instanceof HTMLElement)return;const a=()=>{let e=document.querySelectorAll(".tsfem-e-focus-assessment-wrap[data-assessment-type=\"url\"][data-assess=\"0\"]");e instanceof NodeList&&e.length&&(u("pageUrl"),N("pageUrl"),e.forEach(e=>S(e)))};new n(()=>{a(),N("pageUrl"),e("#sample-permalink").trigger(R("pageUrl").get("trigger"))}).observe(s,{childList:!0,subtree:!0})})(),(()=>{if("undefined"==typeof tinyMCE||"function"!=typeof tinyMCE.on)return;let t=!1;tinyMCE.on("addEditor",n=>{if(t)return;if("content"!==n.editor.id)return;t=!0,u("pageContent"),N("pageContent");let s={},a=tinyMCE.get("content"),i=!1,o=!1;a.on("Dirty",()=>{o||(B("pageContent","unknown"),o=!0)}),a.on("GetContent",()=>{clearTimeout(s.GetContent),!i&&a.isDirty()&&(B("pageContent","loading"),i=!0,o=!1),s.GetContent=setTimeout(()=>{a.isDirty()||e("#content").trigger(R("pageContent").get("trigger")),i=!1,o=!1},1e3)})})})()},Q=()=>{t.isGutenbergPage?z():J()},V=()=>{let e=document.querySelectorAll(".tsfem-e-focus-collapse-wrap");for(let n=e.length;n--;){let s=l(e[n].id),a=d(s,"keyword");if(a.value.length){if(a.dataset.prev=a.value,tsfem_inpost.isPremium&&t.languageSupported.any){let e=d(s,"lexical_selector");e.dataset.prev=e.value,1{if(Q(),t.hasOwnProperty("focusElements")&&(f(t.focusElements,!0),u(),N()),0===Object.keys(a).length){let e=document.getElementById("tsfem-e-focus-analysis-wrap");if(e instanceof Element){let t=e.querySelector(".tsf-flex-setting-input");t instanceof Element&&(t.innerHTML=wp.template("tsfem-e-focus-nofocus")())}return}j(),T(),tsfem_inpost.isPremium&&t.languageSupported.any&&(q(),M()),V()},Y=()=>{e(".tsfem-e-focus-enable-if-js").removeAttr("disabled"),e(".tsfem-e-focus-disable-if-js").attr("disabled","disabled"),e(".tsfem-e-focus-requires-javascript").removeClass("tsfem-e-focus-requires-javascript")};return Object.assign({load:()=>{document.body.addEventListener("tsf-onload",Y),document.body.addEventListener("tsf-ready",X)}},{focusRegistry:s,activeFocusAreas:a,activeAssessments:o,updateFocusRegistry:f,updateActiveFocusAreas:u,resetAnalysisChangeListeners:N,triggerAllAnalysis:K,analysisChangeEvents:R,getSubIdPrefix:l,getSubElementById:d,setAllRatersOf:B})}(jQuery),window.tsfem_e_focus_inpost.load(); diff --git a/extensions/essentials/focus/trunk/views/inpost/focus-template.php b/extensions/essentials/focus/trunk/views/inpost/focus-template.php index af65f193..009bac94 100644 --- a/extensions/essentials/focus/trunk/views/inpost/focus-template.php +++ b/extensions/essentials/focus/trunk/views/inpost/focus-template.php @@ -3,9 +3,13 @@ * @package TSF_Extension_Manager\Extension\Focus\Admin\Views * @subpackage TSF_Extension_Manager\Inpost\Audit; */ + namespace TSF_Extension_Manager\Extension\Focus; -defined( 'ABSPATH' ) and $_class = \TSF_Extension_Manager\Extension\Focus\get_active_class() and $this instanceof $_class or die; +// phpcs:disable, VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- includes. (somehow, this file doesn't parse well...) +// phpcs:disable, WordPress.WP.GlobalVariablesOverride -- This isn't the global scope. + +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) and $_class = \TSF_Extension_Manager\Extension\Focus\get_active_class() and $this instanceof $_class or die; ?>
> @@ -32,11 +36,14 @@ '', \esc_attr( $post_input['lexical_form']['selector_id'] ), \esc_attr( $post_input['lexical_form']['value'] ), - \esc_attr( implode( ' ', [ - 'tsfem-e-focus-lexical-selector', - 'tsfem-e-focus-enable-if-js', - 'tsfem-e-focus-requires-javascript', - ] ) ), + \esc_attr( implode( + ' ', + [ + 'tsfem-e-focus-lexical-selector', + 'tsfem-e-focus-enable-if-js', + 'tsfem-e-focus-requires-javascript', + ] + ) ), \TSF_Extension_Manager\HTML::make_sequential_dropdown_option_list( $post_input['lexical_data']['value'], $post_input['lexical_form']['value'] ?: '' @@ -55,7 +62,7 @@ vprintf( '', [ - $is_premium ? \esc_attr( $hidden_input['id'] ) : '', + \esc_attr( $is_premium ? $hidden_input['id'] : '' ), \esc_attr( $hidden_input['id'] ), \esc_attr( json_encode( $hidden_input['value'] ) ), ] @@ -68,7 +75,7 @@ vprintf( '', [ - $is_premium ? \esc_attr( $hidden_input['id'] ) : '', + \esc_attr( $is_premium ? $hidden_input['id'] : '' ), \esc_attr( $hidden_input['id'] ), \esc_attr( $hidden_input['value'] ), ] @@ -85,12 +92,15 @@ printf( '%s', - \esc_attr( implode( ' ', [ - 'tsfem-e-focus-edit-subject-button-wrap', - 'tsfem-e-focus-edit-subject-button-wrap-disabled', - 'tsfem-e-focus-requires-javascript', - 'tsf-tooltip-wrap', - ] ) ), + \esc_attr( implode( + ' ', + [ + 'tsfem-e-focus-edit-subject-button-wrap', + 'tsfem-e-focus-edit-subject-button-wrap-disabled', + 'tsfem-e-focus-requires-javascript', + 'tsf-tooltip-wrap', + ] + ) ), vsprintf( '%s', [ @@ -99,12 +109,15 @@ \esc_attr( $action_ids['subject_edit'] ) ), \esc_attr( $action_ids['subject_edit'] ), - \esc_attr( implode( ' ', [ - 'tsfem-e-focus-edit-subject', - 'tsfem-e-inpost-icon', - 'tsfem-e-inpost-icon-edit', - 'tsf-tooltip-item', - ] ) ), + \esc_attr( implode( + ' ', + [ + 'tsfem-e-focus-edit-subject', + 'tsfem-e-inpost-icon', + 'tsfem-e-inpost-icon-edit', + 'tsf-tooltip-item', + ] + ) ), \esc_attr__( 'Adjusting the subject requires JavaScript', 'the-seo-framework-extension-manager' ), \esc_attr( $_tooltip ), ] @@ -114,7 +127,7 @@ //= TEMP until highligher comes. print ''; } - // TODO: upcoming version. + // phpcs:disable -- TODO: upcoming version. // printf( // '%s', // \esc_attr( implode( ' ', [ @@ -141,9 +154,10 @@ // ] // ) // ); + // phpcs:enable printf( '', - \esc_attr( $action_ids['collapser'] ), //* @see first checkbox + \esc_attr( $action_ids['collapser'] ), // @see first checkbox \esc_attr__( 'View analysis', 'the-seo-framework-extension-manager' ), '' ); diff --git a/extensions/essentials/focus/trunk/views/inpost/inpost.php b/extensions/essentials/focus/trunk/views/inpost/inpost.php index f4ab1417..527ddbec 100644 --- a/extensions/essentials/focus/trunk/views/inpost/inpost.php +++ b/extensions/essentials/focus/trunk/views/inpost/inpost.php @@ -3,33 +3,49 @@ * @package TSF_Extension_Manager\Extension\Focus\Admin\Views * @subpackage TSF_Extension_Manager\Inpost\Audit; */ + namespace TSF_Extension_Manager\Extension\Focus; +// phpcs:disable, VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- includes. +// phpcs:disable, WordPress.WP.GlobalVariablesOverride -- This isn't the global scope. + /** * @package TSF_Extension_Manager\Classes */ use \TSF_Extension_Manager\InpostGUI as InpostGUI; use \TSF_Extension_Manager\InpostHTML as InpostHTML; -defined( 'ABSPATH' ) and InpostGUI::verify( $_secret ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) and InpostGUI::verify( $_secret ) or die; $option_index = InpostGUI::get_option_key( $post_meta['kw']['option_index'], $post_meta['pm_index'] ); + $make_option_id = function( $id, $key ) use ( $option_index ) { return sprintf( '%s[%s][%s]', $option_index, $id, $key ); }; create_analysis_field :; $focus_title = sprintf( '
%s
', $post_meta['kw']['label']['title'] ); - $focus_info = sprintf( '
%s
', \the_seo_framework()->make_info( - $post_meta['kw']['label']['desc'], - $post_meta['kw']['label']['link'], - false - ) ); + $focus_info = sprintf( + '
%s
', + \the_seo_framework()->make_info( + $post_meta['kw']['label']['desc'], + $post_meta['kw']['label']['link'], + false + ) + ); $focus_label = $focus_title . $focus_info; //= Fix array if data is missing. - $keyword_meta = array_slice( array_merge_recursive( $post_meta['kw']['values'], $defaults ), 0, 3 ); + $keyword_meta = \array_slice( + array_merge_recursive( + $post_meta['kw']['values'], + $defaults + ), + 0, + 3 + ); + // phpcs:disable, Generic.WhiteSpace.ScopeIndent.IncorrectExact -- we're templating. analysis_fields_output :; InpostHTML::wrap_flex( 'block-open', '', 'tsfem-e-focus-analysis-wrap' ); InpostHTML::wrap_flex( 'label', $focus_label ); @@ -42,69 +58,70 @@ return isset( $values[ $id ] ) ? $values[ $id ] : ''; }; - call_user_func( - $template_cb, [ - 'supportive' => (bool) $i++, // true if 2nd or later iteration. - 'is_premium' => $is_premium, + \call_user_func( + $template_cb, + [ + 'supportive' => (bool) $i++, // true if 2nd or later iteration. + 'is_premium' => $is_premium, 'language_supported' => $language_supported, - 'has_keyword' => (bool) strlen( $values['keyword'] ), - 'sub_scores' => [ + 'has_keyword' => (bool) \strlen( $values['keyword'] ), + 'sub_scores' => [ 'key' => $make_option_id( $id, 'scores' ), 'values' => $values['scores'], ], - 'wrap_ids' => [ + 'wrap_ids' => [ /* These shouldn't be saved. */ - 'collapse' => $make_option_id( $id, 'collapse' ), - 'header' => $make_option_id( $id, 'header' ), - 'content' => $make_option_id( $id, 'content' ), - 'edit' => $make_option_id( $id, 'edit' ), - 'evaluate' => $make_option_id( $id, 'evaluate' ), + 'collapse' => $make_option_id( $id, 'collapse' ), + 'header' => $make_option_id( $id, 'header' ), + 'content' => $make_option_id( $id, 'content' ), + 'edit' => $make_option_id( $id, 'edit' ), + 'evaluate' => $make_option_id( $id, 'evaluate' ), 'inflections' => $make_option_id( $id, 'inflections' ), - 'synonyms' => $make_option_id( $id, 'synonyms' ), + 'synonyms' => $make_option_id( $id, 'synonyms' ), ], - 'action_ids' => [ + 'action_ids' => [ /* These shouldn't be saved. */ - 'collapser' => $make_option_id( $id, 'collapser' ), - 'highlighter' => $make_option_id( $id, 'highlighter' ), - 'subject_edit' => $make_option_id( $id, 'subject_edit' ), + 'collapser' => $make_option_id( $id, 'collapser' ), + 'highlighter' => $make_option_id( $id, 'highlighter' ), + 'subject_edit' => $make_option_id( $id, 'subject_edit' ), 'definition_selector' => $make_option_id( $id, 'definition_selector' ), ], - 'post_input' => [ - 'keyword' => [ + 'post_input' => [ + 'keyword' => [ 'id' => $make_option_id( $id, 'keyword' ), 'value' => $get_value( 'keyword' ), ], - 'lexical_form' => [ - 'id' => $make_option_id( $id, 'lexical_form' ), + 'lexical_form' => [ + 'id' => $make_option_id( $id, 'lexical_form' ), 'selector_id' => $make_option_id( $id, 'lexical_selector' ), - 'value' => $get_value( 'lexical_form' ), + 'value' => $get_value( 'lexical_form' ), ], - 'lexical_data' => [ + 'lexical_data' => [ 'id' => $make_option_id( $id, 'lexical_data' ), 'value' => $get_value( 'lexical_data' ) ?: [], ], - 'active_inflections' => [ + 'active_inflections' => [ 'id' => $make_option_id( $id, 'active_inflections' ), 'value' => $get_value( 'active_inflections' ), ], - 'active_synonyms' => [ + 'active_synonyms' => [ 'id' => $make_option_id( $id, 'active_synonyms' ), 'value' => $get_value( 'active_synonyms' ), ], 'definition_selection' => [ - 'id' => $make_option_id( $id, 'definition_selection' ), + 'id' => $make_option_id( $id, 'definition_selection' ), 'selector_id' => $make_option_id( $id, 'definition_dropdown' ), - 'value' => $get_value( 'definition_selection' ), + 'value' => $get_value( 'definition_selection' ), ], - 'inflection_data' => [ + 'inflection_data' => [ 'id' => $make_option_id( $id, 'inflection_data' ), 'value' => $get_value( 'inflection_data' ) ?: [], ], - 'synonym_data' => [ + 'synonym_data' => [ 'id' => $make_option_id( $id, 'synonym_data' ), 'value' => $get_value( 'synonym_data' ) ?: [], ], - 'score' => [ + 'score' => [ 'id' => $make_option_id( $id, 'score' ), 'value' => $get_value( 'score' ) ?: [], ], @@ -114,3 +131,4 @@ endforeach; InpostHTML::wrap_flex( 'content-close', '' ); InpostHTML::wrap_flex( 'block-close', '' ); + // phpcs:enable, Generic.WhiteSpace.ScopeIndent.IncorrectExact diff --git a/extensions/essentials/focus/trunk/views/inpost/js-templates.php b/extensions/essentials/focus/trunk/views/inpost/js-templates.php index 75bf2fd3..79f8b495 100644 --- a/extensions/essentials/focus/trunk/views/inpost/js-templates.php +++ b/extensions/essentials/focus/trunk/views/inpost/js-templates.php @@ -3,18 +3,22 @@ * @package TSF_Extension_Manager\Extension\Focus\Views * @subpackage TSF_Extension_Manager\Inpost\Audit\Templates; */ + namespace TSF_Extension_Manager\Extension\Focus; +// phpcs:disable, VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- includes. +// phpcs:disable, WordPress.WP.GlobalVariablesOverride -- This isn't the global scope. + /** * @package TSF_Extension_Manager\Classes */ use \TSF_Extension_Manager\InpostGUI as InpostGUI; -defined( 'ABSPATH' ) and InpostGUI::verify( $_secret ) or die; +\defined( 'TSF_EXTENSION_MANAGER_PRESENT' ) and InpostGUI::verify( $_secret ) or die; ?>