Location: PHPKode > projects > phpCAMALEO > skins/phpCAMALEO/import/Prepare_contents.php
<?php
/***************************************************************************
 *	Prepare_contents.php
 *
 *	begin		: July 2005
 *	version		: 14 October 2006
 *	copyright	: (C) 2005,2006 grandolini.net
 *
 *	Split the site page contents to reduce the server load.
 *
 *	Input:		[root]/import/[language].txt
 *	Output:		[root]/lang/[language]/*.*
 *				if missing, directories are automatically created
 *
 *	If site contents or this page are changed, update the pre-processed
 *	files then manually ftp to the site the "[root]/lang/*.*" directory!!
 *
 **************************************************************************/
switch($_SESSION[sitelanguage])
{
	case 'eng':
		$contents=$_SESSION[skinf].'import/english.txt';
		$page=$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/welcome.txt';
		break;

#	case 'deu':
#		$contents=$_SESSION[skinf].'import/german.txt';
#		$page=$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/welcome.txt';
#		break;

#	case 'fre':
#		$contents=$_SESSION[skinf].'import/french.txt';
#		$page=$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/welcome.txt';
#		break;

#	case 'ita':
#		$contents=$_SESSION[skinf].'import/italian.txt';
#		$page=$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/welcome.txt';
#		break;

#	case 'esp':
#		$contents=$_SESSION[skinf].'import/spanish.txt';
#		$page=$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/welcome.txt';
#		break;

	default:
		$contents=$_SESSION[skinf].'import/english.txt';
		$page=$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/welcome.txt';
}
#
#	If there are not updates, return
#
if(	file_exists($page) and filemtime($contents)<=filemtime($page)
		&&
#	filemtime($_SESSION[skinf].'import/Prepare_contents.php')<=filemtime($page)
#		&&
	filemtime($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'skins/phpCAMALEO/import/Prepare_contents.php')<=filemtime($page)
		&&
	filemtime($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'inc/paypal_donate.htm')<=filemtime($page)
	#======================================================
	#	add any other file to look for changes here below
	#======================================================
#		&&
#	filemtime($_SESSION[skinf].'import/myfile.htm')<=filemtime($page)
)
{
	return;
}
?><html>
<head>
	<title>phpCAMALEO =)</title>
	<link href="http://<?=$_SERVER[HTTP_HOST].'/'.$_SESSION[misc][folder]?>/skins/<?=$_SESSION[misc][skin]?>/alfa2.ico" rel="shortcut icon" type="image/x-icon" />
	<link href="http://<?=$_SERVER[HTTP_HOST].'/'.$_SESSION[misc][folder]?>/skins/<?=$_SESSION[misc][skin]?>/MAIN.CSS" rel="stylesheet" type="text/css" />
	<meta http-equiv="Refresh" content="30; URL=<?=$_SERVER[REQUEST_URI]?>">
</head>
<body>
<form method="post" action="<?=$_SERVER[PHP_SELF]?>">
<h3><img src="http://<?=$_SERVER[HTTP_HOST].'/'.$_SESSION[misc][folder]?>/img/camaleos/camaleo.h50dk.gif" /> Hi, one or more pages are changed...</h3>
The page you required will be automatically loaded in 30 seconds, if you are in a hurry press the 
<input tabindex="1" class="button" type="button" name="clickme" value=" ENTER " onclick="javascript:window.location='<?=$_SERVER[REQUEST_URI]?>';"> button.
<hr id="line">
<small><?php
#
if(!file_exists($_SESSION[skinf].'lang/index.html'))
{
	#	Create the main language directory
	#
	mkdir($_SESSION[skinf].'lang',0777);
	$fd=@fopen($_SESSION[skinf].'lang/index.html','w') or die('Cannot write file: '.$_SESSION[skinf].'lang/index.html');
	@fclose($fd);
}
if(!file_exists($_SESSION[skinf].'lang/'.$_SESSION[sitelanguage]))
{
	#	Create the language subdirectory
	#
	mkdir($_SESSION[skinf].'lang/'.$_SESSION[sitelanguage],0777);
}
if(file_exists($contents))
{
	if($handle=opendir($_SESSION[skinf].'lang/'.$_SESSION[sitelanguage]))
	{
		while(($file=readdir($handle))!==false)
		{
			if(substr($file,-4)=='.txt' && is_file($_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/'.$file))
			{
				unlink($_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/'.$file);
			}
		}
		closedir($handle);
	}
	@unlink($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'/tmp/last_update_'.$_SESSION[misc][skin].'.inc'); # remove the last update include
	$result=@file($contents);
	foreach($result as $key=>$val)
	{
		$record=trim($val);
		$output_flag=1;
		if(substr($record,0,1)=='{')
		{
			#
			#	It is a tag: {aboutus}
			#
			if(substr($record,1,1)!='/')
			{
				#	It is a BEGINNING tag: {/aboutus}
				#
				$tag_name=substr($record,1,strlen($record)-2);
				$pd=0;
				unset($page_data);
			}
			else
			{
				#	It is an ENDING tag: {/aboutus}
				#
				$tmp=explode('/',$tag_name);
				if(count($tmp)>1)
				{
					$t=count($tmp)-1;
					for($i=0;$i<$t;$i++)
					{
						if(!file_exists($_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/'.$tmp[$i]))
						{
							#	Create the language subdirectory
							#
							mkdir($_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/'.$tmp[$i],0777);
						}
					}
				}
				#
				if(count($page_data)>0)
				{
					echo 'Writing @&gt; '.$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/'.$tag_name.'.txt<br />';
					$fd=@fopen($_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/'.$tag_name.'.txt', 'w') 
						or die('Cannot write file: '.$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/'.$tag_name.'.txt');
					foreach($page_data as $pk=>$pv)
					{
						$fout=@fwrite($fd, $pv."\n");
					}
					@fclose($fd);
				}
				$tag_name='';
			}
		}
		else
		{
			#	It is not a tag
			#
			$PHP_to_include=substr($record,0,7);
			if($PHP_to_include=='PHPinc=')
			{
				#	Look for: PHPinc=file-name.txt
				#
				$end=strpos($record,'§§',7);
				$f_name=substr($record,7,strlen($record)-9);
				ob_start();
				$rep_data=readfile($_SESSION[skinf].'import/'.$f_name);
				$rep_string=ob_get_contents();
				ob_end_clean();
				$record=str_replace($PHP_to_include.$f_name.'§§', $rep_string, $record);
			}
			#
			#	Page title
			#
			$PHP_to_remove=substr($record,0,9);
			if($PHP_to_remove=='PHPtitle=')
			{
				#	Look for: PHPtitle={text will become the page title}
				#
				$_TITLES[$tag_name]=substr($record,9);
				$output_flag=0;
			}
			if($output_flag==1)
			{
				#	Body substitutions
				#
				$tmp=str_replace('PHPdef=', 'define', $record);
				$record=str_replace('PHP=FIREFOX', GET_FIREFOX, $record);
				#
				$record=str_replace('PHP=PAYPAL',	file_get_contents($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'inc/paypal_donate.htm'), $record);
				$record=str_replace('PHP=info',		'<img src="img/info.gif" title="Tip" width="15" height="15" border="0" />&nbsp;', $record);
				$record=str_replace('PHP=warn',		'<img src="img/warning.gif" title="Warning!" width="17" height="16" border="0" />&nbsp;', $record);
				$record=str_replace('PHP=line',		'<hr id="line" style="height:1px; width:100%; " />', $record);
				$record=str_replace('PHP=rev',		'<font class="rev" />', $record);
				$record=str_replace('§§', '</font>', $record);
				#
				if($record=='') { $record='<br /><br />'; }
				#
				#	Add line to the output array
				#
				$page_data[$pd]=$record;
				$pd++;
			}
		}
	}
	#
	#	Write TITLES.inc page
	#
	if(count($_TITLES)>0)
	{
		echo 'Writing @&gt; '.$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/TITLES.inc<br />';
		@unlink($_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/TITLES.inc');
		$fd=@fopen($_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/TITLES.inc', 'w')
			or die('Cannot write file: '.$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/TITLES.inc');
		#
		if($fd)
		{
			$fout=@fwrite($fd, "<?php ".'$_TITLE=array('."\n");
			foreach($_TITLES as $key=>$val) { $fout=@fwrite($fd, "\t'".strtolower($key).'\'=>\''.str_replace("'","\'",$val)."',\n"); }
			$fout=@fwrite($fd, "); ?>");
			@fclose($fd);
		}
	}
}
?>
<hr id="line">
***END OF JOB ***
</small>
</form>
<script>document.forms[0].clickme.focus();</script>
</body>
</html>
<?php die; ?>
Return current item: phpCAMALEO