librecat/user.php

80 lines
2.4 KiB
PHP

<?php
session_start();
$db = new SQLite3('ask.db');
$p_user = $db->query("SELECT * FROM users WHERE username = '" . $_GET["q"] . "';")->fetchArray(SQLITE3_ASSOC);
if(!$p_user || !$p_user["id"]){
include("404.php");
die();
}
if(isset($_SESSION["uid"])){
if($_SESSION["uid"] == $p_user["id"]){
$is_current_user = true;
}
}
?>
<html>
<head>
<title><?= $p_user["username"] ?> | LibreCat</title>
</head>
<body>
<?php include("include/header.php"); ?>
<h2><?= $p_user["username"] ?></h2>
<p><?= $p_user["bio"] ?></p>
<?php
if($is_current_user){
if($fancy_urls)
echo("<a href='/config/profile'>config</a>");
else
echo("<a href='/config.php?q=profile'>config</a>");
}
?>
<form name="input" action="/action/publish-question.php" method="post">
<textarea placeholder="Ask me anything!" id="post-text" name="post-text"></textarea>
<br/>
<input type="hidden" name="uid" value="<?= $p_user["id"] ?>"/>
<p><input type="checkbox" <?php if(!isset($_SESSION["uid"])) echo("checked disabled"); ?> name="anon"/> Post anonymously</p>
<?php if(isset($errorMsg)) echo "<p>$errorMsg</p>\n"; ?>
<input type="submit" name="post-submit"/>
</form>
<?php
$u_prep = $db->prepare("SELECT * FROM users WHERE id = :id");
$qs = $db->query("SELECT * FROM questions WHERE user = '" . $p_user["id"] . "' LIMIT 0, 10;");
$time = new DateTime("@0");
while($current = $qs->fetchArray(SQLITE3_ASSOC)){
// Execute prepared statement
$u_prep->bindValue(":id", $current["by"], SQLITE3_INTEGER);
$q_user = $u_prep->execute()->fetchArray(SQLITE3_ASSOC);
if($q_user["id"] == 0) echo("<h3>" . $q_user["name"] ."</h3>");
else if($fancy_urls) echo("<a href='/user/" . $q_user["name"] . "'><h3>" . $q_user["name"] ."</h3></a>\n");
else echo("<a href='/user.php?q=" . $q_user["name"] . "'><h3>" . $q_user["name"] ."</h3></a>\n");
echo("\t<p>". $current["question"] ."<p>\n");
if($is_current_user){
echo("\t<a href='/action/reply.php?q=".$current["id"]."'>reply</a> ");
echo("\t<a href='/action/delete-question.php?q=".$current["id"]."'>delete</a> ");
echo("fav ignore ");
}
// Time
$time->settimestamp($current["q_date"]);
echo($time->format("y-m-d h:i:s"));
if($current["answer"]){
echo("<p>" . $current["answer"] . "</p>");
$time->settimestamp($current["a_date"]);
echo($time->format("y-m-d h:i:s"));
}
echo("\n\n");
}
?>
</body>
</html>