feed: Switched to new PicoFeed implementation
This commit is contained in:
parent
6d1a7c7e09
commit
f1cfc0c08c
1 changed files with 60 additions and 23 deletions
|
@ -53,16 +53,18 @@ if ($_SESSION['login']) {
|
||||||
$art_dir = "./../../articles/" . $_GET['blog'] . "/";
|
$art_dir = "./../../articles/" . $_GET['blog'] . "/";
|
||||||
$feed_path = "./../../feed/" . $_GET['blog'] . ".atom";
|
$feed_path = "./../../feed/" . $_GET['blog'] . ".atom";
|
||||||
|
|
||||||
$writer = new Atom();
|
if ($_GET['blog'] == "main") {
|
||||||
|
$blogtitle = $settings['blog']['title'];
|
||||||
|
} else {
|
||||||
|
$blogtitl = $settings['blog']['title'] . " - " . ucwords($_GET['blog']);
|
||||||
|
}
|
||||||
|
|
||||||
$writer->title = $blogtitle;
|
$feedBuilder = AtomFeedBuilder::create()
|
||||||
$writer->site_url = $blogurl;
|
->withTitle($blogtitle)
|
||||||
$writer->feed_url = $blogurl . "/feed/" . $_GET['blog'] . ".atom";
|
->withAuthor($settings['blog']['author'])
|
||||||
$writer->author = array(
|
->withFeedUrl($settings['blog']['url'] . "/feed/" . $_GET['blog'] . ".atom")
|
||||||
'name' => $blogauthor,
|
->withSiteUrl($settings['blog']['url'])
|
||||||
'url' => $blogurl,
|
->withDate(new DateTime(date(DATE_ATOM)));
|
||||||
'email' => ''
|
|
||||||
);
|
|
||||||
|
|
||||||
$articles = scandir($art_dir, 1);
|
$articles = scandir($art_dir, 1);
|
||||||
|
|
||||||
|
@ -77,25 +79,45 @@ if ($_SESSION['login']) {
|
||||||
$text = Parsedown::instance()
|
$text = Parsedown::instance()
|
||||||
->setBreaksEnabled(true)// with linebreaks
|
->setBreaksEnabled(true)// with linebreaks
|
||||||
->text($file);
|
->text($file);
|
||||||
$writer->items[] = array(
|
if (new DateTime(date(DATE_ATOM, strtotime($datestring))) != null) {
|
||||||
'title' => ArticleGenerator::getTitle($art_dir, $article),
|
$date = new DateTime(
|
||||||
'updated' => strtotime(
|
date(
|
||||||
ArticleGenerator::getDate($art_dir . $article)
|
DATE_ATOM,
|
||||||
),
|
strtotime($datestring)
|
||||||
'url' => $blogurl . "./?article=" .
|
)
|
||||||
substr($article, 0, strlen($article) - 3),
|
|
||||||
'summary'=> ArticleGenerator::getSummary(
|
|
||||||
$art_dir, $article
|
|
||||||
),
|
|
||||||
'content' => $text
|
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$date = new DateTime(date(DATE_ATOM));
|
||||||
|
}
|
||||||
|
$date = new DateTime(date(DATE_ATOM));
|
||||||
|
$feedBuilder
|
||||||
|
->withItem(AtomItemBuilder::create($feedBuilder)
|
||||||
|
->withTitle(
|
||||||
|
ArticleGenerator::getTitle($art_dir, $article)
|
||||||
|
)
|
||||||
|
->withUrl(
|
||||||
|
$settings['blog']['url'] . "./?article=" . substr($article, 0, strlen($article) - 3)
|
||||||
|
)
|
||||||
|
->withAuthor(
|
||||||
|
ArticleGenerator::getAuthor($art_dir, $article)
|
||||||
|
)
|
||||||
|
->withPublishedDate(
|
||||||
|
parseDate(ArticleGenerator::getDate($art_dir, $article))
|
||||||
|
)
|
||||||
|
->withUpdatedDate(
|
||||||
|
parseDate(ArticleGenerator::getDate($art_dir, $article))
|
||||||
|
)
|
||||||
|
->withSummary(
|
||||||
|
ArticleGenerator::getSummary($art_dir, $article)
|
||||||
|
)
|
||||||
|
->withContent($text));
|
||||||
$amount += 1;
|
$amount += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$feed = $writer->execute();
|
$feed = $feedBuilder->build();
|
||||||
|
|
||||||
$file = fopen($feed_path, "w");
|
$file = fopen($feed_path, "w");
|
||||||
|
|
||||||
|
@ -108,4 +130,19 @@ if ($_SESSION['login']) {
|
||||||
|
|
||||||
echo "0";
|
echo "0";
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
function parseDate($datestring)
|
||||||
|
{
|
||||||
|
$datetime = new DateTime(date(DATE_ATOM));
|
||||||
|
try {
|
||||||
|
$datetime = new DateTime(
|
||||||
|
date(
|
||||||
|
DATE_ATOM,
|
||||||
|
strtotime($datestring)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$datetime = new DateTime(date(DATE_ATOM));
|
||||||
|
}
|
||||||
|
return $datetime;
|
||||||
|
}
|
||||||
|
|
Reference in a new issue