2020-05-17 00:02:20 +00:00
< ? php
2020-08-27 20:57:05 +00:00
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 );
2020-08-29 12:31:09 +00:00
if ( ! $p_user || $p_user [ " id " ] == 0 ){ // Test if user exists or if it is the id 0, anonymous
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-08-29 12:31:09 +00:00
< div id = " parent-container " >
< div id = " user-container " >
< p id = " user-name " >< ? = $p_user [ " username " ] ?> </p>
< p class = " user-bio " >< ? php
2020-05-30 20:23:04 +00:00
// 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-08-16 15:22:31 +00:00
< ? php
2020-08-27 20:57:05 +00:00
/** QUESTION HIGHLIGHT **/
2020-08-16 15:22:31 +00:00
if ( isset ( $_GET [ " p " ])){
2020-08-27 20:57:05 +00:00
//Get info about the question
2020-08-16 15:22:31 +00:00
$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 );
2020-08-27 20:57:05 +00:00
if ( $p_user [ " id " ] == $h_question [ " user " ]){ // Only show question that are for this user
2020-08-16 15:22:31 +00:00
echo ( '<div class="highlighted-post">' );
echo ( '<div class="question-body">' );
$time = new DateTime ( " @0 " );
2020-08-27 20:57:05 +00:00
// Title
2020-08-16 15:22:31 +00:00
echo ( " <p class='question-username'> " );
2020-08-27 20:57:05 +00:00
if ( $h_user [ " id " ] == 0 ){ // no link if anonymous
2020-08-16 15:22:31 +00:00
echo ( $h_user [ " name " ]);
}
else {
2020-08-27 20:57:05 +00:00
echo ( " <a href='/user " );
if ( $fancy_urls )
echo ( " / " );
else
echo ( " .php?q= " );
echo ( $h_user [ " name " ] . " '> " . $h_user [ " name " ] . " </a> \n " );
2020-08-16 15:22:31 +00:00
}
echo ( " asked:</p> " );
2020-08-27 20:57:05 +00:00
// Actual question text
2020-08-16 15:22:31 +00:00
echo ( " \t <p class='question-text'> " . $h_question [ " question " ] . " </p> \n " );
2020-08-27 20:57:05 +00:00
// Footer
2020-08-16 15:22:31 +00:00
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> " );
echo ( " fav ignore " );
}
2020-08-27 20:57:05 +00:00
// Time
2020-08-16 15:22:31 +00:00
$time -> settimestamp ( $h_question [ " q_date " ]);
echo ( '<p class="question-date">' );
echo ( '<a href="?p=' . $h_question [ " id " ] . '">' . $time -> format ( 'Y-m-d h:i:s' ) . '</a>' );
echo ( '</p>' );
echo ( '</div>' ); // question-body
2020-08-27 20:57:05 +00:00
/* Answer */
2020-08-16 15:22:31 +00:00
if ( $h_question [ " answer " ]){
echo ( " <div class='answer'> " );
echo ( '<p class="title">' . $p_user [ " name " ] . ' answered:' );
2020-08-27 20:57:05 +00:00
2020-08-16 15:22:31 +00:00
echo ( " <p class='answer-text'> " . $h_question [ " answer " ] . " </p> " );
2020-08-27 20:57:05 +00:00
2020-08-16 15:22:31 +00:00
$time -> settimestamp ( $h_question [ " a_date " ]);
echo ( " <p class='answer-date'> " . $time -> format ( " Y-m-d h:i:s " ) . " </p> " );
echo ( " </div> " );
}
2020-08-27 20:57:05 +00:00
echo ( '</div>' ); // highlighted-post
2020-08-16 15:22:31 +00:00
}
}
?>
2020-05-20 16:08:25 +00:00
2020-08-29 12:31:09 +00:00
< div class = " columns-container " >
< div class = " column form-column " >
< 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 " value = " Ask " name = " post-submit " />
</ form >
</ div >
< div class = " question-container column " >
< ? php
if ( ! $_GET [ " page " ]) $_GET [ " page " ] = 1 ;
2020-08-27 20:57:05 +00:00
$p_limit = 10 ; // TODO: Make the limit variable
2020-08-29 12:31:09 +00:00
$p_offset = ( $_GET [ 'page' ] - 1 ) * $p_limit ; // SQLite3 unsertands offsets in units, not pages
2020-08-27 20:57:05 +00:00
if ( ! $p_offset || $p_offset <= 0 ) $p_offset = 0 ;
// TODO: Build a mechanism to make off-limits pages show as the last one
2020-08-29 12:31:09 +00:00
$q_count = $db -> query ( 'SELECT COUNT(*) FROM questions WHERE user = "' . $p_user [ " id " ] . '";' ) -> fetchArray ( SQLITE3_ASSOC )[ 'COUNT(*)' ];
2020-08-27 20:57:05 +00:00
2020-05-21 09:04:09 +00:00
$u_prep = $db -> prepare ( " SELECT * FROM users WHERE id = :id " );
2020-08-27 20:57:05 +00:00
$qs = $db -> query ( " SELECT * FROM questions WHERE user = ' " . $p_user [ " id " ] . " ' ORDER BY id DESC LIMIT " . $p_limit . " OFFSET " . $p_offset . " ; " );
/** QUESTIONS MAIN LOOP **/
2020-05-21 11:57:27 +00:00
$time = new DateTime ( " @0 " );
2020-05-20 16:08:25 +00:00
while ( $current = $qs -> fetchArray ( SQLITE3_ASSOC )){
2020-08-27 20:57:05 +00:00
// 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-21 11:57:27 +00:00
2020-08-29 12:31:09 +00:00
echo ( " \t \t \t " );
echo ( " <div class='question'> \n " );
2020-08-27 20:57:05 +00:00
// Question username
2020-08-29 12:31:09 +00:00
echo ( " \t \t \t \t " );
2020-08-27 20:57:05 +00:00
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= " );
2020-08-29 12:31:09 +00:00
echo ( $q_user [ " name " ] . " '> " . $q_user [ " name " ] . " </a> " );
2020-08-27 20:57:05 +00:00
}
2020-08-29 12:31:09 +00:00
echo ( " </p> \n " );
2020-08-27 20:57:05 +00:00
// Actual text body
2020-08-29 12:31:09 +00:00
echo ( " \t \t \t \t " );
echo ( " <p class='question-text'> " . $current [ " question " ] . " </p> \n " );
2020-05-21 20:09:04 +00:00
2020-08-27 20:57:05 +00:00
/* Question footer */
2020-08-29 12:31:09 +00:00
echo ( " \t \t \t \t " );
2020-08-16 15:22:31 +00:00
echo ( '<div class="question-footer">' );
2020-08-29 12:31:09 +00:00
echo ( " \n " );
2020-08-27 20:57:05 +00:00
// Actions
2020-05-21 20:09:04 +00:00
if ( $is_current_user ){
2020-08-29 12:31:09 +00:00
echo ( " \t \t \t \t \t " );
echo ( " <a href='/action/reply.php?q= " . $current [ " id " ] . " '>reply</a> \n " );
echo ( " \t \t \t \t \t " );
echo ( " <a href='/action/delete-question.php?q= " . $current [ " id " ] . " '>delete</a> \n " );
echo ( " \t \t \t \t \t " );
echo ( " fav \n " );
2020-05-21 20:09:04 +00:00
}
2020-08-27 20:57:05 +00:00
// Time
2020-05-22 00:20:59 +00:00
$time -> settimestamp ( $current [ " q_date " ]);
2020-08-29 12:31:09 +00:00
echo ( " \t \t \t \t \t " );
2020-08-16 11:20:18 +00:00
echo ( '<a href="?p=' . $current [ " id " ] . '">' );
echo ( " <p class='question-date'> " . $time -> format ( " Y-m-d h:i:s " ) . " </p> " );
2020-08-29 12:31:09 +00:00
echo ( " </a> \n " );
2020-08-27 20:57:05 +00:00
2020-08-29 12:31:09 +00:00
echo ( " \t \t \t \t " );
echo ( " </div> \n " ); // Footer
2020-08-27 20:57:05 +00:00
/* Answer */
2020-05-22 00:20:59 +00:00
if ( $current [ " answer " ]){
2020-08-29 12:31:09 +00:00
echo ( " \t \t \t \t " );
echo ( " <div class='answer'> \n " );
echo ( " \t \t \t \t \t " );
echo ( nl2br ( " <p class='answer-text'> " . $current [ " answer " ] . " </p> \n " ));
2020-05-22 00:20:59 +00:00
$time -> settimestamp ( $current [ " a_date " ]);
2020-08-29 12:31:09 +00:00
echo ( " \t \t \t \t \t " );
echo ( " <p class='answer-date'> " . $time -> format ( " Y-m-d h:i:s " ) . " </p> \n " );
echo ( " \t \t \t \t " );
echo ( " </div> \n " );
}
echo ( " \t \t \t " );
echo ( " </div> \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 .= " <div class='page-selector'> \n " ;
function ps_item ( $label , $link ){
$ps_item = " " ;
if ( $link ){
$link_init = " <a href='/user " ;
if ( $fancy_urls )
$link_init .= " / " . $_GET [ " q " ] . " ? " ;
else
$link_init .= " .php?q= " . $_GET [ " q " ] . " & " ;
$link_init = $link_init . " page= " . $link . " '> " ;
$label = $link_init . $label . " </a> " ;
2020-05-22 00:20:59 +00:00
}
2020-05-30 20:23:04 +00:00
2020-08-29 12:31:09 +00:00
$ps_item = " \t <div class='ps_item'> " . $label . " </div> \n " ;
return $ps_item ;
2020-05-20 16:08:25 +00:00
}
2020-08-29 12:31:09 +00:00
// "|<" 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 .= " </div> \n " ;
echo $ps ;
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 >