Paretje Wrote:ZiNga BuRgA Wrote:Yeah, MyBB's Who's Online list isn't exactly great for plugins...
Indeed, but I thanks MyBB that they did what I asked a long time ago: first the language, then the hook (global.php).
They fixed that? O_O
I should make my plugin take advantage of that then. Thanks a lot for the tip!
It was possible to load the language twice, however, I'm sure you're aware of the extra unnecessary overhead
Paretje Wrote:When you use 1.2.10, you must to change admin/usergroups.php (yesno code, because the hook is before the yesno codes etc. ) and online.php (because there is only one hook at the start and one at the end of the file )
You can hook before the yesno codes, and copy all the code that MyBB users. Then use exit; to escape executing MyBB's code. It's "dirty" in the fact that you have to duplicate a whole heap of code, however, it's a method of getting around the issue. The problem with this is, that it won't work well with multiple plugins doing the same thing (which is why it's "dirty"
).
As for Who's Online, here's the code MyPlaza uses:
$plugins->add_hook('online_user', 'myplaza_wol_users', 10);
function myplaza_wol_users()
{
global $user, $doneusers, $forums, $myplaza_wol_users, $plugins;
$p = my_strpos($user['location'], '/plaza.php');
if(!$p) return;
$params = my_substr($user['location'], $p+10);
if(my_strlen($params) > 1)
{
$params = explode('&', my_substr($params, 1));
foreach($params as $param)
{
$temp = explode('=', $param);
$parameters[$temp[0]] = $temp[1];
}
}
$user['params'] = $parameters;
$plugins->run_hooks('myplaza_wol_process');
$myplaza_wol_users[] = $user;
// dunno if it's quicker to use a static variable to count the users.... meh
$placeholder = 'myplaza_'.count($myplaza_wol_users);
// now that we have all the data, we'll have to do some forging to bypass MyBB's WOL restrictions :S
// we'll forge the location to announcements
$user['location'] = 'forged_request/announcements.php?fid='.$placeholder;
$forums[$placeholder] = $placeholder;
}
$plugins->add_hook('online_end', 'myplaza_wol_end', 100);
function myplaza_wol_end()
{
global $lang, $forums, $myplaza_wol_users, $onlinerows, $user, $plugins;
if(!isset($myplaza_wol_users) || empty($myplaza_wol_users)) return;
$lang->load('myplaza');
$finds = array();
$replaces = array();
$i=1;
//for($i=1; $i<=count($myplaza_wol_params); $i++)
foreach($myplaza_wol_users as $key => $user)
{
$finds[] = sprintf($lang->viewing_announcements, 'myplaza_'.$i, 'myplaza_'.$i);
$replacement = '';
if(isset($user['params']['action']))
{
if($user['params']['action'] == 'stats')
$replacement = $lang->myplaza_wol_stats;
if($user['params']['action'] == 'history')
$replacement = $lang->myplaza_wol_history;
if($user['params']['action'] == 'do_buy')
$replacement = $lang->myplaza_wol_buying;
}
else
$replacement = $lang->myplaza_wol_plaza;
$plugins->run_hooks_by_ref('myplaza_wol', $replacement);
if(!$replacement) $replacement = sprintf($lang->myplaza_wol_unknown, $user['location']);
$replaces[] = $replacement;
$i++;
}
$onlinerows = str_replace($finds, $replaces, $onlinerows);
}
Yeah, just please use a different prefix for $placeholder
I plan to make some other plugins using the above trick.
Paretje Wrote:In 1.2, maybe it's the first choice. But maybe it's already fixed in MyBB 1.4 ...
Yeah, I'd really like to see "_code" hooks at the end, before endform() in the MyBB 1.4 AdminCP - would make plugin development a lot easier, and work better for users too
Still, a great plugin