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: LAImageSizeCacheManager.php
<?php namespace la\core\cache;
[0] Fix | Delete
if ( ! defined( 'WPINC' ) ) die;
[1] Fix | Delete
[2] Fix | Delete
use Exception;
[3] Fix | Delete
use flow\social\cache\FFImageSizeCacheBase;
[4] Fix | Delete
use la\core\LAUtils;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Flow-Flow.
[8] Fix | Delete
*
[9] Fix | Delete
* @package FlowFlow
[10] Fix | Delete
* @author Looks Awesome <email@looks-awesome.com>
[11] Fix | Delete
[12] Fix | Delete
* @link http://looks-awesome.com
[13] Fix | Delete
* @copyright Looks Awesome
[14] Fix | Delete
*/
[15] Fix | Delete
class LAImageSizeCacheManager extends FFImageSizeCacheBase {
[16] Fix | Delete
const FF_IMG_CACHE_SIZE = 1000;
[17] Fix | Delete
[18] Fix | Delete
private $image_cache = null;
[19] Fix | Delete
private $new_images = [];
[20] Fix | Delete
private $context;
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* LAImageSizeCacheManager constructor.
[24] Fix | Delete
*
[25] Fix | Delete
* @param array $context
[26] Fix | Delete
*/
[27] Fix | Delete
public function __construct($context) {
[28] Fix | Delete
$this->context = $context;
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
public function getOriginalUrl($url){
[32] Fix | Delete
$this->lazy();
[33] Fix | Delete
[34] Fix | Delete
$h = hash('md5', $url);
[35] Fix | Delete
if (array_key_exists($h, $this->image_cache)){
[36] Fix | Delete
return $this->image_cache[$h]['original_url'];
[37] Fix | Delete
}
[38] Fix | Delete
return '';
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* @param string $url
[43] Fix | Delete
* @param string $original_url
[44] Fix | Delete
*
[45] Fix | Delete
* @return array
[46] Fix | Delete
*/
[47] Fix | Delete
public function size($url, $original_url = ''){
[48] Fix | Delete
$this->lazy();
[49] Fix | Delete
[50] Fix | Delete
$h = hash('md5', $url);
[51] Fix | Delete
if ($original_url != '') $url = $original_url;
[52] Fix | Delete
if (!array_key_exists($h, $this->image_cache)){
[53] Fix | Delete
try{
[54] Fix | Delete
$time = date("Y-m-d H:i:s", time());
[55] Fix | Delete
if (!empty($url)) {
[56] Fix | Delete
if (isset($_REQUEST['debug'])){
[57] Fix | Delete
ini_set('upload_max_filesize', '16M');
[58] Fix | Delete
ini_set('post_max_size', '16M');
[59] Fix | Delete
ini_set('max_input_time', '60');
[60] Fix | Delete
}
[61] Fix | Delete
@list($width, $height) = getimagesize($url);
[62] Fix | Delete
if (empty($width) || empty($height)){
[63] Fix | Delete
@list($width, $height) = $this->alternativeGetImageSize($url);
[64] Fix | Delete
if (empty($width) || empty($height)){
[65] Fix | Delete
$width = -1;
[66] Fix | Delete
$height = -1;
[67] Fix | Delete
}
[68] Fix | Delete
}
[69] Fix | Delete
$data = [ 'creation_time' => $time, 'width' => $width, 'height' => $height, 'original_url' => $original_url ];
[70] Fix | Delete
} else $data = [ 'creation_time' => $time, 'width' => -1, 'height' => -1, 'original_url' => $original_url ];
[71] Fix | Delete
if ($data['width'] > 0 && $data['height'] > 0){
[72] Fix | Delete
$this->image_cache[$h] = $data;
[73] Fix | Delete
$this->new_images[$h] = $data;
[74] Fix | Delete
}
[75] Fix | Delete
return $data;
[76] Fix | Delete
} catch ( Exception $e) {
[77] Fix | Delete
error_log($url);
[78] Fix | Delete
error_log($e->getMessage());
[79] Fix | Delete
error_log($e->getTraceAsString());
[80] Fix | Delete
return [ 'time' => time(), 'width' => -1, 'height' => -1, 'error' => $e->getMessage() ];
[81] Fix | Delete
}
[82] Fix | Delete
}
[83] Fix | Delete
return $this->image_cache[$h];
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* @return void
[88] Fix | Delete
*/
[89] Fix | Delete
public function save() {
[90] Fix | Delete
$this->lazy();
[91] Fix | Delete
[92] Fix | Delete
$dbm = LAUtils::dbm($this->context);
[93] Fix | Delete
$conn = $dbm->conn();
[94] Fix | Delete
if (sizeof($this->new_images) > 0 && $conn->beginTransaction()){
[95] Fix | Delete
foreach ( $this->new_images as $url => $image ) {
[96] Fix | Delete
$conn->query('INSERT INTO ?n SET `url` = ?s, ?u ON DUPLICATE KEY UPDATE ?u',
[97] Fix | Delete
$dbm->image_cache_table_name, $url, $image, [ 'creation_time' => $image['creation_time'] ] );
[98] Fix | Delete
}
[99] Fix | Delete
$conn->commit();
[100] Fix | Delete
}
[101] Fix | Delete
$conn->rollback();
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
private function alternativeGetImageSize($url){
[105] Fix | Delete
$raw = $this->ranger($url);
[106] Fix | Delete
if ($raw === 'URL signature expired'){
[107] Fix | Delete
return [ -1, -1 ];
[108] Fix | Delete
}
[109] Fix | Delete
$im = imagecreatefromstring($raw);
[110] Fix | Delete
$width = imagesx($im);
[111] Fix | Delete
$height = imagesy($im);
[112] Fix | Delete
imagedestroy($im);
[113] Fix | Delete
return [ $width, $height ];
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
private function ranger($url){
[117] Fix | Delete
$headers = [
[118] Fix | Delete
"Range: bytes=0-32768"
[119] Fix | Delete
];
[120] Fix | Delete
[121] Fix | Delete
$curl = curl_init($url);
[122] Fix | Delete
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36');
[123] Fix | Delete
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
[124] Fix | Delete
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
[125] Fix | Delete
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
[126] Fix | Delete
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 5000);
[127] Fix | Delete
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
[128] Fix | Delete
$data = curl_exec($curl);
[129] Fix | Delete
curl_close($curl);
[130] Fix | Delete
return $data;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
private function lazy(){
[134] Fix | Delete
if ($this->image_cache == null) {
[135] Fix | Delete
$dbm = LAUtils::dbm($this->context);
[136] Fix | Delete
$sql = "SELECT `url`, `width`, `height`, `original_url` FROM ?n ORDER BY `creation_time` DESC LIMIT ?i";
[137] Fix | Delete
if (false === ($result = $dbm->conn()->getIndCol('url', $sql, $dbm->image_cache_table_name, self::FF_IMG_CACHE_SIZE))) {
[138] Fix | Delete
$result = [];
[139] Fix | Delete
}
[140] Fix | Delete
$this->image_cache = $result;
[141] Fix | Delete
}
[142] Fix | Delete
}
[143] Fix | Delete
}
[144] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function