158 lines
3.5 KiB
PHP
158 lines
3.5 KiB
PHP
<?php
|
|
|
|
function insertEmoji($text) {
|
|
global $db;
|
|
|
|
echo "gay";
|
|
|
|
$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=""
|
|
) {
|
|
global $emojiEnabled;
|
|
|
|
if ($emojiEnabled) {
|
|
$q = $question["parsedtext"];
|
|
} else {
|
|
$q = $question["text"];
|
|
}
|
|
|
|
$q .= "<div class=\"time\">{$question['time']}</div>";
|
|
|
|
if ($question["responsetext"]) {
|
|
$q .= "<div class=\"response\">";
|
|
|
|
if ($emojiEnabled) {
|
|
$q .= $question['parsedresponsetext'];
|
|
} else {
|
|
$q .= $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 name=\"text\" value=\"{$question['responsetext']}\" autofocus required><br>
|
|
|
|
";
|
|
if ($question["iscwed"] === "t") {
|
|
$q .= "cw: <input name=\"cw\" value=\"{$question['cw']}\"><br>";
|
|
} else {
|
|
$q .= "cw: <input name=\"cw\"><br>";
|
|
}
|
|
|
|
$q .= "<input type=\"submit\" value=\"send\"></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";
|
|
}
|
|
|
|
if ($emojiEnabled) {
|
|
$cw = $question["parsedcw"];
|
|
} else {
|
|
$cw = $question["cw"];
|
|
}
|
|
|
|
$q = "<details{$open}><summary>cw: {$cw}</summary>{$q}</details>";
|
|
}
|
|
|
|
return "<div class=\"question\">{$q}</div>";
|
|
}
|
|
|
|
?>
|