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

Reply
 
Thread Tools
[How-To] Walkthrough of hack development & Coding Tips: Thread Promotion System
IdanB's Avatar
IdanB
Join Date: May 2009
Posts: 171

Electronics Engineer working as Software Developer. Knowledge of: C / C++ / C# / ASP.NET / PHP / TCL / VHDL. Active Staff & Coder position @ vBHackers.com

Israel
Show Printable Version Email this Page Subscription
IdanB IdanB is offline 05-09-2009, 10:00 PM

I've wrote this tutorial @ other modding community i'm member on few days ago. I wanted to share it with this community as well, so members that don't visit there can benefit from it here as well.

This tutorial will provide complete walk-through of the development made to create "Thread Promotion system" modification (can be found @ https://vborg.vbsupport.ru/showthread.php?p=1808040)

So, lets get going:

This guide assumes the following:
  • You have installed a phpadmin on your server & have some basic knowlege of how to use it (or know basic MYSQL syntax & how ot add/delete fields into tables)
  • You have some knowledge of basic php coding. I will explain code as possible, but some basic syntax knowledge is required.

Development stages:
  1. Have modification idea & understand the way you wish to implant it on the forum.
  2. Prepare database structure required.
  3. Place admincp into debug mode.
  4. Create Product.
  5. Add Plugins.
  6. Testing of code - is it working way we wanted.
  7. Add install/uninstall code.
  8. Export & save final product.
  9. Share back with community.

1. Modification Idea:
This modification was as reply to request made.
as request mentioned, he wanted a system that would allow him to set forum as being able to have "thread promotion" inside it. Which actually means once reply count passed XX it will automatically moved from forum A to B.
The above description tells us 2 things:
  1. This "feature" should be per forum, as some forums may have it & some may not.
  2. Possible "info" required to "drive logic" behind it is:
    • Is it enabled for the selected forum ?
    • What is the reply count (that once passed should be moved)
    • What is the target forum that it should be moved to.

Analyze & Process Information:
(1) Mod appearance on admincp (& Hook Location):
With above said, right now the coder should "see" the modification in his mind. Knowing you'll add some section under "Forum Manager" as you want it to be intergated in way every new forum add or edit will allow you to set it. & you need some code to perform the check.
This will later on be "translated" to "forumadmin_edit_form" hook code.

(2) Mod Core Code (& Hook Location):
Since idea speaks of "if reply count > XXX" common sense suggest this should be implanted right after a person finished to post new reply. As right then we can "ask" what was the reply number & have we passed the mark we aimed for. And if we did - do your "magic".
This will later on be "translated" to "newreply_post_complete" hook code.

(3) Possible pitfalls & consideration points in code:
  1. Reply has 2 seperate engines - add reply (own page) & quick reply (AJAX).
  2. Once thread moved, the forum counters are no longer updated (link to last thrread on forum home, etc.)
  3. Data Manager needs to be told of new fields we add to the forum, so they may be "recognized" by the forum engine.
(4) Lets discuss details & DB structure:
In general you should know the structure of your vbulletin (at least the common tables that construct it).
In our case: we are most likely to need some info (either fetch or set) from 3 tables : "forum", "thread", "post".
these tables have parent-child relationshionship structure similar to following: forum -> thread -> posts
(thread has forum parent id, post has thread parent id)
  • table "forum" holds the forums listing - there we will need to update the counters/stats (last post, last poster, thread/post count, etc.)
  • table "thread" holds the threads posted. Each thread has refrenced to his "parent forum". So any "move" operaton invovles replaced "parent id" from forum A to forum B".
  • table "post" will be needed to gather information about the last post made, as when we move the thread, we now want the source forum to link to the other most recent post. So any poster information should be in here.
2. Prepare DB Changes:
As reminder, we came to conclusion we will need the following information "present" for us:
  • Is it enabled for the selected forum ?
  • What is the reply count (that once passed should be moved)
  • What is the target forum that it should be moved to.
This "translates" to the following:
"Enable" filed that will act as BOOLEAN (true/falsE).
"Reply Count" field of int type.
"Forum ID" field of int type (says to us which is the target forum to be moved thereads onto.

Lets get to business, logon on your phpmyadmin, go to table "forum" & add 3 new fields:

And screen after fill these:

Once made, you'll see this screen:

Please "save" the (copy & paste to some place, will be used later) the ALTER query, as we will need it to the install code:
The query should be like the following:
Code:
ALTER TABLE `forum` ADD `enable_thread_promotion` TINYINT( 1 ) NOT NULL ,
ADD `reply_count_for_promotion` INT NOT NULL ,
ADD `target_forum_id` INT NOT NULL
3. Configure admincp to debug mode:
This can be done either from config.php or install some plugin for it.
there are several debug mode hacks, just install one of them.

4. Create Product:
Go to Admincp, from side nav select "Plugin & Products" -> "Manage Products" :

Select "Add/Import Product":

On the "Add New Product" screen fill the information as demonstrated in the following picture:

When done, click "Save".
Once product added you should see following screen:


5. Add Plugins:
As discussed @ section 1, we will have in this modification 4 plugins/hooks.
  1. Admincp code - placed under the "forumadmin_edit_form" allowing the admin screen options.
  2. Data Manger fields support - since we are adding new fields here, we need to tell the vbulletin we are using these fields. For that purpose we will be using the "forumdata_start" hook (see code below later on)
  3. Main Core Code - placed under the "newreply_post_complete" hook. This will allow to place code logic there & check the reply count & perform changes accordingly.
  4. Main Core Code (exact copy paste) for AJAX support - same code as above hook, just copied onto "newreply_post_ajax" to support AJAX.

So, lets start add them one by one:
Admincp hook:
From Admincp: "Plugins & Products" -> "Plugin Manager":

Then select "Add new plugin":

Then we fill the fields as shown in this picture:


The code that was placed onto this hook is:
PHP Code:
// Header
print_table_header('Thread Promotion System');

// Enabled ?
print_yes_no_row('Enabled ?''forum[enable_thread_promotion]'$forum[enable_thread_promotion]);

// Reply Count Settings
print_input_row('Reply Count''forum[reply_count_for_promotion]'$forum[reply_count_for_promotion]);

// List all possible target forums (that are not this forum)
if ( $forum[forumid] == "")
{
    
// List all - this is new forum add
    
$query "SELECT forumid, title FROM forum";  
}
else
{
   
// This is edit - List all other than this forum id
    
$query "SELECT forumid, title FROM forum WHERE forumid<>$forum[forumid]";  
}


$qry=$db->query_read($query);
while (
$result $db->fetch_array($qry)) 

        
$arr[$result ['forumid']] = $result ['title']; 

print_select_row("Forum Target",'forum[target_forum_id]',$arr,$forum[target_forum_id]); 
Notes Regarding Code:
  • In the above example i've also used function called print_select_row, which allow to create a "combo-box" (selection box). The function expect to be passed with array, holding key -> value pairs. In the above code, as you can see i'm performing SQL query to get list of all forum title & their id, while excluding the forum itself (as it make no sense to allow promote from forum to itself).
  • the $forum[forumid] check for null, is in case this is new forum add, then no forumid is available, in that case, we allow to list all currently available forums.
Click "Save" to save plugin.

Data Manger Field Support hook:
In the same way add another plugin, this time select "forumdata_start" as hook location.
In there add code as shown in the next picture:


Core Code hook:
In the same way add another plugin, this time select "newreply_post_complete" as hook location.
In there add code as shown in the next picture:

I dont want to make this "monster post", You can get full source on the modification, i'll just put the following notes:
  1. First block fetch all information of forum this post was made on. Forum ID is located on $threadinfo[forumid].
  2. Later on 2 condition are made: enabled & if current post count > what we configured. Note the current reply count is located on var $threadinfo[replycount] & that this is zero-based ! (first reply returns in there 0 !!)
  3. I update the "thread" table, replacing "forumid" with new one.
  4. Update stats counters on "forum" table (based on info gathering, made on several queries).
  5. There are several checks to make sure numbers are indeed numbers. I used php function called is_numeric() that verify var holds numbers only.
  6. Pay attention all string fields has qoute wrapping around them on query (used escape chars \" on query lines)

Core Code AJAX hook:
This is exact copy & paste of previosu hook, just place it on "newreply_post_ajax" as hook location.


At this point all plugins should be complete:


6. Testing Code:
Check the code on your forum. Through it you'll find pitfall you didnt think about.
In this case for example the reply count was zero-based, so i had to add -1 factor on code. These sort of things can only be found while you "hands on" code & test it, so dont be afraid !

Also general tip, if certain code not working, try to place php die("soem text"); on certain key points to tell if the code executed till that point. That can help to debug certain things.

7. Add Install/Uninstall Code:
On Admincp go to "Plugin & Products" -> "Manage Products" & edit the current product we just did:

Now we'll add the install/uninstall code, which is the db changes (add fields for install & drop fields for uninstall).
Now it's time to use that ALTER query we wrote while back.
Note the DROP query can be obtained from phpmyadmin as well.

Then you will see this:


When you have both MYSQL queries we can add it to product as shown here:


All thats left now is to export & save

8. Export & save hack:
From "Product Manger" choose export as seen here:


Then save it on your directory:


That's it !!
Congratulations, if you followed all this (long) guide, you have now made your hack successfully
Don't forget to share back with community your work

I hope this guide has helped anyone out there that wanted to get into the modding & gets hands-on & start coding & was missing some pratical hand-on step-by-step tutorial..
If anyone has any further questions, post them here & i will help gladly.

Enjoy
Reply With Quote
  #12  
Old 11-13-2009, 10:02 AM
Carnage Carnage is offline
 
Join Date: Jan 2005
Location: uk
Posts: 760
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

if you wish to add options to the global settings thing here are three easy steps:

1. enable debug mode in the admincp
2. goto the options page that you use to modify settings
3. click the link to add new options/option groups
Reply With Quote
  #13  
Old 11-13-2009, 11:26 AM
mortezax's Avatar
mortezax mortezax is offline
 
Join Date: Aug 2008
Location: Persia
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thank you
Reply With Quote
  #14  
Old 09-04-2010, 05:17 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is great, I was looking for this for a year!
Reply With Quote
  #15  
Old 11-27-2010, 10:56 PM
kootta kootta is offline
 
Join Date: May 2009
Posts: 19
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

that's so nice informative post keep it up
Reply With Quote
  #16  
Old 04-04-2011, 06:47 PM
munnakv munnakv is offline
 
Join Date: Jun 2008
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just stumbled on this and bookmarked. Thanks for this. I will need it some time in the future.
Reply With Quote
  #17  
Old 09-27-2011, 02:03 PM
Maestro_xxx Maestro_xxx is offline
 
Join Date: Sep 2011
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice work truly 5/5
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:34 AM.


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.07090 seconds
  • Memory Usage 2,291KB
  • Queries Executed 21 (?)
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_code
  • (1)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
  • (1)pagenav_pagelink
  • (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
  • (6)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_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
  • 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_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