MyBB Community Forums

Full Version: plugin function problem !
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello
I wanna creat a new plugin

but i dont know what is the problem with this function

function ParseSpoiler($msg)
{
	global $mybb;
	if ($on != "0")
	{
		$cach = "#\[cach\](.*?)\[/cach\]#si";

		if ($mybb->user['uid'] != $post['uid'])
		{
			$rep = "Access_restreint";
		}
		else
		{	$rep = "Access_autorise"; }
			
		$msg = preg_replace($cach, $rep, $msg);

		return $msg;
	}
	
}

but in the forum when the same user get "Access_restreint" and this is not what i want !!

thanx for help !
I guess access restriction for if ($mybb->user['uid'] != $post['uid']) is not what you wanted.
it is the reverse. that is, if ($mybb->user['uid'] == $post['uid']) then restricted
(2013-04-12, 08:05 PM).m. Wrote: [ -> ]I guess access restriction for if ($mybb->user['uid'] != $post['uid']) is not what you wanted.
it is the reverse. that is, if ($mybb->user['uid'] == $post['uid']) then restricted

noo this is not what i want

I want to autorise the access to the same user that writ the post and restrict access to other users

I dont know if you understand me !!
$post is not globalised. I think you also have to pass $msg by reference. (I also cleaned up your code a little bit:

function ParseSpoiler(&$msg)
{
	// added $post to the global statement. Prefixed $msg above with & (pass by reference). Removed != "0" in the if statement below. Rearranged the if-else to be a bit more readable.
	global $mybb, $post;
	if ($on)
	{
		$cach = "#\[cach\](.*?)\[/cach\]#si";

		if ($mybb->user['uid'] != $post['uid'])
		{
			$rep = "Access_restreint";
		}
		else
		{
			$rep = "Access_autorise";
		}
			
		$msg = preg_replace($cach, $rep, $msg);

		return $msg;
	}
}
(2013-04-13, 12:04 AM)Seabody Wrote: [ -> ]$post is not globalised. I think you also have to pass $msg by reference. (I also cleaned up your code a little bit:

function ParseSpoiler(&$msg)
{
	// added $post to the global statement. Prefixed $msg above with & (pass by reference). Removed != "0" in the if statement below. Rearranged the if-else to be a bit more readable.
	global $mybb, $post;
	if ($on)
	{
		$cach = "#\[cach\](.*?)\[/cach\]#si";

		if ($mybb->user['uid'] != $post['uid'])
		{
			$rep = "Access_restreint";
		}
		else
		{
			$rep = "Access_autorise";
		}
			
		$msg = preg_replace($cach, $rep, $msg);

		return $msg;
	}
}

Thank You verry much!! I will post my first plugin soon