Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2014, 07:01 PM
josh_krz josh_krz is offline
 
Join Date: Feb 2012
Location: United Kingdom
Posts: 42
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Insert custom thread field into the database

Hi there,

I have a good understanding of the vB templating system and PHP knowledge but I am having trouble working out how I could add a custom field on my thread pages to a new column in the "thread" table.

I know how I could add info to the table using PHP prepared statements but apparently it is better to use vBulletins own database classes however I can't find information on it anywhere!

I also don't know how I would get the generated thread ID to use as a reference when inserting this info or what my custom field would be called, I can't just use $POST['field']. These variables seem to be a mystery.

Advanced vBulletin documentation seems to be pretty scarce am I supposed to guess these variables and class names :S.

Thank you.
Reply With Quote
  #2  
Old 01-30-2014, 08:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know of any documentation, but I threw together a bare bones example of adding a field to the thread table, and I've attached the product xml (you'd only want to import this to a test forum). Two things this example doesn't do: create the database field and add the input field to the newthread template. I called my new field "test" and made it a string, so to use this example product you'd need to add a field to your thread table called "test", and add an input control to the form in the newthread template, and set name="test". Alternatively you could edit the code and change the field name and type to something else.

If you have any questions please ask, but if you don't already have the vb source code set up so you can search it, you should do that. If you search for the hook names you can see a little about what's going on at the point where each plugin in executed.
Attached Files
File Type: xml product-add_new_thread_field.xml (1.4 KB, 69 views)
Reply With Quote
Благодарность от:
josh_krz
  #3  
Old 01-30-2014, 09:30 PM
josh_krz josh_krz is offline
 
Join Date: Feb 2012
Location: United Kingdom
Posts: 42
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you kh99, so all I need to do is create the database column and add the field within the template for this to work?

Looking at that XML these things seems pretty straight forward, if there were some definite way to know what classes and functions to use

How do people learn how to code plugins, there must be some cache of resources somewhere outlining these things?

Thanks once again!
Reply With Quote
  #4  
Old 01-30-2014, 09:36 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No there is no tutorial, basically you have to know, php, html, css, and have a understanding of how vBulletin works. Then take it and put it all together.

PHP, basic guide: PHP 5 Tutorial

HTML basic guide: HTML Tutorial - (HTML5 Compliant)

CSS basic guide: CSS Tutorial

vBulletin basic mod guide: Creating a Product
Reply With Quote
Благодарность от:
josh_krz
  #5  
Old 01-30-2014, 10:07 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by josh_krz View Post
Thank you kh99, so all I need to do is create the database column and add the field within the template for this to work?
Right. Also, it should automatically be read in so in most places where you have a $threaddata array, your field value should be there. So for example if you wanted to display the value on the showthread page, you shouldn't need to do anything extra to read it from the database.

BTW, another thing this example doesn't handle is editing the thread.


Quote:
Looking at that XML these things seems pretty straight forward, if there were some definite way to know what classes and functions to use

How do people learn how to code plugins, there must be some cache of resources somewhere outlining these things?
Yeah, I don't know how most people learned, but I just started reading the code. For example if I wanted to add a field to a thread, I'd see that when I'm creating a new thread it goes to newthread.php, so I'd look at that to see what was going on (yeah, it's easy for me to say but I know it takes a lot of time).
Reply With Quote
Благодарность от:
josh_krz
  #6  
Old 01-31-2014, 05:15 PM
josh_krz josh_krz is offline
 
Join Date: Feb 2012
Location: United Kingdom
Posts: 42
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ozzy47 View Post
No there is no tutorial, basically you have to know, php, html, css, and have a understanding of how vBulletin works. Then take it and put it all together.
Thanks for your help but im already pretty comprehensive in PHP 5, HTML 5 and CSS 3. It's just the vBulletin part I thought would have been documented. That link is helpful though!

Quote:
Originally Posted by kh99 View Post
Right. Also, it should automatically be read in so in most places where you have a $threaddata array, your field value should be there. So for example if you wanted to display the value on the showthread page, you shouldn't need to do anything extra to read it from the database.

BTW, another thing this example doesn't handle is editing the thread.
I see so I would need to add a plugin that also reads the current info from the database and adds it in when editing?

Quote:
Originally Posted by kh99 View Post
Yeah, I don't know how most people learned, but I just started reading the code. For example if I wanted to add a field to a thread, I'd see that when I'm creating a new thread it goes to newthread.php, so I'd look at that to see what was going on (yeah, it's easy for me to say but I know it takes a lot of time).
I was initially going to do this but I don't have a test vBulletin site to do this on just my production one. I was worried about messing my site up.

I will take a look at some of the internal code and see what I can make of it. Thank you very much!
Reply With Quote
  #7  
Old 04-04-2016, 06:53 PM
grey_goose grey_goose is offline
 
Join Date: Jun 2009
Posts: 284
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This seems fairly straightforward but I guess I'm messing something up.

1. I've added 'expenditure' to the 'post' table.
2. I'd like to be able to to add/update this field when replies to a thread are made.

newpost_process
PHP Code:
if ($type == 'thread')
{
    
$dataman->setr('expenditure'$post['expenditure']);

newreply_post_start
PHP Code:
$vbulletin->input->clean_gpc('p''expenditure'TYPE_STR);
$newpost['expenditure'] = $vbulletin->GPC['expenditure']; 
newreply_start
PHP Code:
$this->validfields['expenditure'] = array(TYPE_STR,  REQ_NO); 
newreply template
PHP Code:
<input type="text" name="expenditure" /> 
When I look at my post table, there's no values being added to expenditures. I also tried:

PHP Code:
$expenditure $vbulletin->input->clean_gpc('p'"expenditure"TYPE_STR);
$vbulletin->post['expenditure'] += $expenditure
Where am I going wrong?
Reply With Quote
Reply


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:59 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.04280 seconds
  • Memory Usage 2,265KB
  • Queries Executed 14 (?)
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
  • (5)bbcode_php
  • (5)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
  • (3)post_thanks_box_bit
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (1)postbit_attachment
  • (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
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete