Index: branches/5.2.x/core/kernel/utility/email.php =================================================================== diff -u -N -r15552 -r15608 --- branches/5.2.x/core/kernel/utility/email.php (.../email.php) (revision 15552) +++ branches/5.2.x/core/kernel/utility/email.php (.../email.php) (revision 15608) @@ -1,6 +1,6 @@ Array (), - EmailEvent::RECIPIENT_TYPE_CC => Array (), - EmailEvent::RECIPIENT_TYPE_BCC => Array (), + EmailTemplate::RECIPIENT_TYPE_TO => Array (), + EmailTemplate::RECIPIENT_TYPE_CC => Array (), + EmailTemplate::RECIPIENT_TYPE_BCC => Array (), ); /** @@ -113,79 +113,79 @@ $this->Application->removeObject('u.email-from'); $this->recipients = Array ( - EmailEvent::RECIPIENT_TYPE_TO => Array (), - EmailEvent::RECIPIENT_TYPE_CC => Array (), - EmailEvent::RECIPIENT_TYPE_BCC => Array (), + EmailTemplate::RECIPIENT_TYPE_TO => Array (), + EmailTemplate::RECIPIENT_TYPE_CC => Array (), + EmailTemplate::RECIPIENT_TYPE_BCC => Array (), ); $this->toEmail = $this->toEmail = ''; $this->Application->removeObject('u.email-to'); } /** - * Finds e-mail event matching user data + * Finds e-mail template matching user data * * @param string $name * @param int $type * @return bool * @throws InvalidArgumentException * @access public */ - public function findEvent($name, $type) + public function findTemplate($name, $type) { if ( !$name || !preg_match('/^[A-Z\.]+$/', $name) ) { - throw new InvalidArgumentException('Invalid e-mail event name "' . $name . '". Only UPPERCASE characters and dots are allowed.'); + throw new InvalidArgumentException('Invalid e-mail template name "' . $name . '". Only UPPERCASE characters and dots are allowed.'); } - if ( $type != EmailEvent::EVENT_TYPE_ADMIN && $type != EmailEvent::EVENT_TYPE_FRONTEND ) { - throw new InvalidArgumentException('Invalid e-mail event type'); + if ( $type != EmailTemplate::TEMPLATE_TYPE_ADMIN && $type != EmailTemplate::TEMPLATE_TYPE_FRONTEND ) { + throw new InvalidArgumentException('Invalid e-mail template type'); } - // use "-item" special prevent error, when e-mail sent out from e-mail events list - $this->emailEvent = $this->Application->recallObject('emailevents.-item', null, Array ('skip_autoload' => true)); + // use "-item" special prevent error, when e-mail sent out from e-mail templates list + $this->emailTemplate = $this->Application->recallObject('email-template.-item', null, Array ('skip_autoload' => true)); - if ( !$this->emailEvent->isLoaded() || !$this->_sameEvent($name, $type) ) { - // get event parameters by name & type - $this->emailEvent->Load(Array ('Event' => $name, 'Type' => $type)); + if ( !$this->emailTemplate->isLoaded() || !$this->_sameTemplate($name, $type) ) { + // get template parameters by name & type + $this->emailTemplate->Load(Array ('TemplateName' => $name, 'Type' => $type)); } - return $this->_eventUsable(); + return $this->_templateUsable(); } /** - * Detects, that given event data matches currently used event + * Detects, that given e-mail template data matches currently used e-mail template * * @param string $name * @param int $type * @return bool * @access protected */ - protected function _sameEvent($name, $type) + protected function _sameTemplate($name, $type) { - return $this->emailEvent->GetDBField('Event') == $name && $this->emailEvent->GetDBField('Type') == $type; + return $this->emailTemplate->GetDBField('TemplateName') == $name && $this->emailTemplate->GetDBField('Type') == $type; } /** - * Determines if we can use e-mail event we've found based on user data + * Determines if we can use e-mail template we've found based on user data * * @return bool * @access protected */ - protected function _eventUsable() + protected function _templateUsable() { - if ( !$this->emailEvent->isLoaded() || $this->emailEvent->GetDBField('Enabled') == STATUS_DISABLED ) { + if ( !$this->emailTemplate->isLoaded() || $this->emailTemplate->GetDBField('Enabled') == STATUS_DISABLED ) { return false; } - if ( $this->emailEvent->GetDBField('FrontEndOnly') && $this->Application->isAdmin ) { + if ( $this->emailTemplate->GetDBField('FrontEndOnly') && $this->Application->isAdmin ) { return false; } return true; } /** - * Sets e-mail event params + * Sets e-mail template params * * @param Array $params * @access public @@ -196,7 +196,7 @@ } /** - * Returns any custom parameters, that are passed when invoked e-mail event sending + * Returns any custom parameters, that are passed when invoked e-mail template sending * * @return Array * @access protected @@ -247,8 +247,8 @@ 'OtherRecipients' => serialize($this->recipients), 'Subject' => $message_subject, 'SentOn' => TIMENOW, - 'EventName' => $this->emailEvent->GetDBField('Event'), - 'EventType' => $this->emailEvent->GetDBField('Type'), + 'TemplateName' => $this->emailTemplate->GetDBField('TemplateName'), + 'EventType' => $this->emailTemplate->GetDBField('Type'), 'EventParams' => serialize($this->_getCustomParams()), ); @@ -324,7 +324,7 @@ */ protected function _processSender() { - if ( $this->emailEvent->GetDBField('CustomSender') ) { + if ( $this->emailTemplate->GetDBField('CustomSender') ) { $this->_processCustomSender(); } @@ -350,15 +350,15 @@ */ protected function _processCustomSender() { - $address = $this->emailEvent->GetDBField('SenderAddress'); - $address_type = $this->emailEvent->GetDBField('SenderAddressType'); + $address = $this->emailTemplate->GetDBField('SenderAddress'); + $address_type = $this->emailTemplate->GetDBField('SenderAddressType'); switch ($address_type) { - case EmailEvent::ADDRESS_TYPE_EMAIL: + case EmailTemplate::ADDRESS_TYPE_EMAIL: $this->fromEmail = $address; break; - case EmailEvent::ADDRESS_TYPE_USER: + case EmailTemplate::ADDRESS_TYPE_USER: $sql = 'SELECT FirstName, LastName, Email, PortalUserId FROM ' . TABLE_PREFIX . 'Users WHERE Username = ' . $this->Conn->qstr($address); @@ -377,8 +377,8 @@ break; } - if ( $this->emailEvent->GetDBField('SenderName') ) { - $this->fromName = $this->emailEvent->GetDBField('SenderName'); + if ( $this->emailTemplate->GetDBField('SenderName') ) { + $this->fromName = $this->emailTemplate->GetDBField('SenderName'); } } @@ -410,9 +410,9 @@ $this->_collectRecipients(); $header_mapping = Array ( - EmailEvent::RECIPIENT_TYPE_TO => 'To', - EmailEvent::RECIPIENT_TYPE_CC => 'Cc', - EmailEvent::RECIPIENT_TYPE_BCC => 'Bcc', + EmailTemplate::RECIPIENT_TYPE_TO => 'To', + EmailTemplate::RECIPIENT_TYPE_CC => 'Cc', + EmailTemplate::RECIPIENT_TYPE_BCC => 'Bcc', ); $default_email = $this->Application->ConfigValue('DefaultEmailSender'); @@ -424,7 +424,7 @@ continue; } - if ( $recipient_type == EmailEvent::RECIPIENT_TYPE_TO ) { + if ( $recipient_type == EmailTemplate::RECIPIENT_TYPE_TO ) { $this->toEmail = $recipients[0]['email'] ? $recipients[0]['email'] : $default_email; $this->toName = $recipients[0]['name'] ? $recipients[0]['name'] : $this->toEmail; } @@ -448,13 +448,13 @@ */ protected function _collectRecipients() { - $this->_addRecipientsFromXml($this->emailEvent->GetDBField('Recipients')); + $this->_addRecipientsFromXml($this->emailTemplate->GetDBField('Recipients')); $this->_overwriteToRecipient(); $this->_addRecipientByUserId(); $this->_addRecipientFromParams(); - if ( ($this->emailEvent->GetDBField('Type') == EmailEvent::EVENT_TYPE_ADMIN) && !$this->recipients[EmailEvent::RECIPIENT_TYPE_TO] ) { - // admin email event without direct recipient -> send to admin + if ( ($this->emailTemplate->GetDBField('Type') == EmailTemplate::TEMPLATE_TYPE_ADMIN) && !$this->recipients[EmailTemplate::RECIPIENT_TYPE_TO] ) { + // admin email template without direct recipient -> send to admin $this->_addDefaultRecipient(); } } @@ -495,8 +495,8 @@ { $overwrite_to_email = isset($this->params['overwrite_to_email']) ? $this->params['overwrite_to_email'] : false; - if ( !$this->emailEvent->GetDBField('CustomRecipient') || $overwrite_to_email ) { - $this->recipients[EmailEvent::RECIPIENT_TYPE_TO] = Array (); + if ( !$this->emailTemplate->GetDBField('CustomRecipient') || $overwrite_to_email ) { + $this->recipients[EmailTemplate::RECIPIENT_TYPE_TO] = Array (); } } @@ -519,7 +519,7 @@ return; } - $language_field = $this->emailEvent->GetDBField('Type') == EmailEvent::EVENT_TYPE_FRONTEND ? 'FrontLanguage' : 'AdminLanguage'; + $language_field = $this->emailTemplate->GetDBField('Type') == EmailTemplate::TEMPLATE_TYPE_FRONTEND ? 'FrontLanguage' : 'AdminLanguage'; $sql = 'SELECT FirstName, LastName, Email, ' . $language_field . ' AS Language FROM ' . TABLE_PREFIX . 'Users @@ -531,7 +531,7 @@ } $add_recipient = Array ( - 'RecipientAddressType' => EmailEvent::ADDRESS_TYPE_EMAIL, + 'RecipientAddressType' => EmailTemplate::ADDRESS_TYPE_EMAIL, 'RecipientAddress' => $user_info['Email'], 'RecipientName' => trim($user_info['FirstName'] . ' ' . $user_info['LastName']), ); @@ -540,7 +540,7 @@ $this->params['language_id'] = $user_info['Language']; } - array_unshift($this->recipients[EmailEvent::RECIPIENT_TYPE_TO], $add_recipient); + array_unshift($this->recipients[EmailTemplate::RECIPIENT_TYPE_TO], $add_recipient); $user = $this->Application->recallObject('u.email-to', null, Array('skip_autoload' => true)); /* @var $user UsersItem */ @@ -560,7 +560,7 @@ if ( isset($this->params['to_email']) && $this->params['to_email'] ) { $add_recipient['RecipientName'] = ''; - $add_recipient['RecipientAddressType'] = EmailEvent::ADDRESS_TYPE_EMAIL; + $add_recipient['RecipientAddressType'] = EmailTemplate::ADDRESS_TYPE_EMAIL; $add_recipient['RecipientAddress'] = $this->params['to_email']; } @@ -569,7 +569,7 @@ } if ( $add_recipient ) { - array_unshift($this->recipients[EmailEvent::RECIPIENT_TYPE_TO], $add_recipient); + array_unshift($this->recipients[EmailTemplate::RECIPIENT_TYPE_TO], $add_recipient); } } @@ -586,11 +586,11 @@ if ( !$this->_addRecipientsFromXml($xml) ) { $recipient = Array ( 'RecipientName' => $this->Application->ConfigValue('DefaultEmailSender'), - 'RecipientAddressType' => EmailEvent::ADDRESS_TYPE_EMAIL, + 'RecipientAddressType' => EmailTemplate::ADDRESS_TYPE_EMAIL, 'RecipientAddress' => $this->Application->ConfigValue('DefaultEmailSender'), ); - array_unshift($this->recipients[EmailEvent::RECIPIENT_TYPE_TO], $recipient); + array_unshift($this->recipients[EmailTemplate::RECIPIENT_TYPE_TO], $recipient); } } @@ -615,11 +615,11 @@ $recipient_name = $recipient['RecipientName']; switch ($address_type) { - case EmailEvent::ADDRESS_TYPE_EMAIL: + case EmailTemplate::ADDRESS_TYPE_EMAIL: $pairs[] = Array ('email' => $address, 'name' => $recipient_name); break; - case EmailEvent::ADDRESS_TYPE_USER: + case EmailTemplate::ADDRESS_TYPE_USER: $sql = 'SELECT FirstName, LastName, Email FROM ' . TABLE_PREFIX . 'Users WHERE Username = ' . $this->Conn->qstr($address); @@ -636,7 +636,7 @@ } break; - case EmailEvent::ADDRESS_TYPE_GROUP: + case EmailTemplate::ADDRESS_TYPE_GROUP: $sql = 'SELECT u.FirstName, u.LastName, u.Email FROM ' . TABLE_PREFIX . 'UserGroups g JOIN ' . TABLE_PREFIX . 'UserGroupRelations ug ON ug.GroupId = g.GroupId @@ -698,8 +698,8 @@ */ protected function _getHeaders() { - $headers = $this->emailEvent->GetDBField('Headers'); - $headers = 'Subject: ' . $this->emailEvent->GetField('Subject') . ($headers ? "\n" . $headers : ''); + $headers = $this->emailTemplate->GetDBField('Headers'); + $headers = 'Subject: ' . $this->emailTemplate->GetField('Subject') . ($headers ? "\n" . $headers : ''); $headers = explode("\n", $this->_parseText($headers)); $ret = Array (); @@ -710,9 +710,9 @@ } if ( $this->Application->isDebugMode() ) { - // set special header with event name, so it will be easier to determine what's actually was received - $event_type = $this->emailEvent->GetDBField('Type') == EmailEvent::EVENT_TYPE_ADMIN ? 'ADMIN' : 'USER'; - $ret['X-Event-Name'] = $this->emailEvent->GetDBField('Event') . ' - ' . $event_type; + // set special header with template name, so it will be easier to determine what's actually was received + $template_type = $this->emailTemplate->GetDBField('Type') == EmailTemplate::TEMPLATE_TYPE_ADMIN ? 'ADMIN' : 'USER'; + $ret['X-Template-Name'] = $this->emailTemplate->GetDBField('TemplateName') . ' - ' . $template_type; } return $ret; @@ -757,11 +757,11 @@ */ protected function _getMessageBody($is_html = false) { - $message_body = $this->emailEvent->GetField($is_html ? 'HtmlBody' : 'PlainTextBody'); + $message_body = $this->emailTemplate->GetField($is_html ? 'HtmlBody' : 'PlainTextBody'); if ( !trim($message_body) && !$is_html ) { // no plain text part available -> make it from html part then - $message_body = $this->sender->ConvertToText($this->emailEvent->GetField('HtmlBody'), true); + $message_body = $this->sender->ConvertToText($this->emailTemplate->GetField('HtmlBody'), true); } if ( !trim($message_body) ) { @@ -824,7 +824,7 @@ ' 'emailEvent->GetDBField('ReplacementTags'); + $replacement_tags = $this->emailTemplate->GetDBField('ReplacementTags'); $replacement_tags = $replacement_tags ? unserialize($replacement_tags) : Array (); $replacement_tags = array_merge($default_replacement_tags, $replacement_tags);