OSDN Git Service

sync with original 3.3
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / libs / ACTION.php
index ddbdc7d..b5e4def 100755 (executable)
@@ -1,29 +1,39 @@
 <?php
 
+/*
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
+ * Copyright (C) 2002-2007 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * (see nucleus/documentation/index.html#license for more info)
+ */
 /**
-  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 
-  * Copyright (C) 2002-2004 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
-  * as published by the Free Software Foundation; either version 2
-  * of the License, or (at your option) any later version.
-  * (see nucleus/documentation/index.html#license for more info)
-  *
-  * Actions that can be called via action.php
-  *
-  * $Id: ACTION.php,v 1.1.1.1 2005-02-28 07:14:43 kimitake Exp $
-  */
+ * Actions that can be called via action.php
+ *
+ * @license http://nucleuscms.org/license.txt GNU General Public License
+ * @copyright Copyright (C) 2002-2007 The Nucleus Group
+ * @version $Id: ACTION.php,v 1.7 2007-02-04 06:28:45 kimitake Exp $
+ * $NucleusJP: ACTION.php,v 1.6 2007/01/31 10:02:58 kimitake Exp $
+ */
 class ACTION
 {
        function ACTION()
        {
-       
+
        }
-       
-       function doAction($action) 
+
+       function doAction($action)
        {
                switch($action) {
+                       case 'autodraft':
+                               return $this->autoDraft();
+                               break;
+                       case 'updateticket':
+                               return $this->updateTicket();
+                               break;
                        case 'addcomment':
                                return $this->addComment();
                                break;
@@ -32,7 +42,7 @@ class ACTION
                                break;
                        case 'createaccount':
                                return $this->createAccount();
-                               break;          
+                               break;
                        case 'forgotpassword':
                                return $this->forgotPassword();
                                break;
@@ -49,13 +59,14 @@ class ACTION
                                doError(_ERROR_BADACTION);
                }
        }
-       
+
        function addComment() {
                global $CONF, $errormessage, $manager;
 
                $post['itemid'] =       intPostVar('itemid');
                $post['user'] =         postVar('user');
                $post['userid'] =       postVar('userid');
+               $post['email'] =   postVar('email');
                $post['body'] =         postVar('body');
 
                // set cookies when required
@@ -64,6 +75,7 @@ class ACTION
                        $lifetime = time()+2592000;
                        setcookie($CONF['CookiePrefix'] . 'comment_user',$post['user'],$lifetime,'/','',0);
                        setcookie($CONF['CookiePrefix'] . 'comment_userid', $post['userid'],$lifetime,'/','',0);
+                       setcookie($CONF['CookiePrefix'] . 'comment_email',  $post['email'], $lifetime,'/','',0);
                }
 
                $comments = new COMMENTS($post['itemid']);
@@ -75,12 +87,12 @@ class ACTION
                // note: PreAddComment and PostAddComment gets called somewhere inside addComment
                $errormessage = $comments->addComment($blog->getCorrectTime(),$post);
 
-               if ($errormessage == '1') {             
+               if ($errormessage == '1') {
                        // redirect when adding comments succeeded
                        if (postVar('url')) {
-                               redirect(postVar('url'));\r
-                       } else {\r
-                               $url = $CONF['IndexURL'] . createItemLink($post['itemid']);\r
+                               redirect(postVar('url'));
+                       } else {
+                               $url = createItemLink($post['itemid']);
                                redirect($url);
                        }
                } else {
@@ -90,7 +102,7 @@ class ACTION
                                'skinid' => $blog->getDefaultSkin()
                        );
                }
-               
+
                exit;
        }
 
@@ -120,7 +132,7 @@ class ACTION
                $message .= getMailFooter();
 
                $title = _MMAIL_TITLE . ' ' . $fromName;
-               @mb_language('ja');
+               mb_language('ja');
                mb_internal_encoding(_CHARSET);
                @mb_send_mail($tomem->getEmail(), $title, $message, "From: ". $fromMail);
 
@@ -129,20 +141,24 @@ class ACTION
                } else {
                        $CONF['MemberURL'] = $CONF['IndexURL'];
                        if ($CONF['URLMode'] == 'pathinfo')
-                               $url = createMemberLink($tomem->getID());
+                       {
+                               $url = createLink('member', array('memberid' => $tomem->getID(), 'name' => $tomem->getDisplayName()));
+                       }
                        else
+                       {
                                $url = $CONF['IndexURL'] . createMemberLink($tomem->getID());
+                       }
                        redirect($url);
                }
-               
+
                exit;
 
        }
-       
+
        function validateMessage() {
                global $CONF, $member, $manager;
 
-               if (!$CONF['AllowMemberMail']) 
+               if (!$CONF['AllowMemberMail'])
                        return _ERROR_MEMBERMAILDISABLED;
 
                if (!$member->isLoggedIn() && !$CONF['NonmemberMail'])
@@ -150,21 +166,21 @@ class ACTION
 
                if (!$member->isLoggedIn() && (!isValidMailAddress(postVar('frommail'))))
                        return _ERROR_BADMAILADDRESS;
-                       
+
                // let plugins do verification (any plugin which thinks the comment is invalid
                // can change 'error' to something other than '')
                $result = '';
                $manager->notify('ValidateForm', array('type' => 'membermail', 'error' => &$result));
-               
+
                return $result;
-               
+
        }
 
        // creates a new user account
        function createAccount() {
                global $CONF, $manager;
 
-               if (!$CONF['AllowMemberCreate']) 
+               if (!$CONF['AllowMemberCreate'])
                        doError(_ERROR_MEMBERCREATEDISABLED);
 
                // even though the member can not log in, set some random initial password. One never knows.
@@ -173,27 +189,28 @@ class ACTION
 
                // 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 ($r != 1)
                        doError($r);
-                       
+
                // send message containing password.
                $newmem = new MEMBER();
                $newmem->readFromName(postVar('name'));
                $newmem->sendActivationLink('register');
 
-               $manager->notify('PostRegister',array('member' => &$newmem));           
+               $manager->notify('PostRegister',array('member' => &$newmem));
 
                if (postVar('desturl')) {
                        redirect(postVar('desturl'));
                } else {
-                       echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"._MSG_ACTIVATION_SENT;
+                       header ("Content-Type: text/html; charset="._CHARSET);
+                       echo _MSG_ACTIVATION_SENT;
                }
-               
+
                exit;
        }
 
-       // sends a new password 
+       // sends a new password
        function forgotPassword() {
                $membername = trim(postVar('name'));
 
@@ -214,9 +231,10 @@ class ACTION
                if (postVar('url')) {
                        redirect(postVar('url'));
                } else {
-                       echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"._MSG_ACTIVATION_SENT;
+                       header ("Content-Type: text/html; charset="._CHARSET);
+                       echo _MSG_ACTIVATION_SENT;
                }
-               
+
                exit;
        }
 
@@ -225,17 +243,17 @@ class ACTION
                global $itemid, $member, $CONF, $manager;
 
                // check if itemid exists
-               if (!$manager->existsItem($itemid,0,0)) 
+               if (!$manager->existsItem($itemid,0,0))
                        doError(_ERROR_NOSUCHITEM);
 
                $blogid = getBlogIDFromItemID($itemid);
-               $this->checkban($blogid);       
+               $this->checkban($blogid);
 
                $karma =& $manager->getKarma($itemid);
 
                // check if not already voted
-               if (!$karma->isVoteAllowed(serverVar('REMOTE_ADDR'))) 
-                       doError(_ERROR_VOTEDBEFORE);            
+               if (!$karma->isVoteAllowed(serverVar('REMOTE_ADDR')))
+                       doError(_ERROR_VOTEDBEFORE);
 
                // check if item does allow voting
                $item =& $manager->getItem($itemid,0,0);
@@ -243,7 +261,7 @@ class ACTION
                        doError(_ERROR_ITEMCLOSED);
 
                switch($type) {
-                       case 'pos': 
+                       case 'pos':
                                $karma->votePositive();
                                break;
                        case 'neg':
@@ -282,7 +300,7 @@ class ACTION
                else
                        $url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid;
 
-               redirect($url); 
+               redirect($url);
                exit;
        }
 
@@ -311,7 +329,7 @@ class ACTION
                // - no actions are allowed (doAction is not implemented)
                if ($error)
                        doError($error);
-                       
+
                exit;
 
        }
@@ -325,6 +343,41 @@ class ACTION
 
        }
 
+       /**
+        * Gets a new ticket
+        */
+       function updateTicket() {
+               global $manager;
+               if ($manager->checkTicket()) {
+                       echo $manager->getNewTicket();
+               }
+               else {
+                       echo 'err:' . _ERROR_BADTICKET;
+               }
+               return false;
+       }
+
+       /**
+        * Handles AutoSaveDraft
+        */
+       function autoDraft() {
+               global $manager;
+               if ($manager->checkTicket()) {
+                       $manager->loadClass('ITEM');
+                       $info = ITEM::CreateDraftFromRequest();
+                       if ($info['status'] == 'error') {
+                               echo $info['message'];
+                       }
+                       else {
+                               echo $info['draftid'];
+                       }
+               }
+               else {
+                       echo 'err:' . _ERROR_BADTICKET;
+               }
+               return false;
+       }
+
 
 }