Skip to content

Commit

Permalink
FEATURE: merged features from trunk r113768,r13770,r113779-r113782
Browse files Browse the repository at this point in the history
  • Loading branch information
Normann Lou committed Nov 30, 2010
1 parent 56888e2 commit 4251b91
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 444 deletions.
23 changes: 0 additions & 23 deletions README

This file was deleted.

20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Newsletter Module

## Maintainer Contact

* Normann Lou (Nickname: nlou)
normann (at) silverstripe (dot) com

## Requirements

SilverStripe 2.4.2+

## Documentation

http://doc.silverstripe.com/modules:newsletter

## Installation Instructions

Extract the newsletter folder into the top level of your site, and visit
http://www.mysite.com/dev/build to rebuild the database.

3 changes: 1 addition & 2 deletions code/BatchProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ function next() {
else
return $process->next();
}
}
?>
}
3 changes: 1 addition & 2 deletions code/BouncedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ function Entries() {

return new DataObjectSet( $bouncedUsers );
}
}
?>
}
9 changes: 8 additions & 1 deletion code/CheckboxSetWithExtraField.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php

/**
* @package newsletter
*/
class CheckboxSetWithExtraField extends CheckboxSetField{

public $extra = array();
Expand All @@ -21,6 +25,7 @@ class CheckboxSetWithExtraField extends CheckboxSetField{
function __construct($name, $title = "", $source = array(), $extra=array(), $value = "", $extraValue=array(), $form = null) {
if(!empty($extra)) $this->extra = $extra;
if(!empty($extraValue)) $this->extraValue = $extraValue;

parent::__construct($name, $title, $source, $value, $form);
}

Expand Down Expand Up @@ -234,6 +239,9 @@ function saveInto(DataObject $record) {
}

function setValue($val, $data = false){

if(!$data) return;

if(is_string($val)) {
$val = explode(",", $val);
}
Expand All @@ -260,4 +268,3 @@ function setValue($val, $data = false){
}
}
}
?>
33 changes: 23 additions & 10 deletions code/Newsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function getCMSFields($controller = null) {
if($this->Status != 'Draft') {
$mailTab->push( new ReadonlyField("SendDate", _t('Newsletter.SENTAT', 'Sent at'), $this->SendDate) );
}


$this->extend("updateCMSFields", $ret);
return $ret;
}

Expand Down Expand Up @@ -114,9 +115,10 @@ function getTitle() {
function getNewsletterType() {
return DataObject::get_by_id('NewsletterType', $this->ParentID);
}

function getContentBody(){
$content = $this->Content;
$content = $this->obj('Content');

$this->extend("updateContentBody", $content);
return $content;
}
Expand Down Expand Up @@ -187,20 +189,31 @@ class Newsletter_Recipient extends DataObject {
class Newsletter_Email extends Email {

protected $nlType;

function __construct($nlType) {
$this->nlType = $nlType;
protected $newsletter;

/**
* @param Newsletter $newsletter
*/
function __construct($newsletter, $nlType = null) {
$this->newsletter = $newsletter;
$this->nlType = $nlType ? $nlType : $newsletter->getNewsletterType();

parent::__construct();
$this->body = $newsletter->getContentBody();
}

function setTemplate( $template ) {
function setTemplate($template) {
$this->ss_template = $template;
}


function Newsletter() {
return $this->newsletter;
}

function UnsubscribeLink(){
$emailAddr = $this->To();
$nlTypeID = $this->nlType->ID;

return Director::absoluteBaseURL() . "unsubscribe/index/$emailAddr/$nlTypeID";
}
}
?>
}
56 changes: 35 additions & 21 deletions code/NewsletterAdmin.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

/**
* Newsletter administration section
*
* @package newsletter
*/

class NewsletterAdmin extends LeftAndMain {
static $subitem_class = 'Member';

Expand Down Expand Up @@ -158,24 +160,30 @@ public function shownewsletter($params) {
*/
public function preview($request) {
$newsletterID = (int) $request->param('ID');
$obj = DataObject::get_by_id('Newsletter', $newsletterID);
$templateName = ($obj && ($obj->Parent()->Template)) ? $obj->Parent()->Template : 'GenericEmail';
$newsletter = DataObject::get_by_id('Newsletter', $newsletterID);
$templateName = ($newsletter && ($newsletter->Parent()->Template)) ? $newsletter->Parent()->Template : 'GenericEmail';

// Block stylesheets and JS that are not required (email templates should have inline CSS/JS)
Requirements::clear();

// Set template specific variables before passing it to the template
$obj->Body = $obj->Content;

return $this->customise($obj)->renderWith($templateName);
$obj = new DataObject();
$obj->Newsletter = $newsletter;

// create a new body field and copy contents
$obj->Body = new HTMLText();
$obj->Body->setValue($newsletter->getContentBody()->RAW());

return HTTP::absoluteURLs($this->customise($obj)->renderWith($templateName));
}

/**
* Top level call from ajax
* Called when a newsletter type is clicked on the left menu
*/
* Top level call from ajax
* Called when a newsletter type is clicked on the left menu
*/
public function showmailtype($params) {
$params = $params->allParams();

return $this->showWithEditForm( $params, $this->getNewsletterTypeEditForm( $params['ID'] ) );
}

Expand Down Expand Up @@ -475,20 +483,26 @@ public static function template_paths() {
self::$template_paths[] = project() . '/templates/Email';
}
}
else {
if(is_string(self::$template_paths)) {
self::$template_paths = array(self::$template_paths);
}
}

return self::$template_paths;
}

/**
* return array containing all possible email templates file name
* under the folders of both theme and project specific folder.
*
* @return array
*/
public function templateSource(){
$paths = self::template_paths();
$templates = array( "" => _t('TemplateList.NONE', 'None') );

if(isset($paths) && count($paths)){
if(isset($paths) && is_array($paths)){
$absPath = Director::baseFolder();
if( $absPath{strlen($absPath)-1} != "/" )
$absPath .= "/";
Expand All @@ -499,15 +513,17 @@ public function templateSource(){
$templateDir = opendir( $path );
// read all files in the directory
while( ( $templateFile = readdir( $templateDir ) ) !== false ) {
while(($templateFile = readdir($templateDir)) !== false) {
// *.ss files are templates
if( preg_match( '/(.*)\.ss$/', $templateFile, $match ) ){
$templates[$match[1]] = $match[1];
if( preg_match( '/(.*)\.ss$/', $templateFile, $match )){
// change a
$templates[$match[1]] = preg_replace('/_?([A-Z])/', " $1", $match[1]);
}
}
}
}
}

return $templates;
}

Expand Down Expand Up @@ -537,7 +553,7 @@ public function getNewsletterEditForm($myId){
else
$actions->push(new FormAction('send',_t('NewsletterAdmin.SEND','Send...')));

$actions->push(new FormAction('save',_t('NewsletterAdmin.SAVE')));
$actions->push(new FormAction('save',_t('NewsletterAdmin.SAVE', 'Save')));

$form = new Form($this, "NewsletterEditForm", $fields, $actions);
$form->loadDataFrom($email);
Expand Down Expand Up @@ -574,8 +590,7 @@ public function sendnewsletter( /*$data, $form = null*/ ) {
$newsletter = DataObject::get_by_id("Newsletter", $id);
$nlType = $newsletter->getNewsletterType();

$e = new Newsletter_Email($nlType);
$e->Body = $body = $newsletter->getContentBody();
$e = new Newsletter_Email($newsletter, $nlType);
$e->Subject = $subject = $newsletter->Subject;

// TODO Make this dynamic
Expand Down Expand Up @@ -618,7 +633,8 @@ public function sendnewsletter( /*$data, $form = null*/ ) {
case "Unsent":
// Send to only those who have not already been sent this newsletter.
$only_to_unsent = 1;
echo self::sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID, $newsletter->UnsentSubscribers());

echo self::sendToList( $subject, $from, $newsletter, $nlType, $messageID, $newsletter->UnsentSubscribers());
break;
}

Expand All @@ -631,8 +647,8 @@ static function sendToAddress( $email, $address, $messageID = null ) {
$email->send();
}

static function sendToList( $subject, $body, $from, $newsletter, $nlType, $messageID = null, $recipients) {
$emailProcess = new NewsletterEmailProcess( $subject, $body, $from, $newsletter, $nlType, $messageID, $recipients);
static function sendToList( $subject, $from, $newsletter, $nlType, $messageID = null, $recipients) {
$emailProcess = new NewsletterEmailProcess( $subject, $from, $newsletter, $nlType, $messageID, $recipients);
return $emailProcess->start();
}

Expand Down Expand Up @@ -938,6 +954,4 @@ function UploadForm( $id = null ) {
function getMenuTitle() {
return _t('LeftAndMain.NEWSLETTERS',"Newsletters",PR_HIGH,"Menu title");
}
}

?>
}
31 changes: 14 additions & 17 deletions code/NewsletterEmailBlacklist.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

/**
* This class is responsible for ensuring that members who are on it receive NO email
* communication at all. any correspondance is caught before the email is sent.
* @package sapphire
* @subpackage email
*
* @package newsletter
*/
class NewsletterEmailBlacklist extends DataObject{
class NewsletterEmailBlacklist extends DataObject {

static $db = array(
'BlockedEmail' => 'Varchar',
);
Expand All @@ -15,23 +17,20 @@ class NewsletterEmailBlacklist extends DataObject{
);

/**
* Helper function to see if the email being
* sent has specifically been blocked.
* Helper function to see if the email being sent has specifically been blocked.
*
* @return bool
*/
static function isBlocked($email) {
$blockedEmails = DataObject::get("NewsletterEmailBlacklist")->toDropDownMap("ID","BlockedEmail");
if($blockedEmails) {
if(in_array($email, $blockedEmails)) {
return true;
}
}

return false;

return ($blockedEmails && in_array($email, $blockedEmails));
}

/**
* Migrate data from Email_BlackList (the obsolete table)
* to NewsletterEmailBlacklist.
* Migrate data from Email_BlackList (the obsolete table) to NewsletterEmailBlacklist.
*
* @return void
*/
function requireDefaultRecords() {
parent::requireDefaultRecords();
Expand All @@ -42,6 +41,4 @@ function requireDefaultRecords() {
echo("<div style=\"padding:5px; color:white; background-color:blue;\">Data in Email_BlackList has been moved to the new NewsletterEmailBlacklist table. To drop the obsolete table, issue this SQL command: \"DROP TABLE '_obsolete_Email_BlackList'\".</div>");
}
}

}
?>
}
Loading

0 comments on commit 4251b91

Please sign in to comment.