| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfWebDebugPanelMailer extends sfWebDebugPanel |
|---|
| 20 |
{ |
|---|
| 21 |
protected $mailer = null; |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
* Constructor. |
|---|
| 25 |
* |
|---|
| 26 |
* @param sfWebDebug $webDebug The web debug toolbar instance |
|---|
| 27 |
*/ |
|---|
| 28 |
public function __construct(sfWebDebug $webDebug) |
|---|
| 29 |
{ |
|---|
| 30 |
parent::__construct($webDebug); |
|---|
| 31 |
|
|---|
| 32 |
$this->webDebug->getEventDispatcher()->connect('mailer.configure', array($this, 'listenForMailerConfigure')); |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
public function getTitle() |
|---|
| 36 |
{ |
|---|
| 37 |
if ($this->mailer && ($logger = $this->mailer->getLogger()) && $logger->countMessages()) |
|---|
| 38 |
{ |
|---|
| 39 |
return '<img src="'.$this->webDebug->getOption('image_root_path').'/email.png" alt="Emailer" /> '.$logger->countMessages(); |
|---|
| 40 |
} |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
public function getPanelTitle() |
|---|
| 44 |
{ |
|---|
| 45 |
return 'Emails'; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
public function getPanelContent() |
|---|
| 49 |
{ |
|---|
| 50 |
$logger = $this->mailer->getLogger(); |
|---|
| 51 |
|
|---|
| 52 |
if (!$logger || !$messages = $logger->getMessages()) |
|---|
| 53 |
{ |
|---|
| 54 |
return false; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
$html = array(); |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
$strategy = $this->mailer->getDeliveryStrategy(); |
|---|
| 61 |
$html[] = '<h2>Configuration</h2>'; |
|---|
| 62 |
$html[] = '<em>Delivery strategy</em>: '.$strategy; |
|---|
| 63 |
|
|---|
| 64 |
if (sfMailer::SINGLE_ADDRESS == $strategy) |
|---|
| 65 |
{ |
|---|
| 66 |
$html[] = ' - <em>all emails are delivered to</em>: '.$this->mailer->getDeliveryAddress(); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
$html[] = '<h2>Email sent</h2>'; |
|---|
| 71 |
foreach ($messages as $message) |
|---|
| 72 |
{ |
|---|
| 73 |
$html[] = $this->renderMessageInformation($message); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
return implode("\n", $html); |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
protected function renderMessageInformation(Swift_Message $message) |
|---|
| 80 |
{ |
|---|
| 81 |
static $i = 0; |
|---|
| 82 |
|
|---|
| 83 |
$i++; |
|---|
| 84 |
|
|---|
| 85 |
$to = null === $message->getTo() ? '' : implode(', ', array_keys($message->getTo())); |
|---|
| 86 |
|
|---|
| 87 |
$html = array(); |
|---|
| 88 |
$html[] = sprintf('<h3>%s (to: %s) %s</h3>', $message->getSubject(), $to, $this->getToggler('sfWebDebugMailTemplate'.$i)); |
|---|
| 89 |
$html[] = '<div id="sfWebDebugMailTemplate'.$i.'" style="display:'.(1 == $i ? 'block' : 'none').'">'; |
|---|
| 90 |
$html[] = '<pre>'.htmlentities($message->toString(), ENT_QUOTES, $message->getCharset()).'</pre>'; |
|---|
| 91 |
$html[] = '</div>'; |
|---|
| 92 |
|
|---|
| 93 |
return implode("\n", $html); |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
* Listens for the mailer.configure event and captures a reference to the mailer. |
|---|
| 98 |
* |
|---|
| 99 |
* @param sfEvent $event |
|---|
| 100 |
*/ |
|---|
| 101 |
public function listenForMailerConfigure(sfEvent $event) |
|---|
| 102 |
{ |
|---|
| 103 |
$this->mailer = $event->getSubject(); |
|---|
| 104 |
} |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|