title = ""; $image->url = ""; $image->link = ""; $image->description = ""; $rss->image = $image; */ function pubDate($rssitem) { if($rssitem['pubdate']) return $rssitem['pubdate']; if($rssitem['updated']) return $rssitem['updated']; if($rssitem['published']) return $rssitem['published']; } function contentDesc($rssitem) { $minLength = 3; $desc = $rssitem['content']['encoded']; if ($desc && strlen($desc) > $minLength) { return $desc; } $desc = $rssitem['atom_content']; if ($desc && strlen($desc) > $minLength) { return $desc; } $desc = $rssitem['description']; if ($desc && strlen($desc) > $minLength) { return $desc; } } function createFeed() { $feed_path = "cache/feed.xml"; $RSS_FEEDS = array("http://www.gracepointstories.org/feed/", "http://www.gracepointforum.org/feeds/posts/default?alt=rss", "http://www.disgracepointonline.org/feeds/posts/default?alt=rss", "http://gracepointworship.org/?feed=rss2", "http://www.dishgracepoint.com/feeds/posts/default?alt=rss", "http://feeds.feedburner.com/GracepointDevotionsSharing", "http://feeds.feedburner.com/GracepointVideoGracepointFellowshipChurch"); // "http://kellykangblog.wordpress.com/feed/"); $MAX_POSTS_TO_CACHE = 300; /* Set RSS properties */ $rss = new UniversalFeedCreator(); //$rss->useCached(); $rss->title = ""; $rss->author = ""; $rss->pubdate = ""; $rss->description = ""; $rss->link = ""; $rss->syndicationURL = ""; $feeds = array(); foreach($RSS_FEEDS as $url) { $item = array(); $current_feed = fetch_rss($url); $current_items = $current_feed->items; for($i = 0; $i < $MAX_POSTS_TO_CACHE; $i++) { $current_item = $current_items[$i]; $current_item['channel-title'] = $current_feed->channel['title']; $current_item['channel-link'] = $current_feed->channel['link']; array_push($item, $current_item); } array_push($feeds, $item); } for($i = 0; $i < $MAX_POSTS_TO_CACHE; $i++) { $most_recent = 0; for($j = 0; $j < count($feeds); $j++) { $most_recent_date = pubDate($feeds[$most_recent][0]); $current_item_date = pubDate($feeds[$j][0]); if (!isset($current_item_date) || $current_item_date == '') { $most_recent = $most_recent; } else if (!isset($most_recent_date) || $most_recent_date == '') { $most_recent = $j; } else { $most_recent = strtotime($most_recent_date) > strtotime($current_item_date) ? $most_recent : $j; } } $item = array_shift($feeds[$most_recent]); $new_item = new FeedItem(); $new_item->title = $item['title']; $new_item->date = pubDate($item); $new_item->author = $item['dc']['creator']; $new_item->link = $item['link']; $new_item->category = $item['category']; // With description, remove weird characters, convert br's and p's to newlines, then strip tags $str = preg_replace('/[\x00-\x1F\x80-\xFF]/', ' ', contentDesc($item)); $str = str_replace('description = trim($str); $new_item->additionalElements['channel-title'] = $item['channel-title']; $new_item->additionalElements['channel-link'] = $item['channel-link']; if (isset($item['title']) && $item['title'] != "" && strlen($new_item->description) > 30) { $rss->addItem($new_item); } } $rss->saveFeed("RSS2.0", $feed_path, false); } //Check if it's cached, otherwise, create cache $feed_path = "cache/feed.xml"; if(!file_exists($feed_path) || (time() - filemtime($feed_path)) > 1800 ) { // Delete cache $dir = './cache'; $command = 'rm ' . $dir . '/*'; system($command); createFeed(); } $startIndex = isset($_GET["startIndex"]) ? (int) $_GET["startIndex"] : 0; $range = isset($_GET["range"]) ? (int) $_GET["range"] : -1; $xml = file_get_contents($feed_path); if ($startIndex != 0 || $range >= 0) { // Only get the feeds that we want $arr = XML_unserialize($xml); $items = $arr['rss']['channel']['item']; $newItems = array(); $stopIndex = $range > 0 ? $range + $startIndex : count($items); for ($i = 0; $i + $startIndex < $stopIndex; ++$i) { if (isset($items[$i + $startIndex])) { $newItems[$i] = $items[$i + $startIndex]; } } $arr['rss']['channel']['item'] = $newItems; $xml = XML_serialize($arr); } @header('Content-type: text/xml'); echo $xml; ?>