Author Topic: Bug identified in details.php for 1.5 beta  (Read 5160 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Bug identified in details.php for 1.5 beta
« on: May 12, 2002, 01:14:05 AM »
If I add a new image using a URL instead of uploading a file, the following code fragment produces broken links:

Code: [Select]

// Get next and previous image
if (!empty($image_row[$next_image_id])) {
  $next_image_name = stripslashes($image_row[$next_image_id]['image_name']);
  $next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id);
  $next_image_file = MEDIA_PATH."/".$cat_id."/".$image_row[$next_image_id]['image_media_file'];
  $next_thumb_file = THUMB_PATH."/".$cat_id."/".$image_row[$next_image_id]['image_thumb_file'];
}

if (!empty($image_row[$prev_image_id])) {
  $prev_image_name = stripslashes($image_row[$prev_image_id]['image_name']);
  $prev_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$prev_image_id);
  $prev_image_file = MEDIA_PATH."/".$cat_id."/".$image_row[$prev_image_id]['image_media_file'];
  $prev_thumb_file = THUMB_PATH."/".$cat_id."/".$image_row[$prev_image_id]['image_thumb_file'];
}


So
Code: [Select]
{next_image_url} results in:
Code: [Select]

<a href="./details.php?image_id=8"><img src="./data/thumbnails/3/http://www.abc123.com/pics/190/tn190-14.jpg" border="1"></a><br />


My suggested solution:

Track whether or not the image is from a URL or an uploaded file in the 4images_images table.  Construct the image and thumbnail paths if it was uploaded otherwise just use the URL.  

BE SURE TO UPDATE THIS TABLE COLUMN IF THE IMAGE IS EDITED AND A URL IS USED TO REPLACE A PREVIOUSLY UPLOADED IMAGE.  (And delete the local image file)  SAME FOR THE REVERSE SITUATION.

I like this approach since it would also allow for relative URLs.  I have found that 1.5 beta currently only supports absolute URLs.

This IS supported:
Code: [Select]
http://www.abc123.com/pics/190/190-12.jpg

This IS NOT supported:
Code: [Select]
/pics/190/190-12.jpg

----------------------------------------------------------------------------------------

Wenn ich ein neues Bild mit einem URL addiere, anstatt, eine Akte zu hochladen, produziert das folgende Codefragment defekte Verbindungen:

Code: [Select]

// Get next and previous image
if (!empty($image_row[$next_image_id])) {
  $next_image_name = stripslashes($image_row[$next_image_id]['image_name']);
  $next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id);
  $next_image_file = MEDIA_PATH."/".$cat_id."/".$image_row[$next_image_id]['image_media_file'];
  $next_thumb_file = THUMB_PATH."/".$cat_id."/".$image_row[$next_image_id]['image_thumb_file'];
}

if (!empty($image_row[$prev_image_id])) {
  $prev_image_name = stripslashes($image_row[$prev_image_id]['image_name']);
  $prev_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$prev_image_id);
  $prev_image_file = MEDIA_PATH."/".$cat_id."/".$image_row[$prev_image_id]['image_media_file'];
  $prev_thumb_file = THUMB_PATH."/".$cat_id."/".$image_row[$prev_image_id]['image_thumb_file'];
}


So
Code: [Select]
{next_image_url} resultate innen:
Code: [Select]

<a href="./details.php?image_id=8"><img src="./data/thumbnails/3/http://www.abc123.com/pics/190/tn190-14.jpg" border="1"></a><br />


Meine vorgeschlagene Lösung: Schiene, ob oder nicht das Bild von einem URL oder von einer Antriebskraft Akte in der îmages_images Tabelle ist. Konstruieren Sie die Bild- und thumbnailwege, wenn es Antriebskraft anders gerader Gebrauch das URL war.

SEIEN Sie SICHER, DIESE TABELLE SPALTE ZU AKTUALISIEREN, WENN Das BILD REDIGIERT WIRD UND Ein URL BENUTZT WIRD, UM Ein VORHER ANTRIEBSKRAFT BILD ZU ERSETZEN. (und löschen Sie die lokale Bildakte), SELBEN FÜR DIE RÜCKCSituation.

Ich mag diese Annäherung, da sie auch relatives URLs zulassen würde. Ich habe gefunden, daß 1,5 Beta z.Z. nur absolutes URLs stützt.

Dieses WIRD gestützt:
Code: [Select]
http://www.abc123.com/pics/190/190-12.jpg

Dieses WIRD NICHT gestützt:
Code: [Select]
/pics/190/190-12.jpg

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
Bug identified in details.php for 1.5 beta
« Reply #1 on: May 12, 2002, 09:31:01 AM »
Hi!

Please post in english OR german, thanks.

you are right, this is a bug and will be fixed. To solve it replace
Code: [Select]
if (!empty($image_row[$next_image_id])) {
  $next_image_name = stripslashes($image_row[$next_image_id]['image_name']);
  $next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id);
  $next_image_file = MEDIA_PATH."/".$cat_id."/".$image_row[$next_image_id]['image_media_file'];
  $next_thumb_file = THUMB_PATH."/".$cat_id."/".$image_row[$next_image_id]['image_thumb_file'];
}

if (!empty($image_row[$prev_image_id])) {
  $prev_image_name = stripslashes($image_row[$prev_image_id]['image_name']);
  $prev_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$prev_image_id);
  $prev_image_file = MEDIA_PATH."/".$cat_id."/".$image_row[$prev_image_id]['image_media_file'];
  $prev_thumb_file = THUMB_PATH."/".$cat_id."/".$image_row[$prev_image_id]['image_thumb_file'];
}


with:
Code: [Select]
if (!empty($image_row[$next_image_id])) {
  $next_image_name = stripslashes($image_row[$next_image_id]['image_name']);
  $next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id);
  $next_image_file = (is_remote($image_row[$next_image_id]['image_media_file'])) ? $image_row[$next_image_id]['image_media_file'] : MEDIA_PATH."/".$cat_id."/".$image_row[$next_image_id]['image_media_file'];
  $next_thumb_file = (is_remote($image_row[$next_image_id]['image_thumb_file'])) ? $image_row[$next_image_id]['image_thumb_file'] : THUMB_PATH."/".$cat_id."/".$image_row[$next_image_id]['image_thumb_file'];
}

if (!empty($image_row[$prev_image_id])) {
  $prev_image_name = stripslashes($image_row[$prev_image_id]['image_name']);
  $prev_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$prev_image_id);
  $prev_image_file = (is_remote($image_row[$prev_image_id]['image_media_file'])) ? $image_row[$prev_image_id]['image_media_file'] : MEDIA_PATH."/".$cat_id."/".$image_row[$prev_image_id]['image_media_file'];
  $prev_thumb_file = (is_remote($image_row[$prev_image_id]['image_thumb_file'])) ? $image_row[$prev_image_id]['image_thumb_file'] : THUMB_PATH."/".$cat_id."/".$image_row[$prev_image_id]['image_thumb_file'];
}


Greets Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Many thanks for the patch and a Question
« Reply #2 on: May 12, 2002, 07:07:04 PM »
In version 1.0, I enhanced details.php to return new variables 'next_image2' and 'next_image3'.  This was so I could display the previous and next 3 image thumbnails to the user for navigational purposes.  

I don't know PHP but I am make my living as a programmer.  It was easy enough for me to figure out that this data was already available in the cache.

Under 1.5 beta, this cache seems to have been removed.  I spent a couple hours yesterday trying to figure out how to accomplish the same thing but failed.  

Is it possible to copy and hack these sections of code to get the next 3 images?

Code: [Select]

$order = ($config['image_sort'] == "DESC") ? "DESC" : "ASC";
$condition = ($order == "DESC") ? "<" : ">";
$row = $site_db->query_firstrow("SELECT image_id AS next_image_id
                                 FROM ".IMAGES_TABLE."
                                 WHERE ".$config['image_order']." $condition '".$search_key."' AND cat_id = $cat_id AND image_active = 1
                                 ORDER BY ".$config['image_order']." $order
                                 LIMIT 1");
$next_image_id = (!empty($row['next_image_id'])) ? $row['next_image_id'] : 0;
$next_image_name = REPLACE_EMPTY;
$next_image_url = REPLACE_EMPTY;
$next_image_file = REPLACE_EMPTY;
$next_thumb_file = REPLACE_EMPTY;

...

// Get next and previous image
if (!empty($image_row[$next_image_id])) {
  $next_image_name = stripslashes($image_row[$next_image_id]['image_name']);
  $next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id);
  $next_image_file = (is_remote($image_row[$next_image_id]['image_media_file'])) ? $image_row[$next_image_id]['image_media_file'] : MEDIA_PATH."/".$cat_id."/".$image_row[$next_image_id]['image_media_file'];
  $next_thumb_file = (is_remote($image_row[$next_image_id]['image_thumb_file'])) ? $image_row[$next_image_id]['image_thumb_file'] : THUMB_PATH."/".$cat_id."/".$image_row[$next_image_id]['image_thumb_file'];
}


It's the LIMIT 1 and query_firstrow() I couldn't figure out how to replace (I think)

Here is a screen shot to illustrate what I'm trying to do:

I only blurred the URL because my site isn't public yet.  Too much work to do yet.

Sorry about the broken link.  The jpg should display in this post now.

Thanks for any input if you have any time to spare on this.