PlainSQLiteBlog/pages/index.php

49 lines
1.0 KiB
PHP

<?php
global $c;
$strArg1 = substr(Request::getPath(), 1);
$varPosts = [];
// Get one post by its id:
if (preg_match("/^[0-9]{1,}$/", $strArg1))
{
$varPosts = $c->query(
"SELECT *
from posts as p
where
id = ?
order by
created desc",
intval($strArg1));
}
// Get many post by its author:
if (preg_match("/^\@[A-Za-z0-9]{1,}$/", $strArg1))
{
$strArg1 = substr($strArg1, 1);
$varPosts = $c->query(
"SELECT *
from posts as p
where
username like ?
order by
created desc",
$strArg1);
}
if (count($varPosts) < 1)
{
$varPosts = $c->query(
"SELECT *
from posts as p
where
location like ?
or location like '*'
order by
created desc",
Request::getPath());
}
?>
<?php PostRender::rows($varPosts); ?>