From ea36e81b91c8689ae44d413eca4697d1993ac30b Mon Sep 17 00:00:00 2001 From: Andreas Unterkircher Date: Sat, 23 May 2009 09:45:29 +0200 Subject: [PATCH] avoid notice messages about undefined variables, resolves #179 Signed-off-by: Andreas Unterkircher --- phpfspot.class.php | 74 +++++++++++++---------- themes/default/templates/calendar.tpl | 2 +- themes/default/templates/header.tpl | 4 +- themes/default/templates/photo_index.tpl | 32 +++++----- themes/default/templates/search.tpl | 12 ++-- themes/default/templates/single_photo.tpl | 32 ++++++---- themes/default/templates/tags.tpl | 2 +- 7 files changed, 87 insertions(+), 71 deletions(-) diff --git a/phpfspot.class.php b/phpfspot.class.php index b82efa5..1423f98 100644 --- a/phpfspot.class.php +++ b/phpfspot.class.php @@ -213,6 +213,7 @@ class PHPFSPOT { require_once "phpfspot_tmpl.php"; $this->tmpl = new PHPFSPOT_TMPL(); + /* pre-set some template variables */ $this->tmpl->assign('web_path', $this->cfg->web_path); /* Starting with F-Spot 0.4.2, the rating-feature was available */ @@ -1471,40 +1472,45 @@ class PHPFSPOT { } $thumbs = 0; - $images[$thumbs] = Array(); - $img_height[$thumbs] = Array(); - $img_width[$thumbs] = Array(); - $img_id[$thumbs] = Array(); - $img_name[$thumbs] = Array(); - $img_fullname[$thumbs] = Array(); - $img_title = Array(); - $img_rating = Array(); for($i = $begin_with; $i < $end_with; $i++) { - if(isset($photos[$i])) { + if(!isset($photos[$i])) + continue; + + /* on first run, initalize all used variables */ + if($thumbs == 0) { + $images = Array(); + $images[$thumbs] = Array(); + $img_height[$thumbs] = Array(); + $img_width[$thumbs] = Array(); + $img_id[$thumbs] = Array(); + $img_name[$thumbs] = Array(); + $img_fullname[$thumbs] = Array(); + $img_title = Array(); + $img_rating = Array(); + } - $images[$thumbs] = $photos[$i]; - $img_id[$thumbs] = $i; - $img_name[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 15)); - $img_fullname[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 0)); - $img_title[$thumbs] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0)); - $img_rating[$thumbs] = $this->get_photo_rating($photos[$i]); + $images[$thumbs] = $photos[$i]; + $img_id[$thumbs] = $i; + $img_name[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 15)); + $img_fullname[$thumbs] = htmlspecialchars($this->getPhotoName($photos[$i], 0)); + $img_title[$thumbs] = "Click to view photo ". htmlspecialchars($this->getPhotoName($photos[$i], 0)); + $img_rating[$thumbs] = $this->get_photo_rating($photos[$i]); - $thumb_path = $this->get_thumb_path($this->cfg->thumb_width, $photos[$i], $this->get_latest_version($photos[$i])); + /* get local path of the thumbnail image to be displayed */ + $thumb_path = $this->get_thumb_path($this->cfg->thumb_width, $photos[$i], $this->get_latest_version($photos[$i])); - if(file_exists($thumb_path)) { - $info = getimagesize($thumb_path); + /* if the image exist and is readable, extract some details */ + if(file_exists($thumb_path) && is_readable($thumb_path)) { + if($info = getimagesize($thumb_path) !== false) { $img_width[$thumbs] = $info[0]; $img_height[$thumbs] = $info[1]; } - $thumbs++; - } + } + $thumbs++; } - // +1 for for smarty's selection iteration - $thumbs++; - if(isset($_SESSION['searchfor_tag']) && $_SESSION['searchfor_tag'] != '') $this->tmpl->assign('searchfor_tag', $_SESSION['searchfor_tag']); @@ -1629,16 +1635,20 @@ class PHPFSPOT { $this->tmpl->assign('preview_width', $this->cfg->photo_width); $this->tmpl->assign('thumb_container_width', $this->cfg->thumb_width); $this->tmpl->assign('thumb_container_height', $this->cfg->thumb_height+20); - $this->tmpl->assign('images', $images); - $this->tmpl->assign('img_width', $img_width); - $this->tmpl->assign('img_height', $img_height); - $this->tmpl->assign('img_id', $img_id); - $this->tmpl->assign('img_name', $img_name); - $this->tmpl->assign('img_fullname', $img_fullname); - $this->tmpl->assign('img_title', $img_title); - $this->tmpl->assign('img_rating', $img_rating); - $this->tmpl->assign('thumbs', $thumbs); $this->tmpl->assign('selected_tags', $this->getSelectedTags('img')); + // +1 for for smarty's selection iteration + $this->tmpl->assign('thumbs', $thumbs+1); + + if($thumbs > 0) { + $this->tmpl->assign('images', $images); + $this->tmpl->assign('img_width', $img_width); + $this->tmpl->assign('img_height', $img_height); + $this->tmpl->assign('img_id', $img_id); + $this->tmpl->assign('img_name', $img_name); + $this->tmpl->assign('img_fullname', $img_fullname); + $this->tmpl->assign('img_title', $img_title); + $this->tmpl->assign('img_rating', $img_rating); + } $result = $this->tmpl->fetch("photo_index.tpl"); diff --git a/themes/default/templates/calendar.tpl b/themes/default/templates/calendar.tpl index 1f52732..8c1d27e 100644 --- a/themes/default/templates/calendar.tpl +++ b/themes/default/templates/calendar.tpl @@ -18,7 +18,7 @@ {section name="row" loop=$rows step=1} {section name="col" loop=8 step=1} - {if $matrix[row][col] } + {if isset($matrix[row][col]) } {$matrix[row][col]} {/if} {/section} diff --git a/themes/default/templates/header.tpl b/themes/default/templates/header.tpl index c1d7a0c..d592ebf 100644 --- a/themes/default/templates/header.tpl +++ b/themes/default/templates/header.tpl @@ -8,13 +8,13 @@ - { if $use_lightbox } + { if isset($use_lightbox) } { /if } - { if $use_autocomplete } + { if isset($use_autocomplete) } { /if } diff --git a/themes/default/templates/photo_index.tpl b/themes/default/templates/photo_index.tpl index fa63b31..ddc3229 100644 --- a/themes/default/templates/photo_index.tpl +++ b/themes/default/templates/photo_index.tpl @@ -5,13 +5,13 @@
Photo Index - {if $searchfor } + {if isset($searchfor) } {if $count == 1} {$count} image is the result for your search about "{$searchfor}". {else} {$count} images are the result for your search about "{$searchfor}". {/if} - {elseif $tag_result} + {elseif isset($tag_result)} {if $count == 1} {$count} image has been found for the selected tags. {else} @@ -24,22 +24,22 @@ {$count} images have been found. {/if} {/if} - {if $from_date && $to_date } + {if isset($from_date) && isset($to_date) }
Results are limited to a date within {$from_date} to {$to_date}. {/if}
- {if $slideshow_link } + {if isset($slideshow_link) }  Slideshow {/if} - {if $extern_link } + {if isset($extern_link) }  External Link {/if} - {if $export_link } + {if isset($export_link) }  Export {/if} - {if $rss_link } + {if isset($rss_link) }  RSS-Feed {/if}
@@ -48,7 +48,7 @@ -{ if $tag_result } +{ if isset($tag_result) }
@@ -66,10 +66,10 @@ {section name="thumb" loop=$thumbs step=1} - {if $images[thumb] } + {if isset($images[thumb]) }
- { if $user_friendly_url } + { if isset($user_friendly_url) } { else } @@ -79,11 +79,11 @@ {$img_name[thumb]} - { if $use_lightbox } + { if isset($use_lightbox) } { /if } - { if $img_rating[thumb] } + { if isset($img_rating[thumb]) }
{section name="rating" loop=$img_rating[thumb] step=1} @@ -101,7 +101,7 @@
- { if $next_url == "" } + { if !isset($next_url) || $next_url == "" } { if $count != 0 } last page reached { /if } @@ -114,7 +114,7 @@
- { if $previous_url == "" } + { if !isset($previous_url) || $previous_url == "" } { if $count != 0 } first page reached { /if } @@ -127,7 +127,7 @@
- { if $page_selector != "" } + { if isset($page_selector) && $page_selector != "" } {$page_selector} { /if}
@@ -149,7 +149,7 @@ var last_thumb; {section name="thumb" loop=$thumbs step=1} - {if $images[thumb] } + {if isset($images[thumb]) } image_urls[{counter}] = '{$web_path}/phpfspot_img.php?idx={$images[thumb]}&width={$width}'; last_thumb = {$images[thumb]}; {/if} diff --git a/themes/default/templates/search.tpl b/themes/default/templates/search.tpl index 672bb35..69de0a1 100644 --- a/themes/default/templates/search.tpl +++ b/themes/default/templates/search.tpl @@ -7,7 +7,7 @@ Tag: - { if $use_autocomplete } + { if isset($use_autocomplete) } { literal } { /literal } { else } - + { /if } @@ -31,7 +31,7 @@ Name: - + @@ -40,7 +40,7 @@ Date: - { if ! $date_search_enabled } + { if ! isset($date_search_enabled) } { else } @@ -60,11 +60,11 @@ - { if $has_rating } + { if isset($has_rating) } Rating: - { if ! $rate_search_enabled } + { if ! isset($rate_search_enabled) } { else } diff --git a/themes/default/templates/single_photo.tpl b/themes/default/templates/single_photo.tpl index 572bef7..f74b34c 100644 --- a/themes/default/templates/single_photo.tpl +++ b/themes/default/templates/single_photo.tpl @@ -9,7 +9,7 @@ {else} Photos {/if} - {if $description} + {if isset($description) } - {$description}
{/if} {/if} @@ -19,7 +19,7 @@  Auto-Browse - {if $extern_link } + {if isset($extern_link) }  External Link {/if} original resolution Fullsize @@ -29,27 +29,27 @@

- { if $ExifMadeWith } + { if isset($ExifMadeWith) } camera icon Image taken with:
{$ExifMadeWith}
{ /if } - { if $ExifMadeOn } + { if isset($ExifMadeOn) } calendar icon Image made on:
{$ExifMadeOn}
{ /if } - { if $ExifOrigResolution } + { if isset($ExifOrigResolution) } resolution icon Original resolution:
{$ExifOrigResolution}px
{ /if } Size: {$ExifFileSize}
- { if $image_rating } + { if isset($image_rating) && $image_rating > 0 } rating Rating:
{section name="rating" loop=$image_rating step=1} {/section}
{ /if } - { if $has_versions } + { if isset($has_versions) }
Versions:

{ /if } - { if $tags } + { if isset($tags) }
available tags Tagged with:
{ foreach from=$tags key=id item=name } @@ -65,13 +65,13 @@ { /foreach } { /if }
- { if $prev_img } + { if isset($prev_img) && isset($previous_url) } photo icon Previous:

{ /if} - { if $next_img } + { if isset($next_img) && isset($next_url) } photo icon Next:

@@ -82,7 +82,7 @@