: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use flow\social\cache\LAFacebookCacheManager;
use flow\social\FFRemoteFeed;
use flow\social\LAFeedWithComments;
use la\core\cache\LACacheAdapter;
use la\core\cache\LAImageSizeCacheManager;
use la\core\settings\LAGeneralSettings;
use la\core\settings\LASettingsUtils;
use la\core\settings\LAStreamSettings;
if ( ! defined('FF_BY_DATE_ORDER')) define('FF_BY_DATE_ORDER', 'compareByTime');
if ( ! defined('FF_RANDOM_ORDER')) define('FF_RANDOM_ORDER', 'randomCompare');
if ( ! defined('FF_SMART_ORDER')) define('FF_SMART_ORDER', 'smartCompare');
protected static $instance = [];
public static function get_instance($context = null) {
$slug = is_null($context) ? 'flow-flow' : LAUtils::slug($context);
if (!array_key_exists($slug, self::$instance)) {
$slug_down = is_null($context) ? 'flow_flow' : LAUtils::slug_down($context);
$class = get_called_class();
self::$instance[$slug] = new $class($context, $slug, $slug_down);
return self::$instance[$slug];
public static function get_instance_by_slug($slug) {
return (array_key_exists($slug, self::$instance)) ? self::$instance[$slug] : null;
// public static function registry($slug, $instance){
// if (!array_key_exists($slug, self::$instance)) {
// self::$instance[$slug] = $instance;
protected $generalSettings;
* Initialize the plugin by setting localization and loading public scripts
protected function __construct($context, $slug, $slug_down) {
$this->context = $context;
$this->slug_down = $slug_down;
* Default filter for result before send response.
* Use wp filter engine because need to customize result from addons.
add_filter('ff_build_public_response', [ $this, 'buildResponse' ], 1, 8);
public final function register_shortcodes()
add_shortcode($this->getShortcodePrefix(), [ $this, 'renderShortCode' ] );
* Load the plugin text domain for translation.
public final function load_plugin_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
$path = LAUtils::root($this->context) . 'languages/';
load_textdomain( $domain, $path . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, false, $path );
* Fired when a new site is activated with a WPMU environment.
* @param int $blog_id ID of the new blog.
* @noinspection PhpUnused
public final function activate_new_site( $blog_id ) {
if ( 1 !== did_action( 'wpmu_new_blog' ) ) return;
switch_to_blog( $blog_id );
* Register and enqueue public-facing style sheet.
public final function enqueue_styles() {
* Register and enqueues public-facing JavaScript files.
public final function enqueue_scripts() {
// Customization 16.08.18, JS opts added in public.php instead
// $this->enqueueScripts();
// make sure jQuery is always on page
wp_enqueue_script('jquery');
public final function processAjaxRequest() {
if (isset($_REQUEST['stream-id']) && $this->prepareProcess()) {
$dbm = LAUtils::dbm($this->context);
$boosted = (bool)(isset($_REQUEST['boosted']) && (int)$_REQUEST['boosted']);
$dbm->dataInit(true, false, $boosted);
$stream = $dbm->getStream($_REQUEST['stream-id']);
$disableCache = isset($_REQUEST['disable-cache']) ? (bool)$_REQUEST['disable-cache'] : false;
header('Content-Type: application/json');
echo $this->process( [ $stream ], $disableCache);
public final function moderation_apply( ){
if (isset($_REQUEST['stream']) && $this->prepareProcess()) {
$dbm = LAUtils::dbm($this->context);
$stream = $dbm->getStream($_REQUEST['stream']);
$cache = new LACacheAdapter($this->context, false);
$cache->setStream(new LAStreamSettings($stream), true);
* @param bool $only_enable
public final function processAjaxRequestBackground($only_enable = true, $remote = true) {
if ($this->prepareProcess()) {
$dbm = LAUtils::dbm($this->context);
$dbm->dataInit($only_enable, false, $remote);
if (isset($_REQUEST['feed_id'])){
$sources = $dbm->sources();
if (isset($sources[$_REQUEST['feed_id']])){
$this->process4feeds( [ $sources[$_REQUEST['feed_id']] ], false, true);
if (isset($_REQUEST['stream_id'])){
$stream = $dbm->getStream($_REQUEST['stream_id']);
$this->process4feeds( [ $stream ], false, true);
* @return array|false|string
public final function processRequest(){
if (isset($_REQUEST['stream-id']) && $this->prepareProcess()) {
$dbm = LAUtils::dbm($this->context);
$stream = $dbm->getStream($_REQUEST['stream-id']);
return $this->process( [ $stream ], isset($_REQUEST['disable-cache']));
public final function refreshCache($streamId = null, $force = false, $withDisabled = false) {
if ($this->prepareProcess()) {
$dbm = LAUtils::dbm($this->context);
$enabled = $withDisabled ? $conn->parse('`cach`.system_enabled = 0 AND `cach`.boosted != "yep"') : $conn->parse('`cach`.enabled = 1 AND `cach`.system_enabled = 1 AND `cach`.boosted != "yep"');
$sql = $conn->parse('SELECT `cach`.`feed_id` FROM ?n `cach` WHERE ?p AND (`cach`.last_update + `cach`.cache_lifetime * 60) < UNIX_TIMESTAMP() ORDER BY `cach`.last_update', $dbm->cache_table_name, $enabled);
$sql = $conn->parse('SELECT `cach`.`feed_id` FROM ?n `cach` INNER JOIN ?n `ss` ON `ss`.feed_id = `cach`.feed_id WHERE ?p AND `ss`.stream_id = ?s AND (`cach`.last_update + `cach`.cache_lifetime * 60) < UNIX_TIMESTAMP() ORDER BY `cach`.last_update',
$dbm->cache_table_name, $dbm->streams_sources_table_name, $enabled, $streamId);
if (false !== ($feeds = $conn->getCol($sql))){
$useIpv4 = $dbm->getGeneralSettings()->useIPv4();
$use = $dbm->getGeneralSettings()->useCurlFollowLocation();
for ( $i = 0; $i < sizeof($feeds); $i ++ ) {
$_REQUEST['feed_id'] = $feed_id;
$this->processAjaxRequestBackground(!$withDisabled, false);
for ( $i = 0; $i < 8; $i ++ ) {
if (FF_USE_DIRECT_WP_CRON){
$_REQUEST['feed_id'] = $feed_id;
$this->processAjaxRequestBackground(!$withDisabled, false);
//$_COOKIE['XDEBUG_SESSION'] = 'PHPSTORM';
$url = $dbm->getLoadCacheUrl( $feed_id, $force );
LASettingsUtils::get( $url, 1, false, false, $use, $useIpv4);
error_log($e->getMessage());
error_log($e->getTraceAsString());
public final function refreshCache4Disabled() {
$this->refreshCache(null, false, true);
public final function emailNotification () {
$dbm = LAUtils::dbm($this->context);
$settings = $dbm->getGeneralSettings();
if ($settings->enabledEmailNotification()){
$dbm->email_notification();
public final function checkFacebookToken() {
$dbm = LAUtils::dbm($this->context);
if ($dbm->getOption('boosts_email') != false){
/** @var LAFacebookCacheManager $facebookCache */
$facebookCache = $this->context['facebook_cache'];
$facebookCache->getAccessToken();
* @return false|string|string[]
public function renderShortCode ($attr) {
if ($this->prepareProcess()) {
$dbm = LAUtils::dbm($this->context);
$dbm->dataInit(false, false, false);
$stream = (object)$dbm->getStream($attr['id']);
$stream->preview = (isset($attr['preview']) && $attr['preview']);
$stream->gallery = $stream->preview ? LASettingsUtils::NOPE : ( isset($stream->gallery) ? $stream->gallery : LASettingsUtils::NOPE );
$output = $this->renderStream($stream, $this->getPublicContext($stream, $this->context));
/* workaround for extra P tags issue and possibly &&, set to true */
if (LASettingsUtils::notYepNope2ClassicStyleSafe(LAGeneralSettings::get()->original(), 'general-render-alt')){
remove_filter('the_content', 'wptexturize');
remove_filter('the_content', 'wpautop');
echo '<p>Flow-Flow message: Stream with specified ID not found or no feeds were added to stream</p>';
* @param LAStreamSettings $stream
* @noinspection PhpUnusedParameterInspection
public function buildResponse ($result, $all, $context, $errors, $oldHash, $page, $status, $stream) {
$streamId = (int) $stream->getId();
$countOfPages = isset($_REQUEST['countOfPages']) ? $_REQUEST['countOfPages'] : 0;
'id' => $streamId, 'items' => $all, 'errors' => $errors,
'hash' => $oldHash, 'page' => $page, 'countOfPages' => $countOfPages, 'status' => $status
* @throws ReflectionException
public function loadCommentsAndCarousel(){
$post_id = $_REQUEST['post_id'];
$feed_id = $_REQUEST['feed_id4post'];
if ($this->prepareProcess()) {
$dbm = LAUtils::dbm($this->context);
$result['comments'] = $this->process4comments($post_id, $feed_id);
$result['carousel'] = $dbm->getCarousel($feed_id, $post_id);
protected function enqueueStyles() {}
protected function enqueueScripts() {}
protected abstract function getShortcodePrefix();
protected abstract function getNameJSOptions();
protected function getPublicContext($stream, $context){
$context['moderation'] = false;
if (isset($stream->feeds) && !empty($stream->feeds)){
foreach ( $stream->feeds as $source ) {
if (LASettingsUtils::YepNope2ClassicStyleSafe($source, 'mod', false)){
$context['moderation'] = true;
$cache = new LACacheAdapter($context);
$cache->setStream(new LAStreamSettings($stream), $context['moderation']);
$context['stream'] = $stream;
$context['hashOfStream'] = $cache->transientHash($stream->id);
$context['seo'] = false;////$this->generalSettings->isSEOMode();
$context['can_moderate'] = FF_USE_WP ? $this->generalSettings->canModerate() : ff_user_can_moderate();
protected function prepareProcess() {
if (isset($_REQUEST['stream-id'])) $_REQUEST['stream-id'] = @filter_var( trim( $_REQUEST['stream-id'] ), FILTER_SANITIZE_NUMBER_INT);
if (isset($_REQUEST['feed_id'])) $_REQUEST['feed_id'] = @filter_var( trim( $_REQUEST['feed_id'] ), FILTER_SANITIZE_STRING );
if (isset($_REQUEST['action'])) $_REQUEST['action'] = @filter_var( trim( $_REQUEST['action'] ), FILTER_SANITIZE_STRING );
if (isset($_REQUEST['page'])) $_REQUEST['page'] = filter_var( trim( $_REQUEST['page'] ), FILTER_SANITIZE_NUMBER_INT);
if (isset($_REQUEST['countOfPages'])) $_REQUEST['countOfPages'] = filter_var( trim( $_REQUEST['countOfPages'] ), FILTER_SANITIZE_NUMBER_INT);
if (isset($_REQUEST['hash']) && !empty($_REQUEST['hash'])){
$hash = filter_var( $_REQUEST['hash'], FILTER_VALIDATE_REGEXP, [ "options" => [ 'regexp' => '/^\d{10}[.]\w{96}$/' ] ] );
if (isset($_REQUEST['disable-cache']) && !empty($_REQUEST['disable-cache'])){
$_REQUEST['disable-cache'] = filter_var( trim( $_REQUEST['disable-cache'] ), FILTER_SANITIZE_NUMBER_INT);
if (isset($_REQUEST['preview']) && !empty($_REQUEST['preview'])){
$_REQUEST['preview'] = filter_var( trim( $_REQUEST['preview'] ), FILTER_SANITIZE_NUMBER_INT);
$dbm = LAUtils::dbm($this->context);
if ($dbm->countFeeds() > 0) {
$this->generalSettings = $dbm->getGeneralSettings();
protected function renderStream($stream, $context){
$settings = new LAStreamSettings($stream);
if ($settings->isPossibleToShow()){
if ( ! in_array( 'curl', get_loaded_extensions() ) ) {
echo "<p style='background: indianred;padding: 15px;color: white;'>Flow-Flow admin info: Your server doesn't have cURL module installed. Please ask your hosting to check this.</p>";
if (!isset($stream->layout) || empty($stream->layout)) {
echo "<p style='background: indianred;padding: 15px;color: white;'>Flow-Flow admin info: Please choose stream layout on options page.</p>";
$css_version = isset($stream->last_changes) ? $stream->last_changes : '1.0';
$url = content_url() . '/resources/' . LAUtils::slug($context) . '/css/stream-id' . $stream->id . '.css';
$url = content_url() . '/resources/' . LAUtils::slug($context) . '/css/stream-id' . $stream->id . '-'. get_current_blog_id() . '.css';
echo "<link rel='stylesheet' id='ff-dynamic-css" . $stream->id . "' type='text/css' href='{$url}?ver={$css_version}'/>";
/** @noinspection PhpIncludeInspection */
include(LAUtils::root($context) . 'views/public.php');
$output = ob_get_clean();
$output = str_replace("\r\n", '', $output);
protected function process($streams, $disableCache = false, $background = false) {
foreach ($streams as $stream) {
foreach ( LAUtils::dbm($this->context)->sources() as $source ) {
$moderation = LASettingsUtils::YepNope2ClassicStyleSafe($source, 'mod', false);
$settings = new LAStreamSettings($stream);
$cache = new LACacheAdapter($this->context);
$cache->setStream($settings, $moderation);
$instances = $this->createFeedInstances($settings->getAllFeeds());
$result = $cache->posts($instances, $disableCache);
if ($background) return $result;
$errors = $cache->errors();
return $this->prepareResult($result, $errors, $hash, $settings);
} catch ( Exception $e) {
error_log($e->getMessage());
error_log($e->getTraceAsString());
protected function initContextBeforeCreateFeedInstances(){
$this->context['image_size_cache'] = new LAImageSizeCacheManager($this->context);
private function process4feeds($feeds, $disableCache = false, $background = false) {
$instances = $this->createFeedInstances($feeds);
$cache = new LACacheAdapter($this->context, true);
$result = $cache->posts($instances, $disableCache);
if ($background) return $result;
$errors = $cache->errors();
return $this->prepareResult($result, $errors, $hash);
} catch ( Exception $e) {
error_log($e->getMessage());
error_log($e->getTraceAsString());
* Rework code, delete the reference to the database and the logic of expiration life time