email = $email;
$this->timestamp = $timestamp;
}
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";
$headers .= "X-Mailer: PHP/" . phpversion();
$subject = "[".$subject_prefix."] " . $subject;
$ret = mail($this->email, $subject, $message, $headers);
if(!$ret) echo "Fail(".$this->email.")";
}
}
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;
if(array_key_exists($key, $this->mailinglist)) return false;
$this->mailinglist[$key] = $email;
return true;
}
public function remove($email) {
if(array_key_exists($email, $this->mailinglist)) {
unset($this->mailinglist[$email]);
return true;
}
return false;
}
public function write()
{
$fp = fopen($this->file, "w");
fwrite($fp, "\n");
fwrite($fp, "
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 "send": $this->admin_send($action, $vars); break; case "config": $this->admin_config($action, $vars); break; } } public function run($params) { global $page; global $newsletter_action; global $_POST, $GLOBALS; $email = $_POST["newsletter_email"]; // get from lineedit. if($email == "") $email = $GLOBALS["newsletter_email"]; // get from link. $str = ""; $str .= " \n"; if($newsletter_action == "subscribe") { $str .= $this->mailinglist->subscribe($email); } if($newsletter_action == "unsubscribe") { $str .= $this->mailinglist->unsubscribe($email); } return $str; } private function read() { $this->mailinglist = new Mailinglist($this->file); } public function Newsletter($file) { $this->file = $file; if(file_exists($file)) $this->read(); } } function newsletter_init() { global $DATA_DIR; return new Newsletter($DATA_DIR . "/newsletter.xml"); } ?>