Fix RRS feed. Add atom feed.
This commit is contained in:
parent
dd2d22c812
commit
67eea6e90c
@ -9,6 +9,7 @@ class Config {
|
||||
// properties and default values
|
||||
public string $siteTitle = 'My tkr';
|
||||
public string $siteDescription = '';
|
||||
public string $baseUrl = 'http://localhost'; //TODO - make this work
|
||||
public string $basePath = '/';
|
||||
public int $itemsPerPage = 25;
|
||||
public string $timezone = 'relative';
|
||||
|
57
tkr/public/atom/index.php
Normal file
57
tkr/public/atom/index.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../bootstrap.php';
|
||||
|
||||
confirm_setup();
|
||||
|
||||
require_once CLASSES_DIR . '/Config.php';
|
||||
require_once LIB_DIR . '/ticks.php';
|
||||
|
||||
$config = Config::load();
|
||||
$ticks = iterator_to_array(stream_ticks($config->itemsPerPage));
|
||||
$siteTitle = htmlspecialchars($config->siteTitle);
|
||||
$siteUrl = htmlspecialchars($config->baseUrl);
|
||||
$basePath = $siteUrl . htmlspecialchars($config->basePath);
|
||||
$updated = date(DATE_ATOM, strtotime($ticks[0]['timestamp'] ?? 'now'));
|
||||
|
||||
header('Content-Type: application/atom+xml; charset=utf-8');
|
||||
|
||||
echo <<<XML
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>{$siteTitle}</title>
|
||||
<link href="{$siteUrl}atom" rel="self"/>
|
||||
<link href="{$siteUrl}"/>
|
||||
<updated>{$updated}</updated>
|
||||
<id>{$siteUrl}</id>
|
||||
<author>
|
||||
<name>{$siteTitle}</name>
|
||||
</author>
|
||||
XML;
|
||||
|
||||
foreach ($ticks as $tick) {
|
||||
[$date, $time] = explode(' ', $tick['timestamp']);
|
||||
$dateParts = explode('-', $date);
|
||||
$timeParts = explode(':', $time);
|
||||
|
||||
[$year, $month, $day] = $dateParts;
|
||||
[$hour, $minute, $second] = $timeParts;
|
||||
|
||||
$tickPath = "$year/$month/$day/$hour/$minute/$second";
|
||||
$tickUrl = htmlspecialchars($basePath . "tick.php?path=" . $tickPath);
|
||||
$tickTime = date(DATE_ATOM, strtotime($tick['timestamp']));
|
||||
$tickText = htmlspecialchars($tick['tick']);
|
||||
|
||||
|
||||
echo <<<ENTRY
|
||||
<entry>
|
||||
<title>{$tickText}</title>
|
||||
<link href="{$tickUrl}"/>
|
||||
<id>{$tickUrl}</id>
|
||||
<updated>{$tickTime}</updated>
|
||||
<content type="html">{$tickText}</content>
|
||||
</entry>
|
||||
|
||||
ENTRY;
|
||||
}
|
||||
|
||||
echo "</feed>";
|
@ -34,7 +34,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
|
||||
|
||||
<item>
|
||||
<title><?php echo htmlspecialchars($tick['tick']); ?></title>
|
||||
<link><?php echo htmlspecialchars("$config->basePath/tick.php?path=$tickPath"); ?></link>
|
||||
<link><?php echo htmlspecialchars($config->basePath . "tick.php?path=$tickPath"); ?></link>
|
||||
<description><?php echo htmlspecialchars($tick['tick']); ?></description>
|
||||
<pubDate><?php echo date(DATE_RSS, strtotime($tick['timestamp'])); ?></pubDate>
|
||||
<guid><?php echo htmlspecialchars($tickPath); ?></guid>
|
||||
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
require '/app/Config.php';
|
||||
require_once __DIR__ . '/../bootstrap.php';
|
||||
|
||||
confirm_setup();
|
||||
|
||||
require LIB_DIR . '/util.php';
|
||||
|
||||
$path = $_GET['path'] ?? '';
|
||||
$parts = explode('/', $path);
|
||||
@ -12,7 +16,7 @@ if (count($parts) !== 6) {
|
||||
|
||||
[$y, $m, $d, $H, $i, $s] = $parts;
|
||||
$timestamp = "$H:$i:$s";
|
||||
$file = "$tickLocation/$y/$m/$d.txt";
|
||||
$file = TICKS_DIR . "/$y/$m/$d.txt";
|
||||
|
||||
if (!file_exists($file)) {
|
||||
http_response_code(404);
|
||||
@ -24,7 +28,7 @@ $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
if (str_starts_with($line, $timestamp)) {
|
||||
echo "<h1>Tick from $timestamp on $y-$m-$d</h1>";
|
||||
echo "<p>" . htmlspecialchars(explode('|', $line)[1]) . "</p>";
|
||||
echo "<p>" . escape_and_linkify(explode('|', $line)[1]) . "</p>";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user