<?php
# ------------------------------------------------------------------------------
#
# Contains some php utility functions
#
# function find_image_url($dir,$id) {
# function get_valid_img($dir,$id) {
# ------------------------------------------------------------------------------
#
# Copyright (C) 2003 Christian Eheim and Alex Pachikov
#
# This file is part of TVEz (tvez.sourceforge.net).
#
# TVEz is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# TVEz is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with TVEz; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ------------------------------------------------------------------------------
#
# Created on 02/12/2003 by Christian Eheim (hide@address.com)
#
# LAST MODIFIED:
# $Date: 2004/01/11 23:20:50 $
# $Revision: 1.1.1.1 $
# $Author: eheim $
#
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Check if the image exists for a given id
# ------------------------------------------------------------------------------
function find_image_url($dir,$id) {
global $IMG_PATH, $IMG_URL;
if (is_dir("$IMG_PATH/$dir")) {
if ($dh = opendir("$IMG_PATH/$dir")) {
while (($file = readdir($dh)) !== false) {
if (preg_match("/^$id\./", $file)) {
closedir($dh);
return "$IMG_URL/$dir/$file";
}
}
closedir($dh);
}
}
return NULL;
}
# ------------------------------------------------------------------------------
# Return the image url for an id if it exists, otherwise return the url to the
# 'no image availabe' image
# For the large image directory, searches for a large pic first,
# then for a small one, or return the no img
# ------------------------------------------------------------------------------
function get_valid_img($dir,$id) {
global $IMG_URL;
if ($img = find_image_url($dir,$id)) return $img;
if ($dir == "large") {
$dir = "small";
if ($img = find_image_url($dir,$id)) return $img;
}
return "$IMG_URL/noimg.jpg";
}
?>