HEX
Server: LiteSpeed
System: Linux cde4.duelhost.dk 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: dmhkjfau (1027)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/dmhkjfau/public_html/wp-content/plugins/wp-seopress/inc/admin/ajax/ContentAnalysis.php
<?php
/**
 * File: ContentAnalysis.php
 *
 * Description: This file contains the function for the content analysis real preview.
 *
 * @package SEOPress
 * @subpackage Ajax
 */

defined( 'ABSPATH' ) || exit( 'Please don&rsquo;t call the plugin directly. Thanks :)' );

/**
 * Content analysis real preview
 */
function seopress_do_real_preview() {
	check_ajax_referer( 'seopress_real_preview_nonce', '_ajax_nonce', true );

	if ( ! current_user_can( 'edit_posts' ) || ! is_admin() ) {
		return;
	}

	if ( ! isset( $_GET['post_id'] ) ) {
		return;
	}

	$id      = $_GET['post_id'];
	$taxname = isset( $_GET['tax_name'] ) ? $_GET['tax_name'] : null;

	if ( 'yes' === get_post_meta( $id, '_seopress_redirections_enabled', true ) ) {
		$data['title'] = __( 'A redirect is active for this URL. Turn it off to get the Google preview and content analysis.', 'wp-seopress' );
		wp_send_json_error( $data );
		return;
	}

	$dom_result = seopress_get_service( 'RequestPreview' )->getDomById( $id, $taxname );

	if ( ! $dom_result['success'] ) {
		$default_response = array(
			'title'     => '...',
			'meta_desc' => '...',
		);

		switch ( $dom_result['code'] ) {
			case 404:
				$default_response['title'] = __( 'To get your Google snippet preview, publish your post!', 'wp-seopress' );
				break;
			case 401:
				$default_response['title'] = __( 'Your site is protected by an authentication.', 'wp-seopress' );
				break;
			case 'blocked':
				$default_response['title'] = __( 'Content analysis was blocked (HTTP 403/503). A CDN, firewall or security plugin is preventing your server from loading the preview.', 'wp-seopress' );
				break;
			case 'unreachable':
				$default_response['title'] = __( 'Your site could not be reached for content analysis. Please check your server, DNS or firewall configuration.', 'wp-seopress' );
				break;
		}

		wp_send_json_success( $default_response );
		return;
	}

	$str = $dom_result['body'];

	$data = seopress_get_service( 'DomFilterContent' )->getData( $str, $id );

	if ( ! empty( $taxname ) ) {
		wp_send_json_success( $data );
	}

	$data = seopress_get_service( 'DomAnalysis' )->getDataAnalyze(
		$data,
		array(
			'id' => $id,
		)
	);

	$keywords = seopress_get_service( 'DomAnalysis' )->getKeywords(
		array(
			'id' => $id,
		)
	);

	// Save analysis data first so getScore() reads fresh values from the database.
	seopress_get_service( 'ContentAnalysisDatabase' )->saveData( $id, $data, $keywords );

	$post          = get_post( $id );
	$score         = seopress_get_service( 'DomAnalysis' )->getScore( $post );
	$data['score'] = $score;
	seopress_get_service( 'ContentAnalysisDatabase' )->saveData( $id, $data, $keywords );

	/**
	 * We delete old values because we have a new structure
	 *
	 * @deprecated
	 * @since 7.3.0
	 */
	delete_post_meta( $id, '_seopress_content_analysis_api' );
	delete_post_meta( $id, '_seopress_analysis_data' );

	// Re-enable QM.
	remove_filter( 'user_has_cap', 'seopress_disable_qm', 10, 3 );

	wp_send_json_success( $data );
}
add_action( 'wp_ajax_seopress_do_real_preview', 'seopress_do_real_preview' );