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/wp-conte.../plugins/custom-t.../inc/SmashTwi...
File: SinglePostCache.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Class SinglePostCache
[2] Fix | Delete
*
[3] Fix | Delete
* @since 1.0
[4] Fix | Delete
*/
[5] Fix | Delete
namespace TwitterFeed\SmashTwitter;
[6] Fix | Delete
class SinglePostCache {
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* @var array
[10] Fix | Delete
*/
[11] Fix | Delete
private $post_data;
[12] Fix | Delete
[13] Fix | Delete
private $storage_data;
[14] Fix | Delete
private $endpoint;
[15] Fix | Delete
private $term;
[16] Fix | Delete
[17] Fix | Delete
private $posts_table_name;
[18] Fix | Delete
[19] Fix | Delete
private $feeds_posts_table_name;
[20] Fix | Delete
[21] Fix | Delete
public function __construct( $post_data, $endpoint, $term ) {
[22] Fix | Delete
$this->post_data = $post_data;
[23] Fix | Delete
[24] Fix | Delete
$this->storage_data = array(
[25] Fix | Delete
'media_id' => '',
[26] Fix | Delete
'sizes' => '[]',
[27] Fix | Delete
'aspect_ratio' => 1,
[28] Fix | Delete
'images_done' => 0
[29] Fix | Delete
);
[30] Fix | Delete
$this->endpoint = $endpoint;
[31] Fix | Delete
[32] Fix | Delete
$this->term = $term;
[33] Fix | Delete
[34] Fix | Delete
global $wpdb;
[35] Fix | Delete
[36] Fix | Delete
$this->posts_table_name = $wpdb->prefix . CTF_POSTS_TABLE;
[37] Fix | Delete
$this->feeds_posts_table_name = $wpdb->prefix . CTF_FEEDS_POSTS_TABLE;
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
public function get_storage_data() {
[41] Fix | Delete
return $this->storage_data;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
public function get_post_data() {
[45] Fix | Delete
return $this->post_data;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
public function set_storage_data( $key, $value ){
[49] Fix | Delete
return $this->storage_data[ $key ] = $value;
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
public function db_record_exists() {
[53] Fix | Delete
$feed_id_match = $this->db_record();
[54] Fix | Delete
if ( ! empty( $feed_id_match ) ) {
[55] Fix | Delete
$this->storage_data['id'] = $feed_id_match['id'];
[56] Fix | Delete
[57] Fix | Delete
$this->storage_data['media_id'] = $feed_id_match['media_id'];
[58] Fix | Delete
$this->storage_data['sizes'] = $feed_id_match['sizes'];
[59] Fix | Delete
$this->storage_data['aspect_ratio'] = $feed_id_match['aspect_ratio'];
[60] Fix | Delete
$this->storage_data['images_done'] = $feed_id_match['images_done'];
[61] Fix | Delete
$this->storage_data['json_data'] = $feed_id_match['json_data'];
[62] Fix | Delete
}
[63] Fix | Delete
return null !== $feed_id_match;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
public function db_record_exists_for_endpoint_and_term() {
[67] Fix | Delete
global $wpdb;
[68] Fix | Delete
$feeds_posts_table_name = $this->feeds_posts_table_name;
[69] Fix | Delete
[70] Fix | Delete
if( isset( $this->post_data['id_str'] ) ){
[71] Fix | Delete
$feed_id_match = $wpdb->get_results( $wpdb->prepare(
[72] Fix | Delete
"SELECT * FROM $feeds_posts_table_name
[73] Fix | Delete
WHERE id = %s AND type = %s and term = %s LIMIT 1", $this->storage_data['id'], $this->endpoint, $this->term ), ARRAY_A );
[74] Fix | Delete
[75] Fix | Delete
if ( ! empty( $feed_id_match[0] ) ) {
[76] Fix | Delete
return $feed_id_match[0];
[77] Fix | Delete
}
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
return null;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
public function db_record() {
[84] Fix | Delete
global $wpdb;
[85] Fix | Delete
$table_name = $this->posts_table_name;
[86] Fix | Delete
if( isset( $this->post_data['id_str'] ) ){
[87] Fix | Delete
$feed_id_match = $wpdb->get_results( $wpdb->prepare(
[88] Fix | Delete
"SELECT * FROM $table_name
[89] Fix | Delete
WHERE twitter_id = %s LIMIT 1", $this->post_data['id_str'] ), ARRAY_A );
[90] Fix | Delete
[91] Fix | Delete
if ( ! empty( $feed_id_match[0] ) ) {
[92] Fix | Delete
return $feed_id_match[0];
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
return null;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
public function store() {
[100] Fix | Delete
[101] Fix | Delete
$to_store = array(
[102] Fix | Delete
array( 'twitter_id', $this->post_data['id_str'], '%s' ),
[103] Fix | Delete
array( 'created_on', date( 'Y-m-d H:i:s' ), '%s' ),
[104] Fix | Delete
array( 'last_requested', date( 'Y-m-d H:i:s' ), '%s' ),
[105] Fix | Delete
array( 'time_stamp', date('Y-m-d H:i:s', strtotime( $this->post_data['created_at'] ) ), '%s' ),
[106] Fix | Delete
array( 'json_data', json_encode( $this->post_data ), '%s' ),
[107] Fix | Delete
array( 'media_id', '', '%s' ),
[108] Fix | Delete
array( 'sizes', '{}', '%s' ),
[109] Fix | Delete
array( 'aspect_ratio', 1, '%d' ),
[110] Fix | Delete
array( 'images_done', 0, '%d' ),
[111] Fix | Delete
);
[112] Fix | Delete
$data = array();
[113] Fix | Delete
$format = array();
[114] Fix | Delete
foreach ( $to_store as $single_store ) {
[115] Fix | Delete
$data[ $single_store[0] ] = $single_store[1];
[116] Fix | Delete
$format[] = $single_store[2];
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
global $wpdb;
[120] Fix | Delete
$table_name = $this->posts_table_name;
[121] Fix | Delete
$error = $wpdb->insert( $table_name, $data, $format );
[122] Fix | Delete
[123] Fix | Delete
if ( $error !== false ) {
[124] Fix | Delete
$insert_id = $wpdb->insert_id;
[125] Fix | Delete
$to_store = array(
[126] Fix | Delete
array( 'id', $insert_id, '%s' ),
[127] Fix | Delete
array('feed_id', $this->term . '_' . $this->endpoint, '%s'),
[128] Fix | Delete
array('type', $this->endpoint, '%s'),
[129] Fix | Delete
array('term', $this->term, '%s'),
[130] Fix | Delete
);
[131] Fix | Delete
$data = array();
[132] Fix | Delete
$format = array();
[133] Fix | Delete
foreach ( $to_store as $single_store ) {
[134] Fix | Delete
$data[ $single_store[0] ] = $single_store[1];
[135] Fix | Delete
$format[] = $single_store[2];
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$table_name = $this->feeds_posts_table_name;
[139] Fix | Delete
$error = $wpdb->insert( $table_name, $data, $format );
[140] Fix | Delete
[141] Fix | Delete
} else {
[142] Fix | Delete
// log error
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
public function update_single( $insert_feeds_posts )
[148] Fix | Delete
{
[149] Fix | Delete
$to_store = array(
[150] Fix | Delete
array('json_data', json_encode( $this->post_data ), '%s'),
[151] Fix | Delete
array('time_stamp', date('Y-m-d H:i:s', strtotime( $this->post_data['created_at'] ) ), '%s'),
[152] Fix | Delete
array('last_requested', date('Y-m-d H:i:s'), '%s'),
[153] Fix | Delete
);
[154] Fix | Delete
$data = array();
[155] Fix | Delete
$format = array();
[156] Fix | Delete
foreach ($to_store as $single_store) {
[157] Fix | Delete
$data[$single_store[0]] = $single_store[1];
[158] Fix | Delete
$format[] = $single_store[2];
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
global $wpdb;
[162] Fix | Delete
$table_name = $this->posts_table_name;
[163] Fix | Delete
$where = array();
[164] Fix | Delete
$where_format = array();
[165] Fix | Delete
$where['twitter_id'] = $this->post_data['id_str'];
[166] Fix | Delete
$where_format[] = '%s';
[167] Fix | Delete
[168] Fix | Delete
$error = $wpdb->update($table_name, $data, $where, $format, $where_format);
[169] Fix | Delete
[170] Fix | Delete
if ( $insert_feeds_posts ) {
[171] Fix | Delete
$to_store = array(
[172] Fix | Delete
array('id', $this->storage_data['id'], '%s'),
[173] Fix | Delete
array('feed_id', $this->term . '_' . $this->endpoint, '%s'),
[174] Fix | Delete
array('type', $this->endpoint, '%s'),
[175] Fix | Delete
array('term', $this->term, '%s'),
[176] Fix | Delete
);
[177] Fix | Delete
$data = array();
[178] Fix | Delete
$format = array();
[179] Fix | Delete
foreach ($to_store as $single_store) {
[180] Fix | Delete
$data[$single_store[0]] = $single_store[1];
[181] Fix | Delete
$format[] = $single_store[2];
[182] Fix | Delete
}
[183] Fix | Delete
$error = $wpdb->insert($this->feeds_posts_table_name, $data, $format);
[184] Fix | Delete
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
if ($error !== false) {
[188] Fix | Delete
$insert_id = $wpdb->insert_id;
[189] Fix | Delete
} else {
[190] Fix | Delete
// log error
[191] Fix | Delete
}
[192] Fix | Delete
}
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function