4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2005 The Nucleus Group
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * (see nucleus/documentation/index.html#license for more info)
14 * Actions that can be called via action.php
16 * @license http://nucleuscms.org/license.txt GNU General Public License
17 * @copyright Copyright (C) 2002-2005 The Nucleus Group
18 * @version $Id: ACTION.php,v 1.4 2006-07-12 07:11:47 kimitake Exp $
19 * $NucleusJP: ACTION.php,v 1.3 2005/08/13 07:30:01 kimitake Exp $
28 function doAction($action)
32 return $this->addComment();
35 return $this->sendMessage();
38 return $this->createAccount();
40 case 'forgotpassword':
41 return $this->forgotPassword();
44 return $this->doKarma('pos');
47 return $this->doKarma('neg');
50 return $this->callPlugin();
53 doError(_ERROR_BADACTION);
57 function addComment() {
58 global $CONF, $errormessage, $manager;
60 $post['itemid'] = intPostVar('itemid');
61 $post['user'] = postVar('user');
62 $post['userid'] = postVar('userid');
63 $post['body'] = postVar('body');
65 // set cookies when required
66 $remember = intPostVar('remember');
68 $lifetime = time()+2592000;
69 setcookie($CONF['CookiePrefix'] . 'comment_user',$post['user'],$lifetime,'/','',0);
70 setcookie($CONF['CookiePrefix'] . 'comment_userid', $post['userid'],$lifetime,'/','',0);
73 $comments = new COMMENTS($post['itemid']);
75 $blogid = getBlogIDFromItemID($post['itemid']);
76 $this->checkban($blogid);
77 $blog =& $manager->getBlog($blogid);
79 // note: PreAddComment and PostAddComment gets called somewhere inside addComment
80 $errormessage = $comments->addComment($blog->getCorrectTime(),$post);
82 if ($errormessage == '1') {
83 // redirect when adding comments succeeded
85 redirect(postVar('url'));
87 $url = createItemLink($post['itemid']);
91 // else, show error message using default skin for blog
93 'message' => $errormessage,
94 'skinid' => $blog->getDefaultSkin()
101 // Sends a message from the current member to the member given as argument
102 function sendMessage() {
103 global $CONF, $member;
105 $error = $this->validateMessage();
107 return array('message' => $error);
109 if (!$member->isLoggedIn()) {
110 $fromMail = postVar('frommail');
111 $fromName = _MMAIL_FROMANON;
113 $fromMail = $member->getEmail();
114 $fromName = $member->getDisplayName();
117 $tomem = new MEMBER();
118 $tomem->readFromId(postVar('memberid'));
120 $message = _MMAIL_MSG . ' ' . $fromName . "\n"
121 . '(' . _MMAIL_FROMNUC. ' ' . $CONF['IndexURL'] .") \n\n"
122 . _MMAIL_MAIL . " \n\n"
123 . postVar('message');
124 $message .= getMailFooter();
126 $title = _MMAIL_TITLE . ' ' . $fromName;
128 mb_internal_encoding(_CHARSET);
129 @mb_send_mail($tomem->getEmail(), $title, $message, "From: ". $fromMail);
131 if (postVar('url')) {
132 redirect(postVar('url'));
134 $CONF['MemberURL'] = $CONF['IndexURL'];
135 if ($CONF['URLMode'] == 'pathinfo')
137 $url = createLink('member', array('memberid' => $tomem->getID(), 'name' => $tomem->getDisplayName()));
141 $url = $CONF['IndexURL'] . createMemberLink($tomem->getID());
150 function validateMessage() {
151 global $CONF, $member, $manager;
153 if (!$CONF['AllowMemberMail'])
154 return _ERROR_MEMBERMAILDISABLED;
156 if (!$member->isLoggedIn() && !$CONF['NonmemberMail'])
157 return _ERROR_DISALLOWED;
159 if (!$member->isLoggedIn() && (!isValidMailAddress(postVar('frommail'))))
160 return _ERROR_BADMAILADDRESS;
162 // let plugins do verification (any plugin which thinks the comment is invalid
163 // can change 'error' to something other than '')
165 $manager->notify('ValidateForm', array('type' => 'membermail', 'error' => &$result));
171 // creates a new user account
172 function createAccount() {
173 global $CONF, $manager;
175 if (!$CONF['AllowMemberCreate'])
176 doError(_ERROR_MEMBERCREATEDISABLED);
178 // even though the member can not log in, set some random initial password. One never knows.
179 srand((double)microtime()*1000000);
180 $initialPwd = md5(uniqid(rand(), true));
182 // create member (non admin/can not login/no notes/random string as password)
183 $r = MEMBER::create(postVar('name'), postVar('realname'), $initialPwd, postVar('email'), postVar('url'), 0, 0, '');
188 // send message containing password.
189 $newmem = new MEMBER();
190 $newmem->readFromName(postVar('name'));
191 $newmem->sendActivationLink('register');
193 $manager->notify('PostRegister',array('member' => &$newmem));
195 if (postVar('desturl')) {
196 redirect(postVar('desturl'));
198 header ("Content-Type: text/html; charset="._CHARSET);
199 echo _MSG_ACTIVATION_SENT;
205 // sends a new password
206 function forgotPassword() {
207 $membername = trim(postVar('name'));
209 if (!MEMBER::exists($membername))
210 doError(_ERROR_NOSUCHMEMBER);
211 $mem = MEMBER::createFromName($membername);
213 if (!$mem->canLogin())
214 doError(_ERROR_NOLOGON_NOACTIVATE);
216 // check if e-mail address is correct
217 if (!($mem->getEmail() == postVar('email')))
218 doError(_ERROR_INCORRECTEMAIL);
220 // send activation link
221 $mem->sendActivationLink('forgot');
223 if (postVar('url')) {
224 redirect(postVar('url'));
226 header ("Content-Type: text/html; charset="._CHARSET);
227 echo _MSG_ACTIVATION_SENT;
233 // handle karma votes
234 function doKarma($type) {
235 global $itemid, $member, $CONF, $manager;
237 // check if itemid exists
238 if (!$manager->existsItem($itemid,0,0))
239 doError(_ERROR_NOSUCHITEM);
241 $blogid = getBlogIDFromItemID($itemid);
242 $this->checkban($blogid);
244 $karma =& $manager->getKarma($itemid);
246 // check if not already voted
247 if (!$karma->isVoteAllowed(serverVar('REMOTE_ADDR')))
248 doError(_ERROR_VOTEDBEFORE);
250 // check if item does allow voting
251 $item =& $manager->getItem($itemid,0,0);
253 doError(_ERROR_ITEMCLOSED);
257 $karma->votePositive();
260 $karma->voteNegative();
264 $blogid = getBlogIDFromItemID($itemid);
265 $blog =& $manager->getBlog($blogid);
267 // send email to notification address, if any
268 if ($blog->getNotifyAddress() && $blog->notifyOnVote()) {
270 $mailto_msg = _NOTIFY_KV_MSG . ' ' . $itemid . "\n";
271 $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n";
272 if ($member->isLoggedIn()) {
273 $mailto_msg .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
275 $mailto_msg .= _NOTIFY_IP . ' ' . serverVar('REMOTE_ADDR') . "\n";
276 $mailto_msg .= _NOTIFY_HOST . ' ' . gethostbyaddr(serverVar('REMOTE_ADDR')) . "\n";
277 $mailto_msg .= _NOTIFY_VOTE . "\n " . $type . "\n";
278 $mailto_msg .= getMailFooter();
280 $mailto_title = _NOTIFY_KV_TITLE . ' ' . strip_tags($item['title']) . ' (' . $itemid . ')';
282 $frommail = $member->getNotifyFromMailAddress();
284 $notify = new NOTIFICATION($blog->getNotifyAddress());
285 $notify->notify($mailto_title, $mailto_msg , $frommail);
289 $refererUrl = serverVar('HTTP_REFERER');
293 $url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid;
300 * Calls a plugin action
302 function callPlugin() {
305 $pluginName = 'NP_' . requestVar('name');
306 $actionType = requestVar('type');
308 // 1: check if plugin is installed
309 if (!$manager->pluginInstalled($pluginName))
310 doError(_ERROR_NOSUCHPLUGIN);
313 $pluginObject =& $manager->getPlugin($pluginName);
315 $error = $pluginObject->doAction($actionType);
317 $error = 'Could not load plugin (see actionlog)';
319 // doAction returns error when:
320 // - an error occurred (duh)
321 // - no actions are allowed (doAction is not implemented)
329 function checkban($blogid) {
331 $ban = BAN::isBanned($blogid, serverVar('REMOTE_ADDR'));
333 doError(_ERROR_BANNED1 . $ban->iprange . _ERROR_BANNED2 . $ban->message . _ERROR_BANNED3);