Blog
This commit is contained in:
parent
c9b6223a87
commit
f06948851c
@ -1,12 +1,22 @@
|
||||
<?php
|
||||
|
||||
require_once 'website.php';
|
||||
|
||||
class Blog
|
||||
{
|
||||
public static function listAll()
|
||||
/** @var array */
|
||||
private $staticData;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->load();
|
||||
}
|
||||
|
||||
private function load()
|
||||
{
|
||||
$all = require (__DIR__ . '/../statics/blog/__all.php');
|
||||
|
||||
return array_map('self::readSingle', $all);
|
||||
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
|
||||
}
|
||||
|
||||
private static function readSingle($d)
|
||||
@ -25,24 +35,29 @@ class Blog
|
||||
return $d;
|
||||
}
|
||||
|
||||
public static function listAllNewestFirst()
|
||||
public function listAll()
|
||||
{
|
||||
$data = self::listAll();
|
||||
return $this->staticData;
|
||||
}
|
||||
|
||||
public function listAllNewestFirst()
|
||||
{
|
||||
$data = $this->staticData;
|
||||
usort($data, function($a, $b) { return strcasecmp($b['date'], $a['date']); });
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getBlogpost($id)
|
||||
public function getBlogpost($id)
|
||||
{
|
||||
foreach (self::listAll() as $post) {
|
||||
foreach ($this->staticData as $post) {
|
||||
if ($post['id'] == $id) return $post;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getFullBlogpost($id, $subview, &$error)
|
||||
public function getFullBlogpost($id, $subview, &$error)
|
||||
{
|
||||
$post = self::getBlogpost($id);
|
||||
$post = $this->getBlogpost($id);
|
||||
if ($post === null) { $error="Blogpost not found"; return null; }
|
||||
|
||||
$post['issubview'] = false;
|
||||
@ -52,7 +67,7 @@ class Blog
|
||||
if ($isSubEuler)
|
||||
{
|
||||
require_once(__DIR__ . '/../internals/euler.php');
|
||||
$eulerproblem = Euler::getEulerProblemFromStrIdent($subview);
|
||||
$eulerproblem = Website::inst()->Euler()->getEulerProblemFromStrIdent($subview);
|
||||
if ($eulerproblem === null) { $error="Project Euler entry not found"; return null; }
|
||||
$post['submodel'] = $eulerproblem;
|
||||
$post['issubview'] = true;
|
||||
@ -63,7 +78,7 @@ class Blog
|
||||
if ($isSubAdventOfCode)
|
||||
{
|
||||
require_once(__DIR__ . '/../internals/adventofcode.php');
|
||||
$adventofcodeday = AdventOfCode::getDayFromStrIdent($post['extras']['aoc:year'], $subview);
|
||||
$adventofcodeday = Website::inst()->AdventOfCode()->getDayFromStrIdent($post['extras']['aoc:year'], $subview);
|
||||
if ($adventofcodeday === null) { $error="AdventOfCode entry not found"; return null; }
|
||||
$post['submodel'] = $adventofcodeday;
|
||||
$post['issubview'] = true;
|
||||
@ -79,16 +94,18 @@ class Blog
|
||||
|
||||
}
|
||||
|
||||
public static function getPostFragment($post)
|
||||
public function getPostFragment($post)
|
||||
{
|
||||
return file_get_contents($post['file_fragment']);
|
||||
}
|
||||
|
||||
public static function checkConsistency()
|
||||
public function checkConsistency()
|
||||
{
|
||||
$keys = [];
|
||||
|
||||
foreach (self::listAll() as $post)
|
||||
$this->load();
|
||||
|
||||
foreach ($this->staticData as $post)
|
||||
{
|
||||
if (in_array($post['id'], $keys)) return ['result'=>'err', 'message' => 'Duplicate key ' . $post['id']];
|
||||
$keys []= $post['id'];
|
||||
|
Loading…
Reference in New Issue
Block a user