============================================================================================================================
Title: Latest Posts On Index v1.5

Author: John Briggs

Updated/Enhanced by: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)
Updated to 1.9.8 by: WormHole @ XMB Garage

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

Copyright:  2006 John Briggs. All rights reserved.

Compatability: XMB 1.9.8 SP3

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. 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 Admin 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 At Very Bottom 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:   
==========

        $onlinetoday_statuson = $onlinetoday_statusoff = '';
        settingHTML('onlinetoday_status', $onlinetoday_statuson, $onlinetoday_statusoff);

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

        // Latest Posts On Index Mod Begin
         $lpstatuson = $lpstatusoff = '';
         settingHTML('lpstatus', $lpstatuson, $lpstatusoff);
        // 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'] = $SETTINGS['lpcount'];
        $SETTINGS['lplimit'] = $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', ((int)$SETTINGS['lpcount']), 5);
        printsetting2($lang['lplimit'], 'lplimitnew', ((int)$SETTINGS['lplimit']), 5);
        // Latest Posts On Index Mod End

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

        $onlinetodaycountnew = formInt('onlinetodaycountnew');
        $onlinetoday_statusnew = formOnOff('onlinetoday_statusnew');

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

        // Latest Posts On Index Mod Begin
        $lpstatusnew = formOnOff('lpstatusnew');
        $lpcountnew = formInt('lpcountnew');
        $lplimitnew = formInt('lplimitnew');
        // Latest Posts On Index Mod End

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

        $db->query("UPDATE ".X_PREFIX."settings SET


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

        $db->query("UPDATE ".X_PREFIX."settings SET
            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: 
==========

eval('echo "'.template('header').'";');

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

// Latest Posts On Index Mod Begin
$latestposts = '';
if ($SETTINGS['lpstatus'] == 'on') {
    // $self['username'] = isset($self['username']) ? $self['username'] : '';
    $modXmbuser = str_replace(array('*', '.', '+'), array('\*', '\.', '\+'), $xmbuser);
    $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);

$fids = array();
$tids = array();
$fup = array();
if (X_SADMIN) {
    $q = $db->query("SELECT fid FROM ".X_PREFIX."forums WHERE status='on'");
    while($f = $db->fetch_array($q)) {
        $fids[] = $f['fid'];
    }
    $db->free_result($q);
} else {
    $q = $db->query("SELECT fid, type, fup FROM ".X_PREFIX."forums WHERE status='on' AND $restrict");
    while($f = $db->fetch_array($q)) {
        if (isset($f['type']) && $f['type'] == 'sub') {
            $query = $db->query("SELECT private, userlist, name, fid FROM ".X_PREFIX."forums WHERE fid='$f[fup]'");
            $fup = $db->fetch_array($query);
            if (privfcheck($fup['private'], $fup['userlist'])) {
                $fids[] = $f['fid'];
            }
            $db->free_result($query);
        } else {
            $fids[] = $f['fid'];
        }
    }
    $db->free_result($q);

    if (X_MEMBER) {
        // let's add fids for passworded forums that the user can access
        $r2 = array();
        foreach($_COOKIE as $key=>$val) {
            if (preg_match('#^fidpw([0-9]+)$#', $key, $fetch)) {
                $r2[] = '(fid="' . $fetch[1] . '" AND password="'.addslashes($val).'")';
            }
        }

        if (count($r2) > 0) {
            $r = implode(' OR ', $r2);
            $q = $db->query("SELECT fid FROM ".X_PREFIX."forums WHERE $r");
            while($f = $db->fetch_array($q)) {
                $fids[] = $f['fid'];
            }
            $db->free_result($q);
        }
    }
}

if (count($fids) == 0) {
    error($lang['nopoststoday'], false);
}

$latest = array();
$THEME['thisbg'] = $THEME['altbg1'];
$SETTINGS['lpcount'] = intval($SETTINGS['lpcount']);
$lplimit = time() - (intval($SETTINGS['lplimit']) * 86400);
$query = $db->query("SELECT l.*, f.name, f.fid FROM ".X_PREFIX."threads l, ".X_PREFIX."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)) {
    $THEME['thisbg'] = ($THEME['thisbg'] == $THEME['altbg1']) ? $THEME['altbg2'] : $THEME['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_replies = stripslashes(censor($last['replies']));
    $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"><td bgcolor="'.$THEME['thisbg'].'">'.$lang['latestpostsnone'].'</td></tr>';
    }
    eval('$latestposts = "'.template('index_latestposts').'";');
}
// Latest Posts On Index Mod End

============================================================================================================================
=======
Step 5:
=======
===============================
Go To Administration Panel -> Templates
===============================
==================================
Create New Template Name: index_latestposts
==================================
===========================
Add Code Below And Click Submit: 
===========================

<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="$cattext"><strong>$lang[latestpostsindex]</strong></font></td>
</tr>
$latest
</table>
</td>
</tr>
</table>
<br />

============================================================================================================================
=======
Step 6:
=======
==============================
Go to Administration Panel -> Templates:
==============================
======================================
Create New Template Name: index_latestposts_row
======================================
===========================
Add Code Below and Click Submit:
===========================

<tr class="tablerow">
<td bgcolor="$THEME[thisbg]">$last[subject] $lpstr $lplast $lang[textby] $last[author] $lang[textin] $lpforum ($lang[textreplies] <strong>$last[replies]</strong>)</td>
</tr>

============================================================================================================================
=======
Step 7: 
=======

=====================================
Go To Administration Panel -> Templates -> index
=====================================
==========
Find Code: 
==========

$welcome

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

$latestposts

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