PHP code example of enovate / social-stream

1. Go to this page and download the library: Download enovate/social-stream library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

enovate / social-stream example snippets




return [
    'defaultLimit' => 12,
    'cacheDuration' => 120,
    'excludeNonFeed' => true,
    'secureApiEndpoint' => false,
    'maxFetchPages' => 5,
    'fetchPageSize' => 25,
];

use enovate\socialstream\services\Providers;
use craft\events\RegisterComponentTypesEvent;
use yii\base\Event;

Event::on(
    Providers::class,
    Providers::EVENT_REGISTER_PROVIDER_TYPES,
    function (RegisterComponentTypesEvent $event) {
        $event->types[] = MyProvider::class;
    }
);

use enovate\socialstream\base\Provider;
use enovate\socialstream\events\FetchStreamEvent;
use yii\base\Event;

Event::on(
    Provider::class,
    Provider::EVENT_AFTER_FETCH_STREAM,
    function (FetchStreamEvent $event) {
        // Only keep posts that mention a specific hashtag.
        if (!empty($event->result['data'])) {
            $event->result['data'] = array_filter(
                $event->result['data'],
                fn($post) => str_contains((string) $post->caption, '#featured'),
            );
        }
    }
);

use enovate\socialstream\events\StreamRefreshedEvent;
use enovate\socialstream\jobs\RefreshStreamJob;
use yii\base\Event;

Event::on(
    RefreshStreamJob::class,
    RefreshStreamJob::EVENT_AFTER_REFRESH_STREAM,
    function (StreamRefreshedEvent $event) {
        // $event->siteId, $event->provider, $event->options, $event->response
        // ...purge a CDN, ping a webhook, etc.
    }
);
bash
php craft plugin/install social-stream
bash
php craft up