Skip to content

Commit

Permalink
Implemented the Core Email API, created by Huib Keemink and Michael E…
Browse files Browse the repository at this point in the history
…ichelsdoerfer.
  • Loading branch information
creativedutchmen committed Dec 13, 2010
1 parent 03a9a1f commit c28a238
Show file tree
Hide file tree
Showing 13 changed files with 1,591 additions and 83 deletions.
8 changes: 6 additions & 2 deletions symphony/content/content.blueprintsevents.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ function __formAction(){

$documentation_parts[] = self::processDocumentationCode(
'send-email[sender-email] // '.__('Optional').self::CRLF.
'send-email[sender-name] // '.__('Optional').self::CRLF.
'send-email[sender-name] // '.__('Optional').self::CRLF.
'send-email[reply-to-name] // '.__('Optional: The name used in the Reply-To header field.').self::CRLF.
'send-email[reply-to-email] // '.__('Optional: The email-address used in the Reply-To header field.').self::CRLF.
'send-email[subject] // '.__('Optional').self::CRLF.
'send-email[body]'.self::CRLF.
'send-email[recipient] // '.__('list of comma author usernames.'));
Expand All @@ -375,7 +377,9 @@ function __formAction(){
<label>'.__('Email').' <input type="text" name="fields[email]" value="" /></label>
<label>'.__('Message').' <textarea name="fields[message]" rows="5" cols="21"></textarea></label>
<input name="send-email[sender-email]" value="fields[email]" type="hidden" />
<input name="send-email[sender-name]" value="fields[author]" type="hidden" />
<input name="send-email[sender-name]" value="fields[author]" type="hidden" />
<input name="send-email[reply-to-email]" value="fields[email]" type="hidden" />
<input name="send-email[reply-to-name]" value="fields[author]" type="hidden" />
<input name="send-email[subject]" value="You are being contacted" type="hidden" />
<input name="send-email[body]" value="fields[message]" type="hidden" />
<input name="send-email[recipient]" value="fred" type="hidden" />
Expand Down
20 changes: 12 additions & 8 deletions symphony/content/content.login.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,21 @@ function action(){
Symphony::Database()->insert(array('author_id' => $author['id'], 'token' => $token, 'expiry' => DateTimeObj::getGMT('c', time() + (120 * 60))), 'tbl_forgotpass');
}

$this->_email_sent = General::sendEmail($author['email'],
Symphony::Database()->fetchVar('email', 0, "SELECT `email` FROM `tbl_authors` ORDER BY `id` ASC LIMIT 1"),
__('Symphony Concierge'),
__('New Symphony Account Password'),
__('Hi %s,', array($author['first_name'])) . self::CRLF .
try{
$email = Email::create();

$email->recipients = $author['email'];
$email->subject = __('New Symphony Account Password');
$email->text_plain = __('Hi %s,', array($author['first_name'])) . self::CRLF .
__('A new password has been requested for your account. Login using the following link, and change your password via the Authors area:') . self::CRLF .
self::CRLF . ' ' . URL . "/symphony/login/$token/" . self::CRLF . self::CRLF .
self::CRLF . ' ' . URL . "/symphony/login/{$token}/" . self::CRLF . self::CRLF .
__('It will expire in 2 hours. If you did not ask for a new password, please disregard this email.') . self::CRLF . self::CRLF .
__('Best Regards,') . self::CRLF .
__('The Symphony Team'));

__('The Symphony Team');

$email->send();
$this->_email_sent = true;
}

## TODO: Fix Me
###
Expand Down
34 changes: 34 additions & 0 deletions symphony/content/content.systempreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,40 @@ public function view() {
$this->Form->appendChild($group);
}

//Get available EmailGateways
$email_gateway_manager = new EmailGatewayManager($this);
$email_gateways = $email_gateway_manager->listAll();
if(count($email_gateways) >= 1){
$group = new XMLElement('fieldset', NULL, array('class' => 'settings picker'));
$group->appendChild(new XMLElement('legend', __('Email Gateway')));
$label = Widget::Label();

// Get gateway names
ksort($email_gateways);

$default_gateway = $email_gateway_manager->getDefaultGateway();
$selected_is_installed = $email_gateway_manager->__find($default_gateway);

$options = array();
foreach($email_gateways as $handle => $details) {
$options[] = array($handle, (($handle == $default_gateway) || (($selected_is_installed == false) && $handle == 'sendmail')), $details['name']);
}
$select = Widget::Select('settings[Email][default_gateway]', $options);
$label->appendChild($select);
$group->appendChild($label);
$group->appendChild(new XMLElement('p', __('The Symphony core will use the selected gateway to send emails. More gateways can be installed using extensions, and any gateway may be used by custom events or extensions.'), array('class' => 'help')));
// Append email gateway selection
$this->Form->appendChild($group);
}

foreach($email_gateways as $gateway){
$gateway_settings = $email_gateway_manager->create($gateway['handle'])->getPreferencesPane();

if(is_a($gateway_settings, 'XMLElement')){
$this->Form->appendChild($gateway_settings);
}
}

###
# Delegate: AddCustomPreferenceFieldsets
# Description: Add Extension custom preferences. Use the $wrapper reference to append objects.
Expand Down
4 changes: 3 additions & 1 deletion symphony/lib/boot/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
define_safe('TOOLKIT', LIBRARY . '/toolkit');
define_safe('LANG', LIBRARY . '/lang');
define_safe('CORE', LIBRARY . '/core');
define_safe('BOOT', LIBRARY . '/boot');
define_safe('BOOT', LIBRARY . '/boot');

define_safe('EMAILGATEWAYS', TOOLKIT . '/email-gateways');

define_safe('CONTENT', SYMPHONY . '/content');

Expand Down
2 changes: 2 additions & 0 deletions symphony/lib/core/class.symphony.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
require_once(TOOLKIT . '/class.general.php');
require_once(TOOLKIT . '/class.profiler.php');
require_once(TOOLKIT . '/class.author.php');
require_once(TOOLKIT . '/class.email.php');

require_once(TOOLKIT . '/class.authormanager.php');
require_once(TOOLKIT . '/class.extensionmanager.php');
require_once(TOOLKIT . '/class.emailgatewaymanager.php');

Abstract Class Symphony implements Singleton{

Expand Down
40 changes: 40 additions & 0 deletions symphony/lib/toolkit/class.email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @package toolkit
*/

/**
* The Exception to be thrown by the Email class.
*/
class EmailException extends Exception{
}

include_once(TOOLKIT . '/class.emailgatewaymanager.php');

/**
* The Email class is a factory class to make it possible to send emails using different gateways.
*/
Abstract class Email{

private $gateway;

/**
* Returns the EmailGateway to send emails with.
* Calling this function multiple times will return unique objects.
*
* @param string $gateway
* The name of the gateway to use. Please only supply if specific gateway functions are beeing used.
* If the gateway is not found, it will throw an EmailException
* @return EmailGateway
*/
function create($gateway = null){
$email_gateway_manager = new EmailGatewayManager($this);
if($gateway){
return $email_gateway_manager->create($gateway);
}
else{
return $email_gateway_manager->create($email_gateway_manager->getDefaultGateway());
}
}
}
Loading

0 comments on commit c28a238

Please sign in to comment.