%PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
| Server IP : 14.207.165.8 / Your IP : 216.73.216.26 Web Server : Apache/2.4.18 (Ubuntu) System : Linux 246 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : root ( 0) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,pcntl_exec MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/egp/vendor/zelenin/yii2-rss/ |
Upload File : |
<?php
namespace Zelenin\yii\extensions\Rss;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\widgets\BaseListView;
use Zelenin\Feed;
class RssView extends BaseListView
{
/**
* @var Feed
*/
public $feed;
/**
* @var array
*/
public $channel;
/**
* @var array
*/
public $items;
/**
* @var array
*/
public $requiredChannelElements = ['title', 'link', 'description'];
/**
* @var array
*/
public $requiredItemElements = ['title', 'description', 'link', 'pubDate'];
/**
* @var array
*/
private $channelAttributes = [];
/**
* @var array
*/
private $itemAttributes = [];
/**
* @inheritdoc
*
* @throws InvalidConfigException
*/
public function init()
{
if ($this->dataProvider === null) {
throw new InvalidConfigException('The "dataProvider" property must be set');
}
$this->channelAttributes = $this->getAttributes($this->channel);
foreach ($this->requiredChannelElements as $channelElement) {
if (!in_array($channelElement, $this->channelAttributes)) {
throw new InvalidConfigException('Required channel attribute "' . $channelElement . '" must be set');
}
}
$this->itemAttributes = $this->getAttributes($this->items);
foreach ($this->requiredItemElements as $itemElement) {
if (!in_array($itemElement, $this->itemAttributes)) {
throw new InvalidConfigException('Required item attribute "' . $itemElement . '" must be set');
}
}
$this->feed = new Feed;
}
/**
* @inheritdoc
*
* @return string|Feed
*/
public function run()
{
$this->renderChannel();
if ($this->dataProvider->getCount() > 0) {
$this->renderItems();
}
return $this->feed;
}
/**
* @return Feed
*/
public function getFeed()
{
return $this->feed;
}
public function renderChannel()
{
$this->getFeed()->addChannel(ArrayHelper::getValue($this->channel, 'link'));
foreach ($this->channel as $element => $value) {
if (is_string($value)) {
$this->getFeed()->addChannelElement($element, $value);
} else {
$result = call_user_func($value, $this, $this->getFeed());
if (is_string($result)) {
$this->getFeed()->addChannelElement($element, $result);
}
}
}
}
/**
* @inheritdoc
*/
public function renderItems()
{
$models = $this->dataProvider->getModels();
foreach ($models as $model) {
$this->renderItem($model);
}
}
/**
* @param $model
*/
public function renderItem($model)
{
$this->getFeed()->addItem();
foreach ($this->items as $element => $value) {
if (is_string($value)) {
if (is_string($element)) {
$this->getFeed()->addItemElement($element, $value);
} else {
$this->getFeed()->addItemElement($value, ArrayHelper::getValue($model, $value));
}
} else {
$result = call_user_func($value, $model, $this, $this->getFeed());
if (is_string($result)) {
$this->getFeed()->addItemElement($element, $result);
}
}
}
}
/**
* @param $configArray
*
* @return array
*
* @throws InvalidConfigException
*/
private function getAttributes($configArray)
{
$attributes = [];
foreach ($configArray as $key => $value) {
if (is_string($key)) {
$attributes[] = $key;
} else {
if (is_string($value)) {
$attributes[] = $value;
} else {
throw new InvalidConfigException('Wrong configured attribute');
}
}
}
return $attributes;
}
}