vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Automated Thread Prefixes (https://vborg.vbsupport.ru/showthread.php?t=323446)

iNate19 09-10-2016 03:27 PM

Automated Thread Prefixes
 
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:

PHP 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'$vbulletinERRTYPE_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:

PHP Code:

$fids '1,2,3'

Input the comma-delimited list of forumids in which you wish this to happen.

In the lines:

PHP Code:

$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

Quote:

Originally Posted by MarkFL (Post 2575789)
Create a new plugin hooked at "cron_script_cleanup_hourly" with the following code:

PHP 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'$vbulletinERRTYPE_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:

PHP Code:

$fids '1,2,3'

Input the comma-delimited list of forumids in which you wish this to happen.

In the lines:

PHP Code:

$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

Quote:

Originally Posted by Paul M (Post 2575793)
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

Quote:

Originally Posted by Paul M (Post 2575801)
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

Quote:

Originally Posted by MarkFL (Post 2576025)
If you are using my cron-based approach, then change all instances of $v_thread['views'] to $v_thread['replycount'].

Awesome, thank you

--------------- Added [DATE]1474160516[/DATE] at [TIME]1474160516[/TIME] ---------------

Quote:

Originally Posted by MarkFL (Post 2576025)
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 [DATE]1474160680[/DATE] at [TIME]1474160680[/TIME] ---------------

PHP Code:

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'$vbulletinERRTYPE_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?


All times are GMT. The time now is 07:11 PM.

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.01317 seconds
  • Memory Usage 1,791KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete