============================================================================================================================
Name: Last Post Upgrade

Version: 1.0

Last modified: 05/09/2009 @ 20:30 (GMT)

Description:
This modification will change the display format of the last post.
If the last post was made within 7 days, it will display: Today, Yesterday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, or Sunday.
Any older posts will diplay the date as normal.

Compatibility: XMB 1.9.11

Code Developed By: Adam Clarke (http://www.xmbservices.com)

MOD History: V1.0 (05/09/2009 @ 20:30) - Initial Release for XMB 1.9.11.

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

Note: Backup all affected files, templates & database's.

Affected Files (4): include/functions.inc.php, forumdisplay.php, header.php, today.php

Affected Templates (0): NONE

============================================================================================================================
========
STEP 1:
========
=========================
Edit File: include/functions.inc.php
=========================
==========
Find Code:
==========

function printGmDate($timestamp=null, $altFormat=null, $altOffset=0) {
    global $dateformat, $SETTINGS, $timeoffset, $addtime;

    if ($timestamp === null) {
        $timestamp = time();
    }

    if ($altFormat === null) {
        $altFormat = $dateformat;
    }

    $f = false;
    if ((($pos = strpos($altFormat, 'F')) !== false && $f = true) || ($pos2 = strpos($altFormat, 'M')) !== false) {
        $startStr = substr($altFormat, 0, $pos);
        $endStr = substr($altFormat, $pos+1);
        $month = gmdate('m', $timestamp + ($timeoffset*3600)+(($altOffset+$addtime)*3600));
        $textM = month2text($month);
        return printGmDate($timestamp, $startStr, $altOffset).substr($textM,0, ($f ? strlen($textM) : 3)).printGmDate($timestamp, $endStr, $altOffset);
    } else {
        return gmdate($altFormat, $timestamp + ($timeoffset * 3600) + (($altOffset+$addtime) * 3600));
    }
}

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

// Last Post Upgrade Mod Begin
function printGmDate($timestamp=null, $altFormat=null, $altOffset=0) {
    global $dateformat, $SETTINGS, $timeoffset, $addtime, $lang;

    if ($timestamp === null) {
        $timestamp = time();
    }

    if ($altFormat === null) {
        $altFormat = $dateformat;
    }

    $now = time();
    $today = gmmktime(0, 0, 0, gmdate('n', $now), gmdate('j', $now), gmdate('Y', $now)) - (($timeoffset*3600) + ($SETTINGS['addtime']*3600));;

    if ($timestamp >= $today) {
        return $lang['texttoday'];
    } elseif ($timestamp >= ($today - 86400)) {
        return $lang['textyesterday'];
    } elseif ($timestamp >= ($today - 518400)) {
        return $lang['text'.strtolower(gmdate('D', $timestamp + ($timeoffset * 3600) + ($SETTINGS['addtime'] * 3600)))];
    }

    $f = false;
    if ((($pos = strpos($altFormat, 'F')) !== false && $f = true) || ($pos2 = strpos($altFormat, 'M')) !== false) {
        $startStr = substr($altFormat, 0, $pos);
        $endStr = substr($altFormat, $pos+1);
        $month = gmdate('m', $timestamp + ($timeoffset*3600)+(($altOffset+$addtime)*3600));
        $textM = month2text($month);
        return printGmDate($timestamp, $startStr, $altOffset).substr($textM,0, ($f ? strlen($textM) : 3)).printGmDate($timestamp, $endStr, $altOffset);
    } else {
        return gmdate($altFormat, $timestamp + ($timeoffset * 3600) + (($altOffset+$addtime) * 3600));
    }
}

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

$lastpostdate = gmdate($dateformat, $lastpost[0] + ($timeoffset * 3600) + ($SETTINGS['addtime'] * 3600));

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

$lastpostdate = printGmDate($lastpost[0]);

============================================================================================================================
========
STEP 2:
========
=====================
Edit File: forumdisplay.php
=====================
==========
Find Code:
==========

$lastreplydate = gmdate($dateformat, $lastpost[0] + ($timeoffset * 3600) + ($addtime * 3600));

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

$lastreplydate = printGmDate($lastpost[0]);

============================================================================================================================
========
STEP 3:
========
=================
Edit File: header.php
=================
==========
Find Code:
==========

/* Set Up HTML Templates and Themes */

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

// Assert Last Post Date Upgrade Translation
if (!isset($lang['texttoday'])) {
    require_once(ROOT.'include/translation.inc.php');
    $phrases = array();
    $phrases['texttoday'] = "<strong>Today</strong>";
    $phrases['textyesterday'] = "<strong>Yesterday</strong>";
    $phrases['textmon'] = "Monday";
    $phrases['texttue'] = "Tuesday";
    $phrases['textwed'] = "Wednesday";
    $phrases['textthu'] = "Thursday";
    $phrases['textfri'] = "Friday";
    $phrases['textsat'] = "Saturday";
    $phrases['textsun'] = "Sunday";
    setManyLangValues($phrases, $langfile);
    loadLang($langfile);
}

============================================================================================================================
========
STEP 4:
========
================
Edit File: today.php
================
==========
Find Code:
==========

$lastreplydate = gmdate($dateformat, $lastpost[0] + $tmOffset);

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

$lastreplydate = printGmDate($lastpost[0]);

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