Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordpres.../admin/import/plugins
File: class-import-squirrly.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* File with the class to handle data from Squirrly.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Admin\Import\Plugins
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Class with functionality to import & clean Squirrly post metadata.
[8] Fix | Delete
*/
[9] Fix | Delete
class WPSEO_Import_Squirrly extends WPSEO_Plugin_Importer {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* The plugin name.
[13] Fix | Delete
*
[14] Fix | Delete
* @var string
[15] Fix | Delete
*/
[16] Fix | Delete
protected $plugin_name = 'Squirrly SEO';
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Holds the name of the table Squirrly uses to store data.
[20] Fix | Delete
*
[21] Fix | Delete
* @var string
[22] Fix | Delete
*/
[23] Fix | Delete
protected $table_name;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Meta key, used in SQL LIKE clause for delete query.
[27] Fix | Delete
*
[28] Fix | Delete
* @var string
[29] Fix | Delete
*/
[30] Fix | Delete
protected $meta_key = '_sq_post_keyword';
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Data to import from (and the target to field) the serialized array stored in the SEO field in the Squirrly table.
[34] Fix | Delete
*
[35] Fix | Delete
* @var array
[36] Fix | Delete
*/
[37] Fix | Delete
protected $seo_field_keys = [
[38] Fix | Delete
'noindex' => 'meta-robots-noindex',
[39] Fix | Delete
'nofollow' => 'meta-robots-nofollow',
[40] Fix | Delete
'title' => 'title',
[41] Fix | Delete
'description' => 'metadesc',
[42] Fix | Delete
'canonical' => 'canonical',
[43] Fix | Delete
'cornerstone' => '_yst_is_cornerstone',
[44] Fix | Delete
'tw_media' => 'twitter-image',
[45] Fix | Delete
'tw_title' => 'twitter-title',
[46] Fix | Delete
'tw_description' => 'twitter-description',
[47] Fix | Delete
'og_title' => 'opengraph-title',
[48] Fix | Delete
'og_description' => 'opengraph-description',
[49] Fix | Delete
'og_media' => 'opengraph-image',
[50] Fix | Delete
'focuskw' => 'focuskw',
[51] Fix | Delete
];
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* WPSEO_Import_Squirrly constructor.
[55] Fix | Delete
*/
[56] Fix | Delete
public function __construct() {
[57] Fix | Delete
parent::__construct();
[58] Fix | Delete
[59] Fix | Delete
global $wpdb;
[60] Fix | Delete
$this->table_name = $wpdb->prefix . 'qss';
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Imports the post meta values to Yoast SEO.
[65] Fix | Delete
*
[66] Fix | Delete
* @return bool Import success status.
[67] Fix | Delete
*/
[68] Fix | Delete
protected function import() {
[69] Fix | Delete
$results = $this->retrieve_posts();
[70] Fix | Delete
foreach ( $results as $post ) {
[71] Fix | Delete
$return = $this->import_post_values( $post->identifier );
[72] Fix | Delete
if ( ! $return ) {
[73] Fix | Delete
return false;
[74] Fix | Delete
}
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
return true;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Retrieve the posts from the Squirrly Database.
[82] Fix | Delete
*
[83] Fix | Delete
* @return array Array of post IDs from the DB.
[84] Fix | Delete
*/
[85] Fix | Delete
protected function retrieve_posts() {
[86] Fix | Delete
global $wpdb;
[87] Fix | Delete
return $wpdb->get_results(
[88] Fix | Delete
$wpdb->prepare(
[89] Fix | Delete
$this->retrieve_posts_query(),
[90] Fix | Delete
get_current_blog_id()
[91] Fix | Delete
)
[92] Fix | Delete
);
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Returns the query to return an identifier for the posts to import.
[97] Fix | Delete
*
[98] Fix | Delete
* @return string Query to get post ID's from the DB.
[99] Fix | Delete
*/
[100] Fix | Delete
protected function retrieve_posts_query() {
[101] Fix | Delete
return "SELECT post_id AS identifier FROM {$this->table_name} WHERE blog_id = %d";
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Removes the DB table and the post meta field Squirrly creates.
[106] Fix | Delete
*
[107] Fix | Delete
* @return bool Cleanup status.
[108] Fix | Delete
*/
[109] Fix | Delete
protected function cleanup() {
[110] Fix | Delete
global $wpdb;
[111] Fix | Delete
[112] Fix | Delete
// If we can clean, let's clean.
[113] Fix | Delete
$wpdb->query( "DROP TABLE {$this->table_name}" );
[114] Fix | Delete
[115] Fix | Delete
// This removes the post meta field for the focus keyword from the DB.
[116] Fix | Delete
parent::cleanup();
[117] Fix | Delete
[118] Fix | Delete
// If we can still see the table, something went wrong.
[119] Fix | Delete
if ( $this->detect() ) {
[120] Fix | Delete
$this->cleanup_error_msg();
[121] Fix | Delete
return false;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
return true;
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Detects whether there is post meta data to import.
[129] Fix | Delete
*
[130] Fix | Delete
* @return bool Boolean indicating whether there is something to import.
[131] Fix | Delete
*/
[132] Fix | Delete
protected function detect() {
[133] Fix | Delete
global $wpdb;
[134] Fix | Delete
[135] Fix | Delete
$result = $wpdb->get_var( "SHOW TABLES LIKE '{$this->table_name}'" );
[136] Fix | Delete
if ( is_wp_error( $result ) || is_null( $result ) ) {
[137] Fix | Delete
return false;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
return true;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* Imports the data of a post out of Squirrly's DB table.
[145] Fix | Delete
*
[146] Fix | Delete
* @param mixed $post_identifier Post identifier, can be ID or string.
[147] Fix | Delete
*
[148] Fix | Delete
* @return bool Import status.
[149] Fix | Delete
*/
[150] Fix | Delete
private function import_post_values( $post_identifier ) {
[151] Fix | Delete
$data = $this->retrieve_post_data( $post_identifier );
[152] Fix | Delete
if ( ! $data ) {
[153] Fix | Delete
return false;
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
if ( ! is_numeric( $post_identifier ) ) {
[157] Fix | Delete
$post_id = url_to_postid( $post_identifier );
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
if ( is_numeric( $post_identifier ) ) {
[161] Fix | Delete
$post_id = (int) $post_identifier;
[162] Fix | Delete
$data['focuskw'] = $this->maybe_add_focus_kw( $post_identifier );
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
foreach ( $this->seo_field_keys as $squirrly_key => $yoast_key ) {
[166] Fix | Delete
$this->import_meta_helper( $squirrly_key, $yoast_key, $data, $post_id );
[167] Fix | Delete
}
[168] Fix | Delete
return true;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Retrieves the Squirrly SEO data for a post from the DB.
[173] Fix | Delete
*
[174] Fix | Delete
* @param int $post_identifier Post ID.
[175] Fix | Delete
*
[176] Fix | Delete
* @return array|bool Array of data or false.
[177] Fix | Delete
*/
[178] Fix | Delete
private function retrieve_post_data( $post_identifier ) {
[179] Fix | Delete
global $wpdb;
[180] Fix | Delete
[181] Fix | Delete
if ( is_numeric( $post_identifier ) ) {
[182] Fix | Delete
$post_identifier = (int) $post_identifier;
[183] Fix | Delete
$query_where = 'post_id = %d';
[184] Fix | Delete
}
[185] Fix | Delete
if ( ! is_numeric( $post_identifier ) ) {
[186] Fix | Delete
$query_where = 'URL = %s';
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
$replacements = [
[190] Fix | Delete
get_current_blog_id(),
[191] Fix | Delete
$post_identifier,
[192] Fix | Delete
];
[193] Fix | Delete
[194] Fix | Delete
$data = $wpdb->get_var(
[195] Fix | Delete
$wpdb->prepare(
[196] Fix | Delete
"SELECT seo FROM {$this->table_name} WHERE blog_id = %d AND " . $query_where,
[197] Fix | Delete
$replacements
[198] Fix | Delete
)
[199] Fix | Delete
);
[200] Fix | Delete
if ( ! $data || is_wp_error( $data ) ) {
[201] Fix | Delete
return false;
[202] Fix | Delete
}
[203] Fix | Delete
$data = maybe_unserialize( $data );
[204] Fix | Delete
return $data;
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* Squirrly stores the focus keyword in post meta.
[209] Fix | Delete
*
[210] Fix | Delete
* @param int $post_id Post ID.
[211] Fix | Delete
*
[212] Fix | Delete
* @return string The focus keyword.
[213] Fix | Delete
*/
[214] Fix | Delete
private function maybe_add_focus_kw( $post_id ) {
[215] Fix | Delete
$focuskw = get_post_meta( $post_id, '_sq_post_keyword', true );
[216] Fix | Delete
if ( $focuskw ) {
[217] Fix | Delete
$focuskw = json_decode( $focuskw );
[218] Fix | Delete
return $focuskw->keyword;
[219] Fix | Delete
}
[220] Fix | Delete
return '';
[221] Fix | Delete
}
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function