Changed DataObjects/Images.phpImages.php
authorAlan <alan@roojs.com>
Mon, 27 Mar 2023 04:33:29 +0000 (12:33 +0800)
committerAlan <alan@roojs.com>
Mon, 27 Mar 2023 04:33:29 +0000 (12:33 +0800)
DataObjects/Images.php
Images.php

index 907b890..4eb72f5 100644 (file)
@@ -200,13 +200,10 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
      *
      * @return - target file name
      */
-    function getStoreName($alt = false
+    function getStoreName() 
     {
         $opts = HTML_FlexyFramework::get()->Pman;
         $fn = preg_replace('/[^a-z0-9_\.]+/i', '_', $this->filename);
-        if ($alt) {
-            $fn = preg_replace('/[^a-z0-9\.]+/i', '_', $this->filename);
-        }
         return implode( '/', array(
             $opts['storedir'], '_images_', date('Y/m', strtotime($this->created)), $this->id . '-'. $fn
         ));
@@ -672,9 +669,6 @@ class Pman_Core_DataObjects_Images extends DB_DataObject
     function toFileConvert()
     {
         $fn = $this->getStoreName();
-        if (!file_exists($fn)) {
-            $fn = $this->getStoreName(true);
-        }
         
         require_once 'File/Convert.php';
         $fc = new File_Convert($this->getStoreName(), $this->mimetype);
index 92c99e9..5a0deb8 100644 (file)
@@ -285,10 +285,13 @@ class Pman_Core_Images extends Pman
     {
         $this->sessionState(0); // turn off session... - locking...
         require_once 'File/Convert.php';
-        if (!file_exists($img->getStoreName()) && !file_exists($img->getStoreName(true))) {
-//            print_r($img);exit;
-            header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
-                urlencode("Original file was missing : " . $img->getStoreName()));
+        if (!file_exists($img->getStoreName())) {
+            if (!$this->canFix($img)) {
+                header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=missing-image-see-original-response');
+                echo "Original file was missing : " . $img->getStoreName();
+                exit;
+            }
+            
     
         }
 //        print_r($img);exit;
@@ -664,4 +667,33 @@ class Pman_Core_Images extends Pman
         }
     }
     
+    function canFix($img) {
+        // look for the image in the folder, with matching id.
+        // this is problematic..
+        $fn = $img->getStoreName();
+        if (file_exists($fn . '-really-missing')) {
+            return false;
+        }
+        if (!file_exists(dirname($fn))) {
+            return false;
+        }
+        foreach( scandir(dirname($fn)) as $n) {
+            if (empty($n) || $n[0] == '.') {
+                continue;
+            }
+            $bits = explode('-', $n);
+            if ($n[0] != $img->id) {
+                continue;
+            }
+            if (preg_match('/\.[0-9]+x[0-9]]+\.jpeg$/', $n)) {
+                continue;
+            }
+            cp(dirname($fn). $n, $fn);
+            return true;
+        }
+        // fixme - flag it as bad
+    }
+        
+        
+         
 }