35 lines
1.2 KiB
PHP
35 lines
1.2 KiB
PHP
<?php
|
|
|
|
final class FeedManager
|
|
{
|
|
|
|
const BASE_PATH = "./data/articles";
|
|
|
|
public static function getLatestPosts(int $count): array
|
|
{
|
|
$dot_dirs = [".", ".."];
|
|
$posts = [];
|
|
foreach (array_diff(scandir(self::BASE_PATH, SCANDIR_SORT_DESCENDING), $dot_dirs) as $year) {
|
|
$year_path = self::BASE_PATH . "/$year";
|
|
foreach (array_diff(scandir($year_path, SCANDIR_SORT_DESCENDING), $dot_dirs) as $month) {
|
|
$month_path = "$year_path/$month";
|
|
foreach (array_diff(scandir($month_path, SCANDIR_SORT_DESCENDING), $dot_dirs) as $day) {
|
|
$day_path = "$month_path/$day";
|
|
foreach (array_diff(scandir($day_path, SCANDIR_SORT_DESCENDING), $dot_dirs) as $file) {
|
|
$file_path = "$day_path/$file";
|
|
if (pathinfo($file_path, PATHINFO_EXTENSION) !== "txt") {
|
|
continue;
|
|
}
|
|
$posts[] = FeedParser::parse($file_path);
|
|
if (count($posts) === $count) {
|
|
return $posts;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $posts;
|
|
}
|
|
|
|
}
|