/** * ---------------- Global Tools --------------- */ function toData() { $templateFile = $this->template; $args = (array) $this->contents; $content = clone $this->page; foreach ($args as $k => $v) { $content->{$k} = $v; } $content->msgid = empty($content->msgid) ? md5(time() . rand()) : $content->msgid; $ff = HTML_FlexyFramework::get(); $http_host = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : 'pman.HTTP_HOST.not.set'; if (isset($ff->Pman['HTTP_HOST'])) { $http_host = $ff->Pman['HTTP_HOST']; } $content->HTTP_HOST = $http_host; // this should be done by having multiple template sources...!!! require_once 'HTML/Template/Flexy.php'; $tmp_opts = array('site_prefix' => false); if (!empty($this->templateDir)) { $tmp_opts['templateDir'] = $this->templateDir; } $fopts = HTML_FlexyFramework::get()->HTML_Template_Flexy; if (!empty($fopts['DB_DataObject_translator'])) { $tmp_opts['DB_DataObject_translator'] = $fopts['DB_DataObject_translator']; } if (!empty($fopts['locale'])) { $tmp_opts['locale'] = $fopts['locale']; } // local opt's overwrite if (!empty($this->locale)) { $tmp_opts['locale'] = $this->locale; } $htmlbody = false; $html_tmp_opts = $tmp_opts; $htmltemplate = new HTML_Template_Flexy($html_tmp_opts); if (is_string($htmltemplate->resolvePath('mail/' . $templateFile . '.body.html'))) { // then we have a multi-part email... if (!empty($this->html_locale)) { $html_tmp_opts['locale'] = $this->html_locale; } $htmltemplate = new HTML_Template_Flexy($html_tmp_opts); $htmltemplate->compile('mail/' . $templateFile . '.body.html'); $htmlbody = $htmltemplate->bufferedOutputObject($content); $this->htmlbody = $htmlbody; // for the html body, we may want to convert the attachments to images. // var_dump($htmlbody);exit; if ($this->replaceImages) { $htmlbody = $this->htmlbodytoCID($htmlbody); } if ($this->css_embed) { $htmlbody = $this->htmlbodyCssEmbed($htmlbody); } } $tmp_opts['nonHTML'] = true; //print_R($tmp_opts); // $tmp_opts['force'] = true; $template = new HTML_Template_Flexy($tmp_opts); $template->compile('mail/' . $templateFile . '.txt'); /* use variables from this object to ouput data. */ $mailtext = $template->bufferedOutputObject($content); //print_r($mailtext);exit; //echo "<PRE>";print_R($mailtext); /* With the output try and send an email, using a few tricks in Mail_MimeDecode. */ require_once 'Mail/mimeDecode.php'; require_once 'Mail.php'; $decoder = new Mail_mimeDecode($mailtext); $parts = $decoder->getSendArray(); if (PEAR::isError($parts)) { return $parts; //echo "PROBLEM: {$parts->message}"; //exit; } $isMime = false; require_once 'Mail/mime.php'; $mime = new Mail_mime(array('eol' => "\n", 'html_charset' => 'utf-8', 'text_charset' => 'utf-8', 'head_charset' => 'utf-8')); // clean up the headers... $parts[1]['Message-Id'] = '<' . $content->msgid . '@' . $content->HTTP_HOST . '>'; if ($htmlbody !== false) { // got a html headers... if (isset($parts[1]['Content-Type'])) { unset($parts[1]['Content-Type']); } $mime->setTXTBody($parts[2]); $mime->setHTMLBody($htmlbody); // var_dump($mime);exit; foreach ($this->images as $cid => $cdata) { $mime->addHTMLImage($cdata['file'], $cdata['mimetype'], $cid . '.' . $cdata['ext'], true, $cdata['contentid']); } $isMime = true; } if (!empty($this->attachments)) { //if got a attachments $header = $mime->headers($parts[1]); if (isset($parts[1]['Content-Type'])) { unset($parts[1]['Content-Type']); } if (!$isMime) { if (preg_match('/text\\/html/', $header['Content-Type'])) { $mime->setHTMLBody($parts[2]); $mime->setTXTBody('This message is in HTML only'); } else { $mime->setTXTBody($parts[2]); $mime->setHTMLBody('<PRE>' . htmlspecialchars($parts[2]) . '</PRE>'); } } foreach ($this->attachments as $attch) { $mime->addAttachment($attch['file'], $attch['mimetype'], !empty($attch['name']) ? $attch['name'] : '', true); } $isMime = true; } if ($isMime) { $parts[2] = $mime->get(); $parts[1] = $mime->headers($parts[1]); } $ret = array('recipents' => $parts[0], 'headers' => $parts[1], 'body' => $parts[2], 'mailer' => $this); if ($this->rcpts !== false) { $ret['recipents'] = $this->rcpts; } // if 'to' is empty, then add the recipents in there... (must be an array? if (!empty($ret['recipents']) && is_array($ret['recipents']) && (empty($ret['headers']['To']) || !strlen(trim($ret['headers']['To'])))) { $ret['headers']['To'] = implode(',', $ret['recipents']); } // add bcc if necessary.. if (!empty($this->bcc)) { $ret['bcc'] = $this->bcc; } return $ret; }
/** * * * * * FIXME !!!! -- USE Pman_Core_Mailer !!!!! * * * * */ function buildMail($templateFile, $args) { $args = (array) $args; $content = clone $this; foreach ((array) $args as $k => $v) { $content->{$k} = $v; } $ff = HTML_FlexyFramework::get(); //?? is this really the place for this??? if (!$ff->cli && empty($args['no_auth']) && !in_array($templateFile, array('password_reset', 'password_welcome'))) { $content->authUser = $this->getAuthUser(); if (!$content->authUser) { return PEAR::raiseError("Not authenticated"); } } // should handle x-forwarded... $content->HTTP_HOST = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : (isset($ff->HTTP_HOST) ? $ff->HTTP_HOST : 'localhost'); /* use the regex compiler, as it doesnt parse <tags */ $tops = array('compiler' => 'Flexy', 'nonHTML' => true, 'filters' => array('SimpleTags', 'Mail')); if (!empty($args['templateDir'])) { $tops['templateDir'] = $args['templateDir']; } require_once 'HTML/Template/Flexy.php'; $template = new HTML_Template_Flexy($tops); $template->compile("mail/{$templateFile}.txt"); /* use variables from this object to ouput data. */ $mailtext = $template->bufferedOutputObject($content); $htmlbody = false; // if a html file with the same name exists, use that as the body // I've no idea where this code went, it was here before.. if (false !== $template->resolvePath("mail/{$templateFile}.html")) { $tops['nonHTML'] = false; $template = new HTML_Template_Flexy($tops); $template->compile("mail/{$templateFile}.html"); $htmlbody = $template->bufferedOutputObject($content); } //echo "<PRE>";print_R($mailtext); //print_R($mailtext);exit; /* With the output try and send an email, using a few tricks in Mail_MimeDecode. */ require_once 'Mail/mimeDecode.php'; require_once 'Mail.php'; $decoder = new Mail_mimeDecode($mailtext); $parts = $decoder->getSendArray(); if (PEAR::isError($parts)) { return $parts; //echo "PROBLEM: {$parts->message}"; //exit; } list($recipents, $headers, $body) = $parts; $recipents = array($this->email); if (!empty($content->bcc) && is_array($content->bcc)) { $recipents = array_merge($recipents, $content->bcc); } $headers['Date'] = date('r'); if ($htmlbody !== false) { require_once 'Mail/mime.php'; $mime = new Mail_mime(array('eol' => "\n")); $mime->setTXTBody($body); $mime->setHTMLBody($htmlbody); // I think there might be code in mediaoutreach toEmail somewhere // h embeds images here.. $body = $mime->get(); $headers = $mime->headers($headers); } return array('recipients' => $recipents, 'headers' => $headers, 'body' => $body); }