From 41e2ffeee0e896a445e5e90af1b07eace13178a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=B2sweg?= Date: Sat, 29 Aug 2020 14:31:09 +0200 Subject: [PATCH] Make page selector and HTML cleanup --- themes/minimalpunk/css/user.css.php | 31 +++++- user.php | 148 ++++++++++++++++++++-------- 2 files changed, 136 insertions(+), 43 deletions(-) diff --git a/themes/minimalpunk/css/user.css.php b/themes/minimalpunk/css/user.css.php index 2d6111c..2c72f62 100644 --- a/themes/minimalpunk/css/user.css.php +++ b/themes/minimalpunk/css/user.css.php @@ -36,7 +36,9 @@ } -/* Form column */ + + /* Form column */ + .form-column{ background-color: ; padding: 10px; @@ -55,7 +57,8 @@ background-color: } -/* Highlighted post (?p=id) */ + + /* Highlighted post (?p=p) */ .highlighted-post{ background-color: ; @@ -88,7 +91,9 @@ color: ; } -/* Questions */ + + /* Questions */ + .question-container{ padding: 10px; background-color: ; @@ -127,7 +132,25 @@ margin-top: 20px; } -/* Footer */ + + /* Page selector */ + +.page-selector{ + text-align: center; + color: ; +} + .ps_item{ + display: inline-block; + } + .ps_item a{ + padding: 5px; + font-weight: bold; + text-decoration: none; + } + + + /* Footer */ + #footer{ padding: 10px; /*background-color: ;*/ diff --git a/user.php b/user.php index 7968ec1..c4c41be 100644 --- a/user.php +++ b/user.php @@ -7,7 +7,7 @@ include("include/settings.php"); $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"]){ +if(!$p_user || $p_user["id"] == 0){ // Test if user exists or if it is the id 0, anonymous include("404.php"); die(); } @@ -27,10 +27,10 @@ if(isset($_SESSION["uid"])){ -
-
-

-

+

+

+

@@ -121,28 +121,28 @@ if(isset($_GET["p"])){ } ?> -
-
-
- -
- "/> -

name="anon"/> Post anonymously

- $errorMsg

\n"; ?> - -
- -
-
- +
+
+ +
+ "/> +

name="anon"/> Post anonymously

+ $errorMsg

\n"; ?> + +
+
+ +
+query('SELECT COUNT(*) FROM questions WHERE user = "' . $p_user["id"] . '";')->fetchArray(SQLITE3_ASSOC)['COUNT(*)']; - // echo $count; + $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 .";"); @@ -158,9 +158,11 @@ if(isset($_GET["p"])){ $u_prep->bindValue(":id", $current["by"], SQLITE3_INTEGER); $q_user = $u_prep->execute()->fetchArray(SQLITE3_ASSOC); - echo("
"); + echo("\t\t\t"); + echo("
\n"); // Question username + echo("\t\t\t\t"); echo("

" ); if($q_user["id"] == 0){ // no link if anonymous echo($q_user["name"]); @@ -172,45 +174,113 @@ if(isset($_GET["p"])){ echo ("/"); else echo(".php?q="); - echo($q_user["name"] . "'>" . $q_user["name"] ."\n"); + echo($q_user["name"] . "'>" . $q_user["name"] .""); } - echo("

"); + echo("

\n"); // Actual text body - echo("\t

". $current["question"] ."

\n"); + echo("\t\t\t\t"); + echo("

". $current["question"] ."

\n"); /* Question footer */ + echo("\t\t\t\t"); echo(''); // Footer + echo("\t\t\t\t"); + echo("
\n"); // Footer /* Answer */ if($current["answer"]){ - echo("
"); - echo("

" . $current["answer"] . "

"); - $time->settimestamp($current["a_date"]); - echo("

" . $time->format("Y-m-d h:i:s") . "

"); - echo("
"); - } - echo("\n\n"); + echo("\t\t\t\t"); + echo("
\n"); - echo("
"); // Question + echo("\t\t\t\t\t"); + echo(nl2br("

" . $current["answer"] . "

\n")); + + $time->settimestamp($current["a_date"]); + echo("\t\t\t\t\t"); + echo("

" . $time->format("Y-m-d h:i:s") . "

\n"); + + echo("\t\t\t\t"); + echo("
\n"); + } + + echo("\t\t\t"); + echo("
\n"); // Question + echo("\n"); } + + + /* PAGE SELECTOR */ + // ps_* means Page Selector + + $p_total = ceil($q_count / $p_limit); + $ps_margin = 2; // Amount of page numbers to show after and before the actual one + + // Limit displayed numbers to the existing ones (bound logic) + if($_GET["page"] - $ps_margin < 1) $ps_init = 1; + else if($_GET["page"] + $ps_margin > $p_total) $ps_init = $p_total - $ps_margin * 2; + else $ps_init = $_GET["page"] - $ps_margin; + + $ps = ""; + $ps .= "
\n"; + + function ps_item($label, $link){ + $ps_item = ""; + + if($link){ + $link_init = ""; + + $label = $link_init . $label . ""; + } + + $ps_item = "\t
" . $label . "
\n"; + + return $ps_item; + } + + // "|<" and "<" + if($ps_init > 1) $ps .= ps_item("|<", 1); + if($_GET["page"] > 1) $ps .= ps_item("<", $_GET["page"] - 1); + + // Numbers + for($i = $ps_init; $i <= $ps_init + $ps_margin * 2 && $i <= $p_total && $p_total != 1; $i++){ + if($i == $_GET["page"]) $ps .= ps_item($i, ""); + else $ps .= ps_item($i, $i); + } + + // ">" and ">|" + if($_GET["page"] < $p_total) $ps .= ps_item(">", $_GET["page"] + 1); + if($ps_init + $ps_margin * 2 < $p_total) $ps .= ps_item(">|",$p_total); + + $ps .= "
\n"; + + echo $ps; ?>