DataObjects/core.sql
[Pman.Core] / Images.php
index 676234c..9554939 100644 (file)
@@ -221,17 +221,18 @@ class Pman_Core_Images extends Pman
      */
     
     
-    static function replaceImgURLS($html)
+    static function replaceImageURLS($html)
     {
         
         $ff = HTML_FlexyFramework::get();
-        if (!isset($ff->Pman_Image['public_baseURL'])) {
+        if (!isset($ff->Pman_Images['public_baseURL'])) {
             return $html;
         }
-        $baseURL = $ff->Pman_Image['public_baseURL'];
+        //var_dump($ff->Pman_Images['public_baseURL']);
+        $baseURL = $ff->Pman_Images['public_baseURL'];
         
-        preg_match_all('/<img\w[^>]+>/i',$html, $result); 
-
+        preg_match_all('/<img\s+[^>]+>/i',$html, $result); 
+        //print_r($result);
         $matches = array_unique($result[0]);
         foreach($matches as $img) {
             $imatch = array();
@@ -245,11 +246,11 @@ class Pman_Core_Images extends Pman
             if (!isset($attr['src']) || 0 !== strpos($attr['src'], $baseURL)) {
                 continue;
             }
-            $html = self::replaceImgUrl($html, $baseURL, $img, $attr, $attr['src'] );
+            $html = self::replaceImgUrl($html, $baseURL, $img, $attr,  'src' );
         }
         
         $result = array();
-        preg_match_all('/<a\w[^>]+>/i',$html, $result); 
+        preg_match_all('/<a\s+[^>]+>/i',$html, $result); 
 
         $matches = array_unique($result[0]);
         foreach($matches as $img) {
@@ -264,12 +265,12 @@ class Pman_Core_Images extends Pman
             if (!isset($attr['href']) || 0 !== strpos($attr['href'], $baseURL)) { 
                 continue;
             }
-            $html = self::replaceImgUrl($html, $baseURL, $img, $attr, $attr['href'] );
+            $html = self::replaceImgUrl($html, $baseURL, $img, $attr, 'href' );
         }
         
         return $html;
     }
-    static function replaceImgUrl($html, $baseURL, $tag, $attr, $attr_url
+    static function replaceImgUrl($html, $baseURL, $tag, $attr, $attr_name
     {
         
         //print_R($attr);
@@ -277,6 +278,8 @@ class Pman_Core_Images extends Pman
         // Images/{ID}/fullname.xxxx
         // Images/Thumb/200/{ID}/fullname.xxxx
         // Images/Download/{ID}/fullname.xxxx
+        
+        $attr_url = $attr[$attr_name];
         $umatch  = false;
         if(!preg_match('#/(Images|Images/Thumb/[a-z0-9]+|Images/Download)/([0-9]+)/(.*)$#', $attr_url, $umatch))  {
             continue;
@@ -288,13 +291,12 @@ class Pman_Core_Images extends Pman
         }
         $type = explode('/', $umatch[1]);
         $thumbsize = -1;
-        $new_thumbsize = -1;
-        
+         
         if (count($type) > 2 && $type[1] == 'Thumb') {
             $thumbsize = $type[2];
-            $provider = 'Images/Thumb';
+            $provider = '/Images/Thumb';
         } else {
-            $provider = $umatch[1];
+            $provider = '/'.$umatch[1];
         }
         
         if (!empty($attr['width']) || !empty($attr['height']) )
@@ -304,7 +306,7 @@ class Pman_Core_Images extends Pman
                 (empty($attr['width']) ? '0' : $attr['width'] * 1) .
                 'x' .
                 (empty($attr['height']) ? '0' : $attr['height'] * 1);
-            
+             $provider = '/Images/Thumb';
             
         }
         
@@ -327,8 +329,8 @@ class Pman_Core_Images extends Pman
         // finally replace the original TAG with the new version..
         
         $new_tag = str_replace(
-            'src="'. $attr['src'] . '"',
-            'src="'. htmlspecialchars($img->URL($new_thumbsize , $provider, $baseURL)) . '"',
+            $attr_name. '="'. $attr_url . '"',
+            $attr_name .'="'. htmlspecialchars($img->URL($thumbsize, $provider, $baseURL)) . '"',
             $tag
         );