Userpage when logged in now working

Favorite list and pastes on userpage fixed.
This commit is contained in:
aftercase 2021-07-24 23:58:16 +01:00
parent c59e2e747b
commit cd4bb33439
3 changed files with 18 additions and 16 deletions

View file

@ -13,9 +13,9 @@
* GNU General Public License in GPL.txt for more details.
*/
function getUserFavs(DatabaseHandle $conn, string $user_id) : array {
function getUserFavs(DatabaseHandle $conn, int $user_id) : array {
$query = $conn->prepare(
"SELECT pins.f_time, pastes.id, pastes.title, pastes.created_at, pastes.tagsys
"SELECT pins.f_time, pastes.id, pins.paste_id, pastes.title, pastes.created_at, pastes.tagsys, pastes.updated_at
FROM pins
INNER JOIN pastes ON pastes.id = pins.paste_id
WHERE pins.user_id = ?");
@ -28,9 +28,9 @@ function checkFavorite(DatabaseHandle $conn, int $paste_id, int $user_id) : stri
$query->execute([$user_id, $paste_id]);
if ($query->fetch()) {
return "<a href='#' id='favorite' class='iconn tool-iconn' data-fid='" . $paste_id . "'><i class='far fa-star fa-lg has-text-grey' title='Favourite'></i></a>";
return "<a href='#' id='favorite' class='icon tool-icon' data-fid='" . $paste_id . "'><i class='fas fa-star fa-lg has-text-grey' title='Favourite'></i></a>";
} else {
return "<a href='#' id='favorite' class='iconn tool-iconn' data-fid='" . $paste_id . "'><i class='fas fa-star fa-lg has-text-grey' title='Favourite'></i></a>";
return "<a href='#' id='favorite' class='icon tool-icon' data-fid='" . $paste_id . "'><i class='far fa-star fa-lg has-text-grey' title='Favourite'></i></a>";
}
}

View file

@ -226,7 +226,7 @@ $protocol = paste_protocol();
<td>
<a href="' . $protocol . $baseurl . '/' . $p_link . '" title="' . $title . '">' . ($title) . '</a>
</td>
<td data-sort="' . $p_date . '" class="td-center">
<td data-sort="' . $p_date->format('U') . '" class="td-center">
<span>' . $p_dateui . '</span>
</td>
<td class="td-center">
@ -264,21 +264,22 @@ $protocol = paste_protocol();
</thead>
<tbody>
<?php
$res = getUserFavs($conn, $profile_username);
foreach ($res as $index => $row) {
foreach ($profile_favs as $index => $row) {
$ftitle = Trim($row['title']);
$f_id = Trim($row['f_paste']);
$f_date = Trim($row['f_time']);
$Recent_update = Trim($row['now_time']);
$f_id = Trim($row['paste_id']);
$f_date = new DateTime($row['f_time']);
$f_dateui = $f_date->format("d F Y");
$Recent_update = new DateTime($row['updated_at']);
$Recent_update_u = date_format($Recent_update,'U');
$f_tags = Trim($row['tagsys']);
$ftagArray = explode(',', $f_tags);
$ftagArray = array_filter($ftagArray);
$p_link = ($mod_rewrite == '1') ? "$f_id" : "paste.php?favdel=$fu_id";
$f_delete_link = ($mod_rewrite == '1') ? "user.php?favdel&user=$profile_username&fid=$fu_id" : "user.php?favdel&user=$profile_username&fid=$fu_id";
//$p_link = ($mod_rewrite == '1') ? "$f_id" : "paste.php?favdel=$fu_id";
//$f_delete_link = ($mod_rewrite == '1') ? "user.php?favdel&user=$profile_username&fid=$f_id" : "user.php?favdel&user=$profile_username&fid=$f_id";
$title = truncate($title, 20, 50);
$current_time = time();
$past = strtotime('-2 day', $current_time);
if ($past <= $Recent_update && $Recent_update <= $current_time) {
if ($past <= $Recent_update_u && $Recent_update_u <= $current_time) {
$updatenote = "<i class='far fa-check-square fa-lg' aria-hidden='true'></i>";
} else {
$updatenote = "<i class='far fa-minus-square fa-lg' aria-hidden='true'></i>";
@ -288,11 +289,11 @@ $protocol = paste_protocol();
<td>
<a href="' . $protocol . $baseurl . '/' . $p_link . '" title="' . $ftitle . '">' . ($ftitle) . '</a>
</td>
<td data-sort="' . $f_date . '" class="td-left">
<span>' . date("d F Y", $f_date) . '</span>
<td data-sort="' . $f_dateui . '" class="td-left">
<span>' . date_format($f_date,'U') . '</span>
</td>
<td class="td-center">
<span style="display:none;">' . $Recent_update . '</span>
<span style="display:none;">' . $Recent_update_u . '</span>
' . $updatenote . '
</td>
<td class="td-left">';

View file

@ -90,6 +90,7 @@ $profile_total_paste_views = intval($query->fetch(PDO::FETCH_NUM)[0]);
$profile_join_date = $profile_info['date'];
$profile_pastes = getUserPastes($conn, $profile_info['id']);
$profile_favs = getUserFavs($conn, $profile_info['id']);
$is_current_user = ($current_user !== null) && ($profile_info['id'] == $current_user->user_id);
updatePageViews($conn);