Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add templating #124

Merged
merged 19 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 7 additions & 52 deletions include/CacheViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -168,59 +169,13 @@ private function display(): void
}
}

$html = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>CacheViewer</title>
<link rel="stylesheet" type="text/css" href="static/style.css" />
</head>
<body>
<header>
<nav class="crumbs">
<ol>
<li><a href="index.php">BetterVideoRss</a></li>
<li><a href="tools.html">Tools</a></li>
<li>Cache Viewer</li>
</ol>
</nav>
</header>
<div id="main" class="viewer">
<table class="stats">
<thead>
<tr>
<th>Files</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<tr class="center">
<td>{$fileCount}</td>
<td>{$cacheSize}</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr class="center">
<th>#</th>
<th>Name</th>
<th>Type</th>
<th>Last Modified</th>
<th>Size</th>
<th>View</th>
</tr>
</thead>
<tbody>
{$tbody}
<tbody>
</table>
</div>
</body>
</html>
HTML;
$html = new Template('cache-viewer.html', [
'fileCount' => $fileCount,
'cacheSize' => $cacheSize,
'tbody' => $tbody
]);

echo $html;
echo $html->render();
}

/**
Expand Down
1 change: 0 additions & 1 deletion include/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App;

use App\Helper\Validate;
use App\Helper\File;
use App\Exception\ConfigurationException as ConfigException;
use Exception;

Expand Down
16 changes: 9 additions & 7 deletions include/Format/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,27 @@
}

$media = <<<HTML
<a target="_blank" title="Watch on YouTube" href="{$video['url']}">
<img title="video thumbnail" src="{$thumbnailUrl}" loading="lazy"/>
</a>
HTML;
<a target="_blank" title="Watch on YouTube" href="{$video['url']}">
<img title="video thumbnail" src="{$thumbnailUrl}" loading="lazy"/>
</a>
HTML;

if ($this->embedVideos === true) {
$url = Url::getEmbed($video['id']);

$media = <<<HTML
<iframe width="100%" height="410" src="{$url}" frameborder="0" allow="encrypted-media;" loading="lazy"></iframe>
HTML;
<iframe width="100%" height="410" src="{$url}" frameborder="0" allow="encrypted-media;" loading="lazy"></iframe>

Check warning on line 114 in include/Format/Format.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 128 characters
HTML;
}

return <<<HTML
$html = <<<HTML
{$media}<hr/>
<span>Published: <time datetime="{$datetime}">{$published}</time></span>
<span> - Duration: <span class="duration">{$video['duration']}</span></span>
<hr/><p>{$description}</p>
HTML;

return \App\Helper\Format::minify(trim($html));
}

/**
Expand Down
51 changes: 13 additions & 38 deletions include/Format/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Format;

use App\Configuration as Config;
use App\Template;
use App\Helper\Url;

class Html extends Format
Expand All @@ -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 = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>{$feedTitle}</title>
<meta name="robots" content="noindex, follow">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="{$feedDescription}">
<link rel="stylesheet" type="text/css" href="static/style.css" />
<link rel="alternate" type="application/rss+xml" title="{$feedTitle} RSS feed" href="{$rssUrl}">
<link rel="alternate" type="application/json" title="{$feedTitle} JSON feed" href="{$jsonUrl}">
</head>
<body>
<header class="center">
<a target="_blank" href="{$feedUrl}">{$feedTitle}</a>
</header>
<main>
<section id="links">
Feed format: $feedFormatButtons
</section>
<section id="items">
{$items}
</section>
</main>
<footer class="center">
BetterVideoRss - <a href="https://github.com/VerifiedJoseph/BetterVideoRss">Source Code</a>
</footer>
</body>
</html>
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);
}

/**
Expand Down
59 changes: 25 additions & 34 deletions include/Format/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Format;

use App\Configuration as Config;
use App\Template;
use App\Helper\Convert;
use App\Helper\Url;

Expand All @@ -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')
Expand All @@ -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 = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{$feedTitle}</title>
<link>{$feedUrl}</link>
<atom:link href="{$selfUrl}" rel="self"/>
<description>{$feedDescription}</description>
<pubDate>{$feedUpdated}</pubDate>
<image>
<url>{$feedImage}</url>
</image>
{$items}
</channel>
</rss>
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);
}

/**
Expand Down Expand Up @@ -84,19 +75,19 @@ protected function buildItems(): string
}

$items .= <<<XML
<item>
<title>{$itemTitle}</title>
<pubDate>{$itemTimestamp}</pubDate>
<link>{$itemUrl}</link>
<guid isPermaLink="true">{$itemUrl}</guid>
<author>
<name>{$itemAuthor}</name>
</author>
<content:encoded>{$itemContent}</content:encoded>
<enclosure url="{$itemEnclosure}" type="image/jpeg" />
{$itemCategories}
</item>
XML;
<item>
<title>{$itemTitle}</title>
<pubDate>{$itemTimestamp}</pubDate>
<link>{$itemUrl}</link>
<guid isPermaLink="true">{$itemUrl}</guid>
<author>
<name>{$itemAuthor}</name>
</author>
<content:encoded>{$itemContent}</content:encoded>
<enclosure url="{$itemEnclosure}" type="image/jpeg" />
{$itemCategories}
</item>
XML;
}

return $items;
Expand Down
Loading
Loading