View Full Version : Automated Thread Prefixes
iNate19
09-10-2016, 03:27 PM
I was presented an idea and have been racking my brain trying to figure out how to pull it off.
I need to find a way to have Automated Thread Prefixes for a specific forum, according to thread views.
For instance, if a particular thread reaches 100 views... Then the thread prefix automatically becomes "Title 1"; then if it reaches 500 views it becomes "Title 2".
Any ideas?
MarkFL
09-10-2016, 06:03 PM
Create a new plugin hooked at "cron_script_cleanup_hourly" with the following code:
global $vbulletin, $db;
$fids = '1,2,3';
$title1 = 'title_1';
$title2 = 'title_2';
$v_threads = $vbulletin->db->query_read("
SELECT thread.*
FROM " . TABLE_PREFIX . "thread AS thread
WHERE views > 99
AND forumid IN (" . $fids . ")
");
while ($v_thread = $vbulletin->db->fetch_array($v_threads))
{
$newprefix = '';
if (($vthread['views'] < 500) AND ($vthread['prefixid'] != $title1))
{
$newprefix = $title1;
}
elseif ($vthread['views'] > 499) AND ($vthread['prefixid'] != $title2))
{
$newprefix = $title2;
}
if ($newprefix)
{
$dataman =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$dataman->set_existing($v_thread);
$dataman->set('prefixid', $newprefix);
$dataman->save();
unset($dataman);
build_forum_counters($v_thread['forumid']);
build_thread_counters($v_thread['threadid']);
}
}
Now, in the line:
$fids = '1,2,3';
Input the comma-delimited list of forumids in which you wish this to happen.
In the lines:
$title1 = 'title_1';
$title2 = 'title_2';
replace 'title_1' and 'title_2' with the ids of the prefixes you have defined for this purpose.
Note: I haven't tested this, but it is based on a plugin from one of my products I use at MHB. Please let me know if you have any issues with it. :)
iNate19
09-10-2016, 06:55 PM
Create a new plugin hooked at "cron_script_cleanup_hourly" with the following code:
global $vbulletin, $db;
$fids = '1,2,3';
$title1 = 'title_1';
$title2 = 'title_2';
$v_threads = $vbulletin->db->query_read("
SELECT thread.*
FROM " . TABLE_PREFIX . "thread AS thread
WHERE views > 99
AND forumid IN (" . $fids . ")
");
while ($v_thread = $vbulletin->db->fetch_array($v_threads))
{
$newprefix = '';
if (($vthread['views'] < 500) AND ($vthread['prefixid'] != $title1))
{
$newprefix = $title1;
}
elseif ($vthread['views'] > 499) AND ($vthread['prefixid'] != $title2))
{
$newprefix = $title2;
}
if ($newprefix)
{
$dataman =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$dataman->set_existing($v_thread);
$dataman->set('prefixid', $newprefix);
$dataman->save();
unset($dataman);
build_forum_counters($v_thread['forumid']);
build_thread_counters($v_thread['threadid']);
}
}
Now, in the line:
$fids = '1,2,3';
Input the comma-delimited list of forumids in which you wish this to happen.
In the lines:
$title1 = 'title_1';
$title2 = 'title_2';
replace 'title_1' and 'title_2' with the ids of the prefixes you have defined for this purpose.
Note: I haven't tested this, but it is based on a plugin from one of my products I use at MHB. Please let me know if you have any issues with it. :)
Appreciate it. I'll try it out and let you know
Paul M
09-10-2016, 10:30 PM
You could also do it a completely different way (in real time) by having some code on a reply hook that checks the reply count and updates the prefix as required.
MarkFL
09-11-2016, 02:29 AM
You could also do it a completely different way (in real time) by having some code on a reply hook that checks the reply count and updates the prefix as required.
The OP wants it to be based on views instead of replies, however, the code could be on a showthread hook instead to do it in real time. :)
Paul M
09-11-2016, 12:53 PM
Views ? oh, I didnt notice that. Strange thing to base it on, very easily abused.
Still, yeah, same thing, different hook.
iNate19
09-17-2016, 09:23 PM
Views ? oh, I didnt notice that. Strange thing to base it on, very easily abused.
Still, yeah, same thing, different hook.
Good point, how would I change it to replies instead of views?
MarkFL
09-17-2016, 09:33 PM
If you are using my cron-based approach, then change all instances of $v_thread['views'] to $v_thread['replycount'].
iNate19
09-17-2016, 10:21 PM
If you are using my cron-based approach, then change all instances of $v_thread['views'] to $v_thread['replycount'].
Awesome, thank you
--------------- Added 1474160516 at 1474160516 ---------------
If you are using my cron-based approach, then change all instances of $v_thread['views'] to $v_thread['replycount'].
I'm testing the View code and it doesn't seem to be working, plug in is active.
--------------- Added 1474160680 at 1474160680 ---------------
global $vbulletin, $db;
$fids = '36';
$title1 = 'Bronze';
$title2 = 'Silver';
$title3 = 'Gold';
$title4 = 'Platinum';
$title5 = 'Diamond';
$v_threads = $vbulletin->db->query_read("
SELECT thread.*
FROM " . TABLE_PREFIX . "thread AS thread
WHERE views > 99
AND forumid IN (" . $fids . ")
");
while ($v_thread = $vbulletin->db->fetch_array($v_threads))
{
$newprefix = '';
if (($vthread['views'] < 249) AND ($vthread['Bronze'] != $title1))
{
$newprefix = $title1;
}
elseif ($vthread['views'] < 499) AND ($vthread['Silver'] != $title2))
{
$newprefix = $title2;
}
elseif ($vthread['views'] < 999) AND ($vthread['Gold'] != $title3))
{
$newprefix = $title3;
}
elseif ($vthread['views'] < 2499) AND ($vthread['Platinum'] != $title4))
{
$newprefix = $title4;
}
elseif ($vthread['views'] > 2500) AND ($vthread['Diamond'] != $title5))
{
$newprefix = $title5;
}
if ($newprefix)
{
$dataman =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$dataman->set_existing($v_thread);
$dataman->set('prefixid', $newprefix);
$dataman->save();
unset($dataman);
build_forum_counters($v_thread['forumid']);
build_thread_counters($v_thread['threadid']);
}
}
MarkFL
09-18-2016, 12:27 AM
Did you manually run the cron job, or wait for it to run?
Paul M
09-18-2016, 02:44 PM
I think you will need to update this ;
SELECT thread.*
FROM " . TABLE_PREFIX . "thread AS thread
WHERE views > 99
AND forumid IN (" . $fids . ")
MarkFL
09-18-2016, 02:52 PM
I think you will need to update this ;
SELECT thread.*
FROM " . TABLE_PREFIX . "thread AS thread
WHERE views > 99
AND forumid IN (" . $fids . ")
Good catch, Paul. Yes, change "views" to "replycount" as well.
iNate19
09-18-2016, 06:33 PM
Good catch, Paul. Yes, change "views" to "replycount" as well.
I was testing it on the views option instead of reply count.
Also, I waited for the cron to run in its own for over 48 hours and nothing happened.
MarkFL
09-19-2016, 02:17 AM
It appears that, in the last code you posted, the elseif conditions need opening parens in front of $vthread['views'].
iNate19
09-19-2016, 01:41 PM
It appears that, in the last code you posted, the elseif conditions need opening parens in front of $vthread['views'].
????
MarkFL
09-19-2016, 02:07 PM
Look at the lines you posted of the form:
elseif ($vthread['views'] < 499) AND ($vthread['Silver'] != $title2))
Those need to have this form:
elseif (($vthread['views'] < 499) AND ($vthread['Silver'] != $title2))
iNate19
09-19-2016, 08:15 PM
Look at the lines you posted of the form:
elseif ($vthread['views'] < 499) AND ($vthread['Silver'] != $title2))
Those need to have this form:
elseif (($vthread['views'] < 499) AND ($vthread['Silver'] != $title2))
I made these corrections to the code I recently posted and have it working in a test forum, unfortunately only the "Bronze" prefix is working. It does not change to the next prefix after the thread views reach the next number
MarkFL
09-19-2016, 09:14 PM
The name of the array being used in the while loop is $v_thread, not $vthread. That was a typo I introduced in my original code.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.