MyBB Hacks

Full Version: OUGC Mark PM As Unread
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Okay, I'm tired and in a weird mood.  This means that I will do a half dazed skim over and blurt out anything that catches my attention.
  • Code:
     * 1.- You may edit whatever you want to fit your needs without permission.
     * 3.- You MUST NOT remove any license comments in any file that comes with this plugin pack.

    Can I make #1 override #3?

  • PHP Code:
    		$mark = ougc_markpmasunread_markunread($mybb->input['markunread']);
    		if($mark !== true)
    		{
    			global $lang;
    			$lang->load('ougc_markpmasunread');
    
    			switch((int)$mark)
    			{
    				case 1:
    					$message = $lang->ougc_markpmasunread_error_invalidpm;
    					break;
    				case 2:
    					$message = $lang->ougc_markpmasunread_error_alreadyunread;
    					break;
    				case 3:
    					$message = $lang->ougc_markpmasunread_error_userupdate;
    					break;
    				default:
    					$message = $lang->ougc_markpmasunread_error_unkown;
    					break;
    			}
    			error($message);
    		}

    Okay, that seemed awkward...  Maybe skip the magic numbers and pass back better references?

  • I honestly would just chuck the entire contents of the ougc_markpmasunread template into the private_messagebit template - saves a shit-tonne of work, but whatever makes you happy I guess
  • PHP Code:
    	$return = false;
    	(isset($pmid) && ($pmid = (int)$pmid)) or ($return = true);
    	($pmid && $pmid > 0) or ($return = true);
    
    	if($return)
    	{
    		return 1;
    	}

    Seems the same as

    PHP Code:
    if(($pmid = (int)@$pmid) > 0) return 1;

    Okay, yeah, I'm being pedantic...

  • When marking unread, the pmid isn't validated against a user - eg it's possibly to mark someone else's PMs as unread, if you want to be a bored twat with nothing better to do, that is
  • Also marking unread doesn't have/check postkeys, but I honestly wouldn't care for it myself

Okay, there's absolutely nothing wrong with the plugin, I just need some negative points to stick up for my own enjoyment.
I'm going to bed.
Quote:Okay, I'm tired and in a weird mood.  This means that I will do a half dazed skim over and blurt out anything that catches my attention.
  • Code:
     * 1.- You may edit whatever you want to fit your needs without permission.
     * 3.- You MUST NOT remove any license comments in any file that comes with this plugin pack.

    Can I make #1 override #3?


You can, but you are no suppose to Tongue

Quote:
  • PHP Code:
    	$return = false;
    	(isset($pmid) && ($pmid = (int)$pmid)) or ($return = true);
    	($pmid && $pmid > 0) or ($return = true);
    
    	if($return)
    	{
    		return 1;
    	}

    Seems the same as

    PHP Code:
    if(($pmid = (int)@$pmid) > 0) return 1;


Didn't know we could use @ to hide variable errors too (just functions). This should probably save code in future.

Quote:
  • I honestly would just chuck the entire contents of the ougc_markpmasunread template into the private_messagebit template - saves a shit-tonne of work, but whatever makes you happy I guess

It is done that way so that the text is only show when necessary, I know nothing about regex, so I will be even more work to hide it using a different way (I like nice details too).

Quote:
  • When marking unread, the pmid isn't validated against a user - eg it's possibly to mark someone else's PMs as unread, if you want to be a bored twat with nothing better to do, that is
  • Also marking unread doesn't have/check postkeys, but I honestly wouldn't care for it myself

Didn't think about that.

Quote:
  • PHP Code:
    		$mark = ougc_markpmasunread_markunread($mybb->input['markunread']);
    		if($mark !== true)
    		{
    			global $lang;
    			$lang->load('ougc_markpmasunread');
    
    			switch((int)$mark)
    			{
    				case 1:
    					$message = $lang->ougc_markpmasunread_error_invalidpm;
    					break;
    				case 2:
    					$message = $lang->ougc_markpmasunread_error_alreadyunread;
    					break;
    				case 3:
    					$message = $lang->ougc_markpmasunread_error_userupdate;
    					break;
    				default:
    					$message = $lang->ougc_markpmasunread_error_unkown;
    					break;
    			}
    			error($message);
    		}

    Okay, that seemed awkward...  Maybe skip the magic numbers and pass back better references?


Probably can reduce the code there, but what exactly do you mean?

Tank you for the review Zinga Burga.
(08-21-2012 05:12 AM)Sama34 Wrote: [ -> ]Didn't know we could use @ to hide variable errors too (just functions). This should probably save code in future.
It's actually unnecessary because MyBB ignores notice errors, but I just chucked it there for the sake of doing so.

(08-21-2012 05:12 AM)Sama34 Wrote: [ -> ]It is done that way so that the text is only show when necessary, I know nothing about regex, so I will be even more work to hide it using a different way (I like nice details too).
Okay, I missed that - my bad.
Still doable with a CSS hack, but I guess it's less elegant.

(08-21-2012 05:12 AM)Sama34 Wrote: [ -> ]Probably can reduce the code there, but what exactly do you mean?

PHP Code:
if($mark = ougc_markpmasunread_markunread($mybb->input['markunread'])) {
	global $lang;
	$lang->load('ougc_markpmasunread');
	error($lang->$mark);
}

function ougc_markpmasunread_markunread(...) {
if(you_suck)
	return 'ougc_markpmasunread_error_invalidpm';
...
return false;
}


Doesn't handle the default case, but all return values from the function are controlled, right?

Yes, they are. Thank you Zinga Burga, I had applied the improvements you highlighted.

I suppose this will be good enough for the license as well:
Quote:* 1.- You MUST NOT remove any license comments in any file that comes within this package.
* 2.- You MUST NOT redistribute this or any modified version of this plugin by any means without the author written permission.
* 3.- You MAY edit whatever you want to fit your needs without permission (EXCEPT FOR THAT MENTIONED IN #1).
Reference URL's