Changeset 3423066
- Timestamp:
- 12/18/2025 03:54:37 PM (3 months ago)
- Location:
- diagnoseo
- Files:
-
- 6 edited
- 51 copied
-
tags/1.2.56 (copied) (copied from diagnoseo/trunk)
-
tags/1.2.56/css/diagnoseo-admin.css (copied) (copied from diagnoseo/trunk/css/diagnoseo-admin.css)
-
tags/1.2.56/css/diagnoseo-editor.css (copied) (copied from diagnoseo/trunk/css/diagnoseo-editor.css)
-
tags/1.2.56/css/diagnoseo.css (copied) (copied from diagnoseo/trunk/css/diagnoseo.css)
-
tags/1.2.56/diagnoseo.php (copied) (copied from diagnoseo/trunk/diagnoseo.php) (1 diff)
-
tags/1.2.56/includes/actions.php (copied) (copied from diagnoseo/trunk/includes/actions.php)
-
tags/1.2.56/includes/admin-bar-menu.php (copied) (copied from diagnoseo/trunk/includes/admin-bar-menu.php)
-
tags/1.2.56/includes/api-endpoints.php (copied) (copied from diagnoseo/trunk/includes/api-endpoints.php)
-
tags/1.2.56/includes/assets.php (copied) (copied from diagnoseo/trunk/includes/assets.php)
-
tags/1.2.56/includes/blocks.php (copied) (copied from diagnoseo/trunk/includes/blocks.php)
-
tags/1.2.56/includes/blocks/breadcrumbs/breadcrumbs.php (copied) (copied from diagnoseo/trunk/includes/blocks/breadcrumbs/breadcrumbs.php)
-
tags/1.2.56/includes/category-links.php (copied) (copied from diagnoseo/trunk/includes/category-links.php)
-
tags/1.2.56/includes/class-diagnoseo-breadcrumbs.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-breadcrumbs.php) (2 diffs)
-
tags/1.2.56/includes/class-diagnoseo-generalsettings.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-generalsettings.php)
-
tags/1.2.56/includes/class-diagnoseo-metabox-placeholders.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-metabox-placeholders.php)
-
tags/1.2.56/includes/class-diagnoseo-metatags.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-metatags.php)
-
tags/1.2.56/includes/class-diagnoseo-metatagsettings.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-metatagsettings.php)
-
tags/1.2.56/includes/class-diagnoseo-postmetaimport.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-postmetaimport.php) (5 diffs)
-
tags/1.2.56/includes/class-diagnoseo-pro-version.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-pro-version.php)
-
tags/1.2.56/includes/class-diagnoseo-schemasettings.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-schemasettings.php)
-
tags/1.2.56/includes/class-diagnoseo-scripts.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-scripts.php)
-
tags/1.2.56/includes/class-diagnoseo-scriptsettings.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-scriptsettings.php)
-
tags/1.2.56/includes/class-diagnoseo-settings.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-settings.php)
-
tags/1.2.56/includes/class-diagnoseo-settingshelper.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-settingshelper.php)
-
tags/1.2.56/includes/class-diagnoseo-sitemapsettings.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-sitemapsettings.php)
-
tags/1.2.56/includes/class-diagnoseo-socialsettings.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-socialsettings.php)
-
tags/1.2.56/includes/class-diagnoseo-toolspage.php (copied) (copied from diagnoseo/trunk/includes/class-diagnoseo-toolspage.php)
-
tags/1.2.56/includes/content-watcher-meta.php (copied) (copied from diagnoseo/trunk/includes/content-watcher-meta.php)
-
tags/1.2.56/includes/content-watcher-scripts.php (copied) (copied from diagnoseo/trunk/includes/content-watcher-scripts.php)
-
tags/1.2.56/includes/css-variables.php (copied) (copied from diagnoseo/trunk/includes/css-variables.php)
-
tags/1.2.56/includes/customize/breadcrumbs.php (copied) (copied from diagnoseo/trunk/includes/customize/breadcrumbs.php)
-
tags/1.2.56/includes/customize/customize-utils.php (copied) (copied from diagnoseo/trunk/includes/customize/customize-utils.php)
-
tags/1.2.56/includes/customize/deeplink.php (copied) (copied from diagnoseo/trunk/includes/customize/deeplink.php)
-
tags/1.2.56/includes/customize/defaults.php (copied) (copied from diagnoseo/trunk/includes/customize/defaults.php)
-
tags/1.2.56/includes/metabox-seo-settings.php (copied) (copied from diagnoseo/trunk/includes/metabox-seo-settings.php)
-
tags/1.2.56/includes/option-defaults.php (copied) (copied from diagnoseo/trunk/includes/option-defaults.php)
-
tags/1.2.56/includes/sitemap.php (copied) (copied from diagnoseo/trunk/includes/sitemap.php)
-
tags/1.2.56/includes/structured-data.php (copied) (copied from diagnoseo/trunk/includes/structured-data.php)
-
tags/1.2.56/includes/utils.php (copied) (copied from diagnoseo/trunk/includes/utils.php)
-
tags/1.2.56/js/blocks/breadcrumbs.min.js (copied) (copied from diagnoseo/trunk/js/blocks/breadcrumbs.min.js)
-
tags/1.2.56/js/build/index.js (copied) (copied from diagnoseo/trunk/js/build/index.js) (1 diff)
-
tags/1.2.56/js/diagnoseo-checks.min.js (copied) (copied from diagnoseo/trunk/js/diagnoseo-checks.min.js)
-
tags/1.2.56/js/diagnoseo-editor-metabox.min.js (copied) (copied from diagnoseo/trunk/js/diagnoseo-editor-metabox.min.js)
-
tags/1.2.56/js/diagnoseo-editor.min.js (copied) (copied from diagnoseo/trunk/js/diagnoseo-editor.min.js) (1 diff)
-
tags/1.2.56/js/diagnoseo.min.js (copied) (copied from diagnoseo/trunk/js/diagnoseo.min.js)
-
tags/1.2.56/js/formats/build/index.asset.php (copied) (copied from diagnoseo/trunk/js/formats/build/index.asset.php)
-
tags/1.2.56/js/formats/build/index.js (copied) (copied from diagnoseo/trunk/js/formats/build/index.js)
-
tags/1.2.56/languages (copied) (copied from diagnoseo/trunk/languages)
-
tags/1.2.56/readme.txt (copied) (copied from diagnoseo/trunk/readme.txt) (1 diff)
-
tags/1.2.56/smtconfig.json (copied) (copied from diagnoseo/trunk/smtconfig.json)
-
tags/1.2.56/wpml-config.xml (copied) (copied from diagnoseo/trunk/wpml-config.xml)
-
trunk/diagnoseo.php (modified) (1 diff)
-
trunk/includes/class-diagnoseo-breadcrumbs.php (modified) (2 diffs)
-
trunk/includes/class-diagnoseo-postmetaimport.php (modified) (5 diffs)
-
trunk/js/build/index.js (modified) (1 diff)
-
trunk/js/diagnoseo-editor.min.js (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
diagnoseo/tags/1.2.56/diagnoseo.php
r3365809 r3423066 4 4 * Plugin URI: https://diagnoseo.com/wordpress-seo-plugin/ 5 5 * Description: Powerful SEO plugin for WordPress. The most lightweight and complete SEO solution on the market! It includes best-in-class content analyzer and keyword placement checkpoints. 6 * Version: 1.2.5 46 * Version: 1.2.56 7 7 * Author: DiagnoSEO 8 8 * Author URI: https://diagnoseo.com/ -
diagnoseo/tags/1.2.56/includes/class-diagnoseo-breadcrumbs.php
r3328173 r3423066 103 103 private function prepare_page_ancestor_data( $post_id ) { 104 104 $bc_parent = intval( get_post_meta( $post_id, 'diagnoseo_bc_parent', true ) ); 105 $post_array = empty( $bc_parent ) ? get_post_ancestors( $post_id ) : array( $bc_parent );105 $post_array = empty( $bc_parent ) ? get_post_ancestors( $post_id ) : $this->get_bc_ancestors( $bc_parent ); 106 106 krsort( $post_array ); 107 107 … … 111 111 $this->prepare_item_data( empty( $postlist_title ) ? $post->post_title : $postlist_title, get_permalink( $postid ) ); 112 112 } 113 } 114 /** 115 * Gets post ancestors by the diagnoseo_bc_parent custom field 116 * 117 * @param Integer $post_id ID of the current post. 118 */ 119 private function get_bc_ancestors( $post_id ) { 120 $ancestors = array( $post_id ); 121 $bc_parent = intval( get_post_meta( $post_id, 'diagnoseo_bc_parent', true ) ); 122 while ( ! empty( $bc_parent ) ) { 123 $ancestors[] = $bc_parent; 124 $bc_parent = intval( get_post_meta( $bc_parent, 'diagnoseo_bc_parent', true ) ); 125 } 126 return $ancestors; 113 127 } 114 128 -
diagnoseo/tags/1.2.56/includes/class-diagnoseo-postmetaimport.php
r3115296 r3423066 14 14 */ 15 15 class Diagnoseo_PostMetaImport { 16 17 /** 18 * @var array meta_keys Diagnoseo meta key names. 19 */ 20 private $meta_keys = array( 'diagnoseo_meta_keyword', 'diagnoseo_meta_title', 'diagnoseo_meta_description' ); 21 22 /** 23 * @var array import_keys Meta keys imported for each plugin 24 */ 25 private $import_keys = array( 26 'rankmath' => array( 'rank_math_focus_keyword', 'rank_math_title', 'rank_math_description' ), 27 'aioseo' => array( '_aioseo_keywords', '_aioseo_title', '_aioseo_description' ), 28 'yoast' => array( '_yoast_wpseo_focuskw', '_yoast_wpseo_title', '_yoast_wpseo_metadesc' ), 29 'seopress' => array( '_seopress_analysis_target_kw', 'rank_math_title', 'rank_math_description' ), 30 ); 16 31 /** 17 32 * Title/description variables for plugins … … 19 34 * @var array plugin_vars 20 35 */ 21 p ublic$plugin_vars = array(36 private $plugin_vars = array( 22 37 'yoast' => array( 23 38 '%%sitename%%', … … 158 173 * @var array new_vars 159 174 */ 160 p ublic$new_vars = array(175 private $new_vars = array( 161 176 'yoast' => array( 162 177 '%sitename%', … … 383 398 */ 384 399 private function import_rankmath_postmeta( $prevent_overwrite = false ) { 385 $this->import_home_meta_rankmath(); 386 387 $options = array( 388 'post_type' => 'any', 389 'posts_per_page' => -1, 390 'meta_query' => array( //phpcs:ignore 391 'relation' => 'OR', 392 array( 393 'key' => 'rank_math_focus_keyword', 394 'compare' => 'EXISTS', 395 ), 396 array( 397 'key' => 'rank_math_title', 398 'compare' => 'EXISTS', 399 ), 400 array( 401 'key' => 'rank_math_description', 402 'compare' => 'EXISTS', 403 ), 404 ), 405 ); 406 407 $query = new WP_Query( $options ); 408 if ( $query->have_posts() ) { 409 while ( $query->have_posts() ) { 410 $query->the_post(); 411 $meta = get_post_custom( get_the_ID() ); 412 ?> 413 <p> 414 <?php esc_html_e( 'Importing meta data for post:', 'diagnoseo' ); ?><br> 415 <?php echo esc_html( get_the_ID() . ' (' . get_the_title() . ')' ); ?> 416 </p> 417 <?php 418 $keyword = empty( $meta['rank_math_focus_keyword'] ) ? '' : $meta['rank_math_focus_keyword'][0]; 419 $title = empty( $meta['rank_math_title'] ) ? '' : str_replace( $this->plugin_vars['rankmath'], $this->new_vars['rankmath'], $meta['rank_math_title'][0] ); 420 $descr = empty( $meta['rank_math_description'] ) ? '' : str_replace( $this->plugin_vars['rankmath'], $this->new_vars['rankmath'], $meta['rank_math_description'][0] ); 421 422 if ( ! empty( $keyword ) ) { 423 $current_keyword = get_post_meta( get_the_ID(), 'diagnoseo_meta_keyword', true ); 424 if ( ( $prevent_overwrite && empty( $current_keyword ) ) || ! $prevent_overwrite ) { 425 update_post_meta( get_the_ID(), 'diagnoseo_meta_keyword', $keyword ); 426 } 427 } 428 if ( ! empty( $title ) ) { 429 $current_title = get_post_meta( get_the_ID(), 'diagnoseo_meta_title', true ); 430 if ( ( $prevent_overwrite && empty( $current_title ) ) || ! $prevent_overwrite ) { 431 update_post_meta( get_the_ID(), 'diagnoseo_meta_title', $title ); 432 } 433 } 434 if ( ! empty( $descr ) ) { 435 $current_descr = get_post_meta( get_the_ID(), 'diagnoseo_meta_description', true ); 436 if ( ( $prevent_overwrite && empty( $current_descr ) ) || ! $prevent_overwrite ) { 437 update_post_meta( get_the_ID(), 'diagnoseo_meta_description', $descr ); 438 } 439 } 440 } 441 } 400 global $wpdb; 401 $wpdb->flush(); 402 $time = microtime(true); 403 404 $imported_meta = $this->fetch_postmeta( $this->import_keys['rankmath'] ); 405 $current_meta = $this->fetch_postmeta( $this->meta_keys ); 406 $new_meta = $this->prepare_postmeta( $imported_meta, $current_meta, 'rankmath', $prevent_overwrite ); 407 $result = $this->save_imported_postmeta( $new_meta['insert'], $new_meta['update'] ); 408 409 $duration = intval( microtime(true) - $time ) ?? 0; 410 echo "<p>Import time: $duration milliseconds<br>Inserted: {$result['inserted']}<br>Updated: {$result['updated']}</p>"; 442 411 } 443 412 … … 745 714 } 746 715 716 /** 717 * Inserts imported post meta to the database. 718 * 719 * @param Array $data Array of post meta objects. 720 */ 721 private function insert_postmeta( $data ) { 722 global $wpdb; 723 $values = array_map( 724 function( $item ) { 725 return "($item->post_id, '$item->meta_key', '$item->meta_value')"; 726 }, 727 $data 728 ); 729 $sql = "insert into {$wpdb->prefix}postmeta (post_id, meta_key, meta_value) values " . implode( ', ', $values); 730 $result = $wpdb->query( $sql ); 731 return $result; 732 } 733 734 /** 735 * Updates post meta entries. 736 * 737 * @param Array $data Array of post meta objects 738 */ 739 private function update_postmeta( $data ) { 740 global $wpdb; 741 $where = implode( "', '", $this->meta_keys ); 742 $updates = array(); 743 foreach ( $data as $item ) { 744 $updates[] = "when meta_key='{$item->meta_key}' and post_id={$item->post_id} then '{$item->meta_value}'"; 745 } 746 $updates = implode( "\n ", $updates); 747 $sql = "update {$wpdb->prefix}postmeta set meta_value = case 748 $updates 749 else meta_value 750 end 751 where meta_key in ('$where')"; 752 753 $result = $wpdb->query( $sql ); 754 return $result; 755 } 756 757 /** 758 * Fetches post meta with certain keys 759 * 760 * @param Array $keys Array of meta field keys. 761 */ 762 private function fetch_postmeta( $keys ) { 763 global $wpdb; 764 $key_list = "'" . implode( "', '", $keys ) . "'"; 765 $sql = "select post_id, meta_key, meta_value from {$wpdb->prefix}postmeta where meta_key in ($key_list)"; 766 return $wpdb->get_results($sql); 767 } 768 769 /** 770 * Prepares the post meta for import: changes keys and in-value variables 771 * 772 * @param Array $imported Post meta object array imported from plugin 773 * @param Array $current Post meta added with DiagnoSEO 774 * @param String $src Slug of plugin from which we are importing 775 * @param Boolean $prevent_overwrite If the import should preserve already set post meta 776 */ 777 private function prepare_postmeta( $imported, $current, $src, $prevent_overwrite = false ) { 778 $new_meta = array(); 779 780 // replace key names and variables in meta values. 781 foreach ( $imported as $item ) { 782 if ( in_array( $item->meta_key, $this->import_keys[ $src ] ) ) { 783 $item->meta_key = str_replace($this->import_keys[ $src ], $this->meta_keys, $item->meta_key); 784 $item->meta_value = str_replace($this->plugin_vars[ $src ], $this->new_vars[ $src ], $item->meta_value); 785 $new_meta[] = $item; 786 } 787 } 788 789 // split entries to those that will be inserted and those that will be updated/ 790 $to_insert = array(); 791 $to_update = array(); 792 793 foreach ( $new_meta as $item ) { 794 $found = array_find( 795 $current, 796 function( $entry ) use ( $item ) { 797 return $entry->post_id === $item->post_id && $entry->meta_key === $item->meta_key; 798 } 799 ); 800 if ( empty( $found ) ) { 801 $to_insert[] = $item; 802 } elseif ( ! $prevent_overwrite ) { 803 $to_update[] = $item; 804 } 805 } 806 807 // return the result. 808 return array( 809 'insert' => $to_insert, 810 'update' => $to_update, 811 ); 812 } 813 814 /** 815 * Saves imported post meta to database and returns numbers of inserted and updated entries 816 * 817 * @param Array $to_insert Array of post meta objectsto be inserted 818 * @param Array $to_update Array of post meta objectsto be updated 819 */ 820 private function save_imported_postmeta( $to_insert, $to_update ) { 821 if ( ! empty( $to_insert ) ) { 822 $inserted = $this->insert_postmeta( $to_insert ); 823 } 824 if ( ! empty( $to_update ) ) { 825 $updated = $this->update_postmeta( $to_update ); 826 } 827 828 return array( 829 'inserted' => $inserted ?? 0, 830 'updated' => $updated ?? 0, 831 ); 832 } 747 833 748 834 } -
diagnoseo/tags/1.2.56/js/build/index.js
r3213874 r3423066 1 !function(){"use strict";var e=window.wp.element,t=window.wp.plugins,a=function(){return(0,e.createElement)("svg",{"enable-background":"new 0 0 20 20",height:"20",width:"20",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",className:"diagnoseo-icon"},(0,e.createElement)("clipPath",{id:"a"},(0,e.createElement)("path",{d:"m0 0h20v20h-20z"})),(0,e.createElement)("path",{className:"diagnoseo-icon-part-tick",d:"m12.377 5.866 1.835 1.612-4.839 5.508-4.11-3.576 1.672-1.902 2.256 1.982z"}),(0,e.createElement)("path",{className:"diagnoseo-icon-part-magnifier","clip-path":"url(#a)",d:"m16.298 15.209c1.745-1.983 2.548-4.603 2.208-7.228-.315-2.426-1.555-4.584-3.493-6.077s-4.341-2.139-6.768-1.828c-2.426.315-4.584 1.555-6.077 3.493s-2.142 4.341-1.827 6.767c.649 5.007 5.251 8.554 10.259 7.905 1.441-.188 2.824-.717 4.014-1.536l3.749 3.295 1.476-1.68zm-1.471-1.887c-1.111 1.443-2.72 2.368-4.527 2.602-1.808.235-3.598-.247-5.041-1.361-1.444-1.111-2.368-2.719-2.602-4.527-.483-3.73 2.158-7.158 5.889-7.642.296-.038.59-.057.881-.057 3.375 0 6.316 2.511 6.761 5.946.235 1.806-.249 3.596-1.361 5.039"}))};class l extends React.Component{constructor(e){super(e),this.state={score:0,timeout:null},this.handleCheckChanged=this.handleCheckChanged.bind(this),this.calculateScore=this.calculateScore.bind(this),this.runAllChecks=this.runAllChecks.bind(this)}calculateScore(){const e=window.diagnoseo.checks.filter((e=>"check"===e.type));let t=e.length+1,a=e.filter((e=>e.checked)),l=window.diagnoseo.additionalKeywordCount===window.diagnoseo.RelatedKeywordsInPost?a.length+1:a.length,o=Math.round(100*l/t);this.setState({score:o})}runAllChecks(){const{select:e}=window.wp.data,t=window.diagnoseo.checks.filter((e=>"check"===e.type)),a={postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,featuredImageId:e("core/editor").getEditedPostAttribute("featured_media"),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,slug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks()};if(!a.featuredImageId||a.featuredImage)a.metaTitle=seoHelper.replaceVariables(a.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),a.metaDescription=seoHelper.replaceVariables(a.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),t.forEach(((e,t)=>{if(!e.test)return;let l="ok"===e.test(a),o=window.diagnoseo.checks.findIndex((t=>t.id===e.id));window.diagnoseo.checks[o].checked=l})),this.calculateScore();else var l=setInterval((()=>{e("core").getMedia(a.featuredImageId)&&(clearInterval(l),this.runAllChecks())}),500)}handleCheckChanged(){clearTimeout(this.state.timeout),this.setState({timeout:setTimeout(this.calculateScore,300)})}async componentDidMount(){window.addEventListener("check-changed",this.handleCheckChanged),setTimeout(this.runAllChecks,1e3)}componentWillUnmount(){window.removeEventListener("check-changed",this.handleCheckChanged)}render(){let t,l=this.state.score;switch(!0){case l<60:t="score-low";break;case l>=60&&l<80:t="score-medium";break;case l>=80:t="score-high"}let o=`diagnoseo-button-content ${t}`;return(0,e.createElement)("span",{className:o},(0,e.createElement)(a,null),(0,e.createElement)("b",{className:"diagnoseo-score"},this.state.score,"/100"))}whenEditorIsReady(){return new Promise((e=>{const t=subscribe((()=>{(select("core/editor").isCleanNewPost()||select("core/block-editor").getBlockCount()>0)&&(t(),e())}))}))}}var o=l,n=window.wp.editor,i=window.wp.components,r=window.wp.data,s=window.wp.i18n,d=window.wp.compose,c=(0,d.compose)((0,r.withDispatch)(((e,t)=>({setMetaValue:a=>{var l={};l[t.fieldName]=a,e("core/editor").editPost({meta:l}),t.changeCallback&&t.changeCallback(a)}}))),(0,r.withSelect)(((e,t)=>({metaValue:e("core/editor").getEditedPostAttribute("meta")[t.fieldName]}))))((t=>(0,e.createElement)(i.TextControl,{label:t.label,value:t.metaValue,onChange:e=>t.setMetaValue(e)}))),u=(0,d.compose)((0,r.withSelect)((e=>({content:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword}))))((t=>{var a=0;if(t.keyword){var l=t.content.replace(/<\!--.*?-->/g,""),o=(l=(l=l.replace(/(\r\n|\n|\r)/gm," ")).toLowerCase()).split(" ");o=o.filter((e=>""!==e));var n=seoHelper.countOccurences(t.keyword,l);n&&(a=n/o.length*100,a=parseFloat(a.toFixed(2)))}let i;if(window.diagnoseoPro){let t="diagnoseo-check optimal-keyword-density";t+=a>=1&&a<=3?" ok":" nok",i=(0,e.createElement)("p",{className:t},(0,s.__)("Optimal keyword density","diagnoseo")," ",(0,e.createElement)("b",{className:"value"},"1% - 3%"))}else i=(0,e.createElement)("p",{className:"diagnoseo-check optimal-keyword-density"},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",(0,s.__)("Optimal keyword density","diagnoseo"));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("p",{className:"diagnoseo-stats keyword-density"},(0,s.__)("Keyword density","diagnoseo")," ",(0,e.createElement)("b",{className:"value"},a,"%")),i)})),m=t=>{let a=["diagnoseo-check",t.id];if(t.test){let e=t.test(t.postData);"string"==typeof e&&a.push(e);let l="ok"===e,o=t.checkConfig.findIndex((e=>e.id===t.id));t.checkConfig[o].checked!==l&&window.dispatchEvent(new Event("check-changed")),t.checkConfig[o].checked=l}if(t.inPro)return(0,e.createElement)("p",{className:a.join(" ")},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))));const l=t.valueFieldName&&t.postData[t.valueFieldName]?(0,e.createElement)("b",null,t.postData[t.valueFieldName]):"";return(0,e.createElement)("p",{className:a.join(" ")},t.label," ",l)},g=t=>{let a=["diagnoseo-stats",t.id];if(t.inPro)return(0,e.createElement)("p",{className:a.join(" ")},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))));let l,o=(0,e.createElement)("b",{className:"value"}),n="";if(t.test){let l=t.test(t.postData);o=(0,e.createElement)("b",{className:"value"},l.value),n=l.comment?(0,e.createElement)("span",{className:"comment"},l.comment):"",l.status&&a.push(l.status)}return l=t.order&&"value label"!==t.order?(0,e.createElement)(e.Fragment,null,t.label," ",o," ",n):(0,e.createElement)(e.Fragment,null,o," ",t.label),(0,e.createElement)("p",{className:a.join(" ")},l)},h=(0,d.compose)((0,r.withSelect)((e=>({postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,urlSlug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks(),optimalKeywordDensity:2,optimalWordNumber:300,optimalHeadingNumber:1,optimalImageNumber:1,postType:e("core/editor").getCurrentPostType()}))))((t=>{const a=window.diagnoseo.checks,l=a.filter((e=>e.section===t.sectionName)),o={postTitle:t.postTitle,postContent:t.postContent,keyword:t.keyword,metaTitle:seoHelper.replaceVariables(t.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),metaDescription:seoHelper.replaceVariables(t.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),slug:t.urlSlug,blocks:t.blocks,featuredImage:t.featuredImage,optimalKeywordDensity:t.optimalKeywordDensity,optimalWordNumber:t.optimalWordNumber,optimalHeadingNumber:t.optimalHeadingNumber,optimalImageNumber:t.optimalImageNumber},n=l.map((l=>{let n=!0;if(l.postTypes&&(n=l.postTypes.includes(t.postType)),!l.hidden&&n)switch(l.type){case"check":return l.inPro?(0,e.createElement)(m,{id:l.id,label:l.label,inPro:l.inPro}):(0,e.createElement)(m,{id:l.id,label:l.label,test:l.test,postData:o,checkConfig:a,valueFieldName:l.valueFieldName});case"stats":return l.inPro?(0,e.createElement)(g,{id:l.id,label:l.label,inPro:l.inPro}):(0,e.createElement)(g,{id:l.id,label:l.label,test:l.test,order:l.order,postData:o})}}));return(0,e.createElement)(e.Fragment,null,n.map(((t,a)=>(0,e.createElement)(React.Fragment,{key:a},t))))}));class p extends React.Component{constructor(e){super(e),this.state={keyword:"",keywordList:[],keywordLimit:window.diagnoseoPro?window.diagnoseoPro.additionalKeywordLimit:window.diagnoseo.additionalKeywordLimit,apiKey:"",language:diagnoseo_settings?diagnoseo_settings.locale.substr(0,2):"",loading:!1},this.handleChange=this.handleChange.bind(this),this.handleLangChange=this.handleLangChange.bind(this),this.handleLoadButtonClick=this.handleLoadButtonClick.bind(this),this.relatedKeywordsApiUrl="diagnoseo/v1/related-keywords"}stripKeywordData(e){return(e=-1===e.indexOf("|")?e:e.substr(0,e.indexOf(" |"))).trim()}async loadRelatedKeywords(){const e=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,t=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;if(!e)return void alert((0,s.__)('Please enter the "focus keyword" first',"diagnoseo"));if(!this.state.language)return void alert((0,s.__)("Please select language.","diagnoseo"));this.setState({loading:!0});let a=await this.getRelatedKeywords(e,t);if(a.length){let e=this.state.keywordList;a.forEach((t=>{t={name:t.trim()};let a=e.findIndex((e=>e.name===t));-1===a?e.push(t):(e[a].repeat_min=t.repeat_min,e[a].repeat_max=t.repeat_max)})),this.saveKeywords(e)}this.setState({loading:!1})}saveKeywords(e){const t=[...new Set(e)];t.splice(this.state.keywordLimit),this.setState({keywordList:t}),window.onbeforeunload=null,(0,r.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_additional_keywords:JSON.stringify(t)}})}saveLanguage(e){(0,r.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_language:e}})}componentDidMount(){let e=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_additional_keywords,t=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;try{e=JSON.parse(e)}catch{e=""}this.setState({language:t,keyword:this.props.focusKeyword,keywordList:e||[]})}async handleLoadButtonClick(){window.diagnoseoPro?this.loadRelatedKeywords():alert((0,s.__)("Related keywords and Pro data require DiagnoSEO Pro.","diagnoseo"))}handleChange(e){const t=this.state.keywordList,{stripKeywordData:a}=this;let l=e.map((e=>{let l=a(e.value||e),o=t.findIndex((e=>l===e.name));return{name:l,repeat_min:-1!==o?t[o].repeat_min:0,repeat_max:-1!==o?t[o].repeat_max:0}}));this.saveKeywords(l)}handleLangChange(e){this.setState({language:e}),this.saveLanguage(e)}render(){let{postTitle:t,postContent:a,featuredMedia:l}=this.props;const{countOccurences:o}=seoHelper;let n=0,r=this.state.keywordList.map((e=>{let i=e.name||"",r="error",s=function(e){a=seoHelper.stripTags(a);let n=0;return n+=o(e,t),n+=o(e,a),n+=seoHelper.isKeywordInAnyAlt(e,a),n+=l?o(e,l.alt_text):0,n}(i);s&&(r=e.repeat_min&&e.repeat_max?s>=e.repeat_min&&s<=e.repeat_max?"success":"validating":"success",n++);let d=` | ${s}`;return e.repeat_min&&e.repeat_max&&(d+=` (${e.repeat_min} - ${e.repeat_max})`),{value:i+d,status:r}})),d=!1;window.diagnoseo.RelatedKeywordsInPost!==n&&(window.diagnoseo.RelatedKeywordsInPost=n,d=!0),window.diagnoseo.additionalKeywordCount!==r.length&&(window.diagnoseo.additionalKeywordCount=r.length,d=!0),d&&window.dispatchEvent(new Event("check-changed"));let c=this.state.loading?(0,s.__)("Please wait... Loading related keywords. It can take up to a few minutes.","diagnoseo"):(0,e.createElement)("button",{className:"button get-related-keywords",onClick:this.handleLoadButtonClick},(0,s.__)("Get related keywords","diagnoseo"));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"components-base-control__field add-keyword diagnoseo-related-keywords"},(0,e.createElement)(i.FormTokenField,{label:(0,e.createElement)("b",null,(0,s.__)("Related keywords","diagnoseo")),onChange:this.handleChange,value:r,maxLength:this.state.keywordLimit+10}),(0,e.createElement)("p",{className:"components-form-token-field__help"},(0,s.__)("Limits: 10 keywords in free, 100 keywords in Pro","diagnoseo")),(0,e.createElement)(i.SelectControl,{options:[{value:"",label:"Choose language"},{value:"albanian",label:"Albanian"},{value:"arabic",label:"Arabic"},{value:"armenian",label:"Armenian"},{value:"awadhi",label:"Awadhi"},{value:"azerbaijani",label:"Azerbaijani"},{value:"bashkir",label:"Bashkir"},{value:"basque",label:"Basque"},{value:"belarusian",label:"Belarusian"},{value:"bengali",label:"Bengali"},{value:"bhojpuri",label:"Bhojpuri"},{value:"bosnian",label:"Bosnian"},{value:"brazilian Portuguese",label:"Brazilian Portuguese"},{value:"bulgarian",label:"Bulgarian"},{value:"cantonese (Yue)",label:"Cantonese (Yue)"},{value:"catalan",label:"Catalan"},{value:"chhattisgarhi",label:"Chhattisgarhi"},{value:"chinese",label:"Chinese"},{value:"croatian",label:"Croatian"},{value:"czech",label:"Czech"},{value:"danish",label:"Danish"},{value:"dogri",label:"Dogri"},{value:"dutch",label:"Dutch"},{value:"english",label:"English"},{value:"estonian",label:"Estonian"},{value:"faroese",label:"Faroese"},{value:"finnish",label:"Finnish"},{value:"french",label:"French"},{value:"galician",label:"Galician"},{value:"georgian",label:"Georgian"},{value:"german",label:"German"},{value:"greek",label:"Greek"},{value:"gujarati",label:"Gujarati"},{value:"haryanvi",label:"Haryanvi"},{value:"hindi",label:"Hindi"},{value:"hungarian",label:"Hungarian"},{value:"indonesian",label:"Indonesian"},{value:"irish",label:"Irish"},{value:"italian",label:"Italian"},{value:"japanese",label:"Japanese"},{value:"javanese",label:"Javanese"},{value:"kannada",label:"Kannada"},{value:"kashmiri",label:"Kashmiri"},{value:"kazakh",label:"Kazakh"},{value:"konkani",label:"Konkani"},{value:"korean",label:"Korean"},{value:"kyrgyz",label:"Kyrgyz"},{value:"latvian",label:"Latvian"},{value:"lithuanian",label:"Lithuanian"},{value:"macedonian",label:"Macedonian"},{value:"maithili",label:"Maithili"},{value:"malay",label:"Malay"},{value:"maltese",label:"Maltese"},{value:"mandarin",label:"Mandarin"},{value:"mandarin Chinese",label:"Mandarin Chinese"},{value:"marathi",label:"Marathi"},{value:"marwari",label:"Marwari"},{value:"min Nan",label:"Min Nan"},{value:"moldovan",label:"Moldovan"},{value:"mongolian",label:"Mongolian"},{value:"montenegrin",label:"Montenegrin"},{value:"nepali",label:"Nepali"},{value:"norwegian",label:"Norwegian"},{value:"oriya",label:"Oriya"},{value:"pashto",label:"Pashto"},{value:"persian",label:"Persian"},{value:"polish",label:"Polish"},{value:"portuguese",label:"Portuguese"},{value:"punjabi",label:"Punjabi"},{value:"rajasthani",label:"Rajasthani"},{value:"romanian",label:"Romanian"},{value:"russian",label:"Russian"},{value:"sanskrit",label:"Sanskrit"},{value:"santali",label:"Santali"},{value:"serbian",label:"Serbian"},{value:"sindhi",label:"Sindhi"},{value:"sinhala",label:"Sinhala"},{value:"slovak",label:"Slovak"},{value:"slovene",label:"Slovene"},{value:"slovenian",label:"Slovenian"},{value:"spanish",label:"Spanish"},{value:"swahili",label:"Swahili"},{value:"swedish",label:"Swedish"},{value:"tajik",label:"Tajik"},{value:"tamil",label:"Tamil"},{value:"tatar",label:"Tatar"},{value:"telugu",label:"Telugu"},{value:"thai",label:"Thai"},{value:"turkish",label:"Turkish"},{value:"turkmen",label:"Turkmen"},{value:"ukrainian",label:"Ukrainian"},{value:"urdu",label:"Urdu"},{value:"uzbek",label:"Uzbek"},{value:"vietnamese",label:"Vietnamese"},{value:"welsh",label:"Welsh"},{value:"wu",label:"Wu"}],value:this.state.language,onChange:this.handleLangChange,label:(0,s.__)("Language","diagnoseo")}),(0,e.createElement)("p",null,c)))}getRelatedKeywords(e,t){return new Promise((a=>{const l=new FormData;l.append("keyword",e),l.append("language",t),l.append("count",30),fetch("/wp-json/diagnoseo/v1/related-keywords",{method:"POST",body:l}).then((e=>e.json())).then((e=>{"ok"===e.status?a(e.keywords.split(",")):a([])})).catch((e=>{console.error(e),a([])}))}))}}var b=(0,d.compose)((0,r.withSelect)((e=>{const t=e("core/editor").getEditedPostAttribute("featured_media");return{postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredMedia:e("core").getMedia(t,{context:"embed"})||{}}})))((t=>(0,e.createElement)(p,{postTitle:t.postTitle,postContent:t.postContent,featuredMedia:t.featuredMedia,seoDataCollector:t.seoDataCollector}))),w=(0,d.compose)((0,r.withSelect)((e=>{if(!window.diagnoseoPro)return{};const t={categories:e("core/editor").getEditedPostAttribute("categories"),status:"publish",per_page:10,exclude:[e("core/editor").getEditedPostAttribute("id")]};return{suggestedPosts:wp.data.select("core").getEntityRecords("postType","post",t)||[]}})))((t=>{if(window.diagnoseoPro){var a="";return t.suggestedPosts.length?(a=t.suggestedPosts.map((t=>(0,e.createElement)("li",null,(0,e.createElement)("a",{href:t.link},t.title.raw)))),a=(0,e.createElement)("ol",null,a)):a=(0,e.createElement)("p",null,(0,s.__)("Could not prepare suggestions as there are no posts related to this one")),a}return(0,e.createElement)("p",null,(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))))})),v=(0,d.compose)((0,r.withDispatch)((e=>({setMetaValues:t=>{e("core/editor").editPost({meta:{}})}}))))((t=>{let a=window.diagnoseoPro?"DiagnoSEO Pro":"DiagnoSEO";return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(n.PluginSidebarMoreMenuItem,{target:"diagnoseo-content-analyzer"},(0,s.__)("DiagnoSEO Content Watcher","diagnoseo")),(0,e.createElement)(n.PluginSidebar,{title:a,name:"diagnoseo-content-analyzer"},(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Content analyzer","diagnoseo"),initialOpen:"true"},(0,e.createElement)(h,{sectionName:"content"})),(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Keyword placement","diagnoseo"),initialOpen:"true"},(0,e.createElement)(c,{fieldName:"diagnoseo_meta_keyword",label:(0,e.createElement)("b",null,(0,s.__)("Focus keyword","diagnoseo"))}),(0,e.createElement)(u,null),(0,e.createElement)(b,{seoDataCollector:t.setMetaValues}),(0,e.createElement)(h,{sectionName:"keyword"})),(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Internal linking suggestions","diagnoseo"),initialOpen:"true"},(0,e.createElement)(w,null))))}));(0,t.registerPlugin)("diagnoseo-sidebar",{icon:(0,e.createElement)(o,null),render:v})}();1 (()=>{"use strict";const e=window.wp.element,t=window.wp.plugins,a=function(){return(0,e.createElement)("svg",{"enable-background":"new 0 0 20 20",height:"20",width:"20",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",className:"diagnoseo-icon"},(0,e.createElement)("clipPath",{id:"a"},(0,e.createElement)("path",{d:"m0 0h20v20h-20z"})),(0,e.createElement)("path",{className:"diagnoseo-icon-part-tick",d:"m12.377 5.866 1.835 1.612-4.839 5.508-4.11-3.576 1.672-1.902 2.256 1.982z"}),(0,e.createElement)("path",{className:"diagnoseo-icon-part-magnifier","clip-path":"url(#a)",d:"m16.298 15.209c1.745-1.983 2.548-4.603 2.208-7.228-.315-2.426-1.555-4.584-3.493-6.077s-4.341-2.139-6.768-1.828c-2.426.315-4.584 1.555-6.077 3.493s-2.142 4.341-1.827 6.767c.649 5.007 5.251 8.554 10.259 7.905 1.441-.188 2.824-.717 4.014-1.536l3.749 3.295 1.476-1.68zm-1.471-1.887c-1.111 1.443-2.72 2.368-4.527 2.602-1.808.235-3.598-.247-5.041-1.361-1.444-1.111-2.368-2.719-2.602-4.527-.483-3.73 2.158-7.158 5.889-7.642.296-.038.59-.057.881-.057 3.375 0 6.316 2.511 6.761 5.946.235 1.806-.249 3.596-1.361 5.039"}))};class l extends React.Component{constructor(e){super(e),this.state={score:0,timeout:null},this.handleCheckChanged=this.handleCheckChanged.bind(this),this.calculateScore=this.calculateScore.bind(this),this.runAllChecks=this.runAllChecks.bind(this)}calculateScore(){const e=window.diagnoseo.checks.filter(e=>"check"===e.type);let t=e.length+1,a=e.filter(e=>e.checked),l=window.diagnoseo.additionalKeywordCount===window.diagnoseo.RelatedKeywordsInPost?a.length+1:a.length,o=Math.round(100*l/t);this.setState({score:o})}runAllChecks(){const{select:e}=window.wp.data,t=window.diagnoseo.checks.filter(e=>"check"===e.type),a={postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,featuredImageId:e("core/editor").getEditedPostAttribute("featured_media"),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,slug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks()};if(!a.featuredImageId||a.featuredImage)a.metaTitle=seoHelper.replaceVariables(a.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),a.metaDescription=seoHelper.replaceVariables(a.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),t.forEach((e,t)=>{if(!e.test)return;let l="ok"===e.test(a),o=window.diagnoseo.checks.findIndex(t=>t.id===e.id);window.diagnoseo.checks[o].checked=l}),this.calculateScore();else var l=setInterval(()=>{e("core").getMedia(a.featuredImageId)&&(clearInterval(l),this.runAllChecks())},500)}handleCheckChanged(){clearTimeout(this.state.timeout),this.setState({timeout:setTimeout(this.calculateScore,300)})}async componentDidMount(){window.addEventListener("check-changed",this.handleCheckChanged),setTimeout(this.runAllChecks,1e3)}componentWillUnmount(){window.removeEventListener("check-changed",this.handleCheckChanged)}render(){let t,l=this.state.score;switch(!0){case l<60:t="score-low";break;case l>=60&&l<80:t="score-medium";break;case l>=80:t="score-high"}let o=`diagnoseo-button-content ${t}`;return(0,e.createElement)("span",{className:o},(0,e.createElement)(a,null),(0,e.createElement)("b",{className:"diagnoseo-score"},this.state.score,"/100"))}whenEditorIsReady(){return new Promise(e=>{const t=subscribe(()=>{(select("core/editor").isCleanNewPost()||select("core/block-editor").getBlockCount()>0)&&(t(),e())})})}}const o=l,n=window.wp.editor,i=window.wp.components,r=window.wp.data,s=window.wp.i18n,d=window.wp.compose,c=(0,d.compose)((0,r.withDispatch)((e,t)=>({setMetaValue:a=>{var l={};l[t.fieldName]=a,e("core/editor").editPost({meta:l}),t.changeCallback&&t.changeCallback(a)}})),(0,r.withSelect)((e,t)=>({metaValue:e("core/editor").getEditedPostAttribute("meta")[t.fieldName]})))(t=>(0,e.createElement)(i.TextControl,{label:t.label,value:t.metaValue,onChange:e=>t.setMetaValue(e)})),u=(0,d.compose)((0,r.withSelect)(e=>({content:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword})))(t=>{var a=0;if(t.keyword){var l=t.content.replace(/<\!--.*?-->/g,""),o=(l=(l=l.replace(/(\r\n|\n|\r)/gm," ")).toLowerCase()).split(" ");o=o.filter(e=>""!==e);var n=seoHelper.countOccurences(t.keyword,l);n&&(a=n/o.length*100,a=parseFloat(a.toFixed(2)))}let i;if(window.diagnoseoPro){let t="diagnoseo-check optimal-keyword-density";t+=a>=1&&a<=3?" ok":" nok",i=(0,e.createElement)("p",{className:t},(0,s.__)("Optimal keyword density","diagnoseo")," ",(0,e.createElement)("b",{className:"value"},"1% - 3%"))}else i=(0,e.createElement)("p",{className:"diagnoseo-check optimal-keyword-density"},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",(0,s.__)("Optimal keyword density","diagnoseo"));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("p",{className:"diagnoseo-stats keyword-density"},(0,s.__)("Keyword density","diagnoseo")," ",(0,e.createElement)("b",{className:"value"},a,"%")),i)}),m=t=>{let a=["diagnoseo-check",t.id];if(t.test){let e=t.test(t.postData);"string"==typeof e&&a.push(e);let l="ok"===e,o=t.checkConfig.findIndex(e=>e.id===t.id);t.checkConfig[o].checked!==l&&window.dispatchEvent(new Event("check-changed")),t.checkConfig[o].checked=l}if(t.inPro)return(0,e.createElement)("p",{className:a.join(" ")},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))));const l=t.valueFieldName&&t.postData[t.valueFieldName]?(0,e.createElement)("b",null,t.postData[t.valueFieldName]):"";return(0,e.createElement)("p",{className:a.join(" ")},t.label," ",l)},g=t=>{let a=["diagnoseo-stats",t.id];if(t.inPro)return(0,e.createElement)("p",{className:a.join(" ")},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))));let l,o=(0,e.createElement)("b",{className:"value"}),n="";if(t.test){let l=t.test(t.postData);o=(0,e.createElement)("b",{className:"value"},l.value),n=l.comment?(0,e.createElement)("span",{className:"comment"},l.comment):"",l.status&&a.push(l.status)}return l=t.order&&"value label"!==t.order?(0,e.createElement)(e.Fragment,null,t.label," ",o," ",n):(0,e.createElement)(e.Fragment,null,o," ",t.label),(0,e.createElement)("p",{className:a.join(" ")},l)},h=(0,d.compose)((0,r.withSelect)(e=>({postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,urlSlug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks(),optimalKeywordDensity:2,optimalWordNumber:300,optimalHeadingNumber:1,optimalImageNumber:1,postType:e("core/editor").getCurrentPostType()})))(t=>{const a=window.diagnoseo.checks,l=a.filter(e=>e.section===t.sectionName),o={postTitle:t.postTitle,postContent:t.postContent,keyword:t.keyword,metaTitle:seoHelper.replaceVariables(t.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),metaDescription:seoHelper.replaceVariables(t.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),slug:t.urlSlug,blocks:t.blocks,featuredImage:t.featuredImage,optimalKeywordDensity:t.optimalKeywordDensity,optimalWordNumber:t.optimalWordNumber,optimalHeadingNumber:t.optimalHeadingNumber,optimalImageNumber:t.optimalImageNumber},n=l.map(l=>{let n=!0;if(l.postTypes&&(n=l.postTypes.includes(t.postType)),!l.hidden&&n)switch(l.type){case"check":return l.inPro?(0,e.createElement)(m,{id:l.id,label:l.label,inPro:l.inPro}):(0,e.createElement)(m,{id:l.id,label:l.label,test:l.test,postData:o,checkConfig:a,valueFieldName:l.valueFieldName});case"stats":return l.inPro?(0,e.createElement)(g,{id:l.id,label:l.label,inPro:l.inPro}):(0,e.createElement)(g,{id:l.id,label:l.label,test:l.test,order:l.order,postData:o})}});return(0,e.createElement)(e.Fragment,null,n.map((t,a)=>(0,e.createElement)(React.Fragment,{key:a},t)))});class p extends React.Component{constructor(e){super(e),this.state={keyword:"",keywordList:[],keywordLimit:window.diagnoseoPro?window.diagnoseoPro.additionalKeywordLimit:window.diagnoseo.additionalKeywordLimit,apiKey:"",language:diagnoseo_settings?diagnoseo_settings.locale.substr(0,2):"",loading:!1},this.handleChange=this.handleChange.bind(this),this.handleLangChange=this.handleLangChange.bind(this),this.handleLoadButtonClick=this.handleLoadButtonClick.bind(this),this.relatedKeywordsApiUrl="diagnoseo/v1/related-keywords"}stripKeywordData(e){return(e=-1===e.indexOf("|")?e:e.substr(0,e.indexOf(" |"))).trim()}async loadRelatedKeywords(){const e=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,t=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;if(!e)return void alert((0,s.__)('Please enter the "focus keyword" first',"diagnoseo"));if(!this.state.language)return void alert((0,s.__)("Please select language.","diagnoseo"));this.setState({loading:!0});let a=await this.getRelatedKeywords(e,t);if(a.length){let e=this.state.keywordList;a.forEach(t=>{t={name:t.trim()};let a=e.findIndex(e=>e.name===t);-1===a?e.push(t):(e[a].repeat_min=t.repeat_min,e[a].repeat_max=t.repeat_max)}),this.saveKeywords(e)}this.setState({loading:!1})}saveKeywords(e){const t=[...new Set(e)];t.splice(this.state.keywordLimit),this.setState({keywordList:t}),window.onbeforeunload=null,(0,r.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_additional_keywords:JSON.stringify(t)}})}saveLanguage(e){(0,r.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_language:e}})}componentDidMount(){let e=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_additional_keywords,t=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;try{e=JSON.parse(e)}catch{e=""}this.setState({language:t,keyword:this.props.focusKeyword,keywordList:e||[]})}async handleLoadButtonClick(){window.diagnoseoPro?this.loadRelatedKeywords():alert((0,s.__)("Related keywords and Pro data require DiagnoSEO Pro.","diagnoseo"))}handleChange(e){const t=this.state.keywordList,{stripKeywordData:a}=this;let l=e.map(e=>{let l=a(e.value||e),o=t.findIndex(e=>l===e.name);return{name:l,repeat_min:-1!==o?t[o].repeat_min:0,repeat_max:-1!==o?t[o].repeat_max:0}});this.saveKeywords(l)}handleLangChange(e){this.setState({language:e}),this.saveLanguage(e)}render(){let{postTitle:t,postContent:a,featuredMedia:l}=this.props;const{countOccurences:o}=seoHelper;let n=0,r=this.state.keywordList.map(e=>{let i=e.name||"",r="error",s=function(e){a=seoHelper.stripTags(a);let n=0;return n+=o(e,t),n+=o(e,a),n+=seoHelper.isKeywordInAnyAlt(e,a),n+=l?o(e,l.alt_text):0,n}(i);s&&(r=e.repeat_min&&e.repeat_max?s>=e.repeat_min&&s<=e.repeat_max?"success":"validating":"success",n++);let d=` | ${s}`;return e.repeat_min&&e.repeat_max&&(d+=` (${e.repeat_min} - ${e.repeat_max})`),{value:i+d,status:r}}),d=!1;window.diagnoseo.RelatedKeywordsInPost!==n&&(window.diagnoseo.RelatedKeywordsInPost=n,d=!0),window.diagnoseo.additionalKeywordCount!==r.length&&(window.diagnoseo.additionalKeywordCount=r.length,d=!0),d&&window.dispatchEvent(new Event("check-changed"));let c=this.state.loading?(0,s.__)("Please wait... Loading related keywords. It can take up to a few minutes.","diagnoseo"):(0,e.createElement)("button",{className:"button get-related-keywords",onClick:this.handleLoadButtonClick},(0,s.__)("Get related keywords","diagnoseo"));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"components-base-control__field add-keyword diagnoseo-related-keywords"},(0,e.createElement)(i.FormTokenField,{label:(0,e.createElement)("b",null,(0,s.__)("Related keywords","diagnoseo")),onChange:this.handleChange,value:r,maxLength:this.state.keywordLimit+10}),(0,e.createElement)("p",{className:"components-form-token-field__help"},(0,s.__)("Limits: 10 keywords in free, 100 keywords in Pro","diagnoseo")),(0,e.createElement)(i.SelectControl,{options:[{value:"",label:"Choose language"},{value:"albanian",label:"Albanian"},{value:"arabic",label:"Arabic"},{value:"armenian",label:"Armenian"},{value:"awadhi",label:"Awadhi"},{value:"azerbaijani",label:"Azerbaijani"},{value:"bashkir",label:"Bashkir"},{value:"basque",label:"Basque"},{value:"belarusian",label:"Belarusian"},{value:"bengali",label:"Bengali"},{value:"bhojpuri",label:"Bhojpuri"},{value:"bosnian",label:"Bosnian"},{value:"brazilian Portuguese",label:"Brazilian Portuguese"},{value:"bulgarian",label:"Bulgarian"},{value:"cantonese (Yue)",label:"Cantonese (Yue)"},{value:"catalan",label:"Catalan"},{value:"chhattisgarhi",label:"Chhattisgarhi"},{value:"chinese",label:"Chinese"},{value:"croatian",label:"Croatian"},{value:"czech",label:"Czech"},{value:"danish",label:"Danish"},{value:"dogri",label:"Dogri"},{value:"dutch",label:"Dutch"},{value:"english",label:"English"},{value:"estonian",label:"Estonian"},{value:"faroese",label:"Faroese"},{value:"finnish",label:"Finnish"},{value:"french",label:"French"},{value:"galician",label:"Galician"},{value:"georgian",label:"Georgian"},{value:"german",label:"German"},{value:"greek",label:"Greek"},{value:"gujarati",label:"Gujarati"},{value:"haryanvi",label:"Haryanvi"},{value:"hindi",label:"Hindi"},{value:"hungarian",label:"Hungarian"},{value:"indonesian",label:"Indonesian"},{value:"irish",label:"Irish"},{value:"italian",label:"Italian"},{value:"japanese",label:"Japanese"},{value:"javanese",label:"Javanese"},{value:"kannada",label:"Kannada"},{value:"kashmiri",label:"Kashmiri"},{value:"kazakh",label:"Kazakh"},{value:"konkani",label:"Konkani"},{value:"korean",label:"Korean"},{value:"kyrgyz",label:"Kyrgyz"},{value:"latvian",label:"Latvian"},{value:"lithuanian",label:"Lithuanian"},{value:"macedonian",label:"Macedonian"},{value:"maithili",label:"Maithili"},{value:"malay",label:"Malay"},{value:"maltese",label:"Maltese"},{value:"mandarin",label:"Mandarin"},{value:"mandarin Chinese",label:"Mandarin Chinese"},{value:"marathi",label:"Marathi"},{value:"marwari",label:"Marwari"},{value:"min Nan",label:"Min Nan"},{value:"moldovan",label:"Moldovan"},{value:"mongolian",label:"Mongolian"},{value:"montenegrin",label:"Montenegrin"},{value:"nepali",label:"Nepali"},{value:"norwegian",label:"Norwegian"},{value:"oriya",label:"Oriya"},{value:"pashto",label:"Pashto"},{value:"persian",label:"Persian"},{value:"polish",label:"Polish"},{value:"portuguese",label:"Portuguese"},{value:"punjabi",label:"Punjabi"},{value:"rajasthani",label:"Rajasthani"},{value:"romanian",label:"Romanian"},{value:"russian",label:"Russian"},{value:"sanskrit",label:"Sanskrit"},{value:"santali",label:"Santali"},{value:"serbian",label:"Serbian"},{value:"sindhi",label:"Sindhi"},{value:"sinhala",label:"Sinhala"},{value:"slovak",label:"Slovak"},{value:"slovene",label:"Slovene"},{value:"slovenian",label:"Slovenian"},{value:"spanish",label:"Spanish"},{value:"swahili",label:"Swahili"},{value:"swedish",label:"Swedish"},{value:"tajik",label:"Tajik"},{value:"tamil",label:"Tamil"},{value:"tatar",label:"Tatar"},{value:"telugu",label:"Telugu"},{value:"thai",label:"Thai"},{value:"turkish",label:"Turkish"},{value:"turkmen",label:"Turkmen"},{value:"ukrainian",label:"Ukrainian"},{value:"urdu",label:"Urdu"},{value:"uzbek",label:"Uzbek"},{value:"vietnamese",label:"Vietnamese"},{value:"welsh",label:"Welsh"},{value:"wu",label:"Wu"}],value:this.state.language,onChange:this.handleLangChange,label:(0,s.__)("Language","diagnoseo")}),(0,e.createElement)("p",null,c)))}getRelatedKeywords(e,t){return new Promise(a=>{const l=new FormData;l.append("keyword",e),l.append("language",t),l.append("count",30),fetch("/wp-json/diagnoseo/v1/related-keywords",{method:"POST",body:l}).then(e=>e.json()).then(e=>{"ok"===e.status?a(e.keywords.split(",")):a([])}).catch(e=>{console.error(e),a([])})})}}const b=(0,d.compose)((0,r.withSelect)(e=>{const t=e("core/editor").getEditedPostAttribute("featured_media");return{postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredMedia:e("core").getMedia(t,{context:"embed"})||{}}}))(t=>(0,e.createElement)(p,{postTitle:t.postTitle,postContent:t.postContent,featuredMedia:t.featuredMedia,seoDataCollector:t.seoDataCollector})),w=(0,d.compose)((0,r.withSelect)(e=>{if(!window.diagnoseoPro)return{};const t={categories:e("core/editor").getEditedPostAttribute("categories"),status:"publish",per_page:10,exclude:[e("core/editor").getEditedPostAttribute("id")]};return{suggestedPosts:wp.data.select("core").getEntityRecords("postType","post",t)||[]}}))(t=>{if(window.diagnoseoPro){var a="";return t.suggestedPosts.length?(a=t.suggestedPosts.map(t=>(0,e.createElement)("li",null,(0,e.createElement)("a",{href:t.link},t.title.raw))),a=(0,e.createElement)("ol",null,a)):a=(0,e.createElement)("p",null,(0,s.__)("Could not prepare suggestions as there are no posts related to this one")),a}return(0,e.createElement)("p",null,(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))))}),v=(0,d.compose)((0,r.withDispatch)(e=>({setMetaValues:t=>{e("core/editor").editPost({meta:{}})}})))(t=>{let a=window.diagnoseoPro?"DiagnoSEO Pro":"DiagnoSEO";return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(n.PluginSidebarMoreMenuItem,{target:"diagnoseo-content-analyzer"},(0,s.__)("DiagnoSEO Content Watcher","diagnoseo")),(0,e.createElement)(n.PluginSidebar,{title:a,name:"diagnoseo-content-analyzer"},(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Content analyzer","diagnoseo"),initialOpen:"true"},(0,e.createElement)(h,{sectionName:"content"})),(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Keyword placement","diagnoseo"),initialOpen:"true"},(0,e.createElement)(c,{fieldName:"diagnoseo_meta_keyword",label:(0,e.createElement)("b",null,(0,s.__)("Focus keyword","diagnoseo"))}),(0,e.createElement)(u,null),(0,e.createElement)(b,{seoDataCollector:t.setMetaValues}),(0,e.createElement)(h,{sectionName:"keyword"})),(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Internal linking suggestions","diagnoseo"),initialOpen:"true"},(0,e.createElement)(w,null))))});(0,t.registerPlugin)("diagnoseo-sidebar",{icon:(0,e.createElement)(o,null),render:v})})(); -
diagnoseo/tags/1.2.56/js/diagnoseo-editor.min.js
r3290407 r3423066 1 const{__}=window.wp.i18n;window.diagnoseo={additionalKeywordLimit:10,additionalKeywordCount:0,RelatedKeywordsInPost:0,checks:[{id:"title-not-too-long",type:"check",label:__("Title not too long"),section:"content",test:e=>{var{metaTitle:t,postTitle:e}=e;if(!t&&!e)return"nok";t=t||e;const a=document.querySelector(".title-sample");a.textContent=t;e=a.clientWidth,t=t.length;return e<=600?60<t?"nok medium-nok":t<=60?"ok":"nok":"nok"}},{id:"title-not-too-short",type:"check",label:__("Title not too short"),section:"content",test:e=>{var{metaTitle:t,postTitle:e}=e;if(!t&&!e)return"nok";e=(t||e).length;return 30<=e?30<=e&&e<35?"nok medium-nok":35<=e?"ok":"nok":"nok"}},{id:"description-not-too-long",type:"check",label:__("Description not too long"),section:"content",test:e=>{var{metaDescription:t}=e;if(!t)return"nok";e=document.querySelector(".description-sample"),t=t.length;if(e.clientWidth<=990){if(155<t)return"nok medium-nok";if(t<=155)return"ok"}return"nok"}},{id:"description-not-too-short",type:"check",label:__("Description not too short"),section:"content",test:e=>{var{metaDescription:e}=e;if(!e)return"nok";e=e.length;if(70<=e){if(e<130)return"nok medium-nok";if(130<=e)return"ok"}return"nok"}},{id:"too-long-sentences",type:"check",label:__("No sentences with more than 20 words"),section:"content",test:e=>{var{postContent:e}=e;e=(e=(e=(e=(e=(e=(e=(e=e.replaceAll("</p>",".</p>")).replaceAll("</h1>",".</h1>")).replaceAll("</h2>",".</h2>")).replaceAll("</h3>",".</h3>")).replaceAll("</h4>",".</h4>")).replaceAll("</h5>",".</h5>")).replaceAll("</h6>",".</h6>")).replaceAll("</li>",".</li>");const t=(e=seoHelper.stripTags(e)).split(/\.|\?|!/);var a=!1;return t.length&&t.forEach(e=>{a=a||20<seoHelper.countWords(e)}),a?"nok":"ok"}},{id:"too-many-words",type:"check",label:__("No paragraphs with more than 100 words"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("p");var o=!1;return a.length&&a.forEach(e=>{100<seoHelper.countWords(e.textContent)&&(o=!0)}),o?"nok":"ok"}},{id:"too-many-sentences",type:"check",label:__("No paragraphs with more than 5 sentences"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("p");var o=!1;return a.length&&a.forEach(e=>{5<e.textContent.split(/\.|\?|!/).filter(e=>!!e.trim()).length&&(o=!0)}),o?"nok":"ok"}},{id:"internal-links-present",type:"check",label:__("Contains internal links"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("a");var o=!1;return a.forEach(e=>{e=e.getAttribute("href")||"";e&&(e.includes("http://"+window.location.hostname)||e.includes("https://"+window.location.hostname)||"/"===e.substr(0,1)||"./"===e.substr(0,2))&&(o=!0)}),o?"ok":"nok"}},{id:"strong-present",type:"check",label:__("Contains bold text (strong tag)"),section:"content",test:e=>seoHelper.countElements(e.postContent,"strong")?"ok":"nok"},{id:"readability",type:"stats",label:__("Readability score"),order:"label value comment",section:"content",test:e=>{var{postContent:t}=e,a=(t=seoHelper.stripTags(t)).split(/\.|\?|!/);a=(a=a.map(e=>e.trim())).filter(e=>e&&" "!==e&&"\n"!==e);e=(t=t.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g," ")).split(" ");e=(e=e.map(e=>e.trim())).filter(e=>e&&""!==e&&"\n"!==e);var t=seoHelper.countSyllables(t),o=206.835-e.length/a.length*1.015-t/e.length*84.6;(o=o.toFixed(2))<0?o=0:100<o&&(o=100);var n="",l="";switch(!0){case isNaN(o):o=__("N/A"),n="",l="nok";break;case 90<o:n=__("Very easy to read","diagnoseo"),l="ok";break;case 80<o&&o<=90:n=__("Easy to read","diagnoseo"),l="ok";break;case 70<o&&o<=80:n=__("Fairly easy to read","diagnoseo"),l="ok";break;case 60<o&&o<=70:n=__("Average reading ease","diagnoseo"),l="nok medium-nok";break;case 50<o&&o<=60:n=__("Fairly difficult to read","diagnoseo"),l="nok";break;case 30<o&&o<=50:n=__("Difficult to read","diagnoseo"),l="nok";break;case 10<o&&o<=30:n=__("Very difficult to read","diagnoseo"),l="nok";break;case o<=10:n=__("Extremely difficult to read","diagnoseo"),l="nok"}return{value:o,comment:n=n&&` (${n})`,status:l}}},{id:"est-reading-time",type:"stats",label:__("Estimated reading time"),section:"content",order:"label value",test:e=>{var{postContent:t}=e,e=seoHelper.countWords(t),t=Math.floor(e/225),e=Math.floor(e%225/3.75);return{value:`${t} ${__("min")} ${e} ${__("s")}`}}},{id:"minimal-word-count",type:"check",label:__("Minimal word count"),section:"content",postTypes:["post","page"],inPro:!0},{id:"words",type:"stats",label:__("words"),section:"content",test:e=>{var{postContent:e}=e;return{value:seoHelper.countWords(e)}}},{id:"chars",type:"stats",label:__("characters"),section:"content",test:e=>({value:e.postContent.length||0})},{id:"sentences",type:"stats",label:__("sentences"),section:"content",test:e=>{var{postContent:e}=e,e=(e=e.replace(/(\r\n|\n|\r)/gm," ")).split(/\.|\?|!/);return{value:(e=(e=e.map(e=>e.trim())).filter(e=>e&&" "!==e&&"\n"!==e)).length||0}}},{id:"paragraphs",type:"stats",label:__("paragraphs"),section:"content",test:e=>({value:seoHelper.countElements(e.postContent,"p")})},{id:"headings",type:"stats",label:__("Headings"),inPro:!0,section:"content"},{id:"optimal-heading-number",type:"check",label:__("Optimal number of headings"),inPro:!0,section:"content"},{id:"images",type:"stats",label:__("Images"),inPro:!0,section:"content"},{id:"optimal-image-number",type:"check",label:__("Optimal number of images"),inPro:!0,section:"content"},{id:"too-long-headings",type:"check",label:__("No too long headings"),inPro:!0,section:"content"},{id:"toc-block",type:"check",label:__("Use Table of Contents block"),inPro:!0,section:"content"},{id:"keyword-exists",type:"check",label:__("Keyword is provided"),section:"keyword",test:e=>e.keyword?"ok":"nok"},{id:"keyword-unique",type:"check",label:__("Focus Keyword not used before"),section:"keyword",test:async a=>{var o=document.querySelector(".keyword-unique");if(a.keyword){let e=new URLSearchParams(window.location.search);var n=Object.fromEntries(e.entries()),n=`${diagnoseoRestUrl}diagnoseo/v1/check-posts-keyword/${a.keyword}/${n.post||0}`;let t=0===await(await fetch(n)).json()?"ok":"nok";o?o&&(o.classList.remove("ok","nok"),o.classList.add(t)):setTimeout(()=>{(o=document.querySelector(".keyword-unique"))&&(o.classList.remove("ok","nok"),o.classList.add(t))},200)}else o&&o.classList.add("ok")}},{id:"keyword-in-title",type:"check",label:__("Keyword present in title tag"),section:"keyword",test:e=>{var{keyword:t,postTitle:a,metaTitle:e}=e;return seoHelper.isKeywordInText(t,e||a)?"ok":"nok"}},{id:"keyword-in-title-beginning",type:"check",label:__("Keyword in the beginning of the title tag"),section:"keyword",test:e=>{var{keyword:t,postTitle:a,metaTitle:e}=e;if(!t)return"nok";a=(a=e||a).toLowerCase(),t=t.toLowerCase();const o=new RegExp("^"+t);return o.test(a)?"ok":"nok"}},{id:"keyword-in-descr",type:"check",label:__("Keyword present in meta description tag"),section:"keyword",test:e=>{var{keyword:t,metaDescription:e}=e;return seoHelper.isKeywordInText(t,e)?"ok":"nok"}},{id:"keyword-in-slug",type:"check",label:__("Keyword present in URL slug"),section:"keyword",test:e=>{var{keyword:t,slug:a,postTitle:e}=e;return t&&(a=a||seoHelper.slugify(e)).includes(seoHelper.slugify(t))?"ok":"nok"}},{id:"slug-length-ok",type:"check",label:__("URL slug length"),section:"keyword",test:e=>{var{slug:t,postTitle:e}=e;if(!t&&!e)return"nok";if((t=t||seoHelper.slugify(e)).length<=60&&t.split("-").length<=5)return"ok";return"nok"}},{id:"keyword-in-h1",type:"check",label:__("Keyword present in H1 element"),section:"keyword",test:e=>{var{keyword:t,postContent:a,postTitle:e}=e;return seoHelper.isKeywordInText(t,e)||seoHelper.isKeywordInAnyElement(t,a,"h1")?"ok":"nok"}},{id:"keyword-in-image-alt",type:"check",label:__("Keyword present in any image alt attribute"),section:"keyword",test:e=>{var{keyword:t,postContent:a,featuredImage:e}=e;return seoHelper.isKeywordInAnyAlt(t,a,e)?"ok":"nok"}},{id:"keyword-in-image-filename",type:"check",label:__("Keyword in image file name"),section:"keyword",inPro:!0,hidden:!0},{id:"keyword-not-in-ext-link",type:"check",label:__("Keyword NOT present in external link text"),section:"keyword",test:e=>{const{keyword:a,postContent:t}=e;if(!a)return"ok";const o=seoHelper.createMarkupEl(t);var n=!1;const l=o.querySelectorAll("a");return l.forEach(e=>{const t=e.getAttribute("href")||"";t.includes("http://"+window.location.hostname)||t.includes("https://"+window.location.hostname)||"/"===t.substr(0,1)||"./"===t.substr(0,2)||!seoHelper.isKeywordInText(a,e.textContent)||(n=!0)}),n?"nok":"ok"}},{id:"keyword-in-first-words",type:"check",label:__("Keyword present within first 100 words"),section:"keyword",test:e=>{var{keyword:t,postContent:e}=e;if(!t)return"nok";var t=t.trim(),a=(e=seoHelper.stripTags(e)).toLowerCase().split(/\s|\n/),o=100<=(a=a.filter(e=>e)).length?100:a.length;if(a=a.splice(0,o),!seoHelper.isKeywordInText(t,a.join(" ")))return"nok";if(1<t.split(" ").length)return"ok";if(a.length)for(let e=0;e<o;e++)a[e]=a[e].replace(".",""),a[e]=a[e].replace(",",""),a[e]=a[e].replace("?",""),a[e]=a[e].replace("!",""),a[e]=a[e].replace(":",""),a[e]=a[e].replace(";","");return a.includes(t)?"ok":"nok"}},{id:"more",type:"check",label:__("Many more powerful SEO checkpoints"),inPro:!0,section:"content"},{id:"more",type:"check",label:__("Many more powerful SEO checkpoints"),inPro:!0,section:"keyword"}],checkResults:{}}, function(){"use strict";function o(){return(0,d.createElement)("svg",{"enable-background":"new 0 0 20 20",height:"20",width:"20",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",className:"diagnoseo-icon"},(0,d.createElement)("clipPath",{id:"a"},(0,d.createElement)("path",{d:"m0 0h20v20h-20z"})),(0,d.createElement)("path",{className:"diagnoseo-icon-part-tick",d:"m12.377 5.866 1.835 1.612-4.839 5.508-4.11-3.576 1.672-1.902 2.256 1.982z"}),(0,d.createElement)("path",{className:"diagnoseo-icon-part-magnifier","clip-path":"url(#a)",d:"m16.298 15.209c1.745-1.983 2.548-4.603 2.208-7.228-.315-2.426-1.555-4.584-3.493-6.077s-4.341-2.139-6.768-1.828c-2.426.315-4.584 1.555-6.077 3.493s-2.142 4.341-1.827 6.767c.649 5.007 5.251 8.554 10.259 7.905 1.441-.188 2.824-.717 4.014-1.536l3.749 3.295 1.476-1.68zm-1.471-1.887c-1.111 1.443-2.72 2.368-4.527 2.602-1.808.235-3.598-.247-5.041-1.361-1.444-1.111-2.368-2.719-2.602-4.527-.483-3.73 2.158-7.158 5.889-7.642.296-.038.59-.057.881-.057 3.375 0 6.316 2.511 6.761 5.946.235 1.806-.249 3.596-1.361 5.039"}))}var d=window.wp.element,e=window.wp.plugins;class t extends React.Component{constructor(e){super(e),this.state={score:0,timeout:null},this.handleCheckChanged=this.handleCheckChanged.bind(this),this.calculateScore=this.calculateScore.bind(this),this.runAllChecks=this.runAllChecks.bind(this)}calculateScore(){const e=window.diagnoseo.checks.filter(e=>"check"===e.type);var t=e.length+1,a=e.filter(e=>e.checked),a=window.diagnoseo.additionalKeywordCount===window.diagnoseo.RelatedKeywordsInPost?a.length+1:a.length,t=Math.round(100*a/t);this.setState({score:t})}runAllChecks(){const{select:e}=window.wp.data,t=window.diagnoseo.checks.filter(e=>"check"===e.type),n={postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,featuredImageId:e("core/editor").getEditedPostAttribute("featured_media"),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,slug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks()};var a;!n.featuredImageId||n.featuredImage?(n.metaTitle=seoHelper.replaceVariables(n.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),n.metaDescription=seoHelper.replaceVariables(n.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),t.forEach((t,e)=>{var a,o;t.test&&(a="ok"===t.test(n),o=window.diagnoseo.checks.findIndex(e=>e.id===t.id),window.diagnoseo.checks[o].checked=a)}),this.calculateScore()):a=setInterval(()=>{e("core").getMedia(n.featuredImageId)&&(clearInterval(a),this.runAllChecks())},500)}handleCheckChanged(){clearTimeout(this.state.timeout),this.setState({timeout:setTimeout(this.calculateScore,300)})}async componentDidMount(){window.addEventListener("check-changed",this.handleCheckChanged),setTimeout(this.runAllChecks,1e3)}componentWillUnmount(){window.removeEventListener("check-changed",this.handleCheckChanged)}render(){let e,t=this.state.score;switch(!0){case t<60:e="score-low";break;case 60<=t&&t<80:e="score-medium";break;case 80<=t:e="score-high"}var a=`diagnoseo-button-content ${e}`;return(0,d.createElement)("span",{className:a},(0,d.createElement)(o,null),(0,d.createElement)("b",{className:"diagnoseo-score"},this.state.score,"/100"))}whenEditorIsReady(){return new Promise(e=>{const t=subscribe(()=>{(select("core/editor").isCleanNewPost()||0<select("core/block-editor").getBlockCount())&&(t(),e())})})}}var a=t,n=window.wp.editor,u=window.wp.components,l=window.wp.data,p=window.wp.i18n,r=window.wp.compose,i=(0,r.compose)((0,l.withDispatch)((a,o)=>({setMetaValue:e=>{var t={};t[o.fieldName]=e,a("core/editor").editPost({meta:t}),o.changeCallback&&o.changeCallback(e)}})),(0,l.withSelect)((e,t)=>({metaValue:e("core/editor").getEditedPostAttribute("meta")[t.fieldName]})))(t=>(0,d.createElement)(u.TextControl,{label:t.label,value:t.metaValue,onChange:e=>t.setMetaValue(e)})),s=(0,r.compose)((0,l.withSelect)(e=>({content:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword})))(e=>{var t,a,o=0;e.keyword&&(a=(a=(t=(t=(t=e.content.replace(/<\!--.*?-->/g,"")).replace(/(\r\n|\n|\r)/gm," ")).toLowerCase()).split(" ")).filter(e=>""!==e),(t=seoHelper.countOccurences(e.keyword,t))&&(o=t/a.length*100,o=parseFloat(o.toFixed(2))));let n;return n=window.diagnoseoPro?(a="diagnoseo-check optimal-keyword-density",(0,d.createElement)("p",{className:a+=1<=o&&o<=3?" ok":" nok"},(0,p.__)("Optimal keyword density","diagnoseo")," ",(0,d.createElement)("b",{className:"value"},"1% - 3%"))):(0,d.createElement)("p",{className:"diagnoseo-check optimal-keyword-density"},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",(0,p.__)("Optimal keyword density","diagnoseo")),(0,d.createElement)(d.Fragment,null,(0,d.createElement)("p",{className:"diagnoseo-stats keyword-density"},(0,p.__)("Keyword density","diagnoseo")," ",(0,d.createElement)("b",{className:"value"},o,"%")),n)}),c=t=>{let e=["diagnoseo-check",t.id];var a;if(t.test&&("string"==typeof(a=t.test(t.postData))&&e.push(a),o="ok"===a,a=t.checkConfig.findIndex(e=>e.id===t.id),t.checkConfig[a].checked!==o&&window.dispatchEvent(new Event("check-changed")),t.checkConfig[a].checked=o),t.inPro)return(0,d.createElement)("p",{className:e.join(" ")},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))));var o=t.valueFieldName&&t.postData[t.valueFieldName]?(0,d.createElement)("b",null,t.postData[t.valueFieldName]):"";return(0,d.createElement)("p",{className:e.join(" ")},t.label," ",o)},m=e=>{let t=["diagnoseo-stats",e.id];if(e.inPro)return(0,d.createElement)("p",{className:t.join(" ")},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",e.label," ",(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))));let a,o=(0,d.createElement)("b",{className:"value"}),n="";var l;return e.test&&(l=e.test(e.postData),o=(0,d.createElement)("b",{className:"value"},l.value),n=l.comment?(0,d.createElement)("span",{className:"comment"},l.comment):"",l.status&&t.push(l.status)),a=e.order&&"value label"!==e.order?(0,d.createElement)(d.Fragment,null,e.label," ",o," ",n):(0,d.createElement)(d.Fragment,null,o," ",e.label),(0,d.createElement)("p",{className:t.join(" ")},a)},g=(0,r.compose)((0,l.withSelect)(e=>({postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,urlSlug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks(),optimalKeywordDensity:2,optimalWordNumber:300,optimalHeadingNumber:1,optimalImageNumber:1,postType:e("core/editor").getCurrentPostType()})))(a=>{const o=window.diagnoseo.checks,e=o.filter(e=>e.section===a.sectionName),n={postTitle:a.postTitle,postContent:a.postContent,keyword:a.keyword,metaTitle:seoHelper.replaceVariables(a.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),metaDescription:seoHelper.replaceVariables(a.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),slug:a.urlSlug,blocks:a.blocks,featuredImage:a.featuredImage,optimalKeywordDensity:a.optimalKeywordDensity,optimalWordNumber:a.optimalWordNumber,optimalHeadingNumber:a.optimalHeadingNumber,optimalImageNumber:a.optimalImageNumber},t=e.map(e=>{let t=!0;if(e.postTypes&&(t=e.postTypes.includes(a.postType)),!e.hidden&&t)switch(e.type){case"check":return e.inPro?(0,d.createElement)(c,{id:e.id,label:e.label,inPro:e.inPro}):(0,d.createElement)(c,{id:e.id,label:e.label,test:e.test,postData:n,checkConfig:o,valueFieldName:e.valueFieldName});case"stats":return e.inPro?(0,d.createElement)(m,{id:e.id,label:e.label,inPro:e.inPro}):(0,d.createElement)(m,{id:e.id,label:e.label,test:e.test,order:e.order,postData:n})}});return(0,d.createElement)(d.Fragment,null,t.map((e,t)=>(0,d.createElement)(React.Fragment,{key:t},e)))});class h extends React.Component{constructor(e){super(e),this.state={keyword:"",keywordList:[],keywordLimit:(window.diagnoseoPro||window.diagnoseo).additionalKeywordLimit,apiKey:"",language:diagnoseo_settings?diagnoseo_settings.locale.substr(0,2):"",loading:!1},this.handleChange=this.handleChange.bind(this),this.handleLangChange=this.handleLangChange.bind(this),this.handleLoadButtonClick=this.handleLoadButtonClick.bind(this),this.relatedKeywordsApiUrl="diagnoseo/v1/related-keywords"}stripKeywordData(e){return(e=-1===e.indexOf("|")?e:e.substr(0,e.indexOf(" |"))).trim()}async loadRelatedKeywords(){var t=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,a=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;if(t)if(this.state.language){this.setState({loading:!0});let e=await this.getRelatedKeywords(t,a);if(e.length){let a=this.state.keywordList;e.forEach(t=>{t={name:t.trim()};var e=a.findIndex(e=>e.name===t);-1===e?a.push(t):(a[e].repeat_min=t.repeat_min,a[e].repeat_max=t.repeat_max)}),this.saveKeywords(a)}this.setState({loading:!1})}else alert((0,p.__)("Please select language.","diagnoseo"));else alert((0,p.__)('Please enter the "focus keyword" first',"diagnoseo"))}saveKeywords(e){const t=[...new Set(e)];t.splice(this.state.keywordLimit),this.setState({keywordList:t}),(window.onbeforeunload=null,l.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_additional_keywords:JSON.stringify(t)}})}saveLanguage(e){(0,l.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_language:e}})}componentDidMount(){let e=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_additional_keywords,t=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;try{e=JSON.parse(e)}catch{e=""}this.setState({language:t,keyword:this.props.focusKeyword,keywordList:e||[]})}async handleLoadButtonClick(){window.diagnoseoPro?this.loadRelatedKeywords():alert((0,p.__)("Related keywords and Pro data require DiagnoSEO Pro.","diagnoseo"))}handleChange(e){const o=this.state.keywordList,{stripKeywordData:n}=this;e=e.map(e=>{let t=n(e.value||e),a=o.findIndex(e=>t===e.name);return{name:t,repeat_min:-1!==a?o[a].repeat_min:0,repeat_max:-1!==a?o[a].repeat_max:0}});this.saveKeywords(e)}handleLangChange(e){this.setState({language:e}),this.saveLanguage(e)}render(){let{postTitle:l,postContent:r,featuredMedia:i}=this.props;const{countOccurences:s}=seoHelper;let c=0,e=this.state.keywordList.map(e=>{let t=e.name||"",a="error",o=function(e){r=seoHelper.stripTags(r);var t=0;return t+=s(e,l),t+=s(e,r),t+=seoHelper.isKeywordInAnyAlt(e,r),t+=i?s(e,i.alt_text):0}(t);o&&(a=!e.repeat_min||!e.repeat_max||o>=e.repeat_min&&o<=e.repeat_max?"success":"validating",c++);let n=` | ${o}`;return e.repeat_min&&e.repeat_max&&(n+=` (${e.repeat_min} - ${e.repeat_max})`),{value:t+n,status:a}}),t=!1;window.diagnoseo.RelatedKeywordsInPost!==c&&(window.diagnoseo.RelatedKeywordsInPost=c,t=!0),window.diagnoseo.additionalKeywordCount!==e.length&&(window.diagnoseo.additionalKeywordCount=e.length,t=!0),t&&window.dispatchEvent(new Event("check-changed"));var a=this.state.loading?(0,p.__)("Please wait... Loading related keywords. It can take up to a few minutes.","diagnoseo"):(0,d.createElement)("button",{className:"button get-related-keywords",onClick:this.handleLoadButtonClick},(0,p.__)("Get related keywords","diagnoseo"));return(0,d.createElement)(d.Fragment,null,(0,d.createElement)("div",{className:"components-base-control__field add-keyword diagnoseo-related-keywords"},(0,d.createElement)(u.FormTokenField,{label:(0,d.createElement)("b",null,(0,p.__)("Related keywords","diagnoseo")),onChange:this.handleChange,value:e,maxLength:this.state.keywordLimit+10}),(0,d.createElement)("p",{className:"components-form-token-field__help"},(0,p.__)("Limits: 10 keywords in free, 100 keywords in Pro","diagnoseo")),(0,d.createElement)(u.SelectControl,{options:[{value:"",label:"Choose language"},{value:"albanian",label:"Albanian"},{value:"arabic",label:"Arabic"},{value:"armenian",label:"Armenian"},{value:"awadhi",label:"Awadhi"},{value:"azerbaijani",label:"Azerbaijani"},{value:"bashkir",label:"Bashkir"},{value:"basque",label:"Basque"},{value:"belarusian",label:"Belarusian"},{value:"bengali",label:"Bengali"},{value:"bhojpuri",label:"Bhojpuri"},{value:"bosnian",label:"Bosnian"},{value:"brazilian Portuguese",label:"Brazilian Portuguese"},{value:"bulgarian",label:"Bulgarian"},{value:"cantonese (Yue)",label:"Cantonese (Yue)"},{value:"catalan",label:"Catalan"},{value:"chhattisgarhi",label:"Chhattisgarhi"},{value:"chinese",label:"Chinese"},{value:"croatian",label:"Croatian"},{value:"czech",label:"Czech"},{value:"danish",label:"Danish"},{value:"dogri",label:"Dogri"},{value:"dutch",label:"Dutch"},{value:"english",label:"English"},{value:"estonian",label:"Estonian"},{value:"faroese",label:"Faroese"},{value:"finnish",label:"Finnish"},{value:"french",label:"French"},{value:"galician",label:"Galician"},{value:"georgian",label:"Georgian"},{value:"german",label:"German"},{value:"greek",label:"Greek"},{value:"gujarati",label:"Gujarati"},{value:"haryanvi",label:"Haryanvi"},{value:"hindi",label:"Hindi"},{value:"hungarian",label:"Hungarian"},{value:"indonesian",label:"Indonesian"},{value:"irish",label:"Irish"},{value:"italian",label:"Italian"},{value:"japanese",label:"Japanese"},{value:"javanese",label:"Javanese"},{value:"kannada",label:"Kannada"},{value:"kashmiri",label:"Kashmiri"},{value:"kazakh",label:"Kazakh"},{value:"konkani",label:"Konkani"},{value:"korean",label:"Korean"},{value:"kyrgyz",label:"Kyrgyz"},{value:"latvian",label:"Latvian"},{value:"lithuanian",label:"Lithuanian"},{value:"macedonian",label:"Macedonian"},{value:"maithili",label:"Maithili"},{value:"malay",label:"Malay"},{value:"maltese",label:"Maltese"},{value:"mandarin",label:"Mandarin"},{value:"mandarin Chinese",label:"Mandarin Chinese"},{value:"marathi",label:"Marathi"},{value:"marwari",label:"Marwari"},{value:"min Nan",label:"Min Nan"},{value:"moldovan",label:"Moldovan"},{value:"mongolian",label:"Mongolian"},{value:"montenegrin",label:"Montenegrin"},{value:"nepali",label:"Nepali"},{value:"norwegian",label:"Norwegian"},{value:"oriya",label:"Oriya"},{value:"pashto",label:"Pashto"},{value:"persian",label:"Persian"},{value:"polish",label:"Polish"},{value:"portuguese",label:"Portuguese"},{value:"punjabi",label:"Punjabi"},{value:"rajasthani",label:"Rajasthani"},{value:"romanian",label:"Romanian"},{value:"russian",label:"Russian"},{value:"sanskrit",label:"Sanskrit"},{value:"santali",label:"Santali"},{value:"serbian",label:"Serbian"},{value:"sindhi",label:"Sindhi"},{value:"sinhala",label:"Sinhala"},{value:"slovak",label:"Slovak"},{value:"slovene",label:"Slovene"},{value:"slovenian",label:"Slovenian"},{value:"spanish",label:"Spanish"},{value:"swahili",label:"Swahili"},{value:"swedish",label:"Swedish"},{value:"tajik",label:"Tajik"},{value:"tamil",label:"Tamil"},{value:"tatar",label:"Tatar"},{value:"telugu",label:"Telugu"},{value:"thai",label:"Thai"},{value:"turkish",label:"Turkish"},{value:"turkmen",label:"Turkmen"},{value:"ukrainian",label:"Ukrainian"},{value:"urdu",label:"Urdu"},{value:"uzbek",label:"Uzbek"},{value:"vietnamese",label:"Vietnamese"},{value:"welsh",label:"Welsh"},{value:"wu",label:"Wu"}],value:this.state.language,onChange:this.handleLangChange,label:(0,p.__)("Language","diagnoseo")}),(0,d.createElement)("p",null,a)))}getRelatedKeywords(a,o){return new Promise(t=>{const e=new FormData;e.append("keyword",a),e.append("language",o),e.append("count",30),fetch("/wp-json/diagnoseo/v1/related-keywords",{method:"POST",body:e}).then(e=>e.json()).then(e=>{"ok"===e.status?t(e.keywords.split(",")):t([])}).catch(e=>{console.error(e),t([])})})}}var k=(0,r.compose)((0,l.withSelect)(e=>{var t=e("core/editor").getEditedPostAttribute("featured_media");return{postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredMedia:e("core").getMedia(t,{context:"embed"})||{}}}))(e=>(0,d.createElement)(h,{postTitle:e.postTitle,postContent:e.postContent,featuredMedia:e.featuredMedia,seoDataCollector:e.seoDataCollector})),w=(0,r.compose)((0,l.withSelect)(e=>{if(!window.diagnoseoPro)return{};e={categories:e("core/editor").getEditedPostAttribute("categories"),status:"publish",per_page:10,exclude:[e("core/editor").getEditedPostAttribute("id")]};return{suggestedPosts:wp.data.select("core").getEntityRecords("postType","post",e)||[]}}))(e=>{if(window.diagnoseoPro){var t="";return t=e.suggestedPosts.length?(t=e.suggestedPosts.map(e=>(0,d.createElement)("li",null,(0,d.createElement)("a",{href:e.link},e.title.raw))),(0,d.createElement)("ol",null,t)):(0,d.createElement)("p",null,(0,p.__)("Could not prepare suggestions as there are no posts related to this one"))}return(0,d.createElement)("p",null,(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))))}),r=(0,r.compose)((0,l.withDispatch)(t=>({setMetaValues:e=>{t("core/editor").editPost({meta:{}})}})))(e=>{var t=window.diagnoseoPro?"DiagnoSEO Pro":"DiagnoSEO";return(0,d.createElement)(d.Fragment,null,(0,d.createElement)(n.PluginSidebarMoreMenuItem,{target:"diagnoseo-content-analyzer"},(0,p.__)("DiagnoSEO Content Watcher","diagnoseo")),(0,d.createElement)(n.PluginSidebar,{title:t,name:"diagnoseo-content-analyzer"},(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Content analyzer","diagnoseo"),initialOpen:"true"},(0,d.createElement)(g,{sectionName:"content"})),(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Keyword placement","diagnoseo"),initialOpen:"true"},(0,d.createElement)(i,{fieldName:"diagnoseo_meta_keyword",label:(0,d.createElement)("b",null,(0,p.__)("Focus keyword","diagnoseo"))}),(0,d.createElement)(s,null),(0,d.createElement)(k,{seoDataCollector:e.setMetaValues}),(0,d.createElement)(g,{sectionName:"keyword"})),(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Internal linking suggestions","diagnoseo"),initialOpen:"true"},(0,d.createElement)(w,null))))});(0,e.registerPlugin)("diagnoseo-sidebar",{icon:(0,d.createElement)(a,null),render:r})}(),document.addEventListener("DOMContentLoaded",function(){"use strict";const e=document.querySelectorAll(".meta-template");e.forEach(e=>{const n=e.querySelector(".choose-variable"),t=e.querySelector(".add-variable"),l=e.querySelector("input, textarea");t&&t.addEventListener("click",e=>{e.preventDefault();var t,a,o=n.value;l.selectionStart||"0"==l.selectionStart?(t=l.selectionStart,a=l.selectionEnd,e=parseInt(t)?" ":"",l.value=l.value.substring(0,t)+e+o+l.value.substring(a,l.value.length)):l.value+=o,l.dispatchEvent(new Event("input"))})});const t=document.querySelectorAll(".diagnoseo-generator-button-free");t&&t.forEach(e=>{e.addEventListener("click",e=>{e.preventDefault(),alert("This feature requires DiagnoSEO Pro")})})}),window.seoHelper={slugify:function(e){e=(e=e.replace(/^\s+|\s+$/g,"")).toLowerCase();for(var t="àáãäâąèéëêęìíïîóòóöôùúüûñńśçćźżł·/_,:;",a=0,o=t.length;a<o;a++)e=e.replace(new RegExp(t.charAt(a),"g"),"aaaaaaeeeeeiiiiooooouuuunnscczzl------".charAt(a));return e=e.replace(/[^a-z0-9 -]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-")},countOccurences:function(e,t){if(!t||!e)return 0;t=t.toLowerCase().replaceAll(/[:;,.!?—]/g,""),e=e.toLowerCase();e=new RegExp(e,"g");return(t.match(e)||[]).length},countSyllables:function(e){if(""===e)return 0;if(e.length<=3)return 1;e=(e=(e=(e=e.toLowerCase()).replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/,"")).replace(/^y/,"")).match(/[aeiouy]{1,2}/g);return e?e.length:0},countWords:function(e){e=(e=(e=e.replace(/(\r\n|\n|\r)/gm," ")).replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g," ")).split(" ");return(e=(e=e.map(e=>e.trim())).filter(e=>e&&""!==e&&"\n"!==e)).length||0},countElements:function(e,t){if(!e||!t)return 0;const a=document.createElement("div");return a.innerHTML=e,a.querySelectorAll(t).length},replaceVariables:function(e){if(e){var{site:t,siteTagline:a,separator:o,excerpt:n,postTitle:l}=document.querySelector(".diagnoseo-preview").dataset;return e=(e=(e=(e=(e=(e=(e=(e=e.replaceAll("%title%",document.body.classList.contains("block-editor-page")?window.wp.data.select("core/editor").getEditedPostAttribute("title"):l)).replaceAll("%sitename%",t)).replaceAll("%tagline%",a)).replaceAll("%sep%",o)).replaceAll("%page%"," ")).replaceAll("%excerpt%",n)).replaceAll("%currentyear%",(new Date).getFullYear())).replaceAll("%currentmonth%",(new Date).toLocaleString("default",{month:"long"}))}},isKeywordInText:function(e,t){if(!e||!t)return!1;e=e.toLowerCase();let a=(t=t.toLowerCase()).toLowerCase().replaceAll(/[:;,.!?-]/g,"");return t.includes(e)||a.includes(e)},isKeywordInAnyElement:function(t,e,a){if(!t||!e||!a)return!1;var o=!1;const n=seoHelper.createMarkupEl(e);return elements=n.querySelectorAll(a),elements.forEach(e=>{seoHelper.isKeywordInText(t,e.textContent)&&(o=!0)}),o},isKeywordInAnyAlt:function(t,e,a=null){if(!t)return!1;if(a&&seoHelper.isKeywordInText(t,a.alt_text))return!0;var o=0;const n=seoHelper.createMarkupEl(e),l=n.querySelectorAll("img");return l.forEach(e=>{e=e.getAttribute("alt").toLowerCase();o+=seoHelper.countOccurences(t,e)}),o},createMarkupEl:function(e){const t=document.createElement("div");return t.innerHTML=e,t},stripTags:function(e){return e.replace(/(<([^>]+)>)/gi,"")}};1 const{__}=window.wp.i18n;window.diagnoseo={additionalKeywordLimit:10,additionalKeywordCount:0,RelatedKeywordsInPost:0,checks:[{id:"title-not-too-long",type:"check",label:__("Title not too long"),section:"content",test:e=>{var{metaTitle:t,postTitle:e}=e;if(!t&&!e)return"nok";t=t||e;const a=document.querySelector(".title-sample");a.textContent=t;e=a.clientWidth,t=t.length;return e<=600?60<t?"nok medium-nok":t<=60?"ok":"nok":"nok"}},{id:"title-not-too-short",type:"check",label:__("Title not too short"),section:"content",test:e=>{var{metaTitle:t,postTitle:e}=e;if(!t&&!e)return"nok";e=(t||e).length;return 30<=e?30<=e&&e<35?"nok medium-nok":35<=e?"ok":"nok":"nok"}},{id:"description-not-too-long",type:"check",label:__("Description not too long"),section:"content",test:e=>{var{metaDescription:t}=e;if(!t)return"nok";e=document.querySelector(".description-sample"),t=t.length;if(e.clientWidth<=990){if(155<t)return"nok medium-nok";if(t<=155)return"ok"}return"nok"}},{id:"description-not-too-short",type:"check",label:__("Description not too short"),section:"content",test:e=>{var{metaDescription:e}=e;if(!e)return"nok";e=e.length;if(70<=e){if(e<130)return"nok medium-nok";if(130<=e)return"ok"}return"nok"}},{id:"too-long-sentences",type:"check",label:__("No sentences with more than 20 words"),section:"content",test:e=>{var{postContent:e}=e;e=(e=(e=(e=(e=(e=(e=(e=e.replaceAll("</p>",".</p>")).replaceAll("</h1>",".</h1>")).replaceAll("</h2>",".</h2>")).replaceAll("</h3>",".</h3>")).replaceAll("</h4>",".</h4>")).replaceAll("</h5>",".</h5>")).replaceAll("</h6>",".</h6>")).replaceAll("</li>",".</li>");const t=(e=seoHelper.stripTags(e)).split(/\.|\?|!/);var a=!1;return t.length&&t.forEach(e=>{a=a||20<seoHelper.countWords(e)}),a?"nok":"ok"}},{id:"too-many-words",type:"check",label:__("No paragraphs with more than 100 words"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("p");var o=!1;return a.length&&a.forEach(e=>{100<seoHelper.countWords(e.textContent)&&(o=!0)}),o?"nok":"ok"}},{id:"too-many-sentences",type:"check",label:__("No paragraphs with more than 5 sentences"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("p");var o=!1;return a.length&&a.forEach(e=>{5<e.textContent.split(/\.|\?|!/).filter(e=>!!e.trim()).length&&(o=!0)}),o?"nok":"ok"}},{id:"internal-links-present",type:"check",label:__("Contains internal links"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("a");var o=!1;return a.forEach(e=>{e=e.getAttribute("href")||"";e&&(e.includes("http://"+window.location.hostname)||e.includes("https://"+window.location.hostname)||"/"===e.substr(0,1)||"./"===e.substr(0,2))&&(o=!0)}),o?"ok":"nok"}},{id:"strong-present",type:"check",label:__("Contains bold text (strong tag)"),section:"content",test:e=>seoHelper.countElements(e.postContent,"strong")?"ok":"nok"},{id:"readability",type:"stats",label:__("Readability score"),order:"label value comment",section:"content",test:e=>{var{postContent:t}=e,a=(t=seoHelper.stripTags(t)).split(/\.|\?|!/);a=(a=a.map(e=>e.trim())).filter(e=>e&&" "!==e&&"\n"!==e);e=(t=t.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g," ")).split(" ");e=(e=e.map(e=>e.trim())).filter(e=>e&&""!==e&&"\n"!==e);var t=seoHelper.countSyllables(t),o=206.835-e.length/a.length*1.015-t/e.length*84.6;(o=o.toFixed(2))<0?o=0:100<o&&(o=100);var n="",l="";switch(!0){case isNaN(o):o=__("N/A"),n="",l="nok";break;case 90<o:n=__("Very easy to read","diagnoseo"),l="ok";break;case 80<o&&o<=90:n=__("Easy to read","diagnoseo"),l="ok";break;case 70<o&&o<=80:n=__("Fairly easy to read","diagnoseo"),l="ok";break;case 60<o&&o<=70:n=__("Average reading ease","diagnoseo"),l="nok medium-nok";break;case 50<o&&o<=60:n=__("Fairly difficult to read","diagnoseo"),l="nok";break;case 30<o&&o<=50:n=__("Difficult to read","diagnoseo"),l="nok";break;case 10<o&&o<=30:n=__("Very difficult to read","diagnoseo"),l="nok";break;case o<=10:n=__("Extremely difficult to read","diagnoseo"),l="nok"}return{value:o,comment:n=n&&` (${n})`,status:l}}},{id:"est-reading-time",type:"stats",label:__("Estimated reading time"),section:"content",order:"label value",test:e=>{var{postContent:t}=e,e=seoHelper.countWords(t),t=Math.floor(e/225),e=Math.floor(e%225/3.75);return{value:`${t} ${__("min")} ${e} ${__("s")}`}}},{id:"minimal-word-count",type:"check",label:__("Minimal word count"),section:"content",postTypes:["post","page"],inPro:!0},{id:"words",type:"stats",label:__("words"),section:"content",test:e=>{var{postContent:e}=e;return{value:seoHelper.countWords(e)}}},{id:"chars",type:"stats",label:__("characters"),section:"content",test:e=>({value:e.postContent.length||0})},{id:"sentences",type:"stats",label:__("sentences"),section:"content",test:e=>{var{postContent:e}=e,e=(e=e.replace(/(\r\n|\n|\r)/gm," ")).split(/\.|\?|!/);return{value:(e=(e=e.map(e=>e.trim())).filter(e=>e&&" "!==e&&"\n"!==e)).length||0}}},{id:"paragraphs",type:"stats",label:__("paragraphs"),section:"content",test:e=>({value:seoHelper.countElements(e.postContent,"p")})},{id:"headings",type:"stats",label:__("Headings"),inPro:!0,section:"content"},{id:"optimal-heading-number",type:"check",label:__("Optimal number of headings"),inPro:!0,section:"content"},{id:"images",type:"stats",label:__("Images"),inPro:!0,section:"content"},{id:"optimal-image-number",type:"check",label:__("Optimal number of images"),inPro:!0,section:"content"},{id:"too-long-headings",type:"check",label:__("No too long headings"),inPro:!0,section:"content"},{id:"toc-block",type:"check",label:__("Use Table of Contents block"),inPro:!0,section:"content"},{id:"keyword-exists",type:"check",label:__("Keyword is provided"),section:"keyword",test:e=>e.keyword?"ok":"nok"},{id:"keyword-unique",type:"check",label:__("Focus Keyword not used before"),section:"keyword",test:async a=>{var o=document.querySelector(".keyword-unique");if(a.keyword){let e=new URLSearchParams(window.location.search);var n=Object.fromEntries(e.entries()),n=`${diagnoseoRestUrl}diagnoseo/v1/check-posts-keyword/${a.keyword}/${n.post||0}`;let t=0===await(await fetch(n)).json()?"ok":"nok";o?o&&(o.classList.remove("ok","nok"),o.classList.add(t)):setTimeout(()=>{(o=document.querySelector(".keyword-unique"))&&(o.classList.remove("ok","nok"),o.classList.add(t))},200)}else o&&o.classList.add("ok")}},{id:"keyword-in-title",type:"check",label:__("Keyword present in title tag"),section:"keyword",test:e=>{var{keyword:t,postTitle:a,metaTitle:e}=e;return seoHelper.isKeywordInText(t,e||a)?"ok":"nok"}},{id:"keyword-in-title-beginning",type:"check",label:__("Keyword in the beginning of the title tag"),section:"keyword",test:e=>{var{keyword:t,postTitle:a,metaTitle:e}=e;if(!t)return"nok";a=(a=e||a).toLowerCase(),t=t.toLowerCase();const o=new RegExp("^"+t);return o.test(a)?"ok":"nok"}},{id:"keyword-in-descr",type:"check",label:__("Keyword present in meta description tag"),section:"keyword",test:e=>{var{keyword:t,metaDescription:e}=e;return seoHelper.isKeywordInText(t,e)?"ok":"nok"}},{id:"keyword-in-slug",type:"check",label:__("Keyword present in URL slug"),section:"keyword",test:e=>{var{keyword:t,slug:a,postTitle:e}=e;return t&&(a=a||seoHelper.slugify(e)).includes(seoHelper.slugify(t))?"ok":"nok"}},{id:"slug-length-ok",type:"check",label:__("URL slug length"),section:"keyword",test:e=>{var{slug:t,postTitle:e}=e;if(!t&&!e)return"nok";if((t=t||seoHelper.slugify(e)).length<=60&&t.split("-").length<=5)return"ok";return"nok"}},{id:"keyword-in-h1",type:"check",label:__("Keyword present in H1 element"),section:"keyword",test:e=>{var{keyword:t,postContent:a,postTitle:e}=e;return seoHelper.isKeywordInText(t,e)||seoHelper.isKeywordInAnyElement(t,a,"h1")?"ok":"nok"}},{id:"keyword-in-image-alt",type:"check",label:__("Keyword present in any image alt attribute"),section:"keyword",test:e=>{var{keyword:t,postContent:a,featuredImage:e}=e;return seoHelper.isKeywordInAnyAlt(t,a,e)?"ok":"nok"}},{id:"keyword-in-image-filename",type:"check",label:__("Keyword in image file name"),section:"keyword",inPro:!0,hidden:!0},{id:"keyword-not-in-ext-link",type:"check",label:__("Keyword NOT present in external link text"),section:"keyword",test:e=>{const{keyword:a,postContent:t}=e;if(!a)return"ok";const o=seoHelper.createMarkupEl(t);var n=!1;const l=o.querySelectorAll("a");return l.forEach(e=>{const t=e.getAttribute("href")||"";t.includes("http://"+window.location.hostname)||t.includes("https://"+window.location.hostname)||"/"===t.substr(0,1)||"./"===t.substr(0,2)||!seoHelper.isKeywordInText(a,e.textContent)||(n=!0)}),n?"nok":"ok"}},{id:"keyword-in-first-words",type:"check",label:__("Keyword present within first 100 words"),section:"keyword",test:e=>{var{keyword:t,postContent:e}=e;if(!t)return"nok";var t=t.trim(),a=(e=seoHelper.stripTags(e)).toLowerCase().split(/\s|\n/),o=100<=(a=a.filter(e=>e)).length?100:a.length;if(a=a.splice(0,o),!seoHelper.isKeywordInText(t,a.join(" ")))return"nok";if(1<t.split(" ").length)return"ok";if(a.length)for(let e=0;e<o;e++)a[e]=a[e].replace(".",""),a[e]=a[e].replace(",",""),a[e]=a[e].replace("?",""),a[e]=a[e].replace("!",""),a[e]=a[e].replace(":",""),a[e]=a[e].replace(";","");return a.includes(t)?"ok":"nok"}},{id:"more",type:"check",label:__("Many more powerful SEO checkpoints"),inPro:!0,section:"content"},{id:"more",type:"check",label:__("Many more powerful SEO checkpoints"),inPro:!0,section:"keyword"}],checkResults:{}},(()=>{"use strict";const d=window.wp.element,e=window.wp.plugins,o=function(){return(0,d.createElement)("svg",{"enable-background":"new 0 0 20 20",height:"20",width:"20",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",className:"diagnoseo-icon"},(0,d.createElement)("clipPath",{id:"a"},(0,d.createElement)("path",{d:"m0 0h20v20h-20z"})),(0,d.createElement)("path",{className:"diagnoseo-icon-part-tick",d:"m12.377 5.866 1.835 1.612-4.839 5.508-4.11-3.576 1.672-1.902 2.256 1.982z"}),(0,d.createElement)("path",{className:"diagnoseo-icon-part-magnifier","clip-path":"url(#a)",d:"m16.298 15.209c1.745-1.983 2.548-4.603 2.208-7.228-.315-2.426-1.555-4.584-3.493-6.077s-4.341-2.139-6.768-1.828c-2.426.315-4.584 1.555-6.077 3.493s-2.142 4.341-1.827 6.767c.649 5.007 5.251 8.554 10.259 7.905 1.441-.188 2.824-.717 4.014-1.536l3.749 3.295 1.476-1.68zm-1.471-1.887c-1.111 1.443-2.72 2.368-4.527 2.602-1.808.235-3.598-.247-5.041-1.361-1.444-1.111-2.368-2.719-2.602-4.527-.483-3.73 2.158-7.158 5.889-7.642.296-.038.59-.057.881-.057 3.375 0 6.316 2.511 6.761 5.946.235 1.806-.249 3.596-1.361 5.039"}))};class t extends React.Component{constructor(e){super(e),this.state={score:0,timeout:null},this.handleCheckChanged=this.handleCheckChanged.bind(this),this.calculateScore=this.calculateScore.bind(this),this.runAllChecks=this.runAllChecks.bind(this)}calculateScore(){const e=window.diagnoseo.checks.filter(e=>"check"===e.type);var t=e.length+1,a=e.filter(e=>e.checked),a=window.diagnoseo.additionalKeywordCount===window.diagnoseo.RelatedKeywordsInPost?a.length+1:a.length,t=Math.round(100*a/t);this.setState({score:t})}runAllChecks(){const{select:e}=window.wp.data,t=window.diagnoseo.checks.filter(e=>"check"===e.type),n={postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,featuredImageId:e("core/editor").getEditedPostAttribute("featured_media"),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,slug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks()};var a;!n.featuredImageId||n.featuredImage?(n.metaTitle=seoHelper.replaceVariables(n.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),n.metaDescription=seoHelper.replaceVariables(n.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),t.forEach((t,e)=>{var a,o;t.test&&(a="ok"===t.test(n),o=window.diagnoseo.checks.findIndex(e=>e.id===t.id),window.diagnoseo.checks[o].checked=a)}),this.calculateScore()):a=setInterval(()=>{e("core").getMedia(n.featuredImageId)&&(clearInterval(a),this.runAllChecks())},500)}handleCheckChanged(){clearTimeout(this.state.timeout),this.setState({timeout:setTimeout(this.calculateScore,300)})}async componentDidMount(){window.addEventListener("check-changed",this.handleCheckChanged),setTimeout(this.runAllChecks,1e3)}componentWillUnmount(){window.removeEventListener("check-changed",this.handleCheckChanged)}render(){let e,t=this.state.score;switch(!0){case t<60:e="score-low";break;case 60<=t&&t<80:e="score-medium";break;case 80<=t:e="score-high"}var a=`diagnoseo-button-content ${e}`;return(0,d.createElement)("span",{className:a},(0,d.createElement)(o,null),(0,d.createElement)("b",{className:"diagnoseo-score"},this.state.score,"/100"))}whenEditorIsReady(){return new Promise(e=>{const t=subscribe(()=>{(select("core/editor").isCleanNewPost()||0<select("core/block-editor").getBlockCount())&&(t(),e())})})}}const a=t,n=window.wp.editor,u=window.wp.components,l=window.wp.data,p=window.wp.i18n,r=window.wp.compose,i=(0,r.compose)((0,l.withDispatch)((a,o)=>({setMetaValue:e=>{var t={};t[o.fieldName]=e,a("core/editor").editPost({meta:t}),o.changeCallback&&o.changeCallback(e)}})),(0,l.withSelect)((e,t)=>({metaValue:e("core/editor").getEditedPostAttribute("meta")[t.fieldName]})))(t=>(0,d.createElement)(u.TextControl,{label:t.label,value:t.metaValue,onChange:e=>t.setMetaValue(e)})),s=(0,r.compose)((0,l.withSelect)(e=>({content:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword})))(e=>{var t,a,o=0;e.keyword&&(a=(a=(t=(t=(t=e.content.replace(/<\!--.*?-->/g,"")).replace(/(\r\n|\n|\r)/gm," ")).toLowerCase()).split(" ")).filter(e=>""!==e),(t=seoHelper.countOccurences(e.keyword,t))&&(o=t/a.length*100,o=parseFloat(o.toFixed(2))));let n;return n=window.diagnoseoPro?(a="diagnoseo-check optimal-keyword-density",a+=1<=o&&o<=3?" ok":" nok",(0,d.createElement)("p",{className:a},(0,p.__)("Optimal keyword density","diagnoseo")," ",(0,d.createElement)("b",{className:"value"},"1% - 3%"))):(0,d.createElement)("p",{className:"diagnoseo-check optimal-keyword-density"},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",(0,p.__)("Optimal keyword density","diagnoseo")),(0,d.createElement)(d.Fragment,null,(0,d.createElement)("p",{className:"diagnoseo-stats keyword-density"},(0,p.__)("Keyword density","diagnoseo")," ",(0,d.createElement)("b",{className:"value"},o,"%")),n)}),c=t=>{let e=["diagnoseo-check",t.id];var a;if(t.test&&("string"==typeof(a=t.test(t.postData))&&e.push(a),o="ok"===a,a=t.checkConfig.findIndex(e=>e.id===t.id),t.checkConfig[a].checked!==o&&window.dispatchEvent(new Event("check-changed")),t.checkConfig[a].checked=o),t.inPro)return(0,d.createElement)("p",{className:e.join(" ")},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))));var o=t.valueFieldName&&t.postData[t.valueFieldName]?(0,d.createElement)("b",null,t.postData[t.valueFieldName]):"";return(0,d.createElement)("p",{className:e.join(" ")},t.label," ",o)},m=e=>{let t=["diagnoseo-stats",e.id];if(e.inPro)return(0,d.createElement)("p",{className:t.join(" ")},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",e.label," ",(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))));let a,o=(0,d.createElement)("b",{className:"value"}),n="";var l;return e.test&&(l=e.test(e.postData),o=(0,d.createElement)("b",{className:"value"},l.value),n=l.comment?(0,d.createElement)("span",{className:"comment"},l.comment):"",l.status&&t.push(l.status)),a=e.order&&"value label"!==e.order?(0,d.createElement)(d.Fragment,null,e.label," ",o," ",n):(0,d.createElement)(d.Fragment,null,o," ",e.label),(0,d.createElement)("p",{className:t.join(" ")},a)},g=(0,r.compose)((0,l.withSelect)(e=>({postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,urlSlug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks(),optimalKeywordDensity:2,optimalWordNumber:300,optimalHeadingNumber:1,optimalImageNumber:1,postType:e("core/editor").getCurrentPostType()})))(a=>{const o=window.diagnoseo.checks,e=o.filter(e=>e.section===a.sectionName),n={postTitle:a.postTitle,postContent:a.postContent,keyword:a.keyword,metaTitle:seoHelper.replaceVariables(a.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),metaDescription:seoHelper.replaceVariables(a.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),slug:a.urlSlug,blocks:a.blocks,featuredImage:a.featuredImage,optimalKeywordDensity:a.optimalKeywordDensity,optimalWordNumber:a.optimalWordNumber,optimalHeadingNumber:a.optimalHeadingNumber,optimalImageNumber:a.optimalImageNumber},t=e.map(e=>{let t=!0;if(e.postTypes&&(t=e.postTypes.includes(a.postType)),!e.hidden&&t)switch(e.type){case"check":return e.inPro?(0,d.createElement)(c,{id:e.id,label:e.label,inPro:e.inPro}):(0,d.createElement)(c,{id:e.id,label:e.label,test:e.test,postData:n,checkConfig:o,valueFieldName:e.valueFieldName});case"stats":return e.inPro?(0,d.createElement)(m,{id:e.id,label:e.label,inPro:e.inPro}):(0,d.createElement)(m,{id:e.id,label:e.label,test:e.test,order:e.order,postData:n})}});return(0,d.createElement)(d.Fragment,null,t.map((e,t)=>(0,d.createElement)(React.Fragment,{key:t},e)))});class h extends React.Component{constructor(e){super(e),this.state={keyword:"",keywordList:[],keywordLimit:(window.diagnoseoPro||window.diagnoseo).additionalKeywordLimit,apiKey:"",language:diagnoseo_settings?diagnoseo_settings.locale.substr(0,2):"",loading:!1},this.handleChange=this.handleChange.bind(this),this.handleLangChange=this.handleLangChange.bind(this),this.handleLoadButtonClick=this.handleLoadButtonClick.bind(this),this.relatedKeywordsApiUrl="diagnoseo/v1/related-keywords"}stripKeywordData(e){return(e=-1===e.indexOf("|")?e:e.substr(0,e.indexOf(" |"))).trim()}async loadRelatedKeywords(){var t=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,a=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;if(t)if(this.state.language){this.setState({loading:!0});let e=await this.getRelatedKeywords(t,a);if(e.length){let a=this.state.keywordList;e.forEach(t=>{t={name:t.trim()};var e=a.findIndex(e=>e.name===t);-1===e?a.push(t):(a[e].repeat_min=t.repeat_min,a[e].repeat_max=t.repeat_max)}),this.saveKeywords(a)}this.setState({loading:!1})}else alert((0,p.__)("Please select language.","diagnoseo"));else alert((0,p.__)('Please enter the "focus keyword" first',"diagnoseo"))}saveKeywords(e){const t=[...new Set(e)];t.splice(this.state.keywordLimit),this.setState({keywordList:t}),(window.onbeforeunload=null,l.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_additional_keywords:JSON.stringify(t)}})}saveLanguage(e){(0,l.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_language:e}})}componentDidMount(){let e=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_additional_keywords,t=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;try{e=JSON.parse(e)}catch{e=""}this.setState({language:t,keyword:this.props.focusKeyword,keywordList:e||[]})}async handleLoadButtonClick(){window.diagnoseoPro?this.loadRelatedKeywords():alert((0,p.__)("Related keywords and Pro data require DiagnoSEO Pro.","diagnoseo"))}handleChange(e){const o=this.state.keywordList,{stripKeywordData:n}=this;e=e.map(e=>{let t=n(e.value||e),a=o.findIndex(e=>t===e.name);return{name:t,repeat_min:-1!==a?o[a].repeat_min:0,repeat_max:-1!==a?o[a].repeat_max:0}});this.saveKeywords(e)}handleLangChange(e){this.setState({language:e}),this.saveLanguage(e)}render(){let{postTitle:l,postContent:r,featuredMedia:i}=this.props;const{countOccurences:s}=seoHelper;let c=0,e=this.state.keywordList.map(e=>{let t=e.name||"",a="error",o=function(e){r=seoHelper.stripTags(r);var t=0;return t+=s(e,l),t+=s(e,r),t+=seoHelper.isKeywordInAnyAlt(e,r),t+=i?s(e,i.alt_text):0}(t);o&&(a=!e.repeat_min||!e.repeat_max||o>=e.repeat_min&&o<=e.repeat_max?"success":"validating",c++);let n=` | ${o}`;return e.repeat_min&&e.repeat_max&&(n+=` (${e.repeat_min} - ${e.repeat_max})`),{value:t+n,status:a}}),t=!1;window.diagnoseo.RelatedKeywordsInPost!==c&&(window.diagnoseo.RelatedKeywordsInPost=c,t=!0),window.diagnoseo.additionalKeywordCount!==e.length&&(window.diagnoseo.additionalKeywordCount=e.length,t=!0),t&&window.dispatchEvent(new Event("check-changed"));var a=this.state.loading?(0,p.__)("Please wait... Loading related keywords. It can take up to a few minutes.","diagnoseo"):(0,d.createElement)("button",{className:"button get-related-keywords",onClick:this.handleLoadButtonClick},(0,p.__)("Get related keywords","diagnoseo"));return(0,d.createElement)(d.Fragment,null,(0,d.createElement)("div",{className:"components-base-control__field add-keyword diagnoseo-related-keywords"},(0,d.createElement)(u.FormTokenField,{label:(0,d.createElement)("b",null,(0,p.__)("Related keywords","diagnoseo")),onChange:this.handleChange,value:e,maxLength:this.state.keywordLimit+10}),(0,d.createElement)("p",{className:"components-form-token-field__help"},(0,p.__)("Limits: 10 keywords in free, 100 keywords in Pro","diagnoseo")),(0,d.createElement)(u.SelectControl,{options:[{value:"",label:"Choose language"},{value:"albanian",label:"Albanian"},{value:"arabic",label:"Arabic"},{value:"armenian",label:"Armenian"},{value:"awadhi",label:"Awadhi"},{value:"azerbaijani",label:"Azerbaijani"},{value:"bashkir",label:"Bashkir"},{value:"basque",label:"Basque"},{value:"belarusian",label:"Belarusian"},{value:"bengali",label:"Bengali"},{value:"bhojpuri",label:"Bhojpuri"},{value:"bosnian",label:"Bosnian"},{value:"brazilian Portuguese",label:"Brazilian Portuguese"},{value:"bulgarian",label:"Bulgarian"},{value:"cantonese (Yue)",label:"Cantonese (Yue)"},{value:"catalan",label:"Catalan"},{value:"chhattisgarhi",label:"Chhattisgarhi"},{value:"chinese",label:"Chinese"},{value:"croatian",label:"Croatian"},{value:"czech",label:"Czech"},{value:"danish",label:"Danish"},{value:"dogri",label:"Dogri"},{value:"dutch",label:"Dutch"},{value:"english",label:"English"},{value:"estonian",label:"Estonian"},{value:"faroese",label:"Faroese"},{value:"finnish",label:"Finnish"},{value:"french",label:"French"},{value:"galician",label:"Galician"},{value:"georgian",label:"Georgian"},{value:"german",label:"German"},{value:"greek",label:"Greek"},{value:"gujarati",label:"Gujarati"},{value:"haryanvi",label:"Haryanvi"},{value:"hindi",label:"Hindi"},{value:"hungarian",label:"Hungarian"},{value:"indonesian",label:"Indonesian"},{value:"irish",label:"Irish"},{value:"italian",label:"Italian"},{value:"japanese",label:"Japanese"},{value:"javanese",label:"Javanese"},{value:"kannada",label:"Kannada"},{value:"kashmiri",label:"Kashmiri"},{value:"kazakh",label:"Kazakh"},{value:"konkani",label:"Konkani"},{value:"korean",label:"Korean"},{value:"kyrgyz",label:"Kyrgyz"},{value:"latvian",label:"Latvian"},{value:"lithuanian",label:"Lithuanian"},{value:"macedonian",label:"Macedonian"},{value:"maithili",label:"Maithili"},{value:"malay",label:"Malay"},{value:"maltese",label:"Maltese"},{value:"mandarin",label:"Mandarin"},{value:"mandarin Chinese",label:"Mandarin Chinese"},{value:"marathi",label:"Marathi"},{value:"marwari",label:"Marwari"},{value:"min Nan",label:"Min Nan"},{value:"moldovan",label:"Moldovan"},{value:"mongolian",label:"Mongolian"},{value:"montenegrin",label:"Montenegrin"},{value:"nepali",label:"Nepali"},{value:"norwegian",label:"Norwegian"},{value:"oriya",label:"Oriya"},{value:"pashto",label:"Pashto"},{value:"persian",label:"Persian"},{value:"polish",label:"Polish"},{value:"portuguese",label:"Portuguese"},{value:"punjabi",label:"Punjabi"},{value:"rajasthani",label:"Rajasthani"},{value:"romanian",label:"Romanian"},{value:"russian",label:"Russian"},{value:"sanskrit",label:"Sanskrit"},{value:"santali",label:"Santali"},{value:"serbian",label:"Serbian"},{value:"sindhi",label:"Sindhi"},{value:"sinhala",label:"Sinhala"},{value:"slovak",label:"Slovak"},{value:"slovene",label:"Slovene"},{value:"slovenian",label:"Slovenian"},{value:"spanish",label:"Spanish"},{value:"swahili",label:"Swahili"},{value:"swedish",label:"Swedish"},{value:"tajik",label:"Tajik"},{value:"tamil",label:"Tamil"},{value:"tatar",label:"Tatar"},{value:"telugu",label:"Telugu"},{value:"thai",label:"Thai"},{value:"turkish",label:"Turkish"},{value:"turkmen",label:"Turkmen"},{value:"ukrainian",label:"Ukrainian"},{value:"urdu",label:"Urdu"},{value:"uzbek",label:"Uzbek"},{value:"vietnamese",label:"Vietnamese"},{value:"welsh",label:"Welsh"},{value:"wu",label:"Wu"}],value:this.state.language,onChange:this.handleLangChange,label:(0,p.__)("Language","diagnoseo")}),(0,d.createElement)("p",null,a)))}getRelatedKeywords(a,o){return new Promise(t=>{const e=new FormData;e.append("keyword",a),e.append("language",o),e.append("count",30),fetch("/wp-json/diagnoseo/v1/related-keywords",{method:"POST",body:e}).then(e=>e.json()).then(e=>{"ok"===e.status?t(e.keywords.split(",")):t([])}).catch(e=>{console.error(e),t([])})})}}const k=(0,r.compose)((0,l.withSelect)(e=>{var t=e("core/editor").getEditedPostAttribute("featured_media");return{postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredMedia:e("core").getMedia(t,{context:"embed"})||{}}}))(e=>(0,d.createElement)(h,{postTitle:e.postTitle,postContent:e.postContent,featuredMedia:e.featuredMedia,seoDataCollector:e.seoDataCollector})),w=(0,r.compose)((0,l.withSelect)(e=>{if(!window.diagnoseoPro)return{};e={categories:e("core/editor").getEditedPostAttribute("categories"),status:"publish",per_page:10,exclude:[e("core/editor").getEditedPostAttribute("id")]};return{suggestedPosts:wp.data.select("core").getEntityRecords("postType","post",e)||[]}}))(e=>{if(window.diagnoseoPro){var t="";return t=e.suggestedPosts.length?(t=e.suggestedPosts.map(e=>(0,d.createElement)("li",null,(0,d.createElement)("a",{href:e.link},e.title.raw))),(0,d.createElement)("ol",null,t)):(0,d.createElement)("p",null,(0,p.__)("Could not prepare suggestions as there are no posts related to this one"))}return(0,d.createElement)("p",null,(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))))}),b=(0,r.compose)((0,l.withDispatch)(t=>({setMetaValues:e=>{t("core/editor").editPost({meta:{}})}})))(e=>{var t=window.diagnoseoPro?"DiagnoSEO Pro":"DiagnoSEO";return(0,d.createElement)(d.Fragment,null,(0,d.createElement)(n.PluginSidebarMoreMenuItem,{target:"diagnoseo-content-analyzer"},(0,p.__)("DiagnoSEO Content Watcher","diagnoseo")),(0,d.createElement)(n.PluginSidebar,{title:t,name:"diagnoseo-content-analyzer"},(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Content analyzer","diagnoseo"),initialOpen:"true"},(0,d.createElement)(g,{sectionName:"content"})),(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Keyword placement","diagnoseo"),initialOpen:"true"},(0,d.createElement)(i,{fieldName:"diagnoseo_meta_keyword",label:(0,d.createElement)("b",null,(0,p.__)("Focus keyword","diagnoseo"))}),(0,d.createElement)(s,null),(0,d.createElement)(k,{seoDataCollector:e.setMetaValues}),(0,d.createElement)(g,{sectionName:"keyword"})),(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Internal linking suggestions","diagnoseo"),initialOpen:"true"},(0,d.createElement)(w,null))))});(0,e.registerPlugin)("diagnoseo-sidebar",{icon:(0,d.createElement)(a,null),render:b})})(),document.addEventListener("DOMContentLoaded",function(){"use strict";const e=document.querySelectorAll(".meta-template");e.forEach(e=>{const n=e.querySelector(".choose-variable"),t=e.querySelector(".add-variable"),l=e.querySelector("input, textarea");t&&t.addEventListener("click",e=>{e.preventDefault();var t,a,o=n.value;l.selectionStart||"0"==l.selectionStart?(t=l.selectionStart,a=l.selectionEnd,e=parseInt(t)?" ":"",l.value=l.value.substring(0,t)+e+o+l.value.substring(a,l.value.length)):l.value+=o,l.dispatchEvent(new Event("input"))})});const t=document.querySelectorAll(".diagnoseo-generator-button-free");t&&t.forEach(e=>{e.addEventListener("click",e=>{e.preventDefault(),alert("This feature requires DiagnoSEO Pro")})})}),window.seoHelper={slugify:function(e){e=(e=e.replace(/^\s+|\s+$/g,"")).toLowerCase();for(var t="àáãäâąèéëêęìíïîóòóöôùúüûñńśçćźżł·/_,:;",a=0,o=t.length;a<o;a++)e=e.replace(new RegExp(t.charAt(a),"g"),"aaaaaaeeeeeiiiiooooouuuunnscczzl------".charAt(a));return e=e.replace(/[^a-z0-9 -]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-")},countOccurences:function(e,t){if(!t||!e)return 0;t=t.toLowerCase().replaceAll(/[:;,.!?—]/g,""),e=e.toLowerCase();e=new RegExp(e,"g");return(t.match(e)||[]).length},countSyllables:function(e){if(""===e)return 0;if(e.length<=3)return 1;e=(e=(e=(e=e.toLowerCase()).replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/,"")).replace(/^y/,"")).match(/[aeiouy]{1,2}/g);return e?e.length:0},countWords:function(e){e=(e=(e=e.replace(/(\r\n|\n|\r)/gm," ")).replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g," ")).split(" ");return(e=(e=e.map(e=>e.trim())).filter(e=>e&&""!==e&&"\n"!==e)).length||0},countElements:function(e,t){if(!e||!t)return 0;const a=document.createElement("div");return a.innerHTML=e,a.querySelectorAll(t).length},replaceVariables:function(e){if(e){var{site:t,siteTagline:a,separator:o,excerpt:n,postTitle:l}=document.querySelector(".diagnoseo-preview").dataset;return e=(e=(e=(e=(e=(e=(e=(e=e.replaceAll("%title%",document.body.classList.contains("block-editor-page")?window.wp.data.select("core/editor").getEditedPostAttribute("title"):l)).replaceAll("%sitename%",t)).replaceAll("%tagline%",a)).replaceAll("%sep%",o)).replaceAll("%page%"," ")).replaceAll("%excerpt%",n)).replaceAll("%currentyear%",(new Date).getFullYear())).replaceAll("%currentmonth%",(new Date).toLocaleString("default",{month:"long"}))}},isKeywordInText:function(e,t){if(!e||!t)return!1;e=e.toLowerCase();let a=(t=t.toLowerCase()).toLowerCase().replaceAll(/[:;,.!?-]/g,"");return t.includes(e)||a.includes(e)},isKeywordInAnyElement:function(t,e,a){if(!t||!e||!a)return!1;var o=!1;const n=seoHelper.createMarkupEl(e);return elements=n.querySelectorAll(a),elements.forEach(e=>{seoHelper.isKeywordInText(t,e.textContent)&&(o=!0)}),o},isKeywordInAnyAlt:function(t,e,a=null){if(!t)return!1;if(a&&seoHelper.isKeywordInText(t,a.alt_text))return!0;var o=0;const n=seoHelper.createMarkupEl(e),l=n.querySelectorAll("img");return l.forEach(e=>{e=e.getAttribute("alt").toLowerCase();o+=seoHelper.countOccurences(t,e)}),o},createMarkupEl:function(e){const t=document.createElement("div");return t.innerHTML=e,t},stripTags:function(e){return e.replace(/(<([^>]+)>)/gi,"")}}; -
diagnoseo/tags/1.2.56/readme.txt
r3365809 r3423066 4 4 Requires at least: 4.7 5 5 Tested up to: 6.8 6 Stable tag: 1.2.5 46 Stable tag: 1.2.56 7 7 Requires PHP: 7.2 8 8 License: GPLv2 or later -
diagnoseo/trunk/diagnoseo.php
r3365809 r3423066 4 4 * Plugin URI: https://diagnoseo.com/wordpress-seo-plugin/ 5 5 * Description: Powerful SEO plugin for WordPress. The most lightweight and complete SEO solution on the market! It includes best-in-class content analyzer and keyword placement checkpoints. 6 * Version: 1.2.5 46 * Version: 1.2.56 7 7 * Author: DiagnoSEO 8 8 * Author URI: https://diagnoseo.com/ -
diagnoseo/trunk/includes/class-diagnoseo-breadcrumbs.php
r3328173 r3423066 103 103 private function prepare_page_ancestor_data( $post_id ) { 104 104 $bc_parent = intval( get_post_meta( $post_id, 'diagnoseo_bc_parent', true ) ); 105 $post_array = empty( $bc_parent ) ? get_post_ancestors( $post_id ) : array( $bc_parent );105 $post_array = empty( $bc_parent ) ? get_post_ancestors( $post_id ) : $this->get_bc_ancestors( $bc_parent ); 106 106 krsort( $post_array ); 107 107 … … 111 111 $this->prepare_item_data( empty( $postlist_title ) ? $post->post_title : $postlist_title, get_permalink( $postid ) ); 112 112 } 113 } 114 /** 115 * Gets post ancestors by the diagnoseo_bc_parent custom field 116 * 117 * @param Integer $post_id ID of the current post. 118 */ 119 private function get_bc_ancestors( $post_id ) { 120 $ancestors = array( $post_id ); 121 $bc_parent = intval( get_post_meta( $post_id, 'diagnoseo_bc_parent', true ) ); 122 while ( ! empty( $bc_parent ) ) { 123 $ancestors[] = $bc_parent; 124 $bc_parent = intval( get_post_meta( $bc_parent, 'diagnoseo_bc_parent', true ) ); 125 } 126 return $ancestors; 113 127 } 114 128 -
diagnoseo/trunk/includes/class-diagnoseo-postmetaimport.php
r3115296 r3423066 14 14 */ 15 15 class Diagnoseo_PostMetaImport { 16 17 /** 18 * @var array meta_keys Diagnoseo meta key names. 19 */ 20 private $meta_keys = array( 'diagnoseo_meta_keyword', 'diagnoseo_meta_title', 'diagnoseo_meta_description' ); 21 22 /** 23 * @var array import_keys Meta keys imported for each plugin 24 */ 25 private $import_keys = array( 26 'rankmath' => array( 'rank_math_focus_keyword', 'rank_math_title', 'rank_math_description' ), 27 'aioseo' => array( '_aioseo_keywords', '_aioseo_title', '_aioseo_description' ), 28 'yoast' => array( '_yoast_wpseo_focuskw', '_yoast_wpseo_title', '_yoast_wpseo_metadesc' ), 29 'seopress' => array( '_seopress_analysis_target_kw', 'rank_math_title', 'rank_math_description' ), 30 ); 16 31 /** 17 32 * Title/description variables for plugins … … 19 34 * @var array plugin_vars 20 35 */ 21 p ublic$plugin_vars = array(36 private $plugin_vars = array( 22 37 'yoast' => array( 23 38 '%%sitename%%', … … 158 173 * @var array new_vars 159 174 */ 160 p ublic$new_vars = array(175 private $new_vars = array( 161 176 'yoast' => array( 162 177 '%sitename%', … … 383 398 */ 384 399 private function import_rankmath_postmeta( $prevent_overwrite = false ) { 385 $this->import_home_meta_rankmath(); 386 387 $options = array( 388 'post_type' => 'any', 389 'posts_per_page' => -1, 390 'meta_query' => array( //phpcs:ignore 391 'relation' => 'OR', 392 array( 393 'key' => 'rank_math_focus_keyword', 394 'compare' => 'EXISTS', 395 ), 396 array( 397 'key' => 'rank_math_title', 398 'compare' => 'EXISTS', 399 ), 400 array( 401 'key' => 'rank_math_description', 402 'compare' => 'EXISTS', 403 ), 404 ), 405 ); 406 407 $query = new WP_Query( $options ); 408 if ( $query->have_posts() ) { 409 while ( $query->have_posts() ) { 410 $query->the_post(); 411 $meta = get_post_custom( get_the_ID() ); 412 ?> 413 <p> 414 <?php esc_html_e( 'Importing meta data for post:', 'diagnoseo' ); ?><br> 415 <?php echo esc_html( get_the_ID() . ' (' . get_the_title() . ')' ); ?> 416 </p> 417 <?php 418 $keyword = empty( $meta['rank_math_focus_keyword'] ) ? '' : $meta['rank_math_focus_keyword'][0]; 419 $title = empty( $meta['rank_math_title'] ) ? '' : str_replace( $this->plugin_vars['rankmath'], $this->new_vars['rankmath'], $meta['rank_math_title'][0] ); 420 $descr = empty( $meta['rank_math_description'] ) ? '' : str_replace( $this->plugin_vars['rankmath'], $this->new_vars['rankmath'], $meta['rank_math_description'][0] ); 421 422 if ( ! empty( $keyword ) ) { 423 $current_keyword = get_post_meta( get_the_ID(), 'diagnoseo_meta_keyword', true ); 424 if ( ( $prevent_overwrite && empty( $current_keyword ) ) || ! $prevent_overwrite ) { 425 update_post_meta( get_the_ID(), 'diagnoseo_meta_keyword', $keyword ); 426 } 427 } 428 if ( ! empty( $title ) ) { 429 $current_title = get_post_meta( get_the_ID(), 'diagnoseo_meta_title', true ); 430 if ( ( $prevent_overwrite && empty( $current_title ) ) || ! $prevent_overwrite ) { 431 update_post_meta( get_the_ID(), 'diagnoseo_meta_title', $title ); 432 } 433 } 434 if ( ! empty( $descr ) ) { 435 $current_descr = get_post_meta( get_the_ID(), 'diagnoseo_meta_description', true ); 436 if ( ( $prevent_overwrite && empty( $current_descr ) ) || ! $prevent_overwrite ) { 437 update_post_meta( get_the_ID(), 'diagnoseo_meta_description', $descr ); 438 } 439 } 440 } 441 } 400 global $wpdb; 401 $wpdb->flush(); 402 $time = microtime(true); 403 404 $imported_meta = $this->fetch_postmeta( $this->import_keys['rankmath'] ); 405 $current_meta = $this->fetch_postmeta( $this->meta_keys ); 406 $new_meta = $this->prepare_postmeta( $imported_meta, $current_meta, 'rankmath', $prevent_overwrite ); 407 $result = $this->save_imported_postmeta( $new_meta['insert'], $new_meta['update'] ); 408 409 $duration = intval( microtime(true) - $time ) ?? 0; 410 echo "<p>Import time: $duration milliseconds<br>Inserted: {$result['inserted']}<br>Updated: {$result['updated']}</p>"; 442 411 } 443 412 … … 745 714 } 746 715 716 /** 717 * Inserts imported post meta to the database. 718 * 719 * @param Array $data Array of post meta objects. 720 */ 721 private function insert_postmeta( $data ) { 722 global $wpdb; 723 $values = array_map( 724 function( $item ) { 725 return "($item->post_id, '$item->meta_key', '$item->meta_value')"; 726 }, 727 $data 728 ); 729 $sql = "insert into {$wpdb->prefix}postmeta (post_id, meta_key, meta_value) values " . implode( ', ', $values); 730 $result = $wpdb->query( $sql ); 731 return $result; 732 } 733 734 /** 735 * Updates post meta entries. 736 * 737 * @param Array $data Array of post meta objects 738 */ 739 private function update_postmeta( $data ) { 740 global $wpdb; 741 $where = implode( "', '", $this->meta_keys ); 742 $updates = array(); 743 foreach ( $data as $item ) { 744 $updates[] = "when meta_key='{$item->meta_key}' and post_id={$item->post_id} then '{$item->meta_value}'"; 745 } 746 $updates = implode( "\n ", $updates); 747 $sql = "update {$wpdb->prefix}postmeta set meta_value = case 748 $updates 749 else meta_value 750 end 751 where meta_key in ('$where')"; 752 753 $result = $wpdb->query( $sql ); 754 return $result; 755 } 756 757 /** 758 * Fetches post meta with certain keys 759 * 760 * @param Array $keys Array of meta field keys. 761 */ 762 private function fetch_postmeta( $keys ) { 763 global $wpdb; 764 $key_list = "'" . implode( "', '", $keys ) . "'"; 765 $sql = "select post_id, meta_key, meta_value from {$wpdb->prefix}postmeta where meta_key in ($key_list)"; 766 return $wpdb->get_results($sql); 767 } 768 769 /** 770 * Prepares the post meta for import: changes keys and in-value variables 771 * 772 * @param Array $imported Post meta object array imported from plugin 773 * @param Array $current Post meta added with DiagnoSEO 774 * @param String $src Slug of plugin from which we are importing 775 * @param Boolean $prevent_overwrite If the import should preserve already set post meta 776 */ 777 private function prepare_postmeta( $imported, $current, $src, $prevent_overwrite = false ) { 778 $new_meta = array(); 779 780 // replace key names and variables in meta values. 781 foreach ( $imported as $item ) { 782 if ( in_array( $item->meta_key, $this->import_keys[ $src ] ) ) { 783 $item->meta_key = str_replace($this->import_keys[ $src ], $this->meta_keys, $item->meta_key); 784 $item->meta_value = str_replace($this->plugin_vars[ $src ], $this->new_vars[ $src ], $item->meta_value); 785 $new_meta[] = $item; 786 } 787 } 788 789 // split entries to those that will be inserted and those that will be updated/ 790 $to_insert = array(); 791 $to_update = array(); 792 793 foreach ( $new_meta as $item ) { 794 $found = array_find( 795 $current, 796 function( $entry ) use ( $item ) { 797 return $entry->post_id === $item->post_id && $entry->meta_key === $item->meta_key; 798 } 799 ); 800 if ( empty( $found ) ) { 801 $to_insert[] = $item; 802 } elseif ( ! $prevent_overwrite ) { 803 $to_update[] = $item; 804 } 805 } 806 807 // return the result. 808 return array( 809 'insert' => $to_insert, 810 'update' => $to_update, 811 ); 812 } 813 814 /** 815 * Saves imported post meta to database and returns numbers of inserted and updated entries 816 * 817 * @param Array $to_insert Array of post meta objectsto be inserted 818 * @param Array $to_update Array of post meta objectsto be updated 819 */ 820 private function save_imported_postmeta( $to_insert, $to_update ) { 821 if ( ! empty( $to_insert ) ) { 822 $inserted = $this->insert_postmeta( $to_insert ); 823 } 824 if ( ! empty( $to_update ) ) { 825 $updated = $this->update_postmeta( $to_update ); 826 } 827 828 return array( 829 'inserted' => $inserted ?? 0, 830 'updated' => $updated ?? 0, 831 ); 832 } 747 833 748 834 } -
diagnoseo/trunk/js/build/index.js
r3213874 r3423066 1 !function(){"use strict";var e=window.wp.element,t=window.wp.plugins,a=function(){return(0,e.createElement)("svg",{"enable-background":"new 0 0 20 20",height:"20",width:"20",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",className:"diagnoseo-icon"},(0,e.createElement)("clipPath",{id:"a"},(0,e.createElement)("path",{d:"m0 0h20v20h-20z"})),(0,e.createElement)("path",{className:"diagnoseo-icon-part-tick",d:"m12.377 5.866 1.835 1.612-4.839 5.508-4.11-3.576 1.672-1.902 2.256 1.982z"}),(0,e.createElement)("path",{className:"diagnoseo-icon-part-magnifier","clip-path":"url(#a)",d:"m16.298 15.209c1.745-1.983 2.548-4.603 2.208-7.228-.315-2.426-1.555-4.584-3.493-6.077s-4.341-2.139-6.768-1.828c-2.426.315-4.584 1.555-6.077 3.493s-2.142 4.341-1.827 6.767c.649 5.007 5.251 8.554 10.259 7.905 1.441-.188 2.824-.717 4.014-1.536l3.749 3.295 1.476-1.68zm-1.471-1.887c-1.111 1.443-2.72 2.368-4.527 2.602-1.808.235-3.598-.247-5.041-1.361-1.444-1.111-2.368-2.719-2.602-4.527-.483-3.73 2.158-7.158 5.889-7.642.296-.038.59-.057.881-.057 3.375 0 6.316 2.511 6.761 5.946.235 1.806-.249 3.596-1.361 5.039"}))};class l extends React.Component{constructor(e){super(e),this.state={score:0,timeout:null},this.handleCheckChanged=this.handleCheckChanged.bind(this),this.calculateScore=this.calculateScore.bind(this),this.runAllChecks=this.runAllChecks.bind(this)}calculateScore(){const e=window.diagnoseo.checks.filter((e=>"check"===e.type));let t=e.length+1,a=e.filter((e=>e.checked)),l=window.diagnoseo.additionalKeywordCount===window.diagnoseo.RelatedKeywordsInPost?a.length+1:a.length,o=Math.round(100*l/t);this.setState({score:o})}runAllChecks(){const{select:e}=window.wp.data,t=window.diagnoseo.checks.filter((e=>"check"===e.type)),a={postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,featuredImageId:e("core/editor").getEditedPostAttribute("featured_media"),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,slug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks()};if(!a.featuredImageId||a.featuredImage)a.metaTitle=seoHelper.replaceVariables(a.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),a.metaDescription=seoHelper.replaceVariables(a.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),t.forEach(((e,t)=>{if(!e.test)return;let l="ok"===e.test(a),o=window.diagnoseo.checks.findIndex((t=>t.id===e.id));window.diagnoseo.checks[o].checked=l})),this.calculateScore();else var l=setInterval((()=>{e("core").getMedia(a.featuredImageId)&&(clearInterval(l),this.runAllChecks())}),500)}handleCheckChanged(){clearTimeout(this.state.timeout),this.setState({timeout:setTimeout(this.calculateScore,300)})}async componentDidMount(){window.addEventListener("check-changed",this.handleCheckChanged),setTimeout(this.runAllChecks,1e3)}componentWillUnmount(){window.removeEventListener("check-changed",this.handleCheckChanged)}render(){let t,l=this.state.score;switch(!0){case l<60:t="score-low";break;case l>=60&&l<80:t="score-medium";break;case l>=80:t="score-high"}let o=`diagnoseo-button-content ${t}`;return(0,e.createElement)("span",{className:o},(0,e.createElement)(a,null),(0,e.createElement)("b",{className:"diagnoseo-score"},this.state.score,"/100"))}whenEditorIsReady(){return new Promise((e=>{const t=subscribe((()=>{(select("core/editor").isCleanNewPost()||select("core/block-editor").getBlockCount()>0)&&(t(),e())}))}))}}var o=l,n=window.wp.editor,i=window.wp.components,r=window.wp.data,s=window.wp.i18n,d=window.wp.compose,c=(0,d.compose)((0,r.withDispatch)(((e,t)=>({setMetaValue:a=>{var l={};l[t.fieldName]=a,e("core/editor").editPost({meta:l}),t.changeCallback&&t.changeCallback(a)}}))),(0,r.withSelect)(((e,t)=>({metaValue:e("core/editor").getEditedPostAttribute("meta")[t.fieldName]}))))((t=>(0,e.createElement)(i.TextControl,{label:t.label,value:t.metaValue,onChange:e=>t.setMetaValue(e)}))),u=(0,d.compose)((0,r.withSelect)((e=>({content:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword}))))((t=>{var a=0;if(t.keyword){var l=t.content.replace(/<\!--.*?-->/g,""),o=(l=(l=l.replace(/(\r\n|\n|\r)/gm," ")).toLowerCase()).split(" ");o=o.filter((e=>""!==e));var n=seoHelper.countOccurences(t.keyword,l);n&&(a=n/o.length*100,a=parseFloat(a.toFixed(2)))}let i;if(window.diagnoseoPro){let t="diagnoseo-check optimal-keyword-density";t+=a>=1&&a<=3?" ok":" nok",i=(0,e.createElement)("p",{className:t},(0,s.__)("Optimal keyword density","diagnoseo")," ",(0,e.createElement)("b",{className:"value"},"1% - 3%"))}else i=(0,e.createElement)("p",{className:"diagnoseo-check optimal-keyword-density"},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",(0,s.__)("Optimal keyword density","diagnoseo"));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("p",{className:"diagnoseo-stats keyword-density"},(0,s.__)("Keyword density","diagnoseo")," ",(0,e.createElement)("b",{className:"value"},a,"%")),i)})),m=t=>{let a=["diagnoseo-check",t.id];if(t.test){let e=t.test(t.postData);"string"==typeof e&&a.push(e);let l="ok"===e,o=t.checkConfig.findIndex((e=>e.id===t.id));t.checkConfig[o].checked!==l&&window.dispatchEvent(new Event("check-changed")),t.checkConfig[o].checked=l}if(t.inPro)return(0,e.createElement)("p",{className:a.join(" ")},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))));const l=t.valueFieldName&&t.postData[t.valueFieldName]?(0,e.createElement)("b",null,t.postData[t.valueFieldName]):"";return(0,e.createElement)("p",{className:a.join(" ")},t.label," ",l)},g=t=>{let a=["diagnoseo-stats",t.id];if(t.inPro)return(0,e.createElement)("p",{className:a.join(" ")},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))));let l,o=(0,e.createElement)("b",{className:"value"}),n="";if(t.test){let l=t.test(t.postData);o=(0,e.createElement)("b",{className:"value"},l.value),n=l.comment?(0,e.createElement)("span",{className:"comment"},l.comment):"",l.status&&a.push(l.status)}return l=t.order&&"value label"!==t.order?(0,e.createElement)(e.Fragment,null,t.label," ",o," ",n):(0,e.createElement)(e.Fragment,null,o," ",t.label),(0,e.createElement)("p",{className:a.join(" ")},l)},h=(0,d.compose)((0,r.withSelect)((e=>({postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,urlSlug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks(),optimalKeywordDensity:2,optimalWordNumber:300,optimalHeadingNumber:1,optimalImageNumber:1,postType:e("core/editor").getCurrentPostType()}))))((t=>{const a=window.diagnoseo.checks,l=a.filter((e=>e.section===t.sectionName)),o={postTitle:t.postTitle,postContent:t.postContent,keyword:t.keyword,metaTitle:seoHelper.replaceVariables(t.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),metaDescription:seoHelper.replaceVariables(t.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),slug:t.urlSlug,blocks:t.blocks,featuredImage:t.featuredImage,optimalKeywordDensity:t.optimalKeywordDensity,optimalWordNumber:t.optimalWordNumber,optimalHeadingNumber:t.optimalHeadingNumber,optimalImageNumber:t.optimalImageNumber},n=l.map((l=>{let n=!0;if(l.postTypes&&(n=l.postTypes.includes(t.postType)),!l.hidden&&n)switch(l.type){case"check":return l.inPro?(0,e.createElement)(m,{id:l.id,label:l.label,inPro:l.inPro}):(0,e.createElement)(m,{id:l.id,label:l.label,test:l.test,postData:o,checkConfig:a,valueFieldName:l.valueFieldName});case"stats":return l.inPro?(0,e.createElement)(g,{id:l.id,label:l.label,inPro:l.inPro}):(0,e.createElement)(g,{id:l.id,label:l.label,test:l.test,order:l.order,postData:o})}}));return(0,e.createElement)(e.Fragment,null,n.map(((t,a)=>(0,e.createElement)(React.Fragment,{key:a},t))))}));class p extends React.Component{constructor(e){super(e),this.state={keyword:"",keywordList:[],keywordLimit:window.diagnoseoPro?window.diagnoseoPro.additionalKeywordLimit:window.diagnoseo.additionalKeywordLimit,apiKey:"",language:diagnoseo_settings?diagnoseo_settings.locale.substr(0,2):"",loading:!1},this.handleChange=this.handleChange.bind(this),this.handleLangChange=this.handleLangChange.bind(this),this.handleLoadButtonClick=this.handleLoadButtonClick.bind(this),this.relatedKeywordsApiUrl="diagnoseo/v1/related-keywords"}stripKeywordData(e){return(e=-1===e.indexOf("|")?e:e.substr(0,e.indexOf(" |"))).trim()}async loadRelatedKeywords(){const e=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,t=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;if(!e)return void alert((0,s.__)('Please enter the "focus keyword" first',"diagnoseo"));if(!this.state.language)return void alert((0,s.__)("Please select language.","diagnoseo"));this.setState({loading:!0});let a=await this.getRelatedKeywords(e,t);if(a.length){let e=this.state.keywordList;a.forEach((t=>{t={name:t.trim()};let a=e.findIndex((e=>e.name===t));-1===a?e.push(t):(e[a].repeat_min=t.repeat_min,e[a].repeat_max=t.repeat_max)})),this.saveKeywords(e)}this.setState({loading:!1})}saveKeywords(e){const t=[...new Set(e)];t.splice(this.state.keywordLimit),this.setState({keywordList:t}),window.onbeforeunload=null,(0,r.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_additional_keywords:JSON.stringify(t)}})}saveLanguage(e){(0,r.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_language:e}})}componentDidMount(){let e=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_additional_keywords,t=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;try{e=JSON.parse(e)}catch{e=""}this.setState({language:t,keyword:this.props.focusKeyword,keywordList:e||[]})}async handleLoadButtonClick(){window.diagnoseoPro?this.loadRelatedKeywords():alert((0,s.__)("Related keywords and Pro data require DiagnoSEO Pro.","diagnoseo"))}handleChange(e){const t=this.state.keywordList,{stripKeywordData:a}=this;let l=e.map((e=>{let l=a(e.value||e),o=t.findIndex((e=>l===e.name));return{name:l,repeat_min:-1!==o?t[o].repeat_min:0,repeat_max:-1!==o?t[o].repeat_max:0}}));this.saveKeywords(l)}handleLangChange(e){this.setState({language:e}),this.saveLanguage(e)}render(){let{postTitle:t,postContent:a,featuredMedia:l}=this.props;const{countOccurences:o}=seoHelper;let n=0,r=this.state.keywordList.map((e=>{let i=e.name||"",r="error",s=function(e){a=seoHelper.stripTags(a);let n=0;return n+=o(e,t),n+=o(e,a),n+=seoHelper.isKeywordInAnyAlt(e,a),n+=l?o(e,l.alt_text):0,n}(i);s&&(r=e.repeat_min&&e.repeat_max?s>=e.repeat_min&&s<=e.repeat_max?"success":"validating":"success",n++);let d=` | ${s}`;return e.repeat_min&&e.repeat_max&&(d+=` (${e.repeat_min} - ${e.repeat_max})`),{value:i+d,status:r}})),d=!1;window.diagnoseo.RelatedKeywordsInPost!==n&&(window.diagnoseo.RelatedKeywordsInPost=n,d=!0),window.diagnoseo.additionalKeywordCount!==r.length&&(window.diagnoseo.additionalKeywordCount=r.length,d=!0),d&&window.dispatchEvent(new Event("check-changed"));let c=this.state.loading?(0,s.__)("Please wait... Loading related keywords. It can take up to a few minutes.","diagnoseo"):(0,e.createElement)("button",{className:"button get-related-keywords",onClick:this.handleLoadButtonClick},(0,s.__)("Get related keywords","diagnoseo"));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"components-base-control__field add-keyword diagnoseo-related-keywords"},(0,e.createElement)(i.FormTokenField,{label:(0,e.createElement)("b",null,(0,s.__)("Related keywords","diagnoseo")),onChange:this.handleChange,value:r,maxLength:this.state.keywordLimit+10}),(0,e.createElement)("p",{className:"components-form-token-field__help"},(0,s.__)("Limits: 10 keywords in free, 100 keywords in Pro","diagnoseo")),(0,e.createElement)(i.SelectControl,{options:[{value:"",label:"Choose language"},{value:"albanian",label:"Albanian"},{value:"arabic",label:"Arabic"},{value:"armenian",label:"Armenian"},{value:"awadhi",label:"Awadhi"},{value:"azerbaijani",label:"Azerbaijani"},{value:"bashkir",label:"Bashkir"},{value:"basque",label:"Basque"},{value:"belarusian",label:"Belarusian"},{value:"bengali",label:"Bengali"},{value:"bhojpuri",label:"Bhojpuri"},{value:"bosnian",label:"Bosnian"},{value:"brazilian Portuguese",label:"Brazilian Portuguese"},{value:"bulgarian",label:"Bulgarian"},{value:"cantonese (Yue)",label:"Cantonese (Yue)"},{value:"catalan",label:"Catalan"},{value:"chhattisgarhi",label:"Chhattisgarhi"},{value:"chinese",label:"Chinese"},{value:"croatian",label:"Croatian"},{value:"czech",label:"Czech"},{value:"danish",label:"Danish"},{value:"dogri",label:"Dogri"},{value:"dutch",label:"Dutch"},{value:"english",label:"English"},{value:"estonian",label:"Estonian"},{value:"faroese",label:"Faroese"},{value:"finnish",label:"Finnish"},{value:"french",label:"French"},{value:"galician",label:"Galician"},{value:"georgian",label:"Georgian"},{value:"german",label:"German"},{value:"greek",label:"Greek"},{value:"gujarati",label:"Gujarati"},{value:"haryanvi",label:"Haryanvi"},{value:"hindi",label:"Hindi"},{value:"hungarian",label:"Hungarian"},{value:"indonesian",label:"Indonesian"},{value:"irish",label:"Irish"},{value:"italian",label:"Italian"},{value:"japanese",label:"Japanese"},{value:"javanese",label:"Javanese"},{value:"kannada",label:"Kannada"},{value:"kashmiri",label:"Kashmiri"},{value:"kazakh",label:"Kazakh"},{value:"konkani",label:"Konkani"},{value:"korean",label:"Korean"},{value:"kyrgyz",label:"Kyrgyz"},{value:"latvian",label:"Latvian"},{value:"lithuanian",label:"Lithuanian"},{value:"macedonian",label:"Macedonian"},{value:"maithili",label:"Maithili"},{value:"malay",label:"Malay"},{value:"maltese",label:"Maltese"},{value:"mandarin",label:"Mandarin"},{value:"mandarin Chinese",label:"Mandarin Chinese"},{value:"marathi",label:"Marathi"},{value:"marwari",label:"Marwari"},{value:"min Nan",label:"Min Nan"},{value:"moldovan",label:"Moldovan"},{value:"mongolian",label:"Mongolian"},{value:"montenegrin",label:"Montenegrin"},{value:"nepali",label:"Nepali"},{value:"norwegian",label:"Norwegian"},{value:"oriya",label:"Oriya"},{value:"pashto",label:"Pashto"},{value:"persian",label:"Persian"},{value:"polish",label:"Polish"},{value:"portuguese",label:"Portuguese"},{value:"punjabi",label:"Punjabi"},{value:"rajasthani",label:"Rajasthani"},{value:"romanian",label:"Romanian"},{value:"russian",label:"Russian"},{value:"sanskrit",label:"Sanskrit"},{value:"santali",label:"Santali"},{value:"serbian",label:"Serbian"},{value:"sindhi",label:"Sindhi"},{value:"sinhala",label:"Sinhala"},{value:"slovak",label:"Slovak"},{value:"slovene",label:"Slovene"},{value:"slovenian",label:"Slovenian"},{value:"spanish",label:"Spanish"},{value:"swahili",label:"Swahili"},{value:"swedish",label:"Swedish"},{value:"tajik",label:"Tajik"},{value:"tamil",label:"Tamil"},{value:"tatar",label:"Tatar"},{value:"telugu",label:"Telugu"},{value:"thai",label:"Thai"},{value:"turkish",label:"Turkish"},{value:"turkmen",label:"Turkmen"},{value:"ukrainian",label:"Ukrainian"},{value:"urdu",label:"Urdu"},{value:"uzbek",label:"Uzbek"},{value:"vietnamese",label:"Vietnamese"},{value:"welsh",label:"Welsh"},{value:"wu",label:"Wu"}],value:this.state.language,onChange:this.handleLangChange,label:(0,s.__)("Language","diagnoseo")}),(0,e.createElement)("p",null,c)))}getRelatedKeywords(e,t){return new Promise((a=>{const l=new FormData;l.append("keyword",e),l.append("language",t),l.append("count",30),fetch("/wp-json/diagnoseo/v1/related-keywords",{method:"POST",body:l}).then((e=>e.json())).then((e=>{"ok"===e.status?a(e.keywords.split(",")):a([])})).catch((e=>{console.error(e),a([])}))}))}}var b=(0,d.compose)((0,r.withSelect)((e=>{const t=e("core/editor").getEditedPostAttribute("featured_media");return{postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredMedia:e("core").getMedia(t,{context:"embed"})||{}}})))((t=>(0,e.createElement)(p,{postTitle:t.postTitle,postContent:t.postContent,featuredMedia:t.featuredMedia,seoDataCollector:t.seoDataCollector}))),w=(0,d.compose)((0,r.withSelect)((e=>{if(!window.diagnoseoPro)return{};const t={categories:e("core/editor").getEditedPostAttribute("categories"),status:"publish",per_page:10,exclude:[e("core/editor").getEditedPostAttribute("id")]};return{suggestedPosts:wp.data.select("core").getEntityRecords("postType","post",t)||[]}})))((t=>{if(window.diagnoseoPro){var a="";return t.suggestedPosts.length?(a=t.suggestedPosts.map((t=>(0,e.createElement)("li",null,(0,e.createElement)("a",{href:t.link},t.title.raw)))),a=(0,e.createElement)("ol",null,a)):a=(0,e.createElement)("p",null,(0,s.__)("Could not prepare suggestions as there are no posts related to this one")),a}return(0,e.createElement)("p",null,(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))))})),v=(0,d.compose)((0,r.withDispatch)((e=>({setMetaValues:t=>{e("core/editor").editPost({meta:{}})}}))))((t=>{let a=window.diagnoseoPro?"DiagnoSEO Pro":"DiagnoSEO";return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(n.PluginSidebarMoreMenuItem,{target:"diagnoseo-content-analyzer"},(0,s.__)("DiagnoSEO Content Watcher","diagnoseo")),(0,e.createElement)(n.PluginSidebar,{title:a,name:"diagnoseo-content-analyzer"},(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Content analyzer","diagnoseo"),initialOpen:"true"},(0,e.createElement)(h,{sectionName:"content"})),(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Keyword placement","diagnoseo"),initialOpen:"true"},(0,e.createElement)(c,{fieldName:"diagnoseo_meta_keyword",label:(0,e.createElement)("b",null,(0,s.__)("Focus keyword","diagnoseo"))}),(0,e.createElement)(u,null),(0,e.createElement)(b,{seoDataCollector:t.setMetaValues}),(0,e.createElement)(h,{sectionName:"keyword"})),(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Internal linking suggestions","diagnoseo"),initialOpen:"true"},(0,e.createElement)(w,null))))}));(0,t.registerPlugin)("diagnoseo-sidebar",{icon:(0,e.createElement)(o,null),render:v})}();1 (()=>{"use strict";const e=window.wp.element,t=window.wp.plugins,a=function(){return(0,e.createElement)("svg",{"enable-background":"new 0 0 20 20",height:"20",width:"20",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",className:"diagnoseo-icon"},(0,e.createElement)("clipPath",{id:"a"},(0,e.createElement)("path",{d:"m0 0h20v20h-20z"})),(0,e.createElement)("path",{className:"diagnoseo-icon-part-tick",d:"m12.377 5.866 1.835 1.612-4.839 5.508-4.11-3.576 1.672-1.902 2.256 1.982z"}),(0,e.createElement)("path",{className:"diagnoseo-icon-part-magnifier","clip-path":"url(#a)",d:"m16.298 15.209c1.745-1.983 2.548-4.603 2.208-7.228-.315-2.426-1.555-4.584-3.493-6.077s-4.341-2.139-6.768-1.828c-2.426.315-4.584 1.555-6.077 3.493s-2.142 4.341-1.827 6.767c.649 5.007 5.251 8.554 10.259 7.905 1.441-.188 2.824-.717 4.014-1.536l3.749 3.295 1.476-1.68zm-1.471-1.887c-1.111 1.443-2.72 2.368-4.527 2.602-1.808.235-3.598-.247-5.041-1.361-1.444-1.111-2.368-2.719-2.602-4.527-.483-3.73 2.158-7.158 5.889-7.642.296-.038.59-.057.881-.057 3.375 0 6.316 2.511 6.761 5.946.235 1.806-.249 3.596-1.361 5.039"}))};class l extends React.Component{constructor(e){super(e),this.state={score:0,timeout:null},this.handleCheckChanged=this.handleCheckChanged.bind(this),this.calculateScore=this.calculateScore.bind(this),this.runAllChecks=this.runAllChecks.bind(this)}calculateScore(){const e=window.diagnoseo.checks.filter(e=>"check"===e.type);let t=e.length+1,a=e.filter(e=>e.checked),l=window.diagnoseo.additionalKeywordCount===window.diagnoseo.RelatedKeywordsInPost?a.length+1:a.length,o=Math.round(100*l/t);this.setState({score:o})}runAllChecks(){const{select:e}=window.wp.data,t=window.diagnoseo.checks.filter(e=>"check"===e.type),a={postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,featuredImageId:e("core/editor").getEditedPostAttribute("featured_media"),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,slug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks()};if(!a.featuredImageId||a.featuredImage)a.metaTitle=seoHelper.replaceVariables(a.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),a.metaDescription=seoHelper.replaceVariables(a.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),t.forEach((e,t)=>{if(!e.test)return;let l="ok"===e.test(a),o=window.diagnoseo.checks.findIndex(t=>t.id===e.id);window.diagnoseo.checks[o].checked=l}),this.calculateScore();else var l=setInterval(()=>{e("core").getMedia(a.featuredImageId)&&(clearInterval(l),this.runAllChecks())},500)}handleCheckChanged(){clearTimeout(this.state.timeout),this.setState({timeout:setTimeout(this.calculateScore,300)})}async componentDidMount(){window.addEventListener("check-changed",this.handleCheckChanged),setTimeout(this.runAllChecks,1e3)}componentWillUnmount(){window.removeEventListener("check-changed",this.handleCheckChanged)}render(){let t,l=this.state.score;switch(!0){case l<60:t="score-low";break;case l>=60&&l<80:t="score-medium";break;case l>=80:t="score-high"}let o=`diagnoseo-button-content ${t}`;return(0,e.createElement)("span",{className:o},(0,e.createElement)(a,null),(0,e.createElement)("b",{className:"diagnoseo-score"},this.state.score,"/100"))}whenEditorIsReady(){return new Promise(e=>{const t=subscribe(()=>{(select("core/editor").isCleanNewPost()||select("core/block-editor").getBlockCount()>0)&&(t(),e())})})}}const o=l,n=window.wp.editor,i=window.wp.components,r=window.wp.data,s=window.wp.i18n,d=window.wp.compose,c=(0,d.compose)((0,r.withDispatch)((e,t)=>({setMetaValue:a=>{var l={};l[t.fieldName]=a,e("core/editor").editPost({meta:l}),t.changeCallback&&t.changeCallback(a)}})),(0,r.withSelect)((e,t)=>({metaValue:e("core/editor").getEditedPostAttribute("meta")[t.fieldName]})))(t=>(0,e.createElement)(i.TextControl,{label:t.label,value:t.metaValue,onChange:e=>t.setMetaValue(e)})),u=(0,d.compose)((0,r.withSelect)(e=>({content:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword})))(t=>{var a=0;if(t.keyword){var l=t.content.replace(/<\!--.*?-->/g,""),o=(l=(l=l.replace(/(\r\n|\n|\r)/gm," ")).toLowerCase()).split(" ");o=o.filter(e=>""!==e);var n=seoHelper.countOccurences(t.keyword,l);n&&(a=n/o.length*100,a=parseFloat(a.toFixed(2)))}let i;if(window.diagnoseoPro){let t="diagnoseo-check optimal-keyword-density";t+=a>=1&&a<=3?" ok":" nok",i=(0,e.createElement)("p",{className:t},(0,s.__)("Optimal keyword density","diagnoseo")," ",(0,e.createElement)("b",{className:"value"},"1% - 3%"))}else i=(0,e.createElement)("p",{className:"diagnoseo-check optimal-keyword-density"},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",(0,s.__)("Optimal keyword density","diagnoseo"));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("p",{className:"diagnoseo-stats keyword-density"},(0,s.__)("Keyword density","diagnoseo")," ",(0,e.createElement)("b",{className:"value"},a,"%")),i)}),m=t=>{let a=["diagnoseo-check",t.id];if(t.test){let e=t.test(t.postData);"string"==typeof e&&a.push(e);let l="ok"===e,o=t.checkConfig.findIndex(e=>e.id===t.id);t.checkConfig[o].checked!==l&&window.dispatchEvent(new Event("check-changed")),t.checkConfig[o].checked=l}if(t.inPro)return(0,e.createElement)("p",{className:a.join(" ")},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))));const l=t.valueFieldName&&t.postData[t.valueFieldName]?(0,e.createElement)("b",null,t.postData[t.valueFieldName]):"";return(0,e.createElement)("p",{className:a.join(" ")},t.label," ",l)},g=t=>{let a=["diagnoseo-stats",t.id];if(t.inPro)return(0,e.createElement)("p",{className:a.join(" ")},(0,e.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))));let l,o=(0,e.createElement)("b",{className:"value"}),n="";if(t.test){let l=t.test(t.postData);o=(0,e.createElement)("b",{className:"value"},l.value),n=l.comment?(0,e.createElement)("span",{className:"comment"},l.comment):"",l.status&&a.push(l.status)}return l=t.order&&"value label"!==t.order?(0,e.createElement)(e.Fragment,null,t.label," ",o," ",n):(0,e.createElement)(e.Fragment,null,o," ",t.label),(0,e.createElement)("p",{className:a.join(" ")},l)},h=(0,d.compose)((0,r.withSelect)(e=>({postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,urlSlug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks(),optimalKeywordDensity:2,optimalWordNumber:300,optimalHeadingNumber:1,optimalImageNumber:1,postType:e("core/editor").getCurrentPostType()})))(t=>{const a=window.diagnoseo.checks,l=a.filter(e=>e.section===t.sectionName),o={postTitle:t.postTitle,postContent:t.postContent,keyword:t.keyword,metaTitle:seoHelper.replaceVariables(t.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),metaDescription:seoHelper.replaceVariables(t.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),slug:t.urlSlug,blocks:t.blocks,featuredImage:t.featuredImage,optimalKeywordDensity:t.optimalKeywordDensity,optimalWordNumber:t.optimalWordNumber,optimalHeadingNumber:t.optimalHeadingNumber,optimalImageNumber:t.optimalImageNumber},n=l.map(l=>{let n=!0;if(l.postTypes&&(n=l.postTypes.includes(t.postType)),!l.hidden&&n)switch(l.type){case"check":return l.inPro?(0,e.createElement)(m,{id:l.id,label:l.label,inPro:l.inPro}):(0,e.createElement)(m,{id:l.id,label:l.label,test:l.test,postData:o,checkConfig:a,valueFieldName:l.valueFieldName});case"stats":return l.inPro?(0,e.createElement)(g,{id:l.id,label:l.label,inPro:l.inPro}):(0,e.createElement)(g,{id:l.id,label:l.label,test:l.test,order:l.order,postData:o})}});return(0,e.createElement)(e.Fragment,null,n.map((t,a)=>(0,e.createElement)(React.Fragment,{key:a},t)))});class p extends React.Component{constructor(e){super(e),this.state={keyword:"",keywordList:[],keywordLimit:window.diagnoseoPro?window.diagnoseoPro.additionalKeywordLimit:window.diagnoseo.additionalKeywordLimit,apiKey:"",language:diagnoseo_settings?diagnoseo_settings.locale.substr(0,2):"",loading:!1},this.handleChange=this.handleChange.bind(this),this.handleLangChange=this.handleLangChange.bind(this),this.handleLoadButtonClick=this.handleLoadButtonClick.bind(this),this.relatedKeywordsApiUrl="diagnoseo/v1/related-keywords"}stripKeywordData(e){return(e=-1===e.indexOf("|")?e:e.substr(0,e.indexOf(" |"))).trim()}async loadRelatedKeywords(){const e=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,t=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;if(!e)return void alert((0,s.__)('Please enter the "focus keyword" first',"diagnoseo"));if(!this.state.language)return void alert((0,s.__)("Please select language.","diagnoseo"));this.setState({loading:!0});let a=await this.getRelatedKeywords(e,t);if(a.length){let e=this.state.keywordList;a.forEach(t=>{t={name:t.trim()};let a=e.findIndex(e=>e.name===t);-1===a?e.push(t):(e[a].repeat_min=t.repeat_min,e[a].repeat_max=t.repeat_max)}),this.saveKeywords(e)}this.setState({loading:!1})}saveKeywords(e){const t=[...new Set(e)];t.splice(this.state.keywordLimit),this.setState({keywordList:t}),window.onbeforeunload=null,(0,r.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_additional_keywords:JSON.stringify(t)}})}saveLanguage(e){(0,r.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_language:e}})}componentDidMount(){let e=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_additional_keywords,t=(0,r.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;try{e=JSON.parse(e)}catch{e=""}this.setState({language:t,keyword:this.props.focusKeyword,keywordList:e||[]})}async handleLoadButtonClick(){window.diagnoseoPro?this.loadRelatedKeywords():alert((0,s.__)("Related keywords and Pro data require DiagnoSEO Pro.","diagnoseo"))}handleChange(e){const t=this.state.keywordList,{stripKeywordData:a}=this;let l=e.map(e=>{let l=a(e.value||e),o=t.findIndex(e=>l===e.name);return{name:l,repeat_min:-1!==o?t[o].repeat_min:0,repeat_max:-1!==o?t[o].repeat_max:0}});this.saveKeywords(l)}handleLangChange(e){this.setState({language:e}),this.saveLanguage(e)}render(){let{postTitle:t,postContent:a,featuredMedia:l}=this.props;const{countOccurences:o}=seoHelper;let n=0,r=this.state.keywordList.map(e=>{let i=e.name||"",r="error",s=function(e){a=seoHelper.stripTags(a);let n=0;return n+=o(e,t),n+=o(e,a),n+=seoHelper.isKeywordInAnyAlt(e,a),n+=l?o(e,l.alt_text):0,n}(i);s&&(r=e.repeat_min&&e.repeat_max?s>=e.repeat_min&&s<=e.repeat_max?"success":"validating":"success",n++);let d=` | ${s}`;return e.repeat_min&&e.repeat_max&&(d+=` (${e.repeat_min} - ${e.repeat_max})`),{value:i+d,status:r}}),d=!1;window.diagnoseo.RelatedKeywordsInPost!==n&&(window.diagnoseo.RelatedKeywordsInPost=n,d=!0),window.diagnoseo.additionalKeywordCount!==r.length&&(window.diagnoseo.additionalKeywordCount=r.length,d=!0),d&&window.dispatchEvent(new Event("check-changed"));let c=this.state.loading?(0,s.__)("Please wait... Loading related keywords. It can take up to a few minutes.","diagnoseo"):(0,e.createElement)("button",{className:"button get-related-keywords",onClick:this.handleLoadButtonClick},(0,s.__)("Get related keywords","diagnoseo"));return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{className:"components-base-control__field add-keyword diagnoseo-related-keywords"},(0,e.createElement)(i.FormTokenField,{label:(0,e.createElement)("b",null,(0,s.__)("Related keywords","diagnoseo")),onChange:this.handleChange,value:r,maxLength:this.state.keywordLimit+10}),(0,e.createElement)("p",{className:"components-form-token-field__help"},(0,s.__)("Limits: 10 keywords in free, 100 keywords in Pro","diagnoseo")),(0,e.createElement)(i.SelectControl,{options:[{value:"",label:"Choose language"},{value:"albanian",label:"Albanian"},{value:"arabic",label:"Arabic"},{value:"armenian",label:"Armenian"},{value:"awadhi",label:"Awadhi"},{value:"azerbaijani",label:"Azerbaijani"},{value:"bashkir",label:"Bashkir"},{value:"basque",label:"Basque"},{value:"belarusian",label:"Belarusian"},{value:"bengali",label:"Bengali"},{value:"bhojpuri",label:"Bhojpuri"},{value:"bosnian",label:"Bosnian"},{value:"brazilian Portuguese",label:"Brazilian Portuguese"},{value:"bulgarian",label:"Bulgarian"},{value:"cantonese (Yue)",label:"Cantonese (Yue)"},{value:"catalan",label:"Catalan"},{value:"chhattisgarhi",label:"Chhattisgarhi"},{value:"chinese",label:"Chinese"},{value:"croatian",label:"Croatian"},{value:"czech",label:"Czech"},{value:"danish",label:"Danish"},{value:"dogri",label:"Dogri"},{value:"dutch",label:"Dutch"},{value:"english",label:"English"},{value:"estonian",label:"Estonian"},{value:"faroese",label:"Faroese"},{value:"finnish",label:"Finnish"},{value:"french",label:"French"},{value:"galician",label:"Galician"},{value:"georgian",label:"Georgian"},{value:"german",label:"German"},{value:"greek",label:"Greek"},{value:"gujarati",label:"Gujarati"},{value:"haryanvi",label:"Haryanvi"},{value:"hindi",label:"Hindi"},{value:"hungarian",label:"Hungarian"},{value:"indonesian",label:"Indonesian"},{value:"irish",label:"Irish"},{value:"italian",label:"Italian"},{value:"japanese",label:"Japanese"},{value:"javanese",label:"Javanese"},{value:"kannada",label:"Kannada"},{value:"kashmiri",label:"Kashmiri"},{value:"kazakh",label:"Kazakh"},{value:"konkani",label:"Konkani"},{value:"korean",label:"Korean"},{value:"kyrgyz",label:"Kyrgyz"},{value:"latvian",label:"Latvian"},{value:"lithuanian",label:"Lithuanian"},{value:"macedonian",label:"Macedonian"},{value:"maithili",label:"Maithili"},{value:"malay",label:"Malay"},{value:"maltese",label:"Maltese"},{value:"mandarin",label:"Mandarin"},{value:"mandarin Chinese",label:"Mandarin Chinese"},{value:"marathi",label:"Marathi"},{value:"marwari",label:"Marwari"},{value:"min Nan",label:"Min Nan"},{value:"moldovan",label:"Moldovan"},{value:"mongolian",label:"Mongolian"},{value:"montenegrin",label:"Montenegrin"},{value:"nepali",label:"Nepali"},{value:"norwegian",label:"Norwegian"},{value:"oriya",label:"Oriya"},{value:"pashto",label:"Pashto"},{value:"persian",label:"Persian"},{value:"polish",label:"Polish"},{value:"portuguese",label:"Portuguese"},{value:"punjabi",label:"Punjabi"},{value:"rajasthani",label:"Rajasthani"},{value:"romanian",label:"Romanian"},{value:"russian",label:"Russian"},{value:"sanskrit",label:"Sanskrit"},{value:"santali",label:"Santali"},{value:"serbian",label:"Serbian"},{value:"sindhi",label:"Sindhi"},{value:"sinhala",label:"Sinhala"},{value:"slovak",label:"Slovak"},{value:"slovene",label:"Slovene"},{value:"slovenian",label:"Slovenian"},{value:"spanish",label:"Spanish"},{value:"swahili",label:"Swahili"},{value:"swedish",label:"Swedish"},{value:"tajik",label:"Tajik"},{value:"tamil",label:"Tamil"},{value:"tatar",label:"Tatar"},{value:"telugu",label:"Telugu"},{value:"thai",label:"Thai"},{value:"turkish",label:"Turkish"},{value:"turkmen",label:"Turkmen"},{value:"ukrainian",label:"Ukrainian"},{value:"urdu",label:"Urdu"},{value:"uzbek",label:"Uzbek"},{value:"vietnamese",label:"Vietnamese"},{value:"welsh",label:"Welsh"},{value:"wu",label:"Wu"}],value:this.state.language,onChange:this.handleLangChange,label:(0,s.__)("Language","diagnoseo")}),(0,e.createElement)("p",null,c)))}getRelatedKeywords(e,t){return new Promise(a=>{const l=new FormData;l.append("keyword",e),l.append("language",t),l.append("count",30),fetch("/wp-json/diagnoseo/v1/related-keywords",{method:"POST",body:l}).then(e=>e.json()).then(e=>{"ok"===e.status?a(e.keywords.split(",")):a([])}).catch(e=>{console.error(e),a([])})})}}const b=(0,d.compose)((0,r.withSelect)(e=>{const t=e("core/editor").getEditedPostAttribute("featured_media");return{postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredMedia:e("core").getMedia(t,{context:"embed"})||{}}}))(t=>(0,e.createElement)(p,{postTitle:t.postTitle,postContent:t.postContent,featuredMedia:t.featuredMedia,seoDataCollector:t.seoDataCollector})),w=(0,d.compose)((0,r.withSelect)(e=>{if(!window.diagnoseoPro)return{};const t={categories:e("core/editor").getEditedPostAttribute("categories"),status:"publish",per_page:10,exclude:[e("core/editor").getEditedPostAttribute("id")]};return{suggestedPosts:wp.data.select("core").getEntityRecords("postType","post",t)||[]}}))(t=>{if(window.diagnoseoPro){var a="";return t.suggestedPosts.length?(a=t.suggestedPosts.map(t=>(0,e.createElement)("li",null,(0,e.createElement)("a",{href:t.link},t.title.raw))),a=(0,e.createElement)("ol",null,a)):a=(0,e.createElement)("p",null,(0,s.__)("Could not prepare suggestions as there are no posts related to this one")),a}return(0,e.createElement)("p",null,(0,e.createElement)("b",null,(0,e.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,s.__)("Available in Pro","diagnoseo"))))}),v=(0,d.compose)((0,r.withDispatch)(e=>({setMetaValues:t=>{e("core/editor").editPost({meta:{}})}})))(t=>{let a=window.diagnoseoPro?"DiagnoSEO Pro":"DiagnoSEO";return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(n.PluginSidebarMoreMenuItem,{target:"diagnoseo-content-analyzer"},(0,s.__)("DiagnoSEO Content Watcher","diagnoseo")),(0,e.createElement)(n.PluginSidebar,{title:a,name:"diagnoseo-content-analyzer"},(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Content analyzer","diagnoseo"),initialOpen:"true"},(0,e.createElement)(h,{sectionName:"content"})),(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Keyword placement","diagnoseo"),initialOpen:"true"},(0,e.createElement)(c,{fieldName:"diagnoseo_meta_keyword",label:(0,e.createElement)("b",null,(0,s.__)("Focus keyword","diagnoseo"))}),(0,e.createElement)(u,null),(0,e.createElement)(b,{seoDataCollector:t.setMetaValues}),(0,e.createElement)(h,{sectionName:"keyword"})),(0,e.createElement)(i.PanelBody,{title:(0,s.__)("Internal linking suggestions","diagnoseo"),initialOpen:"true"},(0,e.createElement)(w,null))))});(0,t.registerPlugin)("diagnoseo-sidebar",{icon:(0,e.createElement)(o,null),render:v})})(); -
diagnoseo/trunk/js/diagnoseo-editor.min.js
r3290407 r3423066 1 const{__}=window.wp.i18n;window.diagnoseo={additionalKeywordLimit:10,additionalKeywordCount:0,RelatedKeywordsInPost:0,checks:[{id:"title-not-too-long",type:"check",label:__("Title not too long"),section:"content",test:e=>{var{metaTitle:t,postTitle:e}=e;if(!t&&!e)return"nok";t=t||e;const a=document.querySelector(".title-sample");a.textContent=t;e=a.clientWidth,t=t.length;return e<=600?60<t?"nok medium-nok":t<=60?"ok":"nok":"nok"}},{id:"title-not-too-short",type:"check",label:__("Title not too short"),section:"content",test:e=>{var{metaTitle:t,postTitle:e}=e;if(!t&&!e)return"nok";e=(t||e).length;return 30<=e?30<=e&&e<35?"nok medium-nok":35<=e?"ok":"nok":"nok"}},{id:"description-not-too-long",type:"check",label:__("Description not too long"),section:"content",test:e=>{var{metaDescription:t}=e;if(!t)return"nok";e=document.querySelector(".description-sample"),t=t.length;if(e.clientWidth<=990){if(155<t)return"nok medium-nok";if(t<=155)return"ok"}return"nok"}},{id:"description-not-too-short",type:"check",label:__("Description not too short"),section:"content",test:e=>{var{metaDescription:e}=e;if(!e)return"nok";e=e.length;if(70<=e){if(e<130)return"nok medium-nok";if(130<=e)return"ok"}return"nok"}},{id:"too-long-sentences",type:"check",label:__("No sentences with more than 20 words"),section:"content",test:e=>{var{postContent:e}=e;e=(e=(e=(e=(e=(e=(e=(e=e.replaceAll("</p>",".</p>")).replaceAll("</h1>",".</h1>")).replaceAll("</h2>",".</h2>")).replaceAll("</h3>",".</h3>")).replaceAll("</h4>",".</h4>")).replaceAll("</h5>",".</h5>")).replaceAll("</h6>",".</h6>")).replaceAll("</li>",".</li>");const t=(e=seoHelper.stripTags(e)).split(/\.|\?|!/);var a=!1;return t.length&&t.forEach(e=>{a=a||20<seoHelper.countWords(e)}),a?"nok":"ok"}},{id:"too-many-words",type:"check",label:__("No paragraphs with more than 100 words"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("p");var o=!1;return a.length&&a.forEach(e=>{100<seoHelper.countWords(e.textContent)&&(o=!0)}),o?"nok":"ok"}},{id:"too-many-sentences",type:"check",label:__("No paragraphs with more than 5 sentences"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("p");var o=!1;return a.length&&a.forEach(e=>{5<e.textContent.split(/\.|\?|!/).filter(e=>!!e.trim()).length&&(o=!0)}),o?"nok":"ok"}},{id:"internal-links-present",type:"check",label:__("Contains internal links"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("a");var o=!1;return a.forEach(e=>{e=e.getAttribute("href")||"";e&&(e.includes("http://"+window.location.hostname)||e.includes("https://"+window.location.hostname)||"/"===e.substr(0,1)||"./"===e.substr(0,2))&&(o=!0)}),o?"ok":"nok"}},{id:"strong-present",type:"check",label:__("Contains bold text (strong tag)"),section:"content",test:e=>seoHelper.countElements(e.postContent,"strong")?"ok":"nok"},{id:"readability",type:"stats",label:__("Readability score"),order:"label value comment",section:"content",test:e=>{var{postContent:t}=e,a=(t=seoHelper.stripTags(t)).split(/\.|\?|!/);a=(a=a.map(e=>e.trim())).filter(e=>e&&" "!==e&&"\n"!==e);e=(t=t.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g," ")).split(" ");e=(e=e.map(e=>e.trim())).filter(e=>e&&""!==e&&"\n"!==e);var t=seoHelper.countSyllables(t),o=206.835-e.length/a.length*1.015-t/e.length*84.6;(o=o.toFixed(2))<0?o=0:100<o&&(o=100);var n="",l="";switch(!0){case isNaN(o):o=__("N/A"),n="",l="nok";break;case 90<o:n=__("Very easy to read","diagnoseo"),l="ok";break;case 80<o&&o<=90:n=__("Easy to read","diagnoseo"),l="ok";break;case 70<o&&o<=80:n=__("Fairly easy to read","diagnoseo"),l="ok";break;case 60<o&&o<=70:n=__("Average reading ease","diagnoseo"),l="nok medium-nok";break;case 50<o&&o<=60:n=__("Fairly difficult to read","diagnoseo"),l="nok";break;case 30<o&&o<=50:n=__("Difficult to read","diagnoseo"),l="nok";break;case 10<o&&o<=30:n=__("Very difficult to read","diagnoseo"),l="nok";break;case o<=10:n=__("Extremely difficult to read","diagnoseo"),l="nok"}return{value:o,comment:n=n&&` (${n})`,status:l}}},{id:"est-reading-time",type:"stats",label:__("Estimated reading time"),section:"content",order:"label value",test:e=>{var{postContent:t}=e,e=seoHelper.countWords(t),t=Math.floor(e/225),e=Math.floor(e%225/3.75);return{value:`${t} ${__("min")} ${e} ${__("s")}`}}},{id:"minimal-word-count",type:"check",label:__("Minimal word count"),section:"content",postTypes:["post","page"],inPro:!0},{id:"words",type:"stats",label:__("words"),section:"content",test:e=>{var{postContent:e}=e;return{value:seoHelper.countWords(e)}}},{id:"chars",type:"stats",label:__("characters"),section:"content",test:e=>({value:e.postContent.length||0})},{id:"sentences",type:"stats",label:__("sentences"),section:"content",test:e=>{var{postContent:e}=e,e=(e=e.replace(/(\r\n|\n|\r)/gm," ")).split(/\.|\?|!/);return{value:(e=(e=e.map(e=>e.trim())).filter(e=>e&&" "!==e&&"\n"!==e)).length||0}}},{id:"paragraphs",type:"stats",label:__("paragraphs"),section:"content",test:e=>({value:seoHelper.countElements(e.postContent,"p")})},{id:"headings",type:"stats",label:__("Headings"),inPro:!0,section:"content"},{id:"optimal-heading-number",type:"check",label:__("Optimal number of headings"),inPro:!0,section:"content"},{id:"images",type:"stats",label:__("Images"),inPro:!0,section:"content"},{id:"optimal-image-number",type:"check",label:__("Optimal number of images"),inPro:!0,section:"content"},{id:"too-long-headings",type:"check",label:__("No too long headings"),inPro:!0,section:"content"},{id:"toc-block",type:"check",label:__("Use Table of Contents block"),inPro:!0,section:"content"},{id:"keyword-exists",type:"check",label:__("Keyword is provided"),section:"keyword",test:e=>e.keyword?"ok":"nok"},{id:"keyword-unique",type:"check",label:__("Focus Keyword not used before"),section:"keyword",test:async a=>{var o=document.querySelector(".keyword-unique");if(a.keyword){let e=new URLSearchParams(window.location.search);var n=Object.fromEntries(e.entries()),n=`${diagnoseoRestUrl}diagnoseo/v1/check-posts-keyword/${a.keyword}/${n.post||0}`;let t=0===await(await fetch(n)).json()?"ok":"nok";o?o&&(o.classList.remove("ok","nok"),o.classList.add(t)):setTimeout(()=>{(o=document.querySelector(".keyword-unique"))&&(o.classList.remove("ok","nok"),o.classList.add(t))},200)}else o&&o.classList.add("ok")}},{id:"keyword-in-title",type:"check",label:__("Keyword present in title tag"),section:"keyword",test:e=>{var{keyword:t,postTitle:a,metaTitle:e}=e;return seoHelper.isKeywordInText(t,e||a)?"ok":"nok"}},{id:"keyword-in-title-beginning",type:"check",label:__("Keyword in the beginning of the title tag"),section:"keyword",test:e=>{var{keyword:t,postTitle:a,metaTitle:e}=e;if(!t)return"nok";a=(a=e||a).toLowerCase(),t=t.toLowerCase();const o=new RegExp("^"+t);return o.test(a)?"ok":"nok"}},{id:"keyword-in-descr",type:"check",label:__("Keyword present in meta description tag"),section:"keyword",test:e=>{var{keyword:t,metaDescription:e}=e;return seoHelper.isKeywordInText(t,e)?"ok":"nok"}},{id:"keyword-in-slug",type:"check",label:__("Keyword present in URL slug"),section:"keyword",test:e=>{var{keyword:t,slug:a,postTitle:e}=e;return t&&(a=a||seoHelper.slugify(e)).includes(seoHelper.slugify(t))?"ok":"nok"}},{id:"slug-length-ok",type:"check",label:__("URL slug length"),section:"keyword",test:e=>{var{slug:t,postTitle:e}=e;if(!t&&!e)return"nok";if((t=t||seoHelper.slugify(e)).length<=60&&t.split("-").length<=5)return"ok";return"nok"}},{id:"keyword-in-h1",type:"check",label:__("Keyword present in H1 element"),section:"keyword",test:e=>{var{keyword:t,postContent:a,postTitle:e}=e;return seoHelper.isKeywordInText(t,e)||seoHelper.isKeywordInAnyElement(t,a,"h1")?"ok":"nok"}},{id:"keyword-in-image-alt",type:"check",label:__("Keyword present in any image alt attribute"),section:"keyword",test:e=>{var{keyword:t,postContent:a,featuredImage:e}=e;return seoHelper.isKeywordInAnyAlt(t,a,e)?"ok":"nok"}},{id:"keyword-in-image-filename",type:"check",label:__("Keyword in image file name"),section:"keyword",inPro:!0,hidden:!0},{id:"keyword-not-in-ext-link",type:"check",label:__("Keyword NOT present in external link text"),section:"keyword",test:e=>{const{keyword:a,postContent:t}=e;if(!a)return"ok";const o=seoHelper.createMarkupEl(t);var n=!1;const l=o.querySelectorAll("a");return l.forEach(e=>{const t=e.getAttribute("href")||"";t.includes("http://"+window.location.hostname)||t.includes("https://"+window.location.hostname)||"/"===t.substr(0,1)||"./"===t.substr(0,2)||!seoHelper.isKeywordInText(a,e.textContent)||(n=!0)}),n?"nok":"ok"}},{id:"keyword-in-first-words",type:"check",label:__("Keyword present within first 100 words"),section:"keyword",test:e=>{var{keyword:t,postContent:e}=e;if(!t)return"nok";var t=t.trim(),a=(e=seoHelper.stripTags(e)).toLowerCase().split(/\s|\n/),o=100<=(a=a.filter(e=>e)).length?100:a.length;if(a=a.splice(0,o),!seoHelper.isKeywordInText(t,a.join(" ")))return"nok";if(1<t.split(" ").length)return"ok";if(a.length)for(let e=0;e<o;e++)a[e]=a[e].replace(".",""),a[e]=a[e].replace(",",""),a[e]=a[e].replace("?",""),a[e]=a[e].replace("!",""),a[e]=a[e].replace(":",""),a[e]=a[e].replace(";","");return a.includes(t)?"ok":"nok"}},{id:"more",type:"check",label:__("Many more powerful SEO checkpoints"),inPro:!0,section:"content"},{id:"more",type:"check",label:__("Many more powerful SEO checkpoints"),inPro:!0,section:"keyword"}],checkResults:{}}, function(){"use strict";function o(){return(0,d.createElement)("svg",{"enable-background":"new 0 0 20 20",height:"20",width:"20",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",className:"diagnoseo-icon"},(0,d.createElement)("clipPath",{id:"a"},(0,d.createElement)("path",{d:"m0 0h20v20h-20z"})),(0,d.createElement)("path",{className:"diagnoseo-icon-part-tick",d:"m12.377 5.866 1.835 1.612-4.839 5.508-4.11-3.576 1.672-1.902 2.256 1.982z"}),(0,d.createElement)("path",{className:"diagnoseo-icon-part-magnifier","clip-path":"url(#a)",d:"m16.298 15.209c1.745-1.983 2.548-4.603 2.208-7.228-.315-2.426-1.555-4.584-3.493-6.077s-4.341-2.139-6.768-1.828c-2.426.315-4.584 1.555-6.077 3.493s-2.142 4.341-1.827 6.767c.649 5.007 5.251 8.554 10.259 7.905 1.441-.188 2.824-.717 4.014-1.536l3.749 3.295 1.476-1.68zm-1.471-1.887c-1.111 1.443-2.72 2.368-4.527 2.602-1.808.235-3.598-.247-5.041-1.361-1.444-1.111-2.368-2.719-2.602-4.527-.483-3.73 2.158-7.158 5.889-7.642.296-.038.59-.057.881-.057 3.375 0 6.316 2.511 6.761 5.946.235 1.806-.249 3.596-1.361 5.039"}))}var d=window.wp.element,e=window.wp.plugins;class t extends React.Component{constructor(e){super(e),this.state={score:0,timeout:null},this.handleCheckChanged=this.handleCheckChanged.bind(this),this.calculateScore=this.calculateScore.bind(this),this.runAllChecks=this.runAllChecks.bind(this)}calculateScore(){const e=window.diagnoseo.checks.filter(e=>"check"===e.type);var t=e.length+1,a=e.filter(e=>e.checked),a=window.diagnoseo.additionalKeywordCount===window.diagnoseo.RelatedKeywordsInPost?a.length+1:a.length,t=Math.round(100*a/t);this.setState({score:t})}runAllChecks(){const{select:e}=window.wp.data,t=window.diagnoseo.checks.filter(e=>"check"===e.type),n={postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,featuredImageId:e("core/editor").getEditedPostAttribute("featured_media"),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,slug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks()};var a;!n.featuredImageId||n.featuredImage?(n.metaTitle=seoHelper.replaceVariables(n.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),n.metaDescription=seoHelper.replaceVariables(n.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),t.forEach((t,e)=>{var a,o;t.test&&(a="ok"===t.test(n),o=window.diagnoseo.checks.findIndex(e=>e.id===t.id),window.diagnoseo.checks[o].checked=a)}),this.calculateScore()):a=setInterval(()=>{e("core").getMedia(n.featuredImageId)&&(clearInterval(a),this.runAllChecks())},500)}handleCheckChanged(){clearTimeout(this.state.timeout),this.setState({timeout:setTimeout(this.calculateScore,300)})}async componentDidMount(){window.addEventListener("check-changed",this.handleCheckChanged),setTimeout(this.runAllChecks,1e3)}componentWillUnmount(){window.removeEventListener("check-changed",this.handleCheckChanged)}render(){let e,t=this.state.score;switch(!0){case t<60:e="score-low";break;case 60<=t&&t<80:e="score-medium";break;case 80<=t:e="score-high"}var a=`diagnoseo-button-content ${e}`;return(0,d.createElement)("span",{className:a},(0,d.createElement)(o,null),(0,d.createElement)("b",{className:"diagnoseo-score"},this.state.score,"/100"))}whenEditorIsReady(){return new Promise(e=>{const t=subscribe(()=>{(select("core/editor").isCleanNewPost()||0<select("core/block-editor").getBlockCount())&&(t(),e())})})}}var a=t,n=window.wp.editor,u=window.wp.components,l=window.wp.data,p=window.wp.i18n,r=window.wp.compose,i=(0,r.compose)((0,l.withDispatch)((a,o)=>({setMetaValue:e=>{var t={};t[o.fieldName]=e,a("core/editor").editPost({meta:t}),o.changeCallback&&o.changeCallback(e)}})),(0,l.withSelect)((e,t)=>({metaValue:e("core/editor").getEditedPostAttribute("meta")[t.fieldName]})))(t=>(0,d.createElement)(u.TextControl,{label:t.label,value:t.metaValue,onChange:e=>t.setMetaValue(e)})),s=(0,r.compose)((0,l.withSelect)(e=>({content:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword})))(e=>{var t,a,o=0;e.keyword&&(a=(a=(t=(t=(t=e.content.replace(/<\!--.*?-->/g,"")).replace(/(\r\n|\n|\r)/gm," ")).toLowerCase()).split(" ")).filter(e=>""!==e),(t=seoHelper.countOccurences(e.keyword,t))&&(o=t/a.length*100,o=parseFloat(o.toFixed(2))));let n;return n=window.diagnoseoPro?(a="diagnoseo-check optimal-keyword-density",(0,d.createElement)("p",{className:a+=1<=o&&o<=3?" ok":" nok"},(0,p.__)("Optimal keyword density","diagnoseo")," ",(0,d.createElement)("b",{className:"value"},"1% - 3%"))):(0,d.createElement)("p",{className:"diagnoseo-check optimal-keyword-density"},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",(0,p.__)("Optimal keyword density","diagnoseo")),(0,d.createElement)(d.Fragment,null,(0,d.createElement)("p",{className:"diagnoseo-stats keyword-density"},(0,p.__)("Keyword density","diagnoseo")," ",(0,d.createElement)("b",{className:"value"},o,"%")),n)}),c=t=>{let e=["diagnoseo-check",t.id];var a;if(t.test&&("string"==typeof(a=t.test(t.postData))&&e.push(a),o="ok"===a,a=t.checkConfig.findIndex(e=>e.id===t.id),t.checkConfig[a].checked!==o&&window.dispatchEvent(new Event("check-changed")),t.checkConfig[a].checked=o),t.inPro)return(0,d.createElement)("p",{className:e.join(" ")},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))));var o=t.valueFieldName&&t.postData[t.valueFieldName]?(0,d.createElement)("b",null,t.postData[t.valueFieldName]):"";return(0,d.createElement)("p",{className:e.join(" ")},t.label," ",o)},m=e=>{let t=["diagnoseo-stats",e.id];if(e.inPro)return(0,d.createElement)("p",{className:t.join(" ")},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",e.label," ",(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))));let a,o=(0,d.createElement)("b",{className:"value"}),n="";var l;return e.test&&(l=e.test(e.postData),o=(0,d.createElement)("b",{className:"value"},l.value),n=l.comment?(0,d.createElement)("span",{className:"comment"},l.comment):"",l.status&&t.push(l.status)),a=e.order&&"value label"!==e.order?(0,d.createElement)(d.Fragment,null,e.label," ",o," ",n):(0,d.createElement)(d.Fragment,null,o," ",e.label),(0,d.createElement)("p",{className:t.join(" ")},a)},g=(0,r.compose)((0,l.withSelect)(e=>({postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,urlSlug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks(),optimalKeywordDensity:2,optimalWordNumber:300,optimalHeadingNumber:1,optimalImageNumber:1,postType:e("core/editor").getCurrentPostType()})))(a=>{const o=window.diagnoseo.checks,e=o.filter(e=>e.section===a.sectionName),n={postTitle:a.postTitle,postContent:a.postContent,keyword:a.keyword,metaTitle:seoHelper.replaceVariables(a.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),metaDescription:seoHelper.replaceVariables(a.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),slug:a.urlSlug,blocks:a.blocks,featuredImage:a.featuredImage,optimalKeywordDensity:a.optimalKeywordDensity,optimalWordNumber:a.optimalWordNumber,optimalHeadingNumber:a.optimalHeadingNumber,optimalImageNumber:a.optimalImageNumber},t=e.map(e=>{let t=!0;if(e.postTypes&&(t=e.postTypes.includes(a.postType)),!e.hidden&&t)switch(e.type){case"check":return e.inPro?(0,d.createElement)(c,{id:e.id,label:e.label,inPro:e.inPro}):(0,d.createElement)(c,{id:e.id,label:e.label,test:e.test,postData:n,checkConfig:o,valueFieldName:e.valueFieldName});case"stats":return e.inPro?(0,d.createElement)(m,{id:e.id,label:e.label,inPro:e.inPro}):(0,d.createElement)(m,{id:e.id,label:e.label,test:e.test,order:e.order,postData:n})}});return(0,d.createElement)(d.Fragment,null,t.map((e,t)=>(0,d.createElement)(React.Fragment,{key:t},e)))});class h extends React.Component{constructor(e){super(e),this.state={keyword:"",keywordList:[],keywordLimit:(window.diagnoseoPro||window.diagnoseo).additionalKeywordLimit,apiKey:"",language:diagnoseo_settings?diagnoseo_settings.locale.substr(0,2):"",loading:!1},this.handleChange=this.handleChange.bind(this),this.handleLangChange=this.handleLangChange.bind(this),this.handleLoadButtonClick=this.handleLoadButtonClick.bind(this),this.relatedKeywordsApiUrl="diagnoseo/v1/related-keywords"}stripKeywordData(e){return(e=-1===e.indexOf("|")?e:e.substr(0,e.indexOf(" |"))).trim()}async loadRelatedKeywords(){var t=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,a=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;if(t)if(this.state.language){this.setState({loading:!0});let e=await this.getRelatedKeywords(t,a);if(e.length){let a=this.state.keywordList;e.forEach(t=>{t={name:t.trim()};var e=a.findIndex(e=>e.name===t);-1===e?a.push(t):(a[e].repeat_min=t.repeat_min,a[e].repeat_max=t.repeat_max)}),this.saveKeywords(a)}this.setState({loading:!1})}else alert((0,p.__)("Please select language.","diagnoseo"));else alert((0,p.__)('Please enter the "focus keyword" first',"diagnoseo"))}saveKeywords(e){const t=[...new Set(e)];t.splice(this.state.keywordLimit),this.setState({keywordList:t}),(window.onbeforeunload=null,l.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_additional_keywords:JSON.stringify(t)}})}saveLanguage(e){(0,l.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_language:e}})}componentDidMount(){let e=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_additional_keywords,t=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;try{e=JSON.parse(e)}catch{e=""}this.setState({language:t,keyword:this.props.focusKeyword,keywordList:e||[]})}async handleLoadButtonClick(){window.diagnoseoPro?this.loadRelatedKeywords():alert((0,p.__)("Related keywords and Pro data require DiagnoSEO Pro.","diagnoseo"))}handleChange(e){const o=this.state.keywordList,{stripKeywordData:n}=this;e=e.map(e=>{let t=n(e.value||e),a=o.findIndex(e=>t===e.name);return{name:t,repeat_min:-1!==a?o[a].repeat_min:0,repeat_max:-1!==a?o[a].repeat_max:0}});this.saveKeywords(e)}handleLangChange(e){this.setState({language:e}),this.saveLanguage(e)}render(){let{postTitle:l,postContent:r,featuredMedia:i}=this.props;const{countOccurences:s}=seoHelper;let c=0,e=this.state.keywordList.map(e=>{let t=e.name||"",a="error",o=function(e){r=seoHelper.stripTags(r);var t=0;return t+=s(e,l),t+=s(e,r),t+=seoHelper.isKeywordInAnyAlt(e,r),t+=i?s(e,i.alt_text):0}(t);o&&(a=!e.repeat_min||!e.repeat_max||o>=e.repeat_min&&o<=e.repeat_max?"success":"validating",c++);let n=` | ${o}`;return e.repeat_min&&e.repeat_max&&(n+=` (${e.repeat_min} - ${e.repeat_max})`),{value:t+n,status:a}}),t=!1;window.diagnoseo.RelatedKeywordsInPost!==c&&(window.diagnoseo.RelatedKeywordsInPost=c,t=!0),window.diagnoseo.additionalKeywordCount!==e.length&&(window.diagnoseo.additionalKeywordCount=e.length,t=!0),t&&window.dispatchEvent(new Event("check-changed"));var a=this.state.loading?(0,p.__)("Please wait... Loading related keywords. It can take up to a few minutes.","diagnoseo"):(0,d.createElement)("button",{className:"button get-related-keywords",onClick:this.handleLoadButtonClick},(0,p.__)("Get related keywords","diagnoseo"));return(0,d.createElement)(d.Fragment,null,(0,d.createElement)("div",{className:"components-base-control__field add-keyword diagnoseo-related-keywords"},(0,d.createElement)(u.FormTokenField,{label:(0,d.createElement)("b",null,(0,p.__)("Related keywords","diagnoseo")),onChange:this.handleChange,value:e,maxLength:this.state.keywordLimit+10}),(0,d.createElement)("p",{className:"components-form-token-field__help"},(0,p.__)("Limits: 10 keywords in free, 100 keywords in Pro","diagnoseo")),(0,d.createElement)(u.SelectControl,{options:[{value:"",label:"Choose language"},{value:"albanian",label:"Albanian"},{value:"arabic",label:"Arabic"},{value:"armenian",label:"Armenian"},{value:"awadhi",label:"Awadhi"},{value:"azerbaijani",label:"Azerbaijani"},{value:"bashkir",label:"Bashkir"},{value:"basque",label:"Basque"},{value:"belarusian",label:"Belarusian"},{value:"bengali",label:"Bengali"},{value:"bhojpuri",label:"Bhojpuri"},{value:"bosnian",label:"Bosnian"},{value:"brazilian Portuguese",label:"Brazilian Portuguese"},{value:"bulgarian",label:"Bulgarian"},{value:"cantonese (Yue)",label:"Cantonese (Yue)"},{value:"catalan",label:"Catalan"},{value:"chhattisgarhi",label:"Chhattisgarhi"},{value:"chinese",label:"Chinese"},{value:"croatian",label:"Croatian"},{value:"czech",label:"Czech"},{value:"danish",label:"Danish"},{value:"dogri",label:"Dogri"},{value:"dutch",label:"Dutch"},{value:"english",label:"English"},{value:"estonian",label:"Estonian"},{value:"faroese",label:"Faroese"},{value:"finnish",label:"Finnish"},{value:"french",label:"French"},{value:"galician",label:"Galician"},{value:"georgian",label:"Georgian"},{value:"german",label:"German"},{value:"greek",label:"Greek"},{value:"gujarati",label:"Gujarati"},{value:"haryanvi",label:"Haryanvi"},{value:"hindi",label:"Hindi"},{value:"hungarian",label:"Hungarian"},{value:"indonesian",label:"Indonesian"},{value:"irish",label:"Irish"},{value:"italian",label:"Italian"},{value:"japanese",label:"Japanese"},{value:"javanese",label:"Javanese"},{value:"kannada",label:"Kannada"},{value:"kashmiri",label:"Kashmiri"},{value:"kazakh",label:"Kazakh"},{value:"konkani",label:"Konkani"},{value:"korean",label:"Korean"},{value:"kyrgyz",label:"Kyrgyz"},{value:"latvian",label:"Latvian"},{value:"lithuanian",label:"Lithuanian"},{value:"macedonian",label:"Macedonian"},{value:"maithili",label:"Maithili"},{value:"malay",label:"Malay"},{value:"maltese",label:"Maltese"},{value:"mandarin",label:"Mandarin"},{value:"mandarin Chinese",label:"Mandarin Chinese"},{value:"marathi",label:"Marathi"},{value:"marwari",label:"Marwari"},{value:"min Nan",label:"Min Nan"},{value:"moldovan",label:"Moldovan"},{value:"mongolian",label:"Mongolian"},{value:"montenegrin",label:"Montenegrin"},{value:"nepali",label:"Nepali"},{value:"norwegian",label:"Norwegian"},{value:"oriya",label:"Oriya"},{value:"pashto",label:"Pashto"},{value:"persian",label:"Persian"},{value:"polish",label:"Polish"},{value:"portuguese",label:"Portuguese"},{value:"punjabi",label:"Punjabi"},{value:"rajasthani",label:"Rajasthani"},{value:"romanian",label:"Romanian"},{value:"russian",label:"Russian"},{value:"sanskrit",label:"Sanskrit"},{value:"santali",label:"Santali"},{value:"serbian",label:"Serbian"},{value:"sindhi",label:"Sindhi"},{value:"sinhala",label:"Sinhala"},{value:"slovak",label:"Slovak"},{value:"slovene",label:"Slovene"},{value:"slovenian",label:"Slovenian"},{value:"spanish",label:"Spanish"},{value:"swahili",label:"Swahili"},{value:"swedish",label:"Swedish"},{value:"tajik",label:"Tajik"},{value:"tamil",label:"Tamil"},{value:"tatar",label:"Tatar"},{value:"telugu",label:"Telugu"},{value:"thai",label:"Thai"},{value:"turkish",label:"Turkish"},{value:"turkmen",label:"Turkmen"},{value:"ukrainian",label:"Ukrainian"},{value:"urdu",label:"Urdu"},{value:"uzbek",label:"Uzbek"},{value:"vietnamese",label:"Vietnamese"},{value:"welsh",label:"Welsh"},{value:"wu",label:"Wu"}],value:this.state.language,onChange:this.handleLangChange,label:(0,p.__)("Language","diagnoseo")}),(0,d.createElement)("p",null,a)))}getRelatedKeywords(a,o){return new Promise(t=>{const e=new FormData;e.append("keyword",a),e.append("language",o),e.append("count",30),fetch("/wp-json/diagnoseo/v1/related-keywords",{method:"POST",body:e}).then(e=>e.json()).then(e=>{"ok"===e.status?t(e.keywords.split(",")):t([])}).catch(e=>{console.error(e),t([])})})}}var k=(0,r.compose)((0,l.withSelect)(e=>{var t=e("core/editor").getEditedPostAttribute("featured_media");return{postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredMedia:e("core").getMedia(t,{context:"embed"})||{}}}))(e=>(0,d.createElement)(h,{postTitle:e.postTitle,postContent:e.postContent,featuredMedia:e.featuredMedia,seoDataCollector:e.seoDataCollector})),w=(0,r.compose)((0,l.withSelect)(e=>{if(!window.diagnoseoPro)return{};e={categories:e("core/editor").getEditedPostAttribute("categories"),status:"publish",per_page:10,exclude:[e("core/editor").getEditedPostAttribute("id")]};return{suggestedPosts:wp.data.select("core").getEntityRecords("postType","post",e)||[]}}))(e=>{if(window.diagnoseoPro){var t="";return t=e.suggestedPosts.length?(t=e.suggestedPosts.map(e=>(0,d.createElement)("li",null,(0,d.createElement)("a",{href:e.link},e.title.raw))),(0,d.createElement)("ol",null,t)):(0,d.createElement)("p",null,(0,p.__)("Could not prepare suggestions as there are no posts related to this one"))}return(0,d.createElement)("p",null,(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))))}),r=(0,r.compose)((0,l.withDispatch)(t=>({setMetaValues:e=>{t("core/editor").editPost({meta:{}})}})))(e=>{var t=window.diagnoseoPro?"DiagnoSEO Pro":"DiagnoSEO";return(0,d.createElement)(d.Fragment,null,(0,d.createElement)(n.PluginSidebarMoreMenuItem,{target:"diagnoseo-content-analyzer"},(0,p.__)("DiagnoSEO Content Watcher","diagnoseo")),(0,d.createElement)(n.PluginSidebar,{title:t,name:"diagnoseo-content-analyzer"},(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Content analyzer","diagnoseo"),initialOpen:"true"},(0,d.createElement)(g,{sectionName:"content"})),(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Keyword placement","diagnoseo"),initialOpen:"true"},(0,d.createElement)(i,{fieldName:"diagnoseo_meta_keyword",label:(0,d.createElement)("b",null,(0,p.__)("Focus keyword","diagnoseo"))}),(0,d.createElement)(s,null),(0,d.createElement)(k,{seoDataCollector:e.setMetaValues}),(0,d.createElement)(g,{sectionName:"keyword"})),(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Internal linking suggestions","diagnoseo"),initialOpen:"true"},(0,d.createElement)(w,null))))});(0,e.registerPlugin)("diagnoseo-sidebar",{icon:(0,d.createElement)(a,null),render:r})}(),document.addEventListener("DOMContentLoaded",function(){"use strict";const e=document.querySelectorAll(".meta-template");e.forEach(e=>{const n=e.querySelector(".choose-variable"),t=e.querySelector(".add-variable"),l=e.querySelector("input, textarea");t&&t.addEventListener("click",e=>{e.preventDefault();var t,a,o=n.value;l.selectionStart||"0"==l.selectionStart?(t=l.selectionStart,a=l.selectionEnd,e=parseInt(t)?" ":"",l.value=l.value.substring(0,t)+e+o+l.value.substring(a,l.value.length)):l.value+=o,l.dispatchEvent(new Event("input"))})});const t=document.querySelectorAll(".diagnoseo-generator-button-free");t&&t.forEach(e=>{e.addEventListener("click",e=>{e.preventDefault(),alert("This feature requires DiagnoSEO Pro")})})}),window.seoHelper={slugify:function(e){e=(e=e.replace(/^\s+|\s+$/g,"")).toLowerCase();for(var t="àáãäâąèéëêęìíïîóòóöôùúüûñńśçćźżł·/_,:;",a=0,o=t.length;a<o;a++)e=e.replace(new RegExp(t.charAt(a),"g"),"aaaaaaeeeeeiiiiooooouuuunnscczzl------".charAt(a));return e=e.replace(/[^a-z0-9 -]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-")},countOccurences:function(e,t){if(!t||!e)return 0;t=t.toLowerCase().replaceAll(/[:;,.!?—]/g,""),e=e.toLowerCase();e=new RegExp(e,"g");return(t.match(e)||[]).length},countSyllables:function(e){if(""===e)return 0;if(e.length<=3)return 1;e=(e=(e=(e=e.toLowerCase()).replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/,"")).replace(/^y/,"")).match(/[aeiouy]{1,2}/g);return e?e.length:0},countWords:function(e){e=(e=(e=e.replace(/(\r\n|\n|\r)/gm," ")).replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g," ")).split(" ");return(e=(e=e.map(e=>e.trim())).filter(e=>e&&""!==e&&"\n"!==e)).length||0},countElements:function(e,t){if(!e||!t)return 0;const a=document.createElement("div");return a.innerHTML=e,a.querySelectorAll(t).length},replaceVariables:function(e){if(e){var{site:t,siteTagline:a,separator:o,excerpt:n,postTitle:l}=document.querySelector(".diagnoseo-preview").dataset;return e=(e=(e=(e=(e=(e=(e=(e=e.replaceAll("%title%",document.body.classList.contains("block-editor-page")?window.wp.data.select("core/editor").getEditedPostAttribute("title"):l)).replaceAll("%sitename%",t)).replaceAll("%tagline%",a)).replaceAll("%sep%",o)).replaceAll("%page%"," ")).replaceAll("%excerpt%",n)).replaceAll("%currentyear%",(new Date).getFullYear())).replaceAll("%currentmonth%",(new Date).toLocaleString("default",{month:"long"}))}},isKeywordInText:function(e,t){if(!e||!t)return!1;e=e.toLowerCase();let a=(t=t.toLowerCase()).toLowerCase().replaceAll(/[:;,.!?-]/g,"");return t.includes(e)||a.includes(e)},isKeywordInAnyElement:function(t,e,a){if(!t||!e||!a)return!1;var o=!1;const n=seoHelper.createMarkupEl(e);return elements=n.querySelectorAll(a),elements.forEach(e=>{seoHelper.isKeywordInText(t,e.textContent)&&(o=!0)}),o},isKeywordInAnyAlt:function(t,e,a=null){if(!t)return!1;if(a&&seoHelper.isKeywordInText(t,a.alt_text))return!0;var o=0;const n=seoHelper.createMarkupEl(e),l=n.querySelectorAll("img");return l.forEach(e=>{e=e.getAttribute("alt").toLowerCase();o+=seoHelper.countOccurences(t,e)}),o},createMarkupEl:function(e){const t=document.createElement("div");return t.innerHTML=e,t},stripTags:function(e){return e.replace(/(<([^>]+)>)/gi,"")}};1 const{__}=window.wp.i18n;window.diagnoseo={additionalKeywordLimit:10,additionalKeywordCount:0,RelatedKeywordsInPost:0,checks:[{id:"title-not-too-long",type:"check",label:__("Title not too long"),section:"content",test:e=>{var{metaTitle:t,postTitle:e}=e;if(!t&&!e)return"nok";t=t||e;const a=document.querySelector(".title-sample");a.textContent=t;e=a.clientWidth,t=t.length;return e<=600?60<t?"nok medium-nok":t<=60?"ok":"nok":"nok"}},{id:"title-not-too-short",type:"check",label:__("Title not too short"),section:"content",test:e=>{var{metaTitle:t,postTitle:e}=e;if(!t&&!e)return"nok";e=(t||e).length;return 30<=e?30<=e&&e<35?"nok medium-nok":35<=e?"ok":"nok":"nok"}},{id:"description-not-too-long",type:"check",label:__("Description not too long"),section:"content",test:e=>{var{metaDescription:t}=e;if(!t)return"nok";e=document.querySelector(".description-sample"),t=t.length;if(e.clientWidth<=990){if(155<t)return"nok medium-nok";if(t<=155)return"ok"}return"nok"}},{id:"description-not-too-short",type:"check",label:__("Description not too short"),section:"content",test:e=>{var{metaDescription:e}=e;if(!e)return"nok";e=e.length;if(70<=e){if(e<130)return"nok medium-nok";if(130<=e)return"ok"}return"nok"}},{id:"too-long-sentences",type:"check",label:__("No sentences with more than 20 words"),section:"content",test:e=>{var{postContent:e}=e;e=(e=(e=(e=(e=(e=(e=(e=e.replaceAll("</p>",".</p>")).replaceAll("</h1>",".</h1>")).replaceAll("</h2>",".</h2>")).replaceAll("</h3>",".</h3>")).replaceAll("</h4>",".</h4>")).replaceAll("</h5>",".</h5>")).replaceAll("</h6>",".</h6>")).replaceAll("</li>",".</li>");const t=(e=seoHelper.stripTags(e)).split(/\.|\?|!/);var a=!1;return t.length&&t.forEach(e=>{a=a||20<seoHelper.countWords(e)}),a?"nok":"ok"}},{id:"too-many-words",type:"check",label:__("No paragraphs with more than 100 words"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("p");var o=!1;return a.length&&a.forEach(e=>{100<seoHelper.countWords(e.textContent)&&(o=!0)}),o?"nok":"ok"}},{id:"too-many-sentences",type:"check",label:__("No paragraphs with more than 5 sentences"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("p");var o=!1;return a.length&&a.forEach(e=>{5<e.textContent.split(/\.|\?|!/).filter(e=>!!e.trim()).length&&(o=!0)}),o?"nok":"ok"}},{id:"internal-links-present",type:"check",label:__("Contains internal links"),section:"content",test:e=>{const t=seoHelper.createMarkupEl(e.postContent),a=t.querySelectorAll("a");var o=!1;return a.forEach(e=>{e=e.getAttribute("href")||"";e&&(e.includes("http://"+window.location.hostname)||e.includes("https://"+window.location.hostname)||"/"===e.substr(0,1)||"./"===e.substr(0,2))&&(o=!0)}),o?"ok":"nok"}},{id:"strong-present",type:"check",label:__("Contains bold text (strong tag)"),section:"content",test:e=>seoHelper.countElements(e.postContent,"strong")?"ok":"nok"},{id:"readability",type:"stats",label:__("Readability score"),order:"label value comment",section:"content",test:e=>{var{postContent:t}=e,a=(t=seoHelper.stripTags(t)).split(/\.|\?|!/);a=(a=a.map(e=>e.trim())).filter(e=>e&&" "!==e&&"\n"!==e);e=(t=t.replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g," ")).split(" ");e=(e=e.map(e=>e.trim())).filter(e=>e&&""!==e&&"\n"!==e);var t=seoHelper.countSyllables(t),o=206.835-e.length/a.length*1.015-t/e.length*84.6;(o=o.toFixed(2))<0?o=0:100<o&&(o=100);var n="",l="";switch(!0){case isNaN(o):o=__("N/A"),n="",l="nok";break;case 90<o:n=__("Very easy to read","diagnoseo"),l="ok";break;case 80<o&&o<=90:n=__("Easy to read","diagnoseo"),l="ok";break;case 70<o&&o<=80:n=__("Fairly easy to read","diagnoseo"),l="ok";break;case 60<o&&o<=70:n=__("Average reading ease","diagnoseo"),l="nok medium-nok";break;case 50<o&&o<=60:n=__("Fairly difficult to read","diagnoseo"),l="nok";break;case 30<o&&o<=50:n=__("Difficult to read","diagnoseo"),l="nok";break;case 10<o&&o<=30:n=__("Very difficult to read","diagnoseo"),l="nok";break;case o<=10:n=__("Extremely difficult to read","diagnoseo"),l="nok"}return{value:o,comment:n=n&&` (${n})`,status:l}}},{id:"est-reading-time",type:"stats",label:__("Estimated reading time"),section:"content",order:"label value",test:e=>{var{postContent:t}=e,e=seoHelper.countWords(t),t=Math.floor(e/225),e=Math.floor(e%225/3.75);return{value:`${t} ${__("min")} ${e} ${__("s")}`}}},{id:"minimal-word-count",type:"check",label:__("Minimal word count"),section:"content",postTypes:["post","page"],inPro:!0},{id:"words",type:"stats",label:__("words"),section:"content",test:e=>{var{postContent:e}=e;return{value:seoHelper.countWords(e)}}},{id:"chars",type:"stats",label:__("characters"),section:"content",test:e=>({value:e.postContent.length||0})},{id:"sentences",type:"stats",label:__("sentences"),section:"content",test:e=>{var{postContent:e}=e,e=(e=e.replace(/(\r\n|\n|\r)/gm," ")).split(/\.|\?|!/);return{value:(e=(e=e.map(e=>e.trim())).filter(e=>e&&" "!==e&&"\n"!==e)).length||0}}},{id:"paragraphs",type:"stats",label:__("paragraphs"),section:"content",test:e=>({value:seoHelper.countElements(e.postContent,"p")})},{id:"headings",type:"stats",label:__("Headings"),inPro:!0,section:"content"},{id:"optimal-heading-number",type:"check",label:__("Optimal number of headings"),inPro:!0,section:"content"},{id:"images",type:"stats",label:__("Images"),inPro:!0,section:"content"},{id:"optimal-image-number",type:"check",label:__("Optimal number of images"),inPro:!0,section:"content"},{id:"too-long-headings",type:"check",label:__("No too long headings"),inPro:!0,section:"content"},{id:"toc-block",type:"check",label:__("Use Table of Contents block"),inPro:!0,section:"content"},{id:"keyword-exists",type:"check",label:__("Keyword is provided"),section:"keyword",test:e=>e.keyword?"ok":"nok"},{id:"keyword-unique",type:"check",label:__("Focus Keyword not used before"),section:"keyword",test:async a=>{var o=document.querySelector(".keyword-unique");if(a.keyword){let e=new URLSearchParams(window.location.search);var n=Object.fromEntries(e.entries()),n=`${diagnoseoRestUrl}diagnoseo/v1/check-posts-keyword/${a.keyword}/${n.post||0}`;let t=0===await(await fetch(n)).json()?"ok":"nok";o?o&&(o.classList.remove("ok","nok"),o.classList.add(t)):setTimeout(()=>{(o=document.querySelector(".keyword-unique"))&&(o.classList.remove("ok","nok"),o.classList.add(t))},200)}else o&&o.classList.add("ok")}},{id:"keyword-in-title",type:"check",label:__("Keyword present in title tag"),section:"keyword",test:e=>{var{keyword:t,postTitle:a,metaTitle:e}=e;return seoHelper.isKeywordInText(t,e||a)?"ok":"nok"}},{id:"keyword-in-title-beginning",type:"check",label:__("Keyword in the beginning of the title tag"),section:"keyword",test:e=>{var{keyword:t,postTitle:a,metaTitle:e}=e;if(!t)return"nok";a=(a=e||a).toLowerCase(),t=t.toLowerCase();const o=new RegExp("^"+t);return o.test(a)?"ok":"nok"}},{id:"keyword-in-descr",type:"check",label:__("Keyword present in meta description tag"),section:"keyword",test:e=>{var{keyword:t,metaDescription:e}=e;return seoHelper.isKeywordInText(t,e)?"ok":"nok"}},{id:"keyword-in-slug",type:"check",label:__("Keyword present in URL slug"),section:"keyword",test:e=>{var{keyword:t,slug:a,postTitle:e}=e;return t&&(a=a||seoHelper.slugify(e)).includes(seoHelper.slugify(t))?"ok":"nok"}},{id:"slug-length-ok",type:"check",label:__("URL slug length"),section:"keyword",test:e=>{var{slug:t,postTitle:e}=e;if(!t&&!e)return"nok";if((t=t||seoHelper.slugify(e)).length<=60&&t.split("-").length<=5)return"ok";return"nok"}},{id:"keyword-in-h1",type:"check",label:__("Keyword present in H1 element"),section:"keyword",test:e=>{var{keyword:t,postContent:a,postTitle:e}=e;return seoHelper.isKeywordInText(t,e)||seoHelper.isKeywordInAnyElement(t,a,"h1")?"ok":"nok"}},{id:"keyword-in-image-alt",type:"check",label:__("Keyword present in any image alt attribute"),section:"keyword",test:e=>{var{keyword:t,postContent:a,featuredImage:e}=e;return seoHelper.isKeywordInAnyAlt(t,a,e)?"ok":"nok"}},{id:"keyword-in-image-filename",type:"check",label:__("Keyword in image file name"),section:"keyword",inPro:!0,hidden:!0},{id:"keyword-not-in-ext-link",type:"check",label:__("Keyword NOT present in external link text"),section:"keyword",test:e=>{const{keyword:a,postContent:t}=e;if(!a)return"ok";const o=seoHelper.createMarkupEl(t);var n=!1;const l=o.querySelectorAll("a");return l.forEach(e=>{const t=e.getAttribute("href")||"";t.includes("http://"+window.location.hostname)||t.includes("https://"+window.location.hostname)||"/"===t.substr(0,1)||"./"===t.substr(0,2)||!seoHelper.isKeywordInText(a,e.textContent)||(n=!0)}),n?"nok":"ok"}},{id:"keyword-in-first-words",type:"check",label:__("Keyword present within first 100 words"),section:"keyword",test:e=>{var{keyword:t,postContent:e}=e;if(!t)return"nok";var t=t.trim(),a=(e=seoHelper.stripTags(e)).toLowerCase().split(/\s|\n/),o=100<=(a=a.filter(e=>e)).length?100:a.length;if(a=a.splice(0,o),!seoHelper.isKeywordInText(t,a.join(" ")))return"nok";if(1<t.split(" ").length)return"ok";if(a.length)for(let e=0;e<o;e++)a[e]=a[e].replace(".",""),a[e]=a[e].replace(",",""),a[e]=a[e].replace("?",""),a[e]=a[e].replace("!",""),a[e]=a[e].replace(":",""),a[e]=a[e].replace(";","");return a.includes(t)?"ok":"nok"}},{id:"more",type:"check",label:__("Many more powerful SEO checkpoints"),inPro:!0,section:"content"},{id:"more",type:"check",label:__("Many more powerful SEO checkpoints"),inPro:!0,section:"keyword"}],checkResults:{}},(()=>{"use strict";const d=window.wp.element,e=window.wp.plugins,o=function(){return(0,d.createElement)("svg",{"enable-background":"new 0 0 20 20",height:"20",width:"20",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",className:"diagnoseo-icon"},(0,d.createElement)("clipPath",{id:"a"},(0,d.createElement)("path",{d:"m0 0h20v20h-20z"})),(0,d.createElement)("path",{className:"diagnoseo-icon-part-tick",d:"m12.377 5.866 1.835 1.612-4.839 5.508-4.11-3.576 1.672-1.902 2.256 1.982z"}),(0,d.createElement)("path",{className:"diagnoseo-icon-part-magnifier","clip-path":"url(#a)",d:"m16.298 15.209c1.745-1.983 2.548-4.603 2.208-7.228-.315-2.426-1.555-4.584-3.493-6.077s-4.341-2.139-6.768-1.828c-2.426.315-4.584 1.555-6.077 3.493s-2.142 4.341-1.827 6.767c.649 5.007 5.251 8.554 10.259 7.905 1.441-.188 2.824-.717 4.014-1.536l3.749 3.295 1.476-1.68zm-1.471-1.887c-1.111 1.443-2.72 2.368-4.527 2.602-1.808.235-3.598-.247-5.041-1.361-1.444-1.111-2.368-2.719-2.602-4.527-.483-3.73 2.158-7.158 5.889-7.642.296-.038.59-.057.881-.057 3.375 0 6.316 2.511 6.761 5.946.235 1.806-.249 3.596-1.361 5.039"}))};class t extends React.Component{constructor(e){super(e),this.state={score:0,timeout:null},this.handleCheckChanged=this.handleCheckChanged.bind(this),this.calculateScore=this.calculateScore.bind(this),this.runAllChecks=this.runAllChecks.bind(this)}calculateScore(){const e=window.diagnoseo.checks.filter(e=>"check"===e.type);var t=e.length+1,a=e.filter(e=>e.checked),a=window.diagnoseo.additionalKeywordCount===window.diagnoseo.RelatedKeywordsInPost?a.length+1:a.length,t=Math.round(100*a/t);this.setState({score:t})}runAllChecks(){const{select:e}=window.wp.data,t=window.diagnoseo.checks.filter(e=>"check"===e.type),n={postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,featuredImageId:e("core/editor").getEditedPostAttribute("featured_media"),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,slug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks()};var a;!n.featuredImageId||n.featuredImage?(n.metaTitle=seoHelper.replaceVariables(n.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),n.metaDescription=seoHelper.replaceVariables(n.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),t.forEach((t,e)=>{var a,o;t.test&&(a="ok"===t.test(n),o=window.diagnoseo.checks.findIndex(e=>e.id===t.id),window.diagnoseo.checks[o].checked=a)}),this.calculateScore()):a=setInterval(()=>{e("core").getMedia(n.featuredImageId)&&(clearInterval(a),this.runAllChecks())},500)}handleCheckChanged(){clearTimeout(this.state.timeout),this.setState({timeout:setTimeout(this.calculateScore,300)})}async componentDidMount(){window.addEventListener("check-changed",this.handleCheckChanged),setTimeout(this.runAllChecks,1e3)}componentWillUnmount(){window.removeEventListener("check-changed",this.handleCheckChanged)}render(){let e,t=this.state.score;switch(!0){case t<60:e="score-low";break;case 60<=t&&t<80:e="score-medium";break;case 80<=t:e="score-high"}var a=`diagnoseo-button-content ${e}`;return(0,d.createElement)("span",{className:a},(0,d.createElement)(o,null),(0,d.createElement)("b",{className:"diagnoseo-score"},this.state.score,"/100"))}whenEditorIsReady(){return new Promise(e=>{const t=subscribe(()=>{(select("core/editor").isCleanNewPost()||0<select("core/block-editor").getBlockCount())&&(t(),e())})})}}const a=t,n=window.wp.editor,u=window.wp.components,l=window.wp.data,p=window.wp.i18n,r=window.wp.compose,i=(0,r.compose)((0,l.withDispatch)((a,o)=>({setMetaValue:e=>{var t={};t[o.fieldName]=e,a("core/editor").editPost({meta:t}),o.changeCallback&&o.changeCallback(e)}})),(0,l.withSelect)((e,t)=>({metaValue:e("core/editor").getEditedPostAttribute("meta")[t.fieldName]})))(t=>(0,d.createElement)(u.TextControl,{label:t.label,value:t.metaValue,onChange:e=>t.setMetaValue(e)})),s=(0,r.compose)((0,l.withSelect)(e=>({content:e("core/editor").getEditedPostContent(),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword})))(e=>{var t,a,o=0;e.keyword&&(a=(a=(t=(t=(t=e.content.replace(/<\!--.*?-->/g,"")).replace(/(\r\n|\n|\r)/gm," ")).toLowerCase()).split(" ")).filter(e=>""!==e),(t=seoHelper.countOccurences(e.keyword,t))&&(o=t/a.length*100,o=parseFloat(o.toFixed(2))));let n;return n=window.diagnoseoPro?(a="diagnoseo-check optimal-keyword-density",a+=1<=o&&o<=3?" ok":" nok",(0,d.createElement)("p",{className:a},(0,p.__)("Optimal keyword density","diagnoseo")," ",(0,d.createElement)("b",{className:"value"},"1% - 3%"))):(0,d.createElement)("p",{className:"diagnoseo-check optimal-keyword-density"},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",(0,p.__)("Optimal keyword density","diagnoseo")),(0,d.createElement)(d.Fragment,null,(0,d.createElement)("p",{className:"diagnoseo-stats keyword-density"},(0,p.__)("Keyword density","diagnoseo")," ",(0,d.createElement)("b",{className:"value"},o,"%")),n)}),c=t=>{let e=["diagnoseo-check",t.id];var a;if(t.test&&("string"==typeof(a=t.test(t.postData))&&e.push(a),o="ok"===a,a=t.checkConfig.findIndex(e=>e.id===t.id),t.checkConfig[a].checked!==o&&window.dispatchEvent(new Event("check-changed")),t.checkConfig[a].checked=o),t.inPro)return(0,d.createElement)("p",{className:e.join(" ")},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",t.label," ",(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))));var o=t.valueFieldName&&t.postData[t.valueFieldName]?(0,d.createElement)("b",null,t.postData[t.valueFieldName]):"";return(0,d.createElement)("p",{className:e.join(" ")},t.label," ",o)},m=e=>{let t=["diagnoseo-stats",e.id];if(e.inPro)return(0,d.createElement)("p",{className:t.join(" ")},(0,d.createElement)("i",{className:"dashicons dashicons-lock"})," ",e.label," ",(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))));let a,o=(0,d.createElement)("b",{className:"value"}),n="";var l;return e.test&&(l=e.test(e.postData),o=(0,d.createElement)("b",{className:"value"},l.value),n=l.comment?(0,d.createElement)("span",{className:"comment"},l.comment):"",l.status&&t.push(l.status)),a=e.order&&"value label"!==e.order?(0,d.createElement)(d.Fragment,null,e.label," ",o," ",n):(0,d.createElement)(d.Fragment,null,o," ",e.label),(0,d.createElement)("p",{className:t.join(" ")},a)},g=(0,r.compose)((0,l.withSelect)(e=>({postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredImage:e("core").getMedia(e("core/editor").getEditedPostAttribute("featured_media")),keyword:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,metaTitle:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_title,metaDescription:e("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_description,urlSlug:e("core/editor").getEditedPostAttribute("slug"),blocks:e("core/block-editor").getBlocks(),optimalKeywordDensity:2,optimalWordNumber:300,optimalHeadingNumber:1,optimalImageNumber:1,postType:e("core/editor").getCurrentPostType()})))(a=>{const o=window.diagnoseo.checks,e=o.filter(e=>e.section===a.sectionName),n={postTitle:a.postTitle,postContent:a.postContent,keyword:a.keyword,metaTitle:seoHelper.replaceVariables(a.metaTitle)||(document.querySelector("#seo-title")?seoHelper.replaceVariables(document.querySelector("#seo-title").getAttribute("placeholder")):""),metaDescription:seoHelper.replaceVariables(a.metaDescription)||(document.querySelector("#seo-description")?seoHelper.replaceVariables(document.querySelector("#seo-description").value):""),slug:a.urlSlug,blocks:a.blocks,featuredImage:a.featuredImage,optimalKeywordDensity:a.optimalKeywordDensity,optimalWordNumber:a.optimalWordNumber,optimalHeadingNumber:a.optimalHeadingNumber,optimalImageNumber:a.optimalImageNumber},t=e.map(e=>{let t=!0;if(e.postTypes&&(t=e.postTypes.includes(a.postType)),!e.hidden&&t)switch(e.type){case"check":return e.inPro?(0,d.createElement)(c,{id:e.id,label:e.label,inPro:e.inPro}):(0,d.createElement)(c,{id:e.id,label:e.label,test:e.test,postData:n,checkConfig:o,valueFieldName:e.valueFieldName});case"stats":return e.inPro?(0,d.createElement)(m,{id:e.id,label:e.label,inPro:e.inPro}):(0,d.createElement)(m,{id:e.id,label:e.label,test:e.test,order:e.order,postData:n})}});return(0,d.createElement)(d.Fragment,null,t.map((e,t)=>(0,d.createElement)(React.Fragment,{key:t},e)))});class h extends React.Component{constructor(e){super(e),this.state={keyword:"",keywordList:[],keywordLimit:(window.diagnoseoPro||window.diagnoseo).additionalKeywordLimit,apiKey:"",language:diagnoseo_settings?diagnoseo_settings.locale.substr(0,2):"",loading:!1},this.handleChange=this.handleChange.bind(this),this.handleLangChange=this.handleLangChange.bind(this),this.handleLoadButtonClick=this.handleLoadButtonClick.bind(this),this.relatedKeywordsApiUrl="diagnoseo/v1/related-keywords"}stripKeywordData(e){return(e=-1===e.indexOf("|")?e:e.substr(0,e.indexOf(" |"))).trim()}async loadRelatedKeywords(){var t=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_keyword,a=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;if(t)if(this.state.language){this.setState({loading:!0});let e=await this.getRelatedKeywords(t,a);if(e.length){let a=this.state.keywordList;e.forEach(t=>{t={name:t.trim()};var e=a.findIndex(e=>e.name===t);-1===e?a.push(t):(a[e].repeat_min=t.repeat_min,a[e].repeat_max=t.repeat_max)}),this.saveKeywords(a)}this.setState({loading:!1})}else alert((0,p.__)("Please select language.","diagnoseo"));else alert((0,p.__)('Please enter the "focus keyword" first',"diagnoseo"))}saveKeywords(e){const t=[...new Set(e)];t.splice(this.state.keywordLimit),this.setState({keywordList:t}),(window.onbeforeunload=null,l.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_additional_keywords:JSON.stringify(t)}})}saveLanguage(e){(0,l.dispatch)("core/editor").editPost({meta:{diagnoseo_meta_language:e}})}componentDidMount(){let e=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_additional_keywords,t=(0,l.select)("core/editor").getEditedPostAttribute("meta").diagnoseo_meta_language;try{e=JSON.parse(e)}catch{e=""}this.setState({language:t,keyword:this.props.focusKeyword,keywordList:e||[]})}async handleLoadButtonClick(){window.diagnoseoPro?this.loadRelatedKeywords():alert((0,p.__)("Related keywords and Pro data require DiagnoSEO Pro.","diagnoseo"))}handleChange(e){const o=this.state.keywordList,{stripKeywordData:n}=this;e=e.map(e=>{let t=n(e.value||e),a=o.findIndex(e=>t===e.name);return{name:t,repeat_min:-1!==a?o[a].repeat_min:0,repeat_max:-1!==a?o[a].repeat_max:0}});this.saveKeywords(e)}handleLangChange(e){this.setState({language:e}),this.saveLanguage(e)}render(){let{postTitle:l,postContent:r,featuredMedia:i}=this.props;const{countOccurences:s}=seoHelper;let c=0,e=this.state.keywordList.map(e=>{let t=e.name||"",a="error",o=function(e){r=seoHelper.stripTags(r);var t=0;return t+=s(e,l),t+=s(e,r),t+=seoHelper.isKeywordInAnyAlt(e,r),t+=i?s(e,i.alt_text):0}(t);o&&(a=!e.repeat_min||!e.repeat_max||o>=e.repeat_min&&o<=e.repeat_max?"success":"validating",c++);let n=` | ${o}`;return e.repeat_min&&e.repeat_max&&(n+=` (${e.repeat_min} - ${e.repeat_max})`),{value:t+n,status:a}}),t=!1;window.diagnoseo.RelatedKeywordsInPost!==c&&(window.diagnoseo.RelatedKeywordsInPost=c,t=!0),window.diagnoseo.additionalKeywordCount!==e.length&&(window.diagnoseo.additionalKeywordCount=e.length,t=!0),t&&window.dispatchEvent(new Event("check-changed"));var a=this.state.loading?(0,p.__)("Please wait... Loading related keywords. It can take up to a few minutes.","diagnoseo"):(0,d.createElement)("button",{className:"button get-related-keywords",onClick:this.handleLoadButtonClick},(0,p.__)("Get related keywords","diagnoseo"));return(0,d.createElement)(d.Fragment,null,(0,d.createElement)("div",{className:"components-base-control__field add-keyword diagnoseo-related-keywords"},(0,d.createElement)(u.FormTokenField,{label:(0,d.createElement)("b",null,(0,p.__)("Related keywords","diagnoseo")),onChange:this.handleChange,value:e,maxLength:this.state.keywordLimit+10}),(0,d.createElement)("p",{className:"components-form-token-field__help"},(0,p.__)("Limits: 10 keywords in free, 100 keywords in Pro","diagnoseo")),(0,d.createElement)(u.SelectControl,{options:[{value:"",label:"Choose language"},{value:"albanian",label:"Albanian"},{value:"arabic",label:"Arabic"},{value:"armenian",label:"Armenian"},{value:"awadhi",label:"Awadhi"},{value:"azerbaijani",label:"Azerbaijani"},{value:"bashkir",label:"Bashkir"},{value:"basque",label:"Basque"},{value:"belarusian",label:"Belarusian"},{value:"bengali",label:"Bengali"},{value:"bhojpuri",label:"Bhojpuri"},{value:"bosnian",label:"Bosnian"},{value:"brazilian Portuguese",label:"Brazilian Portuguese"},{value:"bulgarian",label:"Bulgarian"},{value:"cantonese (Yue)",label:"Cantonese (Yue)"},{value:"catalan",label:"Catalan"},{value:"chhattisgarhi",label:"Chhattisgarhi"},{value:"chinese",label:"Chinese"},{value:"croatian",label:"Croatian"},{value:"czech",label:"Czech"},{value:"danish",label:"Danish"},{value:"dogri",label:"Dogri"},{value:"dutch",label:"Dutch"},{value:"english",label:"English"},{value:"estonian",label:"Estonian"},{value:"faroese",label:"Faroese"},{value:"finnish",label:"Finnish"},{value:"french",label:"French"},{value:"galician",label:"Galician"},{value:"georgian",label:"Georgian"},{value:"german",label:"German"},{value:"greek",label:"Greek"},{value:"gujarati",label:"Gujarati"},{value:"haryanvi",label:"Haryanvi"},{value:"hindi",label:"Hindi"},{value:"hungarian",label:"Hungarian"},{value:"indonesian",label:"Indonesian"},{value:"irish",label:"Irish"},{value:"italian",label:"Italian"},{value:"japanese",label:"Japanese"},{value:"javanese",label:"Javanese"},{value:"kannada",label:"Kannada"},{value:"kashmiri",label:"Kashmiri"},{value:"kazakh",label:"Kazakh"},{value:"konkani",label:"Konkani"},{value:"korean",label:"Korean"},{value:"kyrgyz",label:"Kyrgyz"},{value:"latvian",label:"Latvian"},{value:"lithuanian",label:"Lithuanian"},{value:"macedonian",label:"Macedonian"},{value:"maithili",label:"Maithili"},{value:"malay",label:"Malay"},{value:"maltese",label:"Maltese"},{value:"mandarin",label:"Mandarin"},{value:"mandarin Chinese",label:"Mandarin Chinese"},{value:"marathi",label:"Marathi"},{value:"marwari",label:"Marwari"},{value:"min Nan",label:"Min Nan"},{value:"moldovan",label:"Moldovan"},{value:"mongolian",label:"Mongolian"},{value:"montenegrin",label:"Montenegrin"},{value:"nepali",label:"Nepali"},{value:"norwegian",label:"Norwegian"},{value:"oriya",label:"Oriya"},{value:"pashto",label:"Pashto"},{value:"persian",label:"Persian"},{value:"polish",label:"Polish"},{value:"portuguese",label:"Portuguese"},{value:"punjabi",label:"Punjabi"},{value:"rajasthani",label:"Rajasthani"},{value:"romanian",label:"Romanian"},{value:"russian",label:"Russian"},{value:"sanskrit",label:"Sanskrit"},{value:"santali",label:"Santali"},{value:"serbian",label:"Serbian"},{value:"sindhi",label:"Sindhi"},{value:"sinhala",label:"Sinhala"},{value:"slovak",label:"Slovak"},{value:"slovene",label:"Slovene"},{value:"slovenian",label:"Slovenian"},{value:"spanish",label:"Spanish"},{value:"swahili",label:"Swahili"},{value:"swedish",label:"Swedish"},{value:"tajik",label:"Tajik"},{value:"tamil",label:"Tamil"},{value:"tatar",label:"Tatar"},{value:"telugu",label:"Telugu"},{value:"thai",label:"Thai"},{value:"turkish",label:"Turkish"},{value:"turkmen",label:"Turkmen"},{value:"ukrainian",label:"Ukrainian"},{value:"urdu",label:"Urdu"},{value:"uzbek",label:"Uzbek"},{value:"vietnamese",label:"Vietnamese"},{value:"welsh",label:"Welsh"},{value:"wu",label:"Wu"}],value:this.state.language,onChange:this.handleLangChange,label:(0,p.__)("Language","diagnoseo")}),(0,d.createElement)("p",null,a)))}getRelatedKeywords(a,o){return new Promise(t=>{const e=new FormData;e.append("keyword",a),e.append("language",o),e.append("count",30),fetch("/wp-json/diagnoseo/v1/related-keywords",{method:"POST",body:e}).then(e=>e.json()).then(e=>{"ok"===e.status?t(e.keywords.split(",")):t([])}).catch(e=>{console.error(e),t([])})})}}const k=(0,r.compose)((0,l.withSelect)(e=>{var t=e("core/editor").getEditedPostAttribute("featured_media");return{postTitle:e("core/editor").getEditedPostAttribute("title"),postContent:e("core/editor").getEditedPostContent(),featuredMedia:e("core").getMedia(t,{context:"embed"})||{}}}))(e=>(0,d.createElement)(h,{postTitle:e.postTitle,postContent:e.postContent,featuredMedia:e.featuredMedia,seoDataCollector:e.seoDataCollector})),w=(0,r.compose)((0,l.withSelect)(e=>{if(!window.diagnoseoPro)return{};e={categories:e("core/editor").getEditedPostAttribute("categories"),status:"publish",per_page:10,exclude:[e("core/editor").getEditedPostAttribute("id")]};return{suggestedPosts:wp.data.select("core").getEntityRecords("postType","post",e)||[]}}))(e=>{if(window.diagnoseoPro){var t="";return t=e.suggestedPosts.length?(t=e.suggestedPosts.map(e=>(0,d.createElement)("li",null,(0,d.createElement)("a",{href:e.link},e.title.raw))),(0,d.createElement)("ol",null,t)):(0,d.createElement)("p",null,(0,p.__)("Could not prepare suggestions as there are no posts related to this one"))}return(0,d.createElement)("p",null,(0,d.createElement)("b",null,(0,d.createElement)("a",{href:"https://diagnoseo.com/wordpress-seo-plugin/?utm_source=wp&utm_medium=link&utm_campaign=available_in_pro",target:"_blank",rel:"noreferrer noopener"},(0,p.__)("Available in Pro","diagnoseo"))))}),b=(0,r.compose)((0,l.withDispatch)(t=>({setMetaValues:e=>{t("core/editor").editPost({meta:{}})}})))(e=>{var t=window.diagnoseoPro?"DiagnoSEO Pro":"DiagnoSEO";return(0,d.createElement)(d.Fragment,null,(0,d.createElement)(n.PluginSidebarMoreMenuItem,{target:"diagnoseo-content-analyzer"},(0,p.__)("DiagnoSEO Content Watcher","diagnoseo")),(0,d.createElement)(n.PluginSidebar,{title:t,name:"diagnoseo-content-analyzer"},(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Content analyzer","diagnoseo"),initialOpen:"true"},(0,d.createElement)(g,{sectionName:"content"})),(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Keyword placement","diagnoseo"),initialOpen:"true"},(0,d.createElement)(i,{fieldName:"diagnoseo_meta_keyword",label:(0,d.createElement)("b",null,(0,p.__)("Focus keyword","diagnoseo"))}),(0,d.createElement)(s,null),(0,d.createElement)(k,{seoDataCollector:e.setMetaValues}),(0,d.createElement)(g,{sectionName:"keyword"})),(0,d.createElement)(u.PanelBody,{title:(0,p.__)("Internal linking suggestions","diagnoseo"),initialOpen:"true"},(0,d.createElement)(w,null))))});(0,e.registerPlugin)("diagnoseo-sidebar",{icon:(0,d.createElement)(a,null),render:b})})(),document.addEventListener("DOMContentLoaded",function(){"use strict";const e=document.querySelectorAll(".meta-template");e.forEach(e=>{const n=e.querySelector(".choose-variable"),t=e.querySelector(".add-variable"),l=e.querySelector("input, textarea");t&&t.addEventListener("click",e=>{e.preventDefault();var t,a,o=n.value;l.selectionStart||"0"==l.selectionStart?(t=l.selectionStart,a=l.selectionEnd,e=parseInt(t)?" ":"",l.value=l.value.substring(0,t)+e+o+l.value.substring(a,l.value.length)):l.value+=o,l.dispatchEvent(new Event("input"))})});const t=document.querySelectorAll(".diagnoseo-generator-button-free");t&&t.forEach(e=>{e.addEventListener("click",e=>{e.preventDefault(),alert("This feature requires DiagnoSEO Pro")})})}),window.seoHelper={slugify:function(e){e=(e=e.replace(/^\s+|\s+$/g,"")).toLowerCase();for(var t="àáãäâąèéëêęìíïîóòóöôùúüûñńśçćźżł·/_,:;",a=0,o=t.length;a<o;a++)e=e.replace(new RegExp(t.charAt(a),"g"),"aaaaaaeeeeeiiiiooooouuuunnscczzl------".charAt(a));return e=e.replace(/[^a-z0-9 -]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-")},countOccurences:function(e,t){if(!t||!e)return 0;t=t.toLowerCase().replaceAll(/[:;,.!?—]/g,""),e=e.toLowerCase();e=new RegExp(e,"g");return(t.match(e)||[]).length},countSyllables:function(e){if(""===e)return 0;if(e.length<=3)return 1;e=(e=(e=(e=e.toLowerCase()).replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/,"")).replace(/^y/,"")).match(/[aeiouy]{1,2}/g);return e?e.length:0},countWords:function(e){e=(e=(e=e.replace(/(\r\n|\n|\r)/gm," ")).replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g," ")).split(" ");return(e=(e=e.map(e=>e.trim())).filter(e=>e&&""!==e&&"\n"!==e)).length||0},countElements:function(e,t){if(!e||!t)return 0;const a=document.createElement("div");return a.innerHTML=e,a.querySelectorAll(t).length},replaceVariables:function(e){if(e){var{site:t,siteTagline:a,separator:o,excerpt:n,postTitle:l}=document.querySelector(".diagnoseo-preview").dataset;return e=(e=(e=(e=(e=(e=(e=(e=e.replaceAll("%title%",document.body.classList.contains("block-editor-page")?window.wp.data.select("core/editor").getEditedPostAttribute("title"):l)).replaceAll("%sitename%",t)).replaceAll("%tagline%",a)).replaceAll("%sep%",o)).replaceAll("%page%"," ")).replaceAll("%excerpt%",n)).replaceAll("%currentyear%",(new Date).getFullYear())).replaceAll("%currentmonth%",(new Date).toLocaleString("default",{month:"long"}))}},isKeywordInText:function(e,t){if(!e||!t)return!1;e=e.toLowerCase();let a=(t=t.toLowerCase()).toLowerCase().replaceAll(/[:;,.!?-]/g,"");return t.includes(e)||a.includes(e)},isKeywordInAnyElement:function(t,e,a){if(!t||!e||!a)return!1;var o=!1;const n=seoHelper.createMarkupEl(e);return elements=n.querySelectorAll(a),elements.forEach(e=>{seoHelper.isKeywordInText(t,e.textContent)&&(o=!0)}),o},isKeywordInAnyAlt:function(t,e,a=null){if(!t)return!1;if(a&&seoHelper.isKeywordInText(t,a.alt_text))return!0;var o=0;const n=seoHelper.createMarkupEl(e),l=n.querySelectorAll("img");return l.forEach(e=>{e=e.getAttribute("alt").toLowerCase();o+=seoHelper.countOccurences(t,e)}),o},createMarkupEl:function(e){const t=document.createElement("div");return t.innerHTML=e,t},stripTags:function(e){return e.replace(/(<([^>]+)>)/gi,"")}}; -
diagnoseo/trunk/readme.txt
r3365809 r3423066 4 4 Requires at least: 4.7 5 5 Tested up to: 6.8 6 Stable tag: 1.2.5 46 Stable tag: 1.2.56 7 7 Requires PHP: 7.2 8 8 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.