============================================================================================================================
Modification Title: Latest Posts On Index

Version: 1.5

Author: John Briggs

Updated/Enhanced by: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)

Description:
This modification provides a block where the latest posts will show on index.
This modification provides settings to turn display on/off and how many latest posts to display.
This modification provides restriction security to prevent hidden posts from being shown to unauthorized viewers.

Copyright:  2010 John Briggs. All Rights Reserved.

Compatability: XMB 1.9.5 SP1

Install Note: Before adding this modification to your forum, you should back up all files related to this modification.

License Note: This modification is released under the GPL License v3. A copy is provided with this software package.

Author Note:
You downloaded this modification from XMBGarage.com, the #1 source for XMB related downloads.
Please visit http://www.xmbgarage.com/ for support.
============================================================================================================================
=======
Step 1:
=======
====================================
Go To Administration Panel --> Insert Raw SQL
====================================
============================
Paste Code Below And Click Submit
============================

ALTER TABLE `$table_settings` ADD `lpstatus` set('on','off') NOT NULL default '';
ALTER TABLE `$table_settings` ADD `lpcount` smallint(5) NOT NULL default 0;
ALTER TABLE `$table_settings` ADD `lplimit` smallint(3) NOT NULL default 0;
UPDATE `$table_settings` SET `lpstatus` = 'on', `lpcount` = '5', `lplimit` = '7';

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

// Latest Posts On Index Mod Begin
$lang['latestpostsnone'] = "There are no new Threads or Posts.";
$lang['latestpostsindex'] = "Latest $SETTINGS[lpcount] posts on $SETTINGS[bbname]";
$lang['lpstatus'] = "Latest Posts On Index Status:";
$lang['lpcount'] = "Latest Posts On Index Total:";
$lang['lplimit'] = "How many days would you like to show posts from?";
$lang['textin'] = "in";
$lang['lpposted'] = "was posted on";
$lang['lpreplied'] = "was last replied to on";
// Latest Posts On Index Mod End

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

        $resetSigOn = $resetSigOff = '';
        if($SETTINGS['resetsigs'] == 'on') {
            $resetSigOn = $selHTML;
        } else {
            $resetSigOff = $selHTML;
        }

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

        // Latest Posts On Index Mod Begin
        $lpstatuson = $lpstatusoff = '';
        switch ($SETTINGS['lpstatus']) {
            case 'on':
                $lpstatuson = $selHTML;
                break;
            default:
                $lpstatusoff = $selHTML;
                break;
        }
        // Latest Posts On Index Mod End

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

        $lang['spell_checker'] .= $spell_off_reason;

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

        // Latest Posts On Index Mod Begin
        $SETTINGS['lpcount'] = (int) $SETTINGS['lpcount'];
        $SETTINGS['lplimit'] = (int) $SETTINGS['lplimit'];
        // Latest Posts On Index Mod End

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

        printsetting1($lang['attachimginpost'], "attachimgpostnew", $attachimgposton, $attachimgpostoff);

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

        // Latest Posts On Index Mod Begin
        printsetting1($lang['lpstatus'], 'lpstatusnew', $lpstatuson, $lpstatusoff);
        printsetting2($lang['lpcount'], 'lpcountnew', $SETTINGS['lpcount'], 5);
        printsetting2($lang['lplimit'], 'lplimitnew', $SETTINGS['lpcount'], 5);
        // Latest Posts On Index Mod End

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

        $max_avatar_size_h_new = (int) $max_avatar_size_h_new;

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

        // Latest Posts On Index Mod Begin
        $lpcountnew = (int) $lpcountnew;
        $lplimitnew = (int) $lplimitnew;
        $lpstatusnew = ($lpstatusnew == 'on') ? 'on' : 'off';
        // Latest Posts On Index Mod End

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

        $db->query("UPDATE $table_settings SET

==================================
Find Code In-Line In Above Query Statement:
==================================

");

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

, lpstatus='$lpstatusnew', lpcount='$lpcountnew', lplimit='$lplimitnew'");

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

loadtemplates(

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

loadtemplates(
'index_latestposts',
'index_latestposts_row',

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

if (isset($gid) && is_numeric($gid)) {

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

// Latest Posts On Index Mod Begin
$latestposts = '';
if ($SETTINGS['lpstatus'] == 'on') {
    $self['username'] = isset($self['username']) ? $self['username'] : '';
    $modXmbuser = str_replace(array('*', '.', '+'), array('\*', '\.', '\+'), $self['username']);
    $restrict = array("(password='')");
    switch ($self['status']) {
        case 'Member':
            $restrict[] = 'private = 1';
            $restrict[] = "(userlist = '' OR userlist REGEXP '(^|(,))([:space:])*$modXmbuser([:space:])*((,)|$)')";
            break;
        case 'Moderator':
        case 'Super Moderator':
            $restrict[] = '(private = 1 OR private = 3)';
            $restrict[] = "(if ((private=1 AND userlist != ''), if ((userlist REGEXP '(^|(,))([:space:])*$modXmbuser([:space:])*((,)|$)'), 1, 0), 1))";
            break;
        case 'Administrator':
            $restrict[] = '(private > 0 AND private < 4)';
            $restrict[] = "(if ((private=1 AND userlist != ''), if ((userlist REGEXP '(^|(,))([:space:])*$modXmbuser([:space:])*((,)|$)'), 1, 0), 1))";
            break;
        case 'Super Administrator':
            break;
        default:
            $restrict[] = '(private=1)';
            $restrict[] = "(userlist='')";
            break;
    }
    $restrict = implode(' AND ', $restrict);

    $latest = array();
    $thisbg = $altbg1;
    $SETTINGS['lpcount'] = intval($SETTINGS['lpcount']);
    $lplimit = time() - (intval($SETTINGS['lplimit']) * 86400);
    $query = $db->query("SELECT l.*, f.name, f.fid FROM $table_threads l, $table_forums f WHERE $restrict AND l.lastpost > '$lplimit' AND l.fid=f.fid AND f.status='on' ORDER BY l.lastpost DESC LIMIT 0, $SETTINGS[lpcount]");
    $rowsFound = $db->num_rows($query);
    while ($last = $db->fetch_array($query)) {
        $thisbg = ($thisbg == $altbg1) ? $altbg2 : $altbg1;
        $adjTime = ($timeoffset * 3600) + ($SETTINGS['addtime'] * 3600);
        $lpdate = gmdate($dateformat, $last['lastpost'] + $adjTime);
        $lptime = gmdate($timecode, $last['lastpost'] + $adjTime);
        $lplast = '<strong>'.$lpdate.'</strong> '.$lang['textat'].' <strong>'.$lptime.'</strong>';
        $last['subject'] = shortenString(censor(stripslashes($last['subject'])), 60, X_SHORTEN_SOFT|X_SHORTEN_HARD, '...');
        $last['subject'] = '<a href="viewthread.php?goto=lastpost&amp;tid='.intval($last['tid']).'"><strong>'.$last['subject'].'</strong></a>';
        $lpforum = '<a href="forumdisplay.php?fid='.intval($last['fid']).'"><strong>'.stripslashes($last['name']).'</strong></a>';
        $lp      = explode('|', $last['lastpost']);
        $last['author'] = '<a href="member.php?action=viewpro&amp;member='.rawurlencode($lp[1]).'"><strong>'.trim($lp[1]).'</strong></a>';
        $lpstr = ($last['replies'] == 0) ? $lang['lpposted'] : $lang['lpreplied'];
        eval('$latest[] = "'.template('index_latestposts_row').'";');
    }
    $latest = implode("\n", $latest);
    $db->free_result($query);

    if ($rowsFound < 1) {
        $latest = "<tr class=\"tablerow\">\n<td>$lang[latestpostsnone]</td>\n</tr>";
    }
    eval('$latestposts = "'.template('index_latestposts').'";');
}
// Latest Posts On Index Mod End

============================================================================================================================
=======
Step 5:
=======
===============================
Go To Administration Panel --> Templates
===============================
==============================
Create New Template: index_latestposts
==============================
=============================
Add Code Below and Submit Changes
=============================

<table cellspacing="0" cellpadding="0" border="0" width="$THEME[tablewidth]" align="center">
<tr>
<td bgcolor="$THEME[bordercolor]">
<table border="0" cellspacing="$THEME[borderwidth]" cellpadding="$THEME[tablespace]" width="100%">
<tr class="category">
<td><font color="$THEME[cattext]"><strong>$lang[latestpostsindex]</strong></font></td>
</tr>
$latest
</table>
</td>
</tr>
</table>
<br />

============================================================================================================================
=======
Step 6:
=======
===============================
Go To Administration Panel --> Templates
===============================
=================================
Create New Template: index_latestposts_row
=================================
=============================
Add Code Below and Submit Changes
=============================

<tr class="tablerow">
<td bgcolor="$thisbg">$last[subject] $lpstr $lplast $lang[textby] $last[author] $lang[textin] $lpforum</td>
</tr>

============================================================================================================================
=======
Step 7:
=======
===============================
Go To Administration Panel --> Templates
===============================
================
Edit Template: index
================
==========
Find Code:
==========

$ticker

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

$latestposts

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