MyBB Community Forums

Full Version: Post Warning Notification (Icon).
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
(2012-09-23, 07:28 PM)euantor Wrote: [ -> ]Ok, take a peak at this: http://euantor.com/4-reducing-mybb-plugi...he-postbit

It should help you cut the query count to just one if you do it right. Also, why are you looking up the uid from the user's table? Just use $post['uid'] unless I'm missing something by skim reading on my phone.
Looking at it, thanks.

(2012-09-23, 07:29 PM)euantor Wrote: [ -> ]Also, why are you running get_forum within a loop? I'm sure it runs a query too...
Nope, just tried to avoid any confusion, runs the same amount of queries.
You may just use the pid of the post. No need to use uid either. With this, your query would look like this;

		$pid = intval($post['pid']);
		$query = $db->simple_select("warnings", "*", "pid='{$pid}' AND expired='0'");
		$check = $db->fetch_array($query);

Now use $check['pid'] to check if its true then show the icon and if its false removes icon.
Hope it helps Smile I haven't used the get_forum function before so i've never really looked into it. Thinking about it, forums are cached so it likely just reads the cache.
Building on yaldaram post above, it would probably work without checking the db structure but there's no point fetching everything or using fetch_array when you could probably limit it to 1 result and fetch the warning ID with fetch_column.
Oh, I actually copied it from my plugin. I'm actually fetching these because I'm using few variables on postbit. An screenshot of plugin that I just created for Rocketfoot;

http://yaldaram.com/attachment.php?aid=1397
(2012-09-23, 07:37 PM)Yaldaram Wrote: [ -> ]You may just use the pid of the post. No need to use uid either. With this, your query would look like this;

		$pid = intval($post['pid']);
		$query = $db->simple_select("warnings", "*", "pid='{$pid}' AND expired='0'");
		$check = $db->fetch_array($query);

Now use $check['pid'] to check if its true then show the icon and if its false removes icon.
That's nice, but runs the same amount of queries. Yes, uid isn't needed, I shall remove it in update, thanks.

(2012-09-23, 07:38 PM)euantor Wrote: [ -> ]Hope it helps Smile I haven't used the get_forum function before so i've never really looked into it. Thinking about it, forums are cached so it likely just reads the cache.
I tried, but failed somehow and was presented with MySQL error, though I tried other way and that worked.

I defined $pids as global function and this is my query:

$query = $db->query("
                SELECT u.uid
                FROM ".TABLE_PREFIX."users u
                JOIN ".TABLE_PREFIX."posts p ON (u.uid=p.uid) WHERE p.{$pids}
				JOIN ".TABLE_PREFIX."warnings uw ON (uw.pid=p.pid)
                WHERE uw.expired='0' 
            ");

which throws error, but if instead I add p.{$pids} in end, like:

$query = $db->query("
                SELECT u.uid
                FROM ".TABLE_PREFIX."users u
                JOIN ".TABLE_PREFIX."posts p ON (u.uid=p.uid)
				JOIN ".TABLE_PREFIX."warnings uw ON (uw.pid=p.pid)
                WHERE uw.expired='0' AND p.{$pids}
            ");

it works, but runs the same amount of queries. Sad

Not too experienced with $pids, so any help would be appreciated. Wink

Yes, that get_thread function is cached I think so because I used it for another plugin I coded a while back. Smile
Damn, well I won't be able to get on a computer till Tuesday (2 days time). Writing any amount of code over a single variable is painful on my phone.

What was the actual SQL error btw? Might help me figure out a fix.
Also just noticed my code doesn't display in that blog post. I'll haven't check that when I get a laptop again. In the meantime, check out the postbit function in my MyXBL plugin at http://github.com/euantor/myxbl
<?
	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
(2012-09-23, 08:32 PM)Omar G. Wrote: [ -> ]
	static $pwn_cache = null;
	if(!isset($pwn_cache))
	{
		$pwn_cache = array();
		if(!$GLOBALS['pids'])
		{
			//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

Spot on Omar. Though remember that $pids isn't set for quick reply.
Pages: 1 2 3 4