Cleanup "/user.php"
This commit is contained in:
parent
82c840ce4a
commit
890a24dcd2
82
user.php
82
user.php
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
include("include/settings.php");
|
||||
|
@ -49,11 +50,16 @@ if(isset($_SESSION["uid"])){
|
|||
</div>
|
||||
<?php
|
||||
|
||||
|
||||
/** QUESTION HIGHLIGHT **/
|
||||
|
||||
if(isset($_GET["p"])){
|
||||
|
||||
//Get info about the question
|
||||
$h_question = $db->query("SELECT * FROM questions WHERE id = " . $_GET["p"] . ";")->fetchArray(SQLITE3_ASSOC);
|
||||
$h_user = $db->query("SELECT * FROM users WHERE id = " . $h_question["by"] . ";")->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if($p_user["id"] == $h_question["user"]){
|
||||
if($p_user["id"] == $h_question["user"]){ // Only show question that are for this user
|
||||
|
||||
echo('<div class="highlighted-post">');
|
||||
|
||||
|
@ -61,20 +67,26 @@ if(isset($_GET["p"])){
|
|||
|
||||
$time = new DateTime("@0");
|
||||
|
||||
// Title
|
||||
echo("<p class='question-username'>");
|
||||
if($h_user["id"] == 0){
|
||||
if($h_user["id"] == 0){ // no link if anonymous
|
||||
echo($h_user["name"]);
|
||||
}
|
||||
else if($fancy_urls){
|
||||
echo("<a href='/user/" . $h_user["name"] . "'>" . $h_user["name"] ."</a>");
|
||||
}
|
||||
else{
|
||||
echo("<a href='/user.php?q=" . $h_user["name"] . "'>" . $h_user["name"] ."</a>");
|
||||
echo("<a href='/user");
|
||||
|
||||
if($fancy_urls)
|
||||
echo ("/");
|
||||
else
|
||||
echo(".php?q=");
|
||||
echo($h_user["name"] . "'>" . $h_user["name"] ."</a>\n");
|
||||
}
|
||||
echo(" asked:</p>");
|
||||
|
||||
// Actual question text
|
||||
echo("\t<p class='question-text'>". $h_question["question"] ."</p>\n");
|
||||
|
||||
// Footer
|
||||
if($is_h_question_user){
|
||||
echo("\t<a href='/action/reply.php?q=".$h_question["id"]."'>reply</a> ");
|
||||
echo("\t<a href='/action/delete-question.php?q=".$h_question["id"]."'>delete</a> ");
|
||||
|
@ -89,17 +101,22 @@ if(isset($_GET["p"])){
|
|||
|
||||
echo('</div>'); // question-body
|
||||
|
||||
|
||||
/* Answer */
|
||||
|
||||
if($h_question["answer"]){
|
||||
echo("<div class='answer'>");
|
||||
echo('<p class="title">' . $p_user["name"] . ' answered:');
|
||||
|
||||
echo("<p class='answer-text'>" . $h_question["answer"] . "</p>");
|
||||
|
||||
$time->settimestamp($h_question["a_date"]);
|
||||
echo("<p class='answer-date'>" . $time->format("Y-m-d h:i:s") . "</p>");
|
||||
echo("</div>");
|
||||
}
|
||||
|
||||
echo("\n\n");
|
||||
echo('</div>');
|
||||
|
||||
echo('</div>'); // highlighted-post
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -118,35 +135,70 @@ if(isset($_GET["p"])){
|
|||
</div>
|
||||
<div class="question-container column">
|
||||
<?php
|
||||
$p_limit = 10; // TODO: Make the limit variable
|
||||
$p_offset = $_GET['page'] * $p_limit; // SQLite3 unsertands offsets in units, not pages
|
||||
|
||||
if(!$p_offset || $p_offset <= 0) $p_offset = 0;
|
||||
// TODO: Build a mechanism to make off-limits pages show as the last one
|
||||
|
||||
$count = $db->query('SELECT COUNT(*) FROM questions WHERE user = "' . $p_user["id"] . '";')->fetchArray(SQLITE3_ASSOC)['COUNT(*)'];
|
||||
// echo $count;
|
||||
|
||||
$u_prep = $db->prepare("SELECT * FROM users WHERE id = :id");
|
||||
$qs = $db->query("SELECT * FROM questions WHERE user = '" . $p_user["id"] . "' ORDER BY id DESC LIMIT 0, 10;");
|
||||
$qs = $db->query("SELECT * FROM questions WHERE user = '". $p_user["id"] ."' ORDER BY id DESC LIMIT ". $p_limit ." OFFSET ". $p_offset .";");
|
||||
|
||||
|
||||
/** QUESTIONS MAIN LOOP **/
|
||||
|
||||
|
||||
$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);
|
||||
|
||||
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");
|
||||
// Question username
|
||||
echo("<p class='question-username'>" );
|
||||
if($q_user["id"] == 0){ // no link if anonymous
|
||||
echo($q_user["name"]);
|
||||
}
|
||||
else{
|
||||
echo("<a href='/user");
|
||||
|
||||
if($fancy_urls)
|
||||
echo ("/");
|
||||
else
|
||||
echo(".php?q=");
|
||||
echo($q_user["name"] . "'>" . $q_user["name"] ."</a>\n");
|
||||
}
|
||||
echo("</p>");
|
||||
|
||||
// Actual text body
|
||||
echo("\t<p class='question-text'>". $current["question"] ."</p>\n");
|
||||
|
||||
|
||||
/* Question footer */
|
||||
|
||||
echo('<div class="question-footer">');
|
||||
// Actions
|
||||
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('<a href="?p=' . $current["id"] . '">');
|
||||
echo("<p class='question-date'>" . $time->format("Y-m-d h:i:s") . "</p>");
|
||||
echo("</a>");
|
||||
echo('</div>');
|
||||
|
||||
echo('</div>'); // Footer
|
||||
|
||||
|
||||
/* Answer */
|
||||
|
||||
if($current["answer"]){
|
||||
echo("<div class='answer'>");
|
||||
|
@ -157,7 +209,7 @@ if(isset($_GET["p"])){
|
|||
}
|
||||
echo("\n\n");
|
||||
|
||||
echo("</div>");
|
||||
echo("</div>"); // Question
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue