Location: PHPKode > projects > PHP SiteBuilder > include/photo-functions.php
<?php
/**	
 *	Photo functions
 *
 *	@file	photo-functions.php
 *	@author	Jesper Rønn
 *	@date	2000-05-17	
 *
 *	$Id: photo-functions.php,v 1.9 2001/10/16 02:45:16 zaiborg Exp $
 */

 
/**
 * Read picture file names.
 *
 * @arg		string	$path		Path to search.
 * @arg		string	$pattern	Search pattern for files to find (regexp).
 * @return	array	$items		Array with filenames that matches the pattern.
 */	
function readFileNames($path, $pattern)
{
	if (($d = @dir($path)) == false) return false;

	if (DEBUG) {
		echo "Directory handle: ".$d->handle."<br>\n";
		echo "Path: ".$d->path."<br>\n";
		echo "Files:<br>_______________________________________________________\n";
	}
	while (($fileName = $d->read()) != "") { 
		// special part for file names:
		if (eregi($pattern, $fileName)) { // only read file names that matches pattern
			if (DEBUG) echo "\t$fileName<br>\n";
			$items[] = $fileName;
		} else {
			if (DEBUG ) echo "The file '".$fileName."' was ignored<br>\n";
		}
	}
	$d->close();
	if (gettype($items)!= "array")
	{
		echo '<h4>Wrong type in $items ('.gettype($items).').</h4>';
		echo '<h4>Probably the target dir is empty.</h4>';
	} else {
		sort($items);
	}
	
	return $items;
	
} // end function readFileNames()	


/**
 * Read title etc. from text file.
 *
 * seefile:
 *	photo.php, billeder.php
 *
 * @arg		string	$txtFile file name including path for the file containing the text.
 * @arg		string	$imageFileName name of the image file shown, when called from photo.php
 * @return	array	$txt array with title and subtitle and maybe caption text for picture.
 */
function readTxtFile($txtFile, $imageFileName = null)
{
	if (file_exists($txtFile)) {

		$arr = file($txtFile);
		$includedLinesArr = ignoreComments($arr);
		if (DEBUG) {
			echo "<h3>\$ignoredLinesArr:</h3><pre>";
			print_r($includedLinesArr); echo "</pre>";
		}

		// Read the title for the gallery
		$txt['title']		= $includedLinesArr[0];	// First line
		$txt['subTitle']	= $includedLinesArr[1];	// Second line

		// If we're calling from the indiviual photo viewer (photo.php):
		if ($imageFileName != null) {
			foreach ($includedLinesArr as $line) {
				if (DEBUG) echo "Debug: ".fixup($line)."<br>\n";
				if (strstr($line, $imageFileName)) {
					// match on imageFileName $fileName
					if (DEBUG) echo "<b>MATCH!</b>";
					$tmp = explode ("|:|",$line);
					if ($tmp[2] != "") $txt['title']	= $tmp[2];
					if ($tmp[3] != "") $txt['subTitle']	= $tmp[3];
					$txt['billedTxt']	= $tmp[4];
					$txt['andet']		= $tmp[5];
					} else {
					if (DEBUG) echo "No match.<br>";
				}
			}
		}

		return $txt;

	} else {

		return null;

	}

} // end function readTxtFile()	


function ignoreComments($arr)
{
	foreach ($arr as $line) {
		// trim whitespace in line
		$line = trim($line);
		if (substr($line,0,1)=="#"  ||  $line=="") {
			// ignore lines
			$ignoredLinesArr[] = $line;
		} else {
			$includedLinesArr[] = $line;
		}
	}

	if (DEBUG) {
		echo "<h3>ignoreLines from \$arr:</h3><pre>";
		var_dump($ignoredLinesArr);
		echo "</pre><h3>includedLines from \$arr:</h3><pre>";
		var_dump($includedLinesArr);
		echo "</pre>";
	}
	return  $includedLinesArr;
} // end function ignoreComments($arr) 

/* vim: set tabstop=4: */ 
?>
Return current item: PHP SiteBuilder