21
yotsugi
Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?
  • 2008/7/25 4:17

  • yotsugi

  • Just popping in

  • Posts: 1

  • Since: 2008/7/25


Quote:

This is great! Would there be a way to do this for an individual user...Im a webmaster, but there's a couple other webmasters on the site I work on, and I would like to have a couple of things in my theme so only I would have a slightly different layout.
Also, Im really new to xoops, so if somebody could lay it all out for me, like leoscotch did (thanks for that!)
Thank y'all!

Why you don't create another group for other "webmaster"? On this case, I created one group and placing the other "webmaster" into that group. Then, I'm using $group_id smarty in the template to differentiating the template between the real webmaster and the other webmaster.

For example:
<{if $xoops_isadmin}> 
what to do
<{elseif 
$group_id == 4}> 
something to do if first condition is false and this condition is true
<{/if}>


And if you want to do it to individual user, maybe you can using $user_id smarty...

22
zite83
Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?
  • 2009/3/17 1:35

  • zite83

  • Just popping in

  • Posts: 41

  • Since: 2004/10/5


Here is how I got mine to work

I used this because I have a custom nav bar at the top of my website, it doesn't really need to be dynamic but what I need is when a user logs in if that person belongs to the right group something will show up. So in my case, when a user is logged in and belongs to group 9 he or she will get a "Submit News Link" other users that don't belong to this group do not get the link.

Another thing I noticed is when you update a user and add a new group for them to belong to, it won't take effect till next log in.

/class/template.php
add
global $xoopsUser;
if ( @
$xoopsUser && is_object($xoopsUser) ) {
$this->assign'xoops_usergroups'$xoopsUser->getGroups() );}


under

$this->Smarty();


save file template.php

add to your theme/template
<{foreach item=group from=$xoops_usergroups}>
    <{if 
$group.groupid == 9}>  
        
YOU CAN SEE ME GROUP 9!
    <{/if}>
<{/foreach}>



23
ghia
Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?
  • 2009/3/17 9:58

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Why
if ( @$xoopsUser && is_object($xoopsUser) ) {
?
Is
if ( is_object($xoopsUser) ) {
not sufficient? You should try to avoid the use of @.

24
Catzwolf
Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?
  • 2009/3/17 10:10

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


Quote:

ghia wrote:
Why
if ( @$xoopsUser && is_object($xoopsUser) ) {
?
Is
if ( is_object($xoopsUser) ) {
not sufficient? You should try to avoid the use of @.


I totally agree with that statement.

Problem is that I am seeing this more and more with the core and it is regarded as bad coding practice. When you start suppressing errors, you basically start making the debugging process a nightmare and when in reality, it should be a simple job.

The use of such examples:

@require_one my/file/to/include.php;


To me the worst type of suppressing an error: When it is faster and better to do the following:

if ( file_exists$file XOOPS_ROOT_PATH '/user.php' ) ) {
    require_once 
$file;
} else {
    
trigger_error"File: $file not found" );
}


Thought rather simplistic in its approach, it would provide the information on a fail that a developer would need to correct the issue.

But I am more than sure ghia could provide betters examples :)

Catz :)

25
ghia
Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?
  • 2009/3/17 11:30

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Quote:
But I am more than sure ghia could provide betters examples
No, your example demonstrates exact some of the problems. And this is a real life example by Hervet.

I believe that also the @ is the main problem why so many users have problems with the admin module manager, which fails to show uninstalled modules if there is one in it with some kind of problem. And with no messages in debug, nobody has a clue why.

For me, the @ should be banned, and in the first place from all core code.

26
Catzwolf
Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?
  • 2009/3/17 12:43

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


Yes, I can actually give you a better example with the core that had me baffled for 5 hours and if the @ hadn't been used I would have fixed the problem in about 1 minute.

$this->path_basic XOOPS_ROOT_PATH "/class/captcha";
$this->path_plugin XOOPS_ROOT_PATH "/Frameworks/captcha";

    function 
loadConfig($filename null)
    {
        
$filename = empty($filename) ? "config.php" "config.{$filename}.php";
        
$config = @include "{$this->path_basic}/{$filename}";
        if (
$config_plugin = @include "{$this->path_plugin}/{$filename}") {
            foreach (
$config_plugin as $key => $val) {
                
$config[$key] = $val;
            }
        }
        
        return 
$config;
    }


As you can see, both paths have been suppressed and note the second line is a call to the Framework folders. Here we are making the framework a requirement of the core and not the other way around.

The code that was in the framework was to include a language file and wouldn't be considered a requirement. But the code was something like this:

if (!@include '/path/to/language/file.php') {
    require 
'/path/to/language/file.php';
}


With all the error suppression and the system failing to find the required file, all that happens is that we end up with a white page and even error debugging turned on and nothing to show where the problem lies.

I agree this practice should be banned from the core along with this baby and it's still used within the core code.

foreach ($_POST as $k => $v ){
   
$kk $v;
}


Catz

27
zite83
Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?
  • 2009/3/17 23:01

  • zite83

  • Just popping in

  • Posts: 41

  • Since: 2004/10/5


Thanks for the feed back! I'm not a programmer to the slightest but I can understand the basics of it, I just know how to use others code snippets to solved my problems

28
redheadedrod
Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?

It has been a while since this thread was last updated and I want to know if this method works in the latest versions as of this writing.(2.3.3, 2.4.3)

If I have this right...

In /class/template.php we look for the line...
Quote:
$this->Smarty();


And insert the following lines after...
Quote:

global $xoopsUser;
if ( is_object($xoopsUser) ) {
$this->assign( 'xoops_usergroups', $xoopsUser->getGroups() );}



then in our
theme/template

use
Quote:

<{foreach item=group from=$xoops_usergroups}>
<{if $group.groupid == 9}>
YOU CAN SEE ME GROUP 9!
<{/if}>
<{/foreach}>


Then you could use this to go through every id and adjust the theme or template.

What adjustments would need to be made to this to make it look at the group name? And I assume that the system used ID 0-2 for anonymous, registered and admin.

On my site I have 2 additional users as it is a team site and I am using the registered user as the generic fans and I also have a "player" and "moderator" groups available.

Would rather set them up as the names of the groups so if I add or change groups later this can be used.

Also looks like the function listed in the first page would work the way I want it to as well and be somewhat simpler in the long run. Has anyone tested this and make sure it works?

And as has been asked where would you put this function?

Thanks!

29
JCash
Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?
  • 2012/1/19 22:01

  • JCash

  • Just popping in

  • Posts: 66

  • Since: 2011/2/22


Nice :)

Still works with Xoops 2.5.4 but... why it is not implemented by default ?
May be into Xoops 2.6 code ?

30
mjoel
Re: $xoops_isadmin, $xoops_isuser, but $xoops_?
  • 2013/8/18 10:58

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


Quote:

Dave_L wrote:
This may help. I haven't tested it.

/**
 * Check whether current user is in specified group.
 *
 * @param string $group_name Name of group
 * @return bool True if user is in group, otherwise false
 */
function in_group($group_name) {
   global 
$xoopsUser;
   if (!
is_object($xoopsUser)) {
      return 
false;
   }
   
$member_handler =& xoops_gethandler('member');
   
$groups =& $member_handler->getGroupsByUser($xoopsUser->getVar('uid'), true);
   
$in_group false;
   foreach (
$groups as $group) {
      if (
$group->getVar('name') == $group_name) {
         
$in_group true;
         break;
      }
   }
   return 
$in_group;
}


Then you could assign a template variable:

$xoopsTpl->assign('in_subscribed_group'in_group('subscribed'));


Then in the template:

<{if $in_subscribed_group}>
   ...
<{/if}>


How do i use this if Im in custom php page ?

i tried this but not working
if ($in_group == 'nameofmygroup'
{
echo 
"In Group";
}   
else
{
echo 
"Not in Group";
}

Login

Who's Online

191 user(s) are online (106 user(s) are browsing Support Forums)


Members: 0


Guests: 191


more...

Donat-O-Meter

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

Latest GitHub Commits