DataObjects/Core_enum.php
[Pman.Core] / Mailer.php
index 765e040..040379c 100644 (file)
@@ -21,6 +21,7 @@
        contents
        template
        html_locale => 'en' == always use the 'english translated verison'
+       cache_images => true -- defaults to caching images - set to false to disable.
        replaceImages => true|false,
        locale => 'en' .... or zh_hk....
        rcpts => array()   // override recipients..
@@ -69,11 +70,21 @@ class Pman_Core_Mailer {
     
     var $mail_method = 'SMTP';
     
+    var $cache_images = true;
+    
     function Pman_Core_Mailer($args) {
         foreach($args as $k=>$v) {
             // a bit trusting..
             $this->$k =  $v;
         }
+        // allow core mailer debug setting.
+        $ff = HTML_FlexyFramework::get();
+        
+        if (!empty($ff->Core_Mailer['debug'])) {
+            $this->debug = $ff->Core_Mailer['debug'];
+        }
+        
+        
     }
      
     /**
@@ -365,17 +376,33 @@ class Pman_Core_Mailer {
         // this may raise parse errors as some html may be a component..
         @$dom->loadHTML('<?xml encoding="UTF-8">' .$html);
         $links = $dom->getElementsByTagName('link');
-        //<link rel="stylesheet" type="text/css" href="{rootURL}/roojs1/css-mailer/mailer.css"> 
-        foreach ($links as $i=>$link) {
+        $lc = array();
+        foreach ($links as $link) {  // duplicate as links is dynamic and we change it..!
+            $lc[] = $link;
+        }
+        //<link rel="stylesheet" type="text/css" href="{rootURL}/roojs1/css-mailer/mailer.css">
+        
+        foreach ($lc as $i=>$link) {
+            //var_dump($link->getAttribute('href'));
+            
             if ($link->getAttribute('rel') != 'stylesheet') {
                 continue;
             }
             $url  = $link->getAttribute('href');
             $file = $ff->rootDir . $url;
-            if (!file_exists($file)) {
-                $link->setAttribute('href', 'missing:' . $file);
-                continue;
+            
+            if (!preg_match('#^http://#', $url)) {
+                $file = $ff->rootDir . $url;
+
+                if (!file_exists($file)) {
+                    echo $file;
+                    $link->setAttribute('href', 'missing:' . $file);
+                    continue;
+                }
+            } else {
+               $file = $url;  
             }
+            
             $par = $link->parentNode;
             $par->removeChild($link);
             $s = $dom->createElement('style');
@@ -442,7 +469,10 @@ class Pman_Core_Mailer {
         $user = $uinfo['name']; 
         
         $cache = ini_get('session.save_path')."/Pman_Core_Mailer-{$user}/" . md5($url);
-        if (file_exists($cache) and filemtime($cache) > strtotime('NOW - 1 WEEK')) {
+        if ($this->cache_images &&
+                file_exists($cache) &&
+                filemtime($cache) > strtotime('NOW - 1 WEEK')
+            ) {
             $ret =  json_decode(file_get_contents($cache), true);
             $ret['file'] = $cache . '.data';
             return $ret;