• Main Page
  • Modules
  • Classes
  • Files
  • File List

classes/mail/MailTemplate.inc.php

00001 <?php
00002 
00016 import('lib.pkp.classes.mail.PKPMailTemplate');
00017 
00018 class MailTemplate extends PKPMailTemplate {
00020    var $press;
00021 
00023    var $includeSignature;
00024 
00033    function MailTemplate($emailKey = null, $locale = null, $enableAttachments = null, $press = null, $includeSignature = true) {
00034       parent::PKPMailTemplate($emailKey, $locale, $enableAttachments);
00035 
00036       // If a press wasn't specified, use the current request.
00037       if ($press === null) $press =& Request::getPress();
00038 
00039       $this->includeSignature = $includeSignature;
00040 
00041       if (isset($this->emailKey)) {
00042          $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
00043          $emailTemplate =& $emailTemplateDao->getEmailTemplate($this->emailKey, $this->locale, $press == null ? 0 : $press->getId());
00044       }
00045 
00046       $userSig = '';
00047       $user =& Request::getUser();
00048       if ($user) {
00049          $userSig = $user->getLocalizedSignature();
00050          if (!empty($userSig)) $userSig = "\n" . $userSig;
00051       }
00052 
00053       if (isset($emailTemplate) && Request::getUserVar('subject')==null && Request::getUserVar('body')==null) {
00054          $this->setSubject($emailTemplate->getSubject());
00055          $this->setBody($emailTemplate->getBody() . $userSig);
00056          $this->enabled = $emailTemplate->getEnabled();
00057 
00058          if (Request::getUserVar('usePostedAddresses')) {
00059             $to = Request::getUserVar('to');
00060             if (is_array($to)) {
00061                $this->setRecipients($this->processAddresses ($this->getRecipients(), $to));
00062             }
00063             $cc = Request::getUserVar('cc');
00064             if (is_array($cc)) {
00065                $this->setCcs($this->processAddresses ($this->getCcs(), $cc));
00066             }
00067             $bcc = Request::getUserVar('bcc');
00068             if (is_array($bcc)) {
00069                $this->setBccs($this->processAddresses ($this->getBccs(), $bcc));
00070             }
00071          }
00072       } else {
00073          $this->setSubject(Request::getUserVar('subject'));
00074          $body = Request::getUserVar('body');
00075          if (empty($body)) $this->setBody($userSig);
00076          else $this->setBody($body);
00077          $this->skip = (($tmp = Request::getUserVar('send')) && is_array($tmp) && isset($tmp['skip']));
00078          $this->enabled = true;
00079 
00080          if (is_array($toEmails = Request::getUserVar('to'))) {
00081             $this->setRecipients($this->processAddresses ($this->getRecipients(), $toEmails));
00082          }
00083          if (is_array($ccEmails = Request::getUserVar('cc'))) {
00084             $this->setCcs($this->processAddresses ($this->getCcs(), $ccEmails));
00085          }
00086          if (is_array($bccEmails = Request::getUserVar('bcc'))) {
00087             $this->setBccs($this->processAddresses ($this->getBccs(), $bccEmails));
00088          }
00089       }
00090 
00091       // Default "From" to user if available, otherwise site/press principal contact
00092       $user =& Request::getUser();
00093       if ($user) {
00094          $this->setFrom($user->getEmail(), $user->getFullName());
00095       } elseif ($press == null) {
00096          $site =& Request::getSite();
00097          $this->setFrom($site->getLocalizedContactEmail(), $site->getLocalizedContactName());
00098 
00099       } else {
00100          $this->setFrom($press->getSetting('contactEmail'), $press->getSetting('contactName'));
00101       }
00102 
00103       if ($press && !Request::getUserVar('continued')) {
00104          $this->setSubject('[' . $press->getLocalizedSetting('initials') . '] ' . $this->getSubject());
00105       }
00106 
00107       $this->press =& $press;
00108    }
00109 
00115    function assignParams($paramArray = array()) {
00116       // Add commonly-used variables to the list
00117       if (isset($this->press)) {
00118          // FIXME Include affiliation, title, etc. in signature?
00119          $paramArray['pressName'] = $this->press->getLocalizedName();
00120          $paramArray['principalContactSignature'] = $this->press->getSetting('contactName');
00121       } else {
00122          $site =& Request::getSite();
00123          $paramArray['principalContactSignature'] = $site->getLocalizedContactName();
00124       }
00125       if (!isset($paramArray['pressUrl'])) $paramArray['pressUrl'] = Request::url(Request::getRequestedPressPath());
00126 
00127       return parent::assignParams($paramArray);
00128    }
00129 
00136    function displayEditForm($formActionUrl, $hiddenFormParams = null, $alternateTemplate = null, $additionalParameters = array()) {
00137       $templateMgr =& TemplateManager::getManager();
00138       $templateMgr->assign('helpTopicId', 'press.managementPages.emails');
00139 
00140       parent::displayEditForm($formActionUrl, $hiddenFormParams, $alternateTemplate, $additionalParameters);
00141    }
00142 
00149    function send($clearAttachments = true) {
00150       if (isset($this->press)) {
00151          //If {$templateSignature} exists in the body of the
00152          // message, replace it with the press signature;
00153          // otherwise just append it. This is here to
00154          // accomodate MIME-encoded messages or other cases
00155          // where the signature cannot just be appended.
00156 
00157          // Include the signature if wanted, otherwise replace the variable with an empty string.
00158          $signature = $this->includeSignature ? $this->press->getSetting('emailSignature') : '';
00159          $searchString = '{$templateSignature}';
00160          if (strstr($this->getBody(), $searchString) === false) {
00161             $this->setBody($this->getBody() . "\n" . $signature);
00162          } else {
00163             $this->setBody(str_replace($searchString, $signature, $this->getBody()));
00164          }
00165 
00166          $envelopeSender = $this->press->getSetting('envelopeSender');
00167          if (!empty($envelopeSender) && Config::getVar('email', 'allow_envelope_sender')) $this->setEnvelopeSender($envelopeSender);
00168       }
00169 
00170       return parent::send($clearAttachments);
00171    }
00172 }
00173 
00174 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1