• R/O
  • HTTP
  • SSH
  • HTTPS

pukiwiki: Commit


Commit MetaInfo

Revision30594c96900ce1a6d46d20d7a9cce7fadc3bff85 (tree)
Time2016-01-17 22:08:15
Authorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack2/120 Fix: new plugin doesn't show "New!" indicator on PHP5+

strtotime function requests specific date time format.
So use ISO 8601 (YYYY-MM-DD) as input string.
http://php.net/manual/en/function.strtotime.php

Change Summary

Incremental Difference

--- a/plugin/new.inc.php
+++ b/plugin/new.inc.php
@@ -29,13 +29,21 @@ function plugin_new_inline()
2929 $retval = '';
3030 $args = func_get_args();
3131 $date = strip_autolink(array_pop($args)); // {date} always exists
32-
3332 if($date !== '') {
3433 // Show 'New!' message by the time of the $date string
3534 if (func_num_args() > 2) return '&new([nodate]){date};';
36-
37- $timestamp = strtotime($date);
38- if ($timestamp === -1) return '&new([nodate]){date}: Invalid date string;';
35+ $timestamp = -1;
36+ $dm = null;
37+ if (preg_match('/^\D*(\d{4})\D+(\d{1,2})\D+(\d{1,2})\D+(\d{1,2}:\d{2}:\d{2})\D*$/', $date, $dm)) {
38+ $iso8601_date = $dm[1]
39+ . '-' . substr('0' . $dm[2], -2)
40+ . '-' . substr('0' . $dm[3], -2)
41+ . ' ' . $dm[4];
42+ $timestamp = strtotime($iso8601_date);
43+ }
44+ if ($timestamp === -1 || $timestamp === FALSE) {
45+ return '&new([nodate]){date}: Invalid date string;';
46+ }
3947 $timestamp -= ZONETIME;
4048
4149 $retval = in_array('nodate', $args) ? '' : htmlsc($date);
@@ -89,4 +97,3 @@ function plugin_new_inline()
8997 return $retval;
9098 }
9199 }
92-?>
Show on old repository browser