Public Member Functions | |
getResource () | |
getMail () | |
setTemplateFilter (Varien_Filter_Template $filter) | |
getTemplateFilter () | |
load ($templateId) | |
loadByCode ($templateCode) | |
loadDefault ($templateId, $locale=null) | |
getId () | |
setId ($value) | |
isValidForSend () | |
isPlain () | |
save () | |
getProcessedTemplate (array $variables=array()) | |
getInclude ($template, array $variables) | |
send ($email, $name=null, array $variables=array()) | |
sendTransactional ($templateId, $sender, $email, $name, $vars=array(), $storeId=null) | |
delete () | |
getProcessedTemplateSubject (array $variables) | |
setDesignConfig (array $config) | |
getDesignConfig () | |
addBcc ($bcc) | |
setReturnPath ($email) | |
setReplyTo ($email) | |
Static Public Member Functions | |
static | getDefaultTemplates () |
static | getDefaultTemplatesAsOptionsArray () |
Public Attributes | |
const | TYPE_TEXT = 1 |
const | TYPE_HTML = 2 |
const | XML_PATH_TEMPLATE_EMAIL = 'global/template/email' |
Protected Member Functions | |
_applyDesignConfig () | |
_cancelDesignConfig () | |
Protected Attributes | |
$_templateFilter | |
$_preprocessFlag = false | |
$_mail | |
$_designConfig | |
Static Protected Attributes | |
static | $_defaultTemplates |
Definition at line 45 of file Template.php.
_applyDesignConfig | ( | ) | [protected] |
Apply declared configuration for design
Definition at line 477 of file Template.php.
00478 { 00479 if ($this->getDesignConfig()) { 00480 $design = Mage::getDesign(); 00481 $this->getDesignConfig() 00482 ->setOldArea($design->getArea()) 00483 ->setOldStore($design->getStore()); 00484 00485 if ($this->getDesignConfig()->getArea()) { 00486 Mage::getDesign()->setArea($this->getDesignConfig()->getArea()); 00487 } 00488 00489 if ($this->getDesignConfig()->getStore()) { 00490 Mage::app()->getLocale()->emulate($this->getDesignConfig()->getStore()); 00491 $design->setStore($this->getDesignConfig()->getStore()); 00492 $design->setTheme(''); 00493 $design->setPackageName(''); 00494 } 00495 00496 } 00497 return $this; 00498 }
_cancelDesignConfig | ( | ) | [protected] |
Revert design settings to previous
Definition at line 505 of file Template.php.
00506 { 00507 if ($this->getDesignConfig()) { 00508 if ($this->getDesignConfig()->getOldArea()) { 00509 Mage::getDesign()->setArea($this->getDesignConfig()->getOldArea()); 00510 } 00511 00512 if ($this->getDesignConfig()->getOldStore()) { 00513 Mage::getDesign()->setStore($this->getDesignConfig()->getOldStore()); 00514 Mage::getDesign()->setTheme(''); 00515 Mage::getDesign()->setPackageName(''); 00516 } 00517 } 00518 Mage::app()->getLocale()->revert(); 00519 return $this; 00520 }
addBcc | ( | $ | bcc | ) |
Definition at line 522 of file Template.php.
00523 { 00524 if (is_array($bcc)) { 00525 foreach ($bcc as $email) { 00526 $this->getMail()->addBcc($email); 00527 } 00528 } 00529 elseif ($bcc) { 00530 $this->getMail()->addBcc($bcc); 00531 } 00532 return $this; 00533 }
delete | ( | ) |
Delete template from DB
Definition at line 412 of file Template.php.
00413 { 00414 $this->getResource()->delete($this->getId()); 00415 $this->setId(null); 00416 return $this; 00417 }
static getDefaultTemplates | ( | ) | [static] |
Retrive default templates from config
Definition at line 186 of file Template.php.
00187 { 00188 if(is_null(self::$_defaultTemplates)) { 00189 self::$_defaultTemplates = Mage::getConfig()->getNode(self::XML_PATH_TEMPLATE_EMAIL)->asArray(); 00190 } 00191 00192 return self::$_defaultTemplates; 00193 }
static getDefaultTemplatesAsOptionsArray | ( | ) | [static] |
Retrive default templates as options array
Definition at line 200 of file Template.php.
00201 { 00202 $options = array( 00203 array('value'=>'', 'label'=> '') 00204 ); 00205 00206 foreach (self::getDefaultTemplates() as $templateId=>$value) { 00207 $options[] = array('value'=>$templateId, 'label'=>$value['label']); 00208 } 00209 00210 return $options; 00211 }
getDesignConfig | ( | ) |
Get design configuration data
Definition at line 464 of file Template.php.
00465 { 00466 if(is_null($this->_designConfig)) { 00467 $this->_designConfig = new Varien_Object(); 00468 } 00469 return $this->_designConfig; 00470 }
getId | ( | ) |
Return template id return int|null
Reimplemented from Varien_Object.
Definition at line 217 of file Template.php.
getInclude | ( | $ | template, | |
array $ | variables | |||
) |
Get template code for include directive
string | $template | |
array | $variables |
Reimplemented in Mage_Sales_Model_Email_Template.
Definition at line 300 of file Template.php.
00301 { 00302 $thisClass = __CLASS__; 00303 $includeTemplate = new $thisClass(); 00304 00305 $includeTemplate->loadByCode($template); 00306 00307 return $includeTemplate->getProcessedTemplate($variables); 00308 }
getMail | ( | ) |
Retrieve mail object instance
Definition at line 87 of file Template.php.
00088 { 00089 if (is_null($this->_mail)) { 00090 $this->_mail = new Zend_Mail('utf-8'); 00091 } 00092 return $this->_mail; 00093 }
Process email template code
array | $variables |
Definition at line 269 of file Template.php.
00270 { 00271 $processor = $this->getTemplateFilter(); 00272 $processor->setUseSessionInUrl(false); 00273 00274 if(!$this->_preprocessFlag) { 00275 $variables['this'] = $this; 00276 } 00277 00278 $processor->setIncludeProcessor(array($this, 'getInclude')) 00279 ->setVariables($variables); 00280 00281 $this->_applyDesignConfig(); 00282 try{ 00283 $processedResult = $processor->filter($this->getTemplateText()); 00284 } 00285 catch ( Exception $e) { 00286 $this->_cancelDesignConfig(); 00287 throw $e; 00288 } 00289 $this->_cancelDesignConfig(); 00290 return $processedResult; 00291 }
getProcessedTemplateSubject | ( | array $ | variables | ) |
Process email subject
array | $variables |
Definition at line 425 of file Template.php.
00426 { 00427 $processor = $this->getTemplateFilter(); 00428 00429 if(!$this->_preprocessFlag) { 00430 $variables['this'] = $this; 00431 } 00432 00433 $processor->setVariables($variables); 00434 00435 $this->_applyDesignConfig(); 00436 try{ 00437 $processedResult = $processor->filter($this->getTemplateSubject()); 00438 } 00439 catch ( Exception $e) { 00440 $this->_cancelDesignConfig(); 00441 throw $e; 00442 } 00443 $this->_cancelDesignConfig(); 00444 return $processedResult; 00445 }
getResource | ( | ) |
Return resource of template model.
Definition at line 77 of file Template.php.
00078 { 00079 return Mage::getResourceSingleton('core/email_template'); 00080 }
getTemplateFilter | ( | ) |
Get filter object for template processing logi
Definition at line 112 of file Template.php.
00113 { 00114 if (empty($this->_templateFilter)) { 00115 $this->_templateFilter = Mage::getModel('core/email_template_filter'); 00116 $this->_templateFilter->setUseAbsoluteLinks($this->getUseAbsoluteLinks()); 00117 } 00118 return $this->_templateFilter; 00119 }
isPlain | ( | ) |
isValidForSend | ( | ) |
Return true if this template can be used for sending queue as main template
Definition at line 236 of file Template.php.
00237 { 00238 return !Mage::getStoreConfigFlag('system/smtp/disable') 00239 && $this->getSenderName() 00240 && $this->getSenderEmail() 00241 && $this->getTemplateSubject(); 00242 }
load | ( | $ | templateId | ) |
Load template by id
int | $templateId return Mage_Newsletter_Model_Template |
Definition at line 127 of file Template.php.
00128 { 00129 $this->addData($this->getResource()->load($templateId)); 00130 return $this; 00131 }
loadByCode | ( | $ | templateCode | ) |
Load template by code
string | $templateCode return Mage_Newsletter_Model_Template |
Definition at line 139 of file Template.php.
00140 { 00141 $this->addData($this->getResource()->loadByCode($templateCode)); 00142 return $this; 00143 }
loadDefault | ( | $ | templateId, | |
$ | locale = null | |||
) |
Load default email template from locale translate
string | $templateId | |
string | $locale |
Remove comment lines
Definition at line 151 of file Template.php.
00152 { 00153 $defaultTemplates = self::getDefaultTemplates(); 00154 if (!isset($defaultTemplates[$templateId])) { 00155 return $this; 00156 } 00157 00158 $data = &$defaultTemplates[$templateId]; 00159 $this->setTemplateType($data['type']=='html' ? self::TYPE_HTML : self::TYPE_TEXT); 00160 00161 $templateText = Mage::app()->getTranslator()->getTemplateFile( 00162 $data['file'], 'email', $locale 00163 ); 00164 00165 if (preg_match('/<!--@subject\s*(.*?)\s*@-->/', $templateText, $matches)) { 00166 $this->setTemplateSubject($matches[1]); 00167 $templateText = str_replace($matches[0], '', $templateText); 00168 } 00169 00170 /** 00171 * Remove comment lines 00172 */ 00173 $templateText = preg_replace('#\{\*.*\*\}#suU', '', $templateText); 00174 00175 $this->setTemplateText($templateText); 00176 $this->setId($templateId); 00177 00178 return $this; 00179 }
save | ( | ) |
Save template
Definition at line 257 of file Template.php.
00258 { 00259 $this->getResource()->save($this); 00260 return $this; 00261 }
Send mail to recipient
string | $email E-mail | |
string|null | $name receiver name | |
array | $variables template variables |
Definition at line 318 of file Template.php.
00319 { 00320 if(!$this->isValidForSend()) { 00321 return false; 00322 } 00323 00324 if (is_null($name)) { 00325 $name = substr($email, 0, strpos($email, '@')); 00326 } 00327 00328 $variables['email'] = $email; 00329 $variables['name'] = $name; 00330 00331 ini_set('SMTP', Mage::getStoreConfig('system/smtp/host')); 00332 ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port')); 00333 00334 $mail = $this->getMail(); 00335 if (is_array($email)) { 00336 foreach ($email as $emailOne) { 00337 $mail->addTo($emailOne, $name); 00338 } 00339 } else { 00340 $mail->addTo($email, '=?utf-8?B?'.base64_encode($name).'?='); 00341 } 00342 00343 $this->setUseAbsoluteLinks(true); 00344 $text = $this->getProcessedTemplate($variables, true); 00345 00346 if($this->isPlain()) { 00347 $mail->setBodyText($text); 00348 } else { 00349 $mail->setBodyHTML($text); 00350 } 00351 00352 00353 00354 $mail->setSubject('=?utf-8?B?'.base64_encode($this->getProcessedTemplateSubject($variables)).'?='); 00355 $mail->setFrom($this->getSenderEmail(), $this->getSenderName()); 00356 00357 try { 00358 $mail->send(); // Zend_Mail warning.. 00359 $this->_mail = null; 00360 } 00361 catch (Exception $e) { 00362 return false; 00363 } 00364 00365 return true; 00366 }
sendTransactional | ( | $ | templateId, | |
$ | sender, | |||
$ | email, | |||
$ | name, | |||
$ | vars = array() , |
|||
$ | storeId = null | |||
) |
Send transactional email to recipient
int | $templateId | |
string|array | $sender sneder informatio, can be declared as part of config path | |
string | $email recipient email | |
string | $name recipient name | |
array | $vars varianles which can be used in template | |
int|null | $storeId |
Definition at line 379 of file Template.php.
00380 { 00381 $this->setSentSuccess(false); 00382 if (($storeId === null) && $this->getDesignConfig()->getStore()) { 00383 $storeId = $this->getDesignConfig()->getStore(); 00384 } 00385 00386 if (is_numeric($templateId)) { 00387 $this->load($templateId); 00388 } else { 00389 $localeCode = Mage::getStoreConfig('general/locale/code', $storeId); 00390 $this->loadDefault($templateId, $localeCode); 00391 } 00392 00393 if (!$this->getId()) { 00394 throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid transactional email code: '.$templateId)); 00395 } 00396 00397 if (!is_array($sender)) { 00398 $this->setSenderName(Mage::getStoreConfig('trans_email/ident_'.$sender.'/name', $storeId)); 00399 $this->setSenderEmail(Mage::getStoreConfig('trans_email/ident_'.$sender.'/email', $storeId)); 00400 } else { 00401 $this->setSenderName($sender['name']); 00402 $this->setSenderEmail($sender['email']); 00403 } 00404 00405 $this->setSentSuccess($this->send($email, $name, $vars)); 00406 return $this; 00407 }
setDesignConfig | ( | array $ | config | ) |
Initialize design information for email template and subject processing
array | $config |
Definition at line 453 of file Template.php.
00454 { 00455 $this->getDesignConfig()->setData($config); 00456 return $this; 00457 }
setId | ( | $ | value | ) |
Set id of template
int | $value |
Reimplemented from Varien_Object.
Definition at line 226 of file Template.php.
setReplyTo | ( | $ | ) |
Add Reply-To header
string |
Definition at line 553 of file Template.php.
00554 { 00555 $this->getMail()->addHeader('Reply-To', $email); 00556 return $this; 00557 }
setReturnPath | ( | $ | ) |
Set Return Path
string |
Definition at line 541 of file Template.php.
00542 { 00543 $this->getMail()->setReturnPath($email); 00544 return $this; 00545 }
setTemplateFilter | ( | Varien_Filter_Template $ | filter | ) |
Declare template processing filter
Varien_Filter_Template | $filter |
Definition at line 101 of file Template.php.
$_defaultTemplates [static, protected] |
Definition at line 63 of file Template.php.
$_designConfig [protected] |
Definition at line 70 of file Template.php.
$_mail [protected] |
Definition at line 61 of file Template.php.
$_preprocessFlag = false [protected] |
Definition at line 60 of file Template.php.
$_templateFilter [protected] |
Definition at line 59 of file Template.php.
const TYPE_HTML = 2 |
Definition at line 51 of file Template.php.
const TYPE_TEXT = 1 |
Types of template
Definition at line 50 of file Template.php.
const XML_PATH_TEMPLATE_EMAIL = 'global/template/email' |
Configuration path for default email templates
Definition at line 57 of file Template.php.