Location: PHPKode > projects > phpDocMaker > Utils/fileBrowser.php
<?

// browses the web tree
// updates the files table
// detects files that have been modified

if(!isset($fileBrowser))
{
	$fileBrowser=1;

/*****************************************************
*	test if the file extension of $fileName is valide
******************************************************/



function asValideExtension($fileName)
{
	global $extensions;

	$valide=false;
	$name=explode(".",$fileName);
	$ext=$name[count($name)-1];
	for($i=0;$i<count($extensions);$i++)
	{
		if($ext == $extensions[$i])
			$valide=true;
	}
	return $valide;
}

/*****************************************************
*	test if the file as change since last pass
******************************************************/

function hasChanged($file,$path)
{
	global $connection,$baseDir;

	$resFile=ExecRequest("select * from files where name='$file' and path='$path'",$connection);

	$timeModified=fileMtime($baseDir.$path.$file);

	if(mysql_num_rows($resFile) !=0)
	{
		$req="update files set isStillPresent=1";
		$resFile=mysql_fetch_object($resFile);
		if($resFile->modifTime < $timeModified)
		{
			$req.=",hasChanged=1,modifTime='$timeModified'";
			dispDebug("$file as changed, modifTime= $timeModified");
		}
		$req.=" where id_file='$resFile->id_file'";
		ExecRequest($req,$connection);
	}
	else
	{
		$req= "insert into files set name='$file',path='$path',modifTime='$timeModified',";
		$req.="hasChanged=1,isStillPresent=1";
		ExecRequest($req,$connection);
		dispDebug("new file: $file, modifTime= $timeModified");
	}
}



/****************************************************
* recursive function to browse the whole project tree
*****************************************************/

function recurseDir($dirName="/")
{
	global $baseDir,$excludeDir;

	$realDir=$baseDir . $dirName ;
	//dispDebug("in $realDir");
	$dir = @opendir($realDir);
	$i=0;
	$j=0;

	while ($file = readDir($dir))
	{
		if ($file != "." && $file != "..")
		{

			if(is_dir($realDir.$file) && !isset($excludeDir[$realDir.$file."/"])) // it's a directorie => recursion
			{
				recurseDir($dirName.$file."/");
			}
			else				// it's a file => test extension + updtae table
			{
				if(asValideExtension($file))
				{
					hasChanged($file,$dirName);
				}
			}
		}
	}
	@closedir($dir);
}

	function browseDir()
	{
		global $debug,$connection;

		if($debug)
			$nbFilesBegin=mysql_num_rows(ExecRequest("select id_file from files",$connection));
		ExecRequest("update files set isStillPresent=0,hasChanged=0",$connection);
		recurseDir();
		if($debug)
			$nbFilesMid=mysql_num_rows(ExecRequest("select id_file from files",$connection));
		//ExecRequest("delete from files where isStillPresent=0",$connection);
		if($debug)
		{
			$nbFilesEnd=mysql_num_rows(ExecRequest("select id_file from files",$connection));
			$add=$nbFilesMid-$nbFilesBegin;
			//$del=$nbFilesBegin-$nbFilesEnd+$add;
			dispDebug("$add file(s) added");
		}
	}
}
?>
Return current item: phpDocMaker