#16473 closed defect (bug) (fixed)
RSS Widget always returns current date when 'Display item date' is checked
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | minor | Version: | 3.0.4 |
Component: | Widgets | Keywords: | pubDate RSS |
Focuses: | Cc: |
Description
See http://zippersoftware.com/wp/ for an example of this bug.
Problem:
About line 837 in function wp_widget_rss_output (default-widgets.php) you now have...
$date = ''; if ( $show_date ) { $date = $item->get_date(); if ( $date ) { if ( $date_stamp = strtotime( $date ) ) $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>'; else $date = ''; } }
There are two problems in this code...
- It assumes strtotime returns 'false' for failure. Previous to PHP 5.1.0, this function would return -1 on failure.
- If the pubDate ($date) contains one or more commas, strtotime will fail. Some RSS feeds use commas in pubDate.
My solution:
$date = ''; if ( $show_date ) { $date = $item->get_date(); if ( $date ) { $date = str_replace( ",", "", $date ); if ((( $date_stamp = strtotime( $date )) != -1) && (( $date_stamp = strtotime( $date )) != false )) $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>'; else $date = ''; } }
This solution works with PHP versions prior to 5.1.0 and also strips commas from the pubDate so strtotime won't fail for this reason.
Note: I will be applying this patch to default-widgets.php on the above website in a couple of days, so if you need to see this bug in action you'd better be quick. ;-)
Change History (6)
#2
in reply to:
↑ 1
@
15 years ago
Replying to SergeyBiryukov:
Probably fixed in [16566]. Please check current trunk.
Thanks for the reply. I'm new here so I don't know how to "check current trunk". Can you point me to a link where I can check this? What version is the "current trunk"? Something > 3.0.4?
#3
follow-up:
↓ 4
@
15 years ago
Yeah, currently it's 3.1-RC3-17409. You can download the latest nightly build from http://wordpress.org/nightly-builds/wordpress-latest.zip or perform SVN checkout from http://core.svn.wordpress.org/trunk/.
#4
in reply to:
↑ 3
@
15 years ago
Replying to SergeyBiryukov:
Yeah, currently it's 3.1-RC3-17409. You can download the latest nightly build from http://wordpress.org/nightly-builds/wordpress-latest.zip or perform SVN checkout from http://core.svn.wordpress.org/trunk/.
OK. I dl'ed and installed the latest nightly build and tested the RSS widget. It appears to be working correctly in this build.
Will someone update this ticket accordingly? Or is that my job?
Probably fixed in [16566]. Please check current trunk.