Development

/branches/1.1/lib/plugins/sfCompat10Plugin/lib/view/sfMailView.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/plugins/sfCompat10Plugin/lib/view/sfMailView.class.php

Revision 10270, 3.5 kB (checked in by Carl.Vondrick, 6 years ago)

1.1: added deprecated warnings to all sfCompatPlugin classes (closes #3882)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  *
13  * WARNING: This class is deprecated and will be removed in symfony 1.2.
14  *
15  * @package    symfony
16  * @subpackage view
17  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
18  * @version    SVN: $Id$
19  * @deprecated Deprecated since symfony 1.1
20  */
21 class sfMailView extends sfPHPView
22 {
23   /**
24    * Retrieves the template engine associated with this view.
25    *
26    * @return string sfMail
27    */
28   public function getEngine()
29   {
30     return 'sfMail';
31   }
32
33   /**
34    * Configures template for this view.
35    *
36    * @throws <b>sfActionException</b> If the configure fails
37    */
38   public function configure()
39   {
40     // view.yml configure
41     parent::configure();
42
43     // require our configuration
44     $moduleName = $this->moduleName;
45     require($this->context->getConfigCache()->checkConfig('modules/'.$this->moduleName.'/config/mailer.yml'));
46   }
47
48   /**
49    * Renders the presentation and send the email to the client.
50    *
51    * @return mixed Raw data of the mail
52    */
53   public function render()
54   {
55     $retval = null;
56
57     // execute pre-render check
58     $this->preRenderCheck();
59
60     // get sfMail object from action
61     $mail = $this->attributeHolder->get('mail');
62     if (!$mail)
63     {
64       throw new sfActionException('You must define a sfMail object named $mail ($this->mail) in your action to be able to use a sfMailView.');
65     }
66
67     // render main template
68     $template = $this->getDirectory().'/'.$this->getTemplate();
69     $retval = $this->renderFile($template);
70
71     // render main and alternate templates
72     $all_template_dir  = dirname($template);
73     $all_template_regex = preg_replace('/\\.php$/', '\..+\.php', basename($template));
74     $all_templates = sfFinder::type('file')->name('/^'.$all_template_regex.'$/')->in($all_template_dir);
75     $all_retvals = array();
76     foreach ($all_templates as $templateFile)
77     {
78       if (preg_match('/\.([^.]+?)\.php$/', $templateFile, $matches))
79       {
80         $all_retvals[$matches[1]] = $this->renderFile($templateFile);
81       }
82     }
83
84     // send email
85     if (sfConfig::get('sf_logging_enabled'))
86     {
87       $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Send email to client')));
88     }
89
90     // configuration prefix
91     $config_prefix = 'sf_mailer_'.strtolower($this->moduleName).'_';
92
93     $vars = array(
94       'mailer',
95       'priority', 'content_type', 'charset', 'encoding', 'wordwrap',
96       'hostname', 'port', 'domain', 'username', 'password'
97     );
98     $defaultMail = new sfMail();
99
100     foreach ($vars as $var)
101     {
102       $setter = 'set'.sfInflector::camelize($var);
103       $getter = 'get'.sfInflector::camelize($var);
104       $value  = $mail->$getter() !== $defaultMail->$getter() ? $mail->$getter() : sfConfig::get($config_prefix.strtolower($var));
105       $mail->$setter($value);
106     }
107
108     $mail->setBody($retval);
109
110     // alternate bodies
111     $i = 0;
112     foreach ($all_retvals as $type => $retval)
113     {
114       if ($type == 'altbody' && !$mail->getAltBody())
115       {
116         $mail->setAltBody($retval);
117       }
118       else
119       {
120         ++$i;
121         $mail->addStringAttachment($retval, 'file'.$i, 'base64', 'text/'.$type);
122       }
123     }
124
125     // preparing email to be sent
126     $mail->prepare();
127
128     // send e-mail
129     if (sfConfig::get($config_prefix.'deliver'))
130     {
131       $mail->send();
132     }
133
134     return $mail->getRawHeader().$mail->getRawBody();
135   }
136 }
137
Note: See TracBrowser for help on using the browser.