2012-09-24, 06:06 AM
This user has been denied support.
(2012-09-23, 08:32 PM)Omar G. Wrote: <?Yeah, I failed to remember that it does fetch the fid.
static $pwn_cache = null; if(!isset($pwn_cache)) { $pwn_cache = array(); $where = ''; if(THIS_SCRIPT == 'showthread.php' && $GLOBALS['pids']) { $where = $GLOBALS['pids']; } elseif(THIS_SCRIPT == 'editpost.php') { $where = "pid='{$post['pid']}' AND uid='{$post['uid']}'"; } else { //remove hook and return } $query = $db->simple_select('warnings', 'pid, uid', $GLOBALS['pids']); while($warn = $db->fetch_field($query)) { $pwn_cache[$warn['pid']] = $warn['uid']; } } if(isset($pwn_cache[$post['pid']]) && $pwn_cache[$post['pid']] == $post['uid']) { // so something }
Also, you don't need to get the thread to know the fid, just use $post['fid']
Omar, the above code of yours had some problem, like in below query when you're fetching as a field:
while($warn = $db->fetch_field($query))
I was presented with missing argument for mysqli fetch function, tried a way around but didn't got anything to work. So, I instead fetched it as an array:
while($warn = $db->fetch_array($query))
and that works great. Just wanted to confirm if I can fetch it & store as an array?
And yeah, the function now works correct. The cache is working on the spot, and now am running 9 less queries, which means only 1 on postbit.
Am not good with cache yet, haha, so thanks for the help.
Here's how the current function looks:
function pwn(&$post)
{
global $mybb, $db, $pids;
$post['pwn'] = '';
$fid = $post['fid'];
static $pwn_cache = null;
if(!isset($pwn_cache))
{
$pwn_cache = array();
$where = '';
if(THIS_SCRIPT == 'showthread.php' && $GLOBALS['pids'])
{
$where = $GLOBALS['pids'];
}
elseif(THIS_SCRIPT == 'editpost.php')
{
$where = "pid='{$post['pid']}' AND uid='{$post['uid']}'";
}
else
{
//remove hook and return
}
$query = $db->simple_select('warnings', 'pid, uid, expired', $GLOBALS['pids']);
while($warn = $db->fetch_array($query))
{
$pwn_cache[$warn['pid']] = $warn['uid'];
}
}
if(isset($pwn_cache[$post['pid']]) && $pwn_cache[$warn['expired']] == 0 && $pwn_cache[$post['pid']] == $post['uid'] && is_moderator($fid))
{
$warning_title = "This user is currently warned for this post.";
$post['pwn'] = '
<img src="images/pwn.png" title="'.$warning_title.'" />
';
}
}
Let me know if it's good and if so, I shall submit an updated version.