4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2009 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-2009 The Nucleus Group
18 * @version $Id: ACTION.php 1522 2011-06-21 09:46:14Z sakamocchi $
24 * Constructor for an new ACTION object
33 * Calls functions that handle an action called from action.php
35 function doAction($action)
40 return $this->autoDraft();
44 return $this->updateTicket();
48 return $this->addComment();
52 return $this->sendMessage();
56 return $this->createAccount();
59 case 'forgotpassword':
60 return $this->forgotPassword();
64 return $this->doKarma('pos');
68 return $this->doKarma('neg');
72 return $this->callPlugin();
76 doError(_ERROR_BADACTION);
83 * Adds a new comment to an item (if IP isn't banned)
87 global $CONF, $errormessage, $manager;
89 $post['itemid'] = intPostVar('itemid');
90 $post['user'] = postVar('user');
91 $post['userid'] = postVar('userid');
92 $post['email'] = postVar('email');
93 $post['body'] = postVar('body');
94 $post['remember'] = intPostVar('remember');
96 // set cookies when required
97 #$remember = intPostVar('remember');
99 // begin if: "Remember Me" box checked
100 if ( $post['remember'] == 1 )
102 $lifetime = time() + 2592000;
103 setcookie($CONF['CookiePrefix'] . 'comment_user', $post['user'], $lifetime, '/', '', 0);
104 setcookie($CONF['CookiePrefix'] . 'comment_userid', $post['userid'], $lifetime, '/', '', 0);
105 setcookie($CONF['CookiePrefix'] . 'comment_email', $post['email'], $lifetime, '/', '', 0);
108 $comments = new COMMENTS($post['itemid']);
110 $blog_id = getBlogIDFromItemID($post['itemid']);
111 $this->checkban($blog_id);
112 $blog =& $manager->getBlog($blog_id);
114 // note: PreAddComment and PostAddComment gets called somewhere inside addComment
115 $errormessage = $comments->addComment($blog->getCorrectTime(), $post);
118 if ( $errormessage == '1' )
120 // redirect when adding comments succeeded
121 if ( postVar('url') )
123 redirect(postVar('url') );
127 $url = createItemLink($post['itemid']);
132 // else, show error message using default skin for blo
136 'message' => $errormessage,
137 'skinid' => $blog->getDefaultSkin()
146 * Sends a message from the current member to the member given as argument
148 function sendMessage()
150 global $CONF, $member;
152 $error = $this->validateMessage();
156 return array('message' => $error);
159 if ( !$member->isLoggedIn() )
161 $fromMail = postVar('frommail');
162 $fromName = _MMAIL_FROMANON;
166 $fromMail = $member->getEmail();
167 $fromName = $member->getDisplayName();
170 $tomem = new MEMBER();
171 $tomem->readFromId(postVar('memberid') );
173 $message = _MMAIL_MSG . ' ' . $fromName . "\n"
174 . '(' . _MMAIL_FROMNUC. ' ' . $CONF['IndexURL'] .") \n\n"
175 . _MMAIL_MAIL . " \n\n"
176 . postVar('message');
177 $message .= getMailFooter();
179 $title = _MMAIL_TITLE . ' ' . $fromName;
180 i18n::mail($tomem->getEmail(), $title, $message, $fromMail);
182 if ( postVar('url') )
184 redirect(postVar('url') );
188 $CONF['MemberURL'] = $CONF['IndexURL'];
190 if ( $CONF['URLMode'] == 'pathinfo' )
192 $url = createLink('member', array('memberid' => $tomem->getID(), 'name' => $tomem->getDisplayName() ) );
196 $url = $CONF['IndexURL'] . createMemberLink($tomem->getID());
206 * Checks if a mail to a member is allowed
207 * Returns a string with the error message if the mail is disallowed
209 function validateMessage()
211 global $CONF, $member, $manager;
213 if ( !$CONF['AllowMemberMail'] )
215 return _ERROR_MEMBERMAILDISABLED;
218 if ( !$member->isLoggedIn() && !$CONF['NonmemberMail'] )
220 return _ERROR_DISALLOWED;
223 if ( !$member->isLoggedIn() && (!isValidMailAddress(postVar('frommail') ) ) )
225 return _ERROR_BADMAILADDRESS;
228 // let plugins do verification (any plugin which thinks the comment is invalid
229 // can change 'error' to something other than '')
231 $manager->notify('ValidateForm', array('type' => 'membermail', 'error' => &$result) );
239 * Creates a new user account
241 function createAccount()
243 global $CONF, $manager;
245 if ( !$CONF['AllowMemberCreate'] )
247 doError(_ERROR_MEMBERCREATEDISABLED);
250 // evaluate content from FormExtra
252 $data = array('type' => 'membermail', 'error' => &$result);
253 $manager->notify('ValidateForm', &$data);
262 // even though the member can not log in, set some random initial password. One never knows.
263 srand( (double) microtime() * 1000000);
264 $initialPwd = md5(uniqid(rand(), TRUE) );
266 // create member (non admin/can not login/no notes/random string as password)
267 $name = shorten(postVar('name'), 32, '');
268 $r = MEMBER::create($name, postVar('realname'), $initialPwd, postVar('email'), postVar('url'), 0, 0, '');
275 // send message containing password.
276 $newmem = new MEMBER();
277 $newmem->readFromName($name);
278 $newmem->sendActivationLink('register');
280 $manager->notify('PostRegister', array('member' => &$newmem) );
282 if ( postVar('desturl') )
284 redirect(postVar('desturl') );
288 echo _MSG_ACTIVATION_SENT;
289 echo '<br /><br />Return to <a href="'.$CONF['IndexURL'].'" title="'.$CONF['SiteName'].'">'.$CONF['SiteName'].'</a>';
290 echo "\n</body>\n</html>";
300 * Sends a new password
302 function forgotPassword()
304 $membername = trim(postVar('name') );
306 if ( !MEMBER::exists($membername) )
308 doError(_ERROR_NOSUCHMEMBER);
311 $mem = MEMBER::createFromName($membername);
313 /* below keeps regular users from resetting passwords using forgot password feature
314 Removing for now until clear why it is required.*/
315 /*if (!$mem->canLogin())
316 doError(_ERROR_NOLOGON_NOACTIVATE);*/
318 // check if e-mail address is correct
319 if ( !($mem->getEmail() == postVar('email') ) )
321 doError(_ERROR_INCORRECTEMAIL);
324 // send activation link
325 $mem->sendActivationLink('forgot');
327 if ( postVar('url') )
329 redirect(postVar('url') );
333 echo _MSG_ACTIVATION_SENT;
334 echo '<br /><br />Return to <a href="'.$CONF['IndexURL'].'" title="'.$CONF['SiteName'].'">'.$CONF['SiteName'].'</a>';
344 function doKarma($type)
346 global $itemid, $member, $CONF, $manager;
348 // check if itemid exists
349 if ( !$manager->existsItem($itemid, 0, 0) )
351 doError(_ERROR_NOSUCHITEM);
354 $blogid = getBlogIDFromItemID($itemid);
355 $this->checkban($blogid);
357 $karma =& $manager->getKarma($itemid);
359 // check if not already voted
360 if ( !$karma->isVoteAllowed(serverVar('REMOTE_ADDR') ) )
362 doError(_ERROR_VOTEDBEFORE);
365 // check if item does allow voting
366 $item =& $manager->getItem($itemid, 0, 0);
368 if ( $item['closed'] )
370 doError(_ERROR_ITEMCLOSED);
376 $karma->votePositive();
380 $karma->voteNegative();
384 // $blogid = getBlogIDFromItemID($itemid);
385 $blog =& $manager->getBlog($blogid);
387 // send email to notification address, if any
388 if ( $blog->getNotifyAddress() && $blog->notifyOnVote() )
391 $mailto_msg = _NOTIFY_KV_MSG . ' ' . $itemid . "\n";
392 // if ($CONF['URLMode'] == 'pathinfo') {
393 // $itemLink = createItemLink(intval($itemid));
395 // $itemLink = $CONF['IndexURL'] . createItemLink(intval($itemid));
397 // $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n";
398 $itemLink = createItemLink(intval($itemid) );
399 $temp = parse_url($itemLink);
401 if ( !$temp['scheme'] )
403 $itemLink = $CONF['IndexURL'] . $itemLink;
406 $mailto_msg .= $itemLink . "\n\n";
408 if ( $member->isLoggedIn() )
410 $mailto_msg .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
413 $mailto_msg .= _NOTIFY_IP . ' ' . serverVar('REMOTE_ADDR') . "\n";
414 $mailto_msg .= _NOTIFY_HOST . ' ' . gethostbyaddr(serverVar('REMOTE_ADDR')) . "\n";
415 $mailto_msg .= _NOTIFY_VOTE . "\n " . $type . "\n";
416 $mailto_msg .= getMailFooter();
418 $mailto_title = _NOTIFY_KV_TITLE . ' ' . strip_tags($item['title']) . ' (' . $itemid . ')';
420 $frommail = $member->getNotifyFromMailAddress();
422 $notify = new NOTIFICATION($blog->getNotifyAddress() );
423 $notify->notify($mailto_title, $mailto_msg, $frommail);
426 $refererUrl = serverVar('HTTP_REFERER');
434 // $url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid;
444 * Calls a plugin action
446 function callPlugin()
450 $pluginName = 'NP_' . requestVar('name');
451 $actionType = requestVar('type');
453 // 1: check if plugin is installed
454 if ( !$manager->pluginInstalled($pluginName) )
456 doError(_ERROR_NOSUCHPLUGIN);
460 $pluginObject =& $manager->getPlugin($pluginName);
464 $error = $pluginObject->doAction($actionType);
468 $error = 'Could not load plugin (see actionlog)';
471 // doAction returns error when:
472 // - an error occurred (duh)
473 // - no actions are allowed (doAction is not implemented)
485 * Checks if an IP or IP range is banned
487 function checkban($blogid)
490 $ban = BAN::isBanned($blogid, serverVar('REMOTE_ADDR') );
494 doError(_ERROR_BANNED1 . $ban->iprange . _ERROR_BANNED2 . $ban->message . _ERROR_BANNED3);
503 function updateTicket()
507 if ( $manager->checkTicket() )
509 echo $manager->getNewTicket();
513 echo _ERROR . ':' . _ERROR_BADTICKET;
521 * Handles AutoSaveDraft
527 if ( $manager->checkTicket() )
529 $manager->loadClass('ITEM');
530 $info = ITEM::createDraftFromRequest();
532 if ( $info['status'] == 'error' )
534 echo $info['message'];
538 echo $info['draftid'];
543 echo _ERROR . ':' . _ERROR_BADTICKET;