All pastes #89591 Raw Edit

Stuff

public php v1 · immutable
#89591 ·published 2006-07-16 20:10 UTC
rendered paste body
<?function readXMLFile($filename) {	if(file_exists($filename)) { 		if(filesize($filename) != 0) {			$data = implode('', file($filename));			$result = simplexml_load_file($filename);			return $result;		}	}	else {		echo("Um, there was a problem.");	}}function grab_feed($xml, $i) {	$ch = curl_init();	curl_setopt ($ch, CURLOPT_URL, $xml[$i]['feed_url']);	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 1);	$file_contents = curl_exec($ch);	if($file_contents != "<html><body></body></html>" || $file_contents != "") { 		file_put_contents($xml[$i]['feed_local'], $file_contents);	}	curl_close($ch);}function feed_add($feed_url, $feed_increment, $feed_name, $feed_local, $num) {	$sql = "INSERT INTO " . $table_prefix . "feeds(feed_id, feed_url, feed_increment, feed_name, feed_local, num) VALUES ('', '" . $feed_url . "', '" . $feed_increment . "', '" . $feed_name . "', '" . $feed_local . "', " . $num . ")";	$result = sqlquery($sql);	$output = "Feed " . $feed_name . " successfully added. ";	return $output;}function get_feed($feed_id = 777)  {	$now = time();	$xml = get_feed_data($feed_id);	if($feed_id == 777) {		for($k=0; $k<count($xml); $k++) {			if (file_exists($xml[$k]['feed_local'])) {				if($now > strtotime($xml[$k]['feed_increment'], filectime($xml[$k]['feed_local']))) {					grab_feed($xml, $k);				}				else {					$time[$k] = round(date("U", strtotime($xml[$k]['feed_increment'], filectime($xml[$k]['feed_local'])) - time()) / 60, 2) . " minutes";				}			}			else {				grab_feed($xml, $k);			}		}	}}function get_feed_data($feed_id = 777)  {	global $table_prefix; 	if($feed_id == 777) {		$sql = "SELECT * from " . $table_prefix . "feeds";		$result = sqlquery($sql);		if(mysql_num_rows($result) != 0) {			$i = 0;			while($xmlresult = mysql_fetch_assoc($result)) {				if(filesize($xmlresult['feed_local']) != 0) {					$xml[$i]['feed_id'] = $xmlresult['feed_id'];					$xml[$i]['feed_url'] = $xmlresult['feed_url'];					$xml[$i]['feed_increment'] = $xmlresult['feed_increment'];					$xml[$i]['feed_name'] = $xmlresult['feed_name'];					$xml[$i]['feed_local'] = $xmlresult['feed_local'];					$xml[$i]['num'] = $xmlresult['num'];					$i++;				}			}		}	}	return $xml;}function output_feed($feed_id = 777, $view = "composite") {		$xml = get_feed_data($feed_id);		if($view == "list") {			if($feed_id == 777) {				for($h=0; $h<count($xml); $h++) {					if(file_exists($xml[$h]['feed_local']) && filesize($xml[$h]['feed_local']) != 0) {						$latest = readXMLfile($xml[$h]['feed_local']);						$icon = getFavIcon($xml[$h]['feed_url']);						if($h % 2 != 0) { 							if($icon != "") {								$output .= "<div onmouseover=\"this.className='hover'\" onmouseout=\"this.className='feedlist'\" class=\"feedlist\">\n<h3><img src=\"" . $icon . "\" /><a href=\"" . $xml[$h]['feed_url'] . "\">" . $xml[$h]['feed_name'] . "</a></h3>\n<p class=\"update\">next update: " . $time[$h] . "</p>\n";							}													}						else {							if($icon != "") {								$output .= "<div onmouseover=\"this.className='hover clear'\" onmouseout=\"this.className='feedlist clear'\" class=\"feedlist clear \">\n<h3><img src=\"" . $icon . "\"  /><a href=\"" . $xml[$h]['feed_url'] . "\">" . $xml[$h]['feed_name'] . "</a></h3>\n<p class=\"update\">next update: " . $time[$h] . "</p>\n";							}						}						$output .= "<ul>";									for($j=0; $j<$xml[$h]['num']; $j++) {							if(isSet($latest)) {								if(!isSet($latest->channel->item[$j])) {								if(!isSet($latest->item[$j]->title) && $xml[$i]['feed_name'] == "AudioScrobbler") { 										$latest->item[$j]->title = $latest->item[$j]->description; 									}									else if (preg_match("/audioscrobbler/i", $xml[$h]['feed_url']) && !isSet($latest->item[$j]->title)) { 										$latest->item[$j]->title = "Untitled Item"; 									}									$output .= "<li><a href=\"" . $latest->item[$j]->link . "\">" . $latest->item[$j]->title . "</a></li>\n";								}								else {									if(!isSet($latest->channel->item[$j]->title) && $xml[$i]['feed_name'] == "AudioScrobbler") { 										$latest->channel->item[$j]->title = $latest->channel->item[$j]->description; 									}									else if (preg_match("/audioscrobbler/i", $xml[$h]['feed_url']) && !isSet($latest->channel->item[$j]->title)) { 										$latest->item[$j]->title = "Untitled Item"; 									}									$output .= "<li><a href=\"" . $latest->channel->item[$j]->link . "\">" . $latest->channel->item[$j]->title . "</a></li>\n";								}							}						}						$output .= "</ul></div>\n\n";					}				}			}	}	else if($view == "composite") {		$latest = simplexml_merge($xml);		print_r($latest);	}	return $output;}function simplexml_merge ($xml) {	for($i=0;$i<count($xml);$i++) {		$xml_file[$i] = readXMLfile($xml[$i]['feed_local']);		if(isSet($xml_file[$i]->channel->item)) {			$items[$i] = $xml_file[$i]->channel->item;			if(isSet($xml_file[$i]->channel->item[0]->pubDate)) {				$dates[$i] = strtotime($xml_file[$i]->channel->item[0]->pubDate);			}			else if(isSet($xml_file[$i]->channel->item[0]->date)) {				/*				** The Dublin core's default data format uses ISO 8601 which can't				** be parsed directly using PHP's strtotime().  It is not the only				** valid format so this might fail nonetheless ...				*/				list($year, $month, $day, $hour, $minute, $second) = sscanf($xml_file[$i]->item[0]->date, "%4d-%2d-%2dT%2d:%2d:%2d");				echo($xml_file[$i]->item[0]->date);				$dates[$i] = strtotime("$year-$month-$day $hour:$minute:$second");			}			else {				$dates[$i] = strtotime($xml_file[$i]->channel->item[0]->title); //xanga			}		}		else if(isSet($xml_file[$i]->item)) {			$items[$i] = $xml_file[$i]->item;			if(isSet($xml_file[$i]->item[0]->pubDate)) {				$dates[$i] = strtotime($xml_file[$i]->channel->item[0]->pubDate);			}			else if(isSet($xml_file[$i]->item[0]->date)) {				/*				** The Dublin core's default data format uses ISO 8601 which can't				** be parsed directly using PHP's strtotime().  It is not the only				** valid format so this might fail nonetheless ...				*/				echo($xml_file[$i]->item[0]->date);				list($year, $month, $day, $hour, $minute, $second) = sscanf($xml_file[$i]->item[0]->date, "%4d-%2d-%2dT%2d:%2d:%2d");				$dates[$i] = strtotime("$year-$month-$day $hour:$minute:$second");			}			else {				$dates[$i] = strtotime($xml_file[$i]->item[0]->title); //xanga			}		}	}}?>