Skip to content

Instantly share code, notes, and snippets.

@opello
Created October 27, 2010 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opello/648441 to your computer and use it in GitHub Desktop.
Save opello/648441 to your computer and use it in GitHub Desktop.
Modified for use on my LUG's wiki, these are the changes I had to make to get 'pubDate' elements from Google Groups to format correctly
diff -ur RSS.orig/RSS.php RSS/RSS.php
--- RSS.orig/RSS.php 2010-10-26 21:16:18.000000000 -0500
+++ RSS/RSS.php 2010-10-27 00:21:22.000000000 -0500
@@ -199,8 +199,13 @@
$title = htmlspecialchars( trim( iconv( $charset, $wgOutputEncoding, $item['title'] ) ) );
if ( $date ) {
- $pubdate = trim( iconv( $charset, $wgOutputEncoding, $item['pubdate'] ) );
- $pubdate = date( $date, strtotime( $pubdate ) );
+ if ( isset( $item['date_timestamp'] ) ) {
+ $pubdate = $item['date_timestamp'];
+ } else {
+ $pubdate = trim( iconv( $charset, $wgOutputEncoding, $item['pubdate'] ) );
+ $pubdate = strtotime( $pubdate );
+ }
+ $pubdate = date( $date, $pubdate );
}
$d_title = wfRssFilter( $title, $rssFilter );
@@ -250,11 +255,21 @@
$d_title = wfRssFilter( $title, $rssFilter ) && wfRssFilterout( $title, $rssFilterout );
$title = wfRssHighlight( $title, $rssHighlight );
if ( $date ) {
- $pubdate = isset( $item['pubdate'] ) ? trim( iconv( $charset, $wgOutputEncoding, $item['pubdate'] ) ) : '';
- if ( $pubdate == '' ) {
- $pubdate = trim( iconv( $charset, $wgOutputEncoding, $item['dc']['date'] ) );
+ if ( isset( $item['date_timestamp'] ) ) {
+ $pubdate = $item['date_timestamp'];
+ } else {
+ if ( $pubdate == '' ) {
+ $pubdate = isset( $item['pubdate'] ) ? trim( iconv( $charset, $wgOutputEncoding, $item['pubdate'] ) ) : '';
+ }
+ if ( $pubdate == '' ) {
+ $pubdate = isset( $item['updated'] ) ? trim( iconv( $charset, $wgOutputEncoding, $item['updated'] ) ) : '';
+ }
+ if ( $pubdate == '' ) {
+ $pubdate = isset( $item['dc']['date'] ) ? trim( iconv( $charset, $wgOutputEncoding, $item['dc']['date'] ) ) : '';
+ }
+ $pubdate = strtotime( $pubdate );
}
- $pubdate = date( $date, strtotime( $pubdate ) );
+ $pubdate = date( $date, $pubdate );
}
if ( $d_title && !in_array( $title, $displayed ) ) {
diff -ur RSS.orig/RSSParse.php RSS/RSSParse.php
--- RSS.orig/RSSParse.php 2010-10-26 21:16:18.000000000 -0500
+++ RSS/RSSParse.php 2010-10-27 00:06:53.000000000 -0500
@@ -339,6 +339,11 @@
if ( $epoch && $epoch > 0 ) {
$item['date_timestamp'] = $epoch;
}
+ } elseif ( isset( $item['updated'] ) ) {
+ $epoch = @strtotime( $item['updated'] );
+ if ( $epoch > 0 ) {
+ $item['date_timestamp'] = $epoch;
+ }
}
$this->items[$i] = $item;
@@ -360,7 +365,12 @@
$item['date_timestamp'] = $epoch;
}
} elseif ( isset( $item['pubdate'] ) ) {
- $epoch = @strtotime( $item['pubdate'] );
+ $epoch = @strtotime( str_replace( 'UT', 'UTC', $item['pubdate'] ) );
+ if ( $epoch > 0 ) {
+ $item['date_timestamp'] = $epoch;
+ }
+ } elseif ( isset( $item['updated'] ) ) {
+ $epoch = @strtotime( $item['updated'] );
if ( $epoch > 0 ) {
$item['date_timestamp'] = $epoch;
}
@opello
Copy link
Author

opello commented Oct 27, 2010

Revised to format the dates in Atom 'updated' fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment