123 lines
4.3 KiB
PHP
123 lines
4.3 KiB
PHP
<?php
|
|
class PostRender
|
|
{
|
|
public static function processRows($varRows)
|
|
{
|
|
for ($i = 0; $i < count($varRows); $i++)
|
|
{
|
|
$r = $varRows[$i];
|
|
$r["content"] = Settings::makeReplacements($r["content"]);
|
|
$varRows[$i] = $r;
|
|
}
|
|
|
|
return $varRows;
|
|
}
|
|
|
|
public static function rows($varRows)
|
|
{
|
|
$varUser = UserAuth::getUser();
|
|
$intRenderedRows = 0;
|
|
$intList = Request::getParam("v") == "list";
|
|
$intJson = Request::getParam("v") == "json";
|
|
$intText = Request::getParam("v") == "text";
|
|
|
|
if ($intJson)
|
|
Respond::json(PostRender::processRows($varRows));
|
|
|
|
$strTextBuffer = "";
|
|
|
|
?>
|
|
|
|
<div class="post-container">
|
|
<?php foreach ($varRows as $r): ?>
|
|
<?php if (!UserAuth::visible($r["visibility"])) continue; ?>
|
|
|
|
<?php
|
|
$strText = $r["content"];
|
|
preg_match("/(^|\n).*?([A-Za-z0-9].*?(\!|\.|\,|\?|\n))/i", $strText, $varTitles);
|
|
$strTitle = $varTitles[2];
|
|
$strTitle = trim($strTitle);
|
|
?>
|
|
|
|
<?php if ($intList): ?>
|
|
<div class="post-title">
|
|
<a href="/<?= $r["id"]; ?>"><?= $strTitle; ?></a> · by <?= $r["username"]; ?>
|
|
</div>
|
|
|
|
<?php
|
|
$intRenderedRows++;
|
|
continue;
|
|
?>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($intRenderedRows > 0): ?>
|
|
<hr />
|
|
<?php
|
|
$strTextBuffer .= "\n\n---\n\n";
|
|
?>
|
|
<?php endif; ?>
|
|
|
|
<!-- <?= $strTitle; ?> -->
|
|
<div class="post">
|
|
<div class="post-body">
|
|
<?php PageRender::markdown($r["content"]); ?>
|
|
<?php
|
|
$strTextBuffer .= $r["content"];
|
|
?>
|
|
</div>
|
|
|
|
<div class="post-footer">
|
|
<div class="post-author">by <?= $r["username"]; ?></div>
|
|
<div class="post-date">on <?= $r["created"]; ?> UTC</div>
|
|
|
|
<div class="post-links">
|
|
<a href="/<?= $r["id"]; ?>">Permalink</a> ·
|
|
<a href="<?= $r["location"]; ?>">Related</a>
|
|
|
|
<?php
|
|
$intOwnership =
|
|
UserAuth::has("is_admin") ||
|
|
$varUser["username"] == $r["username"];
|
|
?>
|
|
|
|
<?php if ($intOwnership): ?>
|
|
· <a href="/post/<?= $r["id"]; ?>">Edit</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php
|
|
$strTextBuffer .= "\n";
|
|
$strTextBuffer .= "\n* by {$r["username"]}";
|
|
$strTextBuffer .= "\n* on {$r["created"]}";
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php $intRenderedRows++; ?>
|
|
<?php endforeach; ?>
|
|
|
|
<?php if ($intRenderedRows < 1): ?>
|
|
<?php
|
|
$strMessage = "Sorry, there is nothing here to show.";
|
|
$strTextBuffer .= $strMessage;
|
|
?>
|
|
<div><?= $strMessage; ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php
|
|
|
|
if ($intText)
|
|
{
|
|
ob_clean();
|
|
header("Content-Type: text/plain");
|
|
|
|
$strTextBuffer = Settings::makeReplacements($strTextBuffer);
|
|
echo $strTextBuffer;
|
|
|
|
ob_end_flush();
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
?>
|