# Copyright (c) 2002 Sandino Araico Sánchez /* This program 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. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ # Changelog: # 2002-01-25 Tony J. White tjw@tjw.org - DirectoryMediaIndex (dmi) 1.2 # 2002-03-14 Sandino Araico Sánchez - separated dmi-lib from dmi-1.2.php # Enclosed inside #ifdef duplicates protection # Use $THUMBS_DIR and HOPP's 's' functions # Text file with image title support # Reverse chronological order # Single image navigation # View thumbnails message # 2002-03-16 Sandino Araico Sánchez - Fixed thumbnails link Bug # 2002-04-09 Sandino Araico Sánchez - HOPP templates support # Different templates for dmi-big # 2002-04-20 Sandino Araico Sánchez # Worked around first & last links not showing problem with edges hidden # 2002-08-29 Sandino Araico Sánchez # extracted core functions from dmi-lib # 2002-08-29 Sandino Araico Sánchez - Moved config to constants # 2002-09-09 Sandino Araico Sánchez - New collition-proof function names if(!defined('__DMI_LIB__')) { define('__DMI_LIB__',1); //**********************************************************************/ include "dmi-autoconf.inc"; //**********************************************************************/ // handles spaces and such function shellWrap($in) { return str_replace("\n", "\\", preg_replace("/([ \'\"&;\`\(\)?!])/", "\n\\1", $in)); } // gets filename without extension function dmi_get_file_name($in) { $out = basename($in); $out = substr(strrev(strstr(strrev($out), ".")), 0, -1); return $out; } function safeFileName($in) { return preg_replace("/[^a-z0-9\.]/i", "_", $in); } function stripExtension($in) { if(eregi("(.+)\.[a-z]{3,4}$", $in, $out)) { return $out[1]; } else return $in; } // helper function for interpreting getImageSize() return data function extensionize($in, $type) { if($type == 1) { if(!eregi("\.gif$", $in)) return $in.".gif"; } elseif($type == 2) { if(!eregi("\.jpg$", $in)) return $in.".jpg"; } elseif($type == 3) { if(!eregi("\.png$", $in)) return $in.".png"; } elseif($type == 4) { if(!eregi("\.swf$", $in)) return $in.".swf"; } return $in; } // helper function for interpreting getImageSize() return data function getExtension($type) { if($type == 1) return ".gif"; elseif($type == 2) return ".jpg"; elseif($type == 3) return ".png"; elseif($type == 4) return ".swf"; return ""; } // helper function for interpreting getImageSize() return data function getMimeType($type) { if($type == 1) return "image/gif"; elseif($type == 2) return "image/jpeg"; elseif($type == 3) return "image/png"; elseif($type == 4) return "application/x-shockwave-flash"; return ""; } function is_mpeg_video($filename) { if(!is_executable(__DMI_MPGINFO_PROG)) return 0; $is_mpeg = 0; $cmd = __DMI_MPGINFO_PROG." ".shellWrap($filename); $out = `$cmd`; $out = str_replace("\r", "", $out); $lines = explode("\n", $out); while(list($num, $line) = each($lines)) { if(preg_match("/^ Mpeg .*Video/", $line)) $is_mpeg = 1; } return $is_mpeg; } function getSortInfos($img_infos) { if(!is_array($img_infos)) return 0; foreach($img_infos as $key => $img_info) { $sort_infos[$key]=filectime($img_info['full_file']); } arsort($sort_infos); return $sort_infos; } function getImageTitle($full_file) { $text_file=stripExtension($full_file).'.txt'; #s_log("text_file: $text_file"); if(file_exists($text_file)) { $file=fopen($text_file,'r'); if($file) { $text=fread($file,1024); fclose($file); #s_log("Using text file contents: $text"); } } if(empty($text)) $text=str_replace("_", " ", dmi_get_file_name($full_file)); #s_log("text: $text"); return nl2br(htmlentities($text)); } function clearBitmaps($dump_dir) { if(!is_dir(__DMI_PHOTO_DIR."/thumbs/".$dump_dir)) { return 0; } $full_dump_dir = __DMI_PHOTO_DIR."/thumbs/".$dump_dir; $bmp_dir_handle = opendir($full_dump_dir); while($file = readdir($bmp_dir_handle)) { if($file == ".." || $file == ".") continue; $full_file = __DMI_PHOTO_DIR ."/thumbs/".$dump_dir."/".$file; if(eregi("\.bmp$", $full_file)) $deleted = unlink($full_file); } $success = @rmdir($full_dump_dir); return $success; } function errorImage() { header("Content-type: image/gif"); // this image is image1.gif blatently ripped off from the // apache icons directory $image = "R0lGODlhFAAWAOMAAP/////MM/9mZsz//8zMzJmZmZlmADMzMwAA" ."AAAAAAAAAAAAAAAAAAAAAAAAAAAAACH+TlRoaXMgYXJ0IGlzIGlu" ."IHRoZSBwdWJsaWMgZG9tYWluLiBLZXZpbiBIdWdoZXMsIGtldmlu" ."aEBlaXQuY29tLCBTZXB0ZW1iZXIgMTk5NQAh+QQBAAADACwAAAAA" ."FAAWAAAEbXDISSm6NVckOtLg5YEZQgTcR1oBqq6S2RovjLQYHJ8BT" ."R2FoFB4cwUPkgNgyWReeghAQaVsNi+X5TRpvWa11K4zytwOqoCoOm" ."01V8nicphthYO59Pj9vLT323NYgl1ueoRUQEOKQwc1go+QKhEAOw" ."=="; echo base64_decode($image); exit(); } //**********************************************************************/ } // __DMI_LIB__ ?>