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.../libs/flowflow/core/src/cache
File: LACacheManager.php
<?php namespace la\core\cache;
[0] Fix | Delete
if ( ! defined( 'WPINC' ) ) die;
[1] Fix | Delete
[2] Fix | Delete
use DateTime;
[3] Fix | Delete
use DateTimeZone;
[4] Fix | Delete
use Exception;
[5] Fix | Delete
use flow\social\FFFeed;
[6] Fix | Delete
use flow\social\LAFeedWithComments;
[7] Fix | Delete
use la\core\db\LADBManager;
[8] Fix | Delete
use la\core\LAUtils;
[9] Fix | Delete
use la\core\settings\LAGeneralSettings;
[10] Fix | Delete
use la\core\settings\LASettingsUtils;
[11] Fix | Delete
use la\core\settings\LAStreamSettings;
[12] Fix | Delete
use stdClass;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Flow-Flow.
[16] Fix | Delete
*
[17] Fix | Delete
* @package FlowFlow
[18] Fix | Delete
* @author Looks Awesome <email@looks-awesome.com>
[19] Fix | Delete
[20] Fix | Delete
* @link http://looks-awesome.com
[21] Fix | Delete
* @copyright Looks Awesome
[22] Fix | Delete
*
[23] Fix | Delete
* @property LADBManager $db
[24] Fix | Delete
* @property LAStreamSettings $stream
[25] Fix | Delete
*/
[26] Fix | Delete
class LACacheManager implements LACache{
[27] Fix | Delete
private $force;
[28] Fix | Delete
private $feeds;
[29] Fix | Delete
private $stream;
[30] Fix | Delete
private $hash = '';
[31] Fix | Delete
private $errors = [];
[32] Fix | Delete
[33] Fix | Delete
protected $db;
[34] Fix | Delete
[35] Fix | Delete
function __construct($context = null, $force = false){
[36] Fix | Delete
$this->force = $force;
[37] Fix | Delete
$this->db = LAUtils::dbm($context);
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* @param array $feeds
[42] Fix | Delete
* @param bool $disableCache
[43] Fix | Delete
*
[44] Fix | Delete
* @throws Exception
[45] Fix | Delete
* @return array
[46] Fix | Delete
*/
[47] Fix | Delete
public function posts($feeds, $disableCache){
[48] Fix | Delete
if (isset($_REQUEST['clean']) && $_REQUEST['clean']) $this->db->clean();
[49] Fix | Delete
if (isset($_REQUEST['clean-stream']) && $_REQUEST['clean-stream']) $this->db->clean( [ $this->stream->getId() ] );
[50] Fix | Delete
$this->feeds = $feeds;
[51] Fix | Delete
if ($this->force){
[52] Fix | Delete
$conn = $this->db->conn();
[53] Fix | Delete
$hasNewItems = false;
[54] Fix | Delete
$this->hash = time();
[55] Fix | Delete
/** @var FFFeed $feed */
[56] Fix | Delete
foreach ( $feeds as $feed_id => $feed ) {
[57] Fix | Delete
try{
[58] Fix | Delete
$status = ['status' => empty($feed->feed->errors) ? '1' : '0', 'errors' => serialize([])];
[59] Fix | Delete
if ($this->expiredLifeTime($feed_id)) {
[60] Fix | Delete
$exist_feed_ids = $this->db->getIdPosts($feed_id);
[61] Fix | Delete
[62] Fix | Delete
$posts = $feed->posts(empty($exist_feed_ids));
[63] Fix | Delete
[64] Fix | Delete
$errors = $feed->errors();
[65] Fix | Delete
$countGotPosts = sizeof( $posts );
[66] Fix | Delete
$criticalError = ($countGotPosts == 0 && sizeof($errors) > 0 && $feed->hasCriticalError());
[67] Fix | Delete
$status = ['last_update' => $criticalError ? 0 : time(), 'errors' => $this->serializeErrors($errors), 'status' => (int)(!$criticalError)];
[68] Fix | Delete
[69] Fix | Delete
if (!$criticalError){
[70] Fix | Delete
list($new_posts, $existed_posts) = $this->separation($exist_feed_ids, $posts);
[71] Fix | Delete
$countPosts4Insert = sizeof($new_posts);
[72] Fix | Delete
if ($conn->beginTransaction()){
[73] Fix | Delete
$this->save( $feed, $posts);
[74] Fix | Delete
[75] Fix | Delete
if ($countPosts4Insert > 0) {
[76] Fix | Delete
$this->db->setOrders($feed_id);
[77] Fix | Delete
$hasNewItems = true;
[78] Fix | Delete
}
[79] Fix | Delete
}
[80] Fix | Delete
}
[81] Fix | Delete
if (isset($feed->feed->system_enabled) && $feed->feed->system_enabled != (int)!$criticalError) {
[82] Fix | Delete
$this->db->systemDisableSource($feed_id, (int)!$criticalError);
[83] Fix | Delete
}
[84] Fix | Delete
}
[85] Fix | Delete
$this->db->saveSource($feed_id, $status);
[86] Fix | Delete
$conn->commit();
[87] Fix | Delete
}
[88] Fix | Delete
catch( Exception $e){
[89] Fix | Delete
$conn->rollback();
[90] Fix | Delete
$hasNewItems = false;
[91] Fix | Delete
$errors = [];
[92] Fix | Delete
$errors[] = [
[93] Fix | Delete
'type' => $feed->getType(),
[94] Fix | Delete
'message' => $e->getMessage(),
[95] Fix | Delete
'code' => $e->getCode()
[96] Fix | Delete
];
[97] Fix | Delete
$status = ['last_update' => 0, 'errors' => $this->serializeErrors($errors), 'status' => 0, 'system_enabled' => 0, 'send_email' => 0];
[98] Fix | Delete
$this->db->saveSource($feed->id(), $status);
[99] Fix | Delete
$conn->commit();
[100] Fix | Delete
}
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
if ($hasNewItems){
[104] Fix | Delete
$this->removeOldRecords();
[105] Fix | Delete
$conn->commit();
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
$conn->rollbackAndClose();
[109] Fix | Delete
return [];
[110] Fix | Delete
} else {
[111] Fix | Delete
if (empty($_REQUEST['hash']) || $disableCache){
[112] Fix | Delete
$this->force = true;
[113] Fix | Delete
$_REQUEST['force'] = true;
[114] Fix | Delete
$this->posts($feeds, $disableCache);
[115] Fix | Delete
unset($_REQUEST['force']);
[116] Fix | Delete
$_REQUEST['hash'] = $this->hash();
[117] Fix | Delete
}
[118] Fix | Delete
return $this->get();
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
public function hash(){
[123] Fix | Delete
return $this->encodeHash($this->hash);
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
public function transientHash($streamId){
[127] Fix | Delete
$hash = $this->db->getLastUpdateHash($streamId);
[128] Fix | Delete
return (false !== $hash) ? $this->encodeHash($hash) : '';
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
public function errors(){
[132] Fix | Delete
return $this->errors;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
public function moderate(){
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* @param LAStreamSettings $stream
[140] Fix | Delete
* @param bool $moderation
[141] Fix | Delete
*
[142] Fix | Delete
* @return void
[143] Fix | Delete
*/
[144] Fix | Delete
public function setStream($stream, $moderation = false) {
[145] Fix | Delete
$this->stream = $stream;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
protected function getGetFields(){
[149] Fix | Delete
$select = "post.post_id as id, post.post_type as type, post.user_nickname as nickname, ";
[150] Fix | Delete
$select .= "post.user_pic as userpic, ";
[151] Fix | Delete
$select .= "post.post_timestamp as system_timestamp, ";
[152] Fix | Delete
$select .= "post.location as location, ";
[153] Fix | Delete
$select .= "post.user_link as userlink, post.post_permalink as permalink, ";
[154] Fix | Delete
$select .= "post.image_url, post.image_width, post.image_height, post.media_url, post.media_type, ";
[155] Fix | Delete
$select .= "post.user_counts_media, post.user_counts_follows, post.user_counts_followed_by, ";
[156] Fix | Delete
$select .= "post.media_width, post.media_height, post.post_source, post.post_additional, post.feed_id, ";
[157] Fix | Delete
$select .= "post.carousel_size ";
[158] Fix | Delete
$select .= FF_ALTERNATIVE_POST_STORAGE ? ", post.post_content " : ", post.user_screenname as screenname, post.post_header, post.post_text as text, post.user_bio ";
[159] Fix | Delete
return $select;
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
protected function getGetFilters(){
[163] Fix | Delete
$conn = $this->db->conn();
[164] Fix | Delete
$args[] = $conn->parse('stream.stream_id = ?s', $this->stream->getId());
[165] Fix | Delete
$args[] = $conn->parse('cach.enabled = 1');
[166] Fix | Delete
$args[] = $conn->parse('cach.boosted = \'nope\'');
[167] Fix | Delete
if ($this->stream->showOnlyMediaPosts()) $args[] = "post.image_url IS NOT NULL";
[168] Fix | Delete
if (isset($_REQUEST['hash']))
[169] Fix | Delete
if (isset($_REQUEST['recent'])){
[170] Fix | Delete
$args[] = $conn->parse('post.creation_index > ?s', $this->decodeHash($_REQUEST['hash']));
[171] Fix | Delete
} else {
[172] Fix | Delete
$args[] = $conn->parse('post.creation_index <= ?s', $this->decodeHash($_REQUEST['hash']));
[173] Fix | Delete
}
[174] Fix | Delete
return $args;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
/** @noinspection PhpUnusedParameterInspection */
[178] Fix | Delete
protected function getOnlyNew($moderation){
[179] Fix | Delete
return [];
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* @return mixed
[184] Fix | Delete
*/
[185] Fix | Delete
private function get(){
[186] Fix | Delete
$where = implode(' AND ', $this->getGetFilters());
[187] Fix | Delete
[188] Fix | Delete
$order = 'post.smart_order, post.post_timestamp DESC';
[189] Fix | Delete
if ($this->stream->order() == FF_RANDOM_ORDER) $order = 'post.rand_order, post.post_id';
[190] Fix | Delete
if ($this->stream->order() == FF_BY_DATE_ORDER) $order = 'post.post_timestamp DESC, post.post_id';
[191] Fix | Delete
[192] Fix | Delete
$moderation = [];
[193] Fix | Delete
foreach ( $this->stream->getAllFeeds() as $feed ) {
[194] Fix | Delete
$moderation[$feed['id']] = LASettingsUtils::YepNope2ClassicStyleSafe($feed, 'mod', false);
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
$limit = null;
[198] Fix | Delete
$offset = null;
[199] Fix | Delete
$result = [];
[200] Fix | Delete
if (!isset($_REQUEST['recent'])){
[201] Fix | Delete
$page = isset($_REQUEST['page']) ? (int) $_REQUEST['page'] : 0;
[202] Fix | Delete
$limit = $this->stream->getCountOfPostsOnPage();
[203] Fix | Delete
$offset = $page * $limit;
[204] Fix | Delete
[205] Fix | Delete
if ($page == 0){
[206] Fix | Delete
$result = $this->getOnlyNew($moderation);
[207] Fix | Delete
if (!isset($_REQUEST['countOfPages'])){
[208] Fix | Delete
$totalCount = $this->db->countPostsIf($where);
[209] Fix | Delete
if ($totalCount === false) $totalCount = 0;
[210] Fix | Delete
$countOfPages = ($limit > $totalCount) ? 1 : ceil($totalCount / $limit);
[211] Fix | Delete
$_REQUEST['countOfPages'] = $countOfPages;
[212] Fix | Delete
}
[213] Fix | Delete
}
[214] Fix | Delete
}
[215] Fix | Delete
$resultFromDB = $this->db->getPostsIf($this->getGetFields(), $where, $order, $offset, $limit);
[216] Fix | Delete
if (false === $resultFromDB) $resultFromDB = [];
[217] Fix | Delete
[218] Fix | Delete
foreach ( $resultFromDB as $row ) {
[219] Fix | Delete
$result[] = $this->buildPost($row, $moderation[$row['feed_id']]);
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
//$this->errors = LADB::getError($this->db->conn, $this->db->cache_table_name, $this->db->streams_sources_table_name, $this->stream->getId());
[223] Fix | Delete
$this->hash = $this->db->getHashIf($where);
[224] Fix | Delete
return $result;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
/**
[228] Fix | Delete
* @param $feed
[229] Fix | Delete
* @param $value
[230] Fix | Delete
*
[231] Fix | Delete
* @throws Exception
[232] Fix | Delete
* @return void
[233] Fix | Delete
*/
[234] Fix | Delete
private function save( $feed, $value ) {
[235] Fix | Delete
if (sizeof($value) > 0) {
[236] Fix | Delete
$timezone = get_option( 'timezone_string' );
[237] Fix | Delete
$conn = $this->db->conn();
[238] Fix | Delete
$only4insertPartOfSqlTemplate = $conn->parse('`creation_index`=?i', $this->hash);
[239] Fix | Delete
$status = $this->getDefaultStreamStatus($feed);
[240] Fix | Delete
[241] Fix | Delete
foreach ($value as $id => $post){
[242] Fix | Delete
$feed_id = $post->feed_id;
[243] Fix | Delete
[244] Fix | Delete
$imagePartOfSql = (isset($post->img) && sizeof($post->img) == 3) ?
[245] Fix | Delete
$conn->parse('`image_url`=?s, `image_width`=?i, `image_height`=?i,',
[246] Fix | Delete
$post->img['url'], $post->img['width'], $post->img['height']) : '';
[247] Fix | Delete
$mediaPartOfSql = (isset($post->media) && sizeof($post->media) == 4) ?
[248] Fix | Delete
$conn->parse('`media_url`=?s, `media_width`=?i, `media_height`=?i, `media_type`=?s,',
[249] Fix | Delete
$post->media['url'], $post->media['width'], $post->media['height'], $post->media['type']) : '';
[250] Fix | Delete
[251] Fix | Delete
if (FF_ALTERNATIVE_POST_STORAGE){
[252] Fix | Delete
$post_content = json_encode( [
[253] Fix | Delete
'user_screenname' => $post->screenname,
[254] Fix | Delete
'post_header' => $this->prepareText( isset( $post->header ) ? $post->header : '' ),
[255] Fix | Delete
'post_text' => $this->prepareText($post->text),
[256] Fix | Delete
'user_bio' => (isset($post->userMeta->bio) ? ( $post->userMeta->bio . (isset($post->userMeta->website) ? ' ' . $post->userMeta->website : '')) : ''),
[257] Fix | Delete
]);
[258] Fix | Delete
[259] Fix | Delete
$only4insertPartOfSql = $conn->parse('?p, ?u', $only4insertPartOfSqlTemplate, [
[260] Fix | Delete
'feed_id' => $feed_id,
[261] Fix | Delete
'post_id' => $post->id,
[262] Fix | Delete
'post_type' => $post->type,
[263] Fix | Delete
'post_permalink' => $post->permalink,
[264] Fix | Delete
'user_nickname' => $post->nickname,
[265] Fix | Delete
'user_pic' => $post->userpic,
[266] Fix | Delete
'user_counts_media' => isset($post->userMeta->counts->media) ? $post->userMeta->counts->media : 0,
[267] Fix | Delete
'user_counts_follows' => isset($post->userMeta->counts->follows) ? $post->userMeta->counts->follows : 0,
[268] Fix | Delete
'user_counts_followed_by' => isset($post->userMeta->counts->followed_by) ? $post->userMeta->counts->followed_by : 0,
[269] Fix | Delete
'user_link' => $post->userlink,
[270] Fix | Delete
'post_source' => isset($post->source) ? $post->source : '',
[271] Fix | Delete
'location' => isset($post->location) ? json_encode($post->location) : '',
[272] Fix | Delete
'smart_order' => $post->smart_order,
[273] Fix | Delete
'post_status' => $status
[274] Fix | Delete
]);
[275] Fix | Delete
[276] Fix | Delete
if (!isset($post->additional)) $post->additional = [];
[277] Fix | Delete
$common = [
[278] Fix | Delete
'post_content' => $post_content,
[279] Fix | Delete
'post_timestamp' => $this->correctionTimeZone($post->system_timestamp, $timezone),
[280] Fix | Delete
'post_additional' => json_encode($post->additional),
[281] Fix | Delete
'carousel_size' => 0
[282] Fix | Delete
];
[283] Fix | Delete
}
[284] Fix | Delete
else {
[285] Fix | Delete
$only4insertPartOfSql = $conn->parse('?p, ?u', $only4insertPartOfSqlTemplate, [
[286] Fix | Delete
'feed_id' => $feed_id,
[287] Fix | Delete
'post_id' => $post->id,
[288] Fix | Delete
'post_type' => $post->type,
[289] Fix | Delete
'post_permalink' => $post->permalink,
[290] Fix | Delete
'user_nickname' => $post->nickname,
[291] Fix | Delete
'user_screenname' => $post->screenname,
[292] Fix | Delete
'user_pic' => $post->userpic,
[293] Fix | Delete
'user_bio' => (isset($post->userMeta->bio) ? json_encode( $post->userMeta->bio . (isset($post->userMeta->website) ? ' ' . $post->userMeta->website : '')) : ''),
[294] Fix | Delete
'user_counts_media' => isset($post->userMeta->counts->media) ? $post->userMeta->counts->media : 0,
[295] Fix | Delete
'user_counts_follows' => isset($post->userMeta->counts->follows) ? $post->userMeta->counts->follows : 0,
[296] Fix | Delete
'user_counts_followed_by' => isset($post->userMeta->counts->followed_by) ? $post->userMeta->counts->followed_by : 0,
[297] Fix | Delete
'user_link' => $post->userlink,
[298] Fix | Delete
'post_source' => isset($post->source) ? $post->source : '',
[299] Fix | Delete
'location' => isset($post->location) ? json_encode($post->location) : '',
[300] Fix | Delete
'smart_order' => $post->smart_order,
[301] Fix | Delete
'post_status' => $status
[302] Fix | Delete
]);
[303] Fix | Delete
[304] Fix | Delete
if (!isset($post->additional)) $post->additional = [];
[305] Fix | Delete
$common = [
[306] Fix | Delete
'post_header' => @$conn->getMySQLi()->real_escape_string(trim($post->header)),
[307] Fix | Delete
'post_text' => $this->prepareText($post->text),
[308] Fix | Delete
'post_timestamp' => $this->correctionTimeZone($post->system_timestamp, $timezone),
[309] Fix | Delete
'post_additional' => json_encode($post->additional),
[310] Fix | Delete
'carousel_size' => 0
[311] Fix | Delete
];
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
if (isset($post->carousel) && sizeof($post->carousel) > 1){
[315] Fix | Delete
$this->db->deleteCarousel4Post($feed_id, $post->id);
[316] Fix | Delete
foreach ($post->carousel as $media){
[317] Fix | Delete
$mediaPartOfSql4carousel = $conn->parse('`media_url`=?s, `media_width`=?i, `media_height`=?i, `media_type`=?s,',
[318] Fix | Delete
$media['url'], $media['width'], $media['height'], $media['type']);
[319] Fix | Delete
$this->db->addCarouselMedia($feed_id, $post->id, $media['type'], $mediaPartOfSql4carousel);
[320] Fix | Delete
}
[321] Fix | Delete
$common['carousel_size'] = sizeof($post->carousel);
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
if (isset($post->comments) && sizeof($post->comments) > 1){
[325] Fix | Delete
foreach ($post->comments as $comment){
[326] Fix | Delete
$this->db->addComments($post->id, $comment);
[327] Fix | Delete
}
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
$this->db->addOrUpdatePost($only4insertPartOfSql, $imagePartOfSql, $mediaPartOfSql, $common);
[331] Fix | Delete
}
[332] Fix | Delete
}
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
/**
[336] Fix | Delete
* @param $date
[337] Fix | Delete
* @param $timezone
[338] Fix | Delete
*
[339] Fix | Delete
* @return int
[340] Fix | Delete
* @throws Exception
[341] Fix | Delete
*/
[342] Fix | Delete
private function correctionTimeZone($date, $timezone){
[343] Fix | Delete
// Create datetime object with desired timezone
[344] Fix | Delete
$timezone = empty($timezone) ? 'UTC' : $timezone;
[345] Fix | Delete
$local_timezone = new DateTimeZone($timezone);
[346] Fix | Delete
$date_time = new DateTime('now', $local_timezone);
[347] Fix | Delete
$offset = $date_time->format('P'); // + 05:00
[348] Fix | Delete
[349] Fix | Delete
// Convert offset to number of hours
[350] Fix | Delete
$offset = explode(':', $offset);
[351] Fix | Delete
$offset2 = '';
[352] Fix | Delete
if($offset[1] == 00){ $offset2 = ''; }
[353] Fix | Delete
if($offset[1] == 30){ $offset2 = '.5'; }
[354] Fix | Delete
if($offset[1] == 45){ $offset2 = '.75'; }
[355] Fix | Delete
$hours = floatval($offset[0] . $offset2);
[356] Fix | Delete
[357] Fix | Delete
// Convert hours to seconds
[358] Fix | Delete
$seconds = $hours * 3600;
[359] Fix | Delete
[360] Fix | Delete
// Add/Subtract number of seconds from given unix/gmt/utc timestamp
[361] Fix | Delete
$result = floor( $date + $seconds );
[362] Fix | Delete
return (int) $result;
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
/**
[366] Fix | Delete
* @param $feedId
[367] Fix | Delete
*
[368] Fix | Delete
* @return bool
[369] Fix | Delete
*/
[370] Fix | Delete
private function expiredLifeTime($feedId){
[371] Fix | Delete
if (isset($_REQUEST['force']) && $_REQUEST['force']) return true;
[372] Fix | Delete
$conn = $this->db->conn();
[373] Fix | Delete
/** @noinspection SqlResolve */
[374] Fix | Delete
$sql = $conn->parse('SELECT `cach`.`feed_id` FROM ?n `cach` WHERE `cach`.`feed_id`=?s AND (`cach`.last_update + `cach`.cache_lifetime * 60) < UNIX_TIMESTAMP()', $this->db->cache_table_name, $feedId);
[375] Fix | Delete
return (false !== $conn->getOne($sql));
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
/**
[379] Fix | Delete
* @param array $row
[380] Fix | Delete
* @param bool $moderation
[381] Fix | Delete
*
[382] Fix | Delete
* @return stdClass
[383] Fix | Delete
*/
[384] Fix | Delete
protected function buildPost($row, $moderation = false){
[385] Fix | Delete
$post = new stdClass();
[386] Fix | Delete
$post->id = $row['id'];
[387] Fix | Delete
$post->type = $row['type'];
[388] Fix | Delete
$post->nickname = $row['nickname'];
[389] Fix | Delete
$post->userpic = $row['userpic'];
[390] Fix | Delete
$post->system_timestamp = $row['system_timestamp'];
[391] Fix | Delete
$post->timestamp = LASettingsUtils::classicStyleDate($row['system_timestamp'], LAGeneralSettings::get()->dateStyle());
[392] Fix | Delete
$post->location = json_decode($row['location']);
[393] Fix | Delete
$post->userlink = $row['userlink'];
[394] Fix | Delete
$post->user_counts_media = $row['user_counts_media'];
[395] Fix | Delete
$post->user_counts_follows = $row['user_counts_follows'];
[396] Fix | Delete
$post->user_counts_followed_by = $row['user_counts_followed_by'];
[397] Fix | Delete
$post->permalink = $row['permalink'];
[398] Fix | Delete
if (FF_ALTERNATIVE_POST_STORAGE){
[399] Fix | Delete
$post_content = $row['post_content'];
[400] Fix | Delete
$post_content = json_decode($post_content, true);
[401] Fix | Delete
[402] Fix | Delete
$post->screenname = $post_content['user_screenname'];
[403] Fix | Delete
$post->header = stripslashes($post_content['post_header']);
[404] Fix | Delete
$post->text = stripslashes($post_content['post_text']);
[405] Fix | Delete
$post->user_bio = $post_content['user_bio'];
[406] Fix | Delete
}
[407] Fix | Delete
else {
[408] Fix | Delete
$post->screenname = $row['screenname'];
[409] Fix | Delete
$post->header = stripslashes($row['post_header']);
[410] Fix | Delete
$post->text = stripslashes($row['text']);
[411] Fix | Delete
$post->user_bio = json_decode($row['user_bio']);
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
$post->mod = $moderation;
[415] Fix | Delete
$post->feed = $row['feed_id'];
[416] Fix | Delete
$post->with_comments = $this->feeds[$post->feed] instanceof LAFeedWithComments;
[417] Fix | Delete
[418] Fix | Delete
if (!empty($row['post_source'])) $post->source = $row['post_source'];
[419] Fix | Delete
if ($row['image_url'] != null){
[420] Fix | Delete
$url = $row['image_url'];
[421] Fix | Delete
$width = $row['image_width'];
[422] Fix | Delete
$tWidth = $this->stream->getImageWidth();
[423] Fix | Delete
$height = LASettingsUtils::getScaleHeight($tWidth, $width, $row['image_height']);
[424] Fix | Delete
if (($post->type != 'posts') && $this->db->getGeneralSettings()->useProxyServer() && ($width + 50) > $tWidth) $url = $this->proxy($url, $tWidth);
[425] Fix | Delete
if (($row['image_width'] == '-1') && ($row['image_height'] == '-1')) {
[426] Fix | Delete
$post->img = ['url' => $url, 'type' => 'image'];
[427] Fix | Delete
}
[428] Fix | Delete
else $post->img = ['url' => $url, 'width' => $tWidth, 'height' => $height, 'type' => 'image'];
[429] Fix | Delete
$post->media = $post->img;
[430] Fix | Delete
[431] Fix | Delete
if ($post->type == 'twitter') {
[432] Fix | Delete
$post->text = str_replace('%WIDTH%', $post->img['width'], $post->text);
[433] Fix | Delete
$post->text = str_replace('%HEIGHT%', $post->img['height'], $post->text);
[434] Fix | Delete
}
[435] Fix | Delete
}
[436] Fix | Delete
if ($row['media_url'] != null){
[437] Fix | Delete
$post->media = ['url' => $row['media_url'], 'width' => $row['media_width'], 'height' => $row['media_height'], 'type' => $row['media_type']];
[438] Fix | Delete
}
[439] Fix | Delete
$post->additional = json_decode($row['post_additional']);
[440] Fix | Delete
$post->carousel_size = $row['carousel_size'];
[441] Fix | Delete
return $post;
[442] Fix | Delete
}
[443] Fix | Delete
[444] Fix | Delete
/**
[445] Fix | Delete
* http://carlo.zottmann.org/2013/04/14/google-image-resizer/
[446] Fix | Delete
* @param string $url
[447] Fix | Delete
* @param string $width
[448] Fix | Delete
* @return string
[449] Fix | Delete
*/
[450] Fix | Delete
public static function proxy($url, $width){
[451] Fix | Delete
if (strpos($url, '/www.', 10) > 10) return $url;
[452] Fix | Delete
$query = http_build_query([
[453] Fix | Delete
'container' => 'focus',
[454] Fix | Delete
'resize_w' => $width,
[455] Fix | Delete
'refresh' => 86400, //one day
[456] Fix | Delete
'url' => $url]);
[457] Fix | Delete
return "https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy?".$query;
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
private function separation( $exist_feed_ids, $posts ){
[461] Fix | Delete
$existed_posts = [];
[462] Fix | Delete
foreach ( $exist_feed_ids as $id ) {
[463] Fix | Delete
if (isset($posts[$id])) {
[464] Fix | Delete
$existed_posts[] = $posts[$id];
[465] Fix | Delete
unset($posts[$id]);
[466] Fix | Delete
}
[467] Fix | Delete
}
[468] Fix | Delete
return [$posts, $existed_posts];
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
private function encodeHash($hash){
[472] Fix | Delete
if (!empty($hash)){
[473] Fix | Delete
$postfix = hash('md5', serialize($this->stream->original()));
[474] Fix | Delete
$postfix .= hash('md5', serialize(LAGeneralSettings::get()->original()));
[475] Fix | Delete
$postfix .= hash('md5', serialize(LAGeneralSettings::get()->originalAuth()));
[476] Fix | Delete
return $hash . "." . $postfix;
[477] Fix | Delete
}
[478] Fix | Delete
return $hash;
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
protected function decodeHash($hash){
[482] Fix | Delete
$pos = strpos($hash, ".");
[483] Fix | Delete
if ($pos === false) return $hash;
[484] Fix | Delete
if ($pos == 0) return '';
[485] Fix | Delete
return substr($hash, 0, $pos);
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
private function getDefaultStreamStatus($feed) {
[489] Fix | Delete
if ($this->moderation($feed)){
[490] Fix | Delete
if (defined('FF_SOFT_MODERATION_POLICY') && FF_SOFT_MODERATION_POLICY){
[491] Fix | Delete
return 'approved';
[492] Fix | Delete
}
[493] Fix | Delete
return 'new';
[494] Fix | Delete
}
[495] Fix | Delete
return 'approved';
[496] Fix | Delete
}
[497] Fix | Delete
[498] Fix | Delete
private function moderation($feed) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function