This repository has been archived on 2024-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
mybb-digest/activethreads.php

40 lines
1.3 KiB
PHP
Raw Normal View History

2017-05-04 09:11:59 +03:00
<?php
/**
* Return the latest threads of one forum, where a post has been posted
*
* @param integer $forum_id Forum ID to fetch threads from
* @param integer $limit Amount of threads to get
* @param boolean $excluse_invisible Shall we also get invisible threads?
* @return array
*/
2017-05-04 09:59:49 +03:00
function getLatestActiveThreads($limit = 7, $exclude_invisible = true)
2017-05-04 09:11:59 +03:00
{
2017-05-04 09:59:49 +03:00
global $pdo;
2017-05-04 09:11:59 +03:00
// This will be the array, where we can save the threads
$threads = array();
/**
* If defined forum id is 0, we do not fetch threads from only one forum,
* but we fetch the latest threads of all forums
* Therefore we add the forum_id in the where condition
* We only fetch visible threads, if there is anything we want to hide ;)
* However we can also define that we want the invisible threads as well
*/
2017-05-04 09:59:49 +03:00
$fetch_invisible_threads = intval($exclude_invisible);
2017-05-04 09:11:59 +03:00
// Run the Query
2017-05-04 09:59:49 +03:00
$query = "SELECT `lastpost` FROM `".MYBB_PREFIX."threads`
LEFT JOIN `".MYBB_PREFIX."forums` ON `".MYBB_PREFIX.'forums`.`fid` = `'.MYBB_PREFIX.'threads`.`fid`'."
WHERE `".MYBB_PREFIX."threads`.`visible` = :visible
ORDER BY `".MYBB_PREFIX."threads`.`lastpost` DESC
LIMIT :limit";
$query = $pdo->prepare($query);
$query->execute([
'visible' => $fetch_invisible_threads,
'limit' => intval($limit)
]);
2017-05-04 09:11:59 +03:00
return $query->fetchAll();
}