<?php
/*++++++++++++++++++++++++++++++++++++++++++++++++++++
| LightNEasy Content Management System
| Copyright 2007 - 2009 Fernando Baptista
| http://Lightneasy.org
++++++++++++++++++++++++++++++++++++++++++++++++++++++
| runtime.php runtime module
| no database Version 2.2.2
++++++++++++++++++++++++++++++++++++++++++++++++++++++
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
session_start();
error_reporting(E_ERROR | E_WARNING | E_PARSE);

$message="";
$menu=array();

//Includes the common functions
require_once "./LightNEasy/common.php";

readsetup();

switch(sanitize($_POST['submit'])) {
	case "Send message":
		$message=sendmessage();
		break;
	case "sendcomment":
		$message=sendcomment();
		break;
	case "deletecomment":
		$message=deletecomment();
		break;
	default:
}

if(isset($_GET['dlid'])) 
	$message=senddownload();

$selected=array('index','name');
readmenu();

function extra() {
	if(file_exists("./data/extra.htm")) printcontent($pagenum,"extra.htm");
}

function content() {
  global $pagenum,$edit,$set,$selected,$message,$menu,$langmessage,$LNEversion;
	if($message!="")
		print "<h2 class\"LNE_message\">$message</h2>\n";
	switch($_GET['do']) {
		case "sitemap": {
			print "<h2 class=\"LNE_title\">$langmessage[88]</h2>\n<p><ul>\n";
			print fullmenu(1);
			print "</ul></p>\n";
			break;
		}
		case "login": {
			print "<div align=\"center\"><h2 class=\"LNE_title\">LightNEasy $LNEversion $langmessage[120]</h2><br />\n";
			print "<form method=\"post\" action=\"".$set['indexfile']."\"><fieldset>\n";
			print "<p>Enter your password:&nbsp;<input  type=\"password\" name=\"password\" value=\"\" />\n";
			print "<input type=\"hidden\" name=\"submit\" value=\"login\" />\n";
			print "<input type=\"submit\" name=\"aa\" value=\"$langmessage[120]\" /></p>\n</form></div>\n";
			break;
		}
		default: {
			printcontent($pagenum);
		}
	}
}

function printcontent($pagenum,$file="") {
	$open="%!$";
	$close="$!%";
	if($file=="")
		$page=stripslashes(file_get_contents("./data/".$pagenum.".html"));
	else
		$page=stripslashes(file_get_contents("./data/".$file));
	while(strpos($page,$open)) {
		$pagearray=explode($open,$page,2);
		unset($pagearray1);
		$pagearray1=explode($close,$pagearray[1],2);
		switch($pagearray1[0]) {
			case "contact":
				$pagearray[0].= contact();
				break;
			case "galery":
				$pagearray[0].= galery();
				break;
			case "links":
				$pagearray[0].= show(0,"link");
				break;
			case "downloads":
				$pagearray[0].= show(0,"download");
				break;
			case "news":
				$pagearray[0].= shownews();
				break;
			default:
				if(substr($pagearray1[0],0,7)=="include") {
					print $pagearray[0];
					$pagearray[0]="";
					include trim(substr($pagearray1[0],7));
				} elseif(substr($pagearray1[0],0,9)=="lyteframe") {
					$bb=trim(substr($pagearray1[0],9));
					$aa=explode(" ",$bb);
					if($aa[3]!="") $pagearray[0].= lyteframe($aa[0],$aa[1],$aa[2],$aa[3]);
					elseif($aa[2]!="") $pagearray[0].= lyteframe($aa[0],$aa[1],$aa[2]);
					elseif($aa[1]!="") $pagearray[0].= lyteframe($aa[0],$aa[1]);
					else $pagearray[0].= lyteframe($aa[0]);
				} elseif(substr($pagearray1[0],0,7)=="wrapper") {
					$bb=trim(substr($pagearray1[0],7));
					$aa=explode(" ",$bb);
					$framewidth=0;
					if($aa[1]!="") $framewidth=strval(trim($aa[1]));
					$pagearray[0].= iframe($aa[0],$framewidth);
				} elseif(substr($pagearray1[0],0,9)=="downloads")
					$pagearray[0].= show(trim(substr($pagearray1[0],9)),"download");
				elseif(substr($pagearray1[0],0,6)=="galery")
					$pagearray[0].= galery(trim(substr($pagearray1[0],6)));
				elseif(substr($pagearray1[0],0,5)=="links")
					$pagearray[0].= show(trim(substr($pagearray1[0],5)),"link");
				elseif(substr($pagearray1[0],0,3)=="mp3")
					$pagearray[0].= mp3(trim(substr($pagearray1[0],3)));
				elseif(substr($pagearray1[0],0,6)=="videoy")
					$pagearray[0].= youtube(trim(substr($pagearray1[0],6)));
				elseif(strpos($pagearray1[0],0,6)=="videog")
					$pagearray[0].= googlev(trim(strpos($pagearray1[0],6)));
				elseif(substr($pagearray1[0],0,5)=='place')
					$pagearray[0].= trim(file_get_contents(trim(substr($pagearray1[0],5))));
				elseif(substr($pagearray1[0],0,4)=="news") {
					$bb=trim(substr($pagearray1[0],4));
					$aa=explode(" ",$bb);
					if($aa[3]!="") $pagearray[0].= shownews($aa[0],$aa[1],$aa[2],$aa[3]);
					elseif($aa[2]!="") $pagearray[0].= shownews($aa[0],$aa[1],$aa[2]);
					elseif($aa[1]!="") $pagearray[0].= shownews($aa[0],$aa[1]);
					else $pagearray[0].= shownews($aa[0]);
				} elseif(substr($pagearray1[0],0,6)=="plugin") {
					$pluginame="./plugins/".trim(substr($pagearray1[0],6));
					if(file_exists($pluginame."/place.mod"))
						$pagearray[0].= file_get_contents($pluginame."/place.mod");
					if(file_exists($pluginame."/include.mod")) {
						print $pagearray[0];
						$pagearray[0]="";
						include "$pluginame/include.mod";
					}
				} elseif(substr($pagearray1[0],0,8)=="function") {
					$bb=trim(substr($pagearray1[0],8));
					$aa=explode(" ",$bb);
					if($aa[3]!="") $aa[0]($aa[1],$aa[2],$aa[3]);
					elseif($aa[2]!="") $aa[0]($aa[1],$aa[2]);
					elseif($aa[1]!="") $aa[0]($aa[1]);
					else $aa[0]();
				} else
					print "\n".html_entity_decode($pagearray1[0])."\n";
		}
		$page=$pagearray[0].$pagearray1[1];
	}
	print $page;
}
?>
