Skip to content

Commit

Permalink
Using the new email sending API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rowan Lewis committed Mar 1, 2011
1 parent 3822b67 commit 2ffafea
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 109 deletions.
203 changes: 109 additions & 94 deletions content/content.logs.php
Expand Up @@ -31,7 +31,11 @@ public function __viewPreview() {
}

public function __actionIndex() {
$checked = @array_keys($_POST['items']);
$checked = (
(isset($_POST['items']) && is_array($_POST['items']))
? @array_keys($_POST['items'])

This comment has been minimized.

Copy link
@brendo

brendo Mar 1, 2011

Member

Don't need error suppression if you've already checked ;)

: null
);

if (is_array($checked) and !empty($checked)) {
switch ($_POST['with-selected']) {
Expand Down Expand Up @@ -83,106 +87,113 @@ public function __viewIndex() {
$tableBody = array(
Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', null, count($tableHead))))
);
}

else foreach ($logs as $log) {
extract($log, EXTR_PREFIX_ALL, 'log');

} else {
foreach ($logs as $log) {
extract($log, EXTR_PREFIX_ALL, 'log');

$col_date = Widget::TableData(
$col_date = Widget::TableData(
Widget::Anchor(
DateTimeObj::get(__SYM_DATETIME_FORMAT__, strtotime($log_date)),
URL . "/symphony/extension/emailtemplatefilter/logs/preview/{$log_id}/"
)
);
$col_date->appendChild(Widget::Input("items[{$log_id}]", null, 'checkbox'));

if (!empty($log_subject)) {
$col_subject = Widget::TableData(
General::sanitize($log_subject)
);
}

else {
$col_subject = Widget::TableData('None', 'inactive');
}

if (!empty($log_sender)) {
$col_sender = Widget::TableData(
General::sanitize($log_sender)
);
}

else {
$col_sender = Widget::TableData('None', 'inactive');
}

if (!empty($log_senders)) {
$col_senders = Widget::TableData(
General::sanitize($log_senders)
);
}

else {
$col_senders = Widget::TableData('None', 'inactive');
}

if (!empty($log_recipients)) {
$col_recipients = Widget::TableData(
General::sanitize($log_recipients)
);
}

else {
$col_recipients = Widget::TableData('None', 'inactive');
}

if ($template = $this->_driver->getTemplate($log_template_id)) {
$col_template = Widget::TableData(
Widget::Anchor(
DateTimeObj::get(__SYM_DATETIME_FORMAT__, strtotime($log_date)),
URL . "/symphony/extension/emailtemplatefilter/logs/preview/{$log_id}/"
General::sanitize($template['name']),
URL . "/symphony/extension/emailtemplatefilter/templates/edit/{$log_template_id}/"
)
);
$col_date->appendChild(Widget::Input("items[{$log_id}]", null, 'checkbox'));

if (!empty($log_subject)) {
$col_subject = Widget::TableData(
General::sanitize($log_subject)
);

} else {
$col_subject = Widget::TableData('None', 'inactive');
}

if (!empty($log_sender)) {
$col_sender = Widget::TableData(
General::sanitize($log_sender)
);

} else {
$col_sender = Widget::TableData('None', 'inactive');
}

if (!empty($log_senders)) {
$col_senders = Widget::TableData(
General::sanitize($log_senders)
);

} else {
$col_senders = Widget::TableData('None', 'inactive');
}

if (!empty($log_recipients)) {
$col_recipients = Widget::TableData(
General::sanitize($log_recipients)
);

} else {
$col_recipients = Widget::TableData('None', 'inactive');
}

if ($template = $this->_driver->getTemplate($log_template_id)) {
$col_template = Widget::TableData(
Widget::Anchor(
General::sanitize($template['name']),
URL . "/symphony/extension/emailtemplatefilter/templates/edit/{$log_template_id}/"
)
);
} else {
$col_template = Widget::TableData('None', 'inactive');
}

$entries = $entryManager->fetch($log_entry_id, null, null, null, null, null, false, true);
}

else {
$col_template = Widget::TableData('None', 'inactive');
}

$entries = $entryManager->fetch($log_entry_id, null, null, null, null, null, false, true);

if (!empty($entries) and $entry = $entries[0]) {
$section_id = $entry->get('section_id');
$section = $sectionManager->fetch($section_id);
$column = array_shift($section->fetchVisibleColumns());

if (!empty($entries) and $entry = $entries[0]) {
$section_id = $entry->_fields['section_id'];
$section = $sectionManager->fetch($section_id);
$column = array_shift($section->fetchVisibleColumns());

$data = $entry->getData($column->get('id'));
$link = Widget::Anchor('None', URL . '/symphony/publish/' . $section->get('handle') . '/edit/' . $entry->get('id') . '/', $entry->get('id'), 'content');

/*
$col_section = Widget::TableData(
Widget::Anchor(
General::sanitize($section->get('name')),
URL . '/symphony/publish/' . $section->get('handle') . '/'
)
);
*/

$col_entry = Widget::TableData($column->prepareTableValue($data, $link));

} else {
//$col_section = Widget::TableData('None', 'inactive');
$col_entry = Widget::TableData('None', 'inactive');
}
$data = $entry->getData($column->get('id'));
$link = Widget::Anchor('None', URL . '/symphony/publish/' . $section->get('handle') . '/edit/' . $entry->get('id') . '/', $entry->get('id'), 'content');

$tableBody[] = Widget::TableRow(
array(
$col_date, $col_subject, $col_sender,
$col_senders, $col_recipients,
$col_template, $col_entry
/*
$col_section = Widget::TableData(
Widget::Anchor(
General::sanitize($section->get('name')),
URL . '/symphony/publish/' . $section->get('handle') . '/'
)
);
*/

$col_entry = Widget::TableData($column->prepareTableValue($data, $link));
}

else {
//$col_section = Widget::TableData('None', 'inactive');
$col_entry = Widget::TableData('None', 'inactive');
}

$tableBody[] = Widget::TableRow(
array(
$col_date, $col_subject, $col_sender,
$col_senders, $col_recipients,
$col_template, $col_entry
)
);
}

$table = Widget::Table(
Widget::TableHead($tableHead), null,
Widget::TableBody($tableBody)
);
$table->setAttribute('class', 'selectable');

$this->Form->appendChild($table);

Expand Down Expand Up @@ -211,8 +222,9 @@ public function __viewIndex() {
$li->appendChild(
Widget::Anchor('First', Symphony::Engine()->getCurrentPageURL() . '?pg=1')
);

} else {
}

else {
$li->setValue('First');
}

Expand All @@ -225,8 +237,9 @@ public function __viewIndex() {
$li->appendChild(
Widget::Anchor('← Previous', Symphony::Engine()->getCurrentPageURL(). '?pg=' . ($page - 1))
);

} else {
}

else {
$li->setValue('← Previous');
}

Expand All @@ -246,8 +259,9 @@ public function __viewIndex() {
$li->appendChild(
Widget::Anchor('Next →', Symphony::Engine()->getCurrentPageURL(). '?pg=' . ($page + 1))
);

} else {
}

else {
$li->setValue('Next →');
}

Expand All @@ -260,8 +274,9 @@ public function __viewIndex() {
$li->appendChild(
Widget::Anchor('Last', Symphony::Engine()->getCurrentPageURL(). '?pg=' . $pages)
);

} else {
}

else {
$li->setValue('Last');
}

Expand Down
1 change: 1 addition & 0 deletions content/content.templates.php
Expand Up @@ -537,6 +537,7 @@ public function __viewIndex() {
Widget::TableHead($tableHead), null,
Widget::TableBody($tableBody)
);
$table->setAttribute('class', 'selectable');

$this->Form->appendChild($table);

Expand Down
37 changes: 22 additions & 15 deletions extension.driver.php
Expand Up @@ -397,10 +397,10 @@ public function sendEmail($entry_id, $template_id) {
$generator .= '/' . $page->handle;
$generator = rtrim($generator, '/');
$params = trim($email['params'], '/');
$email['generator'] = "{$generator}/{$params}/";
$generator = "{$generator}/{$params}/";

// Add values:
$email['message'] = (string)file_get_contents($email['generator']);
$email['message'] = (string)file_get_contents($generator);
$email['condition_id'] = $email['id'];
$email['entry_id'] = $entry_id;

Expand All @@ -411,23 +411,30 @@ public function sendEmail($entry_id, $template_id) {
unset($email['sortorder']);
unset($email['page']);
unset($email['params']);
unset($email['generator']);

//var_dump($data->saveXML());
//var_dump(self::$params);
//var_dump($email);
//exit;
$send = Email::create();
$success = false;

// Send the email:
$return = General::sendEmail(
$email['recipients'], $email['senders'], $email['sender'], $email['subject'], $email['message'], array(
'mime-version' => '1.0',
'content-type' => 'text/html; charset="UTF-8"'
)
);
try {
$send->recipients = $email['recipients'];
$send->sender_name = $email['sender'];
$send->sender_email_address = $email['senders'];
$send->subject = $email['subject'];
$send->text_html = $email['message'];
$send->send();
$success = true;
}

catch (EmailGatewayException $e) {
throw new SymphonyErrorPage('Error sending email. ' . $e->getMessage());
}

catch (EmailException $e) {
throw new SymphonyErrorPage('Error sending email. ' . $e->getMessage());
}

// Log the email:
$email['success'] = ($return ? 'yes' : 'no');
$email['success'] = ($success ? 'yes' : 'no');
$email['date'] = DateTimeObj::get('c');

Symphony::Database()->insert($email, 'tbl_etf_logs');
Expand Down

0 comments on commit 2ffafea

Please sign in to comment.