$i->update($ii);
}
-// $this->cachedMailWithOutImages(true, (get_class($this) == 'Pman_Core_DataObjects_Core_email') ? false : true);
- $this->cachedMailWithOutImages(true, false);
+ $this->cachedMailWithOutImages(true, (get_class($this) == 'Pman_Core_DataObjects_Core_email') ? false : true);
+// $this->cachedMailWithOutImages(true, false);
}
function onUpdate($old, $q,$roo)
{
- $this->cachedMailWithOutImages(true, false);
+ $this->cachedMailWithOutImages(true, (get_class($this) == 'Pman_Core_DataObjects_Core_email') ? false : true);
}
function processRelacements($replace_links = true)
{
+ $cfg = isset(HTML_FlexyFramework::get()->Pman_Crm) ? HTML_FlexyFramework::get()->Pman_Crm : false;
+
libxml_use_internal_errors (true);
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->loadHTML('<?xml encoding="UTF-8">'.$this->bodytext);
}
}
+ $unsubscribe = false;
+
+ if(!empty($cfg)){
+ $unsubscribe = $cfg ['server_baseurl'] . '/Crm/Unsubscribe/' . $this->id . '/{person.id}';
+ }
+
+ foreach ($xpath->query('//a[@href]') as $a) {
+
+ $href = $a->getAttribute('href');
+
+ if(preg_match('/#unsubscribe/', $href) && !empty($unsubscribe)){
+ $a->setAttribute('href', $unsubscribe);
+ continue;
+ }
+
+ if(!preg_match('/^http(.*)/', $href)){
+ continue;
+ }
+ if (!$replace_links) {
+ continue;
+ }
+ $link = DB_DataObject::factory('crm_mailing_list_link');
+ $link->setFrom(array(
+ 'url' => $href
+ ));
+
+ if(!$link->find(true)){
+ $link->insert();
+ }
+
+ if(!$link->id){
+ continue;
+ }
+
+ $l = $cfg ['server_baseurl'] . '/Crm/Link/' .$this->id . '/' . $link->id . '/{person.id}.html';
+
+ $a->setAttribute('href', $l);
+
+ }
+
+ if(!empty($unsubscribe)){
+ $element = $doc->createElement('img');
+
+ $element->setAttribute('src', $cfg ['server_baseurl'] . '/Crm/Open/' . $this->id . '/{person.id}.html');
+ $element->setAttribute('width', '1');
+ $element->setAttribute('height', '1');
+
+ $html = $doc->getElementsByTagName('html');
+ $html->item(0)->appendChild($element);
+
+ $this->plaintext = str_replace("{unsubscribe_link}", $unsubscribe, $this->plaintext);
+ }
+
+
$this->bodytext = $doc->saveHTML();
libxml_use_internal_errors (false);
$this->bodytext = str_replace('%7B', '{', $this->bodytext ); // kludge as template is not interpretated as html.
$this->bodytext = str_replace('%7D', '}', $this->bodytext ); // kludge as template is not interpretated as html.
-
+
return;
}
- function send($obj)
- {
+ function send($obj, $force = true, $send = true)
+ {
$contents = (array)$obj;
- $this->cachedMailWithOutImages(true, false);
+ if(empty($this->id)){
+ $this->get('name', $contents['template']);
+ }
+
+ if(empty($this->id)){
+ return PEAR::raiseError("template [{$contents['template']}]has not been set");
+ }
$contents['subject'] = $this->subject;
$ui = posix_getpwuid(posix_geteuid());
+ $cachePath = session_save_path() . '/email-cache-' . $ui['name'] . '/mail/' . $this->tableName() . '-' . $this->id . '.txt';
+
+ if(!$this->isGenerated($cachePath)){
+ $this->cachedMailWithOutImages($force, false);
+ }
+
require_once 'Pman/Core/Mailer.php';
$templateDir = session_save_path() . '/email-cache-' . $ui['name'] ;
+
$r = new Pman_Core_Mailer(array(
'template'=> $this->tableName() . '-' . $this->id,
'templateDir' => $templateDir,
$ret = $r->toData();
+ if(!$send){
+ return $ret;
+ }
+
return $r->send($ret);
}
");
fclose($fh);
+ // cache body
+
+ $this->processRelacements($replace_links);
+
+ $cachePath = session_save_path() . '/email-cache-' . $ui['name'] . '/mail/' . $this->tableName() . '-' . $this->id . '.body.html';
+
+ if (!file_exists(dirname($cachePath))) {
+ mkdir(dirname($cachePath), 0700, true);
+ }
+
+ file_put_contents($cachePath, $this->bodytext);
+
}
function cachedImages()