21
trabis
Re: Paid access to some parts of the website
  • 2009/1/16 23:53

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Let's say that you are not using a module page, let's say that you want to create your own page in the root of your system and have 2 templates ready, one for regular users, other for privileged users.

Here is a complete example for that page:
<?php
//loads XOOPS framework, xoopsUser
include "mainfile.php"

//loads template class and prepares blocks
include_once XOOPS_ROOT_PATH '/header.php'

//get current user id
$uid is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;

//get groups from this user, if any
$member_handler =& xoops_gethandler('member');
$groups =& $member_handler->getGroupsByUser($uidtrue);

//the above method will give as an array of objects, lets get the name of each group 
$usergroups = array();
foreach (
$groups as $group) {
    
$usergroups[] = $group->getVar('name');
}

//prepare our (not cached, and not editable from admin) custom template 
$tpl = new XoopsTpl();

//We have the groups names, now we will see if 'your_group' is one of them
if (in_array('your_group'$usergroups)) {
    
//yes it is, let us display our special page
    
$tpl->display(XOOPS_ROOT_PATH '/your_group_template.html');
} else {
    
//sorry, you must subscribe our service first
    
$tpl->display(XOOPS_ROOT_PATH '/your_nogroup_template.html');
}

//this will render this page inside your theme, with blocks and everything ;-)
include_once XOOPS_ROOT_PATH '/footer.php';
?>

22
deka87
Re: Paid access to some parts of the website
  • 2009/1/17 8:21

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


thanks for the detailed instructions. this code
$member_handler =& xoops_gethandler('member');
$uid is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
$groups =& $member_handler->getGroupsByUser($uidtrue);
$usergroups = array();
$groups =& $member_handler->getGroupsByUser($uidtrue);
foreach (
$groups as $group) {
    
$usergroups[] = $group->getVar('name');
}

if (
in_array('mygroup'$usergroups)) {
    
$xoopsTpl->assign('hasPrivileges'true);
}
worked just fine for me
Mind anchors

23
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/17 11:31

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


Thanks for taking your time Trabis, and your code may very well work. However, I wouldn't know because it simply will not pick up my uid as anything else than 0, regardless of which user I use to log in with. And I suspect this has nothing to do with your code, as this is the case regardless if I use any custom code or not.

Let me give you an example using the the standard system who's online block:
I use my regular computer and go to my site. The who's online block shows 1 guest. I log in, and the block shows 1 guest and 1 user. I use my server to go to the site as well and the block show 2 guests and 1 user. I log in with a different user and the block shows 2 guests and 2 users.

It seems whenever I'm logged on, the system sees me as both a guest and a user, and I just can't seem to get hold of any other ID than the guest ID. Why?

24
deka87
Re: Paid access to some parts of the website
  • 2009/1/17 11:51

  • deka87

  • Friend of XOOPS

  • Posts: 1125

  • Since: 2007/10/5


im not sure but i suggest that XOOPS checkes if the user is still online after a definite period of time like one minute or soemthign and that is why it still can see ya as an anonymous user and a logged on user.
Mind anchors

25
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/17 14:11

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


Yes, that makes sense. I also noticed that the extra user goes away after a while. However, why do I only get uid=0 and not the real uid when I try to get the user with the code (even after the "extra" user has disappeared)?

26
trabis
Re: Paid access to some parts of the website
  • 2009/1/17 14:53

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


The whos online block displayes users that were present in the last 5 minutes and is updated around 1 time each 10 pageviews.

the code is in system/blocks/system_blocks.php
mt_srand((double)microtime()*1000000);
    
// set gc probabillity to 10% for now..
    
if (mt_rand(1100) < 11) {
        
$online_handler->gc(300);//300 seconds(5 minutes)
    
}


You can change this values has you like.

This has nothing to do with your problem. The code Deka used should also work for you. If you paste here your code Then will be able to help you. Thanks.

27
Mazarin
Re: Paid access to some parts of the website
  • 2009/1/17 19:14

  • Mazarin

  • Just can't stay away

  • Posts: 533

  • Since: 2008/12/10


Thanks for putting up with my n00bish questions (and for sort of hijacking this thread).

I got it working within a module now, so thank you very much. I think what confused me a bit was the part that I still can't get to work, i.e. the menu. I am currently using the blue day dynamique theme, which has a menu for navigation just before the content of the site. I would very much like to reflect these restrictions within the module also in the menu, so that the users who don't have access won't even get a menu option to go there.

However, this menu part is where I still can't get the system to pick up any other uid than 0.

28
munky2020
Re: Paid access to some parts of the website
  • 2009/1/17 21:39

  • munky2020

  • Just popping in

  • Posts: 16

  • Since: 2008/11/25


hey i just want to let everyone know that trabis is the best, he has helped me out on several occasions on a site im working on. he doesnt ask for money, but he is definitely worth donating to cuz he rocks!

29
trabis
Re: Paid access to some parts of the website
  • 2009/1/17 22:04

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

munky2020 wrote:
hey i just want to let everyone know that trabis is the best, he has helped me out on several occasions on a site im working on. he doesnt ask for money, but he is definitely worth donating to cuz he rocks!


Thanks, you are to kind!

@niei0637:
Where are you adding the code?
you could add this line in your theme:
<{include_php file="file:$xoops_rootpath/themes/yourtheme/extention.php"}>


Then you add a file into your theme folder (in the example:'yourtheme') named extension.php and you add your code there. This way it will be available for all pages.

30
ghia
Re: Paid access to some parts of the website
  • 2009/1/18 0:57

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Quote:
<{include_php file="file:$xoops_rootpath/themes/yourtheme/extention.php"}>

Then you add a file into your theme folder (in the example:'yourtheme') named extension.php
Is there a typo in these file names?

Login

Who's Online

139 user(s) are online (94 user(s) are browsing Support Forums)


Members: 0


Guests: 139


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits