summaryrefslogtreecommitdiff
path: root/utils/modules
diff options
context:
space:
mode:
authordeva <deva>2010-02-26 16:12:36 +0000
committerdeva <deva>2010-02-26 16:12:36 +0000
commit78a0f0a00650c9a5e3c4d4cadcacc409919067ea (patch)
tree3b30f64b7b6d4608102d5672cba9b7ec0c00dbc4 /utils/modules
parenta741351d5c91913f22255b8e9e5d4586c70735d6 (diff)
Add pressrelease module. Make lots of codesharing with the newsletter module.
Diffstat (limited to 'utils/modules')
-rw-r--r--utils/modules/newsletter.php66
-rw-r--r--utils/modules/pressrelease.php183
2 files changed, 187 insertions, 62 deletions
diff --git a/utils/modules/newsletter.php b/utils/modules/newsletter.php
index ef172e0..5ca19bf 100644
--- a/utils/modules/newsletter.php
+++ b/utils/modules/newsletter.php
@@ -4,30 +4,10 @@ global $UTIL_DIR;
include_once($UTIL_DIR . "/mail.php");
-class Mailinglist {
+class Mailinglist extends _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");
@@ -103,6 +83,9 @@ class Mailinglist {
return $str;
}
+ /**
+ * Overrides the postSingle method in the _Mailinglist class.
+ */
public function postSingle($email, $subject, $message)
{
$subject = "[".$this->subj_prefix."] " . $subject;
@@ -114,47 +97,6 @@ class Mailinglist {
$email->send($subject, $message, $this->sender, $this->replyto);
}
- public function post($subject, $message)
- {
- $subject = "[".$this->subject_prefix."] " . $subject;
-
- $message .= "\n\n".$this->footer;
- $message .= "\n\nTo stop receiving this newsletter, click the following link: ".
- $this->unsubscribe_url."&action=unsubscribe&email=". $this->email . "\n";
-
-
- $sz = sizeof($this->mailinglist);
-
- echo "<div style=\"text-align: center; padding-top: 120px; padding-bottom: 100px; position: absolute; top: 25%; left: 0px; width: 99.4%; height: 150px; border: solid #0000ff 3px; background: #fff; color: #000;\">Sending ". $sz ." mails <br/>\n&lt;";
- ob_flush();
- flush();
-
- $num = 0;
- $lvl = 0;
- $steps = floor($sz / 10) + 1;
-
- foreach($this->mailinglist as $email) {
-
- $this->postSingle($email, $ubject, $message);
-
- $pct = $num / $sz * 100;
- if($pct >= $lvl) {
- printf("<font style=\"font-size: 9px;\">%.0f%%</font>", $lvl);
- $lvl += 100/$steps;
- } else {
- echo ".";
- }
- ob_flush();
- flush();
- $num++;
- }
- echo "<font style=\"font-size: 9px;\">[100%]</font>&gt;\n<br/>done<br/>\n";
- echo "<a style=\"font-size: 20px; font-weight: bold;\" href=\"?page=admin&amp;module=newsletter\">[CLOSE]</a>";
- echo "</div>\n";
- ob_flush();
- flush();
- }
-
public function Mailinglist($file)
{
$this->file = $file;
diff --git a/utils/modules/pressrelease.php b/utils/modules/pressrelease.php
new file mode 100644
index 0000000..de792d2
--- /dev/null
+++ b/utils/modules/pressrelease.php
@@ -0,0 +1,183 @@
+<?php /* -*- mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+global $UTIL_DIR;
+
+include_once($UTIL_DIR . "/mail.php");
+
+class PEmail extends Email {
+ public $url;
+ public $title;
+};
+
+class PMailinglist extends _Mailinglist {
+ private $file;
+
+ public function write()
+ {
+ $fp = fopen($this->file, "w");
+ fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fwrite($fp, "<pressrelease subj_prefix=\"" . $this->subj_prefix . "\"\n");
+ fwrite($fp, " sender=\"" . $this->sender . "\"\n");
+ fwrite($fp, " replyto=\"" . $this->replyto . "\">\n");
+ fwrite($fp, " <footer>" . $this->footer . "</footer>\n");
+ foreach($this->mailinglist as $email) {
+ fwrite($fp, " <email email=\"" .
+ htmlspecialchars($email->email, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " url=\"" . $email->url . "\">\n");
+ fwrite($fp, " name=\"" . $email->name . "\">\n");
+ fwrite($fp, " </email>\n");
+ }
+ fwrite($fp, "</pressrelease>\n");
+
+ fclose($fp);
+ }
+
+ private function read()
+ {
+ $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');
+ $footers = $dom->getElementsByTagName('footer');
+ if($footers) {
+ foreach($footers as $f) {
+ $this->footer = $f->textContent;
+ }
+ }
+
+ $params = $dom->getElementsByTagName('email');
+
+ $cnt = 1;
+ foreach ($params as $param) {
+ $email = new PEmail($param->getAttribute('email'), $cnt++);
+ $email->url = $param->getAttribute('url');
+ $email->name = $param->getAttribute('name');
+ $this->add($email);
+ }
+ }
+
+ public function PMailinglist($file)
+ {
+ $this->file = $file;
+ if(file_exists($this->file)) $this->read();
+ }
+}
+
+class PressRelease {
+
+ private $file;
+ private $mailinglist;
+
+ // Admin config
+ public $admin_title = "Press release";
+ public $admin_submodules = array("Send pressrelease" => "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 PEmail($vars["testaddr"], 0);
+ echo "<div class=\"preview\">\n";
+ $this->mailinglist->postSingle($testmail, $vars["subject"], $vars["content"]);
+ echo "A test mail has been sent to ".$vars["testaddr"]."</div>\n";
+ echo "<p>Looking ok?</p>";
+ $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->write();
+ break;
+
+ default:
+ $form = new Form("update");
+ $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 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)
+ {
+ return "";
+ }
+
+ private function read()
+ {
+ $this->mailinglist = new PMailinglist($this->file);
+ }
+
+ public function PressRelease($file)
+ {
+ $this->file = $file;
+ if(file_exists($file)) $this->read();
+ }
+}
+
+
+function pressrelease_init()
+{
+ global $DATA_DIR;
+ return new PressRelease($DATA_DIR . "/pressrelease.xml");
+}
+
+?> \ No newline at end of file