From 8640edd0906f2e617c6e94840a158bced0f5121b Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 25 Feb 2010 12:16:31 +0000 Subject: Make newsletter send work. --- utils/modules/newsletter.php | 147 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 116 insertions(+), 31 deletions(-) (limited to 'utils/modules') diff --git a/utils/modules/newsletter.php b/utils/modules/newsletter.php index 528b0a5..5a0cade 100644 --- a/utils/modules/newsletter.php +++ b/utils/modules/newsletter.php @@ -1,18 +1,4 @@ -"; -$replyto = $sender; -$footer = " - -Stay Brutal! -// DIE -http://www.executionroom.com -info@executionroom.com -"; +timestamp = $timestamp; } - function send($subject, $message) { - global $subject_prefix; - global $sender; - global $replyto; - global $footer; - - $message .= $footer; - $message .= "\nTo stop receiving this newsletter, click the following link: http://www.executionroom.com/?page=news&action=unsubscribe&email=". $this->email . "\n"; + public function send($subject, $message, + $subject_prefix, $sender, $replyto, $footer, $unsubscribe_url) + { + $message .= "\n\n".$footer; + $message .= "\n\nTo stop receiving this newsletter, click the following link: ".$unsubscribe_url."&action=unsubscribe&email=". $this->email . "\n"; $headers = "From: " . $sender . "\r\n"; $headers .= "Reply-To: " . $replyto . "\r\n"; $headers .= "Content-Type: text/plain; charset=iso-8859-1\r\n"; @@ -40,14 +23,17 @@ class Email { $ret = mail($this->email, $subject, $message, $headers); if(!$ret) echo "Fail(".$this->email.")"; - - //usleep(100000); } } class Mailinglist { private $file; private $mailinglist = array(); + public $subj_prefix; + public $sender; + public $replyto; + public $footer; + public $unsubscribe_url; public function add($email) { $key = $email->email; @@ -69,11 +55,15 @@ class Mailinglist { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); - fwrite($fp, "\n"); + fwrite($fp, "subj_prefix . "\"\n"); + fwrite($fp, " sender=\"" . $this->sender . "\"\n"); + fwrite($fp, " replyto=\"" . $this->replyto . "\"\n"); + fwrite($fp, " unsubscribe_url=\"" . $this->unsubscribe_url . "\">\n"); + fwrite($fp, "
" . $this->footer . "
\n"); foreach($this->mailinglist as $email) { fwrite($fp, " email, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " timestamp=\"" . $email->timestamp . "\">\n"); + fwrite($fp, " timestamp=\"" . $email->timestamp . "\">\n"); fwrite($fp, " \n"); } fwrite($fp, "
\n"); @@ -86,6 +76,20 @@ class Mailinglist { $dom = new DomDocument; $dom->preserveWhiteSpace = FALSE; $dom->load($this->file); + + $nl = $dom->documentElement; + + $this->subj_prefix = $nl->getAttribute('subj_prefix'); + $this->sender = $nl->getAttribute('sender'); + $this->replyto = $nl->getAttribute('replyto'); + $this->unsubscribe_url = $nl->getAttribute('unsubscribe_url'); + $footers = $dom->getElementsByTagName('footer'); + if($footers) { + foreach($footers as $f) { + $this->footer = $f->textContent; + } + } + $params = $dom->getElementsByTagName('email'); foreach ($params as $param) { @@ -134,7 +138,11 @@ class Mailinglist { $steps = floor($sz / 10) + 1; foreach($this->mailinglist as $email) { - $email->send($subject, $message); + $email->send($subject, $message, + $this->subj_prefix, $this->sender, + $this->replyto, $this->footer, + $this->unsubscribe_url); + $pct = $num / $sz * 100; if($pct >= $lvl) { printf("%.0f%%", $lvl); @@ -167,13 +175,90 @@ class Newsletter { // Admin config public $admin_title = "NewsLetter"; - public $admin_submodules = array("Send newsletter" => "create"); + public $admin_submodules = array("Send newsletter" => "send", + "Config" => "config"); + + public function admin_send($action, $vars) + { + global $UID, $ICONS_DIR; + + switch($action) { + case "send": + $this->mailinglist->post($vars["subject"], $vars["content"]); + break; + + case "preview": + $testmail = new Email($vars["testaddr"], 0); + echo "
\n"; + echo $testmail->send($vars["subject"], $vars["content"], + $this->mailinglist->subj_prefix, + $this->mailinglist->sender, + $this->mailinglist->replyto, + $this->mailinglist->footer, + $this->mailinglist->unsubscribe_url); + echo "A test mail has been sent to ".$vars["testaddr"]."
\n"; + echo "

Looking ok?

"; + $form = new Form("send"); + $form->addWidget(new Hidden($vars)); + $form->addWidget(new Button("yes")); + $form->render(); + + $form = new Form("retry"); + $form->addWidget(new Hidden($vars)); + $form->addWidget(new Button("no")); + $form->render(); + break; + + case "retry": + $testaddr = $vars["testaddr"]; + $subject = $vars["subject"]; + $content = $vars["content"]; + default: + $form = new Form("preview"); + $form->addWidget(new LineEdit("Test address:", "testaddr", $testaddr)); + $form->addWidget(new LineEdit("Subject:", "subject", $subject)); + $form->addWidget(new TextEdit("Content:", "content", $content)); + $form->addWidget(new Button("Send")); + $form->render(); + break; + } + } + + public function admin_config($action, $vars) + { + switch($action) { + case "update": + $this->mailinglist->subj_prefix = $vars["subj_prefix"]; + $this->mailinglist->sender = $vars["sender"]; + $this->mailinglist->replyto = $vars["replyto"]; + $this->mailinglist->footer = $vars["footer"]; + $this->mailinglist->unsubscribe_url = $vars["unsubscribe_url"]; + $this->mailinglist->write(); + break; + + default: + $form = new Form("update"); + //http://www.executionroom.com/?page=news + $form->addWidget(new LineEdit("Subject prefix:", "subj_prefix", $this->mailinglist->subj_prefix)); + $form->addWidget(new LineEdit("Sender:", "sender", $this->mailinglist->sender)); + $form->addWidget(new LineEdit("Reply to:", "replyto", $this->mailinglist->replyto)); + $form->addWidget(new TextEdit("Footer:", "footer", $this->mailinglist->footer)); + $form->addWidget(new LineEdit("Unsubscribe URL::", "unsubscribe_url", $this->mailinglist->unsubscribe_url)); + $form->addWidget(new Button("Update")); + $form->render(); + break; + } + } public function admin($sub, $action, $vars) { switch($sub) { - case "create": - // $this->admin_add($action, $vars); + case "send": + $this->admin_send($action, $vars); + break; + + case "config": + $this->admin_config($action, $vars); break; } } -- cgit v1.2.3