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
  #42  
Old 03-10-2006, 01:08 PM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Opps, fixed post #39.
Reply With Quote
  #43  
Old 04-01-2006, 09:29 PM
masterross's Avatar
masterross masterross is offline
 
Join Date: Nov 2005
Location: Bulgaria
Posts: 315
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hello,

i used:

PHP Code:
$db->query("ALTER TABLE " TABLE_PREFIX "user ADD maxthread INT( 10 ) DEFAULT '0' NOT NULL");
$db->query("ALTER TABLE " TABLE_PREFIX "user ADD maxpost INT( 10 ) DEFAULT '0' NOT NULL"); 
and

PHP Code:
<plugin active="1">
<
title>Maximum New Threads/Replies</title
<
hookname>useradmin_edit_start</hookname
<
phpcode>
<![
CDATA
$this->validfields['maxthread'] = array(TYPE_STRREQ_NO); 
$this->validfields['maxtpost'] = array(TYPE_STRREQ_NO); 
]]> 
</
phpcode
</
plugin
PHP Code:
 <plugin active="1">
<
title>Max New Threads/Replies</title>
<
hookname>useradmin_edit_column1</hookname>
<
phpcode><![CDATA[global $getperms$user$vbulletin$forum;
print_table_header($vbphrase['max_user_threads_desc']);
print_input_row($vbphrase['max_thread'], 'forum[maxthread]'$forum['maxthread']);
print_input_row($vbphrase['max_post'], 'forum[maxtpost]'$forum[maxpost]);]]>
</
phpcode>
 
</
plugin
PHP Code:
 <phrasetype name="Control Panel User Management" fieldname="cpuser">
<
phrase name="max_user_threads_desc"><![CDATA[Threads/Posts Limists]]></phrase>
<
phrase name="max_thread"><![CDATA[Maximum Threads]]></phrase>
<
phrase name="max_post"><![CDATA[Maximum Posts]]></phrase>
</
phrasetype
but i've got these errors:
PHP Code:
WarningProblem with method call please report this bug in \acp\user.php on line 554
 
Warning
Problem with method call please report this bug in \includes\class_hook.php on line 92
Warning
Problem with method call please report this bug in \acp\user.php on line 649
 
Warning
Problem with method call please report this bug in \includes\class_hook.php on line 92 
any hints?

thanks,
Ross
Reply With Quote
  #44  
Old 05-14-2006, 12:48 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice tutorial, but it does not provide for using bitfields xml and/or multiple settings within one db field.
I know how to do use bitfield xml with forum settings, if anyone wants a tutorial - I can post one.
Reply With Quote
  #45  
Old 05-18-2006, 05:30 AM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I would acually like to read that myself. Would you post a tutorial on how one can use bitfields per forum setting? Thanks!
Reply With Quote
  #46  
Old 10-10-2006, 09:37 PM
vietkieu_cz vietkieu_cz is offline
 
Join Date: Dec 2005
Posts: 120
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks I've done it
Reply With Quote
  #47  
Old 04-15-2007, 03:39 PM
Blaine0002's Avatar
Blaine0002 Blaine0002 is offline
 
Join Date: Jul 2003
Location: Wisconsin.
Posts: 1,350
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ive followed your code down to the pixel and whenever i try to post using a custom foruminfo in the hook newpost_complete, i get a 'you have already posted this message in the last 5 minutes' thing.
Reply With Quote
  #48  
Old 04-23-2007, 10:59 PM
tehQspm tehQspm is offline
 
Join Date: Mar 2007
Posts: 36
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have a problem with this. I can change the option but it doesn't actually store the data.

Where does the SQL query come in each time you change the option?
Reply With Quote
  #49  
Old 01-22-2008, 08:17 PM
vuiveclub vuiveclub is offline
 
Join Date: Dec 2006
Posts: 78
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This runs on vbb 3.6x only? I've tried on vbb 3.7 but didnt work!
Reply With Quote
  #50  
Old 02-20-2008, 01:54 PM
EnIgMa1234 EnIgMa1234 is offline
 
Join Date: Mar 2006
Location: .:: Ireland ::.
Posts: 1,306
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works fine on 3.7 for me
Reply With Quote
  #51  
Old 04-17-2008, 12:29 PM
Blaine0002's Avatar
Blaine0002 Blaine0002 is offline
 
Join Date: Jul 2003
Location: Wisconsin.
Posts: 1,350
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

figgerd' it out.
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:13 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.11934 seconds
  • Memory Usage 2,340KB
  • 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
  • (13)bbcode_php
  • (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
  • (2)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