Created
July 13, 2017 15:56
-
-
Save tommm/874ac136e8d04faa9c3da0e68e046a8e to your computer and use it in GitHub Desktop.
MyBB: Get unique UIDS from posts on a specific page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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