File manager - Edit - /home/aresglob/public_html/wp/wp-includes/images/smilies/metaboxes.tar
Back
settings.php 0000644 00000203643 15105564751 0007136 0 ustar 00 <?php /* * SITESEO * https://siteseo.io * (c) SiteSEO Team */ namespace SiteSEO\Metaboxes; if(!defined('ABSPATH')){ die('HACKING ATTEMPT!'); } class Settings{ static function render_metabox(){ global $siteseo; $metabox_data = []; $show_content_analysis = true; if(is_user_logged_in()){ if(is_super_admin()){ $siteseo->display_ca_metaboxe = 1; $show_content_analysis = true; } else{ $user = wp_get_current_user(); $siteseo_user_role = current($user->roles); $siteseo_options = get_option('siteseo_advanced_option_name'); $ca_metabox_roles = !empty($siteseo_options['security_metaboxe_ca_role']) ? $siteseo_options['security_metaboxe_ca_role'] : []; if(array_key_exists($siteseo_user_role, $ca_metabox_roles)){ $siteseo->display_ca_metaboxe = 1; $show_content_analysis = false; } } } $metabox_data = self::metabox_data(); self::metabox_form_html($metabox_data, $show_content_analysis); } static function metabox_data(){ global $post, $siteseo; $metabox_data = []; $metabox_data['title'] = $post->post_title; $metabox_data['excerpt'] = $post->post_excerpt; // Getting the first paragraph of the post if(empty($metabox_data['excerpt'])){ $post_seperated = get_extended($post->post_content); if(!empty($post_seperated['main'])){ $metabox_data['excerpt'] = wp_strip_all_tags($post_seperated['main']); } } $metabox_data['keywords'] = get_post_meta($post->ID, 'siteseo_analysis_target_kw',true); $metabox_data['meta_title'] = get_post_meta($post->ID, '_siteseo_titles_title', true); $metabox_data['meta_desc'] = get_post_meta($post->ID, '_siteseo_titles_desc', true); $metabox_data['robots_canonical'] = get_post_meta($post->ID, '_siteseo_robots_canonical', true); $metabox_data['robots_primary_cat'] = get_post_meta($post->ID, '_siteseo_robots_primary_cat', true); $metabox_data['fb_title'] = get_post_meta($post->ID, '_siteseo_social_fb_title', true); $metabox_data['fb_desc'] = get_post_meta($post->ID, '_siteseo_social_fb_desc', true); $metabox_data['fb_img'] = get_post_meta($post->ID, '_siteseo_social_fb_img', true); $siteseo_social_fb_img_attachment_id = get_post_meta($post->ID, '_siteseo_social_fb_img_attachment_id', true); $siteseo_social_fb_img_width = get_post_meta($post->ID, '_siteseo_social_fb_img_width', true); $siteseo_social_fb_img_height = get_post_meta($post->ID, '_siteseo_social_fb_img_height', true); $metabox_data['x_title'] = get_post_meta($post->ID, '_siteseo_social_twitter_title', true); $metabox_data['x_desc'] = get_post_meta($post->ID, '_siteseo_social_twitter_desc', true); $metabox_data['x_img'] = get_post_meta($post->ID, '_siteseo_social_twitter_img', true); $siteseo_social_twitter_img_attachment_id = get_post_meta($post->ID, '_siteseo_social_twitter_img_attachment_id', true); $siteseo_social_twitter_img_width = get_post_meta($post->ID, '_siteseo_social_twitter_img_width', true); $siteseo_social_twitter_img_height = get_post_meta($post->ID, '_siteseo_social_twitter_img_height', true); $metabox_data['redirections_enabled'] = get_post_meta($post->ID, '_siteseo_redirections_enabled', true); $metabox_data['redirections_enabled_regex'] = get_post_meta($post->ID, '_siteseo_redirections_enabled_regex', true); $metabox_data['redirections_logged_status'] = get_post_meta($post->ID, '_siteseo_redirections_logged_status', true); $metabox_data['redirections_type'] = get_post_meta($post->ID, '_siteseo_redirections_type', true); $metabox_data['redirections_value'] = get_post_meta($post->ID, '_siteseo_redirections_value', true); $metabox_data['redirections_param'] = get_post_meta($post->ID, '_siteseo_redirections_param', true); $title_options = get_option('siteseo_titles_option_name', []); $metabox_data['disabled_robots'] = [ 'robots_index' => '', 'robots_follow' => '', 'archive' => '', 'snippet' => '', 'imageindex' => '', ]; if(post_password_required($post->ID) === true || !empty($title_options['titles_noindex'])){ $metabox_data['robots_index'] = 'yes'; $metabox_data['disabled_robots']['robots_index'] = 'disabled'; } else{ $metabox_data['robots_index'] = get_post_meta($post->ID, '_siteseo_robots_index', true); } if(!empty($title_options['titles_nofollow'])){ $metabox_data['robots_follow'] = 'yes'; $metabox_data['disabled_robots']['robots_follow'] = 'disabled'; } else{ $metabox_data['robots_follow'] = get_post_meta($post->ID, '_siteseo_robots_follow', true); } if(!empty($title_options['titles_noarchive'])){ $metabox_data['robots_archive'] = 'yes'; $metabox_data['disabled_robots']['archive'] = 'disabled'; } else{ $metabox_data['robots_archive'] = get_post_meta($post->ID, '_siteseo_robots_archive', true); } if(!empty($title_options['titles_nosnippet'])){ $metabox_data['robots_snippet'] = 'yes'; $metabox_data['disabled_robots']['snippet'] = 'disabled'; } else{ $metabox_data['robots_snippet'] = get_post_meta($post->ID, '_siteseo_robots_snippet', true); } if(!empty($title_options['titles_noimageindex'])){ $metabox_data['robots_imageindex'] = 'yes'; $metabox_data['disabled_robots']['imageindex'] = 'disabled'; } else{ $metabox_data['robots_imageindex'] = get_post_meta($post->ID, '_siteseo_robots_imageindex', true); } return $metabox_data; } static function metabox_term_data($term){ global $tag; $metabox_data = []; $metabox_data['title'] = $tag->name; $metabox_data['excerpt'] = $tag->description; $metabox_data['meta_title'] = get_term_meta($term->term_id, '_siteseo_titles_title', true); $metabox_data['meta_desc'] = get_term_meta($term->term_id, '_siteseo_titles_desc', true); // Social Fields $metabox_data['fb_title'] = get_term_meta($term->term_id, '_siteseo_social_fb_title', true); $metabox_data['fb_desc'] = get_term_meta($term->term_id, '_siteseo_social_fb_desc', true); $metabox_data['fb_img'] = get_term_meta($term->term_id, '_siteseo_social_fb_img', true); $metabox_data['x_title'] = get_term_meta($term->term_id, '_siteseo_social_twitter_title', true); $metabox_data['x_desc'] = get_term_meta($term->term_id, '_siteseo_social_twitter_desc', true); $metabox_data['x_img'] = get_term_meta($term->term_id, '_siteseo_social_twitter_img', true); // Social Dimensions $fb_img_id = get_term_meta($term->term_id, '_siteseo_social_fb_img_attachment_id', true); $fb_img_width = get_term_meta($term->term_id, '_siteseo_social_fb_img_width', true); $fb_img_height = get_term_meta($term->term_id, '_siteseo_social_fb_img_height', true); $x_img_id = get_term_meta($term->term_id, '_siteseo_social_twitter_img_attachment_id', true); $x_img_width = get_term_meta($term->term_id, '_siteseo_social_twitter_img_width', true); $x_img_height = get_term_meta($term->term_id, '_siteseo_social_twitter_img_height', true); // Redirection fields $metabox_data['redirections_enabled'] = get_term_meta($term->term_id, '_siteseo_redirections_enabled', true); $metabox_data['redirections_logged_status'] = get_term_meta($term->term_id, '_siteseo_redirections_logged_status', true); $metabox_data['redirections_type'] = get_term_meta($term->term_id, '_siteseo_redirections_type', true); $metabox_data['redirections_value'] = get_term_meta($term->term_id, '_siteseo_redirections_value', true); $metabox_data['robots_canonical']= get_term_meta($term->term_id, '_siteseo_robots_canonical', true); $title_options = get_option('siteseo_titles_option_name', []); $metabox_data['disabled_robots'] = [ 'robots_index' => '', 'robots_follow' => '', 'archive' => '', 'snippet' => '', 'imageindex' => '', ]; if(!empty($title_options['titles_noindex'])){ $metabox_data['robots_index'] = 'yes'; $metabox_data['disabled_robots']['robots_index'] = 'disabled'; } else { $metabox_data['robots_index'] = get_term_meta($term->term_id, '_siteseo_robots_index', true); } if(!empty($title_options['titles_nofollow'])){ $metabox_data['robots_follow'] = 'yes'; $metabox_data['disabled_robots']['robots_follow'] = 'disabled'; } else { $metabox_data['robots_follow'] = get_term_meta($term->term_id, '_siteseo_robots_follow', true); } if(!empty($title_options['titles_noarchive'])){ $metabox_data['robots_archive'] = 'yes'; $metabox_data['disabled_robots']['archive'] = 'disabled'; } else { $metabox_data['robots_archive'] = get_term_meta($term->term_id, '_siteseo_robots_archive', true); } if(!empty($title_options['titles_nosnippet'])){ $metabox_data['robots_snippet'] = 'yes'; $metabox_data['disabled_robots']['snippet'] = 'disabled'; } else { $metabox_data['robots_snippet'] = get_term_meta($term->term_id, '_siteseo_robots_snippet', true); } if(!empty($title_options['titles_noimageindex'])){ $metabox_data['robots_imageindex'] = 'yes'; $metabox_data['disabled_robots']['imageindex'] = 'disabled'; } else { $metabox_data['robots_imageindex'] = get_term_meta($term->term_id, '_siteseo_robots_imageindex', true); } return $metabox_data; } static function metabox_form_html(&$metabox_data, $show_content_analysis = false){ global $siteseo, $post, $pagenow, $typenow; $pro_settings = isset($siteseo->pro) ? $siteseo->pro : ''; $data_attr = []; $data_attr['data_tax'] = ''; $data_attr['termId'] = ''; if('post-new.php' == $pagenow || 'post.php' == $pagenow){ $data_attr['current_id'] = $post->ID; $data_attr['origin'] = 'post'; $data_attr['title'] = get_the_title($data_attr['current_id']); } elseif('term.php' == $pagenow || 'edit-tags.php' == $pagenow){ global $tag; $data_attr['current_id'] = $tag->term_id; $data_attr['termId'] = $tag->term_id; $data_attr['origin'] = 'term'; $data_attr['data_tax'] = $tag->taxonomy; $data_attr['title'] = $tag->name; } $data_attr['isHomeId'] = get_option('page_on_front'); if($data_attr['isHomeId'] === '0'){ $data_attr['isHomeId'] = ''; } // Static Data $home_url = home_url(); $parsed_url = wp_parse_url($home_url); $host_uri = $parsed_url['host']; $social_placeholder = SITESEO_ASSETS_URL . '/img/social-placeholder.png'; $metabox_tag_drop_kses = [ 'button' => [ 'class' => true, 'type' => true, ], 'span' => [ 'class' => true, ], 'div' => [ 'class' => true, 'style' => true, ], 'input' => [ 'type' => true, 'class' => true, 'name' => true, 'spellcheck' => true, 'placeholder' => true, ], 'ul' => true, 'li' => [ 'class' => true, 'data-*' => true, 'tabindex' => true, ] ]; // Preview of social title and description $current_screen = get_current_screen(); if(!empty($current_screen) && $current_screen->base === 'term'){ $term_id = isset($_GET['tag_ID']) ? (int)$_GET['tag_ID'] : 0; $taxonomy = $current_screen->taxonomy; } else{ $post_type = $current_screen->post_type; } $social_preview_title = ''; $social_preview_desc = ''; if(!empty($metabox_data['meta_title'])){ $social_preview_title = $metabox_data['meta_title']; } elseif(!empty($post_type) && !empty($siteseo->titles_settings['titles_single_titles'][$post_type]['title'])){ $social_preview_title = $siteseo->titles_settings['titles_single_titles'][$post_type]['title']; } elseif(!empty($taxonomy) && !empty($siteseo->titles_settings['titles_tax_titles'][$taxonomy]['title'])){ $social_preview_title = $siteseo->titles_settings['titles_tax_titles'][$taxonomy]['title']; } else{ $social_preview_title = get_the_title(); } if(!empty($metabox_data['meta_desc'])){ $social_preview_desc = $metabox_data['meta_desc']; } elseif(!empty($post_type) && !empty($siteseo->titles_settings['titles_single_titles'][$post_type]['description'])){ $social_preview_desc = $siteseo->titles_settings['titles_single_titles'][$post_type]['description']; } elseif(!empty($taxonomy) && !empty($siteseo->titles_settings['titles_tax_titles'][$taxonomy]['description'])){ $social_preview_desc = $siteseo->titles_settings['titles_tax_titles'][$taxonomy]['description']; } else{ $social_preview_desc = get_bloginfo('description'); } if(empty($siteseo->advanced_settings['appearance_ca_metaboxe']) && !empty($show_content_analysis)){ $siteseo_metabox_tabs = [ 'content-analysis' => __('Content Analysis', 'siteseo') ]; } $siteseo_metabox_tabs['title-settings'] = __('Title', 'siteseo'); $siteseo_metabox_tabs['social-settings'] = __('Social', 'siteseo'); $siteseo_metabox_tabs['advanced-settings'] = __('Advanced', 'siteseo'); $siteseo_metabox_tabs['redirect'] = __('Redirects', 'siteseo'); if(!empty($pro_settings['enable_structured_data']) && !empty($pro_settings['toggle_state_stru_data']) && !empty($show_content_analysis)){ $siteseo_metabox_tabs['structured-data-types'] = __('Structured Data Types', 'siteseo'); } if(!empty($pro_settings['toggle_state_video_sitemap']) && !empty($pro_settings['enable_video_sitemap']) && !empty($show_content_analysis)){ $siteseo_metabox_tabs['video-sitemap'] = __('Video Sitemap', 'siteseo'); } if(!empty($pro_settings['toggle_state_google_news']) && !empty($pro_settings['google_news']) && !empty($show_content_analysis)){ $siteseo_metabox_tabs['google-news'] = __('Google News', 'siteseo'); } echo'<div id="siteseo-metabox-wrapper" class="siteseo-metabox-wrapper"> <div class="siteseo-metabox-tabs" data-home-id="'.esc_attr($data_attr['isHomeId']).'" data-term-id="'.esc_attr($data_attr['termId']).'" data_id="'.esc_attr($data_attr['current_id']).'" data_origin="'.esc_attr($data_attr['origin']).'" data_tax="'.esc_attr($data_attr['data_tax']).'">'; wp_nonce_field('siteseo_metabox_nonce', 'siteseo_metabox_nonce'); foreach($siteseo_metabox_tabs as $siteseo_metabox_tab => $siteseo_metabox_tab_title){ $selected_metabox_tab = ''; if($siteseo_metabox_tab === 'content-analysis'){ $selected_metabox_tab = 'siteseo-metabox-tab-label-active'; } if(empty($siteseo->display_ca_metaboxe) && $siteseo_metabox_tab === 'title-settings'){ $selected_metabox_tab = 'siteseo-metabox-tab-label-active'; } echo'<div class="siteseo-metabox-tab-label '.esc_attr($selected_metabox_tab).'" data-tab="siteseo-metabox-tab-'.esc_attr($siteseo_metabox_tab).'">'; if($siteseo_metabox_tab === 'advanced-settings' && !empty($metabox_data['robots_index'])){ echo'<span class="dashicons dashicons-hidden siteseo-noindex-warning"></span>'; } echo esc_html($siteseo_metabox_tab_title).'</div>'; } $home_url = home_url(); $parsed_home_url = wp_parse_url($home_url); $meta_desc_percentage = '1'; if(!empty($metabox_data['meta_desc'])){ $meta_desc_percentage = (strlen($metabox_data['meta_desc'])/160)*100; } elseif(!empty($metabox_data['excerpt'])){ $meta_desc_percentage = (strlen($metabox_data['excerpt'])/160)*100; } if(intval($meta_desc_percentage) > 100){ $meta_desc_percentage = '100'; } $meta_title_percentage = '1'; if(!empty($metabox_data['meta_title'])){ $meta_title_percentage = (strlen($metabox_data['meta_title'])/60)*100; } else if(!empty($metabox_data['title'])){ $meta_title_percentage = (strlen($metabox_data['title'])/60)*100; } if(intval($meta_title_percentage) > 100){ $meta_title_percentage = '100'; } echo'</div>'; if(empty($siteseo->advanced_settings['appearance_ca_metaboxe']) && $show_content_analysis){ echo'<div class="siteseo-sidebar-tabs siteseo-sidebar-tabs-opened"><span>'.esc_html__('Content Analysis', 'siteseo').'</span><span class="siteseo-sidebar-tabs-arrow"><span class="dashicons dashicons-arrow-down-alt2"></span></span></div> <div class="siteseo-metabox-tab-content-analysis siteseo-metabox-tab" style="display:block;">'; self::content_analysis($post); echo'</div>'; } $allowed_suggestion_tags = array( 'button' => array( 'class' => array(), 'type' => array(), ), 'span' => array( 'id' => array(), 'class' => array(), ), 'div' => array( 'class' => array(), 'style' => array(), ), 'input' => array( 'type' => array(), 'class' => true, 'placeholder' => true, ) ); echo'<div class="siteseo-sidebar-tabs '.(empty($siteseo->display_ca_metaboxe) ? 'siteseo-sidebar-tabs-opened' : '').'"><span>'.esc_html__('Title', 'siteseo').'</span><span class="siteseo-sidebar-tabs-arrow"><span class="dashicons dashicons-arrow-down-alt2"></span></span></div> <div class="siteseo-metabox-tab-title-settings siteseo-metabox-tab" style="'.(empty($siteseo->display_ca_metaboxe) ? 'display:block;' : '').'"> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label>'.esc_html__('Search Preview','siteseo').'</label> </div> <div class="siteseo-metabox-search-preview"> <div class="siteseo-search-preview-toggle"> <span id="siteseo-metabox-search-pc" style="display:none">'.esc_html__('Show Desktop version', 'siteseo').'</span> <span id="siteseo-metabox-search-mobile">'.esc_html__('Show Mobile version', 'siteseo').'</span> </div> <div class="siteseo-search-preview-desktop"> <div class="siteseo-search-preview-metadata"> <div style="background-color: #e2eeff; border: 1px solid #e2eeff; height:28px; width:28px; padding: 3px; border-radius: 50px; display:flex; align-items:center; justify-content:center;"> <svg focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#0060f0"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"></path></svg> </div> <div class="siteseo-search-preview-metadata-link"> <div>'.esc_url($parsed_home_url['host']).'</div> <div><cite>'.esc_url(home_url()).'</cite></div> </div> <div> <svg focusable="false" xmlns="http://www.w3.org/2000/svg" width="20" viewBox="0 0 24 24"><path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"></path></svg> </div> </div> <h3>'.(!empty($metabox_data['meta_title']) ? esc_html(\SiteSEO\TitlesMetas::replace_variables($metabox_data['meta_title'], true)) : (get_the_title() ? esc_html(get_the_title()) : 'Post Title here')).'</h3> <div class="siteseo-search-preview-description"> '.(!empty($metabox_data['meta_desc']) ? esc_html(\SiteSEO\TitlesMetas::replace_variables($metabox_data['meta_desc'], true)) : (!empty($metabox_data['excerpt']) ? esc_html(substr($metabox_data['excerpt'], 0, 160)) : 'Post description')).' </div> </div> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_titles_title_meta">'.esc_html__('Title', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <div class="siteseo-metabox-tags"> <button type="button" class="siteseo-metabox-tag" data-tag="%%post_title%%"><span class="dashicons dashicons-plus"></span> Post Title</button> <button type="button" class="siteseo-metabox-tag" data-tag="%%sitetitle%%"><span class="dashicons dashicons-plus"></span> Site Title</button> <button type="button" class="siteseo-metabox-tag" data-tag="%%sep%%"><span class="dashicons dashicons-plus"></span>Seperator</button>'.wp_kses(siteseo_suggestion_button_metabox(), $allowed_suggestion_tags).' </div> <input type="text" id="siteseo_titles_title_meta" class="siteseo_titles_title_meta" name="siteseo_titles_title" placeholder="'.(!empty($metabox_data['title']) ? esc_attr($metabox_data['title']) : esc_html__('Enter title for this post', 'siteseo')).'" value="'.(!empty($metabox_data['meta_title']) ? esc_html($metabox_data['meta_title']) : '').'"/> <div class="siteseo-metabox-limits"> <span class="siteseo-metabox-limits-meter"><span style="width:'.esc_attr($meta_title_percentage).'%"></span></span> <span class="siteseo-metabox-limits-numbers"><em>'.esc_html(strlen($metabox_data['meta_title'])).'</em> out of 60 max recommended characters</span> </div> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_titles_desc_meta">'.esc_html__('Meta Description', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <div class="siteseo-metabox-tags"> <button type="button" class="siteseo-metabox-tag" data-tag="%%post_excerpt%%"><span class="dashicons dashicons-plus"></span> Post Excerpt</button>'.wp_kses(siteseo_suggestion_button_metabox(), $allowed_suggestion_tags).' </div> <textarea id="siteseo_titles_desc_meta" class="siteseo_titles_desc_meta" name="siteseo_titles_desc" rows="2" placeholder="'.esc_html__('Enter description for this post', 'siteseo').'">'.(!empty($metabox_data['meta_desc']) ? esc_html($metabox_data['meta_desc']) : '').'</textarea> <div class="siteseo-metabox-limits"> <span class="siteseo-metabox-limits-meter"><span style="width:'.esc_attr($meta_desc_percentage).'%"></span></span> <span class="siteseo-metabox-limits-numbers"><em>'.esc_html(strlen($metabox_data['meta_desc'])).'</em> out of 160 max recommended characters</span> </div> </div> </div> </div> <div class="siteseo-sidebar-tabs"><span>'.esc_html__('Social', 'siteseo').'</span><span class="siteseo-sidebar-tabs-arrow"><span class="dashicons dashicons-arrow-down-alt2"></span></span></div> <div class="siteseo-metabox-tab-social-settings siteseo-metabox-tab"> <div class="siteseo-metabox-subtabs"> <div class="siteseo-metabox-tab-label siteseo-metabox-tab-label-active" data-tab="siteseo-metabox-tab-fb-settings">Facebook</div> <div class="siteseo-metabox-tab-label" data-tab="siteseo-metabox-tab-x-settings">X(Twitter)</div> </div> <div class="siteseo-metabox-tab-fb-settings siteseo-metabox-tab" style="display:block;"> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label>'.esc_html__('Preview', 'siteseo').'</label> </div> <div class="siteseo-metabox-fb-preview"> <div class="siteseo-metabox-fb-image"> <img src="'.(!empty($metabox_data['fb_img']) ? esc_url($metabox_data['fb_img']) : esc_url($social_placeholder)).'" alt="Facebook preview" load="lazy"/> </div> <div class="siteseo-metabox-fb-data"> <div class="siteseo-metabox-fb-host">'.(!empty($host_uri) ? esc_html($host_uri) : '').'</div> <div class="siteseo-metabox-fb-title">'.(!empty($metabox_data['fb_title']) ? esc_html(\SiteSEO\TitlesMetas::replace_variables($metabox_data['fb_title'], true)) : esc_html(\SiteSEO\TitlesMetas::replace_variables($social_preview_title, true))).'</div> <div class="siteseo-metabox-fb-desc">'.(!empty($metabox_data['fb_desc']) ? esc_html(\SiteSEO\TitlesMetas::replace_variables($metabox_data['fb_desc'], true)) : esc_html(\SiteSEO\TitlesMetas::replace_variables($social_preview_desc, true))).'</div> </div> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_social_fb_title_meta">'.esc_html__('Facebook Title', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <input type="text" id="siteseo_social_fb_title_meta" class="siteseo_social_fb_title_meta" name="siteseo_social_fb_title" placeholder="'.(!empty($social_preview_title) ? esc_html(\SiteSEO\TitlesMetas::replace_variables($social_preview_title, true)) : '').'" value="'.(!empty($metabox_data['fb_title']) ? esc_attr($metabox_data['fb_title']) : '').'" /> <div class="siteseo-metabox-tags"> <button type="button" class="siteseo-facebook-title" data-tag="%%post_title%%"><span class="dashicons dashicons-plus"></span> Post Title</button> <button type="button" class="siteseo-facebook-title" data-tag="%%sitetitle%%"><span class="dashicons dashicons-plus"></span> Site Title</button> <button type="button" class="siteseo-facebook-title" data-tag="%%sep%%"><span class="dashicons dashicons-plus"></span>Seperator</button>'.wp_kses(siteseo_suggestion_button_metabox(), $allowed_suggestion_tags).' </div> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_social_fb_desc_meta">'.esc_html__('Facebook description', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <textarea id="siteseo_social_fb_desc_meta" class="siteseo_social_fb_desc_meta" name="siteseo_social_fb_desc" rows="2" placeholder="'.(!empty($social_preview_desc) ? esc_html(\SiteSEO\TitlesMetas::replace_variables($social_preview_desc, true)) : '').'">'.(!empty($metabox_data['fb_desc']) ? esc_html($metabox_data['fb_desc']) : '').'</textarea> <div class="siteseo-metabox-tags"> <button type="button" class="siteseo-facebook-desc" data-tag="%%post_excerpt%%"><span class="dashicons dashicons-plus"></span> Post Excerpt</button>'.wp_kses(siteseo_suggestion_button_metabox(), $allowed_suggestion_tags).' </div> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_social_fb_img_meta">'.esc_html__('Facebook Thumbnail', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <span style="color:red; font-weight:bold; display:none;"></span> <input type="text" id="siteseo_social_fb_img_meta" name="siteseo_social_fb_img" class="siteseo_social_fb_img_meta" placeholder="'.esc_html__('Enter URL of the Image you want to be shown as the Facebook image', 'siteseo').'" value="'.(!empty($metabox_data['fb_img']) ? esc_url($metabox_data['fb_img']) : '').'"/> <p class="description">'.esc_html__('Minimum size: 200x200px, ideal ratio 1.91:1, 8Mb max. (eg: 1640x856px or 3280x1712px for retina screens).', 'siteseo').'</p> <input type="hidden" name="siteseo_social_fb_img_attachment_id" id="siteseo_social_fb_img_attachment_id" class="siteseo_social_fb_img_attachment_id" value=""> <input type="hidden" name="siteseo_social_fb_img_width" id="siteseo_social_fb_img_width" class="siteseo_social_fb_img_width" value=""> <input type="hidden" name="siteseo_social_fb_img_height" id="siteseo_social_fb_img_height" class="siteseo_social_fb_img_height" value=""> <button class="components-button is-secondary" id="siteseo_social_fb_img_upload">Upload Image</button> </div> </div> </div> <div class="siteseo-metabox-tab-x-settings siteseo-metabox-tab"> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label>'.esc_html__('Preview','siteseo').'</label> </div> <div> <div class="siteseo-metabox-x-preview"> <div class="siteseo-metabox-x-image"> <img src="'.(!empty($metabox_data['x_img']) ? esc_url($metabox_data['x_img']) : esc_url($social_placeholder)).'" alt="X preview" load="lazy"/> </div> <div class="siteseo-metabox-x-data"> <div class="siteseo-metabox-x-title">'.(!empty($metabox_data['x_title']) ? esc_html(\SiteSEO\TitlesMetas::replace_variables($metabox_data['x_title'], true)) : esc_html(\SiteSEO\TitlesMetas::replace_variables($social_preview_title, true))).'</div> </div> </div> <div class="siteseo-metabox-x-host">From '.(!empty($host_uri) ? esc_html($host_uri) : '').'</div> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_social_twitter_title_meta">'.esc_html__('X Title', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <input type="text" id="siteseo_social_twitter_title_meta" class="siteseo_social_twitter_title_meta" name="siteseo_social_twitter_title" placeholder="'.(!empty($social_preview_title) ? esc_html(\SiteSEO\TitlesMetas::replace_variables($social_preview_title, true)) : '').'" value="'.(!empty($metabox_data['x_title']) ? esc_attr($metabox_data['x_title']) : '').'" /> <div class="siteseo-metabox-tags"> <button type="button" class="siteseo-x-title" data-tag="%%post_title%%"><span class="dashicons dashicons-plus"></span> Post Title</button> <button type="button" class="siteseo-x-title" data-tag="%%sitetitle%%"><span class="dashicons dashicons-plus"></span> Site Title</button> <button type="button" class="siteseo-x-title" data-tag="%%sep%%"><span class="dashicons dashicons-plus"></span>Seperator</button>'.wp_kses(siteseo_suggestion_button_metabox(), $allowed_suggestion_tags).' </div> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_social_twitter_desc_meta">'.esc_html__('X description', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <textarea id="siteseo_social_twitter_desc_meta" class="siteseo_social_twitter_desc_meta" name="siteseo_social_twitter_desc" rows="2" placeholder="'.(!empty($social_preview_desc) ? esc_html(\SiteSEO\TitlesMetas::replace_variables($social_preview_desc, true)) : '').'">'.(!empty($metabox_data['x_desc']) ? esc_attr($metabox_data['x_desc']) : '').'</textarea> <div class="siteseo-metabox-tags"> <button type="button" class="siteseo-x-desc" data-tag="%%post_excerpt%%"><span class="dashicons dashicons-plus"></span> Post Excerpt</button>'.wp_kses(siteseo_suggestion_button_metabox(), $allowed_suggestion_tags).' </div> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_social_twitter_img_meta">'.esc_html__('X Thumbnail', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <span style="color:red; font-weight:bold; display:none;"></span> <input type="text" id="siteseo_social_twitter_img_meta" class="siteseo_social_twitter_img_meta" name="siteseo_social_twitter_img" placeholder="'.esc_html__('Enter URL of the Image you want to be shown as the X image', 'siteseo').'" value="'.(!empty($metabox_data['x_img']) ? esc_attr($metabox_data['x_img']) : '').'" /> <p class="description">'.esc_html__('Minimum size: 144x144px (300x157px with large card enabled), ideal ratio 1:1 (2:1 with large card), 5Mb max.', 'siteseo').'</p> <input type="hidden" name="siteseo_social_twitter_img_attachment_id" id="siteseo_social_twitter_img_attachment_id" class="siteseo_social_twitter_img_attachment_id" value=""> <input type="hidden" name="siteseo_social_twitter_img_width" id="siteseo_social_twitter_img_width" class="siteseo_social_twitter_img_width" value=""> <input type="hidden" name="siteseo_social_twitter_img_height" id="siteseo_social_twitter_img_height" class="siteseo_social_twitter_img_height" value=""> <button class="components-button is-secondary" id="siteseo_social_twitter_img_upload">Upload Image</button> </div> </div> </div> </div>'; if(!empty($pro_settings['enable_structured_data']) && !empty($pro_settings['toggle_state_stru_data']) && !empty($show_content_analysis)){ echo'<div class="siteseo-sidebar-tabs"><span>'.esc_html__('Structured Data Types', 'siteseo').'</span><span class="siteseo-sidebar-tabs-arrow"><span class="dashicons dashicons-arrow-down-alt2"></span></span></div> <div class="siteseo-metabox-tab-structured-data-types siteseo-metabox-tab">'; // Pro fearure do_action('siteseo_display_structured_data_types'); echo'</div>'; } // video sitemap if(!empty($pro_settings['toggle_state_video_sitemap']) && !empty($pro_settings['enable_video_sitemap']) && !empty($show_content_analysis)){ echo'<div class="siteseo-sidebar-tabs"><span>'.esc_html__('Video Sitemap', 'siteseo').'</span><span class="siteseo-sidebar-tabs-arrow"><span class="dashicons dashicons-arrow-down-alt2"></span></span></div> <div class="siteseo-metabox-tab-video-sitemap siteseo-metabox-tab">'; do_action('siteseo_display_video_sitemap'); echo'</div>'; } // gooogle news exclude if(!empty($pro_settings['toggle_state_google_news']) && !empty($pro_settings['google_news']) && !empty($show_content_analysis)){ echo'<div class="siteseo-sidebar-tabs"><span>'.esc_html__('Google News', 'siteseo').'</span><span class="siteseo-sidebar-tabs-arrow"><span class="dashicons dashicons-arrow-down-alt2"></span></span></div> <div class="siteseo-metabox-tab-google-news siteseo-metabox-tab">'; do_action('siteseo_display_google_news'); echo'</div>'; } echo'<div class="siteseo-sidebar-tabs"><span>'; if(!empty($metabox_data['robots_index'])){ echo'<span class="dashicons dashicons-hidden siteseo-noindex-warning"></span>'; } echo esc_html__('Advanced', 'siteseo').'</span><span class="siteseo-sidebar-tabs-arrow"><span class="dashicons dashicons-arrow-down-alt2"></span></span></div> <div class="siteseo-metabox-tab-advanced-settings siteseo-metabox-tab"> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_social_twitter_img_meta">'.esc_html__('Meta Robots Settings', 'siteseo').'</label> <p class="description">'. /* translators: %s represents the degree of severity */ wp_kses_post(sprintf(__('You cannot uncheck a checkbox? This is normal, and it\'s most likely defined in the <a href="%s">global settings of the plugin.</a>', 'siteseo'), esc_url(admin_url('admin.php?page=siteseo-titles#tab=tab_siteseo_titles_single')))).'</p> </div> <div class="siteseo-metabox-input-wrap">'; $robots_options = [ 'siteseo_robots_index_meta' => [ 'desc' => __('Do not display this page in search engine results / Sitemaps', 'siteseo'), 'short' => 'noindex', 'name' => 'siteseo_robots_index', 'checked' => $metabox_data['robots_index'], 'disabled' => $metabox_data['disabled_robots']['robots_index'] ], 'siteseo_robots_follow_meta' => [ 'desc' => __('Do not follow links for this page', 'siteseo'), 'short' => 'nofollow', 'name' => 'siteseo_robots_follow', 'checked' => $metabox_data['robots_follow'], 'disabled' => $metabox_data['disabled_robots']['robots_follow'] ], 'siteseo_robots_imageindex_meta' => [ 'desc' => __('Do not index images for this page', 'siteseo'), 'short' => 'noimageindex', 'name' => 'siteseo_robots_imageindex', 'checked' => $metabox_data['robots_imageindex'], 'disabled' => $metabox_data['disabled_robots']['imageindex'] ], 'siteseo_robots_archive_meta' => [ 'desc' => __('Do not display a "Cached" link in the Google search results', 'siteseo'), 'short' => 'noarchive', 'name' => 'siteseo_robots_archive', 'checked' => $metabox_data['robots_archive'], 'disabled' => $metabox_data['disabled_robots']['archive'] ], 'siteseo_robots_snippet_meta' => [ 'desc' => __('Do not display a description in search results for this page', 'siteseo'), 'short' => 'nosnippet', 'name' => 'siteseo_robots_snippet', 'checked' => $metabox_data['robots_snippet'], 'disabled' => $metabox_data['disabled_robots']['snippet'] ] ]; foreach($robots_options as $robots_id => $robots_option){ $checked = ''; if(!empty($robots_option['checked'])){ $checked = 'checked'; } $disabled = ''; if(!empty($robots_option['disabled'])){ $disabled = 'disabled'; $robots_option['name'] = ''; } echo'<label for="'.esc_attr($robots_id).'" style="display:block; margin-bottom:5px;"> <input type="checkbox" value="yes" id="'.esc_attr($robots_id).'" class="siteseo-metabox-robots-options" name="'.esc_attr($robots_option['name']).'" '.esc_attr($checked).' '.esc_attr($disabled).'/> '.esc_html($robots_option['desc']).' ('.esc_html($robots_option['short']).') </label>'; } echo'</div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_robots_canonical_meta">'.esc_html__('Canonical URL', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <input id="siteseo_robots_canonical_meta" type="text" name="siteseo_robots_canonical" placeholder="'.esc_url(get_the_permalink()).'" value="'.(!empty($metabox_data['robots_canonical']) ? esc_html($metabox_data['robots_canonical']) : '').'"> </div> </div>'; if(!empty($pagenow) && !empty($typenow) && ($pagenow == 'post.php' || $pagenow == 'post-new.php') && ($typenow == 'post' || $typenow == 'product')){ $categories = (object)[]; if($typenow == 'product'){ $categories = get_the_terms($post, 'product_cat'); } else{ $categories = get_categories(); } if(!empty($categories) && !is_wp_error($categories)){ echo'<div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_robots_canonical_meta">'.esc_html__('Select a primary category', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <select id="siteseo_robots_primary_cat" name="siteseo_robots_primary_cat">'; foreach($categories as $category){ $selected = ''; if(!empty($metabox_data['robots_primary_cat']) && $metabox_data['robots_primary_cat'] == $category->term_id){ $selected = 'selected'; } echo'<option value="'.esc_attr($category->term_id).'" '.esc_attr($selected).'>'.esc_html($category->name).'</option>'; } echo'</select> </div> </div>'; } } echo'</div> <div class="siteseo-sidebar-tabs"><span>'.esc_html__('Redirects', 'siteseo').'</span> <span class="siteseo-sidebar-tabs-arrow"><span class="dashicons dashicons-arrow-down-alt2"></span> </span></div> <div class="siteseo-metabox-tab-redirect siteseo-metabox-tab"> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_redirections_enabled_meta">'.esc_html__('Enable redirection', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <input id="siteseo_redirections_enabled_meta" type="checkbox" name="siteseo_redirections_enabled" value="1" '.(!empty($metabox_data['redirections_enabled']) ? 'checked' : '').'> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_redirections_enabled_meta">'.esc_html__('Login status', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <select name="siteseo_redirections_logged_status" id="siteseo_redirections_logged_status"> <option value="both" '.(!empty($metabox_data['redirections_logged_status']) && $metabox_data['redirections_logged_status'] == 'both' ? 'selected' : '').'>'.esc_html__('All', 'siteseo').'</option> <option value="only_logged_in" '.(!empty($metabox_data['redirections_logged_status']) && $metabox_data['redirections_logged_status'] == 'only_logged_in' ? 'selected' : '').'>'.esc_html__('Only when logged In', 'siteseo').'</option> <option value="only_not_logged_in" '.(!empty($metabox_data['redirections_logged_status']) && $metabox_data['redirections_logged_status'] == 'only_not_logged_in' ? 'selected' : '').'>'.esc_html__('Only when not logged in', 'siteseo').'</option> </select> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_redirections_type">'.esc_html__('Redirection Type', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <select name="siteseo_redirections_type" id="siteseo_redirections_type"> <option value="301" '.(!empty($metabox_data['redirections_type']) && $metabox_data['redirections_type'] == '301' ? 'selected' : '').'>'.esc_html__('301 Moved Permanently', 'siteseo').'</option> <option value="302" '.(!empty($metabox_data['redirections_type']) && $metabox_data['redirections_type'] == '302' ? 'selected' : '').'>'.esc_html__('302 Found / Moved Temporarily', 'siteseo').'</option> <option value="307" '.(!empty($metabox_data['redirections_type']) && $metabox_data['redirections_type'] == '307' ? 'selected' : '').'>'.esc_html__('307 Moved Temporarily', 'siteseo').'</option>'; if($typenow === 'siteseo_404'){ echo'<option value="410" '.(!empty($metabox_data['redirections_type']) && $metabox_data['redirections_type'] == '410' ? 'selected' : '').'>'.esc_html__('410 Gone', 'siteseo').'</option> <option value="451" '.(!empty($metabox_data['redirections_type']) && $metabox_data['redirections_type'] == '451' ? 'selected' : '').'>'. esc_html__('451 Unavailable For Legal Reasons', 'siteseo').'</option>'; } echo'</select> </div> </div> <div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_redirections_value_meta">'.esc_html__('Redirection URL', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <input id="siteseo_redirections_value_meta" type="text" name="siteseo_redirections_value" value="'.(!empty($metabox_data['redirections_value']) ? esc_attr($metabox_data['redirections_value']): '').'"> </div> <input type="hidden" id="analysis_tabs" name="analysis_tabs" value="'.esc_html(wp_json_encode(array_keys($siteseo_metabox_tabs))).'"> </div>'; // Note if($typenow === 'siteseo_404'){ echo'<div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_redirections_param">'.esc_html__('Query parameters', 'siteseo').'</label> </div> <div class="siteseo-metabox-input-wrap"> <select name="siteseo_redirections_param" id="siteseo_redirections_param"> <option value="exact_match" '.(!empty($metabox_data['redirections_param']) && $metabox_data['redirections_param'] == 'exact_match' ? 'selected' : '').'>'.esc_html__('Exactly parameters with exact match', 'siteseo').'</option> <option value="without_param" '.(!empty($metabox_data['redirections_param']) && $metabox_data['redirections_param'] == 'without_param' ? 'selected' : '').'>'.esc_html__('Exclude all parameters', 'siteseo').'</option> <option value="with_ignored_param" '.(!empty($metabox_data['redirections_param']) && $metabox_data['redirections_param'] == 'with_ignored_param' ? 'selected' : '').'>'.esc_html__('Exclude all parameters and pass them to the redirection', 'siteseo').'</option> </select> </div> </div>'; } echo'</div> </div>'; } static function content_analysis($post){ wp_nonce_field('siteseo_ca_nonce', 'siteseo_content_analysis_nonce'); $siteseo_real_preview = [ 'siteseo_nonce' => wp_create_nonce('siteseo_real_preview_nonce'), 'siteseo_real_preview' => admin_url('admin-ajax.php'), 'i18n' => ['progress' => __('Analysis in progress...', 'siteseo')], 'ajax_url' => admin_url('admin-ajax.php'), 'get_preview_meta_title' => wp_create_nonce('get_preview_meta_title'), 'realtime_nonce' => wp_create_nonce('siteseo_realtime_nonce'), ]; $metabox_data = []; $metabox_data['analysis_target_kw'] = get_post_meta($post->ID, '_siteseo_analysis_target_kw', true); $metabox_data['analysis_data'] = get_post_meta($post->ID, '_siteseo_analysis_data', true); $metabox_data['readibility_data'] = get_post_meta($post->ID, '_siteseo_readibility_data', true); $metabox_data['meta_title'] = get_post_meta($post->ID, '_siteseo_titles_title', true); $metabox_data['meta_desc'] = get_post_meta($post->ID, '_siteseo_titles_desc', true); $title_options = get_option('siteseo_titles_option_name', []); if(self::titles_single_cpt_noindex_option() || !empty($title_options['titles_noindex']) || true === post_password_required($post->ID)){ $metabox_data['robots_index'] = 'yes'; } else { $metabox_data['robots_index'] = get_post_meta($post->ID, '_siteseo_robots_index', true); } if(post_password_required($post->ID) === true || !empty($title_options['titles_noindex']) || self::titles_single_cpt_noindex_option()){ $metabox_data['robots_index'] = 'yes'; } else{ $metabox_data['robots_index'] = get_post_meta($post->ID, '_siteseo_robots_index', true); } if(!empty($title_options['titles_nofollow']) || self::titles_single_cpt_nofollow_option()){ $metabox_data['robots_follow'] = 'yes'; } else{ $metabox_data['robots_follow'] = get_post_meta($post->ID, '_siteseo_robots_follow', true); } if(!empty($title_options['titles_noarchive'])){ $metabox_data['robots_archive'] = 'yes'; } else{ $metabox_data['robots_archive'] = get_post_meta($post->ID, '_siteseo_robots_archive', true); } if(!empty($title_options['titles_nosnippet'])){ $metabox_data['robots_snippet'] = 'yes'; } else{ $metabox_data['robots_snippet'] = get_post_meta($post->ID, '_siteseo_robots_snippet', true); } if(!empty($title_options['titles_noimageindex'])){ $metabox_data['robots_imageindex'] = 'yes'; } else{ $metabox_data['robots_imageindex'] = get_post_meta($post->ID, '_siteseo_robots_imageindex', true); } $metabox_data['post_id'] = $post->ID; $metabox_data['readibility_data'] = get_post_meta($post->ID, '_siteseo_readibility_data', true); self::siteseo_content_analysis_tab($metabox_data); } static function titles_single_cpt_nofollow_option(){ $siteseo_get_current_cpt = get_post_type(); $options = get_option('siteseo_titles_option_name'); if(!empty($options) && isset($options['titles_single_titles'][$siteseo_get_current_cpt]['nofollow'])){ return $options['titles_single_titles'][$siteseo_get_current_cpt]['nofollow']; } } static function btn_secondary_classes() { //Classic Editor compatibility global $pagenow; $current_screen = null; if(function_exists('get_current_screen')){ $current_screen = get_current_screen(); } if(!empty($current_screen) && method_exists($current_screen, 'is_block_editor') && true === $current_screen->is_block_editor()){ $btn_classes_secondary = 'components-button is-secondary'; } elseif(isset($pagenow) && ($pagenow === 'term.php' || $pagenow === 'post.php' || $pagenow === 'post-new.php')){ $btn_classes_secondary = 'button button-secondary'; } else{ $btn_classes_secondary = 'btn btnSecondary'; } return $btn_classes_secondary; } static function siteseo_content_analysis_tab(&$metabox_data){ global $post; echo '<div class="siteseo-metabox-option-wrap"> <div class="siteseo-metabox-label-wrap"> <label for="siteseo_titles_title_meta">' . esc_html__('Focus Keywords', 'siteseo') . '</label> </div> <div class="siteseo-metabox-input-wrap"> <div id="siteseo_tags_wrapper" style="display: flex; flex-wrap: wrap; gap: 5px; padding: 5px; border: 1px solid #ccc; border-radius: 5px;">'; if(!empty($metabox_data['analysis_target_kw'])){ $tags_arr = explode(',', $metabox_data['analysis_target_kw']); if(!empty($tags_arr) && is_array($tags_arr)){ foreach($tags_arr as $tag_name){ echo '<span class="siteseo-tag">'.esc_html($tag_name).'<span class="siteseo-remove-tag">×</span></span>'; } } } echo '<input id="siteseo_analysis_target_kw_meta" class="siteseo_analysis_target_kw_meta" type="text" placeholder="' . esc_html__('Enter your target keywords', 'siteseo') . '" style="border: none; outline: none; flex: 1; min-width: 150px;" /> <input type="hidden" id="siteseo_tags_hidden" name="siteseo_analysis_target_kw" value="' . (!empty($metabox_data['analysis_target_kw']) ? esc_attr($metabox_data['analysis_target_kw']) : '') . '" /> </div> <p class="description">Press <kbd>Enter</kbd> key on your keyboard to add keyword</p> <button id="siteseo_refresh_seo_analysis" type="button" style="margin-top:10px;" class="'.esc_attr(self::btn_secondary_classes()).'" data_id="'.esc_attr(get_the_ID()).'" data_post_type="'.esc_attr(get_current_screen()->post_type).'"> '.esc_html__('Refresh analysis', 'siteseo').'</button> <p class="description">'.esc_html__('Refresh analysis after saving the post to improve the accuracy of the analysis', 'siteseo').'</p> </div> </div> <div id="siteseo-metabox-content-analysis"> <div id="siteseo-metabox-tabs-container"> <div class="siteseo-metabox-subtabs"> <div class="siteseo-metabox-tab-label siteseo-metabox-tab-label-active" data-tab="siteseo-metabox-seo-analysis-tab">'. esc_html__('SEO Analysis', 'siteseo').'</div> <div class="siteseo-metabox-tab-label" data-tab="siteseo-metabox-readibility-analysis-tab">'.esc_html__('Content Readability', 'siteseo').'</div> </div> <div id="siteseo-metabox-tab-content"> <div class="siteseo-metabox-seo-analysis-tab siteseo-metabox-tab" style="display:block;">'; $post_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : 0; $post = get_post($post_id); Analysis::display_seo_analysis($post); echo'</div> <div class="siteseo-metabox-readibility-analysis-tab siteseo-metabox-tab"> <p class="description">' . esc_html__('This section works as a guide to help you write, better content for your user, this do not have a direct affect on SEO, but it will help you write better content for your users which will help user stay on your site longer, or will improve the Click Through rate. Which will signal search engines about the userfulness and likeleyness of your content by your user which indirectly improve SEO of the page.', 'siteseo') . '</p>'; Analysis::display_content_readibility($metabox_data); echo'</div> </div> </div> </div>'; } static function titles_single_cpt_noindex_option(){ $siteseo_get_current_cpt = get_post_type(); $options = get_option('siteseo_titles_option_name'); if(!empty($options) && isset($options['titles_single_titles'][$siteseo_get_current_cpt]['noindex'])){ return $options['titles_single_titles'][$siteseo_get_current_cpt]['noindex']; } } static function save_ca_metabox($post_id, $post){ if(!isset($_POST['siteseo_content_analysis_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['siteseo_content_analysis_nonce'])), 'siteseo_ca_nonce')){ return $post_id; } // Post type object $post_type = get_post_type_object($post->post_type); //Check permission if(!current_user_can($post_type->cap->edit_post, $post_id) || !siteseo_user_can_metabox()){ return $post_id; } if('attachment' !== get_post_type($post_id)){ if(isset($_POST['siteseo_analysis_target_kw'])){ update_post_meta($post_id, '_siteseo_analysis_target_kw', self::clean_post('siteseo_analysis_target_kw')); } else{ delete_post_meta($post_id, '_siteseo_analysis_target_kw'); } } } static function save_metabox($post_id, $post){ global $siteseo; // Security Check if(!isset($_POST['siteseo_metabox_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['siteseo_metabox_nonce'])), 'siteseo_metabox_nonce')){ return $post_id; } //Post type object $post_type = get_post_type_object($post->post_type); //Check permission if(!current_user_can($post_type->cap->edit_post, $post_id) || !siteseo_user_can_metabox()){ return $post_id; } if('attachment' !== get_post_type($post_id)){ $analysis_tabs = []; $analysis_tabs = json_decode(self::clean_post('analysis_tabs'), true); if(!empty($analysis_tabs) && is_array($analysis_tabs) && in_array('content-analysis', $analysis_tabs)){ if(!empty($_POST['siteseo_analysis_target_kw'])){ update_post_meta($post_id, '_siteseo_analysis_target_kw', self::clean_post('siteseo_analysis_target_kw')); } else{ delete_post_meta($post_id, '_siteseo_analysis_target_kw'); } } if(!empty($analysis_tabs) && is_array($analysis_tabs) && in_array('title-settings', $analysis_tabs)){ if(!empty($_POST['siteseo_titles_title'])){ update_post_meta($post_id, '_siteseo_titles_title', self::clean_post('siteseo_titles_title')); } else{ delete_post_meta($post_id, '_siteseo_titles_title'); } if(!empty($_POST['siteseo_titles_desc'])){ update_post_meta($post_id, '_siteseo_titles_desc', self::clean_post('siteseo_titles_desc')); } else{ delete_post_meta($post_id, '_siteseo_titles_desc'); } } if(!empty($analysis_tabs) && is_array($analysis_tabs) && in_array('advanced-settings', $analysis_tabs)){ if(isset($_POST['siteseo_robots_index'])){ update_post_meta($post_id, '_siteseo_robots_index', 'yes'); } else{ delete_post_meta($post_id, '_siteseo_robots_index'); } if(isset($_POST['siteseo_robots_follow'])){ update_post_meta($post_id, '_siteseo_robots_follow', 'yes'); } else{ delete_post_meta($post_id, '_siteseo_robots_follow'); } if(isset($_POST['siteseo_robots_imageindex'])){ update_post_meta($post_id, '_siteseo_robots_imageindex', 'yes'); } else{ delete_post_meta($post_id, '_siteseo_robots_imageindex'); } if(isset($_POST['siteseo_robots_archive'])){ update_post_meta($post_id, '_siteseo_robots_archive', 'yes'); } else{ delete_post_meta($post_id, '_siteseo_robots_archive'); } if(isset($_POST['siteseo_robots_snippet'])){ update_post_meta($post_id, '_siteseo_robots_snippet', 'yes'); } else{ delete_post_meta($post_id, '_siteseo_robots_snippet'); } if(!empty($_POST['siteseo_robots_canonical'])){ update_post_meta($post_id, '_siteseo_robots_canonical', self::clean_post('siteseo_robots_canonical')); } else{ delete_post_meta($post_id, '_siteseo_robots_canonical'); } if(!empty($_POST['siteseo_robots_primary_cat'])){ update_post_meta($post_id, '_siteseo_robots_primary_cat', self::clean_post('siteseo_robots_primary_cat')); } else{ delete_post_meta($post_id, '_siteseo_robots_primary_cat'); } } if(!empty($analysis_tabs) && is_array($analysis_tabs) && in_array('social-settings', $analysis_tabs)){ //Facebook if(!empty($_POST['siteseo_social_fb_title'])){ update_post_meta($post_id, '_siteseo_social_fb_title', self::clean_post('siteseo_social_fb_title')); } else{ delete_post_meta($post_id, '_siteseo_social_fb_title'); } if(!empty($_POST['siteseo_social_fb_desc'])){ update_post_meta($post_id, '_siteseo_social_fb_desc', self::clean_post('siteseo_social_fb_desc')); } else{ delete_post_meta($post_id, '_siteseo_social_fb_desc'); } if(!empty($_POST['siteseo_social_fb_img'])){ update_post_meta($post_id, '_siteseo_social_fb_img', self::clean_post('siteseo_social_fb_img')); } else{ delete_post_meta($post_id, '_siteseo_social_fb_img'); } if(!empty($_POST['siteseo_social_fb_img_attachment_id']) && !empty($_POST['siteseo_social_fb_img'])){ update_post_meta($post_id, '_siteseo_social_fb_img_attachment_id', self::clean_post('siteseo_social_fb_img_attachment_id')); } else{ delete_post_meta($post_id, '_siteseo_social_fb_img_attachment_id'); } if(!empty($_POST['siteseo_social_fb_img_width']) && !empty($_POST['siteseo_social_fb_img'])){ update_post_meta($post_id, '_siteseo_social_fb_img_width', self::clean_post('siteseo_social_fb_img_width')); } else{ delete_post_meta($post_id, '_siteseo_social_fb_img_width'); } if(!empty($_POST['siteseo_social_fb_img_height']) && !empty($_POST['siteseo_social_fb_img'])){ update_post_meta($post_id, '_siteseo_social_fb_img_height', self::clean_post('siteseo_social_fb_img_height')); } else{ delete_post_meta($post_id, '_siteseo_social_fb_img_height'); } //Twitter if(!empty($_POST['siteseo_social_twitter_title'])){ update_post_meta($post_id, '_siteseo_social_twitter_title', self::clean_post('siteseo_social_twitter_title')); } else{ delete_post_meta($post_id, '_siteseo_social_twitter_title'); } if(!empty($_POST['siteseo_social_twitter_desc'])){ update_post_meta($post_id, '_siteseo_social_twitter_desc', self::clean_post('siteseo_social_twitter_desc')); } else{ delete_post_meta($post_id, '_siteseo_social_twitter_desc'); } if(!empty($_POST['siteseo_social_twitter_img'])){ update_post_meta($post_id, '_siteseo_social_twitter_img', self::clean_post('siteseo_social_twitter_img')); } else{ delete_post_meta($post_id, '_siteseo_social_twitter_img'); } if(!empty($_POST['siteseo_social_twitter_img_attachment_id']) && !empty($_POST['siteseo_social_twitter_img'])){ update_post_meta($post_id, '_siteseo_social_twitter_img_attachment_id', self::clean_post('siteseo_social_twitter_img_attachment_id')); } else{ delete_post_meta($post_id, '_siteseo_social_twitter_img_attachment_id'); } if(!empty($_POST['siteseo_social_twitter_img_width']) && !empty($_POST['siteseo_social_twitter_img'])){ update_post_meta($post_id, '_siteseo_social_twitter_img_width', self::clean_post('siteseo_social_twitter_img_width')); } else{ delete_post_meta($post_id, '_siteseo_social_twitter_img_width'); } if(!empty($_POST['siteseo_social_twitter_img_height']) && !empty($_POST['siteseo_social_twitter_img'])){ update_post_meta($post_id, '_siteseo_social_twitter_img_height', self::clean_post('siteseo_social_twitter_img_height')); } else{ delete_post_meta($post_id, '_siteseo_social_twitter_img_height'); } } if(!empty($analysis_tabs) && is_array($analysis_tabs) && in_array('redirect', $analysis_tabs)){ if(isset($_POST['siteseo_redirections_type'])){ update_post_meta($post_id, '_siteseo_redirections_type', self::clean_post('siteseo_redirections_type')); } if(!empty($_POST['siteseo_redirections_value'])){ update_post_meta($post_id, '_siteseo_redirections_value', self::clean_post('siteseo_redirections_value')); } else{ delete_post_meta($post_id, '_siteseo_redirections_value'); } if(isset($_POST['siteseo_redirections_param'])){ update_post_meta($post_id, '_siteseo_redirections_param', self::clean_post('siteseo_redirections_param')); } if(isset($_POST['siteseo_redirections_enabled'])){ update_post_meta($post_id, '_siteseo_redirections_enabled', 'yes'); } else{ delete_post_meta($post_id, '_siteseo_redirections_enabled', ''); } if(isset($_POST['siteseo_redirections_enabled_regex'])){ update_post_meta($post_id, '_siteseo_redirections_enabled_regex', 'yes'); } else{ delete_post_meta($post_id, '_siteseo_redirections_enabled_regex'); } if(isset($_POST['siteseo_redirections_logged_status'])){ update_post_meta($post_id, '_siteseo_redirections_logged_status', self::clean_post('siteseo_redirections_logged_status')); } else{ delete_post_meta($post_id, '_siteseo_redirections_logged_status'); } } if(!empty($analysis_tabs) && is_array($analysis_tabs) && in_array('structured-data-types', $analysis_tabs)){ if(class_exists('\SiteSEOPro\StructuredData') && method_exists('\SiteSEOPro\StructuredData', 'save_metabox')){ \SiteSEOPro\StructuredData::save_metabox($post_id, $post); } } if(!empty($analysis_tabs) && is_array($analysis_tabs) && in_array('video-sitemap', $analysis_tabs)){ if(class_exists('\SiteSEOPro\VideoSitemap') && method_exists('\SiteSEOPro\VideoSitemap', 'save_video_sitemap')){ \SiteSEOPro\VideoSitemap::save_video_sitemap($post_id, $post); } } if(!empty($analysis_tabs) && is_array($analysis_tabs) && in_array('google-news', $analysis_tabs)){ if(class_exists('\SiteSEOPro\GoogleNews') && method_exists('\SiteSEOPro\GoogleNews', 'save_google_news')){ \SiteSEOPro\GoogleNews::save_google_news($post_id, $post); } } } } static function clean_post($name){ return self::clean_post_req($name); } static function clean_get($name){ return self::clean_post_req($name); } static function clean_post_req($name){ if(empty($name)){ return ''; } if(!isset($_REQUEST[$name])){ return ''; } if(is_array($_REQUEST[$name]) || is_object($_REQUEST[$name])){ return map_deep(wp_unslash($_REQUEST[$name]), 'sanitize_text_field'); } return sanitize_text_field(wp_unslash($_REQUEST[$name])); } static function universal(){ global $siteseo, $pagenow, $post; $post_id = !empty($_REQUEST['post']) ? (int) sanitize_text_field(wp_unslash($_REQUEST['post'])) : 0; if(empty($post_id)){ return; } if(!current_user_can('edit_post', $post_id)){ wp_die(esc_html__('You do not have access to edit this post', 'siteseo')); } $tmp_post = $post; $post = get_post($post_id); $tmp_pagenow = $pagenow; $pagenow = 'post.php'; if(empty($post)){ $post = $tmp_post; return; } set_current_screen($post->post_type); echo '<style>body{height: 100vh;} #wpcontent,#wpbody-content,html.wp-toolbar{padding:0;} .postbox .handle-order-higher, .postbox .handle-order-lower,#minor-publishing-actions,.site-menu-header{display:none !important;} #adminmenumain, #wpfooter, #wpadminbar{display:none;} #wpcontent{margin:auto;} #wpbody-content{position:relative;} .siteseo-metabox-tab{background-color:white;} .siteseo-meta-submit-container{position:fixed;bottom: 20px;right : 20px;} #siteseo_cpt form {position:relative;}.siteseo-btn{display: inline-flex;padding: 0.5rem 1rem;gap: 0.5rem;justify-content: center;align-items: center;border-radius: 0.375rem;font-size: 0.875rem;line-height: 1.25rem;font-weight: 500;white-space: nowrap;cursor:pointer;box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);border:none;text-decoration:none; text-align:center;}.siteseo-btn.primary{background-color:#141b38;color:white;} .siteseo-spinner{display:none;border-radius:50%;animation: siteseo-spinner 1s linear infinite;height: 0.9375rem;width: 0.9375rem;border: 2px solid #dddcdc80;border-left-color: #e3e3e3;} .siteseo-spinner-active{display:inline-block;} @keyframes siteseo-spinner{ 0% { transform: rotate(0deg);} 100% {transform: rotate(360deg);}} .components-button{align-items: center; -webkit-appearance: none; background: none; border: 0; border-radius: 2px; box-sizing: border-box; color:#1e1e1e; cursor: pointer;display: inline-flex; font-family: inherit; font-size: 13px; font-weight: 400; height: 36px; margin: 0; padding: 6px 12px; text-decoration: none; transition: box-shadow .1s linear;}.components-button.is-secondary {background: #0000; box-shadow: inset 0 0 0 1px #3858e9; color:#3858e9; outline: 1px solid #0000; white-space: nowrap;}.siteseo-sidebar-tabs{display:none;} .notice, .update-nag{ display: none !important;}</style> <div id="siteseo_cpt"><form id="siteseo-universal-post" action="post.php" method="post"> <input type="hidden" name="post_id" value="'.esc_attr($post_id).'"/>'; wp_nonce_field('siteseo_universal_nonce', 'security'); self::render_metabox(); echo '<div class="siteseo-meta-submit-container"> <button type="submit" class="siteseo-btn primary">'.esc_html__('Save Changes', 'siteseo').'<span class="siteseo-spinner"></span></button> </div></form></div> <script> jQuery(document).ready(function(){ jQuery("#siteseo-universal-post").on("submit", function(event){ event.preventDefault(); let jEle = jQuery(event.target), spinner = jEle.find(".siteseo-spinner"), formData = {}; jQuery(this).serializeArray().forEach(field => { formData[field.name] = field.value; }); formData["action"] = "siteseo_save_universal_metabox"; spinner.addClass("siteseo-spinner-active"); jQuery.ajax({ method : "POST", url : "'.esc_url(admin_url('admin-ajax.php')).'", data : formData, success : function(res){ //console.log(res); } }).always(function(){ spinner.removeClass("siteseo-spinner-active"); }) }); }); </script>'; $post = $tmp_post; $pagenow = $tmp_pagenow; global $wp_version; if(!empty($wp_version) && version_compare($wp_version, '6.4', '>')){ remove_action('wp_footer', 'the_block_template_skip_link'); } wp_footer(); exit; } static function render_term_metabox($term){ $metabox_data = self::metabox_term_data($term); self::metabox_form_html($metabox_data); } static function save_meta_terms($term_id){ // Security Check if(!isset($_POST['siteseo_metabox_nonce']) || !wp_verify_nonce(self::clean_post('siteseo_metabox_nonce'), 'siteseo_metabox_nonce') ){ return $term_id; } // Getting taxonomy $term = get_term($term_id); $taxonomy = get_taxonomy($term->taxonomy); // Is this user allowed to make these changes if(!current_user_can($taxonomy->cap->edit_terms, $term_id)) { return $term_id; } $analysis_tabs = []; $analysis_tabs = json_decode(self::clean_post('analysis_tabs'), true); if(empty($analysis_tabs) || !is_array($analysis_tabs)){ return $term_id; } $tabs = [ 'title-settings' => [ 'siteseo_titles_title' => '_siteseo_titles_title', 'siteseo_titles_desc' => '_siteseo_titles_desc', ], 'advanced-settings' => [ 'siteseo_robots_index' => '_siteseo_robots_index', 'siteseo_robots_follow' => '_siteseo_robots_follow', 'siteseo_robots_imageindex'=> '_siteseo_robots_imageindex', 'siteseo_robots_archive' => '_siteseo_robots_archive', 'siteseo_robots_snippet' => '_siteseo_robots_snippet', 'siteseo_robots_canonical' => '_siteseo_robots_canonical', ], 'social-settings' => [ 'siteseo_social_fb_title' => '_siteseo_social_fb_title', 'siteseo_social_fb_desc' => '_siteseo_social_fb_desc', 'siteseo_social_fb_img' => '_siteseo_social_fb_img', 'siteseo_social_fb_img_attachment_id' => '_siteseo_social_fb_img_attachment_id', 'siteseo_social_fb_img_width' => '_siteseo_social_fb_img_width', 'siteseo_social_fb_img_height' => '_siteseo_social_fb_img_height', 'siteseo_social_twitter_title' => '_siteseo_social_twitter_title', 'siteseo_social_twitter_desc' => '_siteseo_social_twitter_desc', 'siteseo_social_twitter_img' => '_siteseo_social_twitter_img', ], 'redirect' => [ 'siteseo_redirections_type' => '_siteseo_redirections_type', 'siteseo_redirections_logged_status' => '_siteseo_redirections_logged_status', 'siteseo_redirections_value' => '_siteseo_redirections_value', 'siteseo_redirections_enabled' => '_siteseo_redirections_enabled', ] ]; // Save the key for all the options which are checkboxes $is_checkboxes = [ 'siteseo_robots_index', 'siteseo_robots_follow', 'siteseo_robots_imageindex', 'siteseo_robots_archive', 'siteseo_robots_snippet', 'siteseo_redirections_enabled', ]; foreach($tabs as $tab => $fields){ if(!in_array($tab, $analysis_tabs)){ continue; } foreach($fields as $post_key => $meta_key){ if(!empty($_POST[$post_key])){ $value = in_array($post_key, $is_checkboxes) ? 'yes' : self::clean_post($post_key); update_term_meta($term_id, $meta_key, $value); } else { delete_term_meta($term_id, $meta_key); } } } return $term_id; } } analysis.php 0000644 00000154204 15105564751 0007117 0 ustar 00 <?php /* * SITESEO * https://siteseo.io * (c) SiteSEO Team */ namespace SiteSEO\Metaboxes; if(!defined('ABSPATH')){ die('HACKING ATTEMPT!'); } class Analysis{ static function display_content_readibility($metabox_data){ if(empty($metabox_data) || !isset($metabox_data['post_id'])){ return; // Safeguard in case $metabox_data is incomplete or invalid. } $post_id = $metabox_data['post_id']; $readability_data = get_post_meta($post_id, '_siteseo_readibility_data', true); // Fetch and analyze readability data $analyzes = self::analyze_content($readability_data); // Render the readability data self::render_readibility($analyzes, $readability_data); } static function analyze_content($data){ $analyzes = []; // Analyze different aspects $analyzes = self::analyze_power_word($analyzes, $data); $analyzes = self::analyze_title_number($analyzes, $data); $analyzes = self::analyze_passive_voice($analyzes, $data); $analyzes = self::analyze_paragraph_length($analyzes, $data); return $analyzes; } static function analyze_power_word($analyzes, $data){ if(!empty($data['power_words'])){ $analyzes['power_words'] = [ 'desc' => '<p>'.__('Good: You have power words in your title.', 'siteseo').'</p>', 'impact' => 'good', 'title'=>'Power Word in title' ]; } else{ $analyzes['power_words'] = [ 'desc' => '<p>'.__('Consider adding power words to your title for better impact.', 'siteseo').'</p>', 'impact' => 'low', 'title'=> __('Power Word in title', 'siteseo') ]; } return $analyzes; } static function analyze_title_number($analyzes, $data){ if(!empty($data['number_found'])){ $analyzes['number_found'] = [ /* translators: %s is the number found in the title */ 'desc' => '<p>'.sprintf(__('Good: Your title contains the number "%s".', 'siteseo'), $data['number_found']).'</p>', 'impact' => 'good', 'title' => 'Number in title' ]; } else{ $analyzes['number_found'] = [ 'desc' => '<p>'.__('Consider adding a number to your title to improve CTR.', 'siteseo').'</p>', 'impact' => 'low', 'title' => 'Number in title' ]; } return $analyzes; } static function analyze_passive_voice($analyzes, $data){ //$analyzes['title'] ='Passive Voice'; if(empty($data['passive_voice'])){ $analyzes['passive_voice'] = [ 'desc' => '<p>'.__('Great: No passive voice detected.', 'siteseo').'</p>', 'impact' => 'good', 'title' => 'Passive Voice' ]; } else { $percentage = round(($data['passive_voice']['passive_sentences'] * 100) / $data['passive_voice']['total_sentences']); if($percentage <= 10){ $analyzes['passive_voice'] = [ /* translators: %s is the number found in the title */ 'desc' => '<p>'.sprintf(__('Good: Only %s%% of sentences use passive voice.', 'siteseo'), $percentage).'</p>', 'impact' => 'good', 'title' => 'Passive Voice' ]; } elseif($percentage < 20){ $analyzes['passive_voice'] = [ /* translators: %s is the percentage of sentences using passive voice */ 'desc' => '<p>'.sprintf(__('Okay: %s%% of sentences use passive voice. Try to reduce it.', 'siteseo'), $percentage).'</p>', 'impact' => 'medium', 'title' => 'Passive Voice' ]; } else{ $analyzes['passive_voice'] = [ /* translators: %s is the percentage of sentences using passive voice */ 'desc' => '<p>'.sprintf(__('High: %s%% of sentences use passive voice. Consider revising.', 'siteseo'), $percentage).'</p>', 'impact' => 'high', 'title' => 'Passive Voice' ]; } } return $analyzes; } static function analyze_paragraph_length($analyzes, $data){ if(empty($data['paragraph_length']) || $data['paragraph_length'] < 150){ $analyzes['paragraph_length'] = [ 'desc' => '<p>Good: Your paragraphs are concise.</p>', 'impact' => 'good', 'title' => 'Paragraph Length' ]; } else{ $analyzes['paragraph_length'] = [ /* translators: %s is the current paragraph length in words */ 'desc' => '<p>'.sprintf(__('Consider reducing paragraph length. Current length: %s words.', 'siteseo'), $data['paragraph_length']) . '</p>', 'impact' => 'low', 'title' => 'Paragraph Length' ]; } return $analyzes; } static function render_readibility($analyzes, $analysis_data, $echo = true){ $acceptable_svg = [ 'svg' => [ 'role' => true, 'aria-hidden' => true, 'focusable' => true, 'width' => true, 'height' => true, 'viewbox' => true, 'version' => true, 'xmlns' => true, 'fill' => true, ], 'path' => ['fill' => true, 'd' => true] ]; if(!empty($analyzes)){ $order = ['1' => 'high', '2' => 'medium', '3' => 'low', '4' => 'good']; usort($analyzes, function ($a, $b) use ($order) { return array_search($a['impact'], $order) - array_search($b['impact'], $order); }); // Define SVG icons $high_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9z"/></svg>'; $medium_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7 .2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8 .2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24V296c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z"/></svg>'; $good_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM369 209L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9z"/></svg>'; // Generate HTML $html = '<div id="siteseo-readibility-tabs">'; foreach($analyzes as $key => $value){ $impact_icon = ''; switch ($value['impact']) { case 'high': $impact_icon = $high_icon; break; case 'medium': case 'low': $impact_icon = $medium_icon; break; case 'good': $impact_icon = $good_icon; break; } $html .= '<div class="siteseo-analysis-block">'; $html .= '<div class="siteseo-analysis-block-title">'; $html .= '<div><span class="impact ' . esc_attr($value['impact']) .'" aria-hidden="true">' . $impact_icon . '</span>' . /* translators: %s represents the degree of severity */ '<span class="screen-reader-text">'. sprintf(esc_html__('Degree of severity: %s','siteseo'), esc_html($value['impact'])).'</span>' . esc_html($value['title']) . '</div>'; $html .= '<span class="siteseo-arrow" aria-hidden="true"></span></div>'; $html .= '<div class="siteseo-analysis-block-content">' . wp_kses_post($value['desc']) . '</div>'; $html .= '</div>'; } $html .= '</div>'; if($echo){ $allowed_html = array_merge(wp_kses_allowed_html('post'), $acceptable_svg); echo wp_kses($html, $allowed_html); return; } return $html; } } // Analaysis static function display_seo_analysis($post){ $seo_analysis = self::perform_seo_analysis($post); echo '<div id="siteseo-analysis-tabs"> <div id="siteseo-analysis-tabs-1"> <div class="siteseo-analysis-summary">'; if(!empty($seo_analysis)){ // grp usort($seo_analysis['checks'], function ($a, $b) { $order = ['error' => 0, 'warning' => 1, 'good' => 2]; $a_status_class = isset($a['status_class']) ? $a['status_class'] : ''; $b_status_class = isset($b['status_class']) ? $b['status_class'] : ''; $a_order = isset($order[$a_status_class]) ? $order[$a_status_class] : 3; $b_order = isset($order[$b_status_class]) ? $order[$b_status_class] : 3; return $a_order - $b_order; }); echo '<div class="siteseo-analysis-summary-pill">'; // counts logic if(!empty($seo_analysis['error_count'])){ echo '<span><svg fill="#f33" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M24 22h-24l12-20z"/></svg>'.esc_html($seo_analysis['error_count']). ' Errors</span>'; } if(!empty($seo_analysis['warning_count'])){ echo '<span><svg xmlns="http://www.w3.org/2000/svg" fill="#fa3" viewBox="0 0 448 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M0 96C0 60.7 28.7 32 64 32H384c35.3 0 64 28.7 64 64V416c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96z"/></svg>'.esc_html($seo_analysis['warning_count']). ' Warnings</span>'; } if(!empty($seo_analysis['good_count'])){ echo '<span><svg xmlns="http://www.w3.org/2000/svg" fill="#0c6" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z"/></svg><span>'.esc_html($seo_analysis['good_count']). ' Good</span></span>'; } echo '</div> </div><!-- .analysis-score -->'; // A triangle with exclamation in it. $medium_icon_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7 .2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8 .2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24V296c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z"/></svg>'; // A check inside a solid circle $good_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM369 209L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9z"/></svg>'; $high_icon_svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9z"/></svg>'; $allowed_svg_tags = ['svg' => ['xmlns' => true, 'viewbox' => true, 'width' => true, 'height' => true, 'class' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true], 'path' => ['d' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true]]; foreach($seo_analysis['checks'] as $check){ echo '<div class="siteseo-analysis-block">'; if(isset($check['label'])){ echo'<div class="siteseo-analysis-block-title">'; if(isset($check['status_class'])){ $impact_icon = ''; switch($check['status_class']){ case 'good': $impact_icon = $good_icon; break; case 'warning': $impact_icon = $medium_icon_svg; break; case 'error': $impact_icon = $high_icon_svg; break; } echo '<div><span class="impact '.esc_attr($check['status_class']).'" aria-hidden="true">'.wp_kses($impact_icon, $allowed_svg_tags).'</span> <span class="screen-reader-text">'. /* translators: %s represents the degree of severity */ sprintf(esc_html__('Degree of severity: %s','siteseo'), esc_html($check['status_class'])).'</span>'; } echo esc_html($check['label']).'</div> <span class="siteseo-arrow" aria-hidden="true"></span> </div>'; } if(isset($check['details'])){ echo '<div class="siteseo-analysis-block-content" aria-hidden="true">'.wp_kses_post($check['details']).'</div>'; } echo '</div><!-- .siteseo-analysis-block -->'; } echo '</div><!-- #siteseo-analysis-tabs-1 --> </div><!-- #siteseo-analysis-tabs -->'; } } static function perform_seo_analysis($post){ $content = $post->post_content; $title = $post->post_title; $title = !empty(get_post_meta($post->ID, '_siteseo_titles_title',true)) ? get_post_meta($post->ID, '_siteseo_titles_title', true) : $title; $permalink = get_permalink($post->ID); $keywords = get_post_meta($post->ID, '_siteseo_analysis_target_kw', true); $meta_desc = get_post_meta($post->ID, '_siteseo_titles_desc', true); if(empty($meta_desc)){ $meta_desc = ''; } $analysis = [ 'good_count' => 0, 'warning_count' => 0, 'error_count' => 0, 'checks' => [] ]; $canonical_check = self::check_canonical_url($permalink); $analysis['checks'][] = $canonical_check; self::update_analysis_score($analysis, $canonical_check); $word_count_check = self::check_word_count($content); $analysis['checks'][] = $word_count_check; self::update_analysis_score($analysis, $word_count_check); $keywords_density_check = self::check_keywords_density($content, $keywords); $analysis['checks'][] = $keywords_density_check; self::update_analysis_score($analysis, $keywords_density_check); $meta_title_check = self::check_meta_title($title); $analysis['checks'][] = $meta_title_check; self::update_analysis_score($analysis, $meta_title_check); $meta_description_check = self::check_meta_description($content, $meta_desc); $analysis['checks'][] = $meta_description_check; self::update_analysis_score($analysis, $meta_description_check); $image_alt_check = self::check_image_alt_texts($content); $analysis['checks'][] = $image_alt_check; self::update_analysis_score($analysis, $image_alt_check); $links_outbound_check = self::analyze_outbound_links($content); $analysis['checks'][] = $links_outbound_check; self::update_analysis_score($analysis, $links_outbound_check); $links_internal_check = self::analyze_internal_links($content); $analysis['checks'][] = $links_internal_check; self::update_analysis_score($analysis, $links_internal_check); $headings_check = self::check_headings($content); $analysis['checks'][] = $headings_check; self::update_analysis_score($analysis, $headings_check); $social_tags_check = self::check_social_meta_tags($post); $analysis['checks'][] = $social_tags_check; self::update_analysis_score($analysis, $social_tags_check); $structured_data_check = self::check_structured_data($post); $analysis['checks'][] = $structured_data_check; self::update_analysis_score($analysis, $structured_data_check); $permalink_keywords_check = self::check_keywords_in_permalink($permalink, $keywords); $analysis['checks'][] = $permalink_keywords_check; self::update_analysis_score($analysis, $permalink_keywords_check); $meta_robots_check = self::check_meta_robots($post); $analysis['checks'][] = $meta_robots_check; self::update_analysis_score($analysis, $meta_robots_check); $last_modified_check = self::check_last_modified_date($post); $analysis['checks'][] = $last_modified_check; self::update_analysis_score($analysis, $last_modified_check); $nofollow_links_check = self::analyze_nofollow_links($content); $analysis['checks'][] = $nofollow_links_check; self::update_analysis_score($analysis, $nofollow_links_check); $readability_data = []; $readability_data = self::analyze_readability($content, $title); update_post_meta($post->ID, '_siteseo_readibility_data', $readability_data); $analysis['checks'][] = $readability_data; return $analysis; } static function update_analysis_score(&$analysis, $check){ switch($check['status']){ case 'Good': $analysis['good_count']++; break; case 'Warning': $analysis['warning_count']++; break; case 'Error': $analysis['error_count']++; break; } } static function check_canonical_url($permalink){ $response = wp_remote_get($permalink); if(is_wp_error($response)){ return [ 'label' => 'Canonical URL', 'status' => 'Error', 'status_class' => 'error', 'details' => '<p>' . __('Unable to check canonical URL.', 'siteseo') . '</p>' ]; } $content = wp_remote_retrieve_body($response); preg_match_all('/<link[^>]+rel=[\'"](canonical)[\'"][^>]+href=[\'"]([^\'"]+)[\'"][^>]*>/i', $content, $matches); $canonical_urls = !empty($matches[2]) ? array_unique($matches[2]) : []; $count = count($canonical_urls); $details = ''; $status = 'Warning'; $details .= '<p>'. __('A canonical URL is required by search engines to handle duplicate content.', 'siteseo') .'</p>'; if($count > 0){ $details .= '<p>' . sprintf( /* translators: %s represents the degree of severity */ _n( 'We found %s canonical URL in your source code. Below, the list:', 'We found %s canonical URLs in your source code. Below, the list:', $count, 'siteseo' ), number_format_i18n($count) ) . '</p>'; $details .= '<ul>'; foreach($canonical_urls as $link){ $details .= '<li>' . '<span class="dashicons dashicons-arrow-right"></span>' . '<a href="' . esc_url($link) . '" target="_blank">' . esc_url($link) . '</a>' . '<span class="dashicons dashicons-external"></span>' . '</li>'; } $details .= '</ul>'; if($count > 1){ $status = 'Error'; $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('You must fix this. Canonical URL duplication is bad for SEO.', 'siteseo') . '</p>'; } else{ $status = 'Good'; } } else{ if(get_post_meta(get_the_ID(), '_siteseo_robots_index', true)){ $status = 'Good'; $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>' . __('This page doesn\'t have any canonical URL because your post is set to <strong>noindex</strong>. This is normal.', 'siteseo') . '</p>'; } else{ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('This page doesn\'t have any canonical URL.', 'siteseo') . '</p>'; } } return [ 'label' => 'Canonical URL', 'status' => $status, 'status_class' => strtolower($status), 'details' => $details ]; } static function check_word_count($content){ $word_count = str_word_count(wp_strip_all_tags($content)); $unique_words = count(array_unique(str_word_count(wp_strip_all_tags($content), 1))); $details = ''; if($word_count != 0){ $details = '<p>'. __('Word count isn\'t a direct ranking factor, but it\'s important for your content to be high-quality, relevant, and unique. To meet these criteria, your article should include a sufficient number of paragraphs to ensure adequate word count.', 'siteseo') .'</p>'; $details .= '<ul>'; /* translators: %d represents the words found */ $details .= '<li>'. sprintf(__('%d words found', 'siteseo'), $word_count) .'</li>'; /* translators: %d represents the unique words found */ $details .= '<li>'. sprintf(__('%d unique words found', 'siteseo'), $unique_words) .'</li>'; $details .= '</ul>'; } if($word_count == 0){ $status = 'Error'; $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('No content? Try adding a few more paragraphs.!', 'siteseo') . '</p>'; } elseif($word_count > 300){ $status = 'Good'; $details .= '<li><span class="dashicons dashicons-thumbs-up"></span>' . __('Your content contains over 300 words, which meets the minimum requirement for a post', 'siteseo') .'</li>'; } else{ $status = 'Error'; $details .= '<li><span class="dashicons dashicons-thumbs-down"></span>' . __('Your content is too brief. Consider adding a few more paragraphs!', 'siteseo') .'</li>'; } return [ 'label' => __('Word Count', 'siteseo'), 'status' => $status, 'status_class' => strtolower($status), 'details' => $details ]; } static function check_keywords_density($content, $keywords){ $content = strtolower(wp_strip_all_tags($content)); $keywords = array_filter(explode(',', trim($keywords))); $content_words = str_word_count($content, 1); $count_words = count($content_words); $details = ''; if(empty($keywords) || empty($content_words)){ $details .= '<p>' . __('We couldn\'t calculate the keyword density. This may be because you haven\'t added any content or your target keywords are missing from the post.', 'siteseo') . '</p>'; return [ 'label' => __('Keyword Density', 'siteseo'), 'status' => 'Error', 'status_class' => 'error', 'details' => $details ]; } // calulate $density_details = []; $all_density = []; foreach($keywords as $keyword){ $keyword_occurrence = 0; $keyword = strtolower(trim($keyword)); // If keyword has multiple words if(str_word_count($keyword) > 1){ $pattern = '/\b' . preg_quote($keyword, '/') . '\b/i'; preg_match_all($pattern, $content, $matches); $keyword_occurrence = count($matches[0]); } else { $keyword_occurrence = array_count_values($content_words)[$keyword] ?? 0; } // Calculate density as percentage $kw_density = ($keyword_occurrence * str_word_count($keyword) * 100)/$count_words; $all_density[] = number_format($kw_density, 2); $density_details[] = /* translators: %s represents the degree of severity */ sprintf( '<ul><li><span class="dashicons dashicons-arrow-right"></span>%s</li></ul>', sprintf( /* translators: %s represents a keyword density of */ esc_html__('%1$s was found %2$d times in your content, a keyword density of %3$s%%', 'siteseo'), $keyword, $keyword_occurrence, number_format($kw_density, 2) ) ); } $details .= implode('', $density_details); $details .= '<p class="description">'. sprintf( /* translators: %s represents the keywords stuffing */ __('Find out more about <a href="%s" target="_blank">keywords stuffing</a>', 'siteseo'), 'https://www.youtube.com/watch?v=Rk4qgQdp2UA' ) . '</p>'; if(empty($all_density)){ return [ 'label' => __('Keyword Density', 'siteseo'), 'status' => 'Error', 'status_class' => 'error', 'details' => $details ]; } //avg density $avg_density = array_sum($all_density)/count($all_density); $status = ($avg_density > 1) ? 'Good' : 'Warning'; return [ 'label' => __('Keyword Density', 'siteseo'), 'status' => $status, 'status_class' => strtolower($status), 'details' => $details ]; } static function check_meta_title($title, $keywords = []){ $details = ''; $status = 'Good'; $status_class = 'good'; $title = \SiteSEO\TitlesMetas::replace_variables($title); // length if(empty($title)){ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('A custom title has not been set for this post. If the global meta title works for you, you can disregard this recommendation.', 'siteseo') . '</p>'; $status = 'Warning'; $status_class = 'warning'; } elseif(strlen($title) > 60){ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('Your custom title is too lengthy.', 'siteseo') . '</p>'; $status = 'Warning'; $status_class = 'warning'; } elseif(strlen($title) >= 10 && strlen($title) <= 60){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>' . __('The length of your title is appropriate.', 'siteseo') . '</p>'; } else{ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('Your custom title is too short.', 'siteseo') . '</p>'; $status = 'Warning'; $status_class = 'warning'; } if(!empty($keywords)){ $keyword_counts = []; foreach($keywords as $kw_name){ $kw_count = substr_count(strtolower($title), strtolower($kw_name)); if($kw_count > 0){ $keyword_counts[] = $kw_count; /* translators: %s represents the degree of severity */ $details .= '<ul><li><span class="dashicons dashicons-arrow-right"></span>'. sprintf(esc_html__('%1$s was found %2$d times.', 'siteseo'), $kw_name, $kw_count) . '</li></ul>'; } } if(!empty($keyword_counts)){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'.__('The target keywords are included in the Meta Title', 'siteseo').'</p>'; } else { $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'.__('None of your target keywords are present in the Meta Title.', 'siteseo').'</p>'; $status = $status === 'Good' ? 'Warning' : $status; $status_class = $status_class === 'good' ? 'warning' : $status_class; } } return [ 'label' => __('Meta Title', 'siteseo'), 'status' => $status, 'status_class' => $status_class, 'details' => $details ]; } static function check_meta_description($content, $meta_description = '', $keywords = []){ $details = ''; $status = 'Good'; $status_class = 'good'; $desc = !empty($meta_description) ? $meta_description : wp_trim_words($content, 20); $description = \SiteSEO\TitlesMetas::replace_variables($desc); // desc length if(empty($meta_description)){ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('A custom meta description has not been set for this post. If the global meta description works for you, you can ignore this recommendation.', 'siteseo') . '</p>'; $status = 'Warning'; $status_class = 'warning'; } elseif(strlen($description) > 160){ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('Your custom meta description is too lengthy', 'siteseo') .'</p>'; $status = 'Warning'; $status_class = 'warning'; } elseif(strlen($description) >= 50 && strlen($description) <= 160){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. __('The length of your meta description is appropriate.', 'siteseo').'</p>'; } else{ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. __('The description has been set properly.', 'siteseo').'</p>'; } if(!empty($keywords)){ $keyword_counts = []; foreach($keywords as $kw_name){ $kw_count = substr_count(strtolower($description), strtolower($kw_name)); if($kw_count > 0){ $keyword_counts[] = $kw_count; $details .= '<li><span class="dashicons dashicons-arrow-right"></span>' . /* translators: %s represents the key word count */ sprintf(esc_html__('%1$s was found %2$d times.', 'siteseo'), $kw_name, $kw_count) . '</li>'; } } if(!empty($keyword_counts)){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. __('The target keywords are included in the Meta description.', 'siteseo') . '</p>'; } else{ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('None of your target keywords are included in the Meta description.', 'siteseo') . '</p>'; $status = $status === 'Good' ? 'Warning' : $status; $status_class = $status_class === 'good' ? 'warning' : $status_class; } } return [ 'label' => 'Meta Description', 'status' => $status, 'status_class' => $status_class, 'details' => $details ]; } static function check_image_alt_texts($content){ $result = [ 'label' => __('Alternative texts of images', 'siteseo'), 'status' => 'Good', 'status_class' => 'good', 'details' => '' ]; if(empty($content)){ $result['status'] = 'Warning'; $result['status_class'] = 'warning'; $result['details'] = '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('No content found to analyze. Please add some content to check for images and alt texts.', 'siteseo') . '</p>'; return $result; } preg_match_all('/<img[^>]+src=[\'"]([^\'"]+)[\'"][^>]*>/i', $content, $image_matches); preg_match_all('/<img[^>]+alt=[\'"]([^\'"]+)[\'"][^>]*>/i', $content, $alt_matches); $images_count = count($image_matches[0]); $alt_text_count = count(array_filter($alt_matches[1], 'strlen')); if($images_count === 0){ $result['status'] = 'Warning'; $result['status_class'] = 'warning'; $result['details'] = '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('We couldn\'t find any images in your content. Adding media can boost your SEO.', 'siteseo') . '</p>'; return $result; } if($images_count !== $alt_text_count){ $result['status'] = ($alt_text_count > 0) ? 'Warning' : 'Error'; $result['status_class'] = strtolower($result['status']); $result['details'] = '<p><span class="dashicons dashicons-thumbs-down"></span>' . esc_html__('No alternative text has been found for these images. Alt tags are essential for SEO and accessibility. Please edit your images in the media library or using your preferred page builder, and provide alternative text.', 'siteseo') . '</p>'; if(!empty($image_matches[1])){ $result['details'] .= '<ul class="attachments">'; foreach($image_matches[1] as $index => $img){ if(empty($alt_matches[1][$index])){ $result['details'] .= '<li class="attachment"><figure>' . '<img src="' . esc_url($img) . '"/>' . '<figcaption style="word-break: break-all;">' . esc_html($img) . '</figcaption>' . '</figure></li>'; } } $result['details'] .= '</ul>'; } $result['details'] .= '<p>'. __('Please note that we scan all your source code, which means some missing alternative text for images may be found in your header, sidebar, or footer.', 'siteseo') .'</p>'; } else{ $result['details'] = '<p><span class="dashicons dashicons-thumbs-up"></span>' . __('All alternative tags have been completed. Great job!', 'siteseo') .'</p>'; } return $result; } static function analyze_outbound_links($content){ preg_match_all('/<a[^>]+href=([\'"])(?!#)([^\'"]+)[\'"][^>]*>/i', $content, $links); $outbound_links = array_filter($links[2], function($link){ return strpos($link, get_site_url()) === false; }); $total_outbound = count($outbound_links); $nofollow_count = preg_match_all('/rel=[\'"]nofollow[\'"]/', implode(' ', $links[0])); $status = $total_outbound > 0 ? 'Good' : 'Warning'; $details = ''; $details .= '<p>'. __('The internet is based on the concept of hyperlinks, so linking to different websites is completely natural. However, avoid linking to low-quality or spammy sites. If youre uncertain about a site quality, add the "nofollow" attribute to your link.', 'siteseo') .'</p>'; if($total_outbound > 0){ /* translators: %s represents the detected outbound links on page */ $details .= '<p>'.sprintf(__('We detected %s outbound links on your page. Below is the list.', 'siteseo'), $total_outbound) .'</p>'; $details .= '<ul>'; foreach($outbound_links as $link){ $details .= '<li><span class="dashicons dashicons-arrow-right"></span>'; $details .= '<a href="'.esc_url($link).'" target="_blank">'.esc_url($link).'</a></li>'; } $details .= '</ul>'; } else{ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('This page does not contain any outbound links.', 'siteseo') . '</p>'; } return [ 'label' => __('Outbound Links', 'siteseo'), 'status' => $status, 'status_class' => strtolower($status), 'details' => $details ]; } static function analyze_internal_links($content){ preg_match_all('/<a[^>]+href=([\'"])(?!#)([^\'"]+)[\'"][^>]*>(.*?)<\/a>/i', $content, $links, PREG_SET_ORDER); $internal_links = array_filter($links, function($link) { return strpos($link[2], get_site_url()) !== false; }); $total_internal = count($internal_links); $status = $total_internal > 0 ? 'Good' : 'Warning'; $details = ''; $details .= '<p>'. __('Internal links are crucial for both SEO and user experience. Always aim to interconnect your content using meaningful and relevant anchor text.', 'siteseo') .'</p>'; if($total_internal > 0){ /* translators: %s represents the internal links pointing to page */ $details .= '<p>'. sprintf(__('We identified %s internal links pointing to this page.', 'siteseo'), $total_internal) .'</p>'; $details .= '<ul>'; foreach($internal_links as $link){ $url = $link[2]; $post_id = url_to_postid($url); $details .= '<li><span class="dashicons dashicons-arrow-right"></span>'; $details .= '<a href="'.esc_url($url) .'" target="_blank">'. esc_html($url) . '</a>'; if($post_id){ $details .= '<a class="nounderline" href="' . get_edit_post_link($post_id) . '" ' . 'title="' . /* translators: %s represents the degree of severity */ sprintf(__('edit %s', 'siteseo'), esc_html(get_the_title($post_id))) . '">' . '<span class="dashicons dashicons-edit-large"></span></a>'; } $details .= '</li>'; } $details .= '</ul>'; } else{ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('This page has no internal links from other content. Links from archive pages are not counted as internal links because they lack contextual relevance.', 'siteseo') . '</p>'; } return [ 'label' => __('Internal Links', 'siteseo'), 'status' => $status, 'status_class' => strtolower($status), 'details' => $details ]; } static function analyze_nofollow_links($content){ preg_match_all('/<a[^>]+href=([\'"])([^\'"]+)[\'"][^>]*>(.*?)<\/a>/i', $content, $all_links, PREG_SET_ORDER); $nofollow_links = array_filter($all_links, function($link){ return preg_match('/rel=[\'"][^\'"]*nofollow[^\'"]*[\'"]/', $link[0]); }); $total_nofollow = count($nofollow_links); $status = $total_nofollow > 0 ? 'Warning' : 'Good'; $details = ''; if($total_nofollow > 0){ $details .= '<p>' . /* translators: %d represents the number nofollow attribute */ sprintf( esc_html__('We found %d links with the nofollow attribute on your page. Avoid overusing the nofollow attribute in links. Below is the list:', 'siteseo'), $total_nofollow ) . '</p>'; $details .= '<ul>'; foreach($nofollow_links as $link){ $href = $link[2]; $link_text = $link[3]; $details .= '<li>'. '<span class="dashicons dashicons-arrow-right"></span>'. '<a href="' . esc_url($href) . '" target="_blank">'.esc_html($link_text).'</a>'. '<span class="dashicons dashicons-external"></span>'. '</li>'; } $details .= '</ul>'; } else{ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>' . __('This page does not contain any nofollow links.', 'siteseo') . '</p>'; } return [ 'label' => __('Nofollow Links', 'siteseo'), 'status' => $status, 'status_class' => strtolower($status), 'details' => $details ]; } static function check_headings($content, $keywords = []) { $details = ''; $status = 'Good'; $status_class = 'good'; if(empty(trim($content))){ return [ 'label' => 'Headings', 'status' => 'Warning', 'status_class' => 'warning', 'details' => '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('No content available to check headings.', 'siteseo') . '</p>' ]; } preg_match_all('/<h([1-6])([^>]*)>(.*?)<\/h\1>/is', $content, $heading_matches); if(empty($heading_matches[0])){ return [ 'label' => 'Headings', 'status' => 'Error', 'status_class' => 'error', 'details' => '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('No headings found in the content. Using headings is essential for both SEO and accessibility!', 'siteseo') . '</p>' ]; } $heading_counts = array_count_values($heading_matches[1]); $total_headings = count($heading_matches[0]); $h1_count = $heading_counts[1] ?? 0; if($h1_count > 0){ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . /* translators: %d represents the number of h1 tags */ sprintf(esc_html__('We found %d Heading 1 (H1) tags in your content.', 'siteseo'), $h1_count+1) . '</p>'; $details .= '<p>' . __('You should avoid using more than one H1 heading in your post content. The rule is simple: each web page should have only one H1, which benefits both SEO and accessibility. Below is the list:', 'siteseo') . '</p>'; $details .= '<ul>'; foreach(array_keys($heading_matches[1], '1') as $index){ $details .= '<li><span class="dashicons dashicons-arrow-right"></span>' . wp_strip_all_tags($heading_matches[0][$index]) . '</li>'; } $details .= '</ul>'; $status = 'Warning'; $status_class = 'warning'; } foreach([2, 3] as $level){ $level_count = $heading_counts[$level] ?? 0; $details .= '<p><span class="dashicons dashicons-info"></span>' . /* translators: %d represents the heading */ sprintf(__('Found %1$d H%2$d heading(s)', 'siteseo'), $level_count, $level) . '</p>'; if($level_count > 0){ $details .= '<ul>'; foreach(array_keys($heading_matches[1], (string)$level) as $index){ $details .= '<li><span class="dashicons dashicons-arrow-right"></span>'. wp_strip_all_tags($heading_matches[0][$index]) .'</li>'; } $details .= '</ul>'; } if(!empty($keywords) && $level_count > 0){ $keyword_found = false; $keyword_details = '<ul>'; foreach($keywords as $kw_name){ $kw_count = 0; foreach(array_keys($heading_matches[1], (string)$level) as $index){ $kw_count += substr_count( strtolower(wp_strip_all_tags($heading_matches[0][$index])), strtolower($kw_name) ); } if($kw_count > 0){ $keyword_found = true; $keyword_details .= '<li><span class="dashicons dashicons-arrow-right"></span>' . /* translators: %s represents the degree of severity */ sprintf(esc_html__('%1$s was found %2$d times.', 'siteseo'), $kw_name, $kw_count) . '</li>'; } } $keyword_details .= '</ul>'; if($keyword_found){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>' . /* translators: %s represents the target keywords */ sprintf(__('Target keywords were found in Heading %1$d (H%2$d).', 'siteseo'), $level, $level) . '</p>' . $keyword_details; } else{ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . /* translators: %d represents the target keywords */ sprintf(__('None of your target keywords were found in Heading %1$d (H%2$d).', 'siteseo'), $level, $level) . '</p>'; if($status === 'Good'){ $status = 'Warning'; $status_class = 'warning'; } } } } return [ 'label' => 'Headings', 'status' => $status, 'status_class' => $status_class, 'details' => $details ]; } static function check_social_meta_tags($post = null){ if(!$post){ $post = get_queried_object(); } $details = ''; $status = 'Good'; $status_class = 'good'; $og_titles = get_post_meta($post->ID, '_siteseo_social_fb_title', true); $og_title = $og_titles ? $og_titles : ''; if(empty($og_title)){ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('Your Open Graph Title tag has not been set!', 'siteseo') .'</p>'; $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('Your Open Graph Title is missing!', 'siteseo') .'</p>'; $status = 'Error'; $status_class = 'error'; } else{ $details .= '<h4>'. __('Open Graph Title', 'siteseo') . '</h4>'; $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. __('An Open Graph Title tag was found in your source code.', 'siteseo') . '</p>'; $details .= '<ul><li><span class="dashicons dashicons-arrow-right"></span>' . esc_html($og_title) . '</li></ul>'; } $og_descriptions = get_post_meta($post->ID, '_siteseo_social_fb_desc', true); $og_description = $og_descriptions ? $og_descriptions : ''; if(empty($og_description)){ $details .= '<h4>'. __('Open Graph Description', 'siteseo') .'</h4>'; $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('Your Open Graph Description has not been set!','siteseo').'</p>'; $status = $status === 'Good' ? 'Warning' : $status; $status_class = $status_class === 'good' ? 'warning' : $status_class; } else { $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>' . /* translators: %s represents the og description */ sprintf(esc_html__('We found %s og:description in your content.', 'siteseo'), $og_descriptions) . '</p>'; } // OG Check $og_images = get_post_meta($post->ID, '_siteseo_social_fb_img', true); $og_image = $og_images ? $og_images : ''; if(empty($og_image)){ $details .= '<h4>'. __('Open Graph Image', 'siteseo') .'</h4>'; $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('Your Open Graph Image has not been set!' ,'siteseo') .'</p>'; $status = $status === 'Good' ? 'Warning' : $status; $status_class = $status_class === 'good' ? 'warning' : $status_class; } else{ /* translators: %s represents the og images */ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. sprintf(esc_html__('We found %s og:image in your content.', 'siteseo'), $og_images) . '</p>'; } // Open Graph $og_site_name = get_bloginfo('name'); if(empty($og_site_name)){ $details .= '<h4>'. __('Open Graph Site Name', 'siteseo') .'</h4>'; $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('Your Open Graph Site Name has not been set!' ,'siteseo') .'</p>'; $status = $status === 'Good' ? 'Warning' : $status; $status_class = ($status_class === 'good') ? 'warning' : $status_class; } // Twitter $twitter_title = get_post_meta($post->ID, '_siteseo_social_twitter_title', true); if(empty($twitter_title)){ $details .= '<h4>'. __('X Title', 'siteseo').'</h4>'; $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('Your X Title has not been set!', 'siteseo').'</p>'; $status = $status === 'Good' ? 'Warning' : $status; $status_class = $status_class === 'good' ? 'warning' : $status_class; } $twitter_description = get_post_meta($post->ID, '_siteseo_social_twitter_desc', true); if(empty($twitter_description)){ $details .= '<h4>'. __('X Description','siteseo').'</h4>'; $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('Your X Description has not been set!','siteseo') .'</p>'; $status = $status === 'Good' ? 'Warning' : $status; $status_class = $status_class === 'good' ? 'warning' : $status_class; } $twitter_image = get_post_meta($post->ID, '_siteseo_social_twitter_img', true); if(empty($twitter_image)){ $details .= '<h4>'. __('X Image', 'siteseo') .'</h4>'; $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('Your X Image has not been set!', 'siteseo').'</p>'; $status = $status === 'Good' ? 'Warning' : $status; $status_class = ($status_class === 'good') ? 'warning' : $status_class; } return [ 'label' => __('Social Meta Tags', 'siteseo'), 'status' => $status, 'status_class' => $status_class, 'details' => $details ]; } static function check_structured_data($post){ $schema_type = get_post_meta($post->ID, '_siteseo_structured_data_type', true); $status = !empty($schema_type) ? 'Good' : 'Warning'; return [ 'label' => 'Structured Data', 'status' => $status, 'status_class' => strtolower($status), 'details' => !empty($schema_type) ? 'Schema Type: '.$schema_type : 'No schema defined' ]; } static function check_keywords_in_permalink($permalink, $keywords){ $keywords = array_filter(explode(',', trim($keywords))); $permalink = str_replace('-', ' ', strtolower(basename($permalink))); $content_words = str_word_count($permalink, 1); $count_words = count($content_words); $kw_density = []; $matching_keywords = []; foreach($keywords as $keyword){ $keyword_occurrence = 0; $keyword = strtolower(trim($keyword)); // If keyword has multiple words if(str_word_count($keyword) > 1){ $pattern = '/\b' . preg_quote($keyword, '/') . '\b/i'; preg_match_all($pattern, $permalink, $matches); $keyword_occurrence = count($matches[0]); } else { $keyword_occurrence = array_count_values($content_words)[$keyword] ?? 0; } // Calculate density as percentage $kw_density[] = ($keyword_occurrence * str_word_count($keyword) * 100)/$count_words; if(!empty($kw_density)){ $matching_keywords[] = $keyword; break; } } $status = !empty($kw_density) ? 'Good' : 'Error'; $details = ''; if($status === 'Good'){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. __('Great! One of your target keywords is included in your permalink.', 'siteseo') .'</p>'; $details .= '<ul><li><span class="dashicons dashicons-arrow-right"></span>' . implode(', ', $matching_keywords) . '</li></ul>'; } elseif($permalink === get_home_url() || $permalink === home_url()){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. __('This is your homepage, so this check doesn\'t apply as there is no slug.', 'siteseo') . '</p>'; } else{ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('You should include one of your target keywords in your permalink.', 'siteseo') . '</p>'; } return [ 'label' => __('Keywords in Permalink', 'siteseo'), 'status' => $status, 'status_class' => strtolower($status), 'details' => $details ]; } static function check_meta_robots($post){ $noindex = get_post_meta($post->ID, '_siteseo_robots_index', true); $nofollow = get_post_meta($post->ID, '_siteseo_robots_follow', true); $noimageindex = get_post_meta($post->ID, '_siteseo_robots_imageindex', true); $noarchive = get_post_meta($post->ID, '_siteseo_robots_archive', true); $nosnippet = get_post_meta($post->ID, '_siteseo_robots_snippet', true); $count_meta_robots = 0; $details = ''; $meta_robots_checks = [ 'noindex' => $noindex, 'nofollow' => $nofollow, 'noimageindex' => $noimageindex, 'noarchive' => $noarchive, 'nosnippet' => $nosnippet, ]; foreach($meta_robots_checks as $robot => $value){ if($value !== 'yes'){ continue; } $count_meta_robots++; switch($robot){ case 'noindex': $details .= '<p data-robots="noindex"><span class="dashicons dashicons-thumbs-down"></span>' . __('<strong>noindex</strong> is enabled! Search engines cannot index this page', 'siteseo') . '</p>'; break; case 'nofollow': $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('<strong>nofollow</strong> is on! Search engines can\'t follow your links on this page.', 'siteseo') . '</p>'; break; case 'noimageindex': $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('<strong>nofollow</strong> is enabled! Search engines cannot follow the links on this page.', 'siteseo').'</p>'; break; case 'noarchive': $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('<strong>noarchive</strong> is enabled! Search engines will not cache your page.', 'siteseo') .'</p>'; break; case 'nosnippet': $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>' . __('<strong>nosnippet</strong> is enabled! Search engines will not display a snippet of this page in the search results.', 'siteseo') .'</p>'; break; } } if($count_meta_robots > 0){ /* translators: %s represents the robots tags */ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. sprintf(esc_html__('We found %s meta robots tags on your page. There may be an issue with your theme!', 'siteseo'), $count_meta_robots) .'</p>'; } if($noindex !== 'yes'){ $details .= '<p data-robots="index"><span class="dashicons dashicons-thumbs-up"></span>'. __('<strong>noindex</strong> is disabled. Search engines will index this page.', 'siteseo') .'</p>'; } if($nofollow !== 'yes'){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. __('<strong>nofollow</strong> is disabled. Search engines will follow links on this page.', 'siteseo') .'</p>'; } if($noimageindex !== 'yes'){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. __('<strong>noimageindex</strong> is disabled. Google will index the images on this page.', 'siteseo') .'</p>'; } if($noarchive !== 'yes'){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. __('<strong>noarchive</strong> is disabled. Search engines will probably cache your page.', 'siteseo') .'</p>'; } if($nosnippet !== 'yes'){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>'. __('<strong>nosnippet</strong> is disabled. Search engines will display a snippet of this page in search results.', 'siteseo') .'</p>'; } if($count_meta_robots === 0){ $details .= '<p><span class="dashicons dashicons-thumbs-up"></span>' . __('We found no meta robots on this page. It means, your page is index,follow. Search engines will index it, and follow links. ', 'siteseo') . '</p>'; } $status = ($count_meta_robots === 0) ? 'Good' : (($count_meta_robots <= 2) ? 'Warning' : 'Error'); return [ 'label' => 'Meta Robots', 'status' => $status, 'status_class' => strtolower($status), 'details' => $details ]; } static function check_last_modified_date($post){ $last_modified = get_the_modified_date('Y-m-d', $post); $days_since_modified = round((time() - strtotime($last_modified)) / (60 * 60 * 24)); $status = $days_since_modified < 30 ? 'Good' : ($days_since_modified < 90 ? 'Warning' : 'Error'); $details = ''; if($status == 'Error'){ $details .= '<p><span class="dashicons dashicons-thumbs-down"></span>'. __('This post is a little old!', 'siteseo') .'</p>'; } if($days_since_modified < 365){ $details .='<p><span class="dashicons dashicons-thumbs-up"></span>'.__('The last modified date of this article is less than 1 year. Cool', 'siteseo') .'</p>'; } $details .= '<p>'.__('Search engines love fresh content. Update regularly your articles without entirely rewriting your content and give them a boost in search rankings. SiteSEO takes care of the technical part', 'siteseo').'</p>'; return [ 'label' => 'Last Modified Date', 'status' => $status, 'status_class' => strtolower($status), 'details' => $details ]; } static function analyze_readability($post, $title){ $data = []; // These are power words specifically for headlines. // These are not hard rules, but they are perceived to have a higher CTR if used in the heading. $power_words = ['exclusive', 'revealed', 'secrets', 'ultimate', 'proven', 'unleashed', 'discover', 'breakthrough', 'shocking', 'insider', 'elite', 'uncovered', 'powerful', 'guaranteed', 'transformative', 'instant', 'revolutionary', 'unbelievable', 'top', 'best', 'must-have', 'limited', 'rare', 'unique', 'unprecedented', 'premium', 'urgent', 'today', 'now', 'latest', 'new', 'free', 'bonus', 'offer', 'sensational', 'astonishing', 'incredible', 'jaw-dropping', 'unmissable', 'essential', 'critical', 'vital', 'pivotal', 'game-changer', 'spotlight', 'trending', 'hot', 'popular', 'featured', 'special', 'limited-time', 'hurry', 'last chance', 'countdown']; if(!empty($title)){ // Checking power words. $title_words = explode(' ', strtolower($title)); $present_power_words = array_intersect($title_words, $power_words); if(!empty($present_power_words)){ $data['power_words'] = $present_power_words; } // Checking number in the Title if(preg_match('/\s?\d+\s/', preg_quote($title), $number)){ $data['number_found'] = $number[0]; } } // We are checking paragarph length too. if(!isset($data['paragraph_length'])){ $data['paragraph_length'] = 0; } if(!empty($post)){ preg_match_all('/<p>.*<\/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 self::analyse_passive_voice($paragraph, $data); } } return $data; } static function 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 = self::sentence_is_passive($sentence); if($is_passive == true){ $passive_count++; } } $data['passive_voice']['passive_sentences'] += $passive_count; $data['passive_voice']['total_sentences'] += count($sentences); } static function 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; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.33 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings