<? // Simple plugin: an improved date function -- accepts PHP date operators // VERSION 1.0 // NO WARRANTY - USE AT YOUR OWN RISK! class NP_BetterDate extends NucleusPlugin { function getName() { return 'Better Date'; } function getAuthor() { return 'Nate Silva'; } function getURL() { return 'http://filteredlife.org/betterdate/'; } function getVersion() { return '1.0'; } function supportsFeature($what) { switch($what) { case 'SqlTablePrefix': return 1; default: return 0; } } function getDescription() { $s = 'An improved date function which accepts all PHP date operators. '; $s .= 'Call with <span style="white-space:nowrap;"><%BetterDate(<b>posted</b>, <i>format</i>)%></span>, '; $s .= '<span style="white-space:nowrap;"><%BetterDate(<b>postedutc</b>, <i>format</i>)%></span>, '; $s .= '<span style="white-space:nowrap;"><%BetterDate(<b>now</b>, <i>format</ i>)%></span> '; $s .= 'or <span style="white-space:nowrap;"><%BetterDate(<b>nowutc</b>, <i>format</i>)%></span>. '; $s .= 'The <i>format</i> is a PHP date() string, or the special string <i>iso8601</i>, '; $s .= 'which will use the international standard format. '; $s .= 'A special format <i>tzwithcolon</i> is also available as a hack to make Atom 0.2 '; $s .= '\'issued\' dates validate at feeds.archive.org. The <i>tzwithcolon</i> format only '; $s .= 'applies to the <b>posted</b> date.'; return $s; } function doTemplateVar(&$item,$datetype,$format) { $datetype = strtolower($datetype); $format_iso = 'Y-m-d\TH:i:sO'; $format_iso_utc = 'Y-m-d\TH:i:s\Z'; if ($datetype == 'now') { if (strtolower($format) == 'iso8601') echo date($format_iso); else echo date($format); } elseif ($datetype == 'nowutc') { if (strtolower($format) == 'iso8601') echo gmdate($format_iso_utc); else echo gmdate($format); } elseif ($datetype == 'posted') { if (strtolower($format) == 'iso8601') echo date($format_iso, $item->timestamp); elseif (strtolower($format) == 'tzwithcolon') { // for some reason the feed validator at archive.org expects // the atom/echo/pie "issued" date timezone to have a colon $tz = date('O', $item->timestamp); $tz = substr($tz, 0, 3) . ':' . substr($tz, 3, 2); echo date('Y-m-d\TH:i:s', $item->timestamp) . $tz; } else echo date($format, $item->timestamp); } elseif ($datetype == 'postedutc') { if (strtolower($format) == 'iso8601') echo gmdate($format_iso_utc, $item->timestamp); else echo gmdate($format, $item->timestamp); } } } ?>