mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
* redo page render following the logic of:
Response ─┬─> TextResponse ─> TextResponseImpl
└─> TemplateResponse ─> TemplateResponseImpl
* split up giant files, one per response path
* caching becomes a trait, implemented where necessary
* TextResponses (Ajax) can now be cached
* make use of previously defined php classes for js objects
* Tabs, Listview, Tooltip, Announcement, Markup, Book, ...
* \Aowow\Template\PageTemplate is the new class to be cached
* do not discard error messages generated after vars have been sent to template
and store in session for display at a later time
* implement tracking consent management
* move logic out of template into their respective endpoints
83 lines
3.1 KiB
PHP
83 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace Aowow;
|
|
|
|
require 'includes/kernel.php';
|
|
|
|
if (CLI)
|
|
die("this script must not be run from CLI.\nto setup aowow use 'php aowow'\n");
|
|
|
|
|
|
$pageCall = 'home'; // default to Homepage unless specified otherwise
|
|
$pageParam = '';
|
|
parse_str(parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $query);
|
|
foreach ($query as $page => $param)
|
|
{
|
|
$page = preg_replace('/[^\w\-]/i', '', $page);
|
|
|
|
$pageCall = Util::lower($page);
|
|
$pageParam = $param ?? '';
|
|
break; // only use first k/v-pair to determine page
|
|
}
|
|
|
|
[$classMod, $file] = match (true)
|
|
{
|
|
// is search ajax
|
|
isset($_GET['json']) => ['Json', $pageCall . '_json' ],
|
|
isset($_GET['opensearch']) => ['Open', $pageCall . '_open' ],
|
|
// is powered tooltip
|
|
isset($_GET['power']) => ['Power', $pageCall . '_power' ],
|
|
// is item data xml dump
|
|
isset($_GET['xml']) => ['Xml', $pageCall . '_xml' ],
|
|
// is community content feed
|
|
isset($_GET['rss']) => ['Rss', $pageCall . '_rss' ],
|
|
// is sounds playlist
|
|
isset($_GET['playlist']) => ['Playlist', $pageCall . '_playlist'],
|
|
// pageParam can be sub page
|
|
(bool)preg_match('/^[a-z\-]+$/i', $pageParam) => [Util::ucFirst(strtr($pageParam, ['-' => ''])), Util::lower($pageParam)],
|
|
// no pageParam or PageParam is param for BasePage
|
|
default => ['Base', $pageCall ]
|
|
};
|
|
|
|
// admin=X pages are mixed html and ajax on the same endpoint .. meh
|
|
if ($pageCall == 'admin' && isset($_GET['action']) && preg_match('/^[a-z]+$/', $_GET['action']))
|
|
{
|
|
$classMod .= 'Action' . Util::ucFirst($_GET['action']);
|
|
$file .= '_' . Util::lower($_GET['action']);
|
|
}
|
|
|
|
try {
|
|
$responder = new \StdClass;
|
|
|
|
// 1. try specialized response
|
|
if (file_exists('endpoints/'.$pageCall.'/'.$file.'.php'))
|
|
{
|
|
require_once 'endpoints/'.$pageCall.'/'.$file.'.php';
|
|
|
|
$class = __NAMESPACE__.'\\' . Util::ucFirst(strtr($pageCall, ['-' => ''])).$classMod.'Response';
|
|
$responder = new $class($pageParam);
|
|
}
|
|
// 2. try generalized response
|
|
else if (file_exists('endpoints/'.$pageCall.'/'.$pageCall.'.php'))
|
|
{
|
|
require_once 'endpoints/'.$pageCall.'/'.$pageCall.'.php';
|
|
|
|
$class = __NAMESPACE__.'\\' . Util::ucFirst(strtr($pageCall, ['-' => ''])).'BaseResponse';
|
|
$responder = new $class($pageParam);
|
|
}
|
|
// 3. throw .. your hands in the air and give up
|
|
if (!is_callable([$responder, 'process']))
|
|
throw new \Exception('request handler '.$pageCall.'::'.$classMod.'('.$pageParam.') not found');
|
|
|
|
$responder->process();
|
|
}
|
|
catch (\Exception $e)
|
|
{
|
|
if (isset($_GET['json']) || isset($_GET['opensearch']) || isset($_GET['power']) || isset($_GET['xml']) || isset($_GET['rss']))
|
|
(new TextResponse($pageParam))->generate404();
|
|
else
|
|
(new TemplateResponse($pageParam))->generateError($pageCall);
|
|
}
|
|
|
|
?>
|