135 lines
3.2 KiB
PHP
135 lines
3.2 KiB
PHP
<?php
|
|
|
|
function insertEmoji($text) {
|
|
global $emojiEnabled, $db;
|
|
|
|
if (!$emojiEnabled) {
|
|
return htmlspecialchars($text);
|
|
}
|
|
|
|
$out = "";
|
|
$arr = explode(":", htmlspecialchars($text));
|
|
$c = 0;
|
|
$allowNext = false;
|
|
|
|
foreach ($arr as $segment) {
|
|
$c++;
|
|
|
|
if (!$allowNext) {
|
|
$allowNext = true;
|
|
} else if (sizeof($arr) <= $c) {
|
|
if ($c !== 1) {
|
|
$out .= ":";
|
|
}
|
|
} else {
|
|
if (preg_match("/^[A-Za-z0-9_-]+$/", $segment) !== false) {
|
|
$query = "
|
|
SELECT url FROM emoji WHERE name='{$segment}';
|
|
";
|
|
|
|
$queryResponse = pg_query($db, $query);
|
|
$url = pg_fetch_array($queryResponse);
|
|
|
|
if (pg_num_rows($queryResponse) !== 0) {
|
|
$out .= "<img class=\"emoji\" src=\"{$url['url']}\" alt=\":${segment}:\">";
|
|
$allowNext = false;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if ($c !== 1) {
|
|
$out .= ":";
|
|
}
|
|
}
|
|
|
|
$out .= $segment;
|
|
}
|
|
|
|
return $out;
|
|
}
|
|
|
|
function getQuestion(
|
|
$question,
|
|
$includePermalink=1,
|
|
$isAdmin=0,
|
|
$isResponding=0,
|
|
$adminPassword=""
|
|
) {
|
|
$q = insertEmoji($question["text"]);
|
|
$q .= "<div class=\"time\">{$question['time']}</div>";
|
|
|
|
if ($question["responsetext"]) {
|
|
$q .= "<div class=\"response\">" . insertEmoji($question['responsetext']);
|
|
$q .= "<div class=\"time\">{$question['responsetime']}</div></div>";
|
|
}
|
|
|
|
if ($isResponding) {
|
|
if ($question["responsetext"]) {
|
|
$q .= "<h3>enter your edits</h3>";
|
|
} else {
|
|
$q .= "<h3>enter a response</h3>";
|
|
}
|
|
|
|
$q .= "
|
|
<form class=\"frm\" action=\"index.php\">
|
|
<input hidden name=\"id\" value=\"{$question['id']}\">
|
|
<input hidden name=\"page\" value=\"respond\">
|
|
<input hidden name=\"pw\" value=\"{$adminPassword}\">
|
|
<input id=\"passinput\" name=\"text\" value=\"{$question['responsetext']}\" autofocus required><br>
|
|
<button class=\"submitbutton\" type=\"submit\">send</button>
|
|
</form>
|
|
";
|
|
}
|
|
|
|
if ($includePermalink === 1) {
|
|
$q .= "<a class=\"permalink\" href=\"fetch.php?id={$question['id']}\">permalink</a>";
|
|
}
|
|
|
|
if ($isAdmin === 1) {
|
|
if ($question["ispublic"] === "t") {
|
|
$q .= "<a class=\"permalink\" href=\"index.php?page=respond&id={$question['id']}&pw={$adminPassword}\">";
|
|
|
|
if ($question["isrespondedto"] === "t") {
|
|
$q .= "edit response";
|
|
} else {
|
|
$q .= "respond";
|
|
}
|
|
|
|
$q .= "</a>";
|
|
} else {
|
|
$q .= "<a class=\"permalink\" href=\"index.php?page=mark&action=";
|
|
|
|
if ($question["isprivread"] === "t") {
|
|
$q .= "unread";
|
|
} else {
|
|
$q .= "read";
|
|
}
|
|
|
|
$q .= "&id={$question['id']}&pw={$adminPassword}\">mark ";
|
|
|
|
if ($question["isprivread"] === "t") {
|
|
$q .= "unread";
|
|
} else {
|
|
$q .= "read";
|
|
}
|
|
|
|
$q .= "</a>";
|
|
}
|
|
|
|
$q .= " / <a class=\"permalink\" href=\"index.php?page=delete&id={$question['id']}&pw={$adminPassword}\">delete</a>";
|
|
}
|
|
|
|
if ($question["iscwed"] === "t") {
|
|
$open = "";
|
|
|
|
if ($isResponding) {
|
|
$open = " open";
|
|
}
|
|
|
|
$q = "<details{$open}><summary>cw: " . insertEmoji($question["cw"]) . "</summary>{$q}</details>";
|
|
}
|
|
|
|
return "<div class=\"question\">{$q}</div>";
|
|
}
|
|
|
|
?>
|