Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 Programming Discussions
  #1  
Old 07-29-2014, 05:49 AM
webjocky webjocky is offline
 
Join Date: Jun 2013
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 07-30-2014, 03:34 AM
Dead Eddie's Avatar
Dead Eddie Dead Eddie is offline
 
Join Date: Apr 2004
Location: at Home...
Posts: 196
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #3  
Old 07-30-2014, 10:34 PM
webjocky webjocky is offline
 
Join Date: Jun 2013
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dead Eddie View Post
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 View Post
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 View Post
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 View Post
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 View Post
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?)
Reply With Quote
  #4  
Old 08-01-2014, 03:24 AM
Dead Eddie's Avatar
Dead Eddie Dead Eddie is offline
 
Join Date: Apr 2004
Location: at Home...
Posts: 196
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by webjocky View Post
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 View Post
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 View Post
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 View Post
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 View Post
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 View Post
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.
Reply With Quote
Благодарность от:
tbworld
  #5  
Old 08-01-2014, 07:58 AM
webjocky webjocky is offline
 
Join Date: Jun 2013
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dead Eddie View Post
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 View Post
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 View Post
You asked for a different way, without manual file edits.
Tuch?


Quote:
Originally Posted by Dead Eddie View Post
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 View Post
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 View Post
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 View Post
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:
Reply With Quote
  #6  
Old 08-05-2014, 10:13 PM
Dead Eddie's Avatar
Dead Eddie Dead Eddie is offline
 
Join Date: Apr 2004
Location: at Home...
Posts: 196
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by webjocky View Post
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 View Post
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 View Post
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.
Reply With Quote
  #7  
Old 08-06-2014, 01:43 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Originally Posted by Dead Eddie
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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:05 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04410 seconds
  • Memory Usage 2,297KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (21)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (1)post_thanks_box_bit
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete