Show "(private)" if question is private for clarity

This commit is contained in:
posweg 2020-09-01 10:40:22 +00:00
parent c524836faf
commit 036b8fcc80
5 changed files with 25 additions and 4 deletions

View File

@ -18,11 +18,13 @@ if(isset($_POST["post-submit"])){
$u = $p_user["id"];
$by = 0;
$question = htmlspecialchars($_POST["post-text"], ENT_QUOTES);
$priv = 0;
if(isset($_SESSION["uid"]) && !$_POST["anon"]) $by = $_SESSION["uid"];
if($_POST["priv"]) $priv = 1;
// Insert user into DB
$db->exec("INSERT INTO questions(user,by,question,q_date) VALUES ('$u','$by','$question',". strtotime('now') .");");
$db->exec("INSERT INTO questions(user,by,question,q_date,private) VALUES ('$u','$by','$question',". strtotime('now') .",$priv);");
unset($_POST["post-text"]);
if($fancy_urls) header("Location: /user/" . $p_user["username"]);
else header("Location: /user.php?q=" . $p_user["username"]);

View File

@ -63,7 +63,7 @@ else{
// echo strlen($tweet) . " - " . strlen($question["answer"]) . "<br/><br/>\n";
// echo $tweet;
if($user["tw_oauth_token"] && $user["tw_oauth_verify"]){
if($user["tw_oauth_token"] && $user["tw_oauth_verify"] && $question['private'] != 1){
include("../include/tw-post.php");
post_tweet(htmlspecialchars_decode($tweet, ENT_QUOTES));
}

View File

@ -24,7 +24,8 @@ $db->exec("CREATE TABLE IF NOT EXISTS questions(
q_date INTEGER,
answer TEXT,
a_date INTEGER,
status INTEGER
status INTEGER,
private INTEGER
);");
if(!$db->querySingle("SELECT EXISTS(SELECT * FROM users where id = 0);")){

View File

@ -122,6 +122,12 @@
color: white;
}
.question-private{
font-size: 15px;
font-weight: normal;
color: <?= $color_4 ?>
}
.answer{
clear: both;
padding: 10px;

View File

@ -123,6 +123,7 @@ if(isset($_GET["p"])){
<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>
<p><input type="checkbox" name="priv"/> Private</p>
<?php if(isset($errorMsg)) echo "<p>$errorMsg</p>\n"; ?>
<input type="submit" value="Ask" name="post-submit"/>
</form>
@ -136,11 +137,17 @@ if(isset($_GET["p"])){
if(!$p_offset || $p_offset <= 0) $p_offset = 0;
// TODO: Build a mechanism to make off-limits pages show as the last one
$private_filter = "";
if(!$is_current_user) $private_filter = "AND private IS NOT 1 AND answer IS NOT NULL";
$q_count = $db->query('SELECT COUNT(*) FROM questions WHERE user = "' . $p_user["id"] . '";')->fetchArray(SQLITE3_ASSOC)['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 ". $p_limit ." OFFSET ". $p_offset .";");
$qs = $db->query("SELECT * FROM questions WHERE user = '". $p_user["id"] . "' " . $private_filter . " ORDER BY id DESC LIMIT ". $p_limit ." OFFSET ". $p_offset .";");
/** QUESTIONS MAIN LOOP **/
@ -167,8 +174,13 @@ if(isset($_GET["p"])){
$new_get["q"] = $q_user["name"];
echo("<a href='" . redirect("user", $new_get) . "'>" . $q_user["name"] ."</a>");
}
if($current["private"] == 1){
echo(" ");
echo("<span class='question-private'>(private)</span>");
}
echo("</p>\n");
// Actual text body
echo("\t\t\t\t");
echo("<p class='question-text'>". $current["question"] ."</p>\n");