From c600e51f307528b0b04c188187e74d2543de00b8 Mon Sep 17 00:00:00 2001 From: Chouchen Date: Fri, 21 Oct 2011 16:01:16 +0200 Subject: [PATCH] Better getDateRSS --- srss.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/srss.php b/srss.php index 5f07c29..a406951 100644 --- a/srss.php +++ b/srss.php @@ -113,16 +113,17 @@ class SRSS extends DomDocument implements Iterator { $args = func_get_args(); if(func_num_args() == 0) $args[0] = 'url'; + $img = $this->xpath->query('//channel/image'); + if($img->length != 1) return; // is not in channel + $img = $img->item(0); $r = array(); - if(!empty($this->attr['image'])) + foreach($img->childNodes as $child) { - foreach($this->attr['image'] as $key => $val) + if($child->nodeType == XML_ELEMENT_NODE && in_array($child->nodeName, $args)) { - if(in_array($key, $args)) - $r[$key] = $val; + $r[$child->nodeName] = $child->nodeValue; } } - else return; return (func_num_args() > 1) ? $r : $r[$args[0]]; } @@ -683,10 +684,23 @@ class SRSSTools * format a date for RSS format * @param $date string date to format */ - public static function getRSSDate($date) + public static function getRSSDate($date, $format='') { - if(strtotime($date) !==false) + $datepos = 'dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU'; + if($format != '' && preg_match('~^(['.$datepos.']{1})(-|/)(['.$datepos.']{1})(-|/)(['.$datepos.']{1})$~', $format, $match)){ + $sep = $match[2]; + $format = '%'.$match[1].$sep.'%'.$match[3].$sep.'%'.$match[5]; + if($dateArray = strptime($date, $format)){ + $mois = intval($dateArray['tm_mon']) + 1; + $annee = strlen($dateArray['tm_year']) > 2 ? '20'.substr($dateArray['tm_year'], -2) : '19'.$dateArray['tm_year']; + $date = $annee.'-'.$mois.'-'.$dateArray['tm_mday']; + return date("D, d M Y H:i:s T", strtotime($date)); + } + return ''; + } + else if(strtotime($date) !==false ){ return date("D, d M Y H:i:s T", strtotime($date)); + } else { list($j, $m, $a) = explode('/', $date);