[3.8.0] Thread Promotion System

ChopSuey

New Member
Thread Promotion System
Developed By: Idan B.


First thing i'll mention i'm aware it a while since last i was active here (due to personal reasons), but like said on some post made here, i'll try my best to be active here again & let the fun coding begin .

1. Notes:
This hack was developed to fill request made on our community forum by ConfusedCartman @ [PAID REQUEST] Thread Promotion System
And NO MONEY was charged for this develop - this hack was developed as free service to our community. Should anyone wish to donate for support efforts he is more than welcome to do so.

2. Description & Usage:
Thread Promotion Sytem hack will allow the forum admin to set auto promotion system that will move thread from Forum A to Forum B once passed certain replycount.
Usage Example: "promote" popular threads to a subforum, so that new threads do not get drowned out by popular ones.

3. Installation:
Please click INSTALL.
Installation is pretty easy - just download & install:
Goto: AdminCP->Plugin System->Manage Products : Choose "Add/Import Product" and import this product xml (product-thread_promotion.xml)
4. Upgrade From Older Version:
1. uninstall modification.
2. install new version as described in previous section.

5. Configuration:
Once installed, the "Forum Manger" under admincp will have extra section for each forum:
Section name: "Thread Promotion System"
Enabled ? - Yes/No
Reply Count - Text (INT)
Forum Target - Selection box
6. Copyright:
You may modify the code to further custom your own needs, but may not redistribute it as your own hack.
You are not allowed to re-post this elsewhere without my permissions.
Respect coder's copyright & should you modify the code to fit your needs, leave credit of coder as is.
7. Known Bugs:
None at the moment.
Should any will be found this will be updated here.

8. TO-DO's LIST (Next Versions):
Allow to add redirect thread on original forum.
Allow to set redirect on forum category instead of configuring this per each forum.
Allow to promote vs. matching of cutom field (such as date).
9. Extras (Tutorials & Guides):
This modification was "recorded" with screenshot through entire development stages.
You can find a detailed How-To tutorial, showing step-by-step development of this hack.

Hello everyone,

This guide has been long due. My previous guide [How-To] Simple hack development stages - vBulletin Modifications got alot of good feedback from this community, but it lacked more advanced topics.

This guide is going to be first of many to come in near future, that will guide one through complete hack development, from concept to develop & actual coding stages on the vbulletin system.
My goal in these guides is to give people a complete in-depth view of steps made so they may have refrence of how's it being done.

This guide is complete walkthrough of development made of my last hack release Miscellaneous Hacks - Thread Promotion System - vBulletin Modifications that was developed according to request made @ [PAID REQUEST] Thread Promotion System - vBulletin Modifications

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:
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:
phpmyadminadd3newfields.jpg

And screen after fill these:
fixedwidth.jpg

Once made, you'll see this screen:
fixedwidth2.jpg

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. Place admincp to debug mode:
See my previous simple guide on details how it's made.
This can be done either from config.php or install some plugin for it.

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

Select "Add/Import Product":
admincp2addnewproduct.jpg

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

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


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":
admincp5pluginmanager.jpg

Then select "Add new plugin":
admincp6addnewplugin.jpg

Then we fill the fields as shown in this picture:
admincp7placenewplugind.jpg


The code that was placed onto this hook is:
PHP:
// 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:
  • The list of common print_xxxx functions used on admincp can be found on some older HOW-TO i wrote back while ago @ [How-To] usefull admincp print_xxx functions - vBulletin Modifications
  • In the above example i've also used function i didnt cover in the previous tutorial, 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 incase 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:
admincp8newpluginsaveda.jpg


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:
admincp85addmaincode.jpg

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.
admincp9newpluginforaja.jpg


At this point all plugins should be complete:
admincp10whenallplugins.jpg


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:
admincp11addinstallunin.jpg

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.
phpmyadmindropfieldstog.jpg

Then you will see this:
phpmyadmindeletequeryfo.jpg


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


All thats left now is to export & save :)

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


Then save it on your directory:
admincp14savehackandpos.jpg


That's IT !! :)
Congratulations, if you followed all this (long) guide, you have now made your hack successfully :)

Dont forget to share back with community your work.
I hope you appreciate the effort made here in writing this long tutorial (took me about 3 hours to write it). I did my best to cover all aspects & stages made, step-by-step, with screenshots for every step.
If anyone has any further questions, post them here & i will help gladly.

Enjoy :cool:
 
Top