4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2005 The Nucleus Group
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
11 * (see nucleus/documentation/index.html#license for more info)
\r
13 * Actions that can be called via action.php
\r
15 * $Id: ACTION.php,v 1.2 2005-03-12 06:19:04 kimitake Exp $
\r
25 function doAction($action)
\r
29 return $this->addComment();
\r
32 return $this->sendMessage();
\r
34 case 'createaccount':
\r
35 return $this->createAccount();
\r
37 case 'forgotpassword':
\r
38 return $this->forgotPassword();
\r
40 case 'votepositive':
\r
41 return $this->doKarma('pos');
\r
43 case 'votenegative':
\r
44 return $this->doKarma('neg');
\r
47 return $this->callPlugin();
\r
50 doError(_ERROR_BADACTION);
\r
54 function addComment() {
\r
55 global $CONF, $errormessage, $manager;
\r
57 $post['itemid'] = intPostVar('itemid');
\r
58 $post['user'] = postVar('user');
\r
59 $post['userid'] = postVar('userid');
\r
60 $post['body'] = postVar('body');
\r
62 // set cookies when required
\r
63 $remember = intPostVar('remember');
\r
64 if ($remember == 1) {
\r
65 $lifetime = time()+2592000;
\r
66 setcookie($CONF['CookiePrefix'] . 'comment_user',$post['user'],$lifetime,'/','',0);
\r
67 setcookie($CONF['CookiePrefix'] . 'comment_userid', $post['userid'],$lifetime,'/','',0);
\r
70 $comments = new COMMENTS($post['itemid']);
\r
72 $blogid = getBlogIDFromItemID($post['itemid']);
\r
73 $this->checkban($blogid);
\r
74 $blog =& $manager->getBlog($blogid);
\r
76 // note: PreAddComment and PostAddComment gets called somewhere inside addComment
\r
77 $errormessage = $comments->addComment($blog->getCorrectTime(),$post);
\r
79 if ($errormessage == '1') {
\r
80 // redirect when adding comments succeeded
\r
81 if (postVar('url')) {
\r
82 redirect(postVar('url'));
\r
84 $url = $CONF['IndexURL'] . createItemLink($post['itemid']);
\r
88 // else, show error message using default skin for blog
\r
90 'message' => $errormessage,
\r
91 'skinid' => $blog->getDefaultSkin()
\r
98 // Sends a message from the current member to the member given as argument
\r
99 function sendMessage() {
\r
100 global $CONF, $member;
\r
102 $error = $this->validateMessage();
\r
104 return array('message' => $error);
\r
106 if (!$member->isLoggedIn()) {
\r
107 $fromMail = postVar('frommail');
\r
108 $fromName = _MMAIL_FROMANON;
\r
110 $fromMail = $member->getEmail();
\r
111 $fromName = $member->getDisplayName();
\r
114 $tomem = new MEMBER();
\r
115 $tomem->readFromId(postVar('memberid'));
\r
117 $message = _MMAIL_MSG . ' ' . $fromName . "\n"
\r
118 . '(' . _MMAIL_FROMNUC. ' ' . $CONF['IndexURL'] .") \n\n"
\r
119 . _MMAIL_MAIL . " \n\n"
\r
120 . postVar('message');
\r
121 $message .= getMailFooter();
\r
123 $title = _MMAIL_TITLE . ' ' . $fromName;
\r
125 mb_internal_encoding(_CHARSET);
\r
126 @mb_send_mail($tomem->getEmail(), $title, $message, "From: ". $fromMail);
\r
128 if (postVar('url')) {
\r
129 redirect(postVar('url'));
\r
131 $CONF['MemberURL'] = $CONF['IndexURL'];
\r
132 if ($CONF['URLMode'] == 'pathinfo')
\r
133 $url = createMemberLink($tomem->getID());
\r
135 $url = $CONF['IndexURL'] . createMemberLink($tomem->getID());
\r
143 function validateMessage() {
\r
144 global $CONF, $member, $manager;
\r
146 if (!$CONF['AllowMemberMail'])
\r
147 return _ERROR_MEMBERMAILDISABLED;
\r
149 if (!$member->isLoggedIn() && !$CONF['NonmemberMail'])
\r
150 return _ERROR_DISALLOWED;
\r
152 if (!$member->isLoggedIn() && (!isValidMailAddress(postVar('frommail'))))
\r
153 return _ERROR_BADMAILADDRESS;
\r
155 // let plugins do verification (any plugin which thinks the comment is invalid
\r
156 // can change 'error' to something other than '')
\r
158 $manager->notify('ValidateForm', array('type' => 'membermail', 'error' => &$result));
\r
164 // creates a new user account
\r
165 function createAccount() {
\r
166 global $CONF, $manager;
\r
168 if (!$CONF['AllowMemberCreate'])
\r
169 doError(_ERROR_MEMBERCREATEDISABLED);
\r
171 // even though the member can not log in, set some random initial password. One never knows.
\r
172 srand((double)microtime()*1000000);
\r
173 $initialPwd = md5(uniqid(rand(), true));
\r
175 // create member (non admin/can not login/no notes/random string as password)
\r
176 $r = MEMBER::create(postVar('name'), postVar('realname'), $initialPwd, postVar('email'), postVar('url'), 0, 0, '');
\r
181 // send message containing password.
\r
182 $newmem = new MEMBER();
\r
183 $newmem->readFromName(postVar('name'));
\r
184 $newmem->sendActivationLink('register');
\r
186 $manager->notify('PostRegister',array('member' => &$newmem));
\r
188 if (postVar('desturl')) {
\r
189 redirect(postVar('desturl'));
\r
191 header ("Content-Type: text/html; charset="._CHARSET);
\r
192 echo _MSG_ACTIVATION_SENT;
\r
198 // sends a new password
\r
199 function forgotPassword() {
\r
200 $membername = trim(postVar('name'));
\r
202 if (!MEMBER::exists($membername))
\r
203 doError(_ERROR_NOSUCHMEMBER);
\r
204 $mem = MEMBER::createFromName($membername);
\r
206 if (!$mem->canLogin())
\r
207 doError(_ERROR_NOLOGON_NOACTIVATE);
\r
209 // check if e-mail address is correct
\r
210 if (!($mem->getEmail() == postVar('email')))
\r
211 doError(_ERROR_INCORRECTEMAIL);
\r
213 // send activation link
\r
214 $mem->sendActivationLink('forgot');
\r
216 if (postVar('url')) {
\r
217 redirect(postVar('url'));
\r
219 header ("Content-Type: text/html; charset="._CHARSET);
\r
220 echo _MSG_ACTIVATION_SENT;
\r
226 // handle karma votes
\r
227 function doKarma($type) {
\r
228 global $itemid, $member, $CONF, $manager;
\r
230 // check if itemid exists
\r
231 if (!$manager->existsItem($itemid,0,0))
\r
232 doError(_ERROR_NOSUCHITEM);
\r
234 $blogid = getBlogIDFromItemID($itemid);
\r
235 $this->checkban($blogid);
\r
237 $karma =& $manager->getKarma($itemid);
\r
239 // check if not already voted
\r
240 if (!$karma->isVoteAllowed(serverVar('REMOTE_ADDR')))
\r
241 doError(_ERROR_VOTEDBEFORE);
\r
243 // check if item does allow voting
\r
244 $item =& $manager->getItem($itemid,0,0);
\r
245 if ($item['closed'])
\r
246 doError(_ERROR_ITEMCLOSED);
\r
250 $karma->votePositive();
\r
253 $karma->voteNegative();
\r
257 $blogid = getBlogIDFromItemID($itemid);
\r
258 $blog =& $manager->getBlog($blogid);
\r
260 // send email to notification address, if any
\r
261 if ($blog->getNotifyAddress() && $blog->notifyOnVote()) {
\r
263 $mailto_msg = _NOTIFY_KV_MSG . ' ' . $itemid . "\n";
\r
264 $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n";
\r
265 if ($member->isLoggedIn()) {
\r
266 $mailto_msg .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
\r
268 $mailto_msg .= _NOTIFY_IP . ' ' . serverVar('REMOTE_ADDR') . "\n";
\r
269 $mailto_msg .= _NOTIFY_HOST . ' ' . gethostbyaddr(serverVar('REMOTE_ADDR')) . "\n";
\r
270 $mailto_msg .= _NOTIFY_VOTE . "\n " . $type . "\n";
\r
271 $mailto_msg .= getMailFooter();
\r
273 $mailto_title = _NOTIFY_KV_TITLE . ' ' . strip_tags($item['title']) . ' (' . $itemid . ')';
\r
275 $frommail = $member->getNotifyFromMailAddress();
\r
277 $notify = new NOTIFICATION($blog->getNotifyAddress());
\r
278 $notify->notify($mailto_title, $mailto_msg , $frommail);
\r
282 $refererUrl = serverVar('HTTP_REFERER');
\r
284 $url = $refererUrl;
\r
286 $url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid;
\r
293 * Calls a plugin action
\r
295 function callPlugin() {
\r
298 $pluginName = 'NP_' . requestVar('name');
\r
299 $actionType = requestVar('type');
\r
301 // 1: check if plugin is installed
\r
302 if (!$manager->pluginInstalled($pluginName))
\r
303 doError(_ERROR_NOSUCHPLUGIN);
\r
306 $pluginObject =& $manager->getPlugin($pluginName);
\r
308 $error = $pluginObject->doAction($actionType);
\r
310 $error = 'Could not load plugin (see actionlog)';
\r
312 // doAction returns error when:
\r
313 // - an error occurred (duh)
\r
314 // - no actions are allowed (doAction is not implemented)
\r
322 function checkban($blogid) {
\r
324 $ban = BAN::isBanned($blogid, serverVar('REMOTE_ADDR'));
\r
326 doError(_ERROR_BANNED1 . $ban->iprange . _ERROR_BANNED2 . $ban->message . _ERROR_BANNED3);
\r