X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=inc%2Futils.php;h=a5a1c8be6cf72acbf98f99cccb1aa219766058c5;hp=12c85c673dfd321a9b1d1a955103aa93f5895d2c;hb=19730f2e2bbf61f389882c646f58349df3bcd848;hpb=9acc365249b5e630da6b5cdd23e3a8015f39ddc7 diff --git a/inc/utils.php b/inc/utils.php index 12c85c6..a5a1c8b 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -2,7 +2,9 @@ /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD license. */ -require_once ("inc/settings.php"); +// using include because that file may be sourced even if config file has not +// been created. +@include_once ("inc/settings.php"); function getthumbsdir () { if (THUMBSDIR) { @@ -45,7 +47,7 @@ function unquote($gpc_str) { function thumb_url_from_imgpath ($filename) { if (defined ("THUMBSDIRURL") && (strlen (THUMBSDIRURL) != 0)) { - return rtrim (THUMBSDIRURL, '/') . "/_mini" . rawurlencode ($filename); + return rtrim (THUMBSDIRURL, '/') . "/mini_" . rawurlencode ($filename); } return full_url_from_path (getthumbsdir () . "/mini_" . rawurlencode ($filename)); } @@ -101,7 +103,25 @@ function full_url_from_path ($path) { return "$proto://$host$port$path"; } +function create_thumbnail_or_copy ($filename, $destfile) { + try { + $thumbnail_ok = create_thumbnail ($filename, $destfile); + } catch (Exception $e) { + $thumbnail_ok = false; + } + if (!$thumbnail_ok) { + if (!copy ($filename, $destfile)) { + return false; + } + } + return true; +} + function create_thumbnail ($filename, $destfile) { + if (!function_exists ("imagecreatefromjpeg") + || !function_exists ("imagecreatefrompng")) { + return false; + } $ext = strtolower (ext_safe ($filename)); if ($ext == "jpg" || $ext == "jpeg") { $image = imagecreatefromjpeg ($filename); @@ -162,39 +182,4 @@ function create_thumbnail ($filename, $destfile) { return true; } - -function safe_create_dir ($dirname) { - if (is_dir ($dirname)) { - return; - } - if (file_exists ($dirname)) { - par_error ($dirname . ": " . trans ('exist but is not a directory')); - } - if (!mkdir ($dirname)) { - par_error ($dirname . ": " . trans ('could not create directory')); - } else { - par_success ($dirname . ": " . trans ('directory created')); - } -} - -function safe_create_writable_dir ($dirname) { - safe_create_dir ($dirname); - if (!is_writeable ($dirname) || !is_executable ($dirname)) { - par_error ($dirname . ": " . trans ('could not write in directory')); - } -} - -function leave () { - exit ("\n"); -} -function par_success ($message) { - printf ("

%s

", $message); -} -function par_error ($message) { - printf ("

%s

", $message); - leave (); -} -function par_warn ($message) { - printf ("

%s

", $message); -} ?>