2017-11-08 17:39:50 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Blog
|
|
|
|
{
|
|
|
|
public static function listAll()
|
|
|
|
{
|
2018-01-03 22:08:56 +01:00
|
|
|
$all = require (__DIR__ . '/../statics/blog/__all.php');
|
2017-12-30 23:46:27 +01:00
|
|
|
|
|
|
|
return array_map('self::completeSingle', $all);
|
2017-11-08 17:39:50 +01:00
|
|
|
}
|
2017-12-28 22:53:41 +01:00
|
|
|
|
2017-12-30 23:46:27 +01:00
|
|
|
private static function completeSingle($d)
|
|
|
|
{
|
|
|
|
if ($d['cat']==='blog')
|
|
|
|
$d['url'] = "/blog/" . $d['id'] . "/" . destructiveUrlEncode($d['title']);
|
|
|
|
else if ($d['cat']==='log')
|
|
|
|
$d['url'] = "/log/" . $d['id'] . "/" . destructiveUrlEncode($d['title']);
|
|
|
|
|
|
|
|
$d['canonical'] = "https://www.mikescher.com" . $d['url'];
|
|
|
|
|
|
|
|
return $d;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function listAllOrderedDescending()
|
|
|
|
{
|
2017-12-28 22:53:41 +01:00
|
|
|
$data = self::listAll();
|
|
|
|
usort($data, function($a, $b) { return strcasecmp($b['date'], $a['date']); });
|
|
|
|
return $data;
|
|
|
|
}
|
2017-12-30 23:11:51 +01:00
|
|
|
|
|
|
|
public static function getBlogpost($id)
|
|
|
|
{
|
|
|
|
foreach (self::listAll() as $post) {
|
|
|
|
if ($post['id'] == $id) return $post;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getPostFragment($post)
|
|
|
|
{
|
|
|
|
return file_get_contents( __DIR__ . '/../statics/blog/' . $post['fragment']);
|
|
|
|
}
|
2017-11-08 17:39:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|