Skip to content
Permalink
Browse files

Auto-detect RSS

  • Loading branch information...
Thoulah committed May 5, 2019
1 parent 2c4a1da commit 2c6363ffb25c329179ee8743493e8e5740ebf3a0

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -83,21 +83,21 @@ public function actionOui(): int {
/**
* Retrieves and stores an Atom or RSS feed.
*/
public function actionWebfeed(string $type, string $name, string $url, string $desc): int {
public function actionWebfeed(string $name, string $url, string $desc): int {
$count = 0;
$response = Webrequest::getUrl('', $url)->send();
if (!$response->isOK)
return self::EXIT_CODE_ERROR;
$xml = simplexml_load_string($response->content);
Feed::deleteAll(['feed' => $name]);
$data = $type === 'rss' ? $response->data['channel']['item'] : $response->data['entry'];
foreach ($data as $item) :
foreach (($xml->getName() === 'rss') ? $response->data['channel']['item'] : $response->data['entry'] as $item) :
$time = strtotime(ArrayHelper::getValue($item, 'pubDate') ?? ArrayHelper::getValue($item, 'updated'));
$feedItem = Feed::findOne(['feed' => $name, 'time' => $time]) ?? new Feed();
$feedItem->feed = $name;
$feedItem->title = (string) trim(ArrayHelper::getValue($item, 'title'));
$feedItem->url = (string) ArrayHelper::getValue($item, $type === 'rss' ? 'link' : 'link.@attributes.href');
$feedItem->url = (string) ArrayHelper::getValue($item, $xml->getName() === 'rss' ? 'link' : 'link.@attributes.href');
$feedItem->description = Yii::$app->formatter->cleanInput(ArrayHelper::getValue($item, $desc), false);
$feedItem->time = $time;
$feedItem->save();
@@ -18,8 +18,9 @@ public static function tableName(): string {
public function afterFind(): void {
parent::afterFind();
$this->url = $this->url ?? $this->name;
$this->playlist_embed = $this->playlist_id && $this->playlist_ratio ? Video::getEmbed($this->playlist_source, $this->playlist_id, $this->playlist_ratio, true) : null;
$this->playlist_url = $this->playlist_id ? Video::getUrl($this->playlist_source, $this->playlist_id, true) : null;
$this->playlist_embed = $this->playlist_source && $this->playlist_id && $this->playlist_ratio ? Video::getEmbed($this->playlist_source, $this->playlist_id, $this->playlist_ratio, true) : null;
$this->playlist_url = $this->playlist_source && $this->playlist_id ? Video::getUrl($this->playlist_source, $this->playlist_id, true) : null;
$this->created = Yii::$app->formatter->asTimestamp($this->created);
$this->updated = Yii::$app->formatter->asTimestamp($this->updated);
$this->active = boolval($this->active);
}
@@ -37,7 +38,7 @@ public function behaviors(): array {
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'updated',
'createdAtAttribute' => 'created',
'updatedAtAttribute' => 'updated',
'value' => new Expression('NOW()'),
],
@@ -62,6 +63,7 @@ public static function buildPdf(self $album): string {
Lyrics3Tracks::getLastModified($album->artist->url, $album->year, $album->url),
[
'author' => $album->artist->name,
'created' => $album->created,
'footer' => implode('|', [Html::a(Yii::$app->name, Yii::$app->params['shortDomain']), $album->year, 'Page {PAGENO} of {nb}']),
'header' => implode('|', [$album->artist->name, 'Lyrics', $album->name]),
'keywords' => implode(', ', [$album->artist->name, $album->name, 'lyrics']),
@@ -19,7 +19,7 @@ public function afterFind(): void {
$this->disambiguation = $this->disambiguation ? " ({$this->disambiguation})" : null;
$this->feat = $this->feat ? " (feat. {$this->feat})" : null;
$this->wip = boolval($this->wip);
$this->video = $this->video_id && $this->video_ratio ? Video::getEmbed($this->video_source, $this->video_id, $this->video_ratio) : null;
$this->video = $this->video_source && $this->video_id && $this->video_ratio ? Video::getEmbed($this->video_source, $this->video_id, $this->video_ratio) : null;
}
public static function tracksList(string $artist, string $year, string $name): array {
@@ -0,0 +1,21 @@
<?php
namespace app\models\music;
use Yii;
use yii\db\ActiveQuery;
class LyricsArtistInfo extends \yii\db\ActiveRecord {
public $summaryParsed;
public static function tableName(): string {
return '{{%lyrics_artistinfo}}';
}
public function afterFind(): void {
parent::afterFind();
$this->summaryParsed = Yii::$app->formatter->cleanInput($this->summary ?? '', 'gfm-comment', true);
}
public static function find(): ActiveQuery {
return parent::find()->alias('info');
}
}
@@ -8,7 +8,7 @@
$isHome = Yii::$app->controller->id === 'site' && Yii::$app->controller->action->id === 'index';
$dependency = [
'class' => ExpressionDependency::class,
'expression' => implode('-', [Articles::getLastModified(), ArticlesComments::getLastModified()]),
'params' => ['articles' => Articles::getLastModified(), 'comments' => ArticlesComments::getLastModified()],
'reusable' => true,
];

0 comments on commit 2c6363f

Please sign in to comment.
You can’t perform that action at this time.