From 51fa26797951090aa788fbe8cb38909a27c8b923 Mon Sep 17 00:00:00 2001 From: M3M0RYK1TT3N <99609279+M3M0RYK1TT3N@users.noreply.github.com> Date: Thu, 17 Mar 2022 14:03:06 -0400 Subject: [PATCH] Create recent_threads.php recent thread function --- recent_threads.php | 150 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 recent_threads.php diff --git a/recent_threads.php b/recent_threads.php new file mode 100644 index 000000000..bd8ad95da --- /dev/null +++ b/recent_threads.php @@ -0,0 +1,150 @@ +diff($ago); + + $diff->w = floor($diff->d / 7); + $diff->d -= $diff->w * 7; + + $string = array( + 'y' => 'year', + 'm' => 'month', + 'w' => 'week', + 'd' => 'day', + 'h' => 'hour', + 'i' => 'minute', + 's' => 'second', + ); + foreach ($string as $k => &$v) { + if ($diff->$k) { + $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : ''); + } else { + unset($string[$k]); + } + } + + if (!$full) $string = array_slice($string, 0, 1); + return $string ? implode(', ', $string) . ' ago' : 'just now'; +} + +function shortenText($text, $maxlength = 70, $appendix = "...") +{ + if (mb_strlen($text) <= $maxlength) { + return $text; + } + $text = mb_substr($text, 0, $maxlength - mb_strlen($appendix)); + $text .= $appendix; + return $text; +} + +$RT_boards = listBoards(TRUE, TRUE); +$RT_board_tables = array(); +$RT_threads = array(); +$RT_sort_threads = array(); +$RT_posts = array(); +foreach ($RT_boards as &$board) { + $query = sprintf("SELECT ``id`` AS 'id', ``subject`` as 'title', ``body_nomarkup`` as 'content', ``bump`` as 'time' FROM ``posts_%s`` WHERE ``thread`` IS NULL ORDER BY ``bump`` DESC LIMIT 1", $board); + //echo $query; + $threadQuery = prepare($query); + $threadQuery->execute() or error(db_error($threadQuery)); + $threadResult = $threadQuery->fetchAll(PDO::FETCH_ASSOC); + //print_r($threadResult); + foreach ($threadResult as &$thread) { + if (isset($thread['id'])) { + $query = sprintf("SELECT COUNT(*) AS 'reply_count' FROM ``posts_%s`` WHERE ``thread`` = %s", $board, $thread['id']); + //echo $query; + $threadQuery = prepare($query); + $threadQuery->execute() or error(db_error($threadQuery)); + $threadResult = $threadQuery->fetchAll(PDO::FETCH_ASSOC)[0]; + //print_r($threadResult); + + + + //echo $thread['id'] . " - " . $thread['title'] . "\n"; + $RT_threads[$board] = array( + 'id'=>$thread['id'], + 'title'=>$thread['title'], + 'content'=>$thread['content'], + 'time'=>$thread['time'], + 'replies'=>$threadResult['reply_count'], + 'board'=>$board, + ); + } + } +} + +usort($RT_threads, function($a, $b) { + return $a['time'] - $b['time']; +}); + +$RT_threads = array_reverse($RT_threads); + +$RT_HTML = ' +
| Recent Threads | +Board | +Replies | +Last Post | +
|---|---|---|---|
| + + | ++ + | +
+ '.$thread_replies.' + |
+
+ '.time_elapsed_string('@'.$thread_time).' + |
+