Thread: Forum Home Enhancements - Latest X Threads on Forum Home
View Single Post
  #52  
Old 07-11-2008, 12:18 PM
eviltechie eviltechie is offline
 
Join Date: Mar 2007
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice mod! Thx.

I made a couple modifications for my use, and figured I'd share in case anyone else wants to do similar. I wanted to display the latest threads based on the last post instead of the first. So, whenever a new post is made in a thread it jumps to the top of the list...and also displays the author as the most recent poster.

Here's my edited code, it replaces the Main Code plugin which runs on forumhome_start.

PHP Code:
// enable to run this script
if ($vbulletin->options['latest_thread_enabled'])
{
    
$db->hide_errors();
    global 
$vbulletin;

    
// forum permissions
    
$forumpermissions = array();
    foreach(
$vbulletin->forumcache AS $forum)
    {
        
$forumpermissions[$forum["forumid"]] = fetch_permissions($forum['forumid']);
        if ((!(
$forumpermissions[$forum["forumid"]] & $vbulletin->bf_ugp_forumpermissions['canview'])) OR (!($forum['options'] & $vbulletin->bf_misc_forumoptions['active']) AND !$vbulletin->options['showprivateforums'] AND !in_array($vbulletin->userinfo['usergroupid'], array(5,6,7))))
        {
            
$forumids .= ','.$forum['forumid'];
        }
    }
    if (
$vbulletin->options['latest_thread_exclude']!='')
    {
        
$forumids .= ','.$vbulletin->options['latest_thread_exclude'];
    }
    
$forumids substr($forumids1);
    if (
$forumids!='')
    {
        
$latest_and "thread.forumid NOT IN($forumids)";
        
$latest_and_1 "forum.forumid NOT IN($forumids)";
    }
    
    
// converts options to nice variables
    
$limit $vbulletin->options['latest_thread_number'];
    
    
// query to get the last posts
    
$query $vbulletin->db->query_read("
        SELECT
            thread.forumid as forumid, thread.visible, thread.title as thread_title, thread.threadid as threadid, post.username as username, post.userid as userid, thread.dateline as date,
            forum.title as forum_title,
            post.postid, post.pagetext as pagetext
        FROM " 
TABLE_PREFIX "thread as thread
        LEFT JOIN " 
TABLE_PREFIX "post as post on (thread.lastpostid = post.postid)
        LEFT JOIN " 
TABLE_PREFIX "forum as forum on (thread.forumid = forum.forumid)
        WHERE thread.visible = 1 AND 
$latest_and AND $latest_and_1
        ORDER BY postid DESC
        LIMIT 
$limit"
    
);

    
// reset variables
    
$counter 0;
    
$latest_post_bits '';
    
    while (
$row $vbulletin->db->fetch_array($query))
    {
        
// allow to use alternate color in rows
        
require_once(DIR '/includes/functions.php');
        
exec_switch_bg();
        
        
// strips the bbcode out of the post
        
$row['pagetext'] = strip_bbcode($row['pagetext'], $stripquotes true$fast_and_dirty false$showlinks true);
        
        
// adds the cutoff ... with substr
        
$row['pagetext'] = substr($row['pagetext'], 0$vbulletin->options['latest_thread_cut']) . '...';

        
// convert pagetext to nice looking variable
        
$pagetext $row['pagetext'];
        
$username $row['username'];
        
$userid $row['userid'];
        
$forumid $row['forumid'];
        
$threadid $row['threadid'];
        
$postid $row['postid'];
        
$forumtitle $row['forum_title'];
        
$threadtitle $row['thread_title'];
        
$date vbdate($vbulletin->options['dateformat'], $row['date'], true);
        
$time vbdate($vbulletin->options['timeformat'], $row['date']);
        
        
// increments the counter +1
        
$show['latest_break'] = $counter++;
        
        eval(
'$latest_post_bits .= "' fetch_template('forumhome_latest_thread_bit') . '";');
    }
    
    
// free the query
    
$vbulletin->db->free_result($query);
    
    eval(
'$latest = "' fetch_template('forumhome_latest_thread') . '";');
    
    switch (
$vbulletin->options['latest_thread_location'])
        {
            case 
0$latest_location '$navbar'; break;
            case 
1$latest_location '<!-- main -->'; break;
            case 
2:    $latest_location '<!-- what\'s going on box -->'; break;
        }
    
    if (
$vbulletin->options['latest_thread_auto'])
    {
        
// adds location to forumhome template
        
$vbulletin->templatecache['FORUMHOME'] = str_replace(
            
$latest_location,
            
$latest_location.'$latest',
            
$vbulletin->templatecache['FORUMHOME']
        );
    }



I also modified the template code for forumhome_latest_thread_bit to the following to make the link jump to the latest post when clicked:

PHP Code:
<tr>
    <
td class="$bgclass">
        <
a href="$vboptions[bburl]/showthread.php?$session[sessionurl]t=$threadid&p=$postidclass="smallfont">$threadtitle</a>
        <if 
condition="$vboptions['latest_thread_time']"><span class="smallfont">$date $time</span></if>
        <if 
condition="$vboptions['latest_thread_cut'] != '0'"><div class="smallfont">$pagetext</div></if>
    </
td>
    <
td class="$bgclass">
        <
a href="$vboptions[bburl]/forumdisplay.php?$session[sessionurl]f=$forumidclass="smallfont">$forumtitle</a>
    </
td>
    <
td class="$bgclass">
        <
a href="$vboptions[bburl]/member.php?$session[sessionurl]u=$useridclass="smallfont">$username</a>
    </
td>
</
tr

Seems to be working great thus far! Thanks again.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01160 seconds
  • Memory Usage 1,865KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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
  • showpost_complete