Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Warning Notification (Icon).
#21
There can't be warn for new replies, so the best option could be to stick $post['pwn'] = ''; to the top of my code. Editpost should probably have a special attention though, I updated my last post code.
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#22
Good point, I wasn't thinking about that haha. I just remember facing errors with MyXBL due to quick reply.
Reply
#23
This is a nice plugin. Once it gets updated with the query issues, I'd be glad to use it. Thanks!
Reply
#24
Your ACP theme is so sexy, can I have?
Reply
#25
(2012-09-23, 09:19 PM)Trickshot Wrote: Your ACP theme is so sexy, can I have?

Please stay on topic.
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#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
#27
Quote:and that works great. Just wanted to confirm if I can fetch it & store as an array?

My bad. Yes, you are suppose to fetch the result as array, not a specified field.

The only problem I really see is this:
global $mybb, $db, $pids;

For performance reasons (maybe minimal, but still) you should only add global variables to the local scope (no sure about the correct terms programmers do use) when and where necessary, in this case you don't really need $mybb at all and $pids not always.
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#28
This user has been denied support. This user has been denied support.
You're correct, I've removed them as globals.

I will be submitting new version in a minute or two, if possible, do approve it.

Thank you, everybody for the help to assist me in optimizing the plugin. I learned few more things. Smile

Edit: submitted & approved.

The plugin is now well optimized for v1.1 and runs only 1 query on postbit/showthread and is available to be downloaded from below:

http://mods.mybb.com/view/post-warning-notification
Reply
#29
Tow more suggestions.
  1. Do you really need to create a new settings group just for one setting? (you can, for example, add your setting to the in-core warning settings group)
  2. Hard-coded HTML/language strings, no one likes it Sad.

Adding a new lang file just for one line doesn't seems reasonable at all, so maybe you can do something like this:
	global $lang;
	isset($lang->pwn_mylangstring) or $lang->pwn_mylangstring = 'This user is currently warned for this post.';
	
	$post['pwn'] = '
    
   <img src="images/pwn.png" title="'.$lang->pwn_mylangstring.'" />
   ';

That way people who want to translate your plugin can simple add the following to the global.lang.php file:
$l['pwn_mylangstring'] = 'Usuario advertido. (Spanish blablabla)';

Hope that helps!
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#30
This user has been denied support. This user has been denied support.
Well,

1. I like to create settings for my plugins rather than altering the table. Smile

2. I will see to it, haha, I'm used to it, but I guess I'll update it if I find time, as I am so short of time these days.

I was about to create a language file but I gave up that thought and added the variable instead, I'll update it in the new version.

Thanks for suggestions, appreciated.

PS. This thread is getting insane views for some reason.
Reply


Forum Jump:


Users browsing this thread: 17 Guest(s)