public function actionIndex($id = 0)
 {
     /** @var \himiklab\rss\Rss $module */
     $module = $this->module;
     if (empty($module->feeds[$id])) {
         throw new NotFoundHttpException("RSS feed not found.");
     }
     Yii::$app->response->format = Response::FORMAT_RAW;
     Yii::$app->response->headers->add('Content-Type', 'text/xml');
     if ($view = Yii::$app->cache->get("{$module->cacheKeyPrefix}-{$id}")) {
         echo $view;
         return;
     }
     $feedItems = Feed::find()->select('title, description, link, content, author, pubDate')->where(['feed_id' => $id])->orderBy(['id' => SORT_DESC])->asArray()->all();
     echo $view = $this->renderPartial('index', ['channel' => $module->feeds[$id], 'items' => $feedItems]);
     Yii::$app->cache->set("{$module->cacheKeyPrefix}-{$id}", $view, $module->cacheExpire);
 }
Example #2
0
 /** 
  * the specified feed is exists.
  * @param string $feedId
  * @param string $link
  * @return boolean False if the feed is exists.
  */
 public function itemExists($feedId, $link)
 {
     return Feed::find()->where(['feed_id' => $feedId, 'link' => $link])->exists();
 }