Skip to content

Instantly share code, notes, and snippets.

@tommm
Created July 13, 2017 15:56
Show Gist options
  • Save tommm/874ac136e8d04faa9c3da0e68e046a8e to your computer and use it in GitHub Desktop.
Save tommm/874ac136e8d04faa9c3da0e68e046a8e to your computer and use it in GitHub Desktop.
MyBB: Get unique UIDS from posts on a specific page
$plugins->add_hook('showthread_start', 'plugin_showthread_start');
$plugins->add_hook('showthread_end', 'plugin_showthread_end');
$plugins->add_hook('postbit', 'plugin_postbit');
function plugin_showthread_start()
{
global $unique_uids;
$unique_uids = [];
// Other showthread_start code
}
function plugin_showthread_end()
{
global $db, $unique_uids;
if (empty($unique_uids)) {
return;
}
// Do something with the unique users who have posts on this page
$users = implode(',', array_map('intval', $unique_uids));
$query = $db->simple_select('users', 'uid, username', "uid IN ({$users})");
while($user = $db->fetch_array($query))
{
// ['uid', 'username']
// Alternatively, store user data alongside UID in $unique_uids
}
}
function plugin_postbit($post)
{
global $unique_uids;
if ($post['uid'] && !in_array($post['uid'], $unique_uids)) {
$unique_uids[] = $post['uid'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment