public function replaceLinks($mailText, Kwc_Mail_Recipient_Interface $recipient = null) { if ($recipient) { if ($recipient instanceof Zend_Db_Table_Row_Abstract) { $class = get_class($recipient->getTable()); $recipientPrimary = $recipient->getTable()->info(Zend_Db_Table_Abstract::PRIMARY); $recipientPrimary = $recipientPrimary[1]; } else { if ($recipient instanceof Kwf_Model_Row_Abstract) { $class = get_class($recipient->getModel()); $recipientPrimary = $recipient->getModel()->getPrimaryKey(); } else { throw new Kwf_Exception('Only models or tables are supported.'); } } $recipientSource = $this->getRecipientModelShortcut($class); $m = $this->getChildModel(); } while (preg_match('/\\*([a-zA-Z_]+?)\\*(.+?)(\\*\\*(.+?))?\\*/', $mailText, $matches)) { if (!$recipient) { $mailText = str_replace($matches[0], $matches[2], $mailText); } else { $href = htmlspecialchars_decode($matches[2]); $title = ''; if (isset($matches[4])) { $title = urldecode(htmlspecialchars_decode($matches[4])); } if (!isset($this->_redirectRowsCache[$href . $title])) { $select = $m->select(); $select->whereEquals('value', $href); $select->whereEquals('title', $title); $r = $m->getRow($select); if (!$r) { $r = $m->createRow(array('value' => $href, 'type' => $matches[1], 'title' => $title)); $r->save(); } $this->_redirectRowsCache[$href . $title] = $r; } $r = $this->_redirectRowsCache[$href . $title]; // $recipientSource muss immer dabei sein, auch wenn es nur ein // model gibt. Würde später eines dazukommen, funktionierten die alten // Links nicht mehr // linkId_userId_userSource_hash $newLink = $this->_getRedirectUrl(array($r->id, $recipient->{$recipientPrimary}, $recipientSource)); $mailText = str_replace($matches[0], $newLink, $mailText); } } return $mailText; }
public function createMail(Kwc_Mail_Recipient_Interface $recipient, $data = null, $toAddress = null, $format = null, $addViewTracker = true) { $this->_mailData = $data; $mail = new Kwf_Mail(); $name = $recipient->getMailFirstname() . ' ' . $recipient->getMailLastname(); if (!$recipient->getMailFirstname() || !$recipient->getMailLastname()) { //no name at all if we don't have a complete name $name = null; } if ($toAddress) { $mail->addTo($toAddress, $name); } else { $mail->addTo($recipient->getMailEmail(), $name); } if (!$format && $recipient->getMailFormat() == Kwc_Mail_Recipient_Interface::MAIL_FORMAT_HTML || $format == Kwc_Mail_Recipient_Interface::MAIL_FORMAT_HTML) { $html = $this->getHtml($recipient, $addViewTracker); $mail->setDomain($this->getData()->getDomain()); $mail->setAttachImages($this->_getSetting('attachImages')); $mail->setBodyHtml($html); } $mail->setBodyText($this->getText($recipient)); $mail->setSubject($this->getSubject($recipient)); if ($this->_getSetting('fromEmail')) { $mail->setFrom($this->_getSetting('fromEmail'), $this->_getSetting('fromName')); } if ($this->_getSetting('replyEmail')) { $mail->setReplyTo($this->_getSetting('replyEmail')); } if ($this->_getSetting('returnPath')) { $mail->setReturnPath($this->_getSetting('returnPath')); } $bccs = $this->_getSetting('bcc'); if ($bccs) { if (!is_array($bccs)) { $bccs = array($bccs); } foreach ($bccs as $bcc) { $mail->addBcc($bcc); } } return $mail; }
public static function getPlaceholders(Kwc_Mail_Recipient_Interface $recipient, $language) { $ret = array(); $trl = Kwf_Trl::getInstance(); $ret['firstname'] = $recipient->getMailFirstname(); $ret['lastname'] = $recipient->getMailLastname(); if ($recipient instanceof Kwc_Mail_Recipient_TitleInterface) { $replace = array($recipient->getMailTitle(), $recipient->getMailLastname()); $politeM = $trl->trlKwf('Dear Mr. {0} {1}', $replace, $language); $politeF = $trl->trlKwf('Dear Mrs. {0} {1}', $replace, $language); if ($recipient->getMailGender() == 'male' && $recipient->getMailLastname()) { $t = $trl->trlKwf('Dear Mr. {0} {1}', $replace, $language); } else { if ($recipient->getMailGender() == 'female' && $recipient->getMailLastname()) { $t = $trl->trlKwf('Dear Mrs. {0} {1}', $replace, $language); } else { $t = $trl->trlKwf('Dear Mrs./Mr. {0} {1}', $replace, $language); } } $ret['salutation_polite'] = trim(str_replace(' ', ' ', $t)); if ($recipient->getMailGender() == 'male') { $t = $trl->trlKwf('Mr. {0}', $recipient->getMailTitle(), $language); } else { if ($recipient->getMailGender() == 'female') { $t = $trl->trlKwf('Mrs. {0}', $recipient->getMailTitle(), $language); } else { $t = $recipient->getMailTitle(); } } $ret['salutation_title'] = trim(str_replace(' ', ' ', $t)); $ret['title'] = $recipient->getMailTitle(); } if ($recipient instanceof Kwc_Mail_Recipient_GenderInterface) { $replace = array($recipient->getMailLastname()); if ($recipient->getMailGender() == 'male') { $ret['salutation_polite_notitle'] = $trl->trlKwf('Dear Mr. {0}', $replace, $language); $ret['salutation_hello'] = $trl->trlKwf('Hello Mr. {0}', $replace, $language); $ret['salutation'] = $trl->trlKwf('Mr.', array(), $language); $ret['salutation_firstname'] = $trl->trlcKwf('salutation firstname male', 'Dear {0}', array($recipient->getMailFirstname()), $language); } else { if ($recipient->getMailGender() == 'female') { $ret['salutation_polite_notitle'] = $trl->trlKwf('Dear Mrs. {0}', $replace, $language); $ret['salutation_hello'] = $trl->trlKwf('Hello Mrs. {0}', $replace, $language); $ret['salutation'] = $trl->trlKwf('Mrs.', array(), $language); $ret['salutation_firstname'] = $trl->trlcKwf('salutation firstname female', 'Dear {0}', array($recipient->getMailFirstname()), $language); } else { $replace = array($recipient->getMailFirstname(), $recipient->getMailLastname()); if ($recipient->getMailFirstname() && $recipient->getMailLastname()) { $ret['salutation_polite_notitle'] = trim($trl->trlKwf('Dear {0} {1}', $replace, $language)); } else { $ret['salutation_polite_notitle'] = $trl->trlKwf('Dear Sir or Madam', array(), $language); } $ret['salutation_hello'] = trim($trl->trlKwf('Hello {0} {1}', $replace, $language)); $ret['salutation_firstname'] = $trl->trlcKwf('salutation firstname unknown gender', 'Dear {0}', array($recipient->getMailFirstname()), $language); } } } return $ret; }