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

How do I explode/sort additional usergroups please

Discussion in 'XenForo Development Discussions' started by Ingenious, Feb 22, 2012.

  1. Ingenious

    Ingenious Well-Known Member

    On my basic but functional member map which is created from custom user fields for long/lat, and is a standalone PHP file and not a plugin (although is prettied up by using an embed PHP plugin), I used to have different coloured pointers on vB for different user groups, using this probably quite long winded PHP to sort the additional usergroups out (which were taken directly from the database, and where separated by commas, such as 10,12 if member of group 10 and 12):

    $pieces = explode(",", $membergroupids);
    if (in_array("10", $pieces)) {
    $pointericon=", adifferentmapIcon";
    $pointertext="</br><b>In usergroup 10</b>";
    (and so on, for each usergroup I wanted to show)
    On XenForo though, I cannot make sense of the additional usergroup data.

    Someone in additional usergroup 7 has the data:


    Someone in groups 7 and 13 has the data


    It seems to be 3 + group id + 2c3 + 3 if the group ends in 3

    Groups 6, 7 and 13:


    Groups 6 and 7:


    Any help please on how to explode/sort that so that an array contains just the usergrpoup IDs like the code above?

    I had hoped I could use the xen code to check if a member "is member of" but they don't seem to work in a PHP file that is itself embedded in another which is being wrapped in the forum header and footer.

    Just to be clear, I don't want to make this into a plugin etc I just want to be able to process the raw usergroup data shown above :)
  2. cclaerhout

    cclaerhout Well-Known Member

    Look at this part of code, it should help you:

                $visitor = XenForo_Visitor::getInstance();
                $visitorUserGroupIds = array_merge(array((string)$visitor['user_group_id']), (explode(',', $visitor['secondary_group_ids'])));
                    $abcdef_ok = array_intersect($visitorUserGroupIds, $options->ADMINCP_OPTION);
                if ($abcdef_ok)
    You can see the $visitor['user_group_id'] and $visitor['secondary_group_ids'] variables. The first one will be a string, the second one an array (the user can be in several secondary groups). You can get thoses variables thanks to this command:

    Don't hesitate to use this command to display a variable:
    it's great tool to debug, better than var_dump().
  3. Ingenious

    Ingenious Well-Known Member

    Thanks, but I've looked at that and it doesn't help. Remember I'm running an independent script so I can't use the functions in XenForo, I can only get the raw contents of the usergroups field which is "372c3133" for example. Really I need the relevant PHP code to convert that into 7,13 in this case. The above code explodes around commas which are not in this data, that is how I did it before anyway since it is how vB stores the data.
  4. cclaerhout

    cclaerhout Well-Known Member

    Ingenious likes this.
  5. Ingenious

    Ingenious Well-Known Member

    No, I hadn't, and thanks, that's very useful indeed :)

Share This Page