Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Add options per forum
Logikos
Join Date: Jan 2003
Posts: 2,924

 

Show Printable Version Email this Page Subscription
Logikos Logikos is offline 08-01-2005, 10:00 PM

What this is
This guide will teach you to use the hooks system to add options to your admincp/forum.php page. One finished, you will be able to add new options to your forum with just a few lines of code.

Don't understand?
Ever wanted to turn something on, but only in one of your forums? For example, lets say you want to execute code, but only in forum I.D. 2, 16, and 45.

Lets begin!
In this tutorial we will assume that you want a yes or no option; in order to enable/disable some code. In order to do that we first need to create a new row in the database. This will hold the information of which forums will be enabled/disabled. Always remember that '1' is considered as on, or enabled. And that '0' is considered off, or disabled.

Please make sure this is all done on a test forum!

We have to store the data!
Run this SQL Query:
[sql]
ALTER TABLE forum ADD (
var smallint(3) unsigned not null default ''
)
[/sql]

Var = The name of the row in the database. This should be a name that will describe your system in one word. For example. In my vB Category Icons hack. This row is named 'forumhomeicon'

Now that we have added our new row named 'var'. We now have to add the on/off option in the forums manager area of the admin control panel.

Add the option in the ACP
To add this new option in the ACP we need to create a new hook and add some code to that hook.

The hook name should be: forumadmin_edit_form
And the code should be:
PHP Code:
print_input_row($vbphrase['your_phrase'], 'forum[var]'$forum['var']); 
Notice the 'var'? Remember, that's the row name!
That will actually add the yes/no row to all your forums in the admincp. So when you click on the save button, it will add your selection to the database.

But how does it know which row to add it to? Glad you asked.

You have to create one more hook!
The hook name should be: forumdata_start
And the code to add there is the following
PHP Code:
$this->validfields['var'] = array(TYPE_STRREQ_NO); 
Notice the var again? That's telling it which row to add it to.

I want to add more then just one option!
Then you will need to repeat this tutorial for each option you would like to have.

Now that you have saved both hooks. You can now use the following code in any of your hooks.

PHP Code:
if ($foruminfo['var'] == 1)
{
     
// your code here

In templates you would use

HTML Code:
<if condition="$foruminfo['var'] == 1">
     <!-- Your Code Here -->
</if>
Big Tip:
If you have 2 or more options being added to the forums, you can place all the code in each hook. For example:

Hookname: forumadmin_edit_form
Code:
PHP Code:
print_input_row($vbphrase['your_phrase'], 'forum[var1]'$forum['var1']);
print_input_row($vbphrase['your_phrase'], 'forum[var2]'$forum['var2']); 
Hook Name: forumdata_start
Code:
PHP Code:
$this->validfields['var1'] = array(TYPE_STRREQ_NO);
$this->validfields['var2'] = array(TYPE_STRREQ_NO); 
You don't have to keep creating new hooks for more options for the same hack. Is better to only create hooks for separate hacks.



Custom Fields
The following fields can also be used.
PHP Code:
// This will print an input form. Good for titles, and such.
print_input_row($vbphrase['your_phrase'], 'forum[var]'$forum['var']); 
PHP Code:
//This will print a yes or no row
print_yes_no_row($vbphrase['your_phrase'], 'forum[var]'$forum['var']); 
PHP Code:
//This will print a text area. Good for descriptions
print_textarea_row($vbphrase['your_phrase'], 'forum[var]'$forum['var']); 
There are more that can be used. When I have some more time I will add them all here.

This tutorial was created for a member who needed to know how to do this exact thing, so I figured I would teach everyone.
Reply With Quote
  #12  
Old 08-02-2005, 02:20 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
When i said incorrect, I meant not to your coding standards.
Jeez. Not mine... Jelsoft's.

Quote:
Wort Case scenario: Your Hack uses the next available Bit in forumoptions for "Show Quick Stats for this Forum".
Now the next vBulletin Version comes and redifines this Bit to "Prune this Forum every 24 hours".
Now all users of this Hack have the Bit set ...
The hack was not tested on the new version therefore it should not be installed.

Quote:
Well, what does adding a custom field do?
It adds a record to Table profilefield and alters table userfield to have a new MEDIUMTEXT columd fieldxx.
This is just an easy-to-use frontend to alter the Database, so where is the difference?
Difference is the errors on the user side.

Quote:
Keeping the Product Manager in mind, such DB alterations can be done easily, without the User having to know anything about running queries.
That's true. I still have to get used to the existence of that manager.

Oh, there is an array called $vbulletin->bf_misc_forumoptions, but I cannot find out how is it populated.
Reply With Quote
  #13  
Old 08-02-2005, 02:32 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dark Visor
The hack was not tested on the new version therefore it should not be installed.
You don't seem to see the Problem:
The Hack was installed on the previous Version, which means the Bit is currently set.
No matter if the Users reinstalls it on the new Version (without verified compatiablilty or not), the Bit is still set.[/QUOTE]

Quote:
Oh, there is an array called $vbulletin->bf_misc_forumoptions, but I cannot find out how is it populated.
Refer to my Usergroup Permissions How-To
Reply With Quote
  #14  
Old 08-02-2005, 02:45 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
The Hack was installed on the previous Version, which means the Bit is currently set.
No matter if the Users reinstalls it on the new Version (without verified compatiablilty or not), the Bit is still set.
[/QUOTE]

Ahhh... Crap. Yes, you are right. Solution:
Upon upgrade, let upgrade.php remove all the new bits from the data storage.
Reply With Quote
  #15  
Old 08-02-2005, 02:57 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That would mean Jelsoft taking responsiblity for custom Code - this won't happen
It's our responsibility to avoid such things.
Reply With Quote
  #16  
Old 08-02-2005, 03:01 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
That would mean Jelsoft taking responsiblity for custom Code - this won't happen
It's our responsibility to avoid such things.
No, it would mean Jelsoft taking the measures to avoid the possible negative outside influence of any previously installed hackware. :P

Would you please change the thread's title and prefix it with [How-To]? That way all the how to threads stand out Thx.
Reply With Quote
  #17  
Old 08-02-2005, 05:15 PM
Revan's Avatar
Revan Revan is offline
 
Join Date: Jan 2004
Location: Norway
Posts: 1,671
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

[sql]var smallint(3) not null default ''[/sql]shouldnt it be[sql]var smallint(3) unsigned not null default ''[/sql]?
Reply With Quote
  #18  
Old 08-02-2005, 07:29 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Unsigned woul be better, since you will be able to store more options.
Reply With Quote
  #19  
Old 08-02-2005, 10:54 PM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dark Visor
No, it would mean Jelsoft taking the measures to avoid the possible negative outside influence of any previously installed hackware. :P

Would you please change the thread's title and prefix it with [How-To]? That way all the how to threads stand out Thx.
Jelsoft do not support modified boards - This would come under such a heading, therefore since you do not need to alter the bitfields with a standard installation of vBulletin, unless they alter their own bitfields in an upgrade they should not have to cater for such an scenario

Satan
Reply With Quote
  #20  
Old 08-02-2005, 11:18 PM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dark Visor
Would you please change the thread's title and prefix it with [How-To]? That way all the how to threads stand out Thx.
Read the first 2 words in the thread title. How to add options per forum.

Thanks Revan, fixed first post.
Reply With Quote
  #21  
Old 08-03-2005, 12:06 AM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How-To without braces tho
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 11:44 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.04577 seconds
  • Memory Usage 2,332KB
  • Queries Executed 25 (?)
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)bbcode_html
  • (8)bbcode_php
  • (10)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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_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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete