Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 127 lines (110 sloc) 3.194 kb
a577d36 Removed legacy action helper and resource helper code.
Robert Goldsmith authored
1 <?php
2 /**
3 * Ztal Mail.
4 *
5 * @category Namesco
6 * @package Ztal_Form
7 * @author Robert Goldsmith <rgoldsmith@names.co.uk>
8 * @copyright 2009-2010 Namesco Limited
9 * @license http://names.co.uk/license Namesco
10 */
11
12 /**
13 * Ztal Mail.
14 *
15 * Provides template support for emails.
16 *
17 * @category Namesco
18 * @package Ztal_Mail
19 * @author Robert Goldsmith <rgoldsmith@names.co.uk>
20 */
21 class Ztal_Mail extends Zend_Mail
22 {
23 /**
24 * The view object used to render the email content.
25 *
26 * @var Ztal_Tal_View
27 */
28 public $view = null;
29
30
31 /**
32 * Generate a macro launch stub to render the correct user template.
33 *
34 * Emails can have plain and html parts and these are held in a single
35 * template file by making them macros with names of 'plain' and 'html'.
36 * In order to render the correct macro, this src string is used.
37 *
38 * @return array
39 */
40 protected function _template()
41 {
42 $src = '<tal:block
43 xmlns="http://www.w3.org/1999/xhtml"
44 xmlns:tal="http://xml.zope.org/namespaces/tal"
45 xmlns:metal="http://xml.zope.org/namespaces/metal"
46 xmlns:i18n="http://xml.zope.org/namespaces/i18n"
47 xmlns:phptal="http://phptal.org/ns/phptal"
48 >
49 <tal:block metal:use-macro="${ztalMailMacro}" />
50 </tal:block>';
51 return array('src' => $src, 'name' => __FILE__);
52 }
53
54
55 /**
56 * Calculate the path for the email template.
57 *
58 * @param string $template The template name.
59 *
60 * @return string
61 */
62 protected function _calculateTemplatePath($template)
63 {
1e9408b Refactored array tales out into a new tale class.
Robert Goldsmith authored
64 return '../emails/' . $template . '.email';
a577d36 Removed legacy action helper and resource helper code.
Robert Goldsmith authored
65 }
66
67
68 /**
69 * Constructor.
70 *
71 * @param string $charset The charset to set for the email content.
72 */
73 public function __construct($charset = 'iso-8859-1')
74 {
75 if (!Zend_Registry::isRegistered('Ztal_View')) {
76 throw new Exception('No available Ztal View');
77 }
78
79 $this->view = clone Zend_Registry::get('Ztal_View');
80 $this->view->layout()->disableLayout();
457a667 Added whitespace compression to emails.
Robert Goldsmith authored
81 $this->view->setCompressWhitespace(true);
82
a577d36 Removed legacy action helper and resource helper code.
Robert Goldsmith authored
83
84 parent::__construct($charset);
85 }
86
87
88 /**
89 * Set the plaintext body of the email to the output from the named template.
90 *
91 * @param string $template The name of the template.
92 * @param string $charset The charset to use for the content.
93 * @param int $encoding The encoding to use for the content.
94 *
95 * @return Ztal_Mail
96 */
97 public function setBodyTextFromTemplate($template, $charset = null,
98 $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE
99 ) {
100 $this->view->ztalMailMacro = $this->_calculateTemplatePath($template)
101 . '/plain';
102
103 return $this->setBodyText($this->view->render(
104 $this->_template()), $charset, $encoding);
105 }
106
107
108 /**
109 * Set the html body of the email to the output from the named template.
110 *
111 * @param string $template The name of the template.
112 * @param string $charset The charset to use for the content.
113 * @param int $encoding The encoding to use for the content.
114 *
115 * @return Ztal_Mail
116 */
117 public function setBodyHtmlFromTemplate($template, $charset = null,
118 $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE
119 ) {
120 $this->view->ztalMailMacro = $this->_calculateTemplatePath($template)
121 . '/html';
122
123 return $this->setBodyHtml($this->view->render(
124 $this->_template()), $charset, $encoding);
125 }
126
127 }
Something went wrong with that request. Please try again.