From 9cff69d330760c133d2b22c96da7a89e319b2362 Mon Sep 17 00:00:00 2001 From: deva Date: Sun, 28 Feb 2010 13:06:39 +0000 Subject: Better control of xml enconding... still a lot of testing to do though. --- utils/modules/events.php | 9 ++- utils/modules/news.php | 13 ++-- utils/modules/newsletter.php | 28 ++++---- utils/modules/pressrelease.php | 155 +++++++++++++++++++++++++++++++++++++---- 4 files changed, 167 insertions(+), 38 deletions(-) (limited to 'utils/modules') diff --git a/utils/modules/events.php b/utils/modules/events.php index cf04734..6e1218f 100644 --- a/utils/modules/events.php +++ b/utils/modules/events.php @@ -15,11 +15,10 @@ class Event { public function write($fp) { - fwrite($fp, " title, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " time=\"" . $this->time . "\"\n"); - fwrite($fp, " flyer=\"" . $this->flyer . "\">"); - fwrite($fp, htmlspecialchars($this->description, ENT_QUOTES, "UTF-8")); + fwrite($fp, " title) . "\"\n"); + fwrite($fp, " time=\"" . xmlenc($this->time) . "\"\n"); + fwrite($fp, " flyer=\"" . xmlenc($this->flyer) . "\">"); + fwrite($fp, xmlenc($this->description)); fwrite($fp, " \n"); } diff --git a/utils/modules/news.php b/utils/modules/news.php index 29187ea..00f1d4c 100644 --- a/utils/modules/news.php +++ b/utils/modules/news.php @@ -50,13 +50,12 @@ class NewsEntry { public function write($fp) { - fwrite($fp, " title, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " time=\"" . $this->time . "\"\n"); - fwrite($fp, " category=\"" . $this->category . "\"\n"); - fwrite($fp, " userid=\"" . $this->userid . "\"\n"); - fwrite($fp, " icon=\"" . $this->icon . "\">"); - fwrite($fp, htmlspecialchars($this->description, ENT_QUOTES, "UTF-8")); + fwrite($fp, " title)."\"\n"); + fwrite($fp, " time=\"" . xmlenc($this->time) . "\"\n"); + fwrite($fp, " category=\"" . xmlenc($this->category) . "\"\n"); + fwrite($fp, " userid=\"" . xmlenc($this->userid) . "\"\n"); + fwrite($fp, " icon=\"" . xmlenc($this->icon) . "\">"); + fwrite($fp, xmlenc($this->description)); fwrite($fp, " \n"); } diff --git a/utils/modules/newsletter.php b/utils/modules/newsletter.php index 4bba9c6..3ca3f41 100644 --- a/utils/modules/newsletter.php +++ b/utils/modules/newsletter.php @@ -3,6 +3,7 @@ global $UTIL_DIR; include_once($UTIL_DIR . "/mail.php"); +include_once($UTIL_DIR . "/convert.php"); class Mailinglist extends _Mailinglist { private $file; @@ -13,15 +14,14 @@ class Mailinglist extends _Mailinglist { $fp = fopen($this->file, "w"); 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"); + fwrite($fp, "subj_prefix) . "\"\n"); + fwrite($fp, " sender=\"" . xmlenc($this->sender) . "\"\n"); + fwrite($fp, " replyto=\"" . xmlenc($this->replyto) . "\"\n"); + fwrite($fp, " unsubscribe_url=\"" . xmlenc($this->unsubscribe_url) . "\">\n"); + fwrite($fp, "
" . xmlenc($this->footer) . "
\n"); foreach($this->mailinglist as $email) { - fwrite($fp, " email, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " timestamp=\"" . $email->timestamp . "\">\n"); + fwrite($fp, " email) . "\"\n"); + fwrite($fp, " timestamp=\"" . xmlenc($email->timestamp) . "\">\n"); fwrite($fp, " \n"); } fwrite($fp, "
\n"); @@ -64,9 +64,11 @@ class Mailinglist extends _Mailinglist { $email = new EMail($emailaddr, time()); if($this->add($email)) { $this->write(); - $str .= "
The email: " . $emailaddr . " has now been subscribed.
"; + $str .= "
The email: " . + $emailaddr . " has now been subscribed.
"; } else { - $str .= "
The email: " . $emailaddr . " is already subscribed.
"; + $str .= "
The email: " . + $emailaddr . " is already subscribed.
"; } return $str; } @@ -76,9 +78,11 @@ class Mailinglist extends _Mailinglist { $str = ""; if($this->remove($emailaddr)) { $this->write(); - $str .= "
The email: " . $emailaddr . " has now been unsubscribed.
"; + $str .= "
The email: " . + $emailaddr . " has now been unsubscribed.
"; } else { - $str .= "
The email: " . $emailaddr . " is not subscribed.
"; + $str .= "
The email: " . + $emailaddr . " is not subscribed.
"; } return $str; } diff --git a/utils/modules/pressrelease.php b/utils/modules/pressrelease.php index 4779ffa..542edd0 100644 --- a/utils/modules/pressrelease.php +++ b/utils/modules/pressrelease.php @@ -3,10 +3,11 @@ global $UTIL_DIR; include_once($UTIL_DIR . "/mail.php"); +include_once($UTIL_DIR . "/convert.php"); class PEmail extends Email { public $url; - public $title; + public $name; }; class PMailinglist extends _Mailinglist { @@ -17,15 +18,14 @@ class PMailinglist extends _Mailinglist { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); - fwrite($fp, "subj_prefix . "\"\n"); - fwrite($fp, " sender=\"" . $this->sender . "\"\n"); - fwrite($fp, " replyto=\"" . $this->replyto . "\">\n"); - fwrite($fp, "
" . $this->footer . "
\n"); + fwrite($fp, "subj_prefix) . "\"\n"); + fwrite($fp, " sender=\"" . xmlenc($this->sender) . "\"\n"); + fwrite($fp, " replyto=\"" . xmlenc($this->replyto) . "\">\n"); + fwrite($fp, "
" . xmlenc($this->footer) . "
\n"); foreach($this->mailinglist as $email) { - fwrite($fp, " email, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " url=\"" . $email->url . "\">\n"); - fwrite($fp, " name=\"" . $email->name . "\">\n"); + fwrite($fp, " email) . "\"\n"); + fwrite($fp, " url=\"" . xmlenc($email->url) . "\"\n"); + fwrite($fp, " name=\"" . xmlenc($email->name) . "\">\n"); fwrite($fp, " \n"); } fwrite($fp, "
\n"); @@ -77,7 +77,11 @@ class PressRelease { // Admin config public $admin_title = "Press release"; public $admin_submodules = array("Send" => "send", - "Config" => "config"); + "Config" => "config", + "Add receiver" => "add", + "Edit receiver" => "edit", + "Delete receiver" => "delete", + "View receivers" => "view"); public function admin_send($action, $vars) { @@ -133,16 +137,123 @@ class PressRelease { 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 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_add($action, $vars) + { + global $UID, $GLOBALS; + + switch($action) { + case "add": + $pemail = new PEmail($vars["email"], time()); + $pemail->url = $vars["url"]; + $pemail->name = $vars["name"]; + $this->mailinglist->add($pemail); + $this->mailinglist->write(); + break; + + default: + $form = new Form("add"); + $form->addWidget(new LineEdit("Email:", "email", "")); + $form->addWidget(new LineEdit("URL:", "url", "")); + $form->addWidget(new LineEdit("Name:", "name", "")); + $form->addWidget(new Button("Add")); + $form->render(); + break; + } + } + + public function admin_edit($action, $vars) + { + switch($action) { + case "write": + $email = $this->mailinglist->mailinglist[$vars["editid"]]; + $email->email = $vars["email"]; + $email->url = $vars["url"]; + $email->name = $vars["name"]; + $this->mailinglist->write(); + break; + + case "edit": + $email = $this->mailinglist->mailinglist[$vars["editid"]]; + + $form = new Form("write"); + $form->addWidget(new Hidden(array("editid" => $email->email))); + $form->addWidget(new LineEdit("Email:", "email", $email->email)); + $form->addWidget(new LineEdit("URL:", "url", $email->url)); + $form->addWidget(new LineEdit("Name:", "name", $email->name)); + $form->addWidget(new Button("Edit")); + $form->render(); + break; + + default: + $rcvlist = array(); + foreach($this->mailinglist->mailinglist as $m) { + $title = $m->name . " (".$m->email.")"; + $rcvlist[$title] = $m->email; + } + + ksort($rcvlist); + + $form = new Form("edit"); + $form->addWidget(new ComboBox("Select receiver to edit:", "editid", "", $rcvlist)); + $form->addWidget(new Button("Edit...")); + $form->render(); + break; + } + } + + public function admin_delete($action, $vars) + { + switch($action) { + case "delete": + $this->mailinglist->remove($vars["delrcv"]); + $this->mailinglist->write(); + break; + + default: + $rcvlist = array(); + foreach($this->mailinglist->mailinglist as $m) { + $title = $m->name . " (".$m->email.")"; + $rcvlist[$title] = $m->email; + } + + ksort($rcvlist); + + $form = new Form("delete"); + $form->addWidget(new ComboBox("Select receiver to delete:", "delrcv", "", $rcvlist)); + $form->addWidget(new Button("Delete")); + $form->render(); + break; + } + } + + public function admin_view($action, $vars) + { + switch($action) { + default: + echo "

There are " . sizeof($this->mailinglist->mailinglist) . " receivers:

\n"; + echo "
    \n"; + foreach($this->mailinglist->mailinglist as $m) { + echo "
  • ".xmlenc($m->name)." (url)."\">".$m->url."): ".xmlenc($m->email)."
  • \n"; + } + echo "
\n"; + break; + } + } + public function admin($sub, $action, $vars) { switch($sub) { @@ -153,6 +264,22 @@ class PressRelease { case "config": $this->admin_config($action, $vars); break; + + case "add": + $this->admin_add($action, $vars); + break; + + case "edit": + $this->admin_edit($action, $vars); + break; + + case "delete": + $this->admin_delete($action, $vars); + break; + + case "view": + $this->admin_view($action, $vars); + break; } } -- cgit v1.2.3