OSDN Git Service

Add some codes from 3.61. Currently files under /nucleus/libs and /nucleus/libs/sql...
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / ACTION.php
index d9ad776..ea5c3c8 100755 (executable)
@@ -2,7 +2,7 @@
 
 /*
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2006 The Nucleus Group
+ * Copyright (C) 2002-2010 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
  * Actions that can be called via action.php
  *
  * @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2006 The Nucleus Group
- * @version $Id: ACTION.php,v 1.6 2007-01-31 10:02:58 kimitake Exp $
- * $NucleusJP: ACTION.php,v 1.5 2006/07/17 20:03:44 kimitake Exp $
+ * @copyright Copyright (C) 2002-2010 The Nucleus Group
+ * @version $Id$
+ * $NucleusJP: ACTION.php,v 1.10 2007/05/31 07:23:39 kimitake Exp $
  */
 class ACTION
 {
+       /**
+        *  Constructor for an new ACTION object
+        */
        function ACTION()
        {
-
+               // do nothing
        }
 
+       /**
+        *  Calls functions that handle an action called from action.php
+        */
        function doAction($action)
        {
                switch($action) {
@@ -60,14 +66,17 @@ class ACTION
                }
        }
 
+       /**
+        *  Adds a new comment to an item (if IP isn't banned)
+        */
        function addComment() {
                global $CONF, $errormessage, $manager;
 
-               $post['itemid'] =       intPostVar('itemid');
-               $post['user'] =         postVar('user');
-               $post['userid'] =       postVar('userid');
+               $post['itemid'] =   intPostVar('itemid');
+               $post['user'] =  postVar('user');
+               $post['userid'] =   postVar('userid');
                $post['email'] =   postVar('email');
-               $post['body'] =         postVar('body');
+               $post['body'] =  postVar('body');
 
                // set cookies when required
                $remember = intPostVar('remember');
@@ -106,7 +115,9 @@ class ACTION
                exit;
        }
 
-       // Sends a message from the current member to the member given as argument
+       /**
+        *  Sends a message from the current member to the member given as argument
+        */
        function sendMessage() {
                global $CONF, $member;
 
@@ -150,11 +161,13 @@ class ACTION
                        }
                        redirect($url);
                }
-
                exit;
-
        }
 
+       /**
+        *  Checks if a mail to a member is allowed
+        *  Returns a string with the error message if the mail is disallowed
+        */
        function validateMessage() {
                global $CONF, $member, $manager;
 
@@ -176,41 +189,60 @@ class ACTION
 
        }
 
-       // creates a new user account
+       /**
+        *  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));
+               // evaluate content from FormExtra
+               $result = 1;
+               $data = array('type' => 'membermail', 'error' => &$result);
+               $manager->notify('ValidateForm', &$data);
 
-               // 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 ($result!=1) {
+                       return $result;
+               }
+               else {
 
-               if ($r != 1)
-                       doError($r);
+                       // 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));
 
-               // send message containing password.
-               $newmem = new MEMBER();
-               $newmem->readFromName(postVar('name'));
-               $newmem->sendActivationLink('register');
+                       // create member (non admin/can not login/no notes/random string as password)
+                       $name = shorten(postVar('name'), 32, '');
+                       $r = MEMBER::create($name, postVar('realname'), $initialPwd, postVar('email'), postVar('url'), 0, 0, '');
 
-               $manager->notify('PostRegister',array('member' => &$newmem));
+                       if ($r != 1) {
+                               return $r;
+                       }
 
-               if (postVar('desturl')) {
-                       redirect(postVar('desturl'));
-               } else {
-                       header ("Content-Type: text/html; charset="._CHARSET);
-                       echo _MSG_ACTIVATION_SENT;
-               }
+                       // send message containing password.
+                       $newmem = new MEMBER();
+                       $newmem->readFromName($name);
+                       $newmem->sendActivationLink('register');
 
-               exit;
+                       $manager->notify('PostRegister',array('member' => &$newmem));
+
+                       if (postVar('desturl')) {
+                               redirect(postVar('desturl'));
+                       } else {
+                               // header has been already sent, so deleted the line below
+                               //header ("Content-Type: text/html; charset="._CHARSET);
+                               echo _MSG_ACTIVATION_SENT;
+                               echo '<br /><br />Return to <a href="'.$CONF['IndexURL'].'" title="'.$CONF['SiteName'].'">'.$CONF['SiteName'].'</a>';
+                               echo "\n</body>\n</html>";
+                       }
+                       exit;
+               }
        }
 
-       // sends a new password
+       /**
+        *  Sends a new password
+        */
        function forgotPassword() {
                $membername = trim(postVar('name'));
 
@@ -218,8 +250,10 @@ class ACTION
                        doError(_ERROR_NOSUCHMEMBER);
                $mem = MEMBER::createFromName($membername);
 
-               if (!$mem->canLogin())
-                       doError(_ERROR_NOLOGON_NOACTIVATE);
+               /* below keeps regular users from resetting passwords using forgot password feature
+                        Removing for now until clear why it is required.*/
+               /*if (!$mem->canLogin())
+                       doError(_ERROR_NOLOGON_NOACTIVATE);*/
 
                // check if e-mail address is correct
                if (!($mem->getEmail() == postVar('email')))
@@ -233,12 +267,14 @@ class ACTION
                } else {
                        header ("Content-Type: text/html; charset="._CHARSET);
                        echo _MSG_ACTIVATION_SENT;
+                       echo '<br /><br />Return to <a href="'.$CONF['IndexURL'].'" title="'.$CONF['SiteName'].'">'.$CONF['SiteName'].'</a>';
                }
-
                exit;
        }
 
-       // handle karma votes
+       /**
+        *  Handle karma votes
+        */
        function doKarma($type) {
                global $itemid, $member, $CONF, $manager;
 
@@ -269,14 +305,19 @@ class ACTION
                                break;
                }
 
-               $blogid = getBlogIDFromItemID($itemid);
+//             $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";
+                       $itemLink = createItemLink(intval($itemid));
+                       $temp = parse_url($itemLink);
+                       if (!$temp['scheme']) {
+                               $itemLink = $CONF['IndexURL'] . $itemLink;
+                       }
+                       $mailto_msg .= $itemLink . "\n\n";
                        if ($member->isLoggedIn()) {
                                $mailto_msg .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
                        }
@@ -295,10 +336,12 @@ class ACTION
 
 
                $refererUrl = serverVar('HTTP_REFERER');
-               if ($refererUrl)
+               if ($refererUrl) {
                        $url = $refererUrl;
-               else
-                       $url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid;
+               } else {
+//                     $url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid;
+                       $url = $itemLink;
+               }
 
                redirect($url);
                exit;
@@ -334,6 +377,9 @@ class ACTION
 
        }
 
+       /**
+        *  Checks if an IP or IP range is banned
+        */
        function checkban($blogid) {
                // check if banned
                $ban = BAN::isBanned($blogid, serverVar('REMOTE_ADDR'));
@@ -352,7 +398,7 @@ class ACTION
                        echo $manager->getNewTicket();
                }
                else {
-                       echo 'err:' . _ERROR_BADTICKET;
+                       echo _ERROR . ':' . _ERROR_BADTICKET;
                }
                return false;
        }
@@ -364,7 +410,7 @@ class ACTION
                global $manager;
                if ($manager->checkTicket()) {
                        $manager->loadClass('ITEM');
-                       $info = ITEM::CreateDraftFromRequest();
+                       $info = ITEM::createDraftFromRequest();
                        if ($info['status'] == 'error') {
                                echo $info['message'];
                        }
@@ -373,12 +419,9 @@ class ACTION
                        }
                }
                else {
-                       echo 'err:' . _ERROR_BADTICKET;
+                       echo _ERROR . ':' . _ERROR_BADTICKET;
                }
                return false;
        }
-
-
 }
-
 ?>
\ No newline at end of file