: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
<?php namespace flow\social;
if ( ! defined( 'WPINC' ) ) die;
use flow\social\cache\FFImageSizeCacheBase;
* @author Looks Awesome <email@looks-awesome.com>
* @link http://looks-awesome.com
* @copyright 2014-2016 Looks Awesome
abstract class FFBaseFeed implements FFFeed{
/** @var FFImageSizeCacheBase */
* @var array $filterByWords */
private $criticalError = true;
/** @var array $errors */
function __construct( $type ) {
public function getType(){
public function getCount(){
public function getImageWidth(){
return $this->imageWidth;
public function getAllowableWidth(){
public function init($context, $feed){
$this->context = $context;
$this->imageWidth = defined('FF_MAX_IMAGE_WIDTH') ? FF_MAX_IMAGE_WIDTH : 300;
$this->cache = $context['image_size_cache'];
if ($feed->last_update === 'N/A' && isset($context['count_posts_4init'])){
$this->count = $context['count_posts_4init'];
$this->count = isset($feed->posts) ? intval($feed->posts) : 10;
if (isset($feed->{'include'}) && strlen($feed->{'include'}) > 0) {
$this->include = explode(',', $feed->{'include'});
if ($this->include === false) $this->include = array();
$this->include = array();
if (isset($feed->{'filter-by-words'}) && strlen($feed->{'filter-by-words'}) > 0) {
$this->filterByWords = explode(',', $feed->{'filter-by-words'});
if ($this->filterByWords === false) $this->filterByWords = array();
$this->filterByWords = array();
public final function posts($is_empty_feed) {
$this->count = defined('FF_FEED_INIT_COUNT_POSTS') ? FF_FEED_INIT_COUNT_POSTS : 50;
if ($this->beforeProcess()) {
$this->deferredInit($this->feed);
if (sizeof($this->errors) == 0){
$result += $this->onePagePosts();
} while ($this->nextPage($result));
return $this->afterProcess($result);
} catch (LASocialException $se){
$error = $se->getSocialError();
$error['type'] = $this->getType();
$this->errors[] = $error;
error_log($se->getMessage());
// error_log(print_r($se, true));
'type' => $this->getType(),
'message' => $e->getMessage(),
error_log($e->getMessage());
// error_log(print_r($e, true));
$this->criticalError = true;
protected abstract function deferredInit($feed);
protected abstract function onePagePosts( );
public function errors() {
protected function createImage($url, $width = null, $height = null, $scale = true){
if ($width != -1 && $height != -1) {
if ($width == null || $height == null){
$size = $this->cache->size($url);
$height = $size['height'];
$tWidth = $this->getImageWidth();
return array('url' => $url, 'width' => $tWidth, 'height' => FFFeedUtils::getScaleHeight($tWidth, $width, $height));
return array('url' => $url, 'width' => $width, 'height' => $height);
protected function createMedia($url, $width = null, $height = null, $type = 'image', $scale = false){
return array('type' => $type, 'html' => $url);
if ($width == null || $height == null){
$size = $this->cache->size($url);
$height = $size['height'];
if ($type == 'image' && $scale == true && $width > 600){
$height = FFFeedUtils::getScaleHeight(600, $width, $height);
return array('type' => $type, 'url' => $url, 'width' => $width, 'height' => $height);
protected function createAttachment($link, $name, $image = null, $width = null, $height = null){
if (is_string($image)) $image = $this->createImage($image, $width, $height);
if ($image['width'] > $this->getAllowableWidth())
return array( 'type' => 'article', 'url' => $link, 'displayName' => $name, 'image' => $image);
return array( 'type' => 'article', 'url' => $link, 'displayName' => $name);
protected function includePost($post)
if(count($this->include) == 0) return true;
foreach ( $this->include as $word ) {
$word = mb_strtolower($word);
$firstLetter = mb_substr($word, 0, 1);
if ($firstLetter !== false){
$word = mb_substr($word, 1);
if ((mb_strpos(mb_strtolower($post->screenname), $word) !== false) || (mb_strpos(mb_strtolower($post->nickname), $word) !== false)) {
$word = mb_substr($word, 1);
if (mb_strpos(mb_strtolower($post->permalink), $word) !== false) {
$word = mb_substr($word, 1);
if ( !empty($word) && ((mb_strpos( mb_strtolower( strip_tags( $post->text ) ), '#' . $word) !== false) || (isset($post->header) && mb_strpos( mb_strtolower( strip_tags( $post->header ) ), '#' . $word) !== false))) {
if ( !empty($word) && ((mb_strpos( mb_strtolower( strip_tags( $post->text ) ), $word) !== false) || (isset($post->header) && mb_strpos( mb_strtolower( strip_tags( $post->header ) ), $word) !== false))) {
protected function excludePost($post)
if(count($this->filterByWords) == 0) return true;
foreach ( $this->filterByWords as $word ) {
$word = mb_strtolower($word);
$firstLetter = mb_substr($word, 0, 1);
if ($firstLetter !== false){
$word = mb_substr($word, 1);
if ((mb_strpos(mb_strtolower($post->screenname), $word) !== false) || (mb_strpos(mb_strtolower($post->nickname), $word) !== false)) {
$word = mb_substr($word, 1);
if (mb_strpos(mb_strtolower($post->permalink), $word) !== false) {
if (!empty($word) && ((mb_strpos(mb_strtolower($post->text), $word) !== false) || (isset($post->header) && mb_strpos(mb_strtolower($post->header), $word) !== false))) {
protected function isSuitablePost($post){
if ($post == null) return false;
$suitable = $this->includePost($post);
$suitable = $this->excludePost($post);
protected function beforeProcess(){
return (sizeof($this->errors) == 0);
protected function afterProcess($result){
$this->criticalError = empty($result) && sizeof($this->errors) > 0;
public function hasCriticalError() {
return $this->criticalError;
protected function nextPage($result){
* @throws LASocialRequestException
protected function getFeedData($url, $timeout = 60, $header = false, $log = true){
return FFFeedUtils::getFeedDataWithThrowException($url, $timeout, $header, $log, $this->feed->use_curl_follow_location, $this->feed->use_ipv4);
* TODO Remove this method. Need to use LASocialException
protected function filterErrorMessage($message){
if (sizeof($message) > 0 && isset($message[0]['msg'])){
return stripslashes(htmlspecialchars($message[0]['msg'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'));
return stripslashes(htmlspecialchars($message, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'));
protected function print2log($msg){