public static function parse($source, $url, $more) { $source = str_replace('$', '$', $source); //try to get encoding of RSS if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { $in_enc = strtoupper($m[1]); } else { $in_enc = 'UTF-8'; } //default encoding is utf-8 //change encoding if it's needed $source = RSS::recode($in_enc, $modx->config['modx_charset'], $source); //Collect data about feeed $feed_title = RSS::find_tag($source, 'title'); $feed_link = RSS::find_tag($source, 'link'); $feed_description = RSS::find_tag($source, 'description'); #RSS::_log("$feed_title | $feed_link | $feed_description"); //parse items preg_match_all('/<item[^>]*>(.*?)<\\/item>/ism', $source, $items); $items = $items[1]; /*******************\ <link>link to item</link> <title>Title of item</title> <pubDate>Fri, 01 Apr 2011 14:13:08 +0400</pubDate> <description><![CDATA[Text of item]]></description> \*******************/ $outputs = array(); //walk on items for ($i = 0; $i < count($items); $i++) { $item = $items[$i]; //Collect data $link = RSS::find_tag($item, 'link'); $title = RSS::find_tag($item, 'title'); $date = RSS::find_tag($item, 'pubdate'); $text = RSS::find_tag($item, 'description'); //clear CDATA $text = preg_replace('/(<!\\[CDATA\\[|\\]\\]>)/i', '', $text); //Escape MODx specials $from = array('{', '}', '[', ']'); $to = array('{', '}', '[', ']'); $text = str_replace($from, $to, $text); $param = array('link' => $link, 'title' => $title, 'date' => $date, 'text' => $text, 'more' => $more, 'feed_title' => $feed_title, 'feed_link' => $feed_link, 'feed_description' => $feed_description); array_push($outputs, $param); } return $outputs; }