Location: PHPKode > projects > LNP: Lightweight news portal > news/index.php
<?php
/*
* LGPL piece of code, refer to file included (license)
*/
/*-------------------------------------------------------------------------------------------------
* lightweight news engine v1 par Yanick Bourbeau 2002
* -------------------------------------------------------------------------------------------------*/

require_once("includes/config.php");
require_once(SITE_ROOT."class/phemplate.class.php");

switch($_GET["action"])
	{
	case "potd_old":
	$tpl = new phemplate(SITE_ROOT);
	$tpl->set_file("main","resources/templates/layout_potd.tpl");
	$tpl->set_var("site.name",SITE_NAME);
	$tpl->set_var("site.url",SITE_URL);
	require_once("includes/vote.data.php");
	$tpl->set_var("vote.question",DATA_QUESTION);
	$tpl->set_var("news.title","Picture of the day archive");


// archives
		$dir = opendir(SITE_ROOT."resources/newsdata/news/");
		while ($file = readdir($dir))
				{
				if ($file[0]!=".")
						{
						$list[] = $file;
						}
				}
		closedir($dir);
		rsort($list);

		for ($x=10;$x<count($list);$x++)
			{
			$line = file(SITE_ROOT."resources/newsdata/news/".$list[$x]);
			$archive[$x]["id"] = $list[$x];
			$archive[$x]["title"] = str_replace("\n","",str_replace("\r","",$line[0]));
			}
		$tpl->set_loop("archive",$archive);

// potd listing
   $list = array();
   
		$dir = opendir(SITE_ROOT."navmedia/newsdata/potd/old/");
		while ($file = readdir($dir))
				{
				if ($file[0]!=".")
						{
						if (strpos($file,"_thumb"))
							{
						$list[]["photo"] = $file;
						$list[count($list)-1]["date"] = date("H:i:s m/d/Y",filectime(SITE_ROOT."navmedia/newsdata/potd/old/".$file));
						$list[count($list)-1]["url"] = "show_potd.php?potd=".str_replace("_thumb","_photo",$file);
							}
						}
				}
		closedir($dir);
		rsort($list);
		for ($x=0;$x<count($list);$x++)
					$potd[] = $list[$x];
		$tpl->set_loop("potd",$potd);				
		
	print $tpl->process('','main',2);
	break;
	
	case "show_potd_full":
	print "<HTML><TITLE>POTD</TITLE><BODY BGCOLOR=black><DIV ALIGN=CENTER><BR><IMG SRC=navmedia/newsdata/potd/photo.jpg><BR>
	<FORM>
	<INPUT TYPE=button value=Close onclick=window.close();>
	</FORM>
	</DIV></BODY></HTML>";
	break;
	
	case "vote":
	$tpl = new phemplate(SITE_ROOT);
	$tpl->set_file("main","resources/templates/vote_finish.tpl");
	$tpl->set_var("site.name",SITE_NAME);
	$tpl->set_var("site.url",SITE_URL);
	
	require_once("includes/vote.data.php");
	if (DATA_IP != $_SERVER["REMOTE_ADDR"])
		{
	
	if ($_GET["param1"]=="yes") { $yes = 1; $no = 0; }
	if ($_GET["param1"]=="no") { $yes = 0; $no = 1; }
	
	$fp = @fopen("includes/vote.data.php","w+");
	if ($fp)
	$yes = $yes + DATA_YES;
	$no = $no + DATA_NO;
	fputs($fp,"<?
	define(\"DATA_QUESTION\",\"".DATA_QUESTION."\");
	define(\"DATA_YES\",".$yes.");
	define(\"DATA_NO\",".$no.");
	define(\"DATA_IP\",\"".$_SERVER["REMOTE_ADDR"]."\");
	
	?>");
			}

	$total_votes = DATA_YES + DATA_NO;
	$yes_percent = (DATA_YES * 100) / $total_votes;
	$no_percent = (DATA_NO * 100) / $total_votes;
	$tpl->set_var("vote.question",DATA_QUESTION);
	$output_yes = "
	<TABLE>
	<TR>";
	for ($x=0;$x<(round($yes_percent) / 10);$x++)
		{
		$output_yes .= "<TD bgcolor=green width=12 nowrap>&nbsp;</TD>";
		}
		
	$output_yes .= "<TD> <B>".round($yes_percent)."%</B> (".DATA_YES.")</TD></TR>
	</TABLE>
	";
	
	
	$tpl->set_var("vote.yes",$output_yes);

	$output_no = "
	<TABLE>
	<TR>";
	for ($x=0;$x<(round($no_percent) / 10);$x++)
		{
		$output_no .= "<TD bgcolor=red width=12 nowrap>&nbsp;</TD>";
		}
		
	$output_no .= "<TD> <B>".round($no_percent)."%</B> (".DATA_NO.")</TD></TR>
	</TABLE>
	";


	$tpl->set_var("vote.no",$output_no);
	print $tpl->process('','main',1);
	
	@fclose($fp);
	break;
	
	case "full":
	$tpl = new phemplate(SITE_ROOT);
	$tpl->set_file("main","resources/templates/layout_full.tpl");
	$tpl->set_var("site.name",SITE_NAME);
	$tpl->set_var("site.url",SITE_URL);
require_once("includes/vote.data.php");
	$tpl->set_var("vote.question",DATA_QUESTION);
	$param = $_GET["param"];
	$param = str_replace(".","",$param);
	$param = str_replace("|","",$param);
	$param = str_replace(",","",$param);
	$param = str_replace("/","",$param);
	$param = str_replace("\\","",$param);
	$param = str_replace("|","",$param);
	$param = str_replace("'","",$param);
	$param = str_replace("\"","",$param);
	
	if (file_exists(SITE_ROOT."resources/newsdata/news/".$param))
		{
		$file = file(SITE_ROOT."resources/newsdata/news/".$param);
		for ($x=0;$x<count($file);$x++)
			{
			$file[$x] = str_replace("\r","",$file[$x]);
			$file[$x] = str_replace("\n","",$file[$x]);
			}
		$photo = "";
		$photos = explode(",",$file[3]);
		
		for ($x=0;$x<count($photos);$x++)
			{
			$photos[$x] = str_replace("\r","",$photos[$x]);
			$photos[$x] = str_replace("\n","",$photos[$x]);
			if ($photos[$x]!="")
					{
					$photo_img = explode(".",$photos[$x]);
					$photo_img = $photo_img[0]."_thumb.".$photo_img[1];
					$photo .= "<TD>
					<a href=\"show_photo.php?photo=".$photos[$x]."\" TARGET=_NEW><IMG SRC=\"navmedia/newsdata/news/".$photo_img."\" border=\"0\">
					</a>
					</TD>";
					}
			}
		if (strlen($photo) != "") $photo = "<BR><BR><BR><TABLE align=center><TR>".$photo."</TR></TABLE>\r\n";
		$tpl->set_var("news.title",$file[0]);
		$tpl->set_var("news.author",$file[1]);
		$tpl->set_var("news.date",$file[2]);
		$tpl->set_var("news.story",stripslashes(base64_decode($file[5])).$photo);

		// archives
		$dir = opendir(SITE_ROOT."resources/newsdata/news/");
		while ($file = readdir($dir))
				{
				if ($file[0]!=".")
						{
						$list[] = $file;
						}
				}
		closedir($dir);
		rsort($list);

		for ($x=10;$x<count($list);$x++)
			{
			$line = file(SITE_ROOT."resources/newsdata/news/".$list[$x]);
			$archive[$x]["id"] = $list[$x];
			$archive[$x]["title"] = str_replace("\n","",str_replace("\r","",$line[0]));
			}
				
		$tpl->set_loop("archive",$archive);
		
	print $tpl->process('','main',2);

		}
		else
		{
		header("Location: index.php");
		die();
		}
		
	break;
	
	
	default:
	$tpl = new phemplate(SITE_ROOT);
	$tpl->set_file("main","resources/templates/layout.tpl");
	$tpl->set_var("site.name",SITE_NAME);
	$tpl->set_var("site.url",SITE_URL);
	
	$dir = opendir(SITE_ROOT."resources/newsdata/news/");
	while ($file = readdir($dir))
		{
		if ($file[0]!=".") $items[] = $file;
		}
	closedir($dir);
	rsort($items);
	if (count($items) >= 10) $max_items = 10; else $max_items = count($items);
	
	for ($x=0;$x<$max_items;$x++)
		{
		$item = file(SITE_ROOT."resources/newsdata/news/".$items[$x]);
		for ($y=0;$y<count($item);$y++)
				{
				$item[$y] = str_replace("\r","",$item[$y]);
				$item[$y] = str_replace("\n","",$item[$y]);
				}
				
		$news[$x]["title"] = $item[0];
		$news[$x]["author"] = $item[1];
		$news[$x]["date"] = $item[2];
		$news[$x]["intro"] = stripslashes(base64_decode($item[4]));
		$news[$x]["story"] = stripslashes(base64_decode($item[5]));
		$news[$x]["id"]	= $items[$x];
		}
		
	$tpl->set_loop("news",$news);	
	// archives
		$dir = opendir(SITE_ROOT."resources/newsdata/news/");
		while ($file = readdir($dir))
				{
				if ($file[0]!=".")
						{
						$list[] = $file;
						}
				}
		closedir($dir);
		rsort($list);

		for ($x=10;$x<count($list);$x++)
			{
			$line = file(SITE_ROOT."resources/newsdata/news/".$list[$x]);
			$archive[$x]["id"] = $list[$x];
			$archive[$x]["title"] = str_replace("\n","",str_replace("\r","",$line[0]));
			}
		$tpl->set_loop("archive",$archive);
		
	require_once("includes/vote.data.php");
	$tpl->set_var("vote.question",DATA_QUESTION);
	print $tpl->process('','main',2);
	
	}


?>
Return current item: LNP: Lightweight news portal