diff --git a/include/CacheViewer.php b/include/CacheViewer.php index 81a86ed4..18a61ca4 100644 --- a/include/CacheViewer.php +++ b/include/CacheViewer.php @@ -3,6 +3,7 @@ namespace App; use App\Configuration as Config; +use App\Template; use App\Helper\File; use App\Helper\Convert; use App\Helper\Url; @@ -168,59 +169,13 @@ private function display(): void } } - $html = << - - - CacheViewer - - - -
- -
-
- - - - - - - - - - - - - -
FilesSize
{$fileCount}{$cacheSize}
- - - - - - - - - - - - - {$tbody} - -
#NameTypeLast ModifiedSizeView
-
- - -HTML; + $html = new Template('cache-viewer.html', [ + 'fileCount' => $fileCount, + 'cacheSize' => $cacheSize, + 'tbody' => $tbody + ]); - echo $html; + echo $html->render(); } /** diff --git a/include/Configuration.php b/include/Configuration.php index 3abac946..d623e1c6 100644 --- a/include/Configuration.php +++ b/include/Configuration.php @@ -3,7 +3,6 @@ namespace App; use App\Helper\Validate; -use App\Helper\File; use App\Exception\ConfigurationException as ConfigException; use Exception; diff --git a/include/Format/Format.php b/include/Format/Format.php index 9b9553ab..23a3652b 100644 --- a/include/Format/Format.php +++ b/include/Format/Format.php @@ -102,25 +102,27 @@ protected function buildContent(array $video): string } $media = << - - - HTML; + + + +HTML; if ($this->embedVideos === true) { $url = Url::getEmbed($video['id']); $media = << -HTML; + + HTML; } - return << Published: - Duration: {$video['duration']}

{$description}

HTML; + + return \App\Helper\Format::minify(trim($html)); } /** diff --git a/include/Format/Html.php b/include/Format/Html.php index 8a5edb99..6099902f 100644 --- a/include/Format/Html.php +++ b/include/Format/Html.php @@ -3,6 +3,7 @@ namespace App\Format; use App\Configuration as Config; +use App\Template; use App\Helper\Url; class Html extends Format @@ -16,52 +17,26 @@ class Html extends Format public function build(): void { $feedDescription = htmlspecialchars($this->data['details']['description'], ENT_QUOTES); - $feedTitle = $this->data['details']['title']; - $feedUrl = $this->data['details']['url']; - $feedImage = $this->data['details']['thumbnail']; $rssUrl = htmlspecialchars( Url::getFeed($this->data['details']['type'], $this->data['details']['id'], 'rss', $this->embedVideos) ); + $jsonUrl = htmlspecialchars( Url::getFeed($this->data['details']['type'], $this->data['details']['id'], 'json', $this->embedVideos) ); - $feedFormatButtons = $this->buildFormatButtons(); - - $items = $this->buildItems(); - - $this->feed = << - - - {$feedTitle} - - - - - - - - -
- {$feedTitle} -
-
- -
- {$items} -
-
- - - -HTML; - $this->feed = \App\Helper\Format::minify($this->feed); + $html = new Template('feed.html', [ + 'feedTitle' => $this->data['details']['title'], + 'feedDescription' => $feedDescription, + 'feedUrl' => $this->data['details']['url'], + 'rssUrl' => $rssUrl, + 'jsonUrl' => $jsonUrl, + 'feedFormatButtons' => $this->buildFormatButtons(), + 'items' => $this->buildItems() + ]); + + $this->feed = $html->render(minify: true); } /** diff --git a/include/Format/Rss.php b/include/Format/Rss.php index d8b54fa3..0dcfe834 100644 --- a/include/Format/Rss.php +++ b/include/Format/Rss.php @@ -3,6 +3,7 @@ namespace App\Format; use App\Configuration as Config; +use App\Template; use App\Helper\Convert; use App\Helper\Url; @@ -18,7 +19,6 @@ public function build(): void { $feedDescription = $this->xmlEncode($this->data['details']['description']); $feedTitle = $this->xmlEncode($this->data['details']['title']); - $feedAuthor = $this->xmlEncode($this->data['details']['title']); $feedUrl = $this->xmlEncode($this->data['details']['url']); $feedUpdated = $this->xmlEncode( Convert::unixTime($this->data['updated'], 'r') @@ -29,26 +29,17 @@ public function build(): void Url::getFeed($this->data['details']['type'], $this->data['details']['id'], 'rss', $this->embedVideos) ); - $items = $this->buildItems(); - - $this->feed = << - - - {$feedTitle} - {$feedUrl} - - {$feedDescription} - {$feedUpdated} - - {$feedImage} - - {$items} - - -XML; - - $this->feed = \App\Helper\Format::minify($this->feed); + $xml = new Template('feed.xml', [ + 'feedTitle' => $feedTitle, + 'feedUrl' => $feedUrl, + 'feedDescription' => $feedDescription, + 'feedUpdated' => $feedUpdated, + 'feedImage' => $feedImage, + 'selfUrl' => $selfUrl, + 'items' => $this->buildItems() + ]); + + $this->feed = $xml->render(minify: true); } /** @@ -84,19 +75,19 @@ protected function buildItems(): string } $items .= << - {$itemTitle} - {$itemTimestamp} - {$itemUrl} - {$itemUrl} - - {$itemAuthor} - - {$itemContent} - - {$itemCategories} - -XML; + + {$itemTitle} + {$itemTimestamp} + {$itemUrl} + {$itemUrl} + + {$itemAuthor} + + {$itemContent} + + {$itemCategories} + + XML; } return $items; diff --git a/include/Index.php b/include/Index.php index 4e240189..76994707 100644 --- a/include/Index.php +++ b/include/Index.php @@ -4,7 +4,6 @@ use App\Configuration as Config; use App\Helper\Validate; -use App\Helper\Format; use App\Helper\Url; use Exception; @@ -84,109 +83,16 @@ public function display(): void } } - $selectHtml = $this->createFormatSelect(); - $html = << - - - BetterVideoRss - - - - - -
- BetterVideoRss -
-
-
- {$error} -
-

Channel

-
- -

- -

-

- -

-

- -

-

- -

-
-

{$channelLink}

-
-
-

Playlist

-
- -

- -

-

- -

-

- -

-

- -

-
-

{$playlistLink}

-
-
-

URL

-
- -

- -

-

- -

-

- -

-

- -

-
-

{$fromUrlLink}

-
- -
-
- - -HTML; - - echo Format::minify($html); + $html = new Template('index-page.html', [ + 'error' => $error, + 'selectHtml' => $this->createFormatSelect(), + 'channelLink' => $channelLink, + 'playlistLink' => $playlistLink, + 'fromUrlLink' => $fromUrlLink, + 'version' => $version + ]); + + echo $html->render(minify: true); } /** diff --git a/include/Template.php b/include/Template.php new file mode 100644 index 00000000..40274829 --- /dev/null +++ b/include/Template.php @@ -0,0 +1,65 @@ + $variables Template variables */ + private array $variables = []; + + /** + * @param string $name Template filename + * @param array $variables Template variables + */ + public function __construct(string $name, array $variables = []) + { + $this->variables = $variables; + $this->load($name); + } + + /** + * Render template into page + * + * @param bool $minify Minify HTML + * @return string HTML + */ + public function render(bool $minify = false): string + { + foreach ($this->variables as $name => $value) { + $name = sprintf('{%s}', $name); + $this->html = str_replace($name, $value, $this->html); + } + + if ($minify === true) { + return Format::minify($this->html); + } + + return $this->html; + } + + /** + * Load Template + * + * @param string $name Template filename + * @throws ConfigException if template file is not found. + */ + private function load(string $name): void + { + $path = 'include/templates/' . $name; + + if (file_exists($path) === false) { + throw new ConfigException('Template file not found: ' . $path); + } + + $this->html = File::read($path); + } +} diff --git a/include/templates/cache-viewer.html b/include/templates/cache-viewer.html new file mode 100644 index 00000000..3f42e74e --- /dev/null +++ b/include/templates/cache-viewer.html @@ -0,0 +1,49 @@ + + + + CacheViewer + + + +
+ +
+
+ + + + + + + + + + + + + +
FilesSize
{fileCount}{cacheSize}
+ + + + + + + + + + + + + {tbody} + +
#NameTypeLast ModifiedSizeView
+
+ + diff --git a/include/templates/feed.html b/include/templates/feed.html new file mode 100644 index 00000000..c87cc439 --- /dev/null +++ b/include/templates/feed.html @@ -0,0 +1,28 @@ + + + + {feedTitle} + + + + + + + + +
+ {feedTitle} +
+
+ +
+ {items} +
+
+ + + diff --git a/include/templates/feed.xml b/include/templates/feed.xml new file mode 100644 index 00000000..a6ba4ff9 --- /dev/null +++ b/include/templates/feed.xml @@ -0,0 +1,14 @@ + + + + {feedTitle} + {feedUrl} + + {feedDescription} + {feedUpdated} + + {feedImage} + + {items} + + diff --git a/include/templates/index-page.html b/include/templates/index-page.html new file mode 100644 index 00000000..a25bc090 --- /dev/null +++ b/include/templates/index-page.html @@ -0,0 +1,98 @@ + + + + BetterVideoRss + + + + + +
+ BetterVideoRss +
+
+
+ {error} +
+

Channel

+
+ +

+ +

+

+ +

+

+ +

+

+ +

+
+

{channelLink}

+
+
+

Playlist

+
+ +

+ +

+

+ +

+

+ +

+

+ +

+
+

{playlistLink}

+
+
+

URL

+
+ +

+ +

+

+ +

+

+ +

+

+ +

+
+

{fromUrlLink}

+
+ +
+
+ + \ No newline at end of file diff --git a/tools.html b/tools.html index 646fc399..4411fc07 100644 --- a/tools.html +++ b/tools.html @@ -1,25 +1,23 @@ - - - Tools - - - - - -
- -
-
- -
- + + Tools + + + + +
+ +
+
+ +
+