This commit is contained in:
flash 2022-02-04 20:30:52 +00:00
parent b74b7a548b
commit 49eae219e5
16 changed files with 53 additions and 260 deletions

3
.gitignore vendored
View file

@ -10,4 +10,5 @@
/public/signature/cover_url.txt
/public/signature/np.json
/public/signature/signature.png
.DS_Store
/.debug

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "lib/index"]
path = lib/index
url = https://github.com/flashwave/index.git

View file

@ -1,28 +0,0 @@
<?php
class FmColour {
private $raw = null;
public function __construct(?int $raw) {
$this->raw = $raw;
}
public function hasColour(): bool {
return $this->raw !== null;
}
public function getRaw(): int {
return $this->raw ?? 0;
}
public function getRed(): int { return ($this->getRaw() >> 16) & 0xFF; }
public function getGreen(): int { return ($this->getRaw() >> 8) & 0xFF; }
public function getBlue(): int { return $this->getRaw() & 0xFF; }
public function getHex(): string { return str_pad(dechex($this->getRaw()), 6, '0'); }
public function getCSS(): string {
if(!$this->hasColour())
return 'inherit';
return '#' . $this->getHex();
}
}

View file

@ -1,14 +0,0 @@
<?php
class FmLanguage {
private $language_id = -1;
private $language_name = '';
private $language_colour = null;
public static function fromStdClass(stdClass $lang) {
$langRaw = (array)$lang;
$lang = new static;
foreach($langRaw as $prop => $val)
$lang->{$prop} = $val;
return $lang;
}
}

View file

@ -1,170 +0,0 @@
<?php
class FmProject {
public const TYPE_PROJECT = 'Project';
public const TYPE_TOOL = 'Tool';
private $project_id = -1;
private $project_name = '';
private $project_name_clean = null;
private $project_summary = null;
private $project_description = null;
private $project_order = 0;
private $project_type = self::TYPE_PROJECT;
private $project_featured = 0;
private $project_colour = null;
private $project_homepage = null;
private $project_repository = null;
private $project_forum = null;
private $project_created = null;
private $project_deleted = null;
private $project_archived = null;
private $languages = null;
public function getId(): int {
return $this->project_id < 1 ? -1 : $this->project_id;
}
public function getName(): string {
return $this->project_name;
}
public function getCleanName(): string {
return $this->project_name_clean ?? str_replace(' ', '-', trim(strtolower($this->getName())));
}
public function getSummary(): string {
return $this->project_summary ?? '';
}
public function getDescription(): string {
return $this->project_description ?? '';
}
public function getDescriptionLines(): array {
$linesRaw = array_reverse(explode("\n", $this->getDescription()));
$lines = [];
while(($line = array_pop($linesRaw)) !== false) {
$line = trim($line);
if(!empty($line))
$lines[] = $line;
}
return $lines;
}
public function getOrder(): int {
return $this->project_order;
}
public function getType(): string {
return $this->project_type;
}
public function isProject(): bool {
return $this->getType() === self::TYPE_PROJECT;
}
public function isTool(): bool {
return $this->getType() === self::TYPE_TOOL;
}
public function isFeatured(): bool {
return boolval($this->project_featured);
}
// TODO: INHERIT LANGUAGE COLOUR
public function hasColour(): bool {
return $this->project_colour !== null;
}
public function getColour(): FmColour {
return new FmColour($this->project_colour);
}
public function hasHomepage(): bool {
return !empty($this->project_homepage);
}
public function getHomepage(): string {
return $this->project_homepage ?? '';
}
public function hasRepository(): bool {
return !empty($this->project_repository);
}
public function getRepository(): string {
return $this->project_repository ?? '';
}
public function hasForum(): bool {
return !empty($this->project_forum);
}
public function getForum(): string {
return $this->project_forum ?? '';
}
public function getCreatedTime(): DateTime {
return new DateTime('@' . ($this->project_created ?? 0));
}
public function isDeleted(): bool {
return $this->project_deleted !== null;
}
public function getDeletedTime(): DateTime {
return new DateTime('@' . ($this->project_deleted ?? 0));
}
public function isArchived(): bool {
return $this->project_archived !== null;
}
public function getArchivedTime(): DateTime {
return new DateTime('@' . ($this->project_archived ?? 0));
}
public function getLinks(): array {
$links = [];
if($this->hasHomepage())
$links[] = FmProjectLink::create('homepage', 'Homepage', $this->getHomepage());
if($this->hasRepository())
$links[] = FmProjectLink::create('repository', 'Source', $this->getRepository());
if($this->hasForum())
$links[] = FmProjectLink::create('forum', 'Discussion', $this->getForum());
return $links;
}
public function getLanguages(): array {
return $this->languages ?? [];
}
private function transformLanguages(): void {
if(empty($this->languages))
return;
foreach($this->languages as &$lang)
if($lang instanceof stdClass)
$lang = FmLanguage::fromStdClass($lang);
}
public static function byFeatured(): array {
return cache_output('projects-featured-noconvert', 300, function() {
$projects = json_decode(file_get_contents('https://flash.moe/2020/projects.php?dump_that_shit&noconvert&rf'));
foreach($projects as &$project) {
$projRaw = (array)$project;
$project = new static;
foreach($projRaw as $prop => $val)
$project->{$prop} = $val;
$project->transformLanguages();
}
return $projects;
});
}
public static function all(): array {
return cache_output('projects-noconvert', 300, function() {
$projects = json_decode(file_get_contents('https://flash.moe/2020/projects.php?dump_that_shit&noconvert'));
foreach($projects as &$project) {
$projRaw = (array)$project;
$project = new static;
foreach($projRaw as $prop => $val)
$project->{$prop} = $val;
$project->transformLanguages();
}
return $projects;
});
}
}

View file

@ -1,24 +0,0 @@
<?php
class FmProjectLink {
private $className;
private $text;
private $url;
public function getClass(): string {
return $this->className;
}
public function getText(): string {
return $this->text;
}
public function getUrl(): string {
return $this->url;
}
public static function create(string $class, string $text, string $url): self {
$link = new static;
$link->className = $class;
$this->text = $text;
$this->url = $url;
return $link;
}
}

1
lib/index Submodule

@ -0,0 +1 @@
Subproject commit 74c0e6f17c21af3669345e38598ada1d37675ad4

23
makai.php Normal file
View file

@ -0,0 +1,23 @@
<?php
namespace Makai;
use Index\Autoloader;
define('MKI_STARTUP', microtime(true));
define('MKI_ROOT', __DIR__);
define('MKI_DEBUG', is_file(MKI_ROOT . '/.debug'));
define('MKI_DIR_SRC', MKI_ROOT . '/src');
define('MKI_DIR_LIB', MKI_ROOT . '/lib');
define('MKI_DIR_PUB', MKI_ROOT . '/public');
if(MKI_DEBUG) {
ini_set('display_errors', 'on');
error_reporting(-1);
} else {
ini_set('display_errors', 'off');
error_reporting(0);
}
require_once MKI_DIR_LIB . '/index/index.php';
Autoloader::addNamespace(__NAMESPACE__, MKI_DIR_SRC);

View file

@ -1,4 +1,6 @@
<?php
namespace Makai;
if(preg_match('#^/blog/([0-9]+)$#', $reqPath, $matches) || $reqPath === '/blog.php' || $reqPath === '/blog-post.php') {
if($reqMethod !== 'GET')
return FM_ERR | 405;

View file

@ -1,4 +1,6 @@
<?php
namespace Makai;
if($reqPath === '/contact.php' || $reqPath === '/contact.html') {
if($reqMethod !== 'GET')
return FM_ERR | 405;

View file

@ -1,4 +1,6 @@
<?php
namespace Makai;
if($reqPath === '/etc.php' || $reqPath === 'etc.html'
|| $reqPath === '/etcetera' || $reqPath === '/etcetera.html' || $reqPath === '/etcetera.php'
|| $reqPath === '/misc' || $reqPath === '/misc.html' || $reqPath === '/misc.php') {

View file

@ -1,4 +1,6 @@
<?php
namespace Makai;
if($reqPath === '/about' || $reqPath === '/about.html' || $reqPath === '/about.php'
|| $reqPath === '/index.php' || $reqPath === '/index.html') {
if($reqMethod !== 'GET')
@ -102,19 +104,6 @@ if($reqPath === '/home') {
return FM_HIT;
}
if($reqPath === '/test') {
if($reqMethod !== 'GET')
return FM_ERR | 405;
if($reqHead)
return FM_HIT;
header('Content-Type: text/plain');
var_dump(FmProject::byFeatured());
return FM_HIT;
}
if($reqPath === '/donate') {
header('Location: https://paypal.me/flashwave');
return FM_HIT | 302;
@ -128,7 +117,7 @@ if($reqPath === '/' || $reqPath === '/365') {
$is365 = $reqPath === '/365';
$legacyPage = filter_input(INPUT_GET, 'p', FILTER_SANITIZE_STRING);
$legacyPage = (string)filter_input(INPUT_GET, 'p');
if(!empty($legacyPage)) {
$legacyPages = [
'projects' => '/projects',

View file

@ -1,4 +1,6 @@
<?php
namespace Makai;
if($reqPath === '/projects.php' || $reqPath === '/projects.html'
|| $reqPath === '/utilities' || $reqPath === '/utilities.php' || $reqPath === '/utilities.html') {
if($reqMethod !== 'GET')

View file

@ -1,4 +1,6 @@
<?php
namespace Makai;
if($reqPath === '/related.php' || $reqPath === '/related.html'
|| $reqPath === '/friends' || $reqPath === '/friends.html' || $reqPath === '/friends.php') {
if($reqMethod !== 'GET')

View file

@ -1,4 +1,10 @@
<?php
namespace Makai;
use Index\DateTime;
require_once __DIR__ . '/../makai.php';
define('FM_HIT', 0x01000000);
define('FM_ERR', 0x02000000);
@ -124,14 +130,10 @@ function cache_output(string $name, int $lifetime, callable $callable) {
return unserialize(file_get_contents($path));
}
set_include_path(realpath(__DIR__ . '/../lib/') . PATH_SEPARATOR . get_include_path());
spl_autoload_extensions('.php');
spl_autoload_register();
ob_start();
$reqMethod = filter_input(INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING);
$reqPath = '/' . trim(parse_url(filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_STRING), PHP_URL_PATH), '/');
$reqMethod = (string)filter_input(INPUT_SERVER, 'REQUEST_METHOD');
$reqPath = '/' . trim(parse_url((string)filter_input(INPUT_SERVER, 'REQUEST_URI'), PHP_URL_PATH), '/');
$reqHead = false;
if($reqMethod == 'HEAD') {

View file

@ -28,8 +28,8 @@ try {
}
if(isset($_POST['temp']) && isset($_POST['hash']) && isset($_POST['time'])) {
$temp = (string)filter_input(INPUT_POST, 'temp', FILTER_SANITIZE_STRING);
$hash = (string)filter_input(INPUT_POST, 'hash', FILTER_SANITIZE_STRING);
$temp = (string)filter_input(INPUT_POST, 'temp');
$hash = (string)filter_input(INPUT_POST, 'hash');
$time = (string)filter_input(INPUT_POST, 'time', FILTER_SANITIZE_NUMBER_INT);
if(!hash_equals(hash_hmac('sha256', $temp . '|' . $time, FM_TEMP_KEY), $hash))