All pastes #67242 Raw Edit

Untitled

public text v1 · immutable
#67242 ·published 2006-06-19 16:28 UTC
rendered paste body
###############################################
test.php
##############################################

<?php

error_reporting(E_ALL ^ E_NOTICE);

include_once 'includes/fetch_functions.php';

$marker_start 	= 	'<div id="content" class="milestone">';
$marker_end 	= 	'<form id="stats" action="" method="get">';
$url         	=	'http://www.solid-state.org:8080/solidstate/milestone/v0.4';
$cache_dir		=	'/home/8631398594/www/web/new/pnTemp/Xanthia_cache/';
$vpage_name		=	'roadmap';
$cachetime		=	'86400'; //3600 seconds equals an hour

$page = $cache_dir.$vpage_name;
###################
#look here
###################
//if file exists do this
if (file_exists($page)) {
	$cachedtime	= filemtime($page) + $cachetime;

	//if page is to old, do this
	if ( $cachedtime > time()) {
	$src_content 	= 	get_url ($cache_dir.$vpage_name);	
	}

//if file doesnt exist, pull it
}else{
	$src_content 	= 	parse_retrieved_content ( $url, $marker_start, $marker_end, '', $cache_dir, $vpage_name );
}
###################
#stop looking =P
###################
$src_content	= 	trim ( $src_content );	# Eliminates trailing white space from the HTML source.
$src_content = str_replace("/solidstate/query", "http://www.solid-state.org:8080/solidstate/query", $src_content);
$src_content = str_replace('tickets active"></a>', 'tickets active"></a></td>', $src_content);

print "$src_content";		# Renders the HTML to the browser

?>

############################################################
includes/fetch_functions.php
############################################################
<?php

function get_url ( $url ) {

		$fp = @fopen($url, 'r')
			or die("Can not open $URL via Get method");
			while ( $line = @fgets ( $fp, 1024 )) {
				$contents .= $line;
			}

		fclose ( $fp );

	return $contents;

} # End of get_url().

function cache_content ($cache_dir, $vpage_name, $output ) {

		$cache_page	=	$cache_dir.$vpage_name;

      	$fpw = @fopen ( $cache_page, 'w' )
				or die("Can not write file to cache directory");
      	@fwrite ( $fpw, trim( $output ) );
      	@fclose ( $fpw );

} # End of cache_content().

function parse_retrieved_content ( $url, $marker_start, $marker_end, $debug = 1, $cache_dir, $vpage_name ) {

$_POST['debug'];

		$contents 	= get_url ( $url );

		$separator	=	"<!- Content Marker ->";

		$contents 	=  str_replace($marker_start, $separator, $contents);
		$contents 	=  str_replace($marker_end, $separator, $contents);

		$output 	=	explode ( $separator, $contents );

		cache_content ($cache_dir, $vpage_name, $output[1] );

return $output;

} # End of parse_retrieved_content().
?>