Permalink
Browse files

Maintenance on lyrics

  • Loading branch information...
Thoulah committed Feb 5, 2019
1 parent 3dd89cb commit e030601e33b8df92556527bff323134a8971eb74
@@ -6,6 +6,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"component-dir": "../vendor/components",
"vendor-dir": "../vendor"
},
"require": {

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

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -30,7 +30,7 @@ body {
}

body > .container {
padding: 4.5rem 15px 2rem;
padding: 5.4rem 15px 2rem;
}

h1, h2, h3, h4, h5, h6, .breadcrumb, label {
@@ -43,6 +43,7 @@ h1, h2, h3, h4, h5, h6, .breadcrumb, label {

.navbar-brand {
color: $lightBlue;
font-size: 2.25rem;
font-weight: $font-weight-bold;
text-shadow: 2px 2px 2px #444;

@@ -126,7 +127,7 @@ svg.fa {
.anchor {
display: block;
position: relative;
top: -55px;
top: -4.6rem;
@include invisible(hidden);
}

@@ -192,28 +193,21 @@ form {
background: #a0a0a0;
border-radius: 50%;
bottom: 0px;
color: #fff;
display: none;
line-height: 1.6;
right: calc(50% - 15px);
position: fixed;
text-align: center;
text-decoration: none;
z-index: $zindex-fixed;
@include size(30px);

> :first-child {
color: #fff;
position: relative;
top: 3px;
@include user-select(none);
}
@include user-select(none);

&:hover {
background: #666;
cursor: pointer;

> :first-child {
top: 0px;
}
line-height: 1.4;
}
}

@@ -225,12 +219,11 @@ footer {
}

@include media-breakpoint-up(md) {
.navbar {
span::before {
.navbar .nav-link span::before {
content: "\A";
white-space: pre;
}
}

#btn-scrolltop {
bottom: 40px;
right: 10px;
@@ -109,7 +109,7 @@ public function actionWebfeed(string $type, string $name, string $url, string $d
foreach ($data as $item) :
$time = strtotime(ArrayHelper::getValue($item, 'pubDate') ?? ArrayHelper::getValue($item, 'updated'));
$feedItem = Feed::findOne(['feed' => $name, 'time' => $time]) ?? new Feed();
$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');
@@ -37,7 +37,7 @@ public function actionIndex(int $id = 0, string $action = '', string $q = ''): s
return $this->pageArticle($id);
endif;
$query = Articles::find()->orderBy('id DESC');
$query = Articles::find()->orderBy('updated DESC');
if ($action === "tag" && !empty($q)) :
$query->where(['like', 'tags', $q]);
elseif ($action === "search" && !empty($q)) :
@@ -3,12 +3,12 @@
use Yii;
use app\models\lyrics\{Lyrics1Artists, Lyrics2Albums, Lyrics3Tracks};
use yii\helpers\{ArrayHelper, Url};
use yii\web\NotFoundHttpException;
use yii\web\{NotFoundHttpException, Response};
class LyricsController extends \yii\web\Controller {
const PAGE_INDEX = '0';
const PAGE_ARTIST = '1';
const PAGE_ALBUM = '2';
const PAGE_INDEX = 0;
const PAGE_ARTIST = 1;
const PAGE_ALBUM = 2;
public $page;
public $artist;
@@ -17,27 +17,27 @@ class LyricsController extends \yii\web\Controller {
public $size;
public $lastModified;
public function init() {
public function init(): void {
$this->artist = Yii::$app->request->get('artist');
$this->year = Yii::$app->request->get('year');
$this->album = Yii::$app->request->get('album');
$this->size = Yii::$app->request->get('size');
if ($this->artist && $this->year && $this->album) :
$this->page = self::PAGE_ALBUM;
$this->lastModified = Lyrics3Tracks::lastUpdate($this->artist, $this->year, $this->album);
$this->lastModified = Lyrics3Tracks::lastModified($this->artist, $this->year, $this->album);
elseif ($this->artist) :
$this->page = self::PAGE_ARTIST;
$this->lastModified = Lyrics2Albums::lastUpdate($this->artist);
$this->lastModified = Lyrics2Albums::lastModified($this->artist);
else :
$this->page = self::PAGE_INDEX;
$this->lastModified = Lyrics1Artists::lastUpdate();
$this->lastModified = Lyrics1Artists::lastModified();
endif;
parent::init();
}
public function behaviors() {
public function behaviors(): array {
return [
[
'class' => \yii\filters\HttpCache::class,
@@ -49,9 +49,9 @@ public function behaviors() {
];
}
public function actionIndex() {
public function actionIndex(): string {
switch ($this->page) :
case self::PAGE_INDEX: list($page, $data) = ['1_index', Lyrics1Artists::artistsList()]; break;
case self::PAGE_INDEX: list($page, $data) = ['1_index', (new Lyrics1Artists)->artistsList()]; break;
case self::PAGE_ARTIST: list($page, $data) = $this->pageArtist(); break;
case self::PAGE_ALBUM: list($page, $data) = $this->pageAlbum(); break;
endswitch;
@@ -62,7 +62,7 @@ public function actionIndex() {
]);
}
public function actionAlbumpdf() {
public function actionAlbumpdf(): Response {
$tracks = Lyrics3Tracks::tracksList($this->artist, $this->year, $this->album);
if (!ArrayHelper::keyExists(0, $tracks) || !$tracks[0]->album->active) :
@@ -74,7 +74,7 @@ public function actionAlbumpdf() {
return Yii::$app->response->sendFile($fileName, implode(' - ', [$tracks[0]->artist->url, $tracks[0]->album->year, $tracks[0]->album->url]).'.pdf');
}
public function actionAlbumcover() {
public function actionAlbumcover(): Response {
$tracks = Lyrics3Tracks::tracksList($this->artist, $this->year, $this->album);
if (!ArrayHelper::keyExists(0, $tracks) || !ArrayHelper::isIn($this->size, [100, 500, 800])) :
@@ -2,6 +2,9 @@
namespace app\models;
use Yii;
use kartik\mpdf\Pdf as PdfCreator;
use Mpdf\Pdf\Protection;
use Mpdf\Pdf\Protection\UniqidGenerator;
use Mpdf\Writer\BaseWriter;
use yii\helpers\FileHelper;
class Pdf {
@@ -18,16 +21,19 @@ public function create(string $filename, string $content, string $updated, array
$pdf->content = $content;
$pdf->filename = $filename;
$pdf->destination = PdfCreator::DEST_FILE;
foreach (['author', 'footer', 'header', 'keywords', 'subject', 'title'] as $x) :
if (isset($params[$x])) :
$function = 'Set'.ucfirst($x);
$pdf->api->$function($params[$x]);
endif;
endforeach;
$pdf->render();
$this->replaceLine($filename, '/Producer', $pdf->api->_UTF16BEtextstring('Yii Framework'));
$this->replaceLine($filename, '/CreationDate', $pdf->api->_textstring(date('YmdHis', $created).substr(date('O', $created), 0, 3)."'".substr(date('O', $created), 3, 2)."'"));
$this->replaceLine($filename, '/ModDate', $pdf->api->_textstring(date('YmdHis', $updated).substr(date('O', $updated), 0, 3)."'".substr(date('O', $updated), 3, 2)."'"));
$writer = new BaseWriter($pdf->api, new Protection(new UniqidGenerator()));
$this->replaceLine($filename, '/Producer', $writer->utf16BigEndianTextString('Yii Framework'));
$this->replaceLine($filename, '/CreationDate', $writer->string(date('YmdHis', $created).substr(date('O', $created), 0, 3)."'".substr(date('O', $created), 3, 2)."'"));
$this->replaceLine($filename, '/ModDate', $writer->string(date('YmdHis', $updated).substr(date('O', $updated), 0, 3)."'".substr(date('O', $updated), 3, 2)."'"));
touch($filename, $updated);
endif;
return $filename;
@@ -4,22 +4,20 @@
use yii\db\BatchQueryResult;
class Lyrics1Artists extends \yii\db\ActiveRecord {
const STATUS_INACTIVE = '0';
const STATUS_ACTIVE = '1';
public static function tableName(): string {
return '{{%lyrics_1_artists}}';
}
public function afterFind() {
public function afterFind(): void {
parent::afterFind();
$this->url = $this->url ?? $this->name;
$this->updated = strtotime($this->updated);
$this->active = (bool) $this->active;
}
public static function artistsList(): array {
public function artistsList(): array {
return self::find()
->active(self::tableName())
->orderBy('name')
->all();
}
@@ -31,26 +29,19 @@ public static function albumsList(): BatchQueryResult {
->each();
}
public static function lastUpdate($data = null): int {
$max = 0;
$data = $data ?? self::artistsList();
foreach ($data as $item) :
$max = max($max, $item->updated);
endforeach;
return $max;
public static function lastModified(): int {
$data = self::find()
->active(self::tableName())
->max('updated');
return Yii::$app->formatter->asTimestamp($data);
}
public function getAlbums() {
return $this->hasMany(Lyrics2Albums::class, ['parent' => 'id'])
->orderBy('year, name');
public function getAlbums(): LyricsQuery {
return $this->hasMany(Lyrics2Albums::className(), ['parent' => 'id'])
->active(Lyrics2Albums::tableName());
}
public static function find() {
return parent::find()
->onCondition(
php_sapi_name() === 'cli' || (!Yii::$app->user->isGuest && Yii::$app->user->identity->isAdmin)
? ['or', [self::tableName().'.`active`' => [Self::STATUS_INACTIVE, Self::STATUS_ACTIVE]]]
: [self::tableName().'.`active`' => Self::STATUS_ACTIVE]
);
public static function find(): LyricsQuery {
return new LyricsQuery(get_called_class());
}
}
Oops, something went wrong.

0 comments on commit e030601

Please sign in to comment.