• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Using xenforo permission outside of xenforo?

Member 3639

Active member
#1
Hi all currently using PHPBB on my website Gaming On Linux and i am thinking about switching over.

First Question
My main concern is that everything on the main website that is user based uses phpbbs auth system, how easy is it to see/use the authorisation system of xenforo outside of it?

Like a certain user group say admins, super mods or even an admin created group.

Like including certain files then doing say (dirty example)
Code:
if ($auth->group['admin'] == 1)
// do something
Is it simple enough with xenforo?

Second question
How easy is it to get videos to be able to be embeded via bbcode in posts from popular sites like youtube or veoh?
 

Decent60

Well-known member
#3
It's quite easy to do an admin group and a moderator group:
PHP:
<xen:if is="{$visitor.is_admin}">
//do something, you c an also use is="{$user.is_admin}" or is="{$user.is_moderator}" or is="{$user.is_admin} OR {$user.is_moderator}"
<xen:else>
//do_something_else
</xen:if>
All Admins or Moderators needs put in the Administrator or Moderator group, regardless of rank (even admin rank needs to be put in the Administrator group).
I really never found how to do a specific group id, but it should be fairly easy....depending on what you want to do that is.
 

Member 3639

Active member
#4
It's quite easy to do an admin group and a moderator group:
PHP:
<xen:if is="{$visitor.is_admin}">
//do something, you c an also use is="{$user.is_admin}" or is="{$user.is_moderator}" or is="{$user.is_admin} OR {$user.is_moderator}"
<xen:else>
//do_something_else
</xen:if>
All Admins or Moderators needs put in the Administrator or Moderator group, regardless of rank (even admin rank needs to be put in the Administrator group).
I really never found how to do a specific group id, but it should be fairly easy....depending on what you want to do that is.
I'm not talking inside templates though as that looks like it's from a template, I'm talking outside the script - like website integration using xenForo permissions.
 

James

Well-known member
#7
Hi Liam. Are you wondering because of certain custom pages that you want to port over or just in general? If it's the former, look at the pages system on XF and see if that suits your needs until the devs can get back to you.
 

Member 3639

Active member
#8
I mean outside the forum entirely.

So on my actual website if a user is logged into the xenForo forum i can check certain permissions to allow them to do certain things on the website.
 

Jeremy

Well-known member
#9
As long as the environment is set up correctly (by including it. I'm not 100% certain HOW to set it up correctly) or if you rework everything to be under your forum index.php, you can very easily access everything.
 
#10
I'm not willing to re-code my site to work under a file of the forum.

On PHPBB you do need to include a file or two and then do a tiny bit of code.

Just wandering if you can do the same in xenForo, guess i need a dev to comment on this really.

Things like showing "welcome <username>" on your website if they are logged in, stuff like that.
 

Mike

XenForo developer
Staff member
#11
There is some code that is stuck in controllers that probably shouldn't be. Moving that out would make it a lot easier to do. That is something I will look at. After that, it'd be setting up the environment (autoloader and application bootstrap), then grabbing the session and current visitor info. From there, there are model calls to check various permissions (though you can call the individual pieces more directly if you want).
 
#12
Well a lot of people will be needing something like this no doubt, would be worth it to make it easier for us to do it.

Maybe add info to faq or mod guide or something?
 

Shadab

Well-known member
#13
There is some code that is stuck in controllers that probably shouldn't be. Moving that out would make it a lot easier to do. That is something I will look at. After that, it'd be setting up the environment (autoloader and application bootstrap), then grabbing the session and current visitor info.
I'm bridging my symfony based applications with xenforo, and so far session handing seems to be the only problematic part. Processing of the Remember Me logic would require code duplication, since (like you've said) it's originally located in the abstract controller class. Any chance of moving this logic to the session class itself?

If I skip the code for processing Remember Me, setting up the framework including session and visitor takes just about 10 lines of code. Very easy & simple. :)
 

Mike

XenForo developer
Staff member
#14
I'm bridging my symfony based applications with xenforo, and so far session handing seems to be the only problematic part. Processing of the Remember Me logic would require code duplication, since (like you've said) it's originally located in the abstract controller class. Any chance of moving this logic to the session class itself?
That was the main bit I was referring to, though I'd have to double check approach as there is different code for ACP and front-end sessions (they are distinct). :) There are a few other helper type things that could be moved too.
 
#18
As an example in phpbb you would do this:
Code:
define('IN_PHPBB', true);
$phpbb_root_path = './community/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
 
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
Then you can access all the user info.

So for username:
Code:
$user->data['username']
 

Shadab

Well-known member
#19
As a stop-gap measure, I've created a helper class that you can call to initialize the xenforo application, preload the important data and setup the session properly, taking auto-login into consideration. Let me know (via PC) if you want it. (Although it would become redundant once the code is moved to a helper in xenforo core).

Sample code for that:
PHP:
$startTime = microtime(true);
$xenforoRoot = '/absolute/path/to/xenforo/root/directory';

// Setup XenForo's autoloader
require_once($xenforoRoot . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($xenforoRoot . '/library');

// Initialize the XenForo Framework
GeekPoint_Symfony::initializeXenforo($xenforoRoot, $startTime);

// You can fetch user data using the visitor object
$visitor = XenForo_Visitor::getInstance();

$user_id = $visitor->getUserId();
$username = $visitor->get('username');
$email = $visitor->get('email');
 
#20
Brilliant, have you tested it working?

Are you able to check their permission levels? So you can check if someones admin to let them into an admin centre for a website?