Location: PHPKode > projects > newspaper.php > newspaper-php/newspaper.php
<?
// newspaper.php
include "newspaper_include.php";
deb("Inp_art_fqdn is $Inp_art_fqdn");
deb("You can change viewdate like this: <a href=\"http://$HTTP_HOST$SCRIPT_NAME?nowis=2002-04-01%2018:00:00\">http://$HTTP_HOST$SCRIPT_NAME?nowis=2002-04-01%2018:00:00</a>");
deb("<hr>");

$version="0.04";
# v0.04: new parameter nowis, call it like this: 
#        http://wwwpublish.zdf/aktuelles/newspaper.php?nowis=2002-04-01%18:00:00
#        this is to let me see how a page looks at a certain date
#
$me="newspaper.php V$version";
$showme="Page generated with <a href=\"http://lena.franken.de/newspaper\" target=\"_parent\">$me</a>";

$now = get_now();
# iterate all lines $showme from configfile
# check wether the files mentioned there have to be shown
# 
foreach ($Ishowme as $line) {
	deb("Examining line: $line");
	list ($file_fn,$from,$to)=split("\|",$line);

	# transform $from: dd.mm.yyyy hh:mm -> yyyy.mm.dd hh:mm:00
	if (ereg ("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2})", $from, $regs)) {
		$from = sprintf ("%04d-%02d-%02d %02d:%02d:%02d",
			$regs[3],$regs[2],$regs[1],$regs[4],$regs[5],0);
		deb("From is $from");
	} else {
		continue;
	}
	# transform $to: dd.mm.yyyy hh:mm -> yyyy.mm.dd hh:mm:00
	if (ereg ("([0-9]{1,2}).([0-9]{1,2}).([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2})", $to, $regs)) {
		$to = sprintf ("%04d-%02d-%02d %02d:%02d:%02d",
			$regs[3],$regs[2],$regs[1],$regs[4],$regs[5],0);
		deb("To is $to");
	} else {
		continue;
	}

	# is this the time to show the file?
        if (strcmp($now,$from) <0) {
                deb("skipping file $file_fn because from $from not reached now.");
                continue;
        }
        if (strcmp($now,$to) >0) {
                deb("skipping file $file_fn because to $to was yesterday.");
                continue;
        }

	// create filename including path
	$file_fqn  = "$Inp_art_fqdn/$file_fn";
	if (is_file($file_fqn)) {
		deb ("File $file_fqn exists");
	}
	deb("<b>file $file_fqn will be shown</b>");
	$fqn_toshow[] = $file_fqn;
}


// 
$beef="";
foreach ($fqn_toshow as $fqn) {
	deb("filename to show is $fqn");
	$part = getfile($fqn);
	$part = eregi_replace ("<body bgcolor=\"\#......\">","<body>",$part);
	$part = eregi_replace ("^.*<body>","",$part);
	$part = eregi_replace ("</body>.*$","",$part);
	$beef .= $part . '<br clear="all"<p>&nbsp;</p>';
}

$beef = eregi_replace ('PHPSCRIPT_HINT',$showme,$beef);


// output page
print <<<EOPAGE
<html>
<head>
<base href="$Inp_art_www">
</head>
<title>
$Ititle
</title>
<body>
$beef
</body>
</html>

EOPAGE;

if ($debug) {
	phpinfo();
}


function deb($output) {
	global $debug;
	if ($debug) {
		print $output . "<br>\n";
	}
}

function get_now() {
	global $nowis;
	if ($nowis) {
		$now = $nowis;
	} else {
		$now = date ("Y-m-d H:i:s");
	}
	deb("now is $now");
	return $now;
}


function getfile ($filename) {
	if (! is_file($filename)) {
		$er = "<b>Could not open file \"$filename\"</b><br>";
		deb($er);
		return "";
	}
	$SF=fopen ("$filename","r");
	while (!feof($SF)) {
		$line = fgets($SF,1000);
		$content .= $line;
	}
	fclose($SF);
	return $content;
}

?>
Return current item: newspaper.php