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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
<?php
/* * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) * Copyright (C) 2002-2005 The Nucleus Group * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * (see nucleus/documentation/index.html#license for more info) */ /** * Actions that can be called via action.php * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2005 The Nucleus Group * @version $Id: ACTION.php,v 1.6.2.1 2005/08/15 10:50:12 dekarma Exp $ */ class ACTION { function ACTION() { } function doAction($action) { switch($action) { case 'addcomment': return $this->addComment(); break; case 'sendmessage': return $this->sendMessage(); break; case 'createaccount': return $this->createAccount(); break; case 'forgotpassword': return $this->forgotPassword(); break; case 'votepositive': return $this->doKarma('pos'); break; case 'votenegative': return $this->doKarma('neg'); break; case 'plugin': return $this->callPlugin(); break; default: doError(_ERROR_BADACTION); } } function addComment() { global $CONF, $errormessage, $manager;
$post['itemid'] = intPostVar('itemid'); $post['user'] = postVar('user'); $post['userid'] = postVar('userid'); $post['body'] = postVar('body');
// set cookies when required $remember = intPostVar('remember'); if ($remember == 1) { $lifetime = time()+2592000; setcookie($CONF['CookiePrefix'] . 'comment_user',$post['user'],$lifetime,'/','',0); setcookie($CONF['CookiePrefix'] . 'comment_userid', $post['userid'],$lifetime,'/','',0); }
$comments = new COMMENTS($post['itemid']);
$blogid = getBlogIDFromItemID($post['itemid']); $this->checkban($blogid); $blog =& $manager->getBlog($blogid);
// note: PreAddComment and PostAddComment gets called somewhere inside addComment $errormessage = $comments->addComment($blog->getCorrectTime(),$post);
if ($errormessage == '1') { // redirect when adding comments succeeded if (postVar('url')) { redirect(postVar('url')); } else { $url = $CONF['IndexURL'] . createItemLink($post['itemid']); redirect($url); } } else { // else, show error message using default skin for blog return array( 'message' => $errormessage, 'skinid' => $blog->getDefaultSkin() ); } exit; }
// Sends a message from the current member to the member given as argument function sendMessage() { global $CONF, $member;
$error = $this->validateMessage(); if ($error != '') return array('message' => $error);
if (!$member->isLoggedIn()) { $fromMail = postVar('frommail'); $fromName = _MMAIL_FROMANON; } else { $fromMail = $member->getEmail(); $fromName = $member->getDisplayName(); }
$tomem = new MEMBER(); $tomem->readFromId(postVar('memberid'));
$message = _MMAIL_MSG . ' ' . $fromName . "\n" . '(' . _MMAIL_FROMNUC. ' ' . $CONF['IndexURL'] .") \n\n" . _MMAIL_MAIL . " \n\n" . postVar('message'); $message .= getMailFooter();
$title = _MMAIL_TITLE . ' ' . $fromName; mail($tomem->getEmail(), $title, $message, 'From: '. $fromMail);
if (postVar('url')) { redirect(postVar('url')); } else { $CONF['MemberURL'] = $CONF['IndexURL']; if ($CONF['URLMode'] == 'pathinfo') { $url = createLink('member', array('memberid' => $tomem->getID(), 'name' => $tomem->getDisplayName())); } else { $url = $CONF['IndexURL'] . createMemberLink($tomem->getID()); } redirect($url); } exit;
} function validateMessage() { global $CONF, $member, $manager;
if (!$CONF['AllowMemberMail']) return _ERROR_MEMBERMAILDISABLED;
if (!$member->isLoggedIn() && !$CONF['NonmemberMail']) return _ERROR_DISALLOWED;
if (!$member->isLoggedIn() && (!isValidMailAddress(postVar('frommail')))) return _ERROR_BADMAILADDRESS; // let plugins do verification (any plugin which thinks the comment is invalid // can change 'error' to something other than '') $result = ''; $manager->notify('ValidateForm', array('type' => 'membermail', 'error' => &$result)); return $result; }
// creates a new user account function createAccount() { global $CONF, $manager;
if (!$CONF['AllowMemberCreate']) doError(_ERROR_MEMBERCREATEDISABLED);
// even though the member can not log in, set some random initial password. One never knows. srand((double)microtime()*1000000); $initialPwd = md5(uniqid(rand(), true));
// create member (non admin/can not login/no notes/random string as password) $r = MEMBER::create(postVar('name'), postVar('realname'), $initialPwd, postVar('email'), postVar('url'), 0, 0, ''); if ($r != 1) doError($r); // send message containing password. $newmem = new MEMBER(); $newmem->readFromName(postVar('name')); $newmem->sendActivationLink('register');
$manager->notify('PostRegister',array('member' => &$newmem));
if (postVar('desturl')) { redirect(postVar('desturl')); } else { echo _MSG_ACTIVATION_SENT; } exit; }
// sends a new password function forgotPassword() { $membername = trim(postVar('name'));
if (!MEMBER::exists($membername)) doError(_ERROR_NOSUCHMEMBER); $mem = MEMBER::createFromName($membername);
if (!$mem->canLogin()) doError(_ERROR_NOLOGON_NOACTIVATE);
// check if e-mail address is correct if (!($mem->getEmail() == postVar('email'))) doError(_ERROR_INCORRECTEMAIL);
// send activation link $mem->sendActivationLink('forgot');
if (postVar('url')) { redirect(postVar('url')); } else { echo _MSG_ACTIVATION_SENT; } exit; }
// handle karma votes function doKarma($type) { global $itemid, $member, $CONF, $manager;
// check if itemid exists if (!$manager->existsItem($itemid,0,0)) doError(_ERROR_NOSUCHITEM);
$blogid = getBlogIDFromItemID($itemid); $this->checkban($blogid);
$karma =& $manager->getKarma($itemid);
// check if not already voted if (!$karma->isVoteAllowed(serverVar('REMOTE_ADDR'))) doError(_ERROR_VOTEDBEFORE);
// check if item does allow voting $item =& $manager->getItem($itemid,0,0); if ($item['closed']) doError(_ERROR_ITEMCLOSED);
switch($type) { case 'pos': $karma->votePositive(); break; case 'neg': $karma->voteNegative(); break; }
$blogid = getBlogIDFromItemID($itemid); $blog =& $manager->getBlog($blogid);
// send email to notification address, if any if ($blog->getNotifyAddress() && $blog->notifyOnVote()) {
$mailto_msg = _NOTIFY_KV_MSG . ' ' . $itemid . "\n"; $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n"; if ($member->isLoggedIn()) { $mailto_msg .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n"; } $mailto_msg .= _NOTIFY_IP . ' ' . serverVar('REMOTE_ADDR') . "\n"; $mailto_msg .= _NOTIFY_HOST . ' ' . gethostbyaddr(serverVar('REMOTE_ADDR')) . "\n"; $mailto_msg .= _NOTIFY_VOTE . "\n " . $type . "\n"; $mailto_msg .= getMailFooter();
$mailto_title = _NOTIFY_KV_TITLE . ' ' . strip_tags($item['title']) . ' (' . $itemid . ')';
$frommail = $member->getNotifyFromMailAddress();
$notify = new NOTIFICATION($blog->getNotifyAddress()); $notify->notify($mailto_title, $mailto_msg , $frommail); }
$refererUrl = serverVar('HTTP_REFERER'); if ($refererUrl) $url = $refererUrl; else $url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid;
redirect($url); exit; }
/** * Calls a plugin action */ function callPlugin() { global $manager;
$pluginName = 'NP_' . requestVar('name'); $actionType = requestVar('type');
// 1: check if plugin is installed if (!$manager->pluginInstalled($pluginName)) doError(_ERROR_NOSUCHPLUGIN);
// 2: call plugin $pluginObject =& $manager->getPlugin($pluginName); if ($pluginObject) $error = $pluginObject->doAction($actionType); else $error = 'Could not load plugin (see actionlog)';
// doAction returns error when: // - an error occurred (duh) // - no actions are allowed (doAction is not implemented) if ($error) doError($error); exit;
}
function checkban($blogid) { // check if banned $ban = BAN::isBanned($blogid, serverVar('REMOTE_ADDR')); if ($ban != 0) { doError(_ERROR_BANNED1 . $ban->iprange . _ERROR_BANNED2 . $ban->message . _ERROR_BANNED3); }
}
}
?>
|