Location: PHPKode > projects > phpCAMALEO > common/includes/GetText.php
<?php
/***************************************************************************
 *	GetText.php
 *
 *	begin		: July 2005
 *	version		: 24 October 2006
 *	copyright	: (C) 2004,2006 grandolini.net
 *
 *	Get page contents from a preprocessor: "Prepare_contents.php"
 *
 ***************************************************************************/

switch($_SESSION[sitelanguage])
{
	case 'eng':	$fname=$_SESSION[skinf].'lang/eng/'.$_SESSION[PageNr].'.txt';	break;
	case 'esp':	$fname=$_SESSION[skinf].'lang/esp/'.$_SESSION[PageNr].'.txt';	break;
	case 'ita':	$fname=$_SESSION[skinf].'lang/ita/'.$_SESSION[PageNr].'.txt';	break;
	case 'fre':	$fname=$_SESSION[skinf].'lang/fre/'.$_SESSION[PageNr].'.txt';	break;
	case 'deu':	$fname=$_SESSION[skinf].'lang/deu/'.$_SESSION[PageNr].'.txt';	break;
	default:	$fname=$_SESSION[skinf].'lang/'.$_SESSION[sitelanguage].'/'.$_SESSION[PageNr].'.txt';
}
if(file_exists($fname))
{
	$result=@file($fname);
	foreach($result as $key=>$val)
	{
		$record=trim($val);
		#
		#	Create the proper link to the download page pending on user log
		#
		if($USER_ID!='')	{ $record=str_replace('PHP=GETDWNLOAD','Open the <a href="Download.php">downloads</a> page.', $record); }
		else				{ $record=str_replace('PHP=GETDWNLOAD','We ask you to <a href="Access.php">login</a> to be able to download the '.$_SERVER[HTTP_HOST].' products.', $record); }
		#
		#	Variables
		#
		$record=str_replace('PHP=GET_PDF','<a class="img" href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank" style="border:0px;"><img src="img/getacro.gif" alt="Get Adobe Reader" title="Get Adobe Reader" /></a>',$record);
		$record=str_replace('PHP=SKYPEID',$_SESSION[misc][skype_id],$record);
		#
		#	Currency converter
		#
		$str_to_search='PHP=USDtoEUR'; $currency='USDtoEUR'; $test=strpos($record,$str_to_search,0);
		if($test==0) { $str_to_search='PHP=EURtoUSD'; $currency='EURtoUSD'; $test=strpos($record,$str_to_search,0); }
		if($test>0)
		{	include_once($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'/includes/oanda.inc'); 
			$record=str_replace('PHP=exchange',number_format($_SESSION[eur_to_usd],5,'.',','),$record);
		}
		#
		#	Check for commands
		#
		$cmd=substr($record,0,9);
		#
		if($cmd=='PHPsetSE=' || $cmd=='PHPsetCO=' || $cmd=='PHPdwnLI=' || $cmd=='PHPimgLI=')
		{
			#	Set var
			#
			switch($cmd)
			{
				case 'PHPsetSE=':
					#	setSESSION
					#
					list($name,$value)=explode(',',substr($record,9));
					$_SESSION[$name]=$value;
					break;
					#
				case 'PHPsetCO=':	
					#	setCOOKIE
					#
					list($name,$value)=explode(',',substr($record,9));
					#-| setcookie($name,$value); |-# php does NOT allow this as some headers are already sent at this point
					?><script type="text/javascript">setCookie('<?=$name?>','<?=$value?>');</script><?php
					break;
					#
				case 'PHPdwnLI=':
					# 	download list
					#
					#	PHPdwnLI=local path,[URL: if different than local path]
					#	example: PHPdwnLI=downloads/utils,http://prdownloads.sourceforge.net/phpcamaleo,?download,[DIRONLY]
					#
					include_once($_SESSION[common].'fun2inc/get_filesize.inc');
					$tmp=substr($record,9);
					$_DIR=explode(',',$tmp); if($_DIR[1]=='') { $_DIR[1]=$_DIR[0]; }
					if($handle=@opendir($_DIR[0]))
					{
						while(($file=readdir($handle))!==false)
						{
							if($_DIR[3]=='DIRONLY')
							{
								#	show only the initial directory
								#
								?><table class="datatable" cellspacing="2" cellpadding="4" width="100%">
								<th align="center">Filename</th><th align="center">Size</th><th align="center">MD5 checksum</th><?php
								while(($file=readdir($handle))!==false)
								{
									if(is_file($_DIR[0].'/'.$file) && strtolower(substr($file,0,5))!='index' && $file!='Desktop.ini')
									{
										?><tr id="bgcol3"><td nowrap><a href="<?=$_DIR[1].'/'.$file.$_DIR[2]?>"><?=$file?></a></td><td nowrap><?=get_filesize($_DIR[0].'/'.$file)?></td><td><?=md5_file($_DIR[0].'/'.$file)?></td></tr><?php
									}
								}
								?></table><?php
							}
							else
							{
								#	show all the subdirectories 
								#
								if(is_dir($_DIR[0].'/'.$file) && $file!='.' && $file!='..' && $file!='Previous')
								{
									?><a tabindex="-1" id="<?=$file?>" name="<?=$file?>"></a><h6 style="margin:5px 0 3px 0;">@&gt; <?php echo $file; if(file_exists($_DIR[0].'/'.$file.'/readme.html')) { ?>&nbsp;&bull;&nbsp;<a onmouseover="javascript:this.style.cursor='pointer';" onclick="javascript:makePopup('show_pop.php?text=<?=urlencode($_DIR[0].'/'.$file.'/readme.html')?>','text','640','480');">Release notes</a><?php }?></h6><small><?php
									$subdir=$_DIR[0].'/'.$file;
									if($handle1=@opendir($subdir))
									{
										?><table class="datatable" cellspacing="2" cellpadding="4" width="100%">
										<th align="center">Filename</th><th align="center" width="10%">Size</th><th align="center" width="10%">MD5 checksum</th><?php
										while(($file=readdir($handle1))!==false)
										{
											if($file!='.' && $file!='..' && strtolower(substr($file,0,5))!='index' && strtolower(substr($file,0,6))!='readme' && $file!='Desktop.ini')
											{
												if(is_file($subdir.'/'.$file))
												{
													?><tr class="fondino"><td nowrap><a href="<?=$_DIR[1].'/'.$file.$_DIR[2]?>"><?=$file?></a></td><td align="center" nowrap><?=get_filesize($subdir.'/'.$file)?></td><td><?=md5_file($subdir.'/'.$file)?></td></tr><?php
												}
											}
										}
										closedir($handle1);
										?></table></small><?php
									}
								}
							}
						}
						closedir($handle);
					}
					else
					{
						echo L_NODWNF.' => '.$_DIR[0].'<br /><br />';
					}
					break;
					#
				case 'PHPimgLI=':
					# 	image gallery list
					#
					#	PHPimgLI=local path
					#
					ini_set('max_execution_time',0);
					include_once($_SESSION[common].'fun2inc/get_filesize.inc');
					$_DIR=substr($record,9);
					if($handle=@opendir($_DIR))
					{
						?><table cellspacing="2" cellpadding="4" width="100%"><?php
						while(($file=readdir($handle))!==false)
						{
							if(	is_file($_DIR.'/'.$file) && 
								strtolower(substr($file,-5,5))!='.desc' && 
								strtolower(substr($file,-5,5))!='.http' && 
								strtolower(substr($file,0,5))!='index' && 
								substr($file,0,6)!='thumb_' && 
								$file!='Thumbs.db' && 
								$file!='Desktop.ini')
							{
								if(substr($file,0,6)!='thumb_' && !file_exists($_DIR.'/thumb_'.$file) && (strtolower(substr($file,-4,4))=='.png' || strtolower(substr($file,-4,4))=='.jpg'))
								{
									#	generate thumbnail
									#
									include_once($_SESSION[common].'class/Thumbnail.php');
									$tn=new ThumbNail(180,180);
									$image=file_get_contents($_DIR.'/'.$file);
									$dims=getimagesize($_DIR.'/'.$file);
									$tn->loadData($image,$dims[mime]);
									$tn->buildThumb($_DIR.'/thumb_'.$file);
								}
								else
								{
									$dims=getimagesize($_DIR.'/'.$file);
								}
								$link='';
								$link=str_replace("\r\n",'<br />',@file_get_contents($_DIR.'/'.$file.'.http'));
								$link=str_replace("\n",'<br />',$link); $link=str_replace("\r",'<br />',$link);
								?><tr valign="top" id="bgcol3">
									<td width="180" align="center"><?php if($link!='') { ?><a href="<?=$link?>" style="border:0;cursor:pointer;"><?php } else { ?><a href="javascript:makePopup('show_pop.php?img=<?=urlencode($_DIR.'/'.$file)?>','image','<?=$dims[0]+40?>','<?=$dims[1]+90?>');" style="border:0;cursor:pointer;"><?php } ?><img src="<?=$_DIR.'/thumb_'.$file?>" alt="<?=$_DIR.'/'.$file?>" /></a><br /><small><?=$dims[0]?>x<?=$dims[1]?>&nbsp;<?=get_filesize($_DIR.'/'.$file)?></small></td>
									<td width="99%"><?php $tmp=str_replace("\r\n",'<br />',@file_get_contents($_DIR.'/'.$file.'.desc')); $tmp=str_replace("\n",'<br />',$tmp); $tmp=str_replace("\r",'<br />',$tmp); echo $tmp;?></td>
								</tr><?php
							}
						}
						closedir($handle);
						?></table><?php
					}
					else
					{
						echo L_NOIMGF.' => '.$_DIR.'<br /><br />';
					}
					break;
			}
		}
		else
		{
			#	Output
			#
			$beg=-1; $beg=strpos($record,'PHPgetSE=',0);
			if($beg>-1)
			{
				#	Print a $_SESSION value
				#
				$value=''; $beg+=9;
				$end=strpos($record,'$',$beg);
				$name=substr($record,$beg,$end-$beg);
				$value=$_SESSION[$name];
				$record=str_replace('PHPgetSE='.$name.'$',$value,$record);
			}
			$beg=-1; $beg=strpos($record,'PHPgetDF=',0);
			if($beg>-1)
			{
				#	Print a define
				#
				$value=''; $beg+=9;
				$end=strpos($record,'$',$beg);
				$name=substr($record,$beg,$end-$beg);
				if(defined($name)) { $value=constant($name); } else { $value='{undefined constant:'.$name.'}'; }
				$record=str_replace('PHPgetDF='.$name.'$',$value,$record);
			}
			if( ($_SESSION[browser]=='FF' && $cmd=='PHPbroFF=') ||	# FireFox only
				($_SESSION[browser]=='IE' && $cmd=='PHPbroIE=') ||	# IE only
				(substr($cmd,0,6)!='PHPbro') )						# every browsers
			{
				$record=str_replace('PHPbroFF=','',$record);
				$record=str_replace('PHPbroIE=','',$record);
				if(	substr($cmd,0,6)!='PHPbro' || (
					($_SESSION[browser]=='FF' && $cmd=='PHPbroFF=') || 
					($_SESSION[browser]=='IE' && $cmd=='PHPbroIE=') )
					)
				{
					if($record=='') { $record='<br /><br />'; }
					echo($record."\n");
				}
			}
		}
	}
}
if(!function_exists('get_html_contents'))
{
	#--------------------------------------
	function get_html_contents($file)
	#--------------------------------------
	{
		if(!$file) { return; }
		$data=@file($file);
		$t=count($data);
		for($i=0;$i<$t;$i++) { $out.=$data[$i].'<br />'; }
		return($out);
	}
}
?>
Return current item: phpCAMALEO