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: FFRss.php
<?php namespace flow\social;
[0] Fix | Delete
if ( ! defined( 'WPINC' ) ) die;
[1] Fix | Delete
[2] Fix | Delete
use \SimpleXMLElement;
[3] Fix | Delete
[4] Fix | Delete
/**
[5] Fix | Delete
* Flow-Flow.
[6] Fix | Delete
*
[7] Fix | Delete
* @package FlowFlow
[8] Fix | Delete
* @author Looks Awesome <email@looks-awesome.com>
[9] Fix | Delete
[10] Fix | Delete
* @link http://looks-awesome.com
[11] Fix | Delete
* @copyright 2014-2016 Looks Awesome
[12] Fix | Delete
*/
[13] Fix | Delete
class FFRss extends FFHttpRequestFeed {
[14] Fix | Delete
protected $image;
[15] Fix | Delete
protected $media;
[16] Fix | Delete
protected $userLink;
[17] Fix | Delete
protected $screenName;
[18] Fix | Delete
protected $profileImage;
[19] Fix | Delete
/** @var bool */
[20] Fix | Delete
private $isRichText = false;
[21] Fix | Delete
/** @var bool */
[22] Fix | Delete
private $hideCaption = false;
[23] Fix | Delete
/** @var SimpleXMLElement | null $xml */
[24] Fix | Delete
private $xml = null;
[25] Fix | Delete
/** @var mixed $mrss */
[26] Fix | Delete
private $mrss = false;
[27] Fix | Delete
[28] Fix | Delete
public function __construct( $type = null ) {
[29] Fix | Delete
if (is_null($type)) $type = 'rss';
[30] Fix | Delete
parent::__construct( $type );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
public function deferredInit($feed) {
[34] Fix | Delete
$this->url = $feed->content;
[35] Fix | Delete
$this->isRichText = $feed->{'rich-text'};
[36] Fix | Delete
$this->hideCaption = $feed->{'hide-caption'};
[37] Fix | Delete
if (isset($feed->{'channel-name'})) $this->screenName = $feed->{'channel-name'};
[38] Fix | Delete
$this->profileImage = isset($feed->{'avatar-url'}) && trim($feed->{'avatar-url'}) != ''?
[39] Fix | Delete
$feed->{'avatar-url'} : $this->context['plugin_url'] . '/' . $this->context['slug'] . '/assets/avatar_default_rss.png';
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
protected function getUrl(){
[43] Fix | Delete
return $this->url;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
protected function items($request){
[47] Fix | Delete
libxml_use_internal_errors(true);
[48] Fix | Delete
$pxml = new SimpleXMLElement($request);
[49] Fix | Delete
$this->xml = $pxml;
[50] Fix | Delete
$this->mrss = false;
[51] Fix | Delete
foreach ( $pxml->getNamespaces(true) as $key => $url ) {
[52] Fix | Delete
if ($url === 'http://search.yahoo.com/mrss/'){
[53] Fix | Delete
$this->mrss = $key;
[54] Fix | Delete
break;
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
$result = array();
[58] Fix | Delete
if ($pxml && isset($pxml->channel)) {
[59] Fix | Delete
if (!isset($this->screenName) || strlen($this->screenName) == 0) {
[60] Fix | Delete
$this->screenName = (string)$pxml->channel->title;
[61] Fix | Delete
}
[62] Fix | Delete
if (isset($pxml->channel->link)){
[63] Fix | Delete
$this->userLink = $pxml->channel->link;
[64] Fix | Delete
}
[65] Fix | Delete
if (sizeof($pxml->channel->item) > $this->getCount())
[66] Fix | Delete
for ($i=0; $i < $this->getCount(); $i++) $result[] = $pxml->channel->item[$i];
[67] Fix | Delete
else
[68] Fix | Delete
$result = $pxml->channel->item;
[69] Fix | Delete
}
[70] Fix | Delete
libxml_clear_errors();
[71] Fix | Delete
libxml_use_internal_errors(false);
[72] Fix | Delete
[73] Fix | Delete
return $result;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
protected function prepare( $item ) {
[77] Fix | Delete
$this->image = null;
[78] Fix | Delete
$this->media = null;
[79] Fix | Delete
return parent::prepare( $item );
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
[83] Fix | Delete
protected function getId($item){
[84] Fix | Delete
return hash('md5', isset($item->guid) ? (string)$item->guid : (string) $item->link);
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
protected function getScreenName($item){
[88] Fix | Delete
return $this->screenName;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
protected function getProfileImage($item){
[92] Fix | Delete
return $this->profileImage;
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
protected function getSystemDate($item){
[96] Fix | Delete
if (isset($item->pubDate)) return strtotime($item->pubDate);
[97] Fix | Delete
$d = new \DateTime(); return $d->getTimestamp();
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* @param SimpleXMLElement $item
[102] Fix | Delete
* @return string
[103] Fix | Delete
*/
[104] Fix | Delete
protected function getContent($item){
[105] Fix | Delete
if ($this->isRichText){
[106] Fix | Delete
$content = $item->children('content', true);
[107] Fix | Delete
foreach ($content->encoded as $encoded) {
[108] Fix | Delete
$content = $this->getRichText((string)$encoded);
[109] Fix | Delete
if (trim($content) != ''){
[110] Fix | Delete
return $content;
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
return $this->getRichText((string)$item->description);
[114] Fix | Delete
}
[115] Fix | Delete
return FFFeedUtils::wrapLinks(strip_tags((string)$item->description));
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
protected function getHeader($item){
[119] Fix | Delete
return $this->hideCaption ? '' : $item->title;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
protected function getUserlink($item){
[123] Fix | Delete
return $this->userLink;
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
protected function getPermalink($item){
[127] Fix | Delete
return $item->link;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* @param SimpleXMLElement $item
[132] Fix | Delete
* @return bool
[133] Fix | Delete
*/
[134] Fix | Delete
protected function showImage($item){
[135] Fix | Delete
if (isset($item->enclosure) && 'image/jpeg' == (string)$item->enclosure['type']){
[136] Fix | Delete
$this->image = $this->createImage((string)$item->enclosure['url']);
[137] Fix | Delete
$this->media = $this->createMedia($this->image['url'], $this->image['width'], $this->image['height']);
[138] Fix | Delete
return true;
[139] Fix | Delete
}
[140] Fix | Delete
else if ($this->mrss !== false){
[141] Fix | Delete
//$this->xml->channel->item[2]->children($namespaces['media'])->content->attributes()->height
[142] Fix | Delete
$namespaces = $this->xml->getNamespaces(true);
[143] Fix | Delete
$imageNode = isset($item->children($namespaces[$this->mrss])->thumbnail) ? $item->children($namespaces[$this->mrss])->thumbnail :
[144] Fix | Delete
(isset($item->children($namespaces[$this->mrss])->content) ? $item->children($namespaces[$this->mrss])->content : null);
[145] Fix | Delete
if ($imageNode) {
[146] Fix | Delete
/** @var SimpleXMLElement $attributes */
[147] Fix | Delete
$attributes = $imageNode->attributes();
[148] Fix | Delete
if (!is_null($attributes) && isset($attributes->url)){
[149] Fix | Delete
$url = (string) $attributes->url;
[150] Fix | Delete
if (isset($attributes->height) && isset($attributes->width)){
[151] Fix | Delete
$height = (string) $attributes->height;
[152] Fix | Delete
$width = (string) $attributes->width;
[153] Fix | Delete
$this->image = $this->createImage($url, $width, $height);
[154] Fix | Delete
$this->media = $this->createMedia($url, $width, $height);
[155] Fix | Delete
}
[156] Fix | Delete
else {
[157] Fix | Delete
$this->image = $this->createImage($url);
[158] Fix | Delete
$this->media = $this->createMedia($url, $this->image['width'], $this->image['height']);
[159] Fix | Delete
}
[160] Fix | Delete
return true;
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
return false;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
protected function getImage($item){
[168] Fix | Delete
return $this->image;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
protected function getMedia( $item ) {
[172] Fix | Delete
return $this->media;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
private function getRichText($text){
[176] Fix | Delete
$text = preg_replace('/(<[^>]+) style=".*?"/i', '$1', $text);
[177] Fix | Delete
$text = preg_replace('/(<[^>]+) class=".*?"/i', '$1', $text);
[178] Fix | Delete
if (FF_USE_WP) $text = strip_shortcodes( $text );
[179] Fix | Delete
try {
[180] Fix | Delete
libxml_use_internal_errors(true);
[181] Fix | Delete
$doc = new \DOMDocument();
[182] Fix | Delete
$doc->encoding = 'utf-8';
[183] Fix | Delete
$text = mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8');
[184] Fix | Delete
if (!empty($text) && $doc->loadHTML($text)){
[185] Fix | Delete
//$forRemove = array();
[186] Fix | Delete
//$images = $doc->getElementsByTagName('img');
[187] Fix | Delete
/*foreach ($images as $image){
[188] Fix | Delete
$objImage = ($image->hasAttribute('width') && $image->hasAttribute('height')) ?
[189] Fix | Delete
$this->createImage($image->getAttribute('src'), $image->getAttribute('width'), $image->getAttribute('height'), false) :
[190] Fix | Delete
$this->createImage($image->getAttribute('src'), null, null, false);
[191] Fix | Delete
if ($objImage['width'] > $this->getImageWidth()){
[192] Fix | Delete
$height = FFFeedUtils::getScaleHeight($this->getImageWidth(), $objImage['width'], $objImage['height']);
[193] Fix | Delete
$image->setAttribute('width', $this->getImageWidth());
[194] Fix | Delete
$image->setAttribute('height', $height);
[195] Fix | Delete
continue;
[196] Fix | Delete
}
[197] Fix | Delete
$forRemove[] = $image;
[198] Fix | Delete
}*/
[199] Fix | Delete
[200] Fix | Delete
while (($r = $doc->getElementsByTagName("script")) && $r->length) {
[201] Fix | Delete
$r->item(0)->parentNode->removeChild($r->item(0));
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
/*foreach ($forRemove as $image){
[205] Fix | Delete
$parent = $image->parentNode;
[206] Fix | Delete
$parent->removeChild($image);
[207] Fix | Delete
if (($parent->tagName == 'a') && $parent->childNodes->length == 0){
[208] Fix | Delete
$grandParent = $parent->parentNode;
[209] Fix | Delete
$grandParent->removeChild($parent);
[210] Fix | Delete
}
[211] Fix | Delete
}*/
[212] Fix | Delete
[213] Fix | Delete
$text = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $doc->saveHTML()));
[214] Fix | Delete
}
[215] Fix | Delete
} catch (\Exception $e){
[216] Fix | Delete
$this->errors[] = array(
[217] Fix | Delete
'type' => 'pinterest',
[218] Fix | Delete
'message' => $this->filterErrorMessage($e->getMessage())
[219] Fix | Delete
);
[220] Fix | Delete
}
[221] Fix | Delete
return $text;
[222] Fix | Delete
}
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function