View Single Post
  #1  
Old 11-11-2008, 07:22 PM
nando99 nando99 is offline
 
Join Date: Dec 2005
Location: South Florida
Posts: 218
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Recent Topics - LONG title...

I've been using a customized Recent Topics on non vb pages mod and I have a question... I'd like to shorten the title displayed... I've including the file most likely needed to be edited..

Any help is appreciated...

PHP Code:
<?php
/**
 * VB Recent Topics - main object
 * @author George Gonzalez <webmaster@socaltrailriders.org>
 * @version 2.0
 * @package Recent_Topics
 * @link https://vborg.vbsupport.ru/showthread.php?t=134320
 */

require_once('register.class.php');
require(
'config.php');

/**
 * Main recent topics object
 * @package Recent_Topics
 */
class recent_topics
{
    var 
$db;
    var 
$from;
    var 
$forums = array();
    var 
$quantity 10;
    var 
$pfxs;
    var 
$usepfxs;    
    var 
$prefixes;
    var 
$data = array();
    var 
$time_format 'g:i A';
    var 
$thread_by_post_date;

    
/**
     * This constructor will setup the database, parse options, and grab the data
     * @param array $options Options package with things like forums to include/exclude,
     * quantity of recent topics to return, etc.
     * @return void
     */
    
public function __construct($options)
    {
        if (!
register::exists('db_host')) {
            
trigger_error('Recent topics: Check database settings.'E_USER_ERROR);
        }
    
        
$this->db mysql_connect(register::get('db_host'), register::get('db_user'), register::get('db_password'));

        if (!
$this->db) {
            
trigger_error('Recent topics: Cannot connect to the database. Check your database settings in config.php.'E_USER_ERROR);
        }
        
        
$result mysql_select_db(register::get('db_name'), $this->db);
        
        if (!
$result) {
            
trigger_error('Recent topics: Cannot select the database. Check the database options in config.php.'E_USER_ERROR);        
        }
        
        
$this->parseOptions($options);
        
$this->getData();
    }
    
    
/**
     * Parse Options
     * @param array $options The options package consisting of exclude_from, include_from,
     * quantity, and time_format. all of those are optional
     */    
    
private function parseOptions($options)
    {
        if (!empty(
$options['include_from']) && !empty($options['exclude_form'])) {
            
trigger_error('Recent topics: Can only include or exclude, not both.'E_USER_ERROR);
        }
        
        
// include these forums...
        
if (!empty($options['include_from'])) {
            
$this->extract_forums($options['include_from']);
            
$this->from 'INCLUDE';
        }
        
// exclude these forums . . .
        
elseif (!empty($options['exclude_from'])) {
            
$this->extract_forums($options['exclude_from']);
            
$this->from 'EXCLUDE';
        }
        else {
            
$this->from 'ALL';
        }
        
        if (!isset(
$options['quantity']) || empty($options['quantity'])) {
            
// do nothing (uses the default value)
        
}
        elseif (
intval($options['quantity']) == $options['quantity'] ) {
            
$this->quantity $options['quantity'];
        }
        else {
            
trigger_error('Recent topics: Check the quantity option.'E_USER_ERROR);
        }
        
        if (isset(
$options['time_format']) && !empty($options['time_format'])) {
            
$this->time_format $options['time_format'];
        }
        
        
// include these prefixes...
        
if (!empty($options['include_prefix'])) {
            
$this->usepfxs explode(','$options['include_prefix']);
            
$this->pfxs 'INCLUDE';
        }
        
// exclude these prefixes . . .
        
elseif (!empty($options['exclude_prefix'])) {
            
$this->usepfxs explode(','$options['exclude_prefix']);
            
$this->pfxs 'EXCLUDE';
        }
        else {
            
$this->pfxs 'ALL';
        }
        
        if (!empty(
$options['thread_by_post_date']) && $options['thread_by_post_date'] == true) {
            
$this->thread_by_post_date true;
        }
    }
    
    
/**
     * Extracts forums from comma seperated list into an array and puts it into a 
     * class property
     * @param string $forums_csv The comma seperated forum ID list
     */    
    
private function extract_forums($forums_csv)
    {
        
$forums_csv str_replace(' '''$forums_csv);
        
$this->forums explode(','$forums_csv);
    }
    
    
/**
     * Gets the actual topics data from the database and populates the $this->data property
     */    
    
public function getData()
    {    
        
$pre register::get('db_table_prefix');
        
$url register::get('forum_url');
        
$url str_ireplace('http://'''$url);
        
        switch(
$this->from
        {
            case 
'INCLUDE':
                
$forums 'AND t.forumid IN ('.implode(', '$this->forums).')';
            break;
            case 
'EXCLUDE':
                
$forums 'AND t.forumid NOT IN ('.implode(', '$this->forums).')';    
            break;
            default:
                
$forums '';
            break;
        }

        switch(
$this->pfxs
        {
            case 
'INCLUDE':
                
$usepfxs 'AND t.prefixid IN (\''.implode('\', \''$this->usepfxs).'\')';
            break;
            case 
'EXCLUDE':
                
$usepfxs 'AND t.prefixid NOT IN (\''.implode('\', \''$this->usepfxs).'\')';    
            break;
            default:
                
$usepfxs '';
            break;
        }
        
        
$tt_thumbsforums = array(102,103,104,131);
        
$tt_displaythumbs false;
        
        if (
count(array_intersect($this->forums$tt_thumbsforums))) {
            
$thumbs = array();
            
$tt_displaythumbs true;
            
$q "
                SELECT t.threadid,
                    a.thumbnail_filesize AS thumbsize , MIN(a.attachmentid) AS attachmentid
                FROM 
{$pre}thread t
                LEFT JOIN 
{$pre}attachment a 
                    ON a.postid = t.firstpostid
                WHERE t.forumid IN ("
.implode(','$tt_thumbsforums).")                    
                    AND a.extension IN('jpg','gif','png')
                GROUP BY t.threadid
            "
;
            
            
$results mysql_query($q$this->db);
            if(!
$results) { print "(".mysql_error().") with query $q"; }
            
            while(
$row mysql_fetch_array($results)) {
                
$thumbs[$row[0]] = $row;
            }
        }

        
$ordercolumn "t.lastpost";
        if(
$thread_by_start_date) {
            
$ordercolumn "startdate";
        }
        
        
$q "    
            SELECT     t.threadid, t.title, t.lastpost, t.lastposter, t.forumid, t.lastpostid, t.prefixid,
                f.title_clean, t.dateline AS startdate,
                p.pagetext AS preview
            FROM 
{$pre}thread t
            INNER JOIN 
{$pre}forum f 
                ON (f.forumid = t.forumid)
            INNER JOIN 
{$pre}post p
                ON (t.firstpostid = p.postid)
            WHERE t.visible = '1' 
                AND t.open = '1'
                
{$forums}
                
{$prefixes}
                
{$usepfxs}
            ORDER BY t.lastpost desc 
            LIMIT 
{$this->quantity}
        "
;
                    
        
$results mysql_query($q$this->db);
        if(!
$results) { print "(".mysql_error().") with query $q"; }
        while(
$row mysql_fetch_array($results)) {
            if(
$thumbs[$row['threadid']]) {
                
$row array_merge($row$thumbs[$row['threadid']]);
            }

            
$row['preview'] = $this->strip_quotes($row['preview']);
            
$row['preview'] = htmlspecialchars(substr($this->strip_bbcode($row['preview'], falsetrue), 0200));
        
            
$phrasenames[$row['prefixid']] = mysql_escape_string("prefix_{$row['prefixid']}_title_plain");
            
            
$row['last_post_time'] = date($this->time_format$row['lastpost']);
            
$row['url'] = 'http://'.$url.'showthread.php?t='.$row['threadid'];
            
$row['url_last'] = 'http://'.$url.'showthread.php?p='.$row['lastpostid'].'#post'.$row['lastpostid'];
            
$row['startdate'] = date('m-d-Y h:i A'$row['startdate']);
            
            
$this->data[$row['threadid']] = $row;
            unset(
$row);
        }
        
        
$q "
            SELECT varname, text
            FROM 
{$pre}phrase
            WHERE varname IN ('"
.implode("','"$phrasenames)."')
        "
;
                
        
$results mysql_query($q$this->db);
        if(!
$results) { print "(".mysql_error().") with query $q"; }
        
        while(
$row mysql_fetch_array($results)) {
            
$this->prefixes[$row['varname']] = $row;
        }
    }
    
    
/**
     * Gets the raw data array
     * @return array|boolean The data array or false if there is none
     */    
    
public function get_array()
    {
        return (!empty(
$this->data)) ? $this->data false;
    }
    
    
/**
     * Gets an HTML table of the recent topics
     * @return string HTML table of the recent topics
     */    
    
public function get_html_table()
    {
    
        
$html "\n\n".'    <table id="recent_topics">
    <thead>
        <th>Title</th>
        <th>Last Poster</th>
        <th>Time</th>
    </thead>
    <tbody>'
."\n";
                    
        foreach(
$this->data as $topic) {
            
$html .= '    <tr>
    <td><a href="'
.$topic['url'].'">'.$topic['title'].'</a></td>
    <td>'
.$topic['lastposter'].'</td>
    <td><a href="'
.$topic['url_last'].'">'.$topic['last_post_time'].'</a></td>
</tr>'
."\n";        
        }        
            
        
$html .=    '</tbody>        
        </table>'
;    
        
        return 
$html;
    }
    
        
/**
     * Eye Candy HTML OUTPUT
     * Gets an HTML list of the recent topics
     * @return string HTML list of the recent topics
     */        
    
public function get_html_list_ec()
    {
        
$html "\n\n".'<div class="links">';
        foreach(
$this->data as $topic) {
            if(
$this->prefixes["prefix_{$topic['prefixid']}_title_plain"]) {
                
$topic['prefix'] = $this->prefixes["prefix_{$topic['prefixid']}_title_plain"]['text'];
            }
            
            if(
$topic['attachmentid'] && $topic['thumbsize']) {
                
$topic['thumbnail'] = '<a href="'.$topic['url'].'"><img src="http://www.fatboymagazine.com/attachment.php?attachmentid='.$topic['attachmentid'].'&stc=1&thumb=1" alt="'.$topic['prefix'].'-'.$topic['title'].'" title="'.$topic['prefix'].' - '.$topic['title'].'" border="0"/></a>';
            }
            
            
            
$html .= '

    <div style="display:block;border: solid 2px #CCCCCC;width:96px;height:99px;overflow:hidden;float:left;">
    '
.$topic['thumbnail'].'
    </div>
'
."\n";        
        }        
            
        
$html .=    '</div>'."\n";    
        
        return 
$html;
    }

        
/**
     * General Discussions HTML OUTPUT
     * Gets an HTML list of the recent topics
     * @return string HTML list of the recent topics
     */        
    
public function get_html_list_gd()
    {
        
$html "\n\n".'  <div class="links"><ul>';
        foreach(
$this->data as $topic) {
            if(
$this->prefixes["prefix_{$topic['prefixid']}_title_plain"]) {
                
$topic['prefix'] = $this->prefixes["prefix_{$topic['prefixid']}_title_plain"]['text'];
            }
            
            if(
$topic['attachmentid'] && $topic['thumbsize']) {
                
$topic['thumbnail'] = '<a href="'.$topic['url'].'"><img src="http://www.fatboymagazine.com/attachment.php?attachmentid='.$topic['attachmentid'].'&stc=1&thumb=1" alt="'.$topic['prefix'].'-'.$topic['title'].'" title="'.$topic['prefix'].' - '.$topic['title'].' - " border="0"/></a>';
            }
            
            
            
$html .= '<li><a href="'.$topic['url'].'" title="'.$topic['prefix'].' - '.$topic['title'].'">'.$topic['title'].'</a></li>';        
        }        
            
        
$html .=    '</ul></div>'."\n";    
        
        return 
$html;
    }
    
    
/**
     * Directly echos an HTML table of the recent topics
     */        
    
public function display_html_table()
    {
        echo 
$this->get_html_table();
    }
    
    
/**
     * ADD MORE HTML OUTPUT FUNCTIONS HERE - nando
     * Directly echos an HTML list of the recent topics
     */        
    
public function display_html_list_ec()
    {
        echo 
$this->get_html_list_ec();
    }
    
        public function 
display_html_list_gd()
    {
        echo 
$this->get_html_list_gd();
    }
    
    
/**
     * Closes down the database connection
     */        
    
public function __destruct()
    {
        
mysql_close($this->db);
    }
    
    
    
// #############################################################################
    /**
    * Strips away bbcode from a given string, leaving plain text
    *
    * @param    string    Text to be stripped of bbcode tags
    * @param    boolean    If true, strip away quote tags AND their contents
    * @param    boolean    If true, use the fast-and-dirty method rather than the shiny and nice method
    *
    * @return    string
    */
    
public function strip_bbcode($message$stripquotes false$fast_and_dirty false$showlinks true)
    {
        
$find = array();
        
$replace = array();
    
        if (
$stripquotes)
        {
            
// [quote=username] and [quote]
            
$message strip_quotes($message);
        }
    
        
// a really quick and rather nasty way of removing vbcode
        
if ($fast_and_dirty)
        {
            
// any old thing in square brackets
            
$find[] = '#\[.*/?\]#siU';
            
$replace[] = '';
    
            
$message preg_replace($find$replace$message);
        }
        
// the preferable way to remove vbcode
        
else
        {
            
// simple links
            
$find[] = '#\[(email|url)=("??)(.+)\\2\]\\3\[/\\1\]#siU';
            
$replace[] = '\3';
    
            
// named links
            
$find[] = '#\[(email|url)=("??)(.+)\\2\](.+)\[/\\1\]#siU';
            
$replace[] = ($showlinks '\4 (\3)' '\4');
    
            
// replace links (and quotes if specified) from message
            
$message preg_replace($find$replace$message);
    
            
// strip out all other instances of [x]...[/x]
            
while(preg_match_all('#\[(\w+?)(?>[^\]]*?)\](.*)(\[/\1\])#siU'$message$regs))
            {
                foreach(
$regs[0] AS $key => $val)
                {
                    
$message  str_replace($val$regs[2]["$key"], $message);
                }
            }
            
$message str_replace('[*]'' '$message);
        }
    
        return 
trim($message);
    }
    
    
// #############################################################################
    /**
    * Strips away [quote] tags and their contents from the specified string
    *
    * @param    string    Text to be stripped of quote tags
    *
    * @return    string
    */
    
public function strip_quotes($text)
    {
        
$lowertext strtolower($text);
    
        
// find all [quote tags
        
$start_pos = array();
        
$curpos 0;
        do
        {
            
$pos strpos($lowertext'[quote'$curpos);
            if (
$pos !== false AND ($lowertext[$pos 6] == '=' OR $lowertext[$pos 6] == ']'))
            {
                
$start_pos["$pos"] = 'start';
            }
    
            
$curpos $pos 6;
        }
        while (
$pos !== false);
    
        if (
sizeof($start_pos) == 0)
        {
            return 
$text;
        }
    
        
// find all [/quote] tags
        
$end_pos = array();
        
$curpos 0;
        do
        {
            
$pos strpos($lowertext'[/quote]'$curpos);
            if (
$pos !== false)
            {
                
$end_pos["$pos"] = 'end';
                
$curpos $pos 8;
            }
        }
        while (
$pos !== false);
    
        if (
sizeof($end_pos) == 0)
        {
            return 
$text;
        }
    
        
// merge them together and sort based on position in string
        
$pos_list $start_pos $end_pos;
        
ksort($pos_list);
    
        do
        {
            
// build a stack that represents when a quote tag is opened
            // and add non-quote text to the new string
            
$stack = array();
            
$newtext '';
            
$substr_pos 0;
            foreach (
$pos_list AS $pos => $type)
            {
                
$stacksize sizeof($stack);
                if (
$type == 'start')
                {
                    
// empty stack, so add from the last close tag or the beginning of the string
                    
if ($stacksize == 0)
                    {
                        
$newtext .= substr($text$substr_pos$pos $substr_pos);
                    }
                    
array_push($stack$pos);
                }
                else
                {
                    
// pop off the latest opened tag
                    
if ($stacksize)
                    {
                        
array_pop($stack);
                        
$substr_pos $pos 8;
                    }
                }
            }
    
            
// add any trailing text
            
$newtext .= substr($text$substr_pos);
    
            
// check to see if there's a stack remaining, remove those points
            // as key points, and repeat. Allows emulation of a non-greedy-type
            // recursion.
            
if ($stack)
            {
                foreach (
$stack AS $pos)
                {
                    unset(
$pos_list["$pos"]);
                }
            }
        }
        while (
$stack);
    
        return 
$newtext;
    }
}


?>
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01773 seconds
  • Memory Usage 2,117KB
  • 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
  • (1)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