parse_url; $fp = fopen($this->parse_url,"r"); $error=0; while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { $error++; } } if ($error != 0) { return true; } else { return false; } } function cleanMe($input) { return htmlentities(trim($input),ENT_NOQUOTES, 'UTF-8'); } function data($parser, $data) { if ($this->itemwithin) { switch ($this->tag) { case "LINK": $this->rss_link .= $data; break; case "TITLE": $this->rss_title .= $data; break; case "DESCRIPTION": $this->rss_description .= $data; break; } } } function getCategoryID($fromname) { $query = mysql_query("SELECT id FROM feed_categories WHERE name='$fromname'"); $number = mysql_num_rows($query); $fetch=mysql_fetch_object($query); return ($number == 0) ? false : $fetch->id; } function createCategory() { //echo "CAT SUBMITTED: $this->submitted_cat"; mysql_query("INSERT INTO `feed_categories` ( `id` , `name` )VALUES ('', '$this->submitted_cat')"); $cat_id = mysql_insert_id(); return $cat_id; } function getCategoryName($id) { $cat_id_get = mysql_fetch_object(mysql_query("SELECT id FROM feed_categories WHERE name='$this->submitted_cat'")); $cat_id = $cat_id_get->id; return $cat_id; } // ------------ // FUNCTION: finish() // finish called after start // prints out the links. // here have insertation into DB // ------------- function finish($parser, $tagName) { if ($tagName == "ITEM") { $newrss = html_entity_decode($this->rss_description); if ($this->doDatabase) { // time to check if category exists.. and return ID. if (!$this->getCategoryID($this->submitted_cat)) { $cat_id = $this->createCategory(); } else { $cat_id = $this->getCategoryID($this->submitted_cat); } $check = mysql_query("SELECT * FROM feeds WHERE channel_link='$this->parse_url'"); $nums = mysql_num_rows($check); if ($nums == 0) { mysql_query("INSERT INTO `feeds` ( `id` , `version` , `media` , `channel_title` , `channel_link` , `channel_desc` , `channel_lang` , `channel_lastup` , `channel_copy` , `channel_docs` , `lastUpdate`,`channel_category` )VALUES ('', '2.0', 'RSS', 'N.A', '$this->parse_url', 'n.a', 'en', '".time()."', 'n.a', '', '','$cat_id')"); $feed_id = mysql_insert_id(); } else { $fetch = mysql_fetch_object($check); $feed_id = $fetch->id; } $tryme=mysql_num_rows(mysql_query("SELECT id FROM feed_cache WHERE title='$this->feed_title' AND link='$rss_link'")); if ($tryme == 0) { mysql_query("INSERT INTO `feed_cache` ( `id` , `feed_id` , `cache` , `on` , `title` , `link` , `guid` ,`pubDate` , `description` )VALUES ('', '$feed_id', 'today', '".time()."', '$this->rss_title', '$this->rss_link', 'n.a','".time()."', '$this->rss_description')"); } } echo '

'.$this->cleanMe($this->rss_title).'
'.$newrss.''; $newrss=''; // ------------- // Empty the variables just so we can use them again // This will prevent multiple overlkill // and stiop the links from building up // ------------- $this->rss_title = ''; $this->rss_description = ''; $this->rss_link = ''; $this->itemwithin = false; } } // ------------- // FUNCTION: start() // will be used on parsing // requires three vars // ------------- function start($parser, $tagName, $attrs) { if ($this->itemwithin) { $this->tag = $tagName; } elseif ($tagName == "ITEM") { $this->itemwithin = true; //echo $this->itemwithin/2+1-- } } function parser($url) { $xml_parser = xml_parser_create('UTF-8'); $this->parse_url=$url; xml_set_object($xml_parser,&$this); xml_set_element_handler($xml_parser, "start", "finish"); xml_set_character_data_handler($xml_parser, "data"); $this->loadfile($xml_parser); fclose($fp); // ------------- // Just like above, free it // Same o'ld // ------------- xml_parser_free($xml_parser); return true; } } ?>