Check if User is able to read a post

Discussion forum for MOD Writers regarding MOD Development.
Locked
CrazyBread
Registered User
Posts: 4
Joined: Wed Mar 31, 2010 11:13 pm

Check if User is able to read a post

Post by CrazyBread » Wed Mar 31, 2010 11:22 pm

Hi there,
I try to write a function which checks if an User (user_id) is able to read a post (post_id) like
function checkIfUserHasPermissionToSeePost(user_id, post_id)
and returns me a boolean or something else.
I searched in the internet for weeks, posted already in the german support forum (which is now closed). This is why I look for help in this forum.

Thanks,

CrazyBread

Comkid
Registered User
Posts: 132
Joined: Thu Mar 25, 2010 5:40 am

Re: Check if User is able to read a post

Post by Comkid » Thu Apr 01, 2010 1:34 am

What about this:

Code: Select all

if ($auth->acl_get('f_read', $forum_id))
{

} 
That will be the closet you can get, I believe, that will check if the current user (the one accessing the page), can read the $forum_id ;)
I ist Comkid :P

CrazyBread
Registered User
Posts: 4
Joined: Wed Mar 31, 2010 11:13 pm

Re: Check if User is able to read a post

Post by CrazyBread » Thu Apr 01, 2010 10:22 am

Thanks for this hint.
But I am programming a complete new GUI for phpbb so I work only with the User ID.
I'll try to understand how this function acl_get works...

Any ideas?

CrazyBread
Registered User
Posts: 4
Joined: Wed Mar 31, 2010 11:13 pm

Re: Check if User is able to read a post

Post by CrazyBread » Thu Apr 01, 2010 12:34 pm

This is my function so far:

Code: Select all

	public function checkUserReadPermissionForContribution(Contribution_JnD $contribution,
															User_JnD $checkUser){
		global $db;
		global $user;
		global $auth;
		global $template;
		global $cache;
		global $config;
		global $phpbb_root_path;
		global $phpEx;
		
		$postId = $contribution->getId();
		$userId = $checkUser->getId();
	
		$user->session_create($userId);

		$sql = "SELECT forum_id FROM ".POSTS_TABLE." ".
			   "WHERE post_id = ".$postId.";";
		
    	$result = $db->sql_query($sql);
	$row = $db->sql_fetchrow($result);
    	$forumId = $row['forum_id'];
    	
    if ($auth->acl_get('f_read',$forum_id)){
    	echo "User is able to read";
    } else {
    	echo "user is not able to read";
    }
	}
But it is always the second case "not able to read".
Any ideas?

Comkid
Registered User
Posts: 132
Joined: Thu Mar 25, 2010 5:40 am

Re: Check if User is able to read a post

Post by Comkid » Fri Apr 02, 2010 12:35 am

Because it isn't set ;)

You used $forumId the whole time, whilst the code I gave you uses $forum_id ;)
I ist Comkid :P

CrazyBread
Registered User
Posts: 4
Joined: Wed Mar 31, 2010 11:13 pm

Re: Check if User is able to read a post

Post by CrazyBread » Fri Apr 02, 2010 10:44 am

OMG you're right!
It works!!!!

Thanks a million!

Comkid
Registered User
Posts: 132
Joined: Thu Mar 25, 2010 5:40 am

Re: Check if User is able to read a post

Post by Comkid » Fri Apr 02, 2010 10:52 am

No problems ;)
I ist Comkid :P

Locked

Return to “[3.0.x] MOD Writers Discussion”