1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
<?php /* -*- mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
global $UTIL_DIR;
include_once($UTIL_DIR . "/mail.php");
include_once($UTIL_DIR . "/convert.php");
class PEmail extends Email {
public $url;
public $name;
};
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=\"" . xmlenc($this->subj_prefix) . "\"\n");
fwrite($fp, " sender=\"" . xmlenc($this->sender) . "\"\n");
fwrite($fp, " replyto=\"" . xmlenc($this->replyto) . "\">\n");
fwrite($fp, " <footer>" . xmlenc($this->footer) . "</footer>\n");
foreach($this->mailinglist as $email) {
fwrite($fp, " <email email=\"" . xmlenc($email->email) . "\"\n");
fwrite($fp, " url=\"" . xmlenc($email->url) . "\"\n");
fwrite($fp, " name=\"" . xmlenc($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" => "send",
"Config" => "config",
"Add receiver" => "add",
"Edit receiver" => "edit",
"Delete receiver" => "delete",
"View receivers" => "view");
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_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 "<p>There are " . sizeof($this->mailinglist->mailinglist) . " receivers:</p>\n";
echo "<ul>\n";
foreach($this->mailinglist->mailinglist as $m) {
echo " <li>".xmlenc($m->name)." (<a href=\"".xmlenc($m->url)."\">".$m->url."</a>): ".xmlenc($m->email)."</li>\n";
}
echo "</ul>\n";
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;
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;
}
}
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");
}
?>
|