Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Warning Notification (Icon).
#26
This user has been denied support. This user has been denied support.
(2012-09-23, 08:32 PM)Omar G. Wrote: <?
	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'] Wink
Yeah, I failed to remember that it does fetch the fid. Smile

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. Smile

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. Smile
Reply


Messages In This Thread
Post Warning Notification (Icon). - by crazy4cs - 2012-09-23, 07:43 AM
RE: Post Warning Notification (Icon). - by Euan T - 2012-09-23, 07:16 PM
RE: Post Warning Notification (Icon). - by Euan T - 2012-09-23, 07:28 PM
RE: Post Warning Notification (Icon). - by Euan T - 2012-09-23, 07:29 PM
RE: Post Warning Notification (Icon). - by Euan T - 2012-09-23, 07:38 PM
RE: Post Warning Notification (Icon). - by Euan T - 2012-09-23, 07:40 PM
RE: Post Warning Notification (Icon). - by Euan T - 2012-09-23, 07:52 PM
RE: Post Warning Notification (Icon). - by Euan T - 2012-09-23, 07:56 PM
RE: Post Warning Notification (Icon). - by Euan T - 2012-09-23, 08:37 PM
RE: Post Warning Notification (Icon). - by Euan T - 2012-09-23, 08:51 PM
RE: Post Warning Notification (Icon). - by iHydra - 2012-09-23, 09:11 PM
RE: Post Warning Notification (Icon). - by crazy4cs - 2012-09-24, 06:06 AM
RE: Post Warning Notification (Icon). - by lexy - 2012-09-28, 08:14 AM
RE: Post Warning Notification (Icon). - by lexy - 2012-09-28, 10:26 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)