Ejemplo n.º 1
0
 public function actionFeed($id, $link)
 {
     $newsFeed = NewsFeed::findOne(['id' => $id, 'published' => 1]);
     if (!$newsFeed) {
         throw new NotFoundHttpException("Лента новостей не найдена!");
     }
     if ($newsFeed->link != $link) {
         return $this->redirect(['/rss/' . $newsFeed->fullLink]);
     }
     $response = \Yii::$app->getResponse();
     $headers = $response->getHeaders();
     $headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
     if (true || $newsFeed->hasUpdated()) {
         $feed = new RssView(['dataProvider' => new ActiveDataProvider(['query' => $newsFeed->getNews(), 'sort' => ['defaultOrder' => ['publishDate' => SORT_DESC]], 'pagination' => ['pageSize' => array_key_exists('feedLength', $newsFeed->params) ? $newsFeed->params['feedLength'] : 30]]), 'channel' => ['title' => function ($widget, \Zelenin\Feed $feed) use(&$newsFeed) {
             $feed->addChannelTitle($newsFeed->name);
         }, 'link' => Url::toRoute('/', true), 'description' => $newsFeed->description, 'language' => function ($widget, \Zelenin\Feed $feed) {
             return \Yii::$app->language;
         }, 'image' => function ($widget, \Zelenin\Feed $feed) use(&$newsFeed) {
             $feed->addChannelImage('//k-z.com.ua/images/' . (array_key_exists('image', $newsFeed->params) ? $newsFeed->params['image'] : 'logo1.png'), '//k-z.com.ua', 88, 31, $newsFeed->description);
         }], 'items' => ['title' => function ($model, $widget, \Zelenin\Feed $feed) {
             return $model->title;
         }, 'link' => function ($model, $widget, \Zelenin\Feed $feed) {
             return Url::toRoute([$model->fullLink], true);
         }, 'guid' => function ($model, $widget, \Zelenin\Feed $feed) {
             return Url::toRoute([$model->fullLink], true);
         }, 'description' => function ($model, $widget, \Zelenin\Feed $feed) use(&$newsFeed) {
             $text = htmlspecialchars_decode($model->textPreview);
             if (array_key_exists('hideImages', $newsFeed->params) && $newsFeed->params['hideImages'] == 1) {
                 $text = strip_tags($text, '<a></a><p></p>');
             }
             $text = StringHelper::truncateWords(preg_replace('/\\&(\\#|)(\\w+|\\D+)\\;/m', '', $text), 50);
             return $text;
         }, 'yandex:full-text' => function ($model, $widget, $feed) use(&$newsFeed) {
             $text = htmlspecialchars_decode($model->textPreview . $model->text);
             if (array_key_exists('hideImages', $newsFeed->params) && $newsFeed->params['hideImages'] == 1) {
                 $text = strip_tags($text, '<a></a><p></p>');
             }
             $text = preg_replace('/\\&(\\#|)(\\w+|\\D+)\\;/m', '', $text);
             return $text;
         }, 'author' => function ($model, $widget, \Zelenin\Feed $feed) {
             return $model->author;
         }, 'dc:creator' => function ($model, $widget, \Zelenin\Feed $feed) {
             return $model->author;
         }, 'pubDate' => function ($model, $widget, \Zelenin\Feed $feed) {
             $date = new \DateTime();
             $date->setTimestamp($model->publishDate);
             return $date->format(DATE_RSS);
         }], 'standards' => ['xmlns:dc' => 'http://purl.org/dc/elements/1.1/', 'xmlns:yandex' => 'http://news.yandex.ru', 'xmlns' => 'http://backend.userland.com/rss2']]);
         $feedContent = $feed->run()->__toString();
         \Yii::$app->cache->set('rssfeed-' . $newsFeed->id . '-content', $feedContent);
     } else {
         $feedContent = \Yii::$app->cache->get('rssfeed-' . $newsFeed->id . '-content');
     }
     echo $feedContent;
 }
Ejemplo n.º 2
0
 public function actionRss()
 {
     $dataProvider = new ActiveDataProvider(['query' => Article::find()->with(['user'])->orderby('id DESC'), 'pagination' => ['pageSize' => 10]]);
     $response = \Yii::$app->getResponse();
     \Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
     header("Content-Type: application/xml; charset=UTF-8");
     $response->content = \Zelenin\yii\extensions\Rss\RssView::widget(['dataProvider' => $dataProvider, 'channel' => ['title' => Yii::$app->name, 'link' => Url::toRoute('/', true), 'description' => 'Articles ', 'language' => Yii::$app->language], 'items' => ['title' => function ($model, $widget) {
         return $model->title;
     }, 'description' => function ($model, $widget) {
         return StringHelper::truncateWords($model->content, 50);
     }, 'link' => function ($model, $widget) {
         return Url::toRoute(['article/view', 'id' => $model->id], true);
     }, 'author' => function ($model, $widget) {
         return $model->user->email . ' (' . $model->user->name . ')';
     }, 'pubDate' => function ($model, $widget) {
         $date = \DateTime::createFromFormat('Y-m-d H:i:s', $model->date);
         return $date->format(DATE_RSS);
     }]]);
 }
Ejemplo n.º 3
0
 public function actionRss($category_id = null)
 {
     return RssView::widget(['dataProvider' => new ActiveDataProvider(['query' => Post::find()->published()->category($category_id)->language(Yii::$app->language)->orderBy(['published_at' => SORT_DESC]), 'pagination' => ['pageSize' => $this->module->rssPageSize]]), 'channel' => ['title' => Yii::$app->siteName, 'link' => Url::toRoute(['', 'category_id' => $category_id], true), 'description' => $category_id ? $this->loadCategoryModel($category_id)->title : Yii::t('gromver.platform', 'All news'), 'language' => Yii::$app->language], 'items' => ['title' => function ($model) {
         /** @var $model \gromver\platform\news\models\Post */
         return $model->title;
     }, 'description' => function ($model) {
         /** @var $model \gromver\platform\news\models\Post */
         return $model->preview_text ? $model->preview_text : StringHelper::truncateWords(strip_tags($model->detail_text), 40);
     }, 'link' => function ($model) {
         /** @var $model \gromver\platform\news\models\Post */
         return Url::toRoute($model->getFrontendViewLink(), true);
     }, 'author' => function ($model) {
         /** @var $model \gromver\platform\news\models\Post */
         return $model->user->email . ' (' . $model->user->username . ')';
     }, 'guid' => function ($model) {
         /** @var $model \gromver\platform\news\models\Post */
         return Url::toRoute($model->getFrontendViewLink(), true) . ' ' . Yii::$app->formatter->asDatetime($model->updated_at, 'php:' . DATE_RSS);
     }, 'pubDate' => function ($model) {
         /** @var $model \gromver\platform\news\models\Post */
         return Yii::$app->formatter->asDatetime($model->published_at, 'php:' . DATE_RSS);
     }]]);
 }
 /**
  * Main RSS channel.
  * @return string
  */
 public function actionRss()
 {
     $response = Yii::$app->getResponse();
     $headers = $response->getHeaders();
     $headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
     $response->content = RssView::widget(['dataProvider' => (new Forum())->search(null, true), 'channel' => ['title' => Config::getInstance()->get('name'), 'link' => Url::to(['default/index'], true), 'description' => Config::getInstance()->get('meta_description'), 'language' => Yii::$app->language], 'items' => ['title' => function ($model, $widget) {
         if (!empty($model->latest)) {
             return Html::encode($model->latest->thread->name);
         } else {
             return Html::encode($model->name);
         }
     }, 'description' => function ($model, $widget) {
         if (!empty($model->latest)) {
             return StringHelper::truncateWords($model->latest->content, 50, '...', true);
         }
         return '';
     }, 'link' => function ($model, $widget) {
         if (!empty($model->latest)) {
             return Url::to(['default/show', 'id' => $model->latest->id], true);
         }
         return Url::to(['default/forum', 'cid' => $model->category_id, 'id' => $model->id, 'slug' => $model->slug], true);
     }, 'author' => function ($model, $widget) {
         if (!empty($model->latest)) {
             return $model->latest->author->username;
         }
         return 'Podium';
     }, 'guid' => function ($model, $widget) {
         if (!empty($model->latest)) {
             return Url::to(['default/show', 'id' => $model->latest->id], true) . ' ' . Yii::$app->formatter->asDatetime($model->latest->updated_at, 'php:' . DATE_RSS);
         } else {
             return Url::to(['default/forum', 'cid' => $model->category_id, 'id' => $model->id, 'slug' => $model->slug], true) . ' ' . Yii::$app->formatter->asDatetime($model->updated_at, 'php:' . DATE_RSS);
         }
     }, 'pubDate' => function ($model, $widget) {
         if (!empty($model->latest)) {
             return Yii::$app->formatter->asDatetime($model->latest->updated_at, 'php:' . DATE_RSS);
         } else {
             return Yii::$app->formatter->asDatetime($model->updated_at, 'php:' . DATE_RSS);
         }
     }]]);
 }
Ejemplo n.º 5
0
 public function actionRssCategory($category = NULL)
 {
     if (Yii::$app->params['enableRss']) {
         if ($category) {
             $dataProvider = new ActiveDataProvider(['query' => PostsSearch::find()->where(['published' => 1, 'slugUrl' => $category])->orderBy('created_at DESC')->join('INNER JOIN', "{{%sources}}", "sources_id=sources.id")->join('INNER JOIN', "{{%categories}}", "categories_id=categories.id"), 'pagination' => ['pageSize' => Yii::$app->params['pageSizeRss']]]);
             $response = Yii::$app->getResponse();
             $headers = $response->getHeaders();
             $headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
             echo \Zelenin\yii\extensions\Rss\RssView::widget(['dataProvider' => $dataProvider, 'channel' => ['title' => Yii::$app->params['SiteName'], 'link' => Url::toRoute('/', true), 'description' => Yii::t('app', 'New Records in category {0}', [Categories::getCategoryBySlug($category)->title]), 'language' => function ($widget, \Zelenin\Feed $feed) {
                 return Yii::$app->language;
             }], 'items' => ['image' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return $model->activePhotos[0]->link;
             }, 'title' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return empty($model->title) || is_null($model->title) || !isset($model->title) ? $model->alternativeTitle : $model->title;
             }, 'description' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return '<img src="' . $model->activePhotos[0]->link . '" width="100" style="margin:10px;"/><br/>' . (!empty(StringHelper::truncateWords($model->content, 25)) ? StringHelper::truncateWords($model->content, 25) : NULL);
             }, 'link' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return $model->urlFull;
             }, 'guid' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return $model->recordId . $model->updated_at;
             }, 'pubDate' => function ($model, $widget, \Zelenin\Feed $feed) {
                 return Date(DATE_RSS, $model->updated_at);
             }]]);
         }
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 6
0
 public function actionRss()
 {
     $path = Yii::getAlias('@vendor/zelenin/rss-generator/Feed.php');
     require_once $path;
     $dataProvider = new \yii\data\ActiveDataProvider(['query' => \sircovsw\blog\models\BlogPost::find()->where(['status' => \sircovsw\blog\models\Status::STATUS_ACTIVE])->orderBy(['created_at' => SORT_DESC]), 'pagination' => ['pageSize' => 10]]);
     $response = Yii::$app->getResponse();
     $headers = $response->getHeaders();
     $headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
     echo \Zelenin\yii\extensions\Rss\RssView::widget(['dataProvider' => $dataProvider, 'channel' => ['title' => Yii::$app->name, 'link' => Url::toRoute('/', true), 'description' => 'Блог LinkOnAvt - помощь, справочные материалы, обсуждения', 'language' => function ($widget, \Zelenin\Feed $feed) {
         return Yii::$app->language;
     }, 'image' => function ($widget, \Zelenin\Feed $feed) {
         $feed->addChannelImage('http://' . Yii::$app->params["domain"] . '/img/logo.png', 'http://' . Yii::$app->params["domain"], 100, 100, 'Продвижение сайта самостоятельно');
     }], 'items' => ['title' => function ($model, $widget, \Zelenin\Feed $feed) {
         return $model->title;
     }, 'description' => function ($model, $widget, \Zelenin\Feed $feed) {
         return StringHelper::truncateWords($model->brief, 50);
     }, 'link' => function ($model, $widget, \Zelenin\Feed $feed) {
         $url = 'http://' . Yii::$app->params["domain"] . '/blog/view/' . $model->surname;
         return $url;
         //return Yii::$app->getUrlManager()->createUrl(['blog/default/view', 'surname' => $model->surname]);
         //return Url::toRoute(['blog/default/view', 'surname' => $model->surname], true);
     }, 'author' => function ($model, $widget, \Zelenin\Feed $feed) {
         return $model->user->email . ' (' . $model->user->username . ')';
     }, 'guid' => function ($model, $widget, \Zelenin\Feed $feed) {
         $date = date('d.m.Y H:i:s', $model->created_at);
         $url = 'http://' . Yii::$app->params["domain"] . '/blog/view/' . $model->surname;
         return $url;
         //.' '.\Datetime::createFromFormat('d.m.Y H:i:s', $date)->format(DATE_RSS);
         //return Url::toRoute(['blog/default/view', 'surname' => $model->surname], true).' '.\Datetime::createFromFormat('d.m.Y H:i:s', $date)->format(DATE_RSS);
     }, 'pubDate' => function ($model, $widget, \Zelenin\Feed $feed) {
         $date = date('d.m.Y H:i:s', $model->created_at);
         return \Datetime::createFromFormat('d.m.Y H:i:s', $date)->format(DATE_RSS);
     }]]);
 }
Ejemplo n.º 7
0
 public function actionRss()
 {
     $model = new SearchContent();
     $dataProvider = $model->getItems(true);
     $response = Yii::$app->getResponse();
     $headers = $response->getHeaders();
     $headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
     /** @noinspection PhpUnusedParameterInspection */
     $response->content = RssView::widget(['dataProvider' => $dataProvider, 'channel' => ['title' => Yii::$app->name, 'link' => Url::toRoute('/', true), 'description' => Yii::t('front', 'Articles'), 'language' => Yii::$app->language], 'items' => ['title' => function ($model, $widget) {
         return $model['title'];
     }, 'description' => function ($model, $widget) {
         return StringHelper::truncateWords($model['perex'], 50);
     }, 'link' => function ($model, $widget) {
         return Url::toRoute(['site/content', 'id' => $model['id']], true);
     }, 'guid' => function ($model, $widget) {
         $date = \DateTime::createFromFormat('Y-m-d H:i:s', $model['updated_at']);
         return Url::toRoute(['site/content', 'id' => $model['id']], true) . ' ' . $date->format(DATE_RSS);
     }, 'pubDate' => function ($model, $widget) {
         $date = \DateTime::createFromFormat('Y-m-d H:i:s', $model['updated_at']);
         return $date->format(DATE_RSS);
     }]]);
 }