PDF rausgenommen
This commit is contained in:
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Admin\Ajax
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPSEO_Recalculate_Scores.
|
||||
*
|
||||
* This class handles the SEO score recalculation for all posts with a filled focus keyword.
|
||||
*/
|
||||
class WPSEO_Recalculate_Scores_Ajax {
|
||||
|
||||
/**
|
||||
* Initialize the AJAX hooks.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'wp_ajax_wpseo_recalculate_scores', array( $this, 'recalculate_scores' ) );
|
||||
add_action( 'wp_ajax_wpseo_update_score', array( $this, 'save_score' ) );
|
||||
add_action( 'wp_ajax_wpseo_recalculate_total', array( $this, 'get_total' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the totals for the posts and the terms.
|
||||
*/
|
||||
public function get_total() {
|
||||
check_ajax_referer( 'wpseo_recalculate', 'nonce' );
|
||||
|
||||
wp_die(
|
||||
WPSEO_Utils::format_json_encode(
|
||||
array(
|
||||
'posts' => $this->calculate_posts(),
|
||||
'terms' => $this->calculate_terms(),
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start recalculation.
|
||||
*/
|
||||
public function recalculate_scores() {
|
||||
check_ajax_referer( 'wpseo_recalculate', 'nonce' );
|
||||
|
||||
$fetch_object = $this->get_fetch_object();
|
||||
if ( ! empty( $fetch_object ) ) {
|
||||
$paged = filter_input( INPUT_POST, 'paged', FILTER_VALIDATE_INT );
|
||||
$response = $fetch_object->get_items_to_recalculate( $paged );
|
||||
|
||||
if ( ! empty( $response ) ) {
|
||||
wp_die( WPSEO_Utils::format_json_encode( $response ) );
|
||||
}
|
||||
}
|
||||
|
||||
wp_die( '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the new linkdex score for given post.
|
||||
*/
|
||||
public function save_score() {
|
||||
check_ajax_referer( 'wpseo_recalculate', 'nonce' );
|
||||
|
||||
$fetch_object = $this->get_fetch_object();
|
||||
if ( ! empty( $fetch_object ) ) {
|
||||
$scores = filter_input( INPUT_POST, 'scores', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
||||
$fetch_object->save_scores( $scores );
|
||||
}
|
||||
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the needed object for recalculating scores.
|
||||
*
|
||||
* @return WPSEO_Recalculate_Posts|WPSEO_Recalculate_Terms
|
||||
*/
|
||||
private function get_fetch_object() {
|
||||
switch ( filter_input( INPUT_POST, 'type' ) ) {
|
||||
case 'post':
|
||||
return new WPSEO_Recalculate_Posts();
|
||||
case 'term':
|
||||
return new WPSEO_Recalculate_Terms();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total number of posts.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function calculate_posts() {
|
||||
$count_posts_query = new WP_Query(
|
||||
array(
|
||||
'post_type' => 'any',
|
||||
'meta_key' => '_yoast_wpseo_focuskw',
|
||||
'posts_per_page' => 1,
|
||||
'fields' => 'ids',
|
||||
)
|
||||
);
|
||||
|
||||
return $count_posts_query->found_posts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of terms.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function calculate_terms() {
|
||||
$total = 0;
|
||||
foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
|
||||
$total += wp_count_terms( $taxonomy->name, array( 'hide_empty' => false ) );
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Admin\Ajax
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPSEO_Shortcode_Filter.
|
||||
*
|
||||
* Used for parsing WP shortcodes with AJAX.
|
||||
*/
|
||||
class WPSEO_Shortcode_Filter {
|
||||
|
||||
/**
|
||||
* Initialize the AJAX hooks.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'wp_ajax_wpseo_filter_shortcodes', array( $this, 'do_filter' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the shortcodes.
|
||||
*/
|
||||
public function do_filter() {
|
||||
check_ajax_referer( 'wpseo-filter-shortcodes', 'nonce' );
|
||||
|
||||
$shortcodes = filter_input( INPUT_POST, 'data', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
||||
|
||||
$parsed_shortcodes = array();
|
||||
|
||||
foreach ( $shortcodes as $shortcode ) {
|
||||
$parsed_shortcodes[] = array(
|
||||
'shortcode' => $shortcode,
|
||||
'output' => do_shortcode( $shortcode ),
|
||||
);
|
||||
}
|
||||
|
||||
wp_die( WPSEO_Utils::format_json_encode( $parsed_shortcodes ) );
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Admin\Ajax
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will catch the request to dismiss the target notice (set by notice_name)
|
||||
* and will store the dismiss status as an user meta in the database.
|
||||
*/
|
||||
class Yoast_Dismissable_Notice_Ajax {
|
||||
|
||||
/**
|
||||
* Notice type toggle value for user notices.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const FOR_USER = 'user_meta';
|
||||
|
||||
/**
|
||||
* Notice type toggle value for network notices.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const FOR_NETWORK = 'site_option';
|
||||
|
||||
/**
|
||||
* Notice type toggle value for site notices.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const FOR_SITE = 'option';
|
||||
|
||||
|
||||
/**
|
||||
* Name of the notice that will be dismissed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $notice_name;
|
||||
|
||||
/**
|
||||
* The type of the current notice.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $notice_type;
|
||||
|
||||
/**
|
||||
* Initialize the hooks for the AJAX request.
|
||||
*
|
||||
* @param string $notice_name The name for the hook to catch the notice.
|
||||
* @param string $notice_type The notice type.
|
||||
*/
|
||||
public function __construct( $notice_name, $notice_type = self::FOR_USER ) {
|
||||
$this->notice_name = $notice_name;
|
||||
$this->notice_type = $notice_type;
|
||||
|
||||
add_action( 'wp_ajax_wpseo_dismiss_' . $notice_name, array( $this, 'dismiss_notice' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the dismiss notice request.
|
||||
*/
|
||||
public function dismiss_notice() {
|
||||
check_ajax_referer( 'wpseo-dismiss-' . $this->notice_name );
|
||||
|
||||
$this->save_dismissed();
|
||||
|
||||
wp_die( 'true' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Storing the dismissed value in the database. The target location is based on the set notification type.
|
||||
*/
|
||||
private function save_dismissed() {
|
||||
if ( $this->notice_type === self::FOR_SITE ) {
|
||||
update_option( 'wpseo_dismiss_' . $this->notice_name, 1 );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->notice_type === self::FOR_NETWORK ) {
|
||||
update_site_option( 'wpseo_dismiss_' . $this->notice_name, 1 );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
update_user_meta( get_current_user_id(), 'wpseo_dismiss_' . $this->notice_name, 1 );
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Admin\Ajax
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Yoast_OnPage_Ajax.
|
||||
*
|
||||
* This class will catch the request to dismiss the Ryte notice and will store
|
||||
* the dismiss status as an user meta in the database.
|
||||
*/
|
||||
class Yoast_OnPage_Ajax {
|
||||
|
||||
/**
|
||||
* Initialize the hooks for the AJAX request.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'wp_ajax_wpseo_dismiss_onpageorg', array( $this, 'dismiss_notice' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the dismiss notice request.
|
||||
*/
|
||||
public function dismiss_notice() {
|
||||
check_ajax_referer( 'wpseo-dismiss-onpageorg' );
|
||||
|
||||
$this->save_dismissed();
|
||||
|
||||
wp_die( 'true' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Storing the dismissed value as an user option in the database.
|
||||
*/
|
||||
private function save_dismissed() {
|
||||
update_user_meta( get_current_user_id(), WPSEO_OnPage::USER_META_KEY, 1 );
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Admin\Ajax
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Yoast_Plugin_Conflict_Ajax.
|
||||
*/
|
||||
class Yoast_Plugin_Conflict_Ajax {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $option_name = 'wpseo_dismissed_conflicts';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $dismissed_conflicts = array();
|
||||
|
||||
/**
|
||||
* Initialize the hooks for the AJAX request.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'wp_ajax_wpseo_dismiss_plugin_conflict', array( $this, 'dismiss_notice' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the dismiss notice request.
|
||||
*/
|
||||
public function dismiss_notice() {
|
||||
check_ajax_referer( 'dismiss-plugin-conflict' );
|
||||
|
||||
$conflict_data = filter_input( INPUT_POST, 'data', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
||||
|
||||
$this->dismissed_conflicts = $this->get_dismissed_conflicts( $conflict_data['section'] );
|
||||
|
||||
$this->compare_plugins( $conflict_data['plugins'] );
|
||||
|
||||
$this->save_dismissed_conflicts( $conflict_data['section'] );
|
||||
|
||||
wp_die( 'true' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Getting the user option from the database.
|
||||
*
|
||||
* @return bool|array
|
||||
*/
|
||||
private function get_dismissed_option() {
|
||||
return get_user_meta( get_current_user_id(), $this->option_name, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Getting the dismissed conflicts from the database
|
||||
*
|
||||
* @param string $plugin_section Type of conflict group (such as Open Graph or sitemap).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_dismissed_conflicts( $plugin_section ) {
|
||||
$dismissed_conflicts = $this->get_dismissed_option();
|
||||
|
||||
if ( is_array( $dismissed_conflicts ) && array_key_exists( $plugin_section, $dismissed_conflicts ) ) {
|
||||
return $dismissed_conflicts[ $plugin_section ];
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Storing the conflicting plugins as an user option in the database.
|
||||
*
|
||||
* @param string $plugin_section Plugin conflict type (such as Open Graph or sitemap).
|
||||
*/
|
||||
private function save_dismissed_conflicts( $plugin_section ) {
|
||||
$dismissed_conflicts = $this->get_dismissed_option();
|
||||
|
||||
$dismissed_conflicts[ $plugin_section ] = $this->dismissed_conflicts;
|
||||
|
||||
update_user_meta( get_current_user_id(), $this->option_name, $dismissed_conflicts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loop through the plugins to compare them with the already stored dismissed plugin conflicts.
|
||||
*
|
||||
* @param array $posted_plugins Plugin set to check.
|
||||
*/
|
||||
public function compare_plugins( array $posted_plugins ) {
|
||||
foreach ( $posted_plugins as $posted_plugin ) {
|
||||
$this->compare_plugin( $posted_plugin );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if plugin is already dismissed, if not store it in the array that will be saved later.
|
||||
*
|
||||
* @param string $posted_plugin Plugin to check against dismissed conflicts.
|
||||
*/
|
||||
private function compare_plugin( $posted_plugin ) {
|
||||
if ( ! in_array( $posted_plugin, $this->dismissed_conflicts, true ) ) {
|
||||
$this->dismissed_conflicts[] = $posted_plugin;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user