OSDN Git Service

Just reviewing code formatting.
authorsakamocchi <sakamocchi@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Mon, 21 Mar 2011 02:05:19 +0000 (02:05 +0000)
committersakamocchi <sakamocchi@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Mon, 21 Mar 2011 02:05:19 +0000 (02:05 +0000)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@1170 1ca29b6e-896d-4ea0-84a5-967f57386b96

utf8/nucleus/libs/ACTION.php
utf8/nucleus/libs/COMMENT.php
utf8/nucleus/libs/COMMENTS.php

index 6827cbc..c526722 100755 (executable)
@@ -20,6 +20,7 @@
  */
 class ACTION
 {
+
        /**
         *  Constructor for an new ACTION object
         */
@@ -28,113 +29,147 @@ class ACTION
                // do nothing
        }
 
+
        /**
         *  Calls functions that handle an action called from action.php
         */
-       function doAction($action)
-       {
-               switch($action) {
-                       case 'autodraft':
-                               return $this->autoDraft();
-                               break;
-                       case 'updateticket':
-                               return $this->updateTicket();
-                               break;
-                       case 'addcomment':
-                               return $this->addComment();
-                               break;
-                       case 'sendmessage':
-                               return $this->sendMessage();
-                               break;
-                       case 'createaccount':
-                               return $this->createAccount();
-                               break;
-                       case 'forgotpassword':
-                               return $this->forgotPassword();
-                               break;
-                       case 'votepositive':
-                               return $this->doKarma('pos');
-                               break;
-                       case 'votenegative':
-                               return $this->doKarma('neg');
-                               break;
-                       case 'plugin':
-                               return $this->callPlugin();
-                               break;
-                       default:
-                               doError(_ERROR_BADACTION);
-               }
+       function doAction($action)\r
+       {\r
+               switch($action)\r
+               {\r
+                       case 'autodraft':\r
+                               return $this->autoDraft();\r
+                       break;\r
+               \r
+                       case 'updateticket':\r
+                               return $this->updateTicket();\r
+                       break;\r
+\r
+                       case 'addcomment':\r
+                               return $this->addComment();\r
+                       break;\r
+\r
+                       case 'sendmessage':\r
+                               return $this->sendMessage();\r
+                       break;\r
+\r
+                       case 'createaccount':\r
+                               return $this->createAccount();\r
+                       break;\r
+\r
+                       case 'forgotpassword':\r
+                               return $this->forgotPassword();\r
+                       break;\r
+\r
+                       case 'votepositive':\r
+                               return $this->doKarma('pos');\r
+                       break;\r
+\r
+                       case 'votenegative':\r
+                               return $this->doKarma('neg');\r
+                       break;\r
+\r
+                       case 'plugin':\r
+                               return $this->callPlugin();\r
+                       break;\r
+\r
+                       default:\r
+                               doError(_ERROR_BADACTION);\r
+                       break;\r
+               }\r
        }
 
+
        /**
         *  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['email'] =   postVar('email');
-               $post['body'] =  postVar('body');
+       function addComment()\r
+       {\r
+               global $CONF, $errormessage, $manager;\r
+\r
+               $post['itemid']         = intPostVar('itemid');\r
+               $post['user']           = postVar('user');\r
+               $post['userid']         = postVar('userid');\r
+               $post['email']          = postVar('email');\r
+               $post['body']           = postVar('body');\r
+               $post['remember']       = intPostVar('remember');
 
                // set cookies when required
-               $remember = intPostVar('remember');
-               if ($remember == 1) {
-                       $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);
-               }
+               #$remember = intPostVar('remember');
+\r
+               // begin if: "Remember Me" box checked\r
+               if ( $post['remember'] == 1 )\r
+               {\r
+                       $lifetime = time() + 2592000;\r
+                       setcookie($CONF['CookiePrefix'] . 'comment_user', $post['user'], $lifetime, '/', '', 0);\r
+                       setcookie($CONF['CookiePrefix'] . 'comment_userid', $post['userid'], $lifetime, '/', '', 0);\r
+                       setcookie($CONF['CookiePrefix'] . 'comment_email', $post['email'], $lifetime, '/', '', 0);\r
+               } // end if
 
                $comments = new COMMENTS($post['itemid']);
 
-               $blogid = getBlogIDFromItemID($post['itemid']);
-               $this->checkban($blogid);
-               $blog =& $manager->getBlog($blogid);
+               $blog_id = getBlogIDFromItemID($post['itemid']);\r
+               $this->checkban($blog_id);\r
+               $blog =& $manager->getBlog($blog_id);
 
                // note: PreAddComment and PostAddComment gets called somewhere inside addComment
-               $errormessage = $comments->addComment($blog->getCorrectTime(),$post);
+               $errormessage = $comments->addComment($blog->getCorrectTime(), $post);
 
-               if ($errormessage == '1') {
+               // begin if:\r
+               if ( $errormessage == '1' )\r
+               {
                        // redirect when adding comments succeeded
-                       if (postVar('url')) {
-                               redirect(postVar('url'));
-                       } else {
+                       if ( postVar('url') )\r
+                       {\r
+                               redirect(postVar('url') );\r
+                       }\r
+                       else\r
+                       {
                                $url = createItemLink($post['itemid']);
                                redirect($url);
-                       }
-               } else {
-                       // else, show error message using default skin for blog
+                       } // end if\r
+\r
+               }\r
+               // else, show error message using default skin for blog\r
+               else\r
+               {
                        return array(
-                               'message' => $errormessage,
-                               'skinid' => $blog->getDefaultSkin()
+                               'message'       => $errormessage,\r
+                               'skinid'        => $blog->getDefaultSkin()
                        );
-               }
+               } // end if
 
                exit;
        }
 
+
        /**
         *  Sends a message from the current member to the member given as argument
         */
-       function sendMessage() {
+       function sendMessage()\r
+       {
                global $CONF, $member;
 
                $error = $this->validateMessage();
-               if ($error != '')
+\r
+               if ( $error != '' )\r
+               {
                        return array('message' => $error);
+               }
 
-               if (!$member->isLoggedIn()) {
+               if ( !$member->isLoggedIn() )\r
+               {
                        $fromMail = postVar('frommail');
                        $fromName = _MMAIL_FROMANON;
-               } else {
+               }\r
+               else\r
+               {
                        $fromMail = $member->getEmail();
                        $fromName = $member->getDisplayName();
                }
 
                $tomem = new MEMBER();
-               $tomem->readFromId(postVar('memberid'));
+               $tomem->readFromId(postVar('memberid') );
 
                $message  = _MMAIL_MSG . ' ' . $fromName . "\n"
                          . '(' . _MMAIL_FROMNUC. ' ' . $CONF['IndexURL'] .") \n\n"
@@ -147,76 +182,97 @@ class ACTION
                mb_internal_encoding(_CHARSET);
                @mb_send_mail($tomem->getEmail(), $title, $message, "From: ". $fromMail);
 
-               if (postVar('url')) {
-                       redirect(postVar('url'));
-               } else {
+               if ( postVar('url') )\r
+               {\r
+                       redirect(postVar('url') );\r
+               }\r
+               else\r
+               {
                        $CONF['MemberURL'] = $CONF['IndexURL'];
-                       if ($CONF['URLMode'] == 'pathinfo')
+\r
+                       if ( $CONF['URLMode'] == 'pathinfo' )
                        {
-                               $url = createLink('member', array('memberid' => $tomem->getID(), 'name' => $tomem->getDisplayName()));
+                               $url = createLink('member', array('memberid' => $tomem->getID(), 'name' => $tomem->getDisplayName() ) );
                        }
                        else
                        {
                                $url = $CONF['IndexURL'] . createMemberLink($tomem->getID());
                        }
+
                        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() {
+       function validateMessage()\r
+       {
                global $CONF, $member, $manager;
 
-               if (!$CONF['AllowMemberMail'])
+               if ( !$CONF['AllowMemberMail'] )\r
+               {
                        return _ERROR_MEMBERMAILDISABLED;
+               }
 
-               if (!$member->isLoggedIn() && !$CONF['NonmemberMail'])
-                       return _ERROR_DISALLOWED;
+               if ( !$member->isLoggedIn() && !$CONF['NonmemberMail'] )\r
+               {\r
+                       return _ERROR_DISALLOWED;\r
+               }
 
-               if (!$member->isLoggedIn() && (!isValidMailAddress(postVar('frommail'))))
-                       return _ERROR_BADMAILADDRESS;
+               if ( !$member->isLoggedIn() && (!isValidMailAddress(postVar('frommail') ) ) )\r
+               {\r
+                       return _ERROR_BADMAILADDRESS;\r
+               }
 
                // 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));
+               $manager->notify('ValidateForm', array('type' => 'membermail', 'error' => &$result) );
 
                return $result;
 
        }
 
+
        /**
         *  Creates a new user account
         */
-       function createAccount() {
+       function createAccount()\r
+       {
                global $CONF, $manager;
 
-               if (!$CONF['AllowMemberCreate'])
-                       doError(_ERROR_MEMBERCREATEDISABLED);
+               if ( !$CONF['AllowMemberCreate'] )\r
+               {\r
+                       doError(_ERROR_MEMBERCREATEDISABLED);\r
+               }
 
                // evaluate content from FormExtra
                $result = 1;
                $data = array('type' => 'membermail', 'error' => &$result);
                $manager->notify('ValidateForm', &$data);
 
-               if ($result!=1) {
+               if ( $result != 1 )\r
+               {
                        return $result;
                }
-               else {
+               else\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));
+                       srand( (double) microtime() * 1000000);\r
+                       $initialPwd = md5(uniqid(rand(), TRUE) );
 
                        // 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, '');
 
-                       if ($r != 1) {
+                       if ( $r != 1 )\r
+                       {
                                return $r;
                        }
 
@@ -225,29 +281,39 @@ class ACTION
                        $newmem->readFromName($name);
                        $newmem->sendActivationLink('register');
 
-                       $manager->notify('PostRegister',array('member' => &$newmem));
+                       $manager->notify('PostRegister', array('member' => &$newmem) );
 
-                       if (postVar('desturl')) {
-                               redirect(postVar('desturl'));
-                       } else {
+                       if ( postVar('desturl') )\r
+                       {\r
+                               redirect(postVar('desturl') );\r
+                       }\r
+                       else\r
+                       {
                                // header has been already sent, so deleted the line below
-                               //header ("Content-Type: text/html; charset="._CHARSET);
+                               sendContentType('text/html', '', _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
         */
-       function forgotPassword() {
-               $membername = trim(postVar('name'));
+       function forgotPassword()\r
+       {\r
+               $membername = trim(postVar('name') );
+
+               if ( !MEMBER::exists($membername) )\r
+               {\r
+                       doError(_ERROR_NOSUCHMEMBER);\r
+               }\r
 
-               if (!MEMBER::exists($membername))
-                       doError(_ERROR_NOSUCHMEMBER);
                $mem = MEMBER::createFromName($membername);
 
                /* below keeps regular users from resetting passwords using forgot password feature
@@ -256,31 +322,42 @@ class ACTION
                        doError(_ERROR_NOLOGON_NOACTIVATE);*/
 
                // check if e-mail address is correct
-               if (!($mem->getEmail() == postVar('email')))
-                       doError(_ERROR_INCORRECTEMAIL);
+               if ( !($mem->getEmail() == postVar('email') ) )\r
+               {\r
+                       doError(_ERROR_INCORRECTEMAIL);\r
+               }
 
                // send activation link
                $mem->sendActivationLink('forgot');
 
-               if (postVar('url')) {
-                       redirect(postVar('url'));
-               } else {
-                       header ("Content-Type: text/html; charset="._CHARSET);
+               if ( postVar('url') )\r
+               {\r
+                       redirect(postVar('url') );\r
+               }\r
+               else\r
+               {
+//                     header ("Content-Type: text/html; charset="._CHARSET);
+                       sendContentType('text/html', '', _CHARSET);
                        echo _MSG_ACTIVATION_SENT;
                        echo '<br /><br />Return to <a href="'.$CONF['IndexURL'].'" title="'.$CONF['SiteName'].'">'.$CONF['SiteName'].'</a>';
                }
+
                exit;
        }
 
+
        /**
         *  Handle karma votes
         */
-       function doKarma($type) {
+       function doKarma($type)\r
+       {
                global $itemid, $member, $CONF, $manager;
 
                // check if itemid exists
-               if (!$manager->existsItem($itemid,0,0))
-                       doError(_ERROR_NOSUCHITEM);
+               if ( !$manager->existsItem($itemid, 0, 0) )\r
+               {\r
+                       doError(_ERROR_NOSUCHITEM);\r
+               }
 
                $blogid = getBlogIDFromItemID($itemid);
                $this->checkban($blogid);
@@ -288,39 +365,53 @@ class ACTION
                $karma =& $manager->getKarma($itemid);
 
                // check if not already voted
-               if (!$karma->isVoteAllowed(serverVar('REMOTE_ADDR')))
-                       doError(_ERROR_VOTEDBEFORE);
+               if ( !$karma->isVoteAllowed(serverVar('REMOTE_ADDR') ) )\r
+               {\r
+                       doError(_ERROR_VOTEDBEFORE);\r
+               }
 
                // check if item does allow voting
-               $item =& $manager->getItem($itemid,0,0);
-               if ($item['closed'])
-                       doError(_ERROR_ITEMCLOSED);
-
-               switch($type) {
-                       case 'pos':
-                               $karma->votePositive();
-                               break;
-                       case 'neg':
-                               $karma->voteNegative();
-                               break;
+               $item =& $manager->getItem($itemid, 0, 0);\r
+\r
+               if ( $item['closed'] )\r
+               {\r
+                       doError(_ERROR_ITEMCLOSED);\r
+               }
+
+               switch ( $type )\r
+               {\r
+                       case 'pos':\r
+                               $karma->votePositive();\r
+                       break;\r
+\r
+                       case 'neg':\r
+                               $karma->voteNegative();\r
+                       break;\r
                }
 
 //             $blogid = getBlogIDFromItemID($itemid);
                $blog =& $manager->getBlog($blogid);
 
                // send email to notification address, if any
-               if ($blog->getNotifyAddress() && $blog->notifyOnVote()) {
+               if ( $blog->getNotifyAddress() && $blog->notifyOnVote() )\r
+               {
 
                        $mailto_msg = _NOTIFY_KV_MSG . ' ' . $itemid . "\n";
-                       $itemLink = createItemLink(intval($itemid));
+                       $itemLink = createItemLink(intval($itemid) );
                        $temp = parse_url($itemLink);
-                       if (!$temp['scheme']) {
+
+                       if ( !$temp['scheme'] )\r
+                       {
                                $itemLink = $CONF['IndexURL'] . $itemLink;
                        }
+
                        $mailto_msg .= $itemLink . "\n\n";
-                       if ($member->isLoggedIn()) {
+
+                       if ( $member->isLoggedIn() )\r
+                       {
                                $mailto_msg .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
                        }
+
                        $mailto_msg .= _NOTIFY_IP . ' ' . serverVar('REMOTE_ADDR') . "\n";
                        $mailto_msg .= _NOTIFY_HOST . ' ' .  gethostbyaddr(serverVar('REMOTE_ADDR'))  . "\n";
                        $mailto_msg .= _NOTIFY_VOTE . "\n " . $type . "\n";
@@ -330,15 +421,18 @@ class ACTION
 
                        $frommail = $member->getNotifyFromMailAddress();
 
-                       $notify = new NOTIFICATION($blog->getNotifyAddress());
-                       $notify->notify($mailto_title, $mailto_msg , $frommail);
+                       $notify = new NOTIFICATION($blog->getNotifyAddress() );\r
+                       $notify->notify($mailto_title, $mailto_msg, $frommail);
                }
 
-
                $refererUrl = serverVar('HTTP_REFERER');
-               if ($refererUrl) {
+\r
+               if ( $refererUrl )\r
+               {
                        $url = $refererUrl;
-               } else {
+               }\r
+               else\r
+               {
 //                     $url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid;
                        $url = $itemLink;
                }
@@ -347,81 +441,113 @@ class ACTION
                exit;
        }
 
+
        /**
          * Calls a plugin action
          */
-       function callPlugin() {
+       function callPlugin()\r
+       {
                global $manager;
 
                $pluginName = 'NP_' . requestVar('name');
                $actionType = requestVar('type');
 
                // 1: check if plugin is installed
-               if (!$manager->pluginInstalled($pluginName))
+               if ( !$manager->pluginInstalled($pluginName) )\r
+               {
                        doError(_ERROR_NOSUCHPLUGIN);
+               }
 
                // 2: call plugin
                $pluginObject =& $manager->getPlugin($pluginName);
-               if ($pluginObject)
+\r
+               if ( $pluginObject )\r
+               {
                        $error = $pluginObject->doAction($actionType);
-               else
+               }\r
+               else\r
+               {
                        $error = 'Could not load plugin (see actionlog)';
+               }
 
                // doAction returns error when:
                // - an error occurred (duh)
                // - no actions are allowed (doAction is not implemented)
-               if ($error)
-                       doError($error);
+               if ( $error )\r
+               {\r
+                       doError($error);\r
+               }
 
                exit;
 
        }
 
+
        /**
         *  Checks if an IP or IP range is banned
         */
-       function checkban($blogid) {
+       function checkban($blogid)\r
+       {
                // check if banned
-               $ban = BAN::isBanned($blogid, serverVar('REMOTE_ADDR'));
-               if ($ban != 0) {
+               $ban = BAN::isBanned($blogid, serverVar('REMOTE_ADDR') );\r
+\r
+               if ( $ban != 0 )\r
+               {
                        doError(_ERROR_BANNED1 . $ban->iprange . _ERROR_BANNED2 . $ban->message . _ERROR_BANNED3);
                }
 
        }
 
+
        /**
         * Gets a new ticket
         */
-       function updateTicket() {
+       function updateTicket()\r
+       {
                global $manager;
-               if ($manager->checkTicket()) {
+\r
+               if ( $manager->checkTicket() )\r
+               {
                        echo $manager->getNewTicket();
                }
-               else {
+               else\r
+               {
                        echo _ERROR . ':' . _ERROR_BADTICKET;
                }
-               return false;
+\r
+               return FALSE;
        }
 
+
        /**
         * Handles AutoSaveDraft
         */
-       function autoDraft() {
+       function autoDraft()\r
+       {
                global $manager;
-               if ($manager->checkTicket()) {
+\r
+               if ( $manager->checkTicket() )\r
+               {
                        $manager->loadClass('ITEM');
                        $info = ITEM::createDraftFromRequest();
-                       if ($info['status'] == 'error') {
+
+                       if ( $info['status'] == 'error' )\r
+                       {
                                echo $info['message'];
                        }
-                       else {
+                       else\r
+                       {
                                echo $info['draftid'];
                        }
                }
-               else {
+               else\r
+               {
                        echo _ERROR . ':' . _ERROR_BADTICKET;
                }
-               return false;
+\r
+               return FALSE;
        }
+
 }
+
 ?>
\ No newline at end of file
index 36de7e7..ffaa925 100755 (executable)
@@ -22,7 +22,7 @@ class COMMENT {
 
        /**
          * Returns the requested comment
-         * 
+         *
          * @static
          */
        function getComment($commentid) {
@@ -32,18 +32,21 @@ class COMMENT {
                $comments = sql_query($query);
 
                $aCommentInfo = sql_fetch_assoc($comments);
+
                if ($aCommentInfo) {
                        $aCommentInfo['timestamp'] = strtotime($aCommentInfo['ctime']);
                }
+
                return $aCommentInfo;
        }
 
        /**
          * Prepares a comment to be saved
-         *       
+         *
          * @static
          */
-       function prepare($comment) {
+       function prepare($comment)\r
+       {
                $comment['user'] = strip_tags($comment['user']);
                $comment['userid'] = strip_tags($comment['userid']);
                $comment['email'] = strip_tags($comment['email']);
@@ -52,14 +55,15 @@ class COMMENT {
                $comment['user'] = trim(strtr($comment['user'], "\n", ' ') );
                $comment['userid'] = trim(strtr($comment['userid'], "\'\"\n", '-- ') );
                $comment['email'] = trim(strtr($comment['email'], "\'\"\n", '-- ') );
-               
+
                // begin if: a comment userid is supplied, but does not have an "http://" or "https://" at the beginning - prepend an "http://"
-               if ( !empty($comment['userid']) && (strpos($comment['userid'], 'http://') !== 0) && (strpos($comment['userid'], 'https://') !== 0) ) {
+               if ( !empty($comment['userid']) && (strpos($comment['userid'], 'http://') !== 0) && (strpos($comment['userid'], 'https://') !== 0) )\r
+               {
                        $comment['userid'] = 'http://' . $comment['userid'];
                } // end if
-               
+
                $comment['body'] = COMMENT::prepareBody($comment['body']);
-               
+
                return $comment;
        }
 
@@ -67,27 +71,28 @@ class COMMENT {
         * Prepares the body of a comment
         *
         * @ static
-        */             
+        */
        function prepareBody($body) {
+
                # replaced ereg_replace() below with preg_replace(). ereg* functions are deprecated in PHP 5.3.0
                # original ereg_replace: ereg_replace("\n.\n.\n", "\n", $body);
-               
+
                // convert Windows and Mac style 'returns' to *nix newlines
                $body = preg_replace("/\r\n/", "\n", $body);
                $body = preg_replace("/\r/", "\n", $body);
-               
+
                // then remove newlines when too many in a row (3 or more newlines get converted to 1 newline)
                $body = preg_replace("/\n{3,}/", "\n\n", $body);
-               
+
                // encode special characters as entities
                $body = htmlspecialchars($body);
-               
+
                // trim away whitespace and newlines at beginning and end
                $body = trim($body);
-               
+
                // add <br /> tags
                $body = addBreaks($body);
-               
+
                // create hyperlinks for http:// addresses
                // there's a testcase for this in /build/testcases/urllinking.txt
                $replaceFrom = array(
@@ -107,11 +112,13 @@ class COMMENT {
                return $body;
        }
 
+
+
        /**
         * Creates a link code for unlinked URLs with different protocols
         *
         * @ static
-        */     
+        */
        function createLinkCode($pre, $url, $protocol = 'http') {
                $post = '';
 
@@ -120,18 +127,20 @@ class COMMENT {
                // move the part of URL, starting from the disallowed entity to the 'post' link part
                $aBadEntities = array('&quot;', '&gt;', '&lt;');
                foreach ($aBadEntities as $entity) {
+
                        $pos = strpos($url, $entity);
+
                        if ($pos) {
                                $post = substr($url, $pos) . $post;
                                $url = substr($url, 0, $pos);
-
                        }
+
                }
 
                // remove entities at end (&&&&)
-               if (preg_match('/(&\w+;)+$/i', $url, $matches)) {
+               if (preg_match('/(&\w+;)+$/i', $url, $matches) ) {
                        $post = $matches[0] . $post;    // found entities (1 or more)
-                       $url = substr($url, 0, strlen($url) - strlen($post));
+                       $url = substr($url, 0, strlen($url) - strlen($post) );
                }
 
                // move ending comma from url to 'post' part
@@ -142,21 +151,23 @@ class COMMENT {
 
                # replaced ereg() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
                # original ereg: ereg('^' . $protocol . '://', $url)
+
                if (!preg_match('#^' . $protocol . '://#', $url) )
                {
-                       $linkedUrl = $protocol . (($protocol == 'mailto') ? ':' : '://') . $url;
+                       $linkedUrl = $protocol . ( ($protocol == 'mailto') ? ':' : '://') . $url;
                }
                else
                {
                        $linkedUrl = $url;
                }
-               
+
                if ($protocol != 'mailto') {
                        $displayedUrl = $linkedUrl;
                } else {
                        $displayedUrl = $url;
                }
-               return $pre . '<a href="'.$linkedUrl.'" rel="nofollow">'.shorten($displayedUrl,30,'...').'</a>' . $post;
+
+               return $pre . '<a href="' . $linkedUrl . '" rel="nofollow">' . shorten($displayedUrl,30,'...') . '</a>' . $post;
        }
 }
 ?>
\ No newline at end of file
index 4f5e113..5d53afe 100755 (executable)
@@ -42,7 +42,7 @@ class COMMENTS {
        function COMMENTS($itemid) {
                $this->itemid = intval($itemid);
        }
-
+       
        /**
         * Used when parsing comments
         *
@@ -135,7 +135,8 @@ class COMMENTS {
        /**
         * Adds a new comment to the database
         */
-       function addComment($timestamp, $comment) {
+       function addComment($timestamp, $comment)
+       {
                global $CONF, $member, $manager;
 
                $blogid = getBlogIDFromItemID($this->itemid);
@@ -143,105 +144,143 @@ class COMMENTS {
                $settings =& $manager->getBlog($blogid);
                $settings->readSettings();
 
-               if (!$settings->commentsEnabled())
+               if ( !$settings->commentsEnabled() )
+               {
                        return _ERROR_COMMENTS_DISABLED;
+               }
 
-               if (!$settings->isPublic() && !$member->isLoggedIn())
+               if ( !$settings->isPublic() && !$member->isLoggedIn() )
+               {
                        return _ERROR_COMMENTS_NONPUBLIC;
+               }
 
                // member name protection
-               if ($CONF['ProtectMemNames'] && !$member->isLoggedIn() && MEMBER::isNameProtected($comment['user']))
+               if ( $CONF['ProtectMemNames'] && !$member->isLoggedIn() && MEMBER::isNameProtected($comment['user']) )
+               {
                        return _ERROR_COMMENTS_MEMBERNICK;
+               }
 
                // email required protection
-               if ($settings->emailRequired() && strlen($comment['email']) == 0 && !$member->isLoggedIn()) {
+               if ( $settings->emailRequired() && strlen($comment['email']) == 0 && !$member->isLoggedIn() )
+               {
                        return _ERROR_EMAIL_REQUIRED;
                }
 
                $comment['timestamp'] = $timestamp;
-               $comment['host'] = gethostbyaddr(serverVar('REMOTE_ADDR'));
+               $comment['host'] = gethostbyaddr(serverVar('REMOTE_ADDR') );
                $comment['ip'] = serverVar('REMOTE_ADDR');
 
                // if member is logged in, use that data
-               if ($member->isLoggedIn()) {
+               if ( $member->isLoggedIn() )
+               {
                        $comment['memberid'] = $member->getID();
                        $comment['user'] = '';
                        $comment['userid'] = '';
                        $comment['email'] = '';
-               } else {
+               }
+               else
+               {
                        $comment['memberid'] = 0;
                }
 
                // spam check
-               $continue = false;
+               $continue = FALSE;
                $plugins = array();
 
-               if (isset($manager->subscriptions['ValidateForm']))
+               if ( isset($manager->subscriptions['ValidateForm']) )
+               {
                        $plugins = array_merge($plugins, $manager->subscriptions['ValidateForm']);
+               }
 
-               if (isset($manager->subscriptions['PreAddComment']))
+               if ( isset($manager->subscriptions['PreAddComment']) )
+               {
                        $plugins = array_merge($plugins, $manager->subscriptions['PreAddComment']);
+               }
 
-               if (isset($manager->subscriptions['PostAddComment']))
+               if ( isset($manager->subscriptions['PostAddComment']) )
+               {
                        $plugins = array_merge($plugins, $manager->subscriptions['PostAddComment']);
+               }
 
                $plugins = array_unique($plugins);
 
-               while (list(,$plugin) = each($plugins)) {
+               while ( list(, $plugin) = each($plugins) )
+               {
                        $p = $manager->getPlugin($plugin);
                        $continue = $continue || $p->supportsFeature('handleSpam');
                }
 
-               $spamcheck = array (
+               $spamcheck = array(
                        'type'          => 'comment',
                        'body'          => $comment['body'],
                        'id'        => $comment['itemid'],
-                       'live'          => true,
+                       'live'          => TRUE,
                        'return'        => $continue
                );
 
-               if ($member->isLoggedIn()) {
+               if ( $member->isLoggedIn() )
+               {
                        $spamcheck['author'] = $member->displayname;
                        $spamcheck['email'] = $member->email;
-               } else {
+               }
+               else
+               {
                        $spamcheck['author'] = $comment['user'];
                        $spamcheck['email'] = $comment['email'];
                        $spamcheck['url'] = $comment['userid'];
                }
 
-               $manager->notify('SpamCheck', array ('spamcheck' => &$spamcheck));
+               $manager->notify('SpamCheck', array('spamcheck' => &$spamcheck) );
 
-               if (!$continue && isset($spamcheck['result']) && $spamcheck['result'] == true)
+               if ( !$continue && isset($spamcheck['result']) && $spamcheck['result'] == TRUE )
+               {
                        return _ERROR_COMMENTS_SPAM;
-
+               }
 
                // isValidComment returns either "1" or an error message
                $isvalid = $this->isValidComment($comment, $spamcheck);
-               if ($isvalid != 1)
+
+               if ( $isvalid != 1 )
+               {
                        return $isvalid;
+               }
 
                // send email to notification address, if any
-               if ($settings->getNotifyAddress() && $settings->notifyOnComment()) {
+               if ( $settings->getNotifyAddress() && $settings->notifyOnComment() )
+               {
 
                        $mailto_msg = _NOTIFY_NC_MSG . ' ' . $this->itemid . "\n";
 //                     $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $this->itemid . "\n\n";
                        $temp = parse_url($CONF['Self']);
-                       if ($temp['scheme']) {
+
+                       if ( $temp['scheme'] )
+                       {
                                $mailto_msg .= createItemLink($this->itemid) . "\n\n";
-                       } else {
+                       }
+                       else
+                       {
                                $tempurl = $settings->getURL();
-                               if (substr($tempurl, -1) == '/' || substr($tempurl, -4) == '.php') {
+
+                               if ( substr($tempurl, -1) == '/' || substr($tempurl, -4) == '.php' )
+                               {
                                        $mailto_msg .= $tempurl . '?itemid=' . $this->itemid . "\n\n";
-                               } else {
+                               }
+                               else
+                               {
                                        $mailto_msg .= $tempurl . '/?itemid=' . $this->itemid . "\n\n";
                                }
                        }
-                       if ($comment['memberid'] == 0) {
+
+                       if ( $comment['memberid'] == 0 )
+                       {
                                $mailto_msg .= _NOTIFY_USER . ' ' . $comment['user'] . "\n";
                                $mailto_msg .= _NOTIFY_USERID . ' ' . $comment['userid'] . "\n";
-                       } else {
+                       }
+                       else
+                       {
                                $mailto_msg .= _NOTIFY_MEMBER .' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
                        }
+
                        $mailto_msg .= _NOTIFY_HOST . ' ' . $comment['host'] . "\n";
                        $mailto_msg .= _NOTIFY_COMMENT . "\n " . $comment['body'] . "\n";
                        $mailto_msg .= getMailFooter();
@@ -251,13 +290,13 @@ class COMMENTS {
 
                        $frommail = $member->getNotifyFromMailAddress($comment['email']);
 
-                       $notify =& new NOTIFICATION($settings->getNotifyAddress());
+                       $notify =& new NOTIFICATION($settings->getNotifyAddress() );
                        $notify->notify($mailto_title, $mailto_msg , $frommail);
                }
 
                $comment = COMMENT::prepare($comment);
 
-               $manager->notify('PreAddComment',array('comment' => &$comment, 'spamcheck' => &$spamcheck));
+               $manager->notify('PreAddComment', array('comment' => &$comment, 'spamcheck' => &$spamcheck) );
 
                $name           = sql_real_escape_string($comment['user']);
                $url            = sql_real_escape_string($comment['userid']);
@@ -278,7 +317,9 @@ class COMMENTS {
                                        . ' AND citem   = "' . $itemid . '"'
                                        . ' AND cblog   = "' . $blogid . '"';
                $result     = (integer) quickQuery($qSql);
-               if ($result > 0) {
+
+               if ( $result > 0 )
+               {
                        return _ERROR_BADACTION;
                }
 
@@ -289,70 +330,75 @@ class COMMENTS {
 
                // post add comment
                $commentid = sql_insert_id();
-               $manager->notify('PostAddComment',array('comment' => &$comment, 'commentid' => &$commentid, 'spamcheck' => &$spamcheck));
+               $manager->notify('PostAddComment', array('comment' => &$comment, 'commentid' => &$commentid, 'spamcheck' => &$spamcheck) );
 
                // succeeded !
-               return true;
+               return TRUE;
        }
 
+
        /**
         * Checks if a comment is valid and call plugins
         * that can check if the comment is a spam comment        
         */
-       function isValidComment(&$comment, & $spamcheck) {
+       function isValidComment(&$comment, &$spamcheck) {
+
                global $member, $manager;
-               
+
                // check if there exists a item for this date
-               $item =& $manager->getItem($this->itemid,0,0);
-               
+               $item =& $manager->getItem($this->itemid, 0, 0);
+
                if (!$item)
                {
                        return _ERROR_NOSUCHITEM;
                }
-               
+
                if ($item['closed'])
                {
                        return _ERROR_ITEMCLOSED;
                }
-               
+
                # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
                # original eregi comparison: eregi('[a-zA-Z0-9|\.,;:!\?=\/\\]{90,90}', $comment['body']) != FALSE
-               
+
                // don't allow words that are too long
                if (preg_match('/[a-zA-Z0-9|\.,;:!\?=\/\\\\]{90,90}/', $comment['body']) != 0)
                {
                        return _ERROR_COMMENT_LONGWORD;
                }
-               
+
                // check lengths of comment
-               if (strlen($comment['body'])<3)
+               if (strlen($comment['body']) < 3)
                {
                        return _ERROR_COMMENT_NOCOMMENT;
                }
-               
-               if (strlen($comment['body'])>5000)
+
+               if (strlen($comment['body']) > 5000)
                {
                        return _ERROR_COMMENT_TOOLONG;
                }
-               
+
                // only check username if no member logged in
-               if (!$member->isLoggedIn())
+               if (!$member->isLoggedIn() )
                {
-                       if (strlen($comment['user'])<2)
+
+                       if (strlen($comment['user']) < 2)
                        {
                                return _ERROR_COMMENT_NOUSERNAME;
                        }
+
                }
-               
+
                if ((strlen($comment['email']) != 0) && !(isValidMailAddress(trim($comment['email']) ) ) )
                {
                        return _ERROR_BADMAILADDRESS;
                }
-               
+
                // let plugins do verification (any plugin which thinks the comment is invalid
                // can change 'error' to something other than '1')
                $result = 1;
-               $manager->notify('ValidateForm', array('type' => 'comment', 'comment' => &$comment, 'error' => &$result, 'spamcheck' => &$spamcheck));
+               $manager->notify('ValidateForm', array('type' => 'comment', 'comment' => &$comment, 'error' => &$result, 'spamcheck' => &$spamcheck) );
+
                return $result;
        }
 }