vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB5 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=263)
-   -   Using {vb:raw conversation.groupid} (https://vborg.vbsupport.ru/showthread.php?t=313311)

webjocky 07-29-2014 04:49 AM

Using {vb:raw conversation.groupid}
 
As a vBulletin n00b, I've scoured these (and the vb.com's) forums for the past couple of weeks looking for a solution to this. Since I couldn't find one, I'm having to hack the core files - which I'd rather not do.

I'm hoping someone can tell me a more graceful way to handle this php file modification so that I don't have to hack the core files every time I update to a new release.

Here's what I needed and how I did it:
For those that don't already know, $conversation['groupid'] is not made available for template modifications in the codebase as of 5.1.2 Patch Level 2. The database's node table has a field for this information, but if you take a look - that field only contains NULL values by default. (vb_node -> groupid).

I need to assign avatars to my forum users based on the primary group id. This was easier to do in vB4, but the feature was used very little and so, as the devs have explained, the feature was not included in vB5. With that, I set out to create a group avatar manager myself.

By modifying /core/vb/library/content/text.php, you are now able to pull this information (although another hack is required to fill the database with the groupid of the post author - which I'll update here as soon as I figure that out).

Original @ Line 519
PHP Code:

if (empty($data['userid']))
        {
            
$user vB::getCurrentSession()->fetch_userinfo();
            
$data['authorname'] = $user['username'];
            
$userid $data['userid'] = $user['userid'];
        }
        else
        {
            
$userid $data['userid'];
            if (empty(
$data['authorname']))
            {
                
$data['authorname'] = vB_Api::instanceInternal('user')->fetchUserName($userid);
            }
            
$user vB_Api::instance('user')->fetchUserinfo($userid);
        } 

Modified:
PHP Code:

if (empty($data['userid']))
        {
            
$user vB::getCurrentSession()->fetch_userinfo();
            
$data['authorname'] = $user['username'];
            
$userid $data['userid'] = $user['userid'];
            
$groupid $data['groupid'] = $user['usergroupid'];  //Added groupid
        
}
        else
        {
            
$userid $data['userid'];
            
$groupid $data['groupid']; //Added groupid
            
if (empty($data['authorname']))
            {
                
$data['authorname'] = vB_Api::instanceInternal('user')->fetchUserName($userid);
            }
            
$user vB_Api::instance('user')->fetchUserinfo($userid);
        } 

With that in place, you can now call {vb:raw conversation.groupid}

Edit:
Here's the hack that enables the groupid to be set when someone creates a new forum node (channel/topic/post):
Original File: /core/vb/library/content.php @ Line 199
PHP Code:

    if (empty($data['userid']))
        {
            
$user vB::getCurrentSession()->fetch_userinfo();
            
$data['authorname'] = $user['username'];
            
$userid $data['userid'] = $user['userid'];
        }
        else
        {
            
$userid $data['userid'];
            if (empty(
$data['authorname']))
            {
                
$data['authorname'] = vB_Api::instanceInternal('user')->fetchUserName($userid);
            }
        } 

Change to:
PHP Code:

    if (empty($data['userid']))
        {
            
$user vB::getCurrentSession()->fetch_userinfo();
            
$data['authorname'] = $user['username'];
            
$userid $data['userid'] = $user['userid'];
            
$groupid $data['groupid'] = $user['usergroupid']; //Added groupid
        
}
        else
        {
            
$userid $data['userid'];
            
$groupid $data['groupid']; //Added groupid
            
if (empty($data['authorname']))
            {
                
$data['authorname'] = vB_Api::instanceInternal('user')->fetchUserName($userid);
            }
        } 

As I wait for a response to my question, I hope this helps someone. (just realized: this post contains a lot of hope :))

Edit: There is still one more file to edit that controls Private Message node creation. Will update this post when I find it.

Dead Eddie 07-30-2014 02:34 AM

I don't fully understand the use case, but remember that you can pull any bit of data you want into a template by making direct API calls in vbulletin 5. You don't need to have the data ready before you start rendering the template.

For something like this, it'd probably require an additional query per post (not sure if that's a deal breaker or not). It'd also save manual file edits.

I'm also curious why the user group needs to be attached to the node. Do you want it to stay static in case the user's user group changes?

webjocky 07-30-2014 09:34 PM

Quote:

Originally Posted by Dead Eddie (Post 2508962)
I don't fully understand the use case

As a vB user, you can set your avatar. For my forum, I don't need users to have different avatars and prefer to set them en masse via usergroups. Each usergroup will be assigned a different avatar.

Quote:

Originally Posted by Dead Eddie (Post 2508962)
but remember that you can pull any bit of data you want into a template by making direct API calls in vbulletin 5. You don't need to have the data ready before you start rendering the template.

If vB5 had adequate documentation for using the API instead of having to dig through the code, I (along with many many others) could probably accomplish anything I needed without having to post here. As I stated above, the data required for this is not in the database to begin with. There's a field (groupid) for it in the proper table (node), but the field is full of NULL values by default. If you're talking about something else, please elaborate.

Quote:

Originally Posted by Dead Eddie (Post 2508962)
For something like this, it'd probably require an additional query per post (not sure if that's a deal breaker or not).

I am making zero additional database calls per post. The hacks above works just fine for my purpose without such.

Quote:

Originally Posted by Dead Eddie (Post 2508962)
It'd also save manual file edits.

Your point here is not clear. How will additional database calls save manual file edits?

Quote:

Originally Posted by Dead Eddie (Post 2508962)
I'm also curious why the user group needs to be attached to the node. Do you want it to stay static in case the user's user group changes?

vBulletin forums ACL is driven by usergroups. I have specific needs that require the ability to give different options or show different things per post - based on the post author's usergroup. I imagine I'll have to update user posts when a usergroup is changed so that the usergroupid does not stay static.
Obviously somebody at vBulletin Solutions thought this was a good idea at one point, otherwise why would the database field exist in the node table?

I hope that clarifies what i'm trying to do, why I need to do it, and how I'm attempting to accomplish it. If there's a better way to accomplish what I'm trying to do, I'm all ears!

(I still haven't found the file that controls Private Message node creation. Any ideas?)

Dead Eddie 08-01-2014 02:24 AM

Quote:

Originally Posted by webjocky (Post 2509078)
If vB5 had adequate documentation for using the API instead of having to dig through the code, I (along with many many others) could probably accomplish anything I needed without having to post here.

Not sure what this has to do with me. I have access to EXACTLY the same information you do, and less motivation (I don't have a vb5 public forum running).

Quote:

Originally Posted by webjocky (Post 2509078)
As I stated above, the data required for this is not in the database to begin with. There's a field (groupid) for it in the proper table (node), but the field is full of NULL values by default. If you're talking about something else, please elaborate.

It is in the database, just not the table you're looking for it in. It's in the user table.

Quote:

Originally Posted by webjocky (Post 2509078)
I am making zero additional database calls per post. The hacks above works just fine for my purpose without such.

You asked for a different way, without manual file edits.

Quote:

Originally Posted by webjocky (Post 2509078)
Your point here is not clear. How will additional database calls save manual file edits?

Build an API that looks up the user group based on the user id. Call it within the template. As far as I can see, those are your two options for using the user group ID within the template. (alternatively, you could assign the avatar to the user when they join the usergroup...)

But, this seems to be the way the new system was designed. Build an API to pull the data, grab the data for the template via an API call, and display.

The tags within the template for calling the API are the <vb:data> tags, if you want to look at them.

Quote:

Originally Posted by webjocky (Post 2509078)
Obviously somebody at vBulletin Solutions thought this was a good idea at one point, otherwise why would the database field exist in the node table?

There are vestiges of 3 & 4 within 5. Likely, at one point, someone needed to denormalize whatever table that was in order to access the usergroup without needing to join the user table. That need probably doesn't exist within 5, but nobody removed the column.

Quote:

Originally Posted by webjocky (Post 2509078)
I hope that clarifies what i'm trying to do, why I need to do it, and how I'm attempting to accomplish it. If there's a better way to accomplish what I'm trying to do, I'm all ears!

Like I said, I'm not sure it's better, just different. But, no manual file edits. :)

webjocky 08-01-2014 06:58 AM

Quote:

Originally Posted by Dead Eddie (Post 2509243)
Not sure what this has to do with me. I have access to EXACTLY the same information you do, and less motivation (I don't have a vb5 public forum running).

Obviously the lack of documentation has zero to do with you. The comment you made about using the api was written in such a way that you almost expect a self-proclaimed vb n00b to know enough about the API to utilize it effectively.


Quote:

Originally Posted by Dead Eddie (Post 2509243)
It is in the database, just not the table you're looking for it in. It's in the user table.

Not my point, but you knew that.


Quote:

Originally Posted by Dead Eddie (Post 2509243)
You asked for a different way, without manual file edits.

Tuch?


Quote:

Originally Posted by Dead Eddie (Post 2509243)
Build an API that looks up the user group based on the user id. Call it within the template. As far as I can see, those are your two options for using the user group ID within the template. (alternatively, you could assign the avatar to the user when they join the usergroup...)

Manually assigning avatars to a couple thousand users is not an option.


Quote:

Originally Posted by Dead Eddie (Post 2509243)
But, this seems to be the way the new system was designed. Build an API to pull the data, grab the data for the template via an API call, and display.

The tags within the template for calling the API are the <vb:data> tags, if you want to look at them.

Now this is something I might be able to work with.



Quote:

Originally Posted by Dead Eddie (Post 2509243)
There are vestiges of 3 & 4 within 5. Likely, at one point, someone needed to denormalize whatever table that was in order to access the usergroup without needing to join the user table. That need probably doesn't exist within 5, but nobody removed the column.

Sloppy, but fair enough.


Quote:

Originally Posted by Dead Eddie (Post 2509243)
Like I said, I'm not sure it's better, just different. But, no manual file edits. :)

No manual file edits makes your suggestion better for sure. I really appreciate your input & feedback on this. :up:

Dead Eddie 08-05-2014 09:13 PM

Quote:

Originally Posted by webjocky (Post 2509259)
Obviously the lack of documentation has zero to do with you. The comment you made about using the api was written in such a way that you almost expect a self-proclaimed vb n00b to know enough about the API to utilize it effectively.

Sorry, just the way I talk. I tend to have to explain things to people who understand part of what's going on, but not all of it, so I phrase things to relate new concepts to things they already know. It's a habit.



Quote:

Originally Posted by webjocky (Post 2509259)
Not my point, but you knew that.

Honestly? I thought the availability of the data was what you were looking for.


Quote:

Originally Posted by webjocky (Post 2509259)
Manually assigning avatars to a couple thousand users is not an option.

Nah. You could probably use the API extension system to watch for changes to usergroups. When the usergroup changes, if it's one you want to manually assign an avatar to, you do it then. Then disallow the usergroup from changing their avatar.

That'd be the first road I'd explore. :)

tbworld 08-06-2014 12:43 AM

Originally Posted by Dead Eddie https://vborg.vbsupport.ru/images/cs...s/viewpost.gif
But, this seems to be the way the new system was designed. Build an API to pull the data, grab the data for the template via an API call, and display.
The tags within the template for calling the API are the <vb:data> tags, if you want to look at them.
Elegantly said. :)


All times are GMT. The time now is 10:27 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04032 seconds
  • Memory Usage 1,815KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (21)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete