Jump to content
Updating IPB tonight Read more... ×


This topic is now archived and is closed to further replies.


PHP If Question

Recommended Posts

This is a photo gallery script. It generates 2 different pages. "Case 0" shows all images in a directory and "Case 1" shows only the selected image. It has a face_begin.php and a face_end.php template. I want to add a face_begin_view.php and a face_end_view.php to the case 1 part and leave the case 0 at the default. I have figured out how to change the face_begin.php to face_begin_view.php because it specifically asks the question in case 1 what to use as the template. I also figured out how to add the face_end_view.php to the end of case 1. My problem comes in, that at the very end of the script is where it defines the end template for the entire script. I have tried moving that around, but I can't find out where to put it to make it work only for case 0 and not for case 1. Right now, as the script is below, the single image page shows the correct top template, the correct bottom template, AND below that it shows the incorrect bottom template. I was wondering if anyone could figure out where to put the face_end.php command to make it work properly, or if there is a way to make an if code work, something like (if case=1 face_end_view.php else face_end.php) Any help would be much apprecieated. Thanks!

* Here we have de code that shows a gallery index or an image with its
* comments
* On query string receives: $gid [ $phid || $page ]
* Actions:
* if only is set gid => print gallery index.
* if is set gid and phid => show image, image info and comments
* if gid and page are set => show that page
* if gallery has password then check if user filled gallery password form
* variable, $form_pw, is the same as the stored in the $GID_INFO_FILE
* of the gallery.

* @package user


//_GET[varname] => varname

// 0 -> View gallery
if (!isset($gid)) {
  header("Location: ./gallery.php");
// 1 -> View photo;

if (isset($phid)) {
if (!is_int((int)$phid)) {
    error(_y("Incorrect Arguments"));
//Default page 0;
if ( !isset($page) ) $page='0';
//Obtain gallery directory and information about this gallery.
if (!($dir=get_data($GID_DIRS,$gid)))
    error(_y('Retrieving gallery directory'));

$gid_dir= $BASE_DIR . $dir;
include($gid_dir . $GID_INFO_FILE);
//echo "<br>form:$form_pw-{$gid_info['gallery_password']}-ses:". $HTTP_SESSION_VARS['y_gallery_pwd'];

//Check if gallery has an access password and user inserted it.
//form_pw: password introduced by user in a form.
//gallery_password: password stored in $GID_INFO_FILE
if (!check_admin_login()) { //If user is admin, allow.
  if (strlen($gid_info['gallery_password'])>0) {
    //if gallery_has password => check
    if (!check_gallery_password($gid_info['gallery_password'],$form_pw)){ //if password
      include($TEMPLATE_DIR . 'face_begin.php');
      error(_y("Password incorrect."));
  include($TEMPLATE_DIR . 'face_end.php');

switch($case) {

case 0: { //View Gallery
  //Only count a visit of the gallery when hit is set.
    if ($hit=="yes") {    //Stats
header("Location: ./view.php?gid=$gid");
    include($TEMPLATE_DIR . 'face_begin.php');
    //Now show Gallery thumbnails
    if (!gallery_thumbs($gid,$page))
      error(_y("Gallery data not found. Please re-create this gallery"));

  case 1: { //View Image

    $phid_filename= get_data($gid_dir . $PHID_FILENAMES, $phid);
    $phid_visits=get_data($gid_dir . $PHID_STATS, $phid);
    $phid_comments=get_data($gid_dir . $PHID_COMMENTS, $phid);
    $img_path=$gid_dir . $phid_filename;
    if (!is_file($img_path)) {
include($TEMPLATE_DIR . 'face_begin_view.php');
error(_y('Image not found'));
    $img_url=$gid_dir . rawurlencode($phid_filename);

    $I_TITLE= $gid_info['title'] . " - $phid_filename";
    include($TEMPLATE_DIR . 'face_begin_view.php');
    heading($gid_info['title'] . "- <small>$phid_filename</small>");
    //Setting MAX_IMG_SIZE (view config.php for doc)
    if ($MAX_IMG_SIZE > 0) {
$sz_orig = getimagesize($img_path);
if ($sz_orig[0]> $MAX_IMG_SIZE || $sz_orig[0]> $MAX_IMG_SIZE) {    
    if ($ratio>1) {
    else {
$height=(int) ($MAX_IMG_SIZE*$ratio);
    //Now construct img_size html code
    $img_size= "style=\"width:$width;height=$height\" ";    
    echo "<div class=\"viewimage\"><a name=\"img\"></a><img src=\"".$img_url. "\" ". $img_size . "alt=\"$phid_filename\" id=\"myimage\" class=\"image\" onload=\"preload('$img_url')\" /></div>";
    if ($gid_info['no_comments']!="on") {
print_all_comments($gid_dir . $gid ."_" . $phid, $gid, $phid);
    //print_navigation_bar($gid,$phid, $gid_dir);
    add_listed_visit( $gid_dir . $PHID_STATS, $phid);
include($TEMPLATE_DIR . 'face_end_view.php');
include($TEMPLATE_DIR . 'face_end.php');

Share this post

Link to post
Share on other sites
Why dont you move [code=php:0]include($TEMPLATE_DIR . 'face_end.php');[/code] at the end of case 0. So find the following:

  case 1: {[/code]
Now add [code=php:0]include($TEMPLATE_DIR . 'face_end.php');[/code] before [b]break;[/b]

Share this post

Link to post
Share on other sites
Trying to fix another validation problem... The slideshow requires the following:

[code]<META http-equiv="refresh" content="<?php print $interval; ?>; URL=<?php print $the_url . "&amp;phid=" . $phid_next; ?>">[/code]

Which runs in the main body of the site. There is the top and bottom templates which have the design, and the middle has the code for the scripts.. If I put the meta tag in the head portion, it doesn't work.. Any suggestions?

Share this post

Link to post
Share on other sites
I was actually able to get it to work... I had to edit some in the main body of the script though.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.