public function rss_news(){
//Load the shiny new rssparse
$this->load->library('RSSParser', array('url' => 'http://www.manager.co.th/RSS/Home/Breakingnews.xml', 'life' => 0));
//Get six items from the feed
$data = $this->rssparser->getFeed(10);
return $data;
}
public function rss_sport(){
//Load the shiny new rssparse
$this->load->library('RSSParser', array('url' => 'http://www.manager.co.th/rss/sport/sport.xml', 'life' => 0));
//Get six items from the feed
$data = $this->rssparser->getFeed(10);
return $data;
}
public function main_home()
{
$data['rss_news'] = $this->rss_news();
$data['rss_sport'] = $this->rss_sport();
//is there a cache file ?
if (file_exists($filename))
{
//Has it expired?
$timedif = (time() - filemtime($filename));
if ($timedif < ( $this->cache_life * 60))
{
//its ok - so we can skip all the parsing and just return the cached array here
$this->data = unserialize(implode('', file($filename)));
return true;
}
//So raise the falg
$this->write_cache_flag = true;
} else {
//Raise the flag to write the cache
$this->write_cache_flag = true;
}
}
//Parse the document
$rawFeed = file_get_contents($this->feed_uri);
$xml = new SimpleXmlElement($rawFeed);
//Assign the channel data
$this->channel_data['title'] = $xml->channel->title;
$this->channel_data['description'] = $xml->channel->description;
//Do we need to write the cache file?
if ($this->write_cache_flag)
{
if ( ! $fp = @fopen($filename, 'wb'))
{
echo "ERROR";
log_message('error', "Unable to write cache file: ".$cache_path);
return;
}
flock($fp, LOCK_EX);
fwrite($fp, serialize($this->data));
flock($fp, LOCK_UN);
fclose($fp);
}
return true;
}
/* Return the feeds one at a time: when there are no more feeds return false
* @param No of items to return from the feed
* @return Associative array of items
*/
function getFeed($num) {
$c = 0;
$return = array();
foreach($this->data AS $item)
{
$return[] = $item;
$c++;
if($c == $num) break;
}
return $return;
}
/* Return channel data for the feed */
function & getChannelData() {
$flag = false;
if(!empty($this->channel_data)) {
return $this->channel_data;
} else {
return $flag;
}
}
/* Were we unable to retreive the feeds ? */
function errorInResponse() {
return $this->feed_unavailable;
}