Page 1 of 1

Text under photo

Posted: Tue Oct 18, 2005 4:52 am
by Orklord
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi,

I would like to put a text under the pictures, but I can't find how.

My code:

Code: Select all

<?php

$view       = (isset($_REQUEST['view'])) ? $_REQUEST['view'] : "";
if (!isset($image_dir) || !$image_dir) {
		die("Setup Error:<br>The variable <b>\$image_dir</b> (in the 'USER SETTING' section) is not set.");
	}
	if (($image_dir[strlen($image_dir) - 1] == "/") || ($image_dir[strlen($image_dir) - 1] == "\\")) {
		die("Setup Error:<br>The variable <b>\$image_dir</b> (in the 'USER SETTING' section) should <b>not</b> end with a slash");
	}
	if (!is_dir($image_dir)) {
		die("Setup Error:<br>The variable <b>\$image_dir</b> (in the 'USER SETTING' section) must be a directory.");
	}
	if (!isset($image)) {
		$image = phppg_recursive_listdir($image_dir);
	} else {
		array_walk ($image, 'phppg_add_image_dir');
	}
	
	if (!is_array($image) || !count($image)) {
		die("Setup Error:<br>There are no files in the image directory. You specify this direcory in the 'USER SETTINGS' secion as \$image_dir.");
	}
	if ($view) {
		$image_dir_path = realpath($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . $image_dir); // REALPATH to user specified image directory
		$view_dir_path  = dirname(realpath($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . $view . ".jpg")); // REALPATH to the file we're supposed to be viewing
		if (!$image_dir_path || !$view_dir_path || !stristr($view_dir_path, $image_dir_path)) {
			die("BAD REQUEST<br>Please <a href=\"" . $_SERVER['PHP_SELF'] . "\">go back</a> and request another image");
		}
	}
array_walk ($image, 'phppg_remove_extension');
	$temp_image = array_unique($image);
	$image      = array();
	$i          = 0;
	foreach ($temp_image as $v) { /* reset array keys */
		$image[$i] = $v;
		$i++;
	}
	
	if (!isset($columns)    || !(int) $columns) $columns    = 4; 
	if (!isset($view)       || !$view)          $view       = $image[0];
	if (!isset($next_photo) || !$next_photo)    $next_photo = "Next Photo";
	if (!isset($page_title))    $page_title    = "";
	if (!isset($left_content))  $left_content  = "";
	if (!isset($right_content)) $right_content = "";
	if (!isset($use_gifs))      $use_gifs      = false;
	
	
	
	
	if ($page_title || $left_content || $right_content) {
		?>
		<table class="phppgtitleband">
			<tr>
				<td style="text-align:left;"><?php echo $left_content; ?></td>
				<td style="text-align:center;"><?php echo $page_title; ?></td>
				<td style="text-align:right;"><?php echo $right_content; ?></td>
			</tr>
		</table>
		<?php
	}
	
	
	//if ($view && (file_exists($image_path . $view . ".jpg"))) {
	if ($view && (file_exists($view . ".jpg"))) {
		$currKey = array_keys ($image, $view);
		$nextKey = $currKey[0] + 1;
		$prevKey = $currKey[0] - 1;
		if (!array_key_exists($nextKey, $image)) $nextKey = 0;
		if (!array_key_exists($prevKey, $image)) $prevKey = (count($image) - 1);
		?>
		
		<div class="phppgmainbox">
			
			<!-- NEXT / PREV LINKS -->
			<?php if ($prev_photo || $next_photo) { ?>
			<div class="phppgnextbox">
				<?php if ($prev_photo) { ?>
					<a href="<?php echo $_SERVER['PHP_SELF'] . "?view=" . $image[$prevKey]; ?>"><?php echo $prev_photo; ?></a>
					&nbsp;&nbsp;
				<?php } ?>
				<?php if ($next_photo) { ?>
					<a href="<?php echo $_SERVER['PHP_SELF'] . "?view=" . $image[$nextKey]; ?>"><?php echo $next_photo; ?></a>
				<?php } ?>
			</div>
			<?php } ?>
			
			
			<!-- MAIN PHOTO -->
			<table class="phppgimagebox"><tr><td>
				<div class="phppgimageframe">
					<img src="<?php echo $view; ?>.jpg" alt="" class="phppgimagetag">
				</div>
			</td></tr></table>
		
		</div>
		<?php
	}
	
	
	
	
	
	if ($use_gifs) {
		?>
		<table class="phppggifbox">
			<tr>
				<?php
					$i = 0;
					if (!((int) $columns)) {
						$columns = 4;
					}
					foreach($image as $v) {
						($i % $columns) ? $row = FALSE : $row = TRUE;
						
						if ($i && $row) {
							print("\t</tr>\n");
							print("\t<tr>\n");
						}
						?>
						
						<td><a href="<?php echo $_SERVER['PHP_SELF'] . "?view=" . $v ?>"><img src="<?php echo $v ?>.gif" alt="" border="1"></a></td>
						
						<?php
						$i++;
					}
				?>
			</tr>
		</table>
		<?php
	}

	
	
	
	function phppg_remove_extension(&$value, $key) {
		$value = preg_replace(array("/.gif/i", "/.jpg/i"), "", $value);
	} 

	
	function phppg_add_image_dir(&$value, $key) {
		global $image_dir;
		$value = $image_dir . "/" . $value;
	} 

	
	function phppg_recursive_listdir($base) {
		static $filelist = array();
		static $dirlist  = array();
	
		if(is_dir($base)) {
			$dh = opendir($base);
			while (false !== ($dir = readdir($dh))) {
				if (is_dir($base ."/". $dir) && $dir !== '.' && $dir !== '..') {
					$subbase = $base ."/". $dir;
					$dirlist[] = $subbase;
					$subdirlist = phppg_recursive_listdir($subbase);
				} elseif(is_file($base ."/". $dir) && $dir !== '.' && $dir !== '..') {
					$filelist[] = $base ."/". $dir;
					//$filelist[] = $dir;
				}
			}
			closedir($dh);
		}
		@sort($dirlist);
		@sort($filelist);
		
		$array['dirs'] = $dirlist;
		$array['files'] = $filelist;
		//return $array;
		return $filelist;
	}
	


?>
Thanks


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Oct 18, 2005 5:58 am
by feyd
it'd be added somewhere around the "MAIN PHOTO" html comment..

Posted: Wed Oct 19, 2005 9:45 am
by Orklord
But what do I have to add, and do I have to make a special file with the text?

Posted: Wed Oct 19, 2005 11:28 am
by foobar

Code: Select all

<div class="phppgimageframe">
                    <img src="<?php echo $view; ?>.jpg" alt="" class="phppgimagetag">
                    <br /><!-- Text in here! -->
                </div>

Posted: Wed Oct 19, 2005 11:49 am
by Orklord
Thanks,

but when I want for every photo a different text, I have to say something like foto1 = bla?

Posted: Wed Oct 19, 2005 12:05 pm
by foobar
Orklord wrote:Thanks,

but when I want for every photo a different text, I have to say something like foto1 = bla?
That depends on how your script works. Insert the value into whatever the datasource is, and then access it via the array. (I'm too lazy to tell you exactly how, but you should try to figure it out yourself ;) )