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/flow-flo.../includes/db/migratio...
File: FFMigration_2_16.php
<?php namespace flow\db\migrations;
[0] Fix | Delete
use Exception;
[1] Fix | Delete
use la\core\db\LADDLUtils;
[2] Fix | Delete
use la\core\db\migrations\ILADBMigration;
[3] Fix | Delete
[4] Fix | Delete
if ( ! defined( 'WPINC' ) ) die;
[5] Fix | Delete
/**
[6] Fix | Delete
* Flow-Flow.
[7] Fix | Delete
*
[8] Fix | Delete
* @package FlowFlow
[9] Fix | Delete
* @author Looks Awesome <email@looks-awesome.com>
[10] Fix | Delete
*
[11] Fix | Delete
* @link http://looks-awesome.com
[12] Fix | Delete
* @copyright Looks Awesome
[13] Fix | Delete
*/
[14] Fix | Delete
class FFMigration_2_16 implements ILADBMigration{
[15] Fix | Delete
private $sources;
[16] Fix | Delete
[17] Fix | Delete
public function version() {
[18] Fix | Delete
return '2.16';
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
public function execute($conn, $manager) {
[22] Fix | Delete
$this->sources = [];
[23] Fix | Delete
[24] Fix | Delete
$this->create_cache_table($conn, $manager->cache_table_name, $manager->posts_table_name, $manager->streams_sources_table_name);
[25] Fix | Delete
[26] Fix | Delete
LADDLUtils::addColumnIfNotExist($conn, $manager->cache_table_name, 'settings', 'BLOB');
[27] Fix | Delete
LADDLUtils::addColumnIfNotExist($conn, $manager->cache_table_name, 'enabled', 'TINYINT(1)');
[28] Fix | Delete
LADDLUtils::addColumnIfNotExist($conn, $manager->cache_table_name, 'changed_time', 'INT DEFAULT 0');
[29] Fix | Delete
LADDLUtils::addColumnIfNotExist($conn, $manager->cache_table_name, 'cache_lifetime', 'INT DEFAULT 60');
[30] Fix | Delete
[31] Fix | Delete
if (LADDLUtils::existColumn($conn, $manager->cache_table_name, 'stream_id')){
[32] Fix | Delete
LADDLUtils::dropColumn($conn, $manager->cache_table_name, 'stream_id');
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
if (LADDLUtils::existColumn($conn, $manager->posts_table_name, 'stream_id')){
[36] Fix | Delete
LADDLUtils::dropColumn($conn, $manager->posts_table_name, 'stream_id');
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
$time = time();
[40] Fix | Delete
$streams = $this->streams($conn, $manager->streams_table_name);
[41] Fix | Delete
foreach ( $streams as $stream ) {
[42] Fix | Delete
$stream = $this->getStream($conn, $manager->streams_table_name, $stream['id']);
[43] Fix | Delete
if (!isset($stream->feeds) || is_null($stream->feeds)){
[44] Fix | Delete
continue;
[45] Fix | Delete
}
[46] Fix | Delete
$feeds = json_decode($stream->feeds);
[47] Fix | Delete
$cache_lifetime = 60;
[48] Fix | Delete
if (isset($stream->{'cache-lifetime'})){
[49] Fix | Delete
$cache_lifetime = (int) $stream->{'cache-lifetime'};
[50] Fix | Delete
if ($cache_lifetime > 5760) $cache_lifetime = 10080;
[51] Fix | Delete
else if ($cache_lifetime > 900 && $cache_lifetime <= 5760) $cache_lifetime = 1440;
[52] Fix | Delete
else if ($cache_lifetime > 210 && $cache_lifetime <= 900) $cache_lifetime = 360;
[53] Fix | Delete
else if ($cache_lifetime > 45 && $cache_lifetime <= 210) $cache_lifetime = 60;
[54] Fix | Delete
else if ($cache_lifetime > 17 && $cache_lifetime <= 45) $cache_lifetime = 30;
[55] Fix | Delete
else if (17 >= $cache_lifetime) $cache_lifetime = 5;
[56] Fix | Delete
}
[57] Fix | Delete
$load_last = 5;
[58] Fix | Delete
if (isset($stream->posts)){
[59] Fix | Delete
$load_last = (int) $stream->posts;
[60] Fix | Delete
if ($load_last > 15) $load_last = 20;
[61] Fix | Delete
else if ($load_last > 8 && $load_last <= 15) $load_last = 10;
[62] Fix | Delete
else if ($load_last > 3 && $load_last <= 8) $load_last = 5;
[63] Fix | Delete
else if (3 >= $load_last) $load_last = 1;
[64] Fix | Delete
}
[65] Fix | Delete
foreach ( $feeds as $feed ) {
[66] Fix | Delete
$feed->posts = $load_last;
[67] Fix | Delete
if (isset($stream->moderation)){
[68] Fix | Delete
$feed->mod = $stream->moderation;
[69] Fix | Delete
}
[70] Fix | Delete
$f = serialize($feed);
[71] Fix | Delete
$insert = [
[72] Fix | Delete
'last_update' => time(),
[73] Fix | Delete
'settings' => $f,
[74] Fix | Delete
'enabled' => true,
[75] Fix | Delete
'changed_time' => $time,
[76] Fix | Delete
'cache_lifetime' => $cache_lifetime
[77] Fix | Delete
];
[78] Fix | Delete
$update = [
[79] Fix | Delete
'settings' => $f,
[80] Fix | Delete
'enabled' => true,
[81] Fix | Delete
'changed_time' => $time,
[82] Fix | Delete
'cache_lifetime' => $cache_lifetime
[83] Fix | Delete
];
[84] Fix | Delete
if ( false === $conn->query( 'INSERT INTO ?n SET `feed_id`=?s, ?u ON DUPLICATE KEY UPDATE ?u',
[85] Fix | Delete
$manager->cache_table_name, $feed->id, $insert, $update ) ) {
[86] Fix | Delete
throw new Exception();
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
if ( false === $conn->query( 'INSERT INTO ?n SET `feed_id`=?s, `stream_id`=?i',
[90] Fix | Delete
$manager->streams_sources_table_name, $this->source($f, $feed->id), $stream->id) ) {
[91] Fix | Delete
throw new Exception();
[92] Fix | Delete
}
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
if (LADDLUtils::existColumn($conn, $manager->streams_table_name, 'feeds')){
[97] Fix | Delete
LADDLUtils::dropColumn($conn, $manager->streams_table_name, 'feeds');
[98] Fix | Delete
}
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
private function source($source, $id){
[102] Fix | Delete
$hash = hash('md5', $source);
[103] Fix | Delete
if (array_key_exists($hash, $this->sources)){
[104] Fix | Delete
return $this->sources[$hash];
[105] Fix | Delete
}
[106] Fix | Delete
else {
[107] Fix | Delete
$this->sources[$hash] = $id;
[108] Fix | Delete
return $id;
[109] Fix | Delete
}
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
private function streams($conn, $table_name){
[113] Fix | Delete
if (false !== ($result = $conn->getAll('SELECT `id`, `value` FROM ?n ORDER BY `id`',
[114] Fix | Delete
$table_name))){
[115] Fix | Delete
return $result;
[116] Fix | Delete
}
[117] Fix | Delete
return [];
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
private function getStream($conn, $table_name, $id){
[121] Fix | Delete
if (false !== ($row = $conn->getRow('select `value`, `feeds` from ?n where `id`=?s', $table_name, $id))) {
[122] Fix | Delete
if ($row != null){
[123] Fix | Delete
$options = unserialize($row['value']);
[124] Fix | Delete
$options->feeds = $row['feeds'];
[125] Fix | Delete
return $options;
[126] Fix | Delete
}
[127] Fix | Delete
}
[128] Fix | Delete
return null;
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
private function create_cache_table($conn, $cache_table, $posts_table, $streams2sources_table) {
[132] Fix | Delete
/*
[133] Fix | Delete
* We'll set the default character set and collation for this table.
[134] Fix | Delete
* If we don't do this, some characters could end up being converted
[135] Fix | Delete
* to just ?'s when saved in our table.
[136] Fix | Delete
*/
[137] Fix | Delete
$charset_collate = '';
[138] Fix | Delete
[139] Fix | Delete
$charset = LADDLUtils::charset();
[140] Fix | Delete
if ( !empty( $charset ) ) {
[141] Fix | Delete
$charset_collate = " CHARACTER SET {$charset}";
[142] Fix | Delete
$charset = " CHARACTER SET {$charset}";
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
$collate = LADDLUtils::collate();
[146] Fix | Delete
if ( !empty( $collate ) ) {
[147] Fix | Delete
$charset_collate .= " COLLATE {$collate}";
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
if(!LADDLUtils::existTable($conn, $cache_table)){
[151] Fix | Delete
$sql = "
[152] Fix | Delete
CREATE TABLE `{$cache_table}`
[153] Fix | Delete
(
[154] Fix | Delete
`feed_id` VARCHAR(20) NOT NULL,
[155] Fix | Delete
`last_update` INT NOT NULL,
[156] Fix | Delete
`status` INT NOT NULL DEFAULT 0,
[157] Fix | Delete
`errors` BLOB,
[158] Fix | Delete
`settings` BLOB,
[159] Fix | Delete
`enabled` TINYINT(1) DEFAULT 0,
[160] Fix | Delete
`system_enabled` TINYINT(1) DEFAULT 1,
[161] Fix | Delete
`changed_time` INT DEFAULT 0,
[162] Fix | Delete
`cache_lifetime` INT DEFAULT 60,
[163] Fix | Delete
PRIMARY KEY (`feed_id`)
[164] Fix | Delete
){$charset}";
[165] Fix | Delete
$conn->query($sql);
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if(!LADDLUtils::existTable($conn, $streams2sources_table)){
[169] Fix | Delete
$sql = "
[170] Fix | Delete
CREATE TABLE `{$streams2sources_table}`
[171] Fix | Delete
(
[172] Fix | Delete
`feed_id` VARCHAR(20) NOT NULL,
[173] Fix | Delete
`stream_id` INT NOT NULL,
[174] Fix | Delete
PRIMARY KEY (`feed_id`, `stream_id`)
[175] Fix | Delete
){$charset}";
[176] Fix | Delete
$conn->query($sql);
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
if(!LADDLUtils::existTable($conn, $posts_table)) {
[180] Fix | Delete
$sql = "
[181] Fix | Delete
CREATE TABLE `{$posts_table}`
[182] Fix | Delete
(
[183] Fix | Delete
`feed_id` VARCHAR(20) NOT NULL,
[184] Fix | Delete
`post_id` VARCHAR(50) NOT NULL,
[185] Fix | Delete
`post_type` VARCHAR(10) NOT NULL,
[186] Fix | Delete
`post_date` TIMESTAMP,
[187] Fix | Delete
`post_text` BLOB,
[188] Fix | Delete
`post_permalink` VARCHAR(300),
[189] Fix | Delete
`post_header` VARCHAR(200){$charset_collate},
[190] Fix | Delete
`user_nickname` VARCHAR(100){$charset_collate},
[191] Fix | Delete
`user_screenname` VARCHAR(200){$charset_collate},
[192] Fix | Delete
`user_pic` VARCHAR(300) NOT NULL,
[193] Fix | Delete
`user_link` VARCHAR(300),
[194] Fix | Delete
`user_bio` VARCHAR(200),
[195] Fix | Delete
`user_counts_media` INT,
[196] Fix | Delete
`user_counts_follows` INT,
[197] Fix | Delete
`user_counts_followed_by` INT,
[198] Fix | Delete
`rand_order` REAL,
[199] Fix | Delete
`creation_index` INT NOT NULL DEFAULT 0,
[200] Fix | Delete
`image_url` VARCHAR(500),
[201] Fix | Delete
`image_width` INT,
[202] Fix | Delete
`image_height` INT,
[203] Fix | Delete
`media_url` VARCHAR(500),
[204] Fix | Delete
`media_width` INT,
[205] Fix | Delete
`media_height` INT,
[206] Fix | Delete
`media_type` VARCHAR(100),
[207] Fix | Delete
PRIMARY KEY (`post_id`, `post_type`, `feed_id`)
[208] Fix | Delete
){$charset}";
[209] Fix | Delete
$conn->query($sql);
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
}
[213] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function