.*<\/p>/U', $post, $paragraphs); foreach($paragraphs[0] as $paragraph){ $paragraph = normalize_whitespace(wp_strip_all_tags($paragraph)); $data['paragraph_length'] += substr_count($paragraph, ' ') + 1; // updating paragraph length siteseo_analyse_passive_voice($paragraph, $data); } } return $data; } function siteseo_analyse_passive_voice($paragraph, &$data){ if(empty($paragraph)){ return; } $sentences = explode('.', $paragraph); $passive_count = 0; if(!isset($data['passive_voice']['passive_sentences'])){ $data['passive_voice']['passive_sentences'] = 0; } if(!isset($data['passive_voice']['total_sentences'])){ $data['passive_voice']['total_sentences'] = 0; } if(empty($sentences)){ return; } foreach($sentences as $sentence){ if(empty($sentence)){ continue; } $sentence = normalize_whitespace($sentence); $is_passive = siteseo_sentence_is_passive($sentence); if($is_passive == true){ $passive_count++; } } $data['passive_voice']['passive_sentences'] += $passive_count; $data['passive_voice']['total_sentences'] += count($sentences); } function siteseo_sentence_is_passive($sentence){ $be_words = ['am', 'is', 'are', 'was', 'were', 'be', 'being', 'been']; // TODO: We can check if "en" ending words are a comman pattern too, then we will remove the en ending words too from here. $past_particles = ['gone' ,'done' ,'seen' ,'taken' ,'eaten' ,'written' ,'driven' ,'spoken' ,'broken' ,'chosen' ,'fallen' ,'forgotten' ,'forgiven' ,'hidden' ,'known' ,'grown' ,'drawn' ,'flown' ,'thrown' ,'blown' ,'shown' ,'worn' ,'sworn' ,'torn' ,'woken' ,'begun' ,'sung' ,'run' ,'swum' ,'shaken' ,'given' ,'proven' ,'ridden' ,'risen' ,'shone' ,'shot' ,'fought' ,'thought' ,'bought' ,'brought' ,'caught' ,'taught' ,'built' ,'felt' ,'kept' ,'slept' ,'left' ,'lost' ,'meant' ,'met' ,'read' ,'sold' ,'sent' ,'spent' ,'stood' ,'understood' ,'won' ,'held' ,'told' ,'heard' ,'paid' ,'laid' ,'said' ,'found' ,'made' ,'learned' ,'put']; if(empty($sentence)){ return false; } $words = explode(' ', $sentence); for($i = 0; $i < count($words); $i++){ // Checking if we have a be word if(!in_array($words[$i], $be_words)){ continue; } // If be word is there then need to check if next one is past particle with mostly ends with ed. if(strpos($words[$i+1], 'ed') != strlen($words[$i+1]) - 2){ if(!in_array($words[$i+1], $past_particles)){ continue; } } return true; } return false; } // Analysis every 15 seconds function siteseo_do_realtime_analysis(){ // Security check siteseo_check_ajax_referer('siteseo_realtime_nonce'); if(!current_user_can('edit_posts') || !is_admin()){ return; } $data = []; $post_content = !empty($_POST['post_content']) ? wp_kses_post(wp_unslash($_POST['post_content'])) : ''; $post_id = (int) siteseo_opt_post('post_id'); $post_origin = siteseo_opt_post('post_origin'); $post_type = siteseo_opt_post('post_type'); $post_title = siteseo_opt_post('post_title'); $post_tax = siteseo_opt_post('post_tax'); $post_slug = siteseo_opt_post('post_slug'); $meta = siteseo_opt_post('meta'); $keywords_str = strtolower(siteseo_opt_post('keywords')); $keywords = [$keywords_str]; $h1_title = $post_title; // We use title of the page as h1 // In case we are setting a custom title using SiteSEO metabox then // we will need to consider that as the title for the Analysis. if(!empty($meta['title'])){ $post_title = $meta['title']; update_post_meta($post_id , '_siteseo_titles_title', $meta['title']); } if(strpos($keywords_str, ',') !== FALSE){ $keywords = explode(',', $keywords_str); } $keywords = apply_filters('siteseo_content_analysis_target_keywords', $keywords, $post_id); $post_content = apply_filters('siteseo_dom_analysis_get_post_content', $post_content); // Zion Builder compatibility if(is_plugin_active('zionbuilder/zionbuilder.php')){ $post_content .= get_post_meta($post_id, '_zionbuilder_page_elements', true); } // BeTheme is activated $theme = wp_get_theme(); if('betheme' == $theme->template || 'Betheme' == $theme->parent_theme){ $post_content .= get_post_meta($post_id, 'mfn-page-items-seo', true); } // Themify compatibility if(defined('THEMIFY_DIR') && method_exists('ThemifyBuilder_Data_Manager', '_get_all_builder_text_content')){ global $ThemifyBuilder; $builder_data = $ThemifyBuilder->get_builder_data($post_id); $plain_text = \ThemifyBuilder_Data_Manager::_get_all_builder_text_content($builder_data); $plain_text = do_shortcode($plain_text); if('' != $plain_text){ $post_content = $plain_text; } } // Add WC product excerpt if('product' == $post_type){ $post_content .= get_the_excerpt($post_id); } $post_content = apply_filters('siteseo_content_analysis_content', $post_content, $post_id); $data['target_kws_count'] = siteseo_get_service('CountTargetKeywordsUse')->getCountByKeywords($keywords, $post_id); $data['words_counter'] = preg_match_all("/\p{L}[\p{L}\p{Mn}\p{Pd}'\x{2019}]*/u", normalize_whitespace(wp_strip_all_tags($post_content)), $matches); if(!empty($matches[0])){ $words_counter_unique = count(array_unique($matches[0])); } else { $words_counter_unique = '0'; } $data['words_counter_unique'] = $words_counter_unique; // Checkinng the post slug if(!empty($keywords)){ // Keyword density foreach($keywords as $kw){ if (preg_match_all('#\b(' . $kw . ')\b#iu', stripslashes_deep(wp_strip_all_tags($post_content)), $m)) { $data['kws_density']['matches'][$kw][] = $m[0]; } } if (is_plugin_active('permalink-manager-pro/permalink-manager.php')) { global $permalink_manager_uris; $post_slug = urldecode($permalink_manager_uris[$post_id]); } $post_slug = str_replace('-', ' ', $post_slug); if(isset($post_slug)){ foreach($keywords as $kw){ if (preg_match_all('#\b(' . remove_accents($kw) . ')\b#iu', strip_tags($post_slug), $m)){ $data['kws_permalink']['matches'][$kw][] = $m[0]; } } } } //Title if(!empty($post_title)){ $data['title'] = esc_attr(stripslashes_deep(wp_filter_nohtml_kses($post_title))); if(!empty($keywords)){ foreach($keywords as $kw){ if(preg_match_all('#\b(' . $kw . ')\b#iu', $data['title'], $m)){ $data['meta_title']['matches'][$kw][] = $m[0]; } } } } //Meta desc if(!empty($meta) && !empty($meta['description'])){ $data['meta_desc'] = esc_attr(stripslashes_deep(wp_filter_nohtml_kses(wp_strip_all_tags($meta['description'])))); update_post_meta($post_id , '_siteseo_titles_desc', $meta['description']); if(!empty($keywords) && !empty($data['meta_desc'])){ foreach($keywords as $kw){ if(preg_match_all('#\b(' . $kw . ')\b#iu', $data['meta_desc'], $m)){ $data['meta_description']['matches'][$kw][] = $m[0]; } } } } if('1' == siteseo_get_service('SocialOption')->getSocialFacebookOg()){ //OG:title if(!empty($meta) && !empty($meta['og_title'])){ $data['og_title']['count'] = 1; $data['og_title']['values'][] = esc_attr(stripslashes_deep(wp_filter_nohtml_kses($meta['og_title']))); } //OG:description if(!empty($meta) && !empty($meta['og_title'])){ $data['og_desc']['count'] = 1; $data['og_desc']['values'][] = esc_attr(stripslashes_deep(wp_filter_nohtml_kses($meta['og_title']))); } //OG:image if(!empty($meta) && !empty($meta['og_img'])){ $data['og_img']['count'] = 1; $data['og_img']['values'][] = esc_attr(stripslashes_deep(wp_filter_nohtml_kses($meta['og_img']))); } } if('1' == siteseo_get_service('SocialOption')->getSocialTwitterCard()){ //Twitter:title if (!empty($meta) && !empty($meta['tw_title'])){ $data['tw_title']['count'] = 1; $data['tw_title']['values'][] = esc_attr(stripslashes_deep(wp_filter_nohtml_kses($meta['tw_title']))); } //Twitter:description if (!empty($meta) && !empty($meta['tw_desc'])) { $data['tw_desc']['count'] = 1; $data['tw_desc']['values'][] = esc_attr(stripslashes_deep(wp_filter_nohtml_kses($meta['tw_desc']))); } //Twitter:image if (!empty($meta) && !empty($meta['tw_img'])) { $data['tw_img']['count'] = 1; $data['tw_img']['values'][] = esc_attr(stripslashes_deep(wp_filter_nohtml_kses($meta['tw_img']))); } } // h1 preg_match_all('/