123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- namespace rss\controllers;
- use Yii;
- use yii\web\Controller;
- use yii\web\Response;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Url;
- /**
- * DefaultController implements actions
- */
- class DefaultController extends Controller
- {
- public $defaultAction = 'rss';
- public function actionIndex()
- {
- return $this->redirect("rss");
- }
- /**
- * Displays the Yandex turbo-pages for frontend.
- *
- * @return string
- */
- public function actionTurbo() {
- $module = $this->module;
- if ($module->cacheExpire !== 0 && ($cache = Yii::$app->getCache()) ) {
- $data = $cache->getOrSet(md5('yandex-turbo'), function () use ($module) {
- return [
- 'items' => $module->getTurboItems(),
- 'builded_at' => date('r')
- ];
- }, intval($module->cacheExpire));
- } else {
- $data = [
- 'items' => $module->getTurboItems(),
- 'builded_at' => date('r')
- ];
- }
- $channel = [];
- if (is_array($module->channelOptions))
- $channel = $module->channelOptions;
- if (!isset($channel['title']))
- $channel['title'] = Yii::$app->name;
- if (!isset($channel['link']))
- $channel['link'] = Url::base(true);
- if (!isset($channel['language']))
- $channel['language'] = Yii::$app->language;
- Yii::$app->response->format = Response::FORMAT_XML;
- Yii::$app->getResponse()->getHeaders()->set('Content-Type', 'text/xml; charset=UTF-8');
- return $this->renderPartial('turbo', [
- 'channel' => $channel,
- 'items' => $data['items']
- ]);
- }
- public function actionDzen() {
- $topic = \Yii::$app->request->get("topic",0);
- $module = $this->module;
- if ($module->cacheExpire !== 0 && ($cache = Yii::$app->getCache()) ) {
- $data = $cache->getOrSet(md5('yandex-dzen'.$topic), function () use ($module, $topic) {
- return [
- 'items' => ($topic)?$module->getTopicsItems($topic):$module->getTurboItems(),
- 'builded_at' => date('r')
- ];
- }, intval($module->cacheExpire));
- } else {
- $data = [
- 'items' => ($topic)?$module->getTopicsItems($topic):$module->getTurboItems(),
- 'builded_at' => date('r')
- ];
- }
- $channel = [];
- if (is_array($module->channelOptions))
- $channel = $module->channelOptions;
- if (!isset($channel['title']))
- $channel['title'] = Yii::$app->name;
- if (!isset($channel['link']))
- $channel['link'] = Url::base(true);
- if (!isset($channel['language']))
- $channel['language'] = Yii::$app->language;
- Yii::$app->response->format = Response::FORMAT_XML;
- Yii::$app->getResponse()->getHeaders()->set('Content-Type', 'text/xml; charset=UTF-8');
- $channel['clink'] = $channel['link'];
- if( $topic ){
- $mtopic = new \app\models\base\NewsTopic();
- $ptopic = $mtopic->GetById($topic);
- $channel['title'] = $ptopic->meta_title;
- $channel['clink'] = $ptopic->geturl(true);
- return $this->renderPartial('dzentopic', [
- 'channel' => $channel,
- 'items' => $data['items']
- ]);
- }
- return $this->renderPartial('dzen', [
- 'channel' => $channel,
- 'items' => $data['items']
- ]);
- }
- public function actionRia() {
- $module = $this->module;
- if ($module->cacheExpire !== 0 && ($cache = Yii::$app->getCache()) ) {
- $data = $cache->getOrSet(md5('yandex-ria'), function () use ($module) {
- return [
- 'items' => $module->getTurboItems(),
- 'builded_at' => date('r')
- ];
- }, intval($module->cacheExpire));
- } else {
- $data = [
- 'items' => $module->getTurboItems(),
- 'builded_at' => date('r')
- ];
- }
- $channel = [];
- if (is_array($module->channelOptions))
- $channel = $module->channelOptions;
- if (!isset($channel['title']))
- $channel['title'] = Yii::$app->name;
- if (!isset($channel['link']))
- $channel['link'] = Url::base(true);
- if (!isset($channel['language']))
- $channel['language'] = Yii::$app->language;
- Yii::$app->response->format = Response::FORMAT_XML;
- Yii::$app->getResponse()->getHeaders()->set('Content-Type', 'text/xml; charset=UTF-8');
- return $this->renderPartial('ria', [
- 'channel' => $channel,
- 'items' => $data['items']
- ]);
- }
- public function actionRss() {
- $module = $this->module;
- if ($module->cacheExpire !== 0 && ($cache = Yii::$app->getCache() )) {
- $data = $cache->getOrSet(md5('rss'), function () use ($module) {
- return [
- 'items' => $module->getTurboItems(),
- 'builded_at' => date('r')
- ];
- }, intval($module->cacheExpire));
- } else {
- $data = [
- 'items' => $module->getTurboItems(),
- 'builded_at' => date('r')
- ];
- }
- $channel = [];
- if (is_array($module->channelOptions))
- $channel = $module->channelOptions;
- if (!isset($channel['title']))
- $channel['title'] = Yii::$app->name;
- if (!isset($channel['link']))
- $channel['link'] = Url::base(true);
- if (!isset($channel['language']))
- $channel['language'] = Yii::$app->language;
- Yii::$app->response->format = Response::FORMAT_XML;
- Yii::$app->getResponse()->getHeaders()->set('Content-Type', 'text/xml; charset=UTF-8');
- return $this->renderPartial('rss', [
- 'channel' => $channel,
- 'items' => $data['items']
- ]);
- }
- }
|