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
14 * Actions that can be called via action.php
\r
16 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
17 * @copyright Copyright (C) 2002-2005 The Nucleus Group
\r
18 * @version $Id: ACTION.php,v 1.3 2005-08-13 07:30:01 kimitake Exp $
\r
19 * $NucleusJP: ACTION.php,v 1.2 2005/03/12 06:19:04 kimitake Exp $
\r
28 function doAction($action)
\r
32 return $this->addComment();
\r
35 return $this->sendMessage();
\r
37 case 'createaccount':
\r
38 return $this->createAccount();
\r
40 case 'forgotpassword':
\r
41 return $this->forgotPassword();
\r
43 case 'votepositive':
\r
44 return $this->doKarma('pos');
\r
46 case 'votenegative':
\r
47 return $this->doKarma('neg');
\r
50 return $this->callPlugin();
\r
53 doError(_ERROR_BADACTION);
\r
57 function addComment() {
\r
58 global $CONF, $errormessage, $manager;
\r
60 $post['itemid'] = intPostVar('itemid');
\r
61 $post['user'] = postVar('user');
\r
62 $post['userid'] = postVar('userid');
\r
63 $post['body'] = postVar('body');
\r
65 // set cookies when required
\r
66 $remember = intPostVar('remember');
\r
67 if ($remember == 1) {
\r
68 $lifetime = time()+2592000;
\r
69 setcookie($CONF['CookiePrefix'] . 'comment_user',$post['user'],$lifetime,'/','',0);
\r
70 setcookie($CONF['CookiePrefix'] . 'comment_userid', $post['userid'],$lifetime,'/','',0);
\r
73 $comments = new COMMENTS($post['itemid']);
\r
75 $blogid = getBlogIDFromItemID($post['itemid']);
\r
76 $this->checkban($blogid);
\r
77 $blog =& $manager->getBlog($blogid);
\r
79 // note: PreAddComment and PostAddComment gets called somewhere inside addComment
\r
80 $errormessage = $comments->addComment($blog->getCorrectTime(),$post);
\r
82 if ($errormessage == '1') {
\r
83 // redirect when adding comments succeeded
\r
84 if (postVar('url')) {
\r
85 redirect(postVar('url'));
\r
87 $url = createItemLink($post['itemid']);
\r
91 // else, show error message using default skin for blog
\r
93 'message' => $errormessage,
\r
94 'skinid' => $blog->getDefaultSkin()
\r
101 // Sends a message from the current member to the member given as argument
\r
102 function sendMessage() {
\r
103 global $CONF, $member;
\r
105 $error = $this->validateMessage();
\r
107 return array('message' => $error);
\r
109 if (!$member->isLoggedIn()) {
\r
110 $fromMail = postVar('frommail');
\r
111 $fromName = _MMAIL_FROMANON;
\r
113 $fromMail = $member->getEmail();
\r
114 $fromName = $member->getDisplayName();
\r
117 $tomem = new MEMBER();
\r
118 $tomem->readFromId(postVar('memberid'));
\r
120 $message = _MMAIL_MSG . ' ' . $fromName . "\n"
\r
121 . '(' . _MMAIL_FROMNUC. ' ' . $CONF['IndexURL'] .") \n\n"
\r
122 . _MMAIL_MAIL . " \n\n"
\r
123 . postVar('message');
\r
124 $message .= getMailFooter();
\r
126 $title = _MMAIL_TITLE . ' ' . $fromName;
\r
128 mb_internal_encoding(_CHARSET);
\r
129 @mb_send_mail($tomem->getEmail(), $title, $message, "From: ". $fromMail);
\r
131 if (postVar('url')) {
\r
132 redirect(postVar('url'));
\r
134 $CONF['MemberURL'] = $CONF['IndexURL'];
\r
135 if ($CONF['URLMode'] == 'pathinfo')
\r
136 $url = createMemberLink($tomem->getID());
\r
138 $url = $CONF['IndexURL'] . createMemberLink($tomem->getID());
\r
146 function validateMessage() {
\r
147 global $CONF, $member, $manager;
\r
149 if (!$CONF['AllowMemberMail'])
\r
150 return _ERROR_MEMBERMAILDISABLED;
\r
152 if (!$member->isLoggedIn() && !$CONF['NonmemberMail'])
\r
153 return _ERROR_DISALLOWED;
\r
155 if (!$member->isLoggedIn() && (!isValidMailAddress(postVar('frommail'))))
\r
156 return _ERROR_BADMAILADDRESS;
\r
158 // let plugins do verification (any plugin which thinks the comment is invalid
\r
159 // can change 'error' to something other than '')
\r
161 $manager->notify('ValidateForm', array('type' => 'membermail', 'error' => &$result));
\r
167 // creates a new user account
\r
168 function createAccount() {
\r
169 global $CONF, $manager;
\r
171 if (!$CONF['AllowMemberCreate'])
\r
172 doError(_ERROR_MEMBERCREATEDISABLED);
\r
174 // even though the member can not log in, set some random initial password. One never knows.
\r
175 srand((double)microtime()*1000000);
\r
176 $initialPwd = md5(uniqid(rand(), true));
\r
178 // create member (non admin/can not login/no notes/random string as password)
\r
179 $r = MEMBER::create(postVar('name'), postVar('realname'), $initialPwd, postVar('email'), postVar('url'), 0, 0, '');
\r
184 // send message containing password.
\r
185 $newmem = new MEMBER();
\r
186 $newmem->readFromName(postVar('name'));
\r
187 $newmem->sendActivationLink('register');
\r
189 $manager->notify('PostRegister',array('member' => &$newmem));
\r
191 if (postVar('desturl')) {
\r
192 redirect(postVar('desturl'));
\r
194 header ("Content-Type: text/html; charset="._CHARSET);
\r
195 echo _MSG_ACTIVATION_SENT;
\r
201 // sends a new password
\r
202 function forgotPassword() {
\r
203 $membername = trim(postVar('name'));
\r
205 if (!MEMBER::exists($membername))
\r
206 doError(_ERROR_NOSUCHMEMBER);
\r
207 $mem = MEMBER::createFromName($membername);
\r
209 if (!$mem->canLogin())
\r
210 doError(_ERROR_NOLOGON_NOACTIVATE);
\r
212 // check if e-mail address is correct
\r
213 if (!($mem->getEmail() == postVar('email')))
\r
214 doError(_ERROR_INCORRECTEMAIL);
\r
216 // send activation link
\r
217 $mem->sendActivationLink('forgot');
\r
219 if (postVar('url')) {
\r
220 redirect(postVar('url'));
\r
222 header ("Content-Type: text/html; charset="._CHARSET);
\r
223 echo _MSG_ACTIVATION_SENT;
\r
229 // handle karma votes
\r
230 function doKarma($type) {
\r
231 global $itemid, $member, $CONF, $manager;
\r
233 // check if itemid exists
\r
234 if (!$manager->existsItem($itemid,0,0))
\r
235 doError(_ERROR_NOSUCHITEM);
\r
237 $blogid = getBlogIDFromItemID($itemid);
\r
238 $this->checkban($blogid);
\r
240 $karma =& $manager->getKarma($itemid);
\r
242 // check if not already voted
\r
243 if (!$karma->isVoteAllowed(serverVar('REMOTE_ADDR')))
\r
244 doError(_ERROR_VOTEDBEFORE);
\r
246 // check if item does allow voting
\r
247 $item =& $manager->getItem($itemid,0,0);
\r
248 if ($item['closed'])
\r
249 doError(_ERROR_ITEMCLOSED);
\r
253 $karma->votePositive();
\r
256 $karma->voteNegative();
\r
260 $blogid = getBlogIDFromItemID($itemid);
\r
261 $blog =& $manager->getBlog($blogid);
\r
263 // send email to notification address, if any
\r
264 if ($blog->getNotifyAddress() && $blog->notifyOnVote()) {
\r
266 $mailto_msg = _NOTIFY_KV_MSG . ' ' . $itemid . "\n";
\r
267 $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n";
\r
268 if ($member->isLoggedIn()) {
\r
269 $mailto_msg .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
\r
271 $mailto_msg .= _NOTIFY_IP . ' ' . serverVar('REMOTE_ADDR') . "\n";
\r
272 $mailto_msg .= _NOTIFY_HOST . ' ' . gethostbyaddr(serverVar('REMOTE_ADDR')) . "\n";
\r
273 $mailto_msg .= _NOTIFY_VOTE . "\n " . $type . "\n";
\r
274 $mailto_msg .= getMailFooter();
\r
276 $mailto_title = _NOTIFY_KV_TITLE . ' ' . strip_tags($item['title']) . ' (' . $itemid . ')';
\r
278 $frommail = $member->getNotifyFromMailAddress();
\r
280 $notify = new NOTIFICATION($blog->getNotifyAddress());
\r
281 $notify->notify($mailto_title, $mailto_msg , $frommail);
\r
285 $refererUrl = serverVar('HTTP_REFERER');
\r
287 $url = $refererUrl;
\r
289 $url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid;
\r
296 * Calls a plugin action
\r
298 function callPlugin() {
\r
301 $pluginName = 'NP_' . requestVar('name');
\r
302 $actionType = requestVar('type');
\r
304 // 1: check if plugin is installed
\r
305 if (!$manager->pluginInstalled($pluginName))
\r
306 doError(_ERROR_NOSUCHPLUGIN);
\r
309 $pluginObject =& $manager->getPlugin($pluginName);
\r
311 $error = $pluginObject->doAction($actionType);
\r
313 $error = 'Could not load plugin (see actionlog)';
\r
315 // doAction returns error when:
\r
316 // - an error occurred (duh)
\r
317 // - no actions are allowed (doAction is not implemented)
\r
325 function checkban($blogid) {
\r
327 $ban = BAN::isBanned($blogid, serverVar('REMOTE_ADDR'));
\r
329 doError(_ERROR_BANNED1 . $ban->iprange . _ERROR_BANNED2 . $ban->message . _ERROR_BANNED3);
\r