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/flow-flo.../libs/flowflow/social/src/flow/social
File: FFFeedUtils.php
<?php namespace flow\social;
[0] Fix | Delete
if ( ! defined( 'WPINC' ) ) die;
[1] Fix | Delete
[2] Fix | Delete
use Cake\Cache\Engine\FileEngine;
[3] Fix | Delete
use Cake\Cache\SimpleCacheEngine;
[4] Fix | Delete
use Exception;
[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
* @link http://looks-awesome.com
[12] Fix | Delete
* @copyright 2014-2016 Looks Awesome
[13] Fix | Delete
*/
[14] Fix | Delete
class FFFeedUtils{
[15] Fix | Delete
private static $USER_AGENT = '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';
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* @param int $templateWidth
[19] Fix | Delete
* @param int $originalWidth
[20] Fix | Delete
* @param int $originalHeight
[21] Fix | Delete
* @return int|string
[22] Fix | Delete
*/
[23] Fix | Delete
public static function getScaleHeight($templateWidth, $originalWidth, $originalHeight){
[24] Fix | Delete
if (isset($originalWidth) && isset($originalHeight) && !empty($originalWidth)){
[25] Fix | Delete
$k = $templateWidth / $originalWidth;
[26] Fix | Delete
return (int)round( $originalHeight * $k );
[27] Fix | Delete
}
[28] Fix | Delete
return '';
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* @param $url
[33] Fix | Delete
* @param int $timeout
[34] Fix | Delete
* @param bool $header
[35] Fix | Delete
* @param bool $log
[36] Fix | Delete
* @param bool $followLocation
[37] Fix | Delete
* @param bool $useIpv4
[38] Fix | Delete
*
[39] Fix | Delete
* @return array
[40] Fix | Delete
* @throws LASocialRequestException
[41] Fix | Delete
* @throws Exception
[42] Fix | Delete
*/
[43] Fix | Delete
public static function getFeedDataWithThrowException($url, $timeout = 60, $header = false, $log = true, $followLocation = true, $useIpv4 = true){
[44] Fix | Delete
$response = self::getFeedData($url, $timeout, $header, $log, $followLocation, $useIpv4);
[45] Fix | Delete
[46] Fix | Delete
if (sizeof($response['errors']) > 0){
[47] Fix | Delete
$message = isset($response['errors'][0]['msg']) ? $response['errors'][0]['msg'] : '';
[48] Fix | Delete
if ($message == 'An unknown error has occurred.' && strpos($url, 'comments.summary(true),') > 0){
[49] Fix | Delete
$url = str_replace('comments.summary(true),', '', $url);
[50] Fix | Delete
$response = self::getFeedDataWithThrowException($url, $timeout, $header, $log, $followLocation, $useIpv4);
[51] Fix | Delete
}
[52] Fix | Delete
else {
[53] Fix | Delete
throw new LASocialRequestException($url, $response['errors'], $message);
[54] Fix | Delete
}
[55] Fix | Delete
}
[56] Fix | Delete
return $response;
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* @param string $url
[61] Fix | Delete
* @param int $timeout
[62] Fix | Delete
* @param bool|array $header
[63] Fix | Delete
* @param bool $log
[64] Fix | Delete
*
[65] Fix | Delete
* @param bool $followLocation
[66] Fix | Delete
* @param bool $useIpv4
[67] Fix | Delete
*
[68] Fix | Delete
* @return array
[69] Fix | Delete
*/
[70] Fix | Delete
public static function getFeedData($url, $timeout = 60, $header = false, $log = true, $followLocation = true, $useIpv4 = true){
[71] Fix | Delete
$c = curl_init();
[72] Fix | Delete
curl_setopt($c, CURLOPT_USERAGENT, self::$USER_AGENT);
[73] Fix | Delete
curl_setopt($c, CURLOPT_URL,$url);
[74] Fix | Delete
curl_setopt($c, CURLOPT_POST, 0);
[75] Fix | Delete
curl_setopt($c, CURLOPT_FAILONERROR, true);
[76] Fix | Delete
[77] Fix | Delete
// Enable if you have 'Network is unreachable' error
[78] Fix | Delete
if ($useIpv4) curl_setopt( $c, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
[79] Fix | Delete
if ($followLocation) curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
[80] Fix | Delete
curl_setopt($c, CURLOPT_AUTOREFERER, true);
[81] Fix | Delete
curl_setopt($c, CURLOPT_RETURNTRANSFER,true);
[82] Fix | Delete
curl_setopt($c, CURLOPT_VERBOSE, false);
[83] Fix | Delete
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
[84] Fix | Delete
/** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */
[85] Fix | Delete
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
[86] Fix | Delete
if (isset($_COOKIE['XDEBUG_SESSION']) && $_COOKIE['XDEBUG_SESSION'] == 'PHPSTORM') curl_setopt($c, CURLOPT_COOKIE, 'XDEBUG_SESSION=PHPSTORM');
[87] Fix | Delete
if ($timeout != null) curl_setopt($c, CURLOPT_TIMEOUT, $timeout);
[88] Fix | Delete
curl_setopt($c, CURLOPT_CONNECTTIMEOUT_MS, 5000);
[89] Fix | Delete
if (is_array($header)) curl_setopt($c, CURLOPT_HTTPHEADER, $header);
[90] Fix | Delete
$page = ($followLocation) ? curl_exec($c) : self::curl_exec_follow($c);
[91] Fix | Delete
$error = curl_error($c);
[92] Fix | Delete
$errors = array();
[93] Fix | Delete
if (strlen($error) > 0){
[94] Fix | Delete
if ($log) {
[95] Fix | Delete
if (isset($_REQUEST['debug'])) {
[96] Fix | Delete
echo 'DEBUG:: <br>';
[97] Fix | Delete
var_dump($error);
[98] Fix | Delete
echo '<br>';
[99] Fix | Delete
var_dump(debug_backtrace());
[100] Fix | Delete
echo 'URL: ' . $url;
[101] Fix | Delete
echo '<br>-------<br>';
[102] Fix | Delete
error_log(print_r($error, true));
[103] Fix | Delete
error_log(print_r(debug_backtrace(), true));
[104] Fix | Delete
error_log($url);
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
if (strpos($error, 'Failed to connect') !== false && strpos($error, 'Network is unreachable') !== false){
[108] Fix | Delete
curl_setopt($c, CURLOPT_FAILONERROR, false);
[109] Fix | Delete
$page = ($followLocation) ? curl_exec($c) : self::curl_exec_follow($c);
[110] Fix | Delete
$error2 = curl_error($c);
[111] Fix | Delete
if (strlen($error2) > 0){
[112] Fix | Delete
$error .= '. Please, enable "USE IPV4 PROTOCOL" option at the settings tab.';
[113] Fix | Delete
$errors[] = array('msg' => $error, 'url' => $url);
[114] Fix | Delete
error_log('FFFeedUtils line 110 :: ' . $error);
[115] Fix | Delete
error_log('FFFeedUtils line 111 :: ' . $error2);
[116] Fix | Delete
}
[117] Fix | Delete
curl_close($c);
[118] Fix | Delete
return array('response' => $page, 'errors' => $errors);
[119] Fix | Delete
}
[120] Fix | Delete
else if ((strpos($url, 'https://graph.facebook.com') === 0) ||
[121] Fix | Delete
(strpos($url, 'https://api.instagram.com') === 0) ||
[122] Fix | Delete
(strpos($url, 'https://api.linkedin.com') === 0) ||
[123] Fix | Delete
(strpos($url, 'https://www.googleapis.com') === 0)
[124] Fix | Delete
) {
[125] Fix | Delete
curl_setopt($c, CURLOPT_FAILONERROR, false);
[126] Fix | Delete
$body = ($followLocation) ? curl_exec($c) : self::curl_exec_follow($c);
[127] Fix | Delete
$body = json_decode($body);
[128] Fix | Delete
if (isset($body->error->message)) $error = $body->error->message;
[129] Fix | Delete
else if (isset($body->meta->error_message)) $error = $body->meta->error_message;
[130] Fix | Delete
else if (isset($body->message)) $error = $body->message;
[131] Fix | Delete
else if (!is_null($body)) $error = 'Problem with parsing the error data';//print_r($body, true);
[132] Fix | Delete
}
[133] Fix | Delete
$errors[] = array('msg' => $error, 'url' => $url);
[134] Fix | Delete
} else if (200 != $http_code = curl_getinfo($c, CURLINFO_HTTP_CODE)){
[135] Fix | Delete
$errors[] = ['msg' => 'Unexpected HTTP code: ' . $http_code, 'url' => $url];
[136] Fix | Delete
}
[137] Fix | Delete
curl_close($c);
[138] Fix | Delete
return array('response' => $page, 'errors' => $errors);
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* @param string $text
[143] Fix | Delete
* @return mixed
[144] Fix | Delete
*/
[145] Fix | Delete
public static function removeEmoji($text) {
[146] Fix | Delete
if (defined('FF_REMOVE_EMOJI') && !FF_REMOVE_EMOJI){
[147] Fix | Delete
return $text;
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
// Match Emoticons
[151] Fix | Delete
$regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
[152] Fix | Delete
$clean_text = preg_replace($regexEmoticons, '', $text);
[153] Fix | Delete
[154] Fix | Delete
// Match Miscellaneous Symbols and Pictographs
[155] Fix | Delete
$regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
[156] Fix | Delete
$clean_text = preg_replace($regexSymbols, '', $clean_text);
[157] Fix | Delete
[158] Fix | Delete
// Match Transport And Map Symbols
[159] Fix | Delete
$regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
[160] Fix | Delete
$clean_text = preg_replace($regexTransport, '', $clean_text);
[161] Fix | Delete
[162] Fix | Delete
// Match Miscellaneous Symbols
[163] Fix | Delete
$regexMisc = '/[\x{2600}-\x{26FF}]/u';
[164] Fix | Delete
$clean_text = preg_replace($regexMisc, '', $clean_text);
[165] Fix | Delete
[166] Fix | Delete
// Match Dingbats
[167] Fix | Delete
$regexDingbats = '/[\x{2700}-\x{27BF}]/u';
[168] Fix | Delete
$clean_text = preg_replace($regexDingbats, '', $clean_text);
[169] Fix | Delete
[170] Fix | Delete
return $clean_text;
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* @param string $source
[175] Fix | Delete
* @return mixed
[176] Fix | Delete
*/
[177] Fix | Delete
public static function wrapLinks($source){
[178] Fix | Delete
$pattern = '/(https?:\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/i';
[179] Fix | Delete
$replacement = '<a href="$1">$1</a>';
[180] Fix | Delete
return preg_replace($pattern, $replacement, $source);
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
public static function getUrlFromImg($tag){
[184] Fix | Delete
preg_match("/\<img.+src\=(?:\"|\')(.+?)(?:\"|\')(?:.+?)\>/", $tag, $matches);
[185] Fix | Delete
return $matches[1];
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
public static function preparePrefixContent($content, $prefix){
[189] Fix | Delete
if (strpos($content, $prefix) === 0){
[190] Fix | Delete
return str_replace($prefix, '', $content);
[191] Fix | Delete
}
[192] Fix | Delete
return $content;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
private static function curl_exec_follow($ch, &$maxRedirect = null) {
[196] Fix | Delete
$mr = $maxRedirect === null ? 5 : intval($maxRedirect);
[197] Fix | Delete
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
[198] Fix | Delete
[199] Fix | Delete
if ($mr > 0) {
[200] Fix | Delete
$original_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
[201] Fix | Delete
$newUrl = $original_url;
[202] Fix | Delete
[203] Fix | Delete
$rch = curl_copy_handle($ch);
[204] Fix | Delete
[205] Fix | Delete
curl_setopt($rch, CURLOPT_HEADER, true);
[206] Fix | Delete
curl_setopt($rch, CURLOPT_NOBODY, true);
[207] Fix | Delete
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
[208] Fix | Delete
do {
[209] Fix | Delete
curl_setopt($rch, CURLOPT_URL, $newUrl);
[210] Fix | Delete
$header = curl_exec($rch);
[211] Fix | Delete
if (curl_errno($rch)) {
[212] Fix | Delete
$code = 0;
[213] Fix | Delete
} else {
[214] Fix | Delete
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
[215] Fix | Delete
if ($code == 301 || $code == 302) {
[216] Fix | Delete
preg_match('/Location:(.*?)\n/i', $header, $matches);
[217] Fix | Delete
$newUrl = trim(array_pop($matches));
[218] Fix | Delete
[219] Fix | Delete
// if no scheme is present then the new url is a
[220] Fix | Delete
// relative path and thus needs some extra care
[221] Fix | Delete
if(!preg_match("/^https?:/i", $newUrl)){
[222] Fix | Delete
$newUrl = $original_url . $newUrl;
[223] Fix | Delete
}
[224] Fix | Delete
} else {
[225] Fix | Delete
$code = 0;
[226] Fix | Delete
}
[227] Fix | Delete
}
[228] Fix | Delete
} while ($code && --$mr);
[229] Fix | Delete
[230] Fix | Delete
curl_close($rch);
[231] Fix | Delete
[232] Fix | Delete
if (!$mr) {
[233] Fix | Delete
if ($maxRedirect === null)
[234] Fix | Delete
trigger_error('Too many redirects.', E_USER_WARNING);
[235] Fix | Delete
else
[236] Fix | Delete
$maxRedirect = 0;
[237] Fix | Delete
[238] Fix | Delete
return false;
[239] Fix | Delete
}
[240] Fix | Delete
curl_setopt($ch, CURLOPT_URL, $newUrl);
[241] Fix | Delete
}
[242] Fix | Delete
return curl_exec($ch);
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
public static function hashtagLinks($text) {
[246] Fix | Delete
$result = preg_replace('~(\#)([^\s!,. /()"\'?]+)~', '<a href="https://www.instagram.com/explore/tags/$2">#$2</a>', $text);
[247] Fix | Delete
$result = FFFeedUtils::removeEmoji($result);
[248] Fix | Delete
return $result;
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
[252] Fix | Delete
/**
[253] Fix | Delete
* @param null | array $context
[254] Fix | Delete
*
[255] Fix | Delete
* @return SimpleCacheEngine
[256] Fix | Delete
*/
[257] Fix | Delete
public static function getCache($context = null){
[258] Fix | Delete
$slug = 'flow-flow';
[259] Fix | Delete
if (!is_null($context) && isset($context['slug'])){
[260] Fix | Delete
$slug = $context['slug'];
[261] Fix | Delete
}
[262] Fix | Delete
if (defined('FF_CACHE_PATH')){
[263] Fix | Delete
$session_folder = FF_CACHE_PATH . '/sessions';
[264] Fix | Delete
}
[265] Fix | Delete
else {
[266] Fix | Delete
$session_folder = WP_CONTENT_DIR . '/resources/' . $slug . '/cache/sessions';
[267] Fix | Delete
}
[268] Fix | Delete
$fileEngine = new FileEngine();
[269] Fix | Delete
$fileEngine->init([
[270] Fix | Delete
'duration' => '+1 hours',
[271] Fix | Delete
'path' => $session_folder,
[272] Fix | Delete
'prefix' => 'ff_instagram_']);
[273] Fix | Delete
return new SimpleCacheEngine($fileEngine);
[274] Fix | Delete
}
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function