============================================================================================================================
Modification Name: Thread Preview v1.1

Author: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)

Last Updated: March 01, 2011

Description:
This modification will add a tooltip to your forumdisplay templates to give you a small preview of the thread.
This new version will also add an on/off switch for the feature in the user's preference.
There is also a setting in the admin/settings to set the number of characters to display in the tooltip.

Supported Version: XMB 1.9.5 SP1

Notes: This modification has been updated to remove flash tags from the preview to prevent breaking of forumdisplay.
           This modificatioin has been updated to remove object tags from the preview to prevent breaking of forumdisplay.

This modification is released under the GPL. You should have recieved a copy of it with this software package.

Please backup your files before installing this modification. Neither XMBGarage nor the author can be held 
responsible if your board stops functioning properly due to you installing this modification.

============================================================================================================================
=======
Step 1:
=======
==============================
Go To Admin Panel --> Insert Raw SQL
==============================
===============================
Paste The Following Code and Hit Submit
===============================

ALTER TABLE `$table_members` ADD `threadpreview` varchar(3) NOT NULL default 'on';
ALTER TABLE `$table_settings` ADD `tpreviewlength` INT(5) NOT NULL default '350';

============================================================================================================================
=======
Step 2:
=======
=======================
Edit File: lang/English.lang.php
=======================
=======================
Add To End Of File Above ?>
=======================

// Thread Preview Mod Begin
$lang['threadpreviewstatus'] = "Thread Preview Status:";
$lang['threadpreviewlength'] = "How many characters should be shown in Thread Previews?";
// Thread Preview Mod End

============================================================================================================================
=======
Step 3:
=======
==============
Edit File: cp.php
==============
==========
Find Code:
==========

        printsetting1($lang['reportpoststatus'], 'reportpostnew', $reportposton, $reportpostoff);

===============
Add Code Below:
===============

        // Thread Preview Mod Begin
        printsetting2($lang['threadpreviewlength'], 'tpreviewlengthnew', $SETTINGS['tpreviewlength'], 4);
        // Thread Preview Mod End

==========
Find Code:
==========

        $resetSigNew = ($resetSigNew == 'on') ? 'on' : 'off';

===============
Add Code Below:
===============

        // Thread Preview Mod Begin
        $tpreviewlengthnew = (int) $tpreviewlengthnew;
        // Thread Preview Mod End

==========
Find Code:
==========

        $db->query("UPDATE $table_settings SET

=======================
Find Code At End Of Line: ");
=======================
================
Replace Code With:
================

, tpreviewlength='$tpreviewlengthnew'");

============================================================================================================================
=======
Step 4:
=======
=================
Edit File: memcp.php
=================
==========
Find Code:
==========

        if ($SETTINGS['avastatus'] == 'on') {
            eval('$avatar = "'.template('memcp_profile_avatarurl').'";');
        } else {
            $avatar = '';
        }

===============
Add Code Above:
===============

        // Thread Preview Mod Begin
        $tpreviewon = $tpreviewoff = '';
        switch($member['threadpreview']) {
            case 'on':
                $tpreviewon = $selHTML;
                break;
            default:
                $tpreviewoff = $selHTML;
                break;
        }
        // Thread Preview Mod End

==========
Find Code:
==========

        $newsletter     = (isset($newnewsletter) && $newnewsletter == 'yes') ? 'yes' : 'no';

===============
Add Code Below:
===============

        // Thread Preview Mod Begin
        $threadpreview = (isset($newthreadpreview) && $newthreadpreview == 'on') ? 'on' : 'off';
        // Thread Preview Mod End

==========
Find Code:
==========

        $db->query("UPDATE $table_members SET $pwtxt

=================================================
Add Code To End Of Line Before: WHERE username='$xmbuser'");
=================================================

, threadpreview='$newthreadpreview'

============================================================================================================================
=======
Step 5:
=======
====================
Edit File: forumdisplay.php
====================
==========
Find Code:
==========

$querytop = $db->query("SELECT t.* FROM $table_threads t WHERE t.fid='$fid' $cusdate ORDER BY topped $ascdesc,lastpost $ascdesc LIMIT $start_limit, $tpp");

===============
Add Code Above:
===============

// Thread Preview Mod Begin
$forumtids = array();
// Thread Preview Mod End

==========
Find Code:
==========

    eval('$threadlist .= "'.template($forumdisplay_thread).'";');

===============
Add Code Above:
===============

    // Thread Preview Mod Begin
    if ($self['threadpreview'] == 'on') {
        $forumtids[] = $thread['tid'];
        $tpreview = '{TPREVIEW_'.$thread['tid'].'}';
    }
    // Thread Preview Mod End

==========
Find Code:
==========

if ($topicsnum == 0 && !$notexist) {
    eval('$threadlist = "'.template('forumdisplay_nothreads').'";');
}

===============
Add Code Below:
===============

// Thread Preview Mod Begin
if ($self['threadpreview'] == 'on' && !empty($forumtids)) {
    $tp_find = $tp_replace = array();
    $query = $db->query("SELECT DISTINCT tid, message FROM $table_posts WHERE tid IN(".implode(',', $forumtids).") ORDER BY pid ASC");
    while($post = $db->fetch_array($query)) {
        $tp_find[] = '{TPREVIEW_'.$post['tid'].'}';
        $tp_replace[] = makePreview(stripslashes($post['message']));
    }
    $db->free_result($query);
    
    $threadlist = str_replace($tp_find, $tp_replace, $threadlist);
}
// Thread Preview Mod End

============================================================================================================================
=======
Step 6:
=======
================
Edit File: today.php
================
==========
Find Code:
==========

$tids = array();

===============
Add Code Below:
===============

// Thread Preview Mod Begin
$todaytids = array();
// Thread Preview Mod End

==========
Find Code:
==========

    eval('$today2[] = "'.template('today2').'";');

===============
Add Code Above:
===============

    // Thread Preview Mod Begin
    if ($self['threadpreview'] == 'on') {
        $todaytids[] = $thread['tid'];
        $tpreview = '{TPREVIEW_'.$thread['tid'].'}';
    }
    // Thread Preview Mod End

==========
Find Code:
==========

eval('echo stripslashes("'.template('today').'");');

===============
Add Code Above:
===============

// Thread Preview Mod Begin
if ($self['threadpreview'] == 'on' && !empty($todaytids)) {
    $tp_find = $tp_replace = array();
    $query = $db->query("SELECT DISTINCT tid, message FROM $table_posts WHERE tid IN(".implode(',', $todaytids).") ORDER BY pid ASC");
    while($post = $db->fetch_array($query)) {
        $tp_find[] = '{TPREVIEW_'.$post['tid'].'}';
        $tp_replace[] = makePreview(stripslashes($post['message']));
    }
    $db->free_result($query);

    $rows = str_replace($tp_find, $tp_replace, $rows);
}
// Thread Preview Mod End

============================================================================================================================
=======
Step 7:
=======
==================
Edit File: functions.php
==================
==========
Find Code:
==========

function shortenString($string, $len=100, $shortType=X_SHORTEN_SOFT, $ps='...') {
    if (strlen($string) > $len) {
        if (($shortType & X_SHORTEN_SOFT) === X_SHORTEN_SOFT) {
            $string = preg_replace('#^(.{0,'.$len.'})([\W].*)#', '\1'.$ps, $string);
        }

        if ((strlen($string) > $len+strlen($ps)) && (($shortType & X_SHORTEN_HARD) === X_SHORTEN_HARD)) {
            $string = substr($string, 0, $len).$ps;
        }
        return $string;
    } else {
        return $string;
    }
}

===============
Add Code Below:
===============

// Thread Preview Mod Begin
function makePreview($message) {
    return addslashes(htmlspecialchars(trim(shortenString(censor(strip_tags(htmlspecialchars_decode(trim($message)))), $GLOBALS['SETTINGS']['tpreviewlength'], X_SHORTEN_HARD))));
}
// Thread Preview Mod End

============================================================================================================================
=======
Step 8:
=======
===============================
Go To Administration Panel --> Templates
===============================
=======================
Edit Template: memcp_profile
=======================
==========
Find Code:
==========

<tr class="tablerow">
<td bgcolor="$altbg1" width="22%">$lang[textsig]<br /><span class="smalltxt">$lang[texthtmlis] $htmlis<br />$lang[textbbcodeis] $bbcodeis</span></td>
<td bgcolor="$altbg2"><textarea rows="5" cols="45" name="newsig">$member[sig]</textarea></td>
</tr>

==========
Add Below:
==========

<tr class="tablerow">
<td bgcolor="$THEME[altbg1]" width="22%">$lang[threadpreviewstatus]</td>
<td bgcolor="$THEME[altbg2]"><select name="newthreadpreview">
<option value="on" $tpreviewon>$lang[texton]</option>
<option value="off" $tpreviewoff>$lang[textoff]</option>
</select></td>
</tr>

============================================================================================================================
=======
Step 9:
=======
===============================
Go To Administration Panel --> Templates
===============================
=================================================
Edit Templates: forumdisplay_thread and forumdisplay_thread_admin
=================================================
==========
Find Code:
==========

<td bgcolor="$altbg2" class="tablerow"><font class="mediumtxt">$prefix<a href="viewthread.php?tid=$thread[tid]">$thread[subject]</a>  $multipage2</font></td>

=============
Replace With:
=============

<td bgcolor="$THEME[altbg2]" class="tablerow" title="$tpreview"><font class="mediumtxt">$prefix<a href="viewthread.php?tid=$thread[tid]">$thread[subject]</a>  $multipage2</font></td>

============================================================================================================================
========
Step 10:
========
===============================
Go To Administration Panel --> Templates
===============================
=================
Edit Template: today2
=================
==========
Find Code:
==========

<td width="43%" bgcolor="$altbg1"><font class="12px">$prefix <a href="viewthread.php?tid=$thread[tid]">$thread[subject]</a> $multipage2</font></td>

================
Replace Code With:
================

<td width="43%" bgcolor="$THEME[altbg1]" title="$tpreview"><font class="12px">$prefix <a href="viewthread.php?tid=$thread[tid]">$thread[subject]</a> $multipage2</font></td>

============================================================================================================================
If you don't have Topic Activity installed, you're done! Enjoy!
If you do have Topic Activity installed then do the steps below:
============================================================================================================================
========
Step 12:
========
================
Edit File: activity.php
================
==========
Find Code:
==========

$query = $db->query("SELECT $dotadd1 t.*, f.name FROM ($table_threads t, $table_forums f) $dotadd2 WHERE $srchtype t.lastpost >= '$srchfrom' AND t.fid=f.fid AND f.fid IN ($fidlist) ORDER BY $srchsort $srchorder LIMIT $start_limit, $tpp");

===============
Add Code Above:
===============

// Thread Preview Mod Begin
$previewtids = array();
// Thread Preview Mod End

==========
Find Code:
==========

    eval('$threads .= "'.template('topic_activity_threads').'";');

===============
Add Code Above:
===============

    // Thread Preview Mod Begin
    if ($self['threadpreview'] == 'on') {
        $previewtids[] = $thread['tid'];
        $tpreview = '{TPREVIEW_'.$thread['tid'].'}';
    }
    // Thread Preview Mod End

==========
Find Code:
==========

if ($threadcount == 0) {
    eval('$threads = "'.template('topic_activity_none').'";');
}

===============
Add Code Below:
===============

// Thread Preview Mod Begin
if ($self['threadpreview'] == 'on' && !empty($previewtids)) {
    $tp_find = $tp_replace = array();
    $query = $db->query("SELECT DISTINCT tid, message FROM $table_posts WHERE tid IN(".implode(',', $previewtids).") ORDER BY pid ASC");
    while($post = $db->fetch_array($query)) {
        $tp_find[] = '{TPREVIEW_'.$post['tid'].'}';
        $tp_replace[] = makePreview(stripslashes($post['message']));
    }
    $db->free_result($query);
    
    $threads = str_replace($tp_find, $tp_replace, $threads);
}
// Thread Preview Mod End

============================================================================================================================
========
Step 13:
========
===============================
Go To Administration Panel --> Templates
===============================
===========================
Edit Template: topic_activity_threads
===========================
==========
Find Code:
==========

<td class="tablerow" bgcolor="$THEME[altbg2]">$prefix<a href="viewthread.php?tid=$thread[tid]">$thread[subject]</a> $pages</td>

=============
Replace With:
=============

<td class="tablerow" bgcolor="$THEME[altbg2]" title="$tpreview">$prefix<a href="viewthread.php?tid=$thread[tid]">$thread[subject]</a> $pages</td>

============================================================================================================================
Enjoy!