Location: PHPKode > scripts > Easy Image Catalogue (EIC) > easy-image-catalogue-eic/index.php
<?php 
/*
	EasyImageCatalogue 
	Version 1.3
	written by  Heilmann
	http://www.onlinetools.org/tools/easyimagecatalogue.php	
	DO NOT EDIT THIS FILE
*/
include_once("eic_functions.php");
$HTML=load("easyimagecatalogue_template.html");
$search=$HTTP_GET_VARS['search'];
$s=$HTTP_GET_VARS['s'];
$r=$HTTP_GET_VARS['r'];
$d=$HTTP_GET_VARS['d'];
$p=$HTTP_GET_VARS['p'];
$a=$HTTP_GET_VARS['a'];
?>
<?
$galleries="<select name=\"d\" onchange=\"document.forms[1].submit()\">";
$allfiles=directory(".","all");
natsort($allfiles);
foreach ($allfiles as $a){
	if (!preg_match("/^\.|counterdata/",$a) and is_dir($a)){
		if (file_exists("counterdata/".$a."info.xml")){
			$name=untag(load("counterdata/".$a."info.xml"),"galleryname",0);
			if ($name==""){$name=$a;}
			if ($d==$a){$galleries.= "<option value=\"$a\" selected=\"selected\">$name</option>";}
			else {$galleries.= "<option value=\"$a\">$name</option>";}
			$name="";
		}
	}
}
$galleries.="</select><input type=\"submit\" value=\"go\" /></form>";
$HTML=preg_replace("/<!-- galleries -->/",$galleries,$HTML);
?>
<?
/*------------------------------------------------------------------------------
		No search initiated
------------------------------------------------------------------------------*/ 
if ($search==""){
// no folder set
	if ($d==""){
		$allfiles=directory(".","all");
		natsort($allfiles);
		foreach ($allfiles as $key=>$a){
			if (file_exists("counterdata/".$a."info.xml")){
				$name=untag(load("counterdata/".$a."info.xml"),"galleryname",0);
				if ($name==""){$name=$a;}
				if (!preg_match("/^\.|counterdata/",$a) and is_dir($a)){
					$files=directory($a,"jpg,JPG,JPEG,jpeg,png,PNG");
					$files=ditchtn($files);
					preg_match_all("/<!-- start:gallery -->(.*?)<!-- end:gallery -->/si",$HTML,$item);	
					$nowgal=$item[1][0];
					$nowgal=preg_replace("/<!-- gallerythumb -->/si","<a href=\"index.php?d=$a\"><img src=\"$a/preview.jpg\" border=\"0\"></a>",$nowgal);
					$nowgal=preg_replace("/<!-- galleryname -->/si",$name,$nowgal);
					$nowgal=preg_replace("/<!-- gallerysize -->/si",count($files),$nowgal);
					$nowgal=preg_replace("/<!-- gallerycount -->/si",load("counterdata/$a.txt"),$nowgal);
					$nowgal=preg_replace("/<!-- galleryinfo -->/si",untag(load("counterdata/".$a."info.xml"),"galleryinfo",0),$nowgal);
				}
				$inc.=$nowgal;
			}
		}
	$HTML=preg_replace("/<!-- start:gallery -->.*?<!-- end:gallery -->/si",$inc,$HTML);
	$HTML=preg_replace("/<!-- start:currentgallery -->.*?<!-- end:currentgallery -->/si","",$HTML);
	$HTML=preg_replace("/<!-- start:search -->.*?<!-- end:search -->/si","",$HTML);
	} else {
	preg_match_all("/<!-- start:currentgallery -->(.*?)<!-- end:currentgallery -->/si",$HTML,$item);	
	$item=$item[1][0];
// folder is known
		$it=untag(load("counterdata/".$d."info.xml"),"item",1);
		$name=untag(load("counterdata/".$d."info.xml"),"galleryname",0);
		$galinfo=untag(load("counterdata/".$d."info.xml"),"galleryinfo",0);
		if ($name==""){$name=$d;}
// image is unknown
		if ($p==""){
			// counter
			if ($r!=1){
				if (file_exists("counterdata/$d.txt")){
					$c=load("counterdata/$d.txt");
					$c++;
				}
				else{$c=1;}
				save("counterdata/$d.txt",$c);
			}
		
			$files=directory($d,"jpg,JPG,JPEG,jpeg,png,PNG");
			$files=ditchtn($files);
			if ($name==""){$name=$d;}
			$item=preg_replace("/%galleryname%/si",$name,$item);			
			$item=preg_replace("/%gallerysize%%/si",count($files),$item);			
			$item=preg_replace("/%galleryinfo%%/si",$galinfo,$item);			
			natsort($files);
			foreach ($files as $a){
				preg_match_all("/<!-- start:thumb -->(.*?)<!-- end:thumb -->/si",$HTML,$thumbitem);	
				$thumbitem=$thumbitem[1][0];
				$big=getimagesize("$d/$a");
				if ($it[0]!=""){foreach($it as $i){if(untag($i,"image",0)==$a){$info=untag($i,"copy",0);}}}
				echo "";
				$thumbitem=preg_replace("/<!-- thumb -->/","<a href=\"index.php?d=$d&p=$a\" class=\"img\"><img src=\"$d/tn_$a\" title=\"$info\" border=\"0\" /></a>",$thumbitem);
				$thumbitem=preg_replace("/%width%/",$big[0],$thumbitem);
				$thumbitem=preg_replace("/%height%/",$big[1],$thumbitem);
				$thumbitem=preg_replace("/%filesize%/",round((filesize("$d/$a")/1024)),$thumbitem);
				$thumbinc.=$thumbitem;
			}
			$HTML=preg_replace("/<!-- start:thumb -->.*?<!-- end:thumb -->/si",$thumbinc,$HTML);
			$HTML=preg_replace("/%galleryinfo%/si",$galinfo,$HTML);
			$HTML=preg_replace("/<!-- start:display -->.*?<!-- end:display -->/si","",$HTML);
// image is known
		}else{
			if ($it[0]!=""){foreach($it as $i){if(untag($i,"image",0)==$p){$info=untag($i,"copy",0);}}}
			$size=getimagesize("$d/$p");
			if ($s!=""){
			$HTML=preg_replace("/<!-- searchbigimage -->/","<div align=\"center\"><a href=\"index.php?search=$s\"><img src=\"$d/$p\" $size[3] alt=\"$info\" border=\"0\" /></a></div>",$HTML);
			$HTML=preg_replace("/<!-- start:display -->.*?<!-- end:display -->/si","",$HTML);
			}
			else {
				$files=directory($d,"jpg,JPG,JPEG,jpeg,png,PNG");
				$files=ditchtn($files);
				usort($files,'strnatcmp');
				foreach ($files as $k=>$pn){
					if ($pn==$p){
						$next="";
						$last="";
						$ispic=$k+1;	
						if ($k != 0){$last=$files[$k-1];}
						if ($k != count($files)){$next=$files	[$k+1];}
					}
				}
				preg_match_all("/<!-- prev:(.*?) -->/si",$HTML,$prevlink);	
				preg_match_all("/<!-- next:(.*?) -->/si",$HTML,$nextlink);	
				$prevlink=$prevlink[1][0];
				$nextlink=$nextlink[1][0];
				if ($last!=""){
				$HTML=preg_replace("/<!-- prev.*? -->/","<a href=\"index.php?p=$last&d=$d\">$prevlink</a>&nbsp;&nbsp;",$HTML);
				}
				$HTML=preg_replace("/%imagecount%/",$ispic,$HTML);
				$HTML=preg_replace("/%allpics%/",count($files),$HTML);
				if ($next!=""){
				$HTML=preg_replace("/<!-- next.*? -->/","&nbsp;&nbsp;<a href=\"index.php?p=$next&d=$d\">$nextlink</a>",$HTML);
				}
			$HTML=preg_replace("/<!-- bigimage -->/","<a href=\"index.php?d=$d&r=1\"><img src=\"$d/$p\" $size[3] alt=\"$info\" border=\"0\" /></a>",$HTML);
			}
		
			if ($info!=""){
				$HTML=preg_replace("/<!-- info -->/",$info,$HTML);
			}
			$c=$d.str_replace(".","",$p);
			$pop="no";
			$HTML=preg_replace("/<!-- start:currentthumbs -->.*?<!-- end:currentthumbs -->/si","",$HTML);
			$HTML=preg_replace("/<!-- comments -->/si",include("comments.php"),$HTML);
		}
	}
	$HTML=preg_replace("/%galleryname%/si",$name,$HTML);
	if (count($files)!=0){$imgco=count($files);}
	$HTML=preg_replace("/%gallerysize%/si",$imgco,$HTML);
	$HTML=preg_replace("/<!-- start:gallery -->.*?<!-- end:gallery -->/si","",$HTML);
	$HTML=preg_replace("/<!-- start:search -->.*?<!-- end:search -->/si","",$HTML);
}else{

/*------------------------------------------------------------------------------
	Search initiated
------------------------------------------------------------------------------*/ 
	$found=0;
	$files=directory("counterdata","xml");
	foreach ($files as $f){
		$items=untag(load("counterdata/".$f),"item",1);
			if ($items[0]!=""){
				foreach ($items as $i){
					if (preg_match("/".$search."/si",$i)){
						$url=str_replace("info.xml","",$f)."/tn_".untag($i,"image",0);
						$size=getimagesize($url);
						$thumbs.="<a href=\"index.php?s=$search&d=".str_replace("info.xml","",$f)."&p=".untag($i,"image",0)."\"><img src=\"$url\" class=\"search\" border=\"0\" $size[3] alt=\"".untag($i,"copy",0)."\" /></a>";
						$found++;
					}
				}
			}
		}
		preg_match_all("/<!-- start:search -->(.*?)<!-- end:search -->/si",$HTML,$item);	
		$nowgal=$item[1][0];
		$nowgal=preg_replace("/<!-- searchthumb -->/",$thumbs,$nowgal);
	if ($found==0){
		$nowgal=preg_replace("/<!-- start:found -->(.*?)<!-- end:found -->/si","",$nowgal);	
		}
	else {
		$nowgal=preg_replace("/<!-- start:nonefound -->(.*?)<!-- end:nonefound -->/si","",$nowgal);	
	}
	$nowgal=preg_replace("/%search%/",$search,$nowgal);
	$nowgal=preg_replace("/%number%/",$found,$nowgal);
	$HTML=preg_replace("/<!-- start:search -->(.*?)<!-- end:search -->/si",$nowgal,$HTML);	
	$HTML=preg_replace("/<!-- start:currentgallery -->.*?<!-- end:currentgallery -->/si","",$HTML);
	$HTML=preg_replace("/<!-- start:gallery -->.*?<!-- end:gallery -->/si","",$HTML);
}

$branding="<a href=\"http://www.onlinetools.org/tools/easyimagecatalogue.php\" style=\"background:#eee;color:black;font-size:10px;padding:5px\">Powered by EasyImageCatalogue</a>";
if (preg_match("/<!-- branding -->/",$HTML)){$HTML=preg_replace("/<!-- branding -->/",$branding,$HTML);}
else {$HTML=preg_replace("/<\/body>/si",$branding,$HTML);}
$HTML=preg_replace("/<!--.*?[start|end].*?-->/si","",$HTML);	
echo $HTML;
?>

Return current item: Easy Image Catalogue (EIC)