<?php	
	$feeds = $db->get('rssfeeds')->result_array();
	
	require_once('lib/class_rssparser.php');
	
	$rssparser = new RSSParser;
	
	$rssparser->cache_dir = 'cache/'; 
	$rssparser->cache_time = 0; 
	$rssparser->cp = 'UTF-8'; 
	$rssparser->date_format = 'Y-m-d H:i:s';
	
	foreach ($feeds AS $key => $item)
	{
		$rss = $rssparser->get($item['url']);
		
		foreach ($rss['items'] AS $key => $data)
		{
			if (strstr($item['url'], 'twitter.com'))
			{
				$data['title'] = trim(str_ireplace($Own['username'] . ':', '', $data['title']));
			}
			
			$checklog = $db->query("SELECT id FROM rsslog WHERE rssid = " . $item['id'] . " AND hash = '" . md5($data['title']) . "'")->result_array();
			
			if (!$checklog['id'])
			{
				if (trim($data['title']) != '' AND !strstr($data['title'], '<![CDATA['))
				{
					if ($item['field'] == 'title')
					{
						$message = $data['title'];
					}
					else
					{
						$message = '<strong>' . $data['title'] . '</strong><p>' . $data['description'] . '</p>';
					}
					
					if (strtotime($data['pubDate']) > 0)
					{
						$time = strtotime($data['pubDate']);
					}
					else
					{
						$time = time();
					}

					$db->insert('entry', array(
						'prefix' => 1,
						'content' => Format::Safe(str_replace('script', '<span>script</span>', $message)),
						'time' => $time,
						'from' => Format::Safe($item['from']) 
					));
					
					$db->insert('rsslog', array(
						'rssid' => $item['id'],
						'hash' => md5($data['title'])
					));
				}
			}
			
			unset($checklog);
		}
		
		unset($rss);
	}