Файл: adultscript-2.0.3-pro/files/libraries/framework/feed.php
Строк: 45
<?php
defined('_VALID') or die('Restricted Access!');
class VFeed
{
public static function parse($feed, $limit=0)
{
if( ! function_exists('simplexml_load_file')) {
die('SimpleXML must be installed to use the feed utility!');
}
// bug here...
$parser = ((file_exists($feed) && is_file($feed)) OR VValid::url($feed)) ? 'simplexml_load_file' : 'simplexml_load_string';
$feed = $parser($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($feed === FALSE) {
return array();
}
$feed = isset($feed->channel) ? $feed->xpath('//item') : $feed->entry;
$i = 0;
$items = array();
foreach ($feed as $item) {
if ($limit > 0 AND $i++ === $limit) {
break;
}
$items[] = (array) $item;
}
return $items;
}
public static function create($info, $items, $format = 'rss2', $encoding = 'UTF-8')
{
$feed = '<?xml version="1.0" encoding="'.$encoding.'"?><rss version="2.0"><channel></channel></rss>';
$feed = simplexml_load_string($feed);
foreach ($info as $name => $value){
if (($name === 'pubDate' OR $name === 'lastBuildDate') AND (is_int($value) OR ctype_digit($value))) {
$value = date(DATE_RFC822, $value);
}
$feed->channel->addChild($name, $value);
}
foreach ($items as $item) {
$row = $feed->channel->addChild('item');
foreach ($item as $name => $value) {
if ($name === 'pubDate' AND (is_int($value) OR ctype_digit($value))) {
$value = date(DATE_RFC822, $value);
}
$row->addChild($name, $value);
}
}
return $feed->asXML();
}
}
?>