[pLog-svn] r6445 - in plog/branches/lifetype-1.2/class: action dao

Jon Daley plogworld at jon.limedaley.com
Thu May 8 11:31:50 EDT 2008


 	Which is better to add a new string for this error (something 
about it being a duplicate comment), or to just leave it as "There was an 
error adding the comment"

On Thu, 8 May 2008, jondaley at devel.lifetype.net wrote:

> Author: jondaley
> Date: 2008-05-08 11:27:45 -0400 (Thu, 08 May 2008)
> New Revision: 6445
>
> Modified:
>   plog/branches/lifetype-1.2/class/action/addcommentaction.class.php
>   plog/branches/lifetype-1.2/class/action/addtrackbackaction.class.php
>   plog/branches/lifetype-1.2/class/dao/articlecomments.class.php
>   plog/branches/lifetype-1.2/class/dao/commentscommon.class.php
>   plog/branches/lifetype-1.2/class/dao/trackbacks.class.php
> Log:
> re-added getIdenticalComment (from rev 1599).  Since this API has been broken for a long time, I don't feel bad about changing it within the 1.2 release.  All of the real work has been put into CommentsCommon, and both the addTrackback and addComment use it in the same way, rather than comments passing in each bit of the comment, and trackbacks passing in a comment, which seemed weird.  It also seemed strange to have the parent class have completely different parameters than the child.  tested and it works.  Fixes: http://bugs.lifetype.net/view.php?id=1501   Thanks to maiminh for noticing, and providing code to help fix it
>
> Modified: plog/branches/lifetype-1.2/class/action/addcommentaction.class.php
> ===================================================================
> --- plog/branches/lifetype-1.2/class/action/addcommentaction.class.php	2008-05-07 08:22:03 UTC (rev 6444)
> +++ plog/branches/lifetype-1.2/class/action/addcommentaction.class.php	2008-05-08 15:27:45 UTC (rev 6445)
> @@ -210,17 +210,27 @@
> 				$comment->setUserId( 0 );
> 			}
>
> -			// fire an event
> -			$this->notifyEvent( EVENT_PRE_COMMENT_ADD, Array( "comment" => &$comment ));
> -
> -			if( !$comments->addComment( $comment )) {
> -               	// show an error message if problems
> +                // check if there is already a comment with the same text, topic and made from the same
> +                // IP already in the database because if so, then we will not add the comment that
> +                // the user is trying to add (a reload or submit button mistake, perhaps?)
> +            if( $comments->getIdentical( $comment )){
>                 $this->_view = new ErrorView( $this->_blogInfo );
> +                $this->_view->setValue( "message", "error_adding_duplicate_comment" );
> +                $this->setCommonData();
> +                return false;
> +            }
> +
> +                // fire an event
> +            $this->notifyEvent( EVENT_PRE_COMMENT_ADD, Array( "comment" => &$comment ));
> +
> +            if( !$comments->addComment( $comment )) {
> +                    // show an error message if problems
> +                $this->_view = new ErrorView( $this->_blogInfo );
>                 $this->_view->setValue( "message", "error_adding_comment" );
>                 $this->setCommonData();
>                 return false;
>             }
> -
> +
>             // finally, check if there was any user who wanted to be notified of new comments
>             // to this post...
>             $notifier = new ArticleNotifications();
>
> Modified: plog/branches/lifetype-1.2/class/action/addtrackbackaction.class.php
> ===================================================================
> --- plog/branches/lifetype-1.2/class/action/addtrackbackaction.class.php	2008-05-07 08:22:03 UTC (rev 6444)
> +++ plog/branches/lifetype-1.2/class/action/addtrackbackaction.class.php	2008-05-08 15:27:45 UTC (rev 6445)
> @@ -142,7 +142,7 @@
>             // as spam. The first one would be created by the spam filter and the second one would be created
>             // by us here, so we need to know if the trackback is already there and if not, don't add it.
>             // This also works as an additional protection feature agains repeating trackback spammers.
> -            if( !$trackbacks->getIdenticalTrackback( $trackback )) {
> +            if( !$trackbacks->getIdentical( $trackback )) {
>                 // throw the event in case somebody is listening to it!
>                 $pm->notifyEvent( EVENT_PRE_TRACKBACK_ADD, Array( "trackback" => &$trackback ));
>                 $result = $trackbacks->addTrackBack( $trackback );
>
> Modified: plog/branches/lifetype-1.2/class/dao/articlecomments.class.php
> ===================================================================
> --- plog/branches/lifetype-1.2/class/dao/articlecomments.class.php	2008-05-07 08:22:03 UTC (rev 6444)
> +++ plog/branches/lifetype-1.2/class/dao/articlecomments.class.php	2008-05-08 15:27:45 UTC (rev 6445)
> @@ -46,21 +46,6 @@
>         }
>
>         /**
> -         * Returns true if there already is a comment in the database with the same
> -         * article_id field, topic, text, replying to the same comment, username and so on
> -         * Useful in case we want to check if the user sent the same comment by mistake
> -         * by pressing the 'reload' button twice or something...
> -         *
> -         * @return Returns true if there already is such comment or false otherwise.
> -         */
> -        function getIdenticalComment( $topic, $text, $articleId, $parentId = 0, $userName = "", $userEmail = "", $userUrl = "", $clientIp = "0.0.0.0" )
> -        {
> -			return( CommentsCommon::getIdenticalComment( $topic, $text, $articleId,
> -			                                             $parentId, $userName, $userEmail,
> -														 $userUrl, $clientIp, COMMENT_TYPE_COMMENT ));
> -        }
> -
> -        /**
>          * removes all comments marked as spam from the database
>          */
>         // TODO: CommentsCommon::purgeSpamComments doesn't exist,
>
> Modified: plog/branches/lifetype-1.2/class/dao/commentscommon.class.php
> ===================================================================
> --- plog/branches/lifetype-1.2/class/dao/commentscommon.class.php	2008-05-07 08:22:03 UTC (rev 6444)
> +++ plog/branches/lifetype-1.2/class/dao/commentscommon.class.php	2008-05-08 15:27:45 UTC (rev 6445)
> @@ -528,7 +528,7 @@
> 		/**
> 		 * Delete all the article comments
> 		 *
> -		 * @param blogId
> +		 * @param articleId
> 		 */
> 		function deleteArticleComments( $articleId )
> 		{
> @@ -558,6 +558,39 @@
> 			}
>
> 			return( $res );
> -		}
> +		}
> +
> +		/**
> +		 * Search for an identical comment (or trackback) already saved to the database
> +		 *
> +		 * @param comment
> +		 */
> +        function getIdentical( $comment )
> +        {
> +            $query = "SELECT COUNT(id) AS total FROM ".$this->getPrefix()."articles_comments ".
> +                "WHERE topic = '".Db::qstr($comment->getTopic())."' AND ".
> +                "text = '".Db::qstr($comment->getText())."' AND ".
> +                "article_id = '".Db::qstr($comment->getArticleId())."' AND ".
> +                "parent_id = '".Db::qstr($comment->getParentId())."' AND ".
> +                "client_ip = '".Db::qstr($comment->getClientIp())."' AND ".
> +                "user_name = '".Db::qstr($comment->getUserName())."' AND ".
> +                "user_email = '".Db::qstr($comment->getUserEmail())."' AND ".
> +                "user_url = '".Db::qstr($comment->getUserUrl())."'";
> +            if( $comment->type != COMMENT_TYPE_ANY )
> +                $query .= " AND type = '".Db::qstr($comment->getType())."'";
> +
> +            $result = $this->Execute( $query );
> +
> +            if( !$result )
> +                return false;
> +
> +            $row = $result->FetchRow();
> +            $result->Close();
> +
> +            if( $row["total"] >= 1 )
> +                return true;
> +            else
> +                return false;
> +        }
> 	}
> ?>
> \ No newline at end of file
>
> Modified: plog/branches/lifetype-1.2/class/dao/trackbacks.class.php
> ===================================================================
> --- plog/branches/lifetype-1.2/class/dao/trackbacks.class.php	2008-05-07 08:22:03 UTC (rev 6444)
> +++ plog/branches/lifetype-1.2/class/dao/trackbacks.class.php	2008-05-08 15:27:45 UTC (rev 6445)
> @@ -159,25 +159,5 @@
> 		{
> 			return( CommentsCommon::deleteComment( $trackbackId, COMMENT_TYPE_TRACKBACK ));
> 		}
> -
> -		/**
> -		 * @private
> -		 * @return Returns true if this trackback already exists in the db
> -		 */
> -        function getIdenticalTrackback( $trackback )
> -        {
> -			// :TODO:
> -			//
> -			// implement this
> -			/*return( CommentsCommon::getIdenticalComment( $trackback->getTopic(),
> -														 $trackback->getText(),
> -														 $trackback->getArticleId(),
> -			                                             $trackback->getParentId(),
> -														 $trackback->getUserName(),
> -														 $trackback->getUserEmail(),
> -														 $trackback->getUserUrl(),
> -														 $trackback->getClientIp(),
> -														 COMMENT_TYPE_TRACKBACK ));*/
> -        }
>     }
> ?>
> \ No newline at end of file
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://limedaley.com/mailman/listinfo/plog-svn
>

-- 
Jon Daley
http://jon.limedaley.com/

If you think good architecture is expensive, try bad architecture
-- Brian Foote and Joseph Yoder


More information about the pLog-svn mailing list