]> dev.renevier.net Git - syp.git/blobdiff - inc/utils.php
fixes CHANGES.txt
[syp.git] / inc / utils.php
index 12c85c673dfd321a9b1d1a955103aa93f5895d2c..a5a1c8be6cf72acbf98f99cccb1aa219766058c5 100644 (file)
@@ -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</body></html>");
-}
-function par_success ($message) {
-    printf ("<p class=\"success center\">%s</p>", $message);
-}
-function par_error ($message) {
-    printf ("<p class=\"error center\">%s</p>", $message);
-    leave ();
-}
-function par_warn ($message) {
-    printf ("<p class=\"warn center\">%s</p>", $message);
-}
 ?>