[pLog-svn] r1854 - in plog/trunk: . class/dao

Oscar Renalias oscar at renalias.net
Sun Apr 17 17:48:27 GMT 2005


forgot to say that the wizard has not been updated yet to support this  
feature. All you need to do, if interested in testing this feature is  
execute the following SQL query:

ALTER TABLE plog_articles_comments ADD COLUMN type INTEGER(3) NOT NULL  
DEFAULT 1

Keep in mind that if you don't do this, comments and trackbacks will  
not work.

There is no code to move all trackbacks to the new table yet either,  
that'll come later...

Oscar

On 17 Apr 2005, at 20:35, oscar at devel.plogworld.net wrote:

> Author: oscar
> Date: 2005-04-17 17:35:24 +0000 (Sun, 17 Apr 2005)
> New Revision: 1854
>
> Added:
>    plog/trunk/class/dao/commentscommon.class.php
> Modified:
>    plog/trunk/class/dao/articlecomments.class.php
>    plog/trunk/class/dao/trackback.class.php
>    plog/trunk/class/dao/trackbacks.class.php
>    plog/trunk/class/dao/usercomment.class.php
>    plog/trunk/trackback.php
> Log:
> trackbacks have been merged with comments and now they use the same db  
> table as well as share a lot of common code. The advantages are that  
> now we can mark trackbacks as spam (not implemented yet), store the IP  
> address of who sent a trackback, etc.
>
> The new Trackback class is only extending UserComment so that the  
> interface is the same as in plog 1.0 but, while the common php code  
> that can be used by both Trackbacks and  ArticleComments has been  
> moved to CommentsCommon. Most of the methods are as they used to be in  
> ArticleComments but a new parameter 'type' has added to the methods,  
> so that we can choose whether to work on trackbacks, comments or both  
> of them.
>
> The old Trackbacks and ArticleComments classes keep the old interface  
> (mostly) so that the changes required elsewhere in the code are  
> minimal.
>
> Modified: plog/trunk/class/dao/articlecomments.class.php
> ===================================================================
> --- plog/trunk/class/dao/articlecomments.class.php	2005-04-17 17:32:10  
> UTC (rev 1853)
> +++ plog/trunk/class/dao/articlecomments.class.php	2005-04-17 17:35:24  
> UTC (rev 1854)
> @@ -1,67 +1,21 @@
>  <?php
>
> -	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
> +	include_once( PLOG_CLASS_PATH."class/dao/commentscommon.class.php" );
>  	include_once( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
> -	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
>
> -	define( "COMMENT_ORDER_OLDEST_FIRST", 1 );
> -	define( "COMMENT_ORDER_NEWEST_FIRST", 2 );
> -
>      /**
>  	 * \ingroup DAO
>  	 *
>       * Model for the comments each article can have
>       */
> -	class ArticleComments extends Model
> +	class ArticleComments extends CommentsCommon
>  	{
>
> -    	var $totalComments;
> -		var $_blogSettings;
> -		var $blogSettings;
> -		var $timeDiff;
> -
>      	function ArticleComments()
>          {
> -        	$this->Model();
> -
> -            $this->totalComments = Array();
> -
> -            $this->_blogSettings = Array();
> -			
> -			$this->blogSettings = null;
> -			$this->timeDiff = 0;			
> +        	$this->CommentsCommon();
>          }
>
> -        /**
> -         * Adds a comment to an article
> -		 *
> -		 * @param comment the UserComment object that we're going to add.
> -		 * @return Returns true if successful or false if error. Also in  
> case of success, it will modify the UserComment
> -		 * object passed by reference and include its new id.
> -         */
> -		function addComment( &$comment )
> -        {
> -			$filter = new Textfilter();
> -        	$query = "INSERT INTO ".$this->getPrefix().
> -			          "articles_comments  
> (article_id,topic,text,user_name,user_email,
> -					                      user_url,parent_id,client_ip,status,  
> normalized_text,normalized_topic)
> -					   VALUES  
> (".$comment->getArticleId().",'".Db::qstr($comment->getTopic())."','".
> -					    
> Db::qstr($comment->getText())."','".$comment- 
> >getUserName()."','".$comment->getUserEmail()."','".$comment- 
> >getUserUrl()."',".
> -					   $comment->getParentId().", '".$comment->getClientIp()."',  
> ".$comment->getStatus().", '".
> -					   Db::qstr($filter->normalizeText($comment->getText()))."', '".
> -					   Db::qstr($filter->normalizeText($comment->getTopic()))."');";
> -
> -            $result = $this->Execute( $query );
> -			
> -			if( !$result )
> -				return false;
> -			
> -			// retrieve the last id and save it in the object
> -			$comment->setId( $this->_db->Insert_ID());
> -			
> -			return( true );
> -        }
> -
>  		/**
>  		 * Retrieves all the comments for a post
>  		 *
> @@ -75,57 +29,7 @@
>  		 */
>  		function getPostComments( $artid, $order =  
> COMMENT_ORDER_NEWEST_FIRST, $status = COMMENT_STATUS_ALL, $page = -1,  
> $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
>  		{
> -			$query = "SELECT * FROM ".$this->getPrefix()."articles_comments  
> WHERE article_id = ".$artid;
> -            if( $status != COMMENT_STATUS_ALL )
> -            	$query .= " AND status = $status";
> -
> -			// check in which order we should display those comments
> -			if( $order == COMMENT_ORDER_NEWEST_FIRST )
> -				$query .= " ORDER BY date DESC";
> -			else
> -				$query .= " ORDER BY date ASC";
> -			
> -            $result = $this->Execute( $query, $page, $itemsPerPage );
> -
> -            if( !$result )
> -            	return Array();
> -
> -            $comments = Array();
> -            while ($row = $result->FetchRow()) {
> -
> -				// find out the blogInfo object (after all, all these comments  
> belong to the same
> -				// blog so there is no risk of finding different blog_ids  
> anywhere!
> -				if( $this->blogSettings == null ) {
> -					$prefix = $this->getPrefix();
> -					$articleId = $row["article_id"];
> -					
> -					$query = "SELECT DISTINCT b.settings AS settings FROM  
> {$prefix}blogs b, {$prefix}articles a,
> -					         {$prefix}articles_comments c WHERE c.article_id = a.id  
> AND a.blog_id = b.id
> -							 AND a.id = $articleId";
> -					$result2 = $this->Execute( $query );
> -					$tmpRow = $result2->FetchRow();
> -					$this->blogSettings = Blogs::getBlogSettingsFromField(  
> $tmpRow["settings"] );
> -					
> -					$this->timeDiff = $this->blogSettings->getValue( "time_offset" );
> -				}
> -				
> -			
> -            	$lastArticleId=$row["article_id"];
> -				
> -				// now that we've got the time difference, we can
> -				// calculate what would the "real" date...
> -				$date = $row["date"];								
> -				$date = Timestamp::getDateWithOffset( $date, $this->timeDiff );
> -
> -				$comment = new UserComment(  
> $row["article_id"],	$row["parent_id"], $row["topic"],
> -											$row["text"], $date, $row["user_name"], $row["user_email"],
> -											$row["user_url"], $row["client_ip"], $row["spam_rate"],  
> $row["status"],
> -											$row["id"] );				
> -				
> -                $comments[] = $comment;
> -			}
> -
> -			return $comments;
> +			return( CommentsCommon::getPostComments( $artid, $order, $status,  
> COMMENT_TYPE_COMMENT, $page, $itemsPerPage ));
>  		}
>  		
>  		/**
> @@ -135,60 +39,7 @@
>  		 */
>  		function getPostCommentsByIds( $ids, $order =  
> COMMENT_ORDER_NEWEST_FIRST, $status = COMMENT_STATUS_ALL )
>  		{
> -
> -			$query = "SELECT * FROM ".$this->getPrefix()."articles_comments  
> WHERE article_id IN (".$ids.")";
> -            if( $status != COMMENT_STATUS_ALL )
> -            	$query .= " AND status = $status";
> -
> -			// check in which order we should display those comments
> -			if( $order == COMMENT_ORDER_NEWEST_FIRST )
> -				$query .= " ORDER BY date DESC";
> -			else
> -				$query .= " ORDER BY date ASC";
> -			$result = $this->Execute( $query );
> -			if( !$result )
> -            	return false;
> -				
> -			// initialize these two thingies with harmless values
> -			$blogSettings = null;
> -			$timeDiff = 0;
> -
> -            while ($row = $result->FetchRow()) {
> -			
> -				// find out the blogInfo object (after all, all these comments  
> belong to the same
> -				// blog so there is no risk of finding different blog_ids  
> anywhere!
> -				if( $this->blogSettings == null ) {
> -					$prefix = $this->getPrefix();
> -					$articleId = $row["article_id"];
> -					
> -					$query = "SELECT DISTINCT b.settings AS settings FROM  
> {$prefix}blogs b, {$prefix}articles a,
> -					         {$prefix}articles_comments c WHERE c.article_id = a.id  
> AND a.blog_id = b.id
> -							 AND a.id = $articleId";
> -					$result2 = $this->Execute( $query );
> -					$tmpRow = $result2->FetchRow();
> -					$this->blogSettings = Blogs::getBlogSettingsFromField(  
> $tmpRow["settings"] );
> -					
> -					$this->timeDiff = $this->blogSettings->getValue( "time_offset" );
> -				}
> -				
> -			
> -            	$lastArticleId=$row["article_id"];
> -				
> -				// now that we've got the time difference, we can
> -				// calculate what would the "real" date...
> -				$date = $row["date"];				
> -				$date = Timestamp::getDateWithOffset( $date, $this->timeDiff );
> -
> -				$comment = new UserComment(  
> $row["article_id"],	$row["parent_id"], $row["topic"],
> -											$row["text"], $date, $row["user_name"], $row["user_email"],
> -											$row["user_url"], $row["client_ip"], $row["spam_rate"],  
> $row["status"],
> -											$row["id"] );
> -				
> -				// save the comment in the array
> -                $comments[$lastArticleId][]=$comment;
> -			}
> -
> -			return $comments;
> +			return( CommentsCommon::getPostCommentsByIds( $ids, $order,  
> $status, COMMENT_TYPE_COMMENT ));
>  		}
>  		
>          /**
> @@ -200,17 +51,7 @@
>           */
>          function getNumPostComments( $artId, $status =  
> COMMENT_STATUS_ALL )
>          {
> -		// create the table name
> -		$prefix = $this->getPrefix();
> -		$table = "{$prefix}articles_comments";
> -		// and the condition if any...
> -		$cond = "article_id = '".Db::qstr($artId)."'";
> -		if( $status != COMMENT_STATUS_ALL )
> -			$cond .= " AND status = '".Db::qstr($status)."'";
> -
> -		// get the number of items and return it to the caller
> -		return( $this->getNumItems( $table, $cond ));
> -		
> +			return( CommentsCommon::getNumPostComments( $artId, $status,  
> COMMENT_TYPE_COMMENT ));
>          }
>
>          /**
> @@ -218,17 +59,7 @@
>           */
>          function getPostComment( $artid, $commentid )
>  		{
> -			$query = "SELECT * FROM ".$this->getPrefix()."articles_comments  
> WHERE id = ".$commentid." AND article_id = ".$artid.";";
> -
> -			$result = $this->Execute( $query );
> -
> -			if( !$result )
> -				return false;
> -
> -            $row = $result->FetchRow();
> -            $comment = $this->_fillCommentInformation( $row );
> -
> -			return $comment;
> +			return( getPostComment( $artid, $commentid, COMMENT_TYPE_COMMENT  
> ));
>  		}
>
>          /**
> @@ -241,24 +72,9 @@
>           */
>          function getIdenticalComment( $topic, $text, $articleId,  
> $parentId = 0, $userName = "", $userEmail = "", $userUrl = "",  
> $clientIp = "0.0.0.0" )
>          {
> -        	$query = "SELECT COUNT(*) AS total FROM  
> ".$this->getPrefix()."articles_comments
> -                       WHERE topic = '".Db::qstr($topic)."' AND text  
> = '".Db::qstr($text)."'
> -                       AND article_id = $articleId AND parent_id =  
> $parentId AND
> -                       client_ip = '$clientIp' AND user_name =  
> '$userName' AND
> -                       user_email = '$userEmail' AND user_url =  
> '$userUrl'
> -                       AND date <= NOW()";
> -
> -            $result = $this->Execute( $query );
> -
> -            if( !$result )
> -            	return false;
> -
> -            $row = $result->FetchRow();
> -
> -            if( $row["total"] >= 1 )
> -            	return true;
> -            else
> -            	return false;
> +			return( CommentsCommon::getIdenticalComment( $topic, $text,  
> $articleId,
> +			                                             $parentId, $userName,  
> $userEmail,
> +														 $userUrl, $clientIp, COMMENT_TYPE_COMMENT ));
>          }
>
>          /**
> @@ -339,20 +155,9 @@
>           * @param artid The article identifier.
>           * @param commentid The comment identifier.
>  		 */
> -		function deletePostComment( $artid, $commentid)
> +		function deletePostComment( $artid, $commentid )
>  		{
> -			$query = "DELETE FROM ".$this->getPrefix()."articles_comments  
> WHERE id = ".$commentid." AND article_id = ".$artid.";";
> -
> -			$result = $this->Execute( $query );
> -
> -			if( $this->_db->Affected_Rows( $result ) == 0 )
> -				return;
> -
> -            // update all the other posts
> -            $query = "UPDATE ".$this->getPrefix()."articles_comments  
> SET parent_id = 0 WHERE parent_id = ".$commentid." AND article_id =  
> ".$artid.";";
> -            $result = $this->Execute( $query );
> -
> -			return $result;
> +			return( CommentsCommon::deletePostComment( $artid, $commentid,  
> COMMENT_TYPE_COMMENT ));
>  		}
>  		
>  		/**
> @@ -360,23 +165,12 @@
>           * have this one as the parent and makes them look as if they  
> were 'top level'
>           * comments with no parent.
>           *
> -         * @param artid The article identifier.
>           * @param commentid The comment identifier.
> +         * @param articleId The article identifier.		
>  		 */
> -		function deleteComment( $commentid)
> +		function deleteComment( $commentid, $articleId = -1 )
>  		{
> -			$query = "DELETE FROM ".$this->getPrefix()."articles_comments  
> WHERE id = ".$commentid;
> -
> -			$result = $this->Execute( $query );
> -
> -			if( $this->_db->Affected_Rows( $result ) == 0 )
> -				return;
> -
> -            // update all the other posts
> -            $query = "UPDATE ".$this->getPrefix()."articles_comments  
> SET parent_id = 0 WHERE parent_id = ".$commentid." AND article_id =  
> ".$artid.";";
> -            $result = $this->Execute( $query );
> -
> -			return $result;
> +			return( $this->deletePostComment( $articleId, $commentid ));
>  		}		
>
>          /**
> @@ -386,11 +180,7 @@
>           */
>          function deletePostComments( $artId )
>          {
> -        	$query = "DELETE FROM  
> ".$this->getPrefix()."articles_comments WHERE article_id = $artId";
> -
> -			$result = $this->Execute( $query );
> -
> -            return $result;
> +			return( CommentsCommon::deletePostComments( $artId,  
> COMMENT_TYPE_COMMENT ));
>          }
>
>          /**
> @@ -402,13 +192,7 @@
>           */
>          function updateCommentStatus( $commentId, $status )
>          {
> -        	$query = "UPDATE ".$this->getPrefix()."articles_comments SET
> -                      status = $status, date = date
> -                      WHERE id = $commentId";
> -
> -            $result = $this->Execute( $query );
> -
> -            return $result;
> +			return( CommentsCommon::updateCommentStatus( $commentId, $status,  
> COMMENT_TYPE_COMMENT ));
>          }
>
>          /**
> @@ -416,9 +200,7 @@
>           */
>          function purgeSpamComments()
>          {
> -        	$query = "DELETE FROM  
> ".$this->getPrefix()."articles_comments WHERE status =  
> ".COMMENT_STATUS_SPAM;
> -
> -            return $this->Execute( $query );
> +			return( CommentsCommon::purgeSpamComments( COMMENT_TYPE_COMMENT ));
>          }
>  		
>  		
> @@ -427,19 +209,7 @@
>  		 */
>  		function getComment( $id )
>  		{
> -			$query = "SELECT * FROM ".$this->getPrefix()."articles_comments
> -					  WHERE id = $id";
> -			$result = $this->Execute( $query );
> -			
> -			if( !$result )
> -				return false;
> -				
> -			if( $result->RowCount() == 0 )
> -				return false;
> -				
> -			$row = $result->FetchRow();
> -			
> -			return $this->_fillCommentInformation( $row );
> +			return( CommentsCommon::getComment( $id, COMMENT_TYPE_COMMENT ));
>  		}
>  		
>  		/**
> @@ -451,39 +221,7 @@
>  		 */
>  		function getBlogComments( $blogId, $maxItems = 0, $articleStatus =  
> POST_STATUS_PUBLISHED )
>  		{
> -			$prefix = $this->getPrefix();
> -			$query = "SELECT c.id AS id, c.article_id AS article_id, c.topic  
> AS topic,
> -			                 c.text AS text, c.date AS date, c.user_email AS  
> user_email,
> -							 c.user_url AS user_url, c.user_name AS user_name, c.parent_id  
> AS parent_id,
> -							 c.client_ip AS client_ip, c.send_notification AS  
> send_notification,
> -							 c.status AS status
> -					  FROM {$prefix}articles_comments c, {$prefix}articles a
> -			          WHERE a.blog_id = '".Db::qstr($blogId)."' AND a.id =  
> c.article_id
> -					        AND a.status = $articleStatus
> -					  ORDER BY date DESC";
> -			if( $maxItems > 0 )
> -				$query .= " LIMIT 0, $maxItems";
> -					
> -			$result = $this->Execute( $query );
> -			
> -			if( !$result )
> -				return false;
> -				
> -			if( $result->RowCount() == 0 )
> -				return Array();
> -				
> -			$comments = Array();
> -			$articles = new Articles();
> -			while( $row = $result->FetchRow()) {
> -				// load the article to which this comment belongs
> -				$comment = $this->_fillCommentInformation( $row );
> -				$article = $articles->getBlogArticle( $comment->getArticleId(),  
> $blogId );
> -				$comment->setArticle( $article );
> -				// and store everything in the array
> -				$comments[] = $comment;
> -			}
> -			
> -			return $comments;
> +			return( CommentsCommon::getBlogComments( $blogId, $maxItems,  
> $articleStatus, COMMENT_TYPE_COMMENT ));
>  		}
>  	}
>  ?>
>
> Added: plog/trunk/class/dao/commentscommon.class.php
> ===================================================================
> --- plog/trunk/class/dao/commentscommon.class.php	2005-04-17 17:32:10  
> UTC (rev 1853)
> +++ plog/trunk/class/dao/commentscommon.class.php	2005-04-17 17:35:24  
> UTC (rev 1854)
> @@ -0,0 +1,466 @@
> +<?php
> +
> +	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
> +	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );	
> +	include_once(  
> PLOG_CLASS_PATH."class/dao/articlecommentstatus.class.php" );
> +
> +	/**
> +	 * different orders that comments can have
> +	 */
> +	define( "COMMENT_ORDER_OLDEST_FIRST", 1 );
> +	define( "COMMENT_ORDER_NEWEST_FIRST", 2 );
> +	
> +	/**
> +	 * whether we'd like to fetch a comment, trackback or anything
> +	 */
> +	define( "COMMENT_TYPE_COMMENT", 1 );
> +	define( "COMMENT_TYPE_TRACKBACK", 2 );	
> +	define( "COMMENT_TYPE_ANY", -1 );
> +
> +    /**
> +	 * \ingroup DAO
> +	 *
> +     * Since comments and trackbacks are now in the same table, this  
> class contains all the
> +	 * common code needed to deal with these items. Most of the methods  
> are exactly the same in both
> +	 * ArticleComments and Trackbacks except that they take an  
> additional parameter called 'status'
> +	 * which can either be
> +	 *
> +	 * - COMMENT_TYPE_COMMENT
> +	 * - COMMENT_TYPE_TRACKBACK
> +	 * - COMMENT_TYPE_ANY
> +	 *
> +	 * Depending on whether we'd like to retrieve a trackback or a  
> comment.
> +     */
> +	class CommentsCommon extends Model
> +	{
> +
> +    	var $totalComments;
> +		var $_blogSettings;
> +		var $blogSettings;
> +		var $timeDiff;
> +
> +    	function CommentsCommon()
> +        {
> +        	$this->Model();
> +
> +            $this->totalComments = Array();
> +
> +            $this->_blogSettings = Array();
> +			
> +			$this->blogSettings = null;
> +			$this->timeDiff = 0;			
> +        }
> +
> +        /**
> +         * Adds a comment to an article
> +		 *
> +		 * @param comment the UserComment object that we're going to add.
> +		 * @return Returns true if successful or false if error. Also in  
> case of success, it will modify the UserComment
> +		 * object passed by reference and include its new id.
> +         */
> +		function addComment( &$comment )
> +        {
> +			$filter = new Textfilter();
> +        	$query = "INSERT INTO ".$this->getPrefix().
> +			          "articles_comments  
> (article_id,topic,text,user_name,user_email,
> +					                      user_url,parent_id,client_ip,status,  
> normalized_text,normalized_topic,type)
> +					   VALUES  
> (".$comment->getArticleId().",'".Db::qstr($comment->getTopic())."','".
> +					    
> Db::qstr($comment->getText())."','".$comment- 
> >getUserName()."','".$comment->getUserEmail()."','".
> +					   $comment->getUserUrl()."',".
> +					   $comment->getParentId().", '".$comment->getClientIp()."',  
> ".$comment->getStatus().", '".
> +					   Db::qstr($filter->normalizeText($comment->getText()))."', '".
> +					    
> Db::qstr($filter->normalizeText($comment->getTopic()))."',".$comment- 
> >getType().");";
> +
> +            $result = $this->Execute( $query );
> +			
> +			if( !$result )
> +				return false;
> +			
> +			// retrieve the last id and save it in the object
> +			$comment->setId( $this->_db->Insert_ID());
> +			
> +			return( true );
> +        }
> +
> +		/**
> +		 * Retrieves all the comments for a post
> +		 *
> +		 * @param artid The article identifier
> +		 * @param order The order in which comments should be retrieved
> +		 * @param status The status that the comment should have, use  
> COMMENT_STATUS_ALL for
> +		 * all possible statuses
> +		 * @param page
> +		 * @param itemsPerPage
> +		 * @return False if error or an array of ArticleComments objects
> +		 */
> +		function getPostComments( $artid, $order =  
> COMMENT_ORDER_NEWEST_FIRST, $status = COMMENT_STATUS_ALL, $type =  
> COMMENT_TYPE_ANY, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
> +		{
> +			$query = "SELECT * FROM ".$this->getPrefix()."articles_comments  
> WHERE article_id = '".Db::qstr($artid)."'";
> +            if( $status != COMMENT_STATUS_ALL )
> +            	$query .= " AND status = $status";
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";
> +
> +			// check in which order we should display those comments
> +			if( $order == COMMENT_ORDER_NEWEST_FIRST )
> +				$query .= " ORDER BY date DESC";
> +			else
> +				$query .= " ORDER BY date ASC";
> +			
> +            $result = $this->Execute( $query, $page, $itemsPerPage );
> +
> +            if( !$result )
> +            	return Array();
> +
> +            $comments = Array();
> +            while ($row = $result->FetchRow()) {
> +
> +				// find out the blogInfo object (after all, all these comments  
> belong to the same
> +				// blog so there is no risk of finding different blog_ids  
> anywhere!
> +				if( $this->blogSettings == null ) {
> +					$prefix = $this->getPrefix();
> +					$articleId = $row["article_id"];
> +					
> +					$query = "SELECT DISTINCT b.settings AS settings FROM  
> {$prefix}blogs b, {$prefix}articles a,
> +					         {$prefix}articles_comments c WHERE c.article_id = a.id  
> AND a.blog_id = b.id
> +							 AND a.id = $articleId";
> +					$result2 = $this->Execute( $query );
> +					$tmpRow = $result2->FetchRow();
> +					$this->blogSettings = Blogs::getBlogSettingsFromField(  
> $tmpRow["settings"] );
> +					
> +					$this->timeDiff = $this->blogSettings->getValue( "time_offset" );
> +				}
> +				
> +			
> +            	$lastArticleId=$row["article_id"];
> +				
> +				// now that we've got the time difference, we can
> +				// calculate what would the "real" date...
> +				$date = $row["date"];								
> +				$date = Timestamp::getDateWithOffset( $date, $this->timeDiff );
> +
> +				/**$comment = new UserComment(  
> $row["article_id"],	$row["parent_id"], $row["topic"],
> +											$row["text"], $date, $row["user_name"], $row["user_email"],
> +											$row["user_url"], $row["client_ip"], $row["spam_rate"],  
> $row["status"],
> +											$row["id"] );*/
> +											
> +				$comment = $this->_fillCommentInformation( $row );
> +				
> +                $comments[] = $comment;
> +			}
> +
> +			return $comments;
> +		}
> +		
> +		/**
> +		 * Retrieves all the comments for subquery of posts
> +		 *
> +		 * @private
> +		 */
> +		function getPostCommentsByIds( $ids, $order =  
> COMMENT_ORDER_NEWEST_FIRST, $status = COMMENT_STATUS_ALL, $type =  
> COMMENT_TYPE_ANY )
> +		{
> +
> +			$query = "SELECT * FROM ".$this->getPrefix()."articles_comments  
> WHERE article_id IN (".$ids.")";
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";			
> +            if( $status != COMMENT_STATUS_ALL )
> +            	$query .= " AND status = '".Db::qstr($status)."'";
> +
> +			// check in which order we should display those comments
> +			if( $order == COMMENT_ORDER_NEWEST_FIRST )
> +				$query .= " ORDER BY date DESC";
> +			else
> +				$query .= " ORDER BY date ASC";
> +			$result = $this->Execute( $query );
> +			if( !$result )
> +            	return false;
> +				
> +			// initialize these two thingies with harmless values
> +			$blogSettings = null;
> +			$timeDiff = 0;
> +
> +            while ($row = $result->FetchRow()) {
> +			
> +				// find out the blogInfo object (after all, all these comments  
> belong to the same
> +				// blog so there is no risk of finding different blog_ids  
> anywhere!
> +				if( $this->blogSettings == null ) {
> +					$prefix = $this->getPrefix();
> +					$articleId = $row["article_id"];
> +					
> +					$query = "SELECT DISTINCT b.settings AS settings FROM  
> {$prefix}blogs b, {$prefix}articles a,
> +					         {$prefix}articles_comments c WHERE c.article_id = a.id  
> AND a.blog_id = b.id
> +							 AND a.id = $articleId";
> +					$result2 = $this->Execute( $query );
> +					$tmpRow = $result2->FetchRow();
> +					$this->blogSettings = Blogs::getBlogSettingsFromField(  
> $tmpRow["settings"] );
> +					
> +					$this->timeDiff = $this->blogSettings->getValue( "time_offset" );
> +				}
> +				
> +			
> +            	$lastArticleId=$row["article_id"];
> +				
> +				// now that we've got the time difference, we can
> +				// calculate what would the "real" date...
> +				$date = $row["date"];				
> +				$date = Timestamp::getDateWithOffset( $date, $this->timeDiff );
> +
> +				/**$comment = new UserComment(  
> $row["article_id"],	$row["parent_id"], $row["topic"],
> +											$row["text"], $date, $row["user_name"], $row["user_email"],
> +											$row["user_url"], $row["client_ip"], $row["spam_rate"],  
> $row["status"],
> +											$row["id"] );**/
> +											
> +				$comment = $this->_fillCommentInformation( $row );
> +				
> +				// save the comment in the array
> +                $comments[$lastArticleId][]=$comment;
> +			}
> +
> +			return $comments;
> +		}
> +		
> +        /**
> +         * Returns the total number of comments for a post
> +		 *
> +		 * @param artId the post id
> +		 * @param status
> +		 * @return The number of comments
> +         */
> +        function getNumPostComments( $artId, $status =  
> COMMENT_STATUS_ALL, $type = COMMENT_TYPE_ANY )
> +        {
> +			// create the table name
> +			$prefix = $this->getPrefix();
> +			$table = "{$prefix}articles_comments";
> +			// and the condition if any...
> +			$cond = "article_id = '".Db::qstr($artId)."'";
> +			if( $status != COMMENT_STATUS_ALL )
> +				$cond .= " AND status = '".Db::qstr($status)."'";
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";
> +				
> +
> +			// get the number of items and return it to the caller
> +			return( $this->getNumItems( $table, $cond ));		
> +        }
> +
> +        /**
> +         * Retrieves only one post from a given article
> +         */
> +        function getPostComment( $artid, $commentid, $type =  
> COMMENT_TYPE_ANY )
> +		{
> +			$query = "SELECT * FROM ".$this->getPrefix()."articles_comments
> +			          WHERE id = '".Db::qstr($commentid)."' AND article_id =  
> '".Db::qstr($artid)."'";
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";					
> +
> +			$result = $this->Execute( $query );
> +
> +			if( !$result )
> +				return false;
> +
> +            $row = $result->FetchRow();
> +            $comment = $this->_fillCommentInformation( $row );
> +
> +			return $comment;
> +		}
> +
> +        /**
> +         * 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", $type = COMMENT_TYPE_ANY )
> +        {
> +        	$query = "SELECT COUNT(*) AS total FROM  
> ".$this->getPrefix()."articles_comments
> +                       WHERE topic = '".Db::qstr($topic)."' AND text  
> = '".Db::qstr($text)."'
> +                       AND article_id = $articleId AND parent_id =  
> $parentId AND
> +                       client_ip = '$clientIp' AND user_name =  
> '$userName' AND
> +                       user_email = '$userEmail' AND user_url =  
> '$userUrl'
> +                       AND date <= NOW()";
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";
> +					
> +
> +            $result = $this->Execute( $query );
> +
> +            if( !$result )
> +            	return false;
> +
> +            $row = $result->FetchRow();
> +
> +            if( $row["total"] >= 1 )
> +            	return true;
> +            else
> +            	return false;
> +        }
> +
> +		/**
> +		 * Removes a comment from a post. It also updates all the other  
> posts that
> +         * have this one as the parent and makes them look as if they  
> were 'top level'
> +         * comments with no parent.
> +         *
> +         * @param artid The article identifier.
> +         * @param commentid The comment identifier.
> +		 * @param type
> +		 */
> +		function deletePostComment( $artid, $commentid, $type =  
> COMMENT_TYPE_ANY )
> +		{
> +			$query = "DELETE FROM ".$this->getPrefix()."articles_comments
> +			          WHERE id = '".Db::qstr($commentid)."' AND article_id =  
> '".Db::qstr($artid)."'";
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";
> +
> +			$result = $this->Execute( $query );
> +
> +			if( $this->_db->Affected_Rows( $result ) == 0 )
> +				return;
> +
> +            // update all the other posts
> +            $query = "UPDATE ".$this->getPrefix()."articles_comments  
> SET parent_id = 0 WHERE parent_id = ".$commentid." AND article_id =  
> ".$artid.";";
> +            $result = $this->Execute( $query );
> +
> +			return $result;
> +		}		
> +
> +        /**
> +         * Removes all the comments from a post.
> +         *
> +         * @param artId The article identifier
> +		 * @param type
> +         */
> +        function deletePostComments( $artId, $type = COMMENT_TYPE_ANY  
> )
> +        {
> +        	$query = "DELETE FROM ".$this->getPrefix()."articles_comments
> +			          WHERE article_id = '".Db::qstr($artId)."'";
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";
> +					
> +
> +			$result = $this->Execute( $query );
> +
> +            return $result;
> +        }
> +
> +        /**
> +         * updates the status of a comment, regarding its spam  
> status...
> +         *
> +         * @param commentId
> +         * @param status
> +		 * @param type
> +         * @return true or false, depending...
> +         */
> +        function updateCommentStatus( $commentId, $status, $type =  
> COMMENT_TYPE_ANY )
> +        {
> +        	$query = "UPDATE ".$this->getPrefix()."articles_comments SET
> +                      status = '".Db::qstr($status)."', date = date
> +                      WHERE id = ".Db::qstr($commentId)."'";
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";					
> +
> +            $result = $this->Execute( $query );
> +
> +            return $result;
> +        }
> +
> +        /**
> +         * removes all comments marked as spam from the database
> +		 *
> +		 * @param type
> +         */
> +        function purgeSpamComments( $type = COMMENT_TYPE_ANY )
> +        {
> +        	$query = "DELETE FROM ".$this->getPrefix()."articles_comments
> +			          WHERE status = ".COMMENT_STATUS_SPAM;
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";					
> +			
> +
> +            return $this->Execute( $query );
> +        }
> +		
> +		
> +		/**
> +		 * returns a single comment, identified by its identifier
> +		 *
> +		 * @param type
> +		 */
> +		function getComment( $id, $type = COMMENT_TYPE_ANY )
> +		{
> +			$query = "SELECT * FROM ".$this->getPrefix()."articles_comments
> +					  WHERE id = '".Db::qstr($id)."'";
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";
> +			
> +			$result = $this->Execute( $query );
> +			
> +			if( !$result )
> +				return false;
> +				
> +			if( $result->RowCount() == 0 )
> +				return false;
> +				
> +			$row = $result->FetchRow();
> +			
> +			return $this->_fillCommentInformation( $row );
> +		}
> +		
> +		/**
> +		 * returns the lastest $maxItems comments received in the blog
> +		 *
> +		 * @param blogId
> +		 * @param maxItems
> +		 * @return An array of ArticleComment objects
> +		 */
> +		function getBlogComments( $blogId, $maxItems = 0, $articleStatus =  
> POST_STATUS_PUBLISHED, $type = COMMENT_TYPE_ANY )
> +		{
> +			$prefix = $this->getPrefix();
> +			$query = "SELECT c.id AS id, c.article_id AS article_id, c.topic  
> AS topic,
> +			                 c.text AS text, c.date AS date, c.user_email AS  
> user_email,
> +							 c.user_url AS user_url, c.user_name AS user_name, c.parent_id  
> AS parent_id,
> +							 c.client_ip AS client_ip, c.send_notification AS  
> send_notification,
> +							 c.status AS status
> +					  FROM {$prefix}articles_comments c, {$prefix}articles a
> +			          WHERE a.blog_id = '".Db::qstr($blogId)."' AND a.id =  
> c.article_id
> +					        AND a.status = '".Db::qstr($articleStatus)."'";
> +			if( $type != COMMENT_TYPE_ANY )
> +				$query .= " AND type = '".Db::qstr($type)."'";							
> +			$query .=" ORDER BY date DESC";
> +			if( $maxItems > 0 )
> +				$query .= " LIMIT 0, $maxItems";
> +					
> +			$result = $this->Execute( $query );
> +			
> +			if( !$result )
> +				return false;
> +				
> +			if( $result->RowCount() == 0 )
> +				return Array();
> +				
> +			$comments = Array();
> +			$articles = new Articles();
> +			while( $row = $result->FetchRow()) {
> +				// load the article to which this comment belongs
> +				$comment = $this->_fillCommentInformation( $row );
> +				$article = $articles->getBlogArticle( $comment->getArticleId(),  
> $blogId );
> +				$comment->setArticle( $article );
> +				// and store everything in the array
> +				$comments[] = $comment;
> +			}
> +			
> +			return $comments;
> +		}
> +		
> +		/**
> +		 * @private
> +		 */
> +        function _fillCommentInformation( $row )
> +        {
> +			throw( new Exception( "This method must be implemented by child  
> classes!" ));
> +			
> +			die();
> +		}
> +	}
> +?>
>
> Modified: plog/trunk/class/dao/trackback.class.php
> ===================================================================
> --- plog/trunk/class/dao/trackback.class.php	2005-04-17 17:32:10 UTC  
> (rev 1853)
> +++ plog/trunk/class/dao/trackback.class.php	2005-04-17 17:35:24 UTC  
> (rev 1854)
> @@ -1,26 +1,18 @@
>  <?php
>
>
> -	include_once( PLOG_CLASS_PATH."class/database/dbobject.class.php" );
> +	include_once( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
>
>  	/**
> -     * Represents a trackback item.
> +     * Represents a trackback item, even though in pLog 1.1  
> trackbacks are
> +	 * nothing else than remote comments and in fact they are even  
> stored in the
> +	 * same table as comments.
>  	 *
>  	 * \ingroup DAO
>       */
> -    class TrackBack extends DbObject
> +    class TrackBack extends UserComment
>  	{
>
> -    	var $_url;
> -        var $_title;
> -        var $_articleId;
> -        var $_excerpt;
> -        var $_blogName;
> -        var $_date;
> -        var $_dateObject;
> -        var $_id;
> -		var $_article;
> -
>          /**
>           * Constructor. Creates a new trackback object.
>           *
> @@ -30,22 +22,26 @@
>           * @param excerpt An excerpt of the post.
>           * @param blogName The name of the blog which is ping backing  
> to us.
>           * @param date Date of the post.
> +		 * @param clientIp the IP address where the trackback is coming from
>           * @param id Identifier of this item.
>           */
> -        function TrackBack( $url, $title, $articleId, $excerpt,  
> $blogName, $date, $id = -1)
> +        function TrackBack( $url, $title, $articleId, $excerpt,  
> $blogName, $date, $clientIp, $spamRate = 0, $status =  
> COMMENT_STATUS_NONSPAM, $id = -1 )
>          {
> -			$this->DbObject();
> -        	$this->_url = $url;
> -            $this->_title = $title;
> -            $this->_articleId = $articleId;
> -            $this->_excerpt = $excerpt;
> -            $this->_blogName = $blogName;
> -            $this->_date = $date;
> -            $this->_dateObject = new Timestamp( $this->_date );
> -            $this->_id = $id;
> -			
> -			// this will be initialized later
> -			$this->_article = null;
> +			// initialize the UserComment object
> +			$this->UserComment( $articleId,
> +			                    0,
> +								$title,
> +								$excerpt,
> +								$date,
> +								$blogName,
> +								'',
> +								$url,
> +								$clientIp,
> +								$spamRate,
> +								$status,
> +								$id );
> +			// and mark it as a trackback
> +			$this->setType( COMMENT_TYPE_TRACKBACK );
>          }
>
>          /**
> @@ -55,7 +51,7 @@
>           */
>          function getUrl()
>          {
> -        	return $this->_url;
> +        	return( $this->getUserUrl());
>          }
>
>          /**
> @@ -66,20 +62,10 @@
>           */
>          function getTitle()
>          {
> -        	return $this->_title;
> +        	return( $this->getTopic());
>          }
>
>          /**
> -         * Returns the article identifier of the article for which  
> this trackback link was received.
> -         *
> -         * @param An integer containing the article identifier of  
> this entry.
> -         */
> -        function getArticleId()
> -        {
> -        	return $this->_articleId;
> -        }
> -
> -        /**
>           * According to the specification of the trackback protocol,  
> the excerpt is a short string giving
>           * more information about the entry related to the ping.  
> Normally, it will be at most, the first 255
>           * characters of the entry, but it could also be empty since  
> it is not mandatory.
> @@ -88,7 +74,7 @@
>           */
>          function getExcerpt()
>          {
> -        	return $this->_excerpt;
> +        	return( $this->getText());
>          }
>
>          /**
> @@ -98,67 +84,7 @@
>           */
>          function getBlogName()
>          {
> -        	return $this->_blogName;
> +        	return( $this->getUserName());
>          }
> -
> -        /**
> -         * Returns the date as of the SQL database (14-digit date) of  
> when the trackback ping was received.
> -         *
> -         * @return A 14-digit date representation.
> -         */
> -        function getDate()
> -        {
> -        	return $this->_date;
> -        }
> -
> -        /**
> -         * Returns the identifier of this entry in the database.
> -         *
> -         * @return An integer containing the identifier of this  
> trackback in the database.
> -         */
> -        function getId()
> -        {
> -        	return $this->_id;
> -        }
> -		
> -		/**
> -		 * sets the id of the trackback
> -		 *
> -		 * @param id New database id of the object
> -		 */
> -		function setId( $id )
> -		{
> -			$this->_id = $id;
> -		}
> -
> -        /**
> -         * Returns the Timestamp object corresponding to the SQL-like  
> date. The Timestamp class offers
> -         * convenience methods, easier to use if we want to fetch  
> only the year, month, day, etc.
> -         *
> -         * @return A Timestamp object representing the date.
> -         */
> -        function getDateObject()
> -        {
> -        	return $this->_dateObject;
> -        }
> -		
> -		/**
> -		 * returns the Article object to which this one trackback points
> -		 *
> -		 * @return An Article object
> -		 */
> -		function getArticle()
> -		{
> -			// if we haven't loaded the article yet
> -			if( $this->_article == null ) {
> -				include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
> -				
> -				// load the article and return it
> -				$articles = new Articles();
> -				$this->_article = $articles->getBlogArticle( $this->_articleId );
> -			}
> -			
> -			return( $this->_article );
> -		}
>      }
>  ?>
>
> Modified: plog/trunk/class/dao/trackbacks.class.php
> ===================================================================
> --- plog/trunk/class/dao/trackbacks.class.php	2005-04-17 17:32:10 UTC  
> (rev 1853)
> +++ plog/trunk/class/dao/trackbacks.class.php	2005-04-17 17:35:24 UTC  
> (rev 1854)
> @@ -1,6 +1,6 @@
>  <?php
>
> -	include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
> +	include_once( PLOG_CLASS_PATH."class/dao/commentscommon.class.php" );
>      include_once( PLOG_CLASS_PATH."class/dao/trackback.class.php" );
>
>  	/**
> @@ -9,28 +9,18 @@
>       * here: http://www.movabletype.org/docs/mttrackback.html.
>  	 *
>  	 * \ingroup DAO
> +	 *
> +	 * @see CommentsCommon
>       */
> -    class Trackbacks extends Model
> +    class Trackbacks extends CommentsCommon
>  	{
>
> -    	var $_blogSettings;
> -		var $blogSettings;
> -		var $timeDiff;
> -
>      	/**
>           * Initializes the connection to the database
>           */
>      	function Trackbacks()
>          {
> -        	$this->Model();
> -
> -            // we can keep a little cache of already-fetched  
> BlogSettings
> -            // objects, so that we don't have to fetch them again  
> when the only
> -            // thing that we need to know is the time difference once  
> again
> -            $this->_blogSettings = Array();
> -			
> -			$this->blogSettings = null;
> -			$this->timeDiff = 0;
> +        	$this->CommentsCommon();
>          }
>
>          /**
> @@ -42,83 +32,30 @@
>           */
>  		function addTrackback( &$trackback )
>          {
> -			$artId = $trackback->getArticleId();
> -			$url = $trackback->getUrl();
> -			$title = $trackback->getTitle();
> -			$blog = $trackback->getBlogName();
> -			$excerpt = $trackback->getExcerpt();
> -		
> -        	if( $title == "" )
> -            	$title = $url;
> -
> -        	$query = "INSERT INTO ".$this->getPrefix()."trackbacks  
> (url,title,article_id,excerpt,blog_name)
> -			          VALUES  
> ('".Db::qstr($url)."','".Db::qstr($title)."',".Db::qstr($artId).",'".
> -					  Db::qstr($excerpt)."','".Db::qstr($blog)."');";
> -
> -            $result = $this->Execute( $query );
> -
> -            if( !$result )
> -            	return false;
> -
> -			// set the trackback id
> -			$trackback->setId( $this->_db->Insert_ID());
> -			
> -           	return true;
> +			return( CommentsCommon::addComment( $trackback ));
>          }
>
>          /**
>           * Returns the trackback items for a given article.
>           *
>           * @param artId The article identifier.
> +		 * @param status One of these:
> +		 * - COMMENT_STATUS_ALL
> +		 * - COMMENT_STATUS_SPAM
> +		 * - COMMENT_STATUS_NONSPAM
>  		 * @param page
>  		 * @param itemsPerPage
>           * @return An array of TrackbackItem objects with the  
> information, or false otherwise.
>           */
> -        function getArticleTrackBacks( $artId, $page =  
> DEFAULT_PAGING_ENABLED, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
> +        function getArticleTrackBacks( $artId, $status =  
> COMMENT_STATUS_ALL, $page = DEFAULT_PAGING_ENABLED, $itemsPerPage =  
> DEFAULT_ITEMS_PER_PAGE )
>          {
> -        	$query = "SELECT * FROM ".$this->getPrefix()."trackbacks  
> WHERE article_id = '".Db::qstr($artId)."'";
> -
> -            $result = $this->Execute( $query, $page, $itemsPerPage );
> -
> -            if( !$result )
> -            	return false;
> -
> -            $trackbacks = Array();
> -            while( $row = $result->FetchRow()) {
> -            	//$trackback = $this->_fillTrackbackInformation( $row );
> -				
> -				// find out the blogInfo object (after all, all these comments  
> belong to the same
> -				// blog so there is no risk of finding different blog_ids  
> anywhere!
> -				if( $this->blogSettings == null ) {
> -					$prefix = $this->getPrefix();
> -					$articleId = $row["article_id"];
> -					
> -					$query = "SELECT DISTINCT b.settings AS settings FROM  
> {$prefix}blogs b, {$prefix}articles a,
> -					         {$prefix}articles_comments c WHERE c.article_id = a.id  
> AND a.blog_id = b.id
> -							 AND a.id = $articleId";
> -					$result2 = $this->Execute( $query );
> -					$tmpRow = $result2->FetchRow();
> -					$this->blogSettings = Blogs::getBlogSettingsFromField(  
> $tmpRow["settings"] );
> -					$this->timeDiff = $this->blogSettings->getValue( "time_offset" );
> -				}
> -				
> -				// now that we've got the time difference, we can
> -				// calculate what would the "real" date...
> -				$date = $row["date"];				
> -				$date = Timestamp::getDateWithOffset( $date, $this->timeDiff );
> -
> -				$trackback = new TrackBack( $row["url"],
> -									$row["title"],
> -									$row["article_id"],
> -									$row["excerpt"],
> -									$row["blog_name"],
> -									$date,
> -									$row["id"] );
> -				
> -				$trackbacks[] = $trackback;
> -            }
> -
> -            return $trackbacks;
> +			$tbs = CommentsCommon::getPostComments( $artId,  // article id
> +			                                          
> COMMENT_ORDER_NEWEST_FIRST,   // no choice of order for trackbacks
> +													 $status,  // spam or not
> +													 COMMENT_TYPE_TRACKBACK,   // we're loading trackbacks
> +													 $page,
> +													 $itemsPerPage );
> +			return( $tbs );
>          }
>  		
>  		/**
> @@ -130,31 +67,7 @@
>  		 */
>  		function getBlogTrackbacks( $blogId, $amount = -1 )
>  		{
> -			$prefix = $this->getPrefix();
> -
> -			$query = "SELECT t.id AS id, t.url AS url, t.title AS title,  
> t.article_id AS article_id,
> -			                 t.excerpt AS excerpt, t.blog_name AS blog_name,  
> t.date AS date
> -			          FROM {$prefix}trackbacks t, {$prefix}articles a
> -					  WHERE a.blog_id = '".Db::qstr( $blogId )."' AND a.id =  
> t.article_id
> -					  ORDER BY t.date DESC";
> -			if( $amount > 0 )
> -				$query .= " LIMIT 0, $amount";
> -				
> -			$trackbacks = Array();
> -			
> -			$result = $this->Execute( $query );
> -			
> -			// if there was an error, return an empty array
> -			if( !$result )
> -				return( $trackbacks );
> -				
> -			// otherwise proceed and loop through the rows
> -			while( $row = $result->FetchRow()) {
> -				$trackback = $this->_fillTrackbackInformation( $row );
> -				array_push( $trackbacks, $trackback );
> -			}			
> -			
> -			return( $trackbacks );
> +			return( CommentsCommon::getBlogComments( $blogId, $amount,  
> COMMENT_TYPE_TRACKBACK ));
>  		}
>
>  		/**
> @@ -166,56 +79,7 @@
>  		 */
>          function getArticleTrackBacksByIds( $artIds )
>          {
> -            $trackbacks = array();
> -
> -        	$query = "SELECT * FROM ".$this->getPrefix()."trackbacks  
> WHERE article_id IN (".$artIds.")";
> -
> -            $result = $this->Execute( $query );
> -
> -            if( !$result )
> -            	return Array();
> -				
> -			// harmless values, but they mark that we haven't loaded any data  
> yet!
> -			$blogSettings = null;
> -			$timeDiff = 0;
> -
> -            while ($row = $result->FetchRow()) {
> -			
> -				// find out the blogInfo object (after all, all these comments  
> belong to the same
> -				// blog so there is no risk of finding different blog_ids  
> anywhere!
> -				if( $this->blogSettings == null ) {
> -					$prefix = $this->getPrefix();
> -					$articleId = $row["article_id"];
> -					
> -					$query = "SELECT DISTINCT b.settings AS settings FROM  
> {$prefix}blogs b, {$prefix}articles a,
> -					         {$prefix}articles_comments c WHERE c.article_id = a.id  
> AND a.blog_id = b.id
> -							 AND a.id = $articleId";
> -					$result2 = $this->Execute( $query );
> -					$tmpRow = $result2->FetchRow();
> -					$this->blogSettings = Blogs::getBlogSettingsFromField(  
> $tmpRow["settings"] );
> -					
> -					$this->timeDiff = $this->blogSettings->getValue( "time_offset" );
> -				}
> -			
> -            	$lastArticleId=$row["article_id"];
> -				
> -				// now that we've got the time difference, we can
> -				// calculate what would the "real" date...
> -				$date = $row["date"];				
> -				$date = Timestamp::getDateWithOffset( $date, $this->timeDiff );
> -
> -				$trackback = new TrackBack( $row["url"],
> -									$row["title"],
> -									$row["article_id"],
> -									$row["excerpt"],
> -									$row["blog_name"],
> -									$date,
> -									$row["id"] );
> -
> -                $trackbacks[$lastArticleId][]=$trackback;
> -			}
> -
> -            return $trackbacks;
> +			return( CommentsCommon::getArticleTrackBacksByIds( $artIds,  
> COMMENT_TYPE_TRACKBACK ));
>          }
>
>          /**
> @@ -224,7 +88,7 @@
>           * @private
>           * @param row The row with the information
>           */
> -        function _fillTrackbackInformation( $row )
> +        function _fillCommentInformation( $row )
>          {
>          	// ---
>              // there we go again doing dirty things to the poor  
> trackbacks...
> @@ -255,13 +119,16 @@
>              // calculate what would the "real" date...
>              $date = Timestamp::getDateWithOffset( $date, $timeDiff );
>
> -        	$trackback = new TrackBack( $row["url"],
> -                                  $row["title"],
> +        	$trackback = new TrackBack( $row["user_url"],
> +                                  $row["topic"],
>                                    $row["article_id"],
> -                                  $row["excerpt"],
> -                                  $row["blog_name"],
> +                                  $row["text"],
> +                                  $row["user_name"],
>                                    $date,
> -                                  $row["id"] );
> +								  $row["client_ip"],
> +								  $row["spam_rate"],
> +								  $row["status"],
> +                                  $row["id"] );							
>  								
>  			return( $trackback );
>          }
> @@ -270,19 +137,12 @@
>           * Returns how many trackbacks have been received for the  
> given article
>           *
>           * @param artId The article identifier.
> +		 * @status
>           * @return The number of trackbacks received pointing to that  
> article,
>           */
> -        function getNumTrackbacksArticle( $artId )
> +        function getNumTrackbacksArticle( $artId, $status =  
> COMMENT_STATUS_ALL )
>          {
> -        	if( empty($this->totalTrackbacks)) {
> -        		$query1 = "SELECT article_id, COUNT(*) AS 'count' FROM  
> ".$this->getPrefix()."trackbacks GROUP BY (article_id)";
> -            	$this->totalTrackbacks = $this->_db->GetAssoc( $query1 );
> -            }
> -
> -            $totalTrackbacks = $this->totalTrackbacks[$artId];
> -            if( $totalTrackbacks == "" ) $totalTrackbacks = 0;
> -
> -            return $totalTrackbacks;
> +			return( CommentsCommon::getNumPostComments( $artId, $status,  
> COMMENT_TYPE_TRACKBACK ));
>          }
>
>          /**
> @@ -292,11 +152,7 @@
>           */
>          function deletePostTrackbacks( $artId )
>          {
> -        	$query = "DELETE FROM ".$this->getPrefix()."trackbacks WHERE  
> article_id = $artId";
> -
> -			$result = $this->Execute( $query );
> -
> -            return $result;
> +			return( CommentsCommon::deletePostComments( $artId,  
> COMMENT_TYPE_TRACKBACK ));
>          }
>  		
>  		/**
> @@ -308,22 +164,7 @@
>  		 */
>  		function getArticleTrackback( $trackbackId, $articleId = -1 )
>  		{	
> -			$prefix = $this->getPrefix();
> -			$query = "SELECT * FROM {$prefix}trackbacks WHERE id =  
> '".Db::qstr($trackbackId)."'";
> -			if( $articleId > 0 )
> -				$query .= " AND article_id = '".Db::qstr($articleId)."'";
> -				
> -			$result = $this->Execute( $query );
> -			if( !$result )
> -				return false;
> -				
> -			if( $result->RowCount() == 0 )
> -				return false;
> -				
> -			$row = $result->FetchRow();
> -			$tb = $this->_fillTrackbackInformation( $row );
> -			
> -			return $tb;
> +			return( CommentsCommon::getPostComment( $articleId, $trackbackId,  
> COMMENT_TYPE_TRACKBACK ));
>  		}
>  		
>  		/**
> @@ -333,14 +174,9 @@
>  		 * @param articleId
>  		 * @return True if successful or false otherwise
>  		 */
> -		function deletePostTrackback( $trackbackId, $articleId = -1 )
> +		function deletePostTrackback( $trackbackId, $articleId )
>  		{
> -			$prefix = $this->getPrefix();
> -			$query = "DELETE FROM {$prefix}trackbacks WHERE id =  
> '".Db::qstr($trackbackId)."'";
> -			if( $articleId > 0 )
> -				$query .= " AND article_id = '".Db::qstr($articleId)."'";
> -				
> -			return $this->Execute( $query );
> +			return( CommentsCommon::deletePostComment( $articleId,  
> $trackbackId, COMMENT_TYPE_TRACKBACK ));
>  		}
>      }
>  ?>
>
> Modified: plog/trunk/class/dao/usercomment.class.php
> ===================================================================
> --- plog/trunk/class/dao/usercomment.class.php	2005-04-17 17:32:10 UTC  
> (rev 1853)
> +++ plog/trunk/class/dao/usercomment.class.php	2005-04-17 17:35:24 UTC  
> (rev 1854)
> @@ -4,7 +4,7 @@
>  	include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
>  	include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
>  	include_once( PLOG_CLASS_PATH."class/dao/article.class.php" );
> -
> +	
>      /**
>       * This class represents a comment made by a casual user to an  
> article. Please use the getter methods
>       * exposed here to get all the information regarding this  
> comment, such as the name of the user who
> @@ -83,6 +83,11 @@
>           * @private
>           */
>          var $_status;
> +		
> +		/**
> +		 * @private
> +		 */
> +		var $_type;
>
>          /**
>           * Creates a new user comment.
> @@ -118,6 +123,9 @@
>  			// load this or not... so if I were you, I wouldn't really trust  
> that this has been loaded :)
>  			// also, it is not necessary most of the times!
>  			$this->_article = null;
> +			
> +			// by default, we've got a user comment instead of a trackback
> +			$this->_type = COMMENT_TYPE_COMMENT;
>  		}
>
>          /**
> @@ -341,21 +349,38 @@
>          	$this->_clientIp = $clientIp;
>          }
>
> +		/**
> +		 * Sets the spamn rate of this comment
> +		 *
> +		 * @private
> +		 * @param spamRate The new spam rate
> +		 */
>          function setSpamRate( $spamRate )
>          {
>          	$this->_spamRate = $spamRate;
>          }
>
> +		/**
> +		 * @return Returns the spam rate of this comment
> +		 */
>          function getSpamRate()
>          {
>          	return $this->_spamRate;
>          }
>
> +		/**
> +		 * Sets the status of this comment
> +		 *
> +		 * @param status The new status
> +		 */
>          function setStatus( $status )
>          {
>          	$this->_status = $status;
>          }
>
> +		/**
> +		 * @return Returns the new status of this comment
> +		 */
>          function getStatus()
>          {
>          	return $this->_status;
> @@ -384,6 +409,28 @@
>  		{
>  			return $this->_article;
>  		}
> -
> +		
> +		/**
> +		 * @return Returns the type of this comment, either  
> COMMENT_TYPE_COMMENT or
> +		 * COMMENT_TYPE_TRACKBACK depending on whether the comment is a  
> "normal" user comment
> +		 * or a trackback
> +		 */
> +		function getType()
> +		{
> +			return( $this->_type );
> +		}
> +		
> +		/**
> +		 * sets the comment type
> +		 *
> +		 * @private
> +		 * @param type The new type:
> +		 * - COMMENT_TYPE_COMMENT
> +		 * - COMMENT_TYPE_TRACKBACK
> +		 */
> +		function setType( $type )
> +		{
> +			$this->_type = $type;
> +		}
>  	}
>  ?>
>
> Modified: plog/trunk/trackback.php
> ===================================================================
> --- plog/trunk/trackback.php	2005-04-17 17:32:10 UTC (rev 1853)
> +++ plog/trunk/trackback.php	2005-04-17 17:35:24 UTC (rev 1854)
> @@ -13,7 +13,8 @@
>  	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
>  	include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
>  	include_once(  
> PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
> -    include_once(  
> PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );	
> +    include_once(  
> PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
> +	include_once( PLOG_CLASS_PATH."class/net/client.class.php" );
>
>      //
>      // set this to 'true' if you want this script to log whatever it  
> is
> @@ -162,7 +163,8 @@
>  	$trackbacks = new TrackBacks();
>  	// create teh trackback object
>  	$now = new Timestamp();
> -	$trackback = new Trackback( $url, $title, $articleId, $excerpt,  
> $blogName, $now->getTimestamp());
> +	$ip = Client::getIp();
> +	$trackback = new Trackback( $url, $title, $articleId, $excerpt,  
> $blogName, $now->getTimestamp(), $ip );
>  	// throw the event in case somebody is listening to it!
>  	$pm->notifyEvent( EVENT_PRE_TRACKBACK_ADD, Array( "trackback" =>  
> &$trackback ));
>  	$result = $trackbacks->addTrackBack( $trackback );
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.plogworld.net
> http://devel.plogworld.net/mailman/listinfo/plog-svn
>




More information about the pLog-svn mailing list