librecat/user.php

114 lines
3.6 KiB
PHP
Raw Normal View History

2020-05-17 00:02:20 +00:00
<?php
2020-05-21 15:57:59 +00:00
session_start();
2020-05-30 20:23:04 +00:00
include("include/settings.php");
2020-05-17 20:06:22 +00:00
$db = new SQLite3('ask.db');
2020-05-17 00:02:20 +00:00
2020-05-21 15:57:59 +00:00
$p_user = $db->query("SELECT * FROM users WHERE username = '" . $_GET["q"] . "';")->fetchArray(SQLITE3_ASSOC);
if(!$p_user || !$p_user["id"]){
2020-05-21 08:07:28 +00:00
include("404.php");
die();
}
2020-05-17 00:02:20 +00:00
2020-05-21 15:57:59 +00:00
if(isset($_SESSION["uid"])){
if($_SESSION["uid"] == $p_user["id"]){
$is_current_user = true;
}
}
2020-05-20 16:08:25 +00:00
?>
<html>
<head>
2020-05-30 20:23:04 +00:00
<?php include("themes/$theme_name/user.php"); ?>
2020-05-21 15:57:59 +00:00
<title><?= $p_user["username"] ?> | LibreCat</title>
2020-05-20 16:08:25 +00:00
</head>
2020-05-21 15:57:59 +00:00
<body>
2020-05-30 20:23:04 +00:00
<?php // print_profile($p_user); ?>
2020-05-21 15:57:59 +00:00
<?php include("include/header.php"); ?>
2020-05-30 20:23:04 +00:00
<div id="parent-container">
<div id="user-container">
<p id="user-name"><?= $p_user["username"] ?></p>
<p class="user-bio"><?php
// if($p_user["bio"]) echo($p_user["bio"]);
// else echo("This is a sample bio, please change me, this is just to test the layout.");
?></p>
2020-05-21 17:19:38 +00:00
<?php
if($is_current_user){
2020-05-30 20:23:04 +00:00
echo("<br/>");
2020-08-16 11:03:05 +00:00
if($fancy_urls){
2020-05-21 20:09:04 +00:00
echo("<a href='/config/profile'>config</a>");
2020-08-16 11:03:05 +00:00
echo(" - ");
2020-08-16 11:04:54 +00:00
echo('<a target="_blank" href="https://twitter.com/share?text=Ask%20me%20something&url=https%3A%2F%2Fask.fai.su%2Fuser%2F' . $p_user["username"] . '&ref_src=twsrc%5Etfw">share on twitter</a>');
2020-08-16 11:03:05 +00:00
}
else{
2020-05-21 20:09:04 +00:00
echo("<a href='/config.php?q=profile'>config</a>");
2020-08-16 11:03:05 +00:00
}
2020-05-21 17:19:38 +00:00
}
?>
2020-05-30 20:23:04 +00:00
</div>
2020-05-20 16:08:25 +00:00
2020-05-30 20:23:04 +00:00
<div class="columns-container">
<div class="column form-column">
2020-05-21 18:06:16 +00:00
<form name="input" action="/action/publish-question.php" method="post">
2020-05-21 21:36:32 +00:00
<textarea placeholder="Ask me anything!" id="post-text" name="post-text"></textarea>
2020-05-20 16:08:25 +00:00
<br/>
2020-05-21 18:06:16 +00:00
<input type="hidden" name="uid" value="<?= $p_user["id"] ?>"/>
2020-05-21 21:36:32 +00:00
<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"; ?>
2020-05-30 20:23:04 +00:00
<input type="submit" value="Ask" name="post-submit"/>
2020-05-20 16:08:25 +00:00
</form>
2020-05-30 20:23:04 +00:00
</div>
<div class="question-container column">
2020-05-20 16:08:25 +00:00
<?php
2020-05-21 09:04:09 +00:00
$u_prep = $db->prepare("SELECT * FROM users WHERE id = :id");
2020-05-30 20:23:04 +00:00
$qs = $db->query("SELECT * FROM questions WHERE user = '" . $p_user["id"] . "' ORDER BY id DESC LIMIT 0, 10;");
$time = new DateTime("@0");
2020-05-20 16:08:25 +00:00
while($current = $qs->fetchArray(SQLITE3_ASSOC)){
// Execute prepared statement
2020-05-21 09:04:09 +00:00
$u_prep->bindValue(":id", $current["by"], SQLITE3_INTEGER);
$q_user = $u_prep->execute()->fetchArray(SQLITE3_ASSOC);
2020-05-30 20:23:04 +00:00
echo("<div class='question'>");
if($q_user["id"] == 0) echo("<p class='question-username'>" . $q_user["name"] ."</p>");
else if($fancy_urls) echo("<p class='question-username'><a href='/user/" . $q_user["name"] . "'>" . $q_user["name"] ."</a></p>\n");
else echo("<p class='question-username'><a href='/user.php?q=" . $q_user["name"] . "'>" . $q_user["name"] ."</a></p>\n");
echo("\t<p class='question-text'>". $current["question"] ."</p>\n");
2020-05-21 20:09:04 +00:00
if($is_current_user){
2020-05-22 00:20:59 +00:00
echo("\t<a href='/action/reply.php?q=".$current["id"]."'>reply</a> ");
2020-05-21 20:09:04 +00:00
echo("\t<a href='/action/delete-question.php?q=".$current["id"]."'>delete</a> ");
echo("fav ignore ");
}
// Time
2020-05-22 00:20:59 +00:00
$time->settimestamp($current["q_date"]);
2020-05-30 20:23:04 +00:00
echo("<p class='question-date'>" . $time->format("y-m-d h:i:s") . "</p>");
2020-05-22 00:20:59 +00:00
if($current["answer"]){
2020-05-30 20:23:04 +00:00
echo("<div class='answer'>");
echo("<p class='answer-text'>" . $current["answer"] . "</p>");
2020-05-22 00:20:59 +00:00
$time->settimestamp($current["a_date"]);
2020-05-30 20:23:04 +00:00
echo("<p class='answer-date'>" . $time->format("y-m-d h:i:s") . "</p>");
echo("</div>");
2020-05-22 00:20:59 +00:00
}
2020-05-21 20:09:04 +00:00
echo("\n\n");
2020-05-30 20:23:04 +00:00
echo("</div>");
2020-05-20 16:08:25 +00:00
}
?>
2020-05-30 20:23:04 +00:00
</div>
</div>
</div>
<div id="footer">
<p>
Powered by Librecat, under the GPL3 license.
Source code: <a href="https://git.posweg.es/posweg/librecat">https://git.posweg.es/posweg/librecat</a>
</p>
</div>
2020-05-20 16:08:25 +00:00
</body>
</html>