This repository has been archived by the owner on Nov 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Instafeed.php
62 lines (54 loc) · 1.72 KB
/
Instafeed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* @link https://github.com/nirvana-msu/yii2-instafeed
* @copyright Copyright (c) 2016 Alexander Stepanov
* @license MIT
*/
namespace nirvana\instafeed;
use Yii;
use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\View;
/**
* This widget publishes assets and registers necessary code to run plugin.
* It also optionally renders a div container that plugin would automatically look for, to fill with thumbnails.
* You can control the name of a created javascript plugin variable by configuring widget id.
*
* For more examples and documentation visit https://github.com/stevenschobert/instafeed.js
*
* @author Alexander Stepanov <[email protected]>
*/
class Instafeed extends Widget
{
/**
* @var boolean whether to render `<div id="instafeed"></div>` container that plugin would look for by default
*/
public $renderThumbnailDiv = true;
/**
* @var array instafeed javascript plugin options
*/
public $pluginOptions = [];
/**
* Initializes the widget.
* This method publishes & registers instafeed plugin assets
*/
public function init()
{
InstafeedAsset::register($this->view);
}
/**
* Executes the widget.
* This method renders container div, if necessary, and registers javascript plugin code.
*/
public function run()
{
if ($this->renderThumbnailDiv) {
echo Html::tag('div', '', ['id' => 'instafeed']);
}
$pluginOptions = Json::encode($this->pluginOptions);
$varName = 'instafeed_' . $this->id;
$this->view->registerJs("var $varName = new Instafeed($pluginOptions); $varName.run();",
View::POS_END, 'instafeed-' . $this->id);
}
}