PluginProbe
FeedWordPress / 2011.0211.2
FeedWordPress v2011.0211.2
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
← All changes | feedtime.class.php +8 -35 trunk2011.0211.2 View file →
@@ -1,39 +1,18 @@
1 1 <?php
2 2 /**
3 3 * class FeedTime: handle common date-time formats used in feeds.
4 - * We will try to be as tolerant as possible of different representations, since
5 - * RSS Is A Fucking Mess, broken dates seem to be especially pervasive, etc.
6 - * Supports anything that your version of PHP's strtotime() can handle; also has
7 - * a built-in parser for W3C DTF, in case your PHP doesn't have that.
8 4 *
9 - * Tries to parse a W3C DTF first; then falls back to strtotime(). If strtotime
10 - * fails due to a mystery timezone, then we will try again on local time, with
11 - * the timezone stripped out.
12 - *
13 - * To parse a string representation of a date-time from a feed, instantiate and
14 - * then pull the timestamp:
15 - *
16 - * $time = new FeedTime($s);
17 - * if ( ! $time->failed()) :
18 - * $ts = $time->timestamp();
19 - * else :
20 - * // ...
21 - * endif;
22 5 */
23 6 class FeedTime {
24 7 var $rep;
25 8 var $ts;
26 9
27 - function __construct( $time ) {
10 + function FeedTime ($time) {
28 11 $this->set($time);
29 12 } /* FeedTime constructor */
30 13
31 - function FeedTime( $time ) {
32 - self::__construct( $time );
33 - }
34 -
35 - function set ($time, $recurse = false) {
14 + function set ($time) {
36 15 $this->rep = $time;
37 16 $this->ts = NULL;
38 17 if (is_numeric($time)) : // Presumably a Unix-epoch timestamp
39 18 $this->ts = $this->rep;
@@ -41,12 +20,12 @@
41 20 // First, try to parse it as a W3C date-time
42 21 $this->ts = $this->parse_w3cdtf();
43 22
44 23 if ($this->failed()) :
45 - // In some versions of PHP, strtotime() does not
46 - // support the UT timezone. But since UT is by
47 - // definition within 1 second of UTC, we'll just
48 - // convert it preemptively to avoid problems.
24 + // In some versions of PHP, strtotime() does not support
25 + // the UT timezone. Since UT is by definition within 1
26 + // second of UTC, we'll just convert it here to avoid
27 + // problems.
49 28 $time = preg_replace(
50 29 '/(\s)UT$/',
51 30 '$1UTC',
52 31 $time
@@ -51,14 +30,8 @@
51 30 '$1UTC',
52 31 $time
53 32 );
54 33 $this->ts = strtotime($time);
55 -
56 - if ($this->failed()
57 - and preg_match('/^(.*)([+\-][0-9]+|\s+[A-Za-z]{1,3})$/', $time, $matches)) :
58 - // Try dropping the time zone and recurse
59 - $this->set($matches[1], /*recurse=*/ true);
60 - endif;
61 34 endif;
62 35 endif;
63 36 } /* FeedTime::set() */
64 37
@@ -63,9 +36,9 @@
63 36 } /* FeedTime::set() */
64 37
65 38 function timestamp () {
66 39 $unix = NULL;
67 - if ( ! $this->failed()) :
40 + if (!$this->failed()) :
68 41 $unix = $this->ts;
69 42 endif;
70 43 return $unix;
71 44 } /* FeedTime::timestamp() */
@@ -70,9 +43,9 @@
70 43 return $unix;
71 44 } /* FeedTime::timestamp() */
72 45
73 46 function failed () {
74 - return ( !is_numeric($this->ts) or ! $this->ts or ($this->ts <= 0));
47 + return (!is_numeric($this->ts) or !$this->ts or ($this->ts <= 0));
75 48 } /* FeedTime::failed() */
76 49
77 50 /**
78 51 * FeedTime::parse_w3cdtf() parses a W3C date-time format date into a