DataObjects/Core_enum.php
[Pman.Core] / DataObjects / Core_email.php
index c7d0a21..a026695 100644 (file)
@@ -240,7 +240,7 @@ class Pman_Core_DataObjects_Core_email extends DB_DataObject
         
         if(!empty($unsubscribe)){
             $element = $doc->createElement('img');
-        
+            $element->setAttribute('mailembed', 'no');
             $element->setAttribute('src', $cfg ['server_baseurl']  . '/Crm/Open/' . $this->id . '/{person.id}.html');
             $element->setAttribute('width', '1');
             $element->setAttribute('height', '1');
@@ -281,10 +281,12 @@ class Pman_Core_DataObjects_Core_email extends DB_DataObject
      * convert email with contents into a core mailer object. - ready to send..
      * @param Object|Array $obj Object (or array) to send @see Pman_Core_Mailer
      *    + subject
-     *    + rcpts
+     *    + rcpts || person   << if person is set - then it goes to them...
      *    + replace_links
      *    + template
      *    + mailer_opts
+     *    + person << who it actually goes to..
+     *    
      * @param bool $force - force re-creation of cached version of email.
      *
      * @returns Pman_Core_Mailer
@@ -352,103 +354,25 @@ class Pman_Core_DataObjects_Core_email extends DB_DataObject
         
         return $r;
     }
-        
-        $ret = $r->toData();
-        
-        if(!$send){
-            return $ret;
+    function toMailerData($obj,$force=false)
+    {   
+        $r = $this->toMailer($obj, $force);
+        if (is_a($r, 'PEAR_Error')) {
+            return $r;
         }
-        
-        return $r->send();
-        
-        
+        return $r->toData();
     }
-    
-    
-    /**
-     *
-     * Usage:
-     * $this->rcpts = array('sales@roojs.com');
-     * // or 
-     * $this->rcpts = "Tester <sales@roojs.com>";
-     *
-     * 
-     * // then send it..
-     * $x = DB_DataObject::factory('core_enum');
-     * $x->get('name', 'NAME OF TEMPLATE');
-     * $x->send(array(
-     *      'rcpts' => "Tester <sales@roojs.com>",
-     *      'page' => $this
-     *      'mailer_opts' => array( <<< additional options, like urlmap..)
-     *       'link' => 'http://......'
-       );
-     * // on the template use {link:h} to render the link
-     *
-     *
-     */
+  
     function send($obj, $force = true, $send = true)
     {   
-        $contents = (array)$obj;
-
-        if(empty($this->id)){
-            $this->get('name', $contents['template']);
-        }
-        
-        if(empty($this->id)){
-            $p = new PEAR();
-            return $p->raiseError("template [{$contents['template']}] has not been set");
-        }
-        if(empty($contents['subject'])){
-           $contents['subject'] = $this->subject; 
+        if (!$send) {
+            return $this->toMailerData($obj,$force);
         }
-        
-        if(!empty($contents['rcpts']) && is_array($contents['rcpts'])){
-            $contents['rcpts'] = implode(',', $contents['rcpts']);
-        }
-        
-        $ui = posix_getpwuid(posix_geteuid());
-        
-        $cachePath = session_save_path() . '/email-cache-' . $ui['name'] . '/mail/' . $this->tableName() . '-' . $this->id . '.txt';
-        
-        if($force || !$this->isGenerated($cachePath)){
-            $this->cachedMailWithOutImages($force, empty($contents['replace_links']) ? false : $contents['replace_links']);
+        $r = $this->toMailer($obj, $force);
+        if (is_a($r, 'PEAR_Error')) {
+            return $r;
         }
          
-        require_once 'Pman/Core/Mailer.php';
-        
-        $templateDir = session_save_path() . '/email-cache-' . $ui['name'] ;
-        //print_r($this);
-        
-        
-        $cfg = array(
-            'template'=> $this->tableName() . '-' . $this->id,
-            'templateDir' => $templateDir,
-            'page' => $this,
-            'contents' => $contents,
-            'css_embed' => true, // we should always try and do this with emails...
-        );
-        if (isset($contents['rcpts'])) {
-            $cfg['rcpts'] = $contents['rcpts'];
-        }
-        if (isset($contents['mailer_opts']) && is_array($contents['mailer_opts'])) {
-            $cfg = array_merge($contents['mailer_opts'], $cfg);
-        }
-        
-        
-        $r = new Pman_Core_Mailer($cfg);
-        
-        $imageCache = session_save_path() . '/email-cache-' . $ui['name'] . '/mail/' . $this->tableName() . '-' . $this->id . '-images.txt';
-        
-        if(file_exists($imageCache) && filesize($imageCache)){
-            $images = json_decode(file_get_contents($imageCache), true);
-            $r->images = $images;
-        }
-        
-        $ret = $r->toData();
-        
-        if(!$send){
-            return $ret;
-        }
         
         return $r->send();
     }
@@ -538,7 +462,7 @@ Content-Transfer-Encoding: 7bit
                 continue;
             }
             
-            $images["attachment-$i->id"] = array(
+            $images["attachment-{$i->id}"] = array(
                 'file' => $i->getStoreName(),
                 'mimetype' => $i->mimetype,
                 'ext' => $y->toExt($i->mimetype),