/var/www/aikonia/html/library/controllers/Blurb.php
{
$where = field('writer')->notIn('andrew-david', 'david', 'alexandria');
}
else
{
$where = field('writer')->eq($author);
}
}
$query = $this->queryFactory->select()
->from("blurbs")
->where($where)
->offset(($page - 1) * $blurbsPerPage)
->limit($blurbsPerPage)
->orderBy('id', 'desc')
->compile();
$statement = $this->pdo->prepare($query->sql());
if(!$statement->execute($query->params()))
throw new \Exception("Error fetching blurbs from database.");
$blurbs = array();
foreach($statement->fetchAll(\PDO::FETCH_CLASS, \library\models\Blurb::class) as $blurb)
{
$blurbs[] = \library\models\Blurb::cast($blurb);
}
return $blurbs;
}
public function getNav(string $author = '', int $page = 1):Nav
{
$blurbsPerPage = 20;
$nav = new Nav();
$nav->first = 1;
$nav->previous = max(1, $page - 1);
$where = field('id')->gt(0);
/var/www/aikonia/html/library/controllers/Blurb.php
{
$where = field('writer')->notIn('andrew-david', 'david', 'alexandria');
}
else
{
$where = field('writer')->eq($author);
}
}
$query = $this->queryFactory->select()
->from("blurbs")
->where($where)
->offset(($page - 1) * $blurbsPerPage)
->limit($blurbsPerPage)
->orderBy('id', 'desc')
->compile();
$statement = $this->pdo->prepare($query->sql());
if(!$statement->execute($query->params()))
throw new \Exception("Error fetching blurbs from database.");
$blurbs = array();
foreach($statement->fetchAll(\PDO::FETCH_CLASS, \library\models\Blurb::class) as $blurb)
{
$blurbs[] = \library\models\Blurb::cast($blurb);
}
return $blurbs;
}
public function getNav(string $author = '', int $page = 1):Nav
{
$blurbsPerPage = 20;
$nav = new Nav();
$nav->first = 1;
$nav->previous = max(1, $page - 1);
$where = field('id')->gt(0);
/var/www/aikonia/html/library/views/Blurbs.php
function __construct(Engine $templates, Blurb $blurb)
{
$this->templates = $templates;
$this->blurb = $blurb;
}
public function index(int $page = 1)
{
return $this->get('', $page);
}
public function author(string $author, int $page = 1)
{
return $this->get($author, $page);
}
public function get(string $author = '', int $page = 1)
{
$blurbs = $this->blurb->filter($author, $page);
$this->templates->addGlobals([
'subtitle' => 'Blurbs',
'description' => 'Blurbs for Aikonia, an on-going fantasy adventure webcomic that updates every Monday.'
]);
return $this->templates->render('blurbs', array('blurbs' => $blurbs, 'writer' => $author, 'nav' => $this->blurb->getNav($author, $page)));
}
}
/var/www/aikonia/html/library/views/Blurbs.php
{
/** @var Engine */
private $templates;
/** @var Blurb */
private $blurb;
function __construct(Engine $templates, Blurb $blurb)
{
$this->templates = $templates;
$this->blurb = $blurb;
}
public function index(int $page = 1)
{
return $this->get('', $page);
}
public function author(string $author, int $page = 1)
{
return $this->get($author, $page);
}
public function get(string $author = '', int $page = 1)
{
$blurbs = $this->blurb->filter($author, $page);
$this->templates->addGlobals([
'subtitle' => 'Blurbs',
'description' => 'Blurbs for Aikonia, an on-going fantasy adventure webcomic that updates every Monday.'
]);
return $this->templates->render('blurbs', array('blurbs' => $blurbs, 'writer' => $author, 'nav' => $this->blurb->getNav($author, $page)));
}
}
/var/www/aikonia/html/vendor/pecee/simple-router/src/Pecee/SimpleRouter/Route/Route.php
$namespace = $this->getNamespace();
$className = ($namespace !== null && $controller[0][0] !== '\\') ? $namespace . '\\' . $controller[0] : $controller[0];
$router->debug('Loading class %s', $className);
$class = $router->getClassLoader()->loadClass($className);
if (\count($controller) === 1) {
$controller[1] = '__invoke';
}
$method = $controller[1];
if (method_exists($class, $method) === false) {
throw new NotFoundHttpException(sprintf('Method "%s" does not exist in class "%s"', $method, $className), 404);
}
$router->debug('Executing callback');
return \call_user_func_array([$class, $method], array_values($parameters));
}
protected function parseParameters($route, $url, $parameterRegex = null)
{
$regex = (strpos($route, $this->paramModifiers[0]) === false) ? null :
sprintf(
static::PARAMETERS_REGEX_FORMAT,
$this->paramModifiers[0],
$this->paramOptionalSymbol,
$this->paramModifiers[1]
);
// Ensures that host names/domains will work with parameters
$url = '/' . ltrim($url, '/');
$urlRegex = '';
$parameters = [];
if ($regex === null || (bool)preg_match_all('/' . $regex . '/u', $route, $parameters) === false) {
$urlRegex = preg_quote($route, '/');
} else {
/var/www/aikonia/html/vendor/pecee/simple-router/src/Pecee/SimpleRouter/Router.php
$route->loadMiddleware($this->request, $this);
$route->addGetParametersModelToParameters($this->request);
$route->addFilesToParameters($this->request);
$route->addPostBodyToParameters($this->request);
$output = $this->handleRouteRewrite($key, $url);
if ($output !== null) {
return $output;
}
$methodNotAllowed = false;
$this->request->addLoadedRoute($route);
$this->fireEvents(EventHandler::EVENT_RENDER_ROUTE, [
'route' => $route,
]);
$output = $route->renderRoute($this->request, $this);
if ($output !== null) {
return $output;
}
$output = $this->handleRouteRewrite($key, $url);
if ($output !== null) {
return $output;
}
}
}
} catch (\Exception $e) {
$this->handleException($e);
}
if ($methodNotAllowed === true) {
$message = sprintf('Route "%s" or method "%s" not allowed.', $this->request->getUrl()->getPath(), $this->request->getMethod());
$this->handleException(new NotFoundHttpException($message, 403));
}
if (\count($this->request->getLoadedRoutes()) === 0) {
/var/www/aikonia/html/vendor/pecee/simple-router/src/Pecee/SimpleRouter/Router.php
* @throws \Exception
*/
public function start(): ?string
{
$this->debug('Router starting');
$this->fireEvents(EventHandler::EVENT_INIT);
$this->loadRoutes();
if ($this->csrfVerifier !== null) {
$this->fireEvents(EventHandler::EVENT_RENDER_CSRF, [
'csrfVerifier' => $this->csrfVerifier,
]);
/* Verify csrf token for request */
$this->csrfVerifier->handle($this->request);
}
$output = $this->routeRequest();
$this->fireEvents(EventHandler::EVENT_LOAD, [
'loadedRoutes' => $this->getRequest()->getLoadedRoutes(),
]);
$this->debug('Routing complete');
return $output;
}
/**
* Routes the request
*
* @return string|null
* @throws HttpException
* @throws \Exception
*/
public function routeRequest(): ?string
{
$this->debug('Routing request');
/var/www/aikonia/html/vendor/pecee/simple-router/src/Pecee/SimpleRouter/SimpleRouter.php
*/
protected static $response;
/**
* Router instance
* @var Router
*/
protected static $router;
/**
* Start routing
*
* @throws \Pecee\SimpleRouter\Exceptions\NotFoundHttpException
* @throws \Pecee\Http\Middleware\Exceptions\TokenMismatchException
* @throws HttpException
* @throws \Exception
*/
public static function start(): void
{
echo static::router()->start();
}
/**
* Start the routing an return array with debugging-information
*
* @return array
*/
public static function startDebug(): array
{
$routerOutput = null;
try {
ob_start();
static::router()->setDebugEnabled(true)->start();
$routerOutput = ob_get_contents();
ob_end_clean();
} catch (\Exception $e) {
}
// Try to parse library version
/var/www/aikonia/html/index.php
// ABOUT
SimpleRouter::get('/about', 'About@index')->setName('about');
SimpleRouter::get('/cast', 'About@index')->setName('about');
// LINKS
SimpleRouter::get('/links', 'Links@index')->setName('links');
});
// API
SimpleRouter::group(['prefix' => '/api', 'namespace' => 'library\controllers'], function()
{
// PAGE
SimpleRouter::post('/buffer/post', 'Page@post')->setName('postbuffer');
SimpleRouter::post('/page/images', 'Page@getImages')->setName('getimages');
// COMMENT
SimpleRouter::post('/comment/post', 'Comment@post')->setName('postcomment');
});
SimpleRouter::start();