[pLog-svn] r2311 - in plog/trunk: class/action/admin class/dao class/view/admin templates/admin

oscar at devel.plogworld.net oscar at devel.plogworld.net
Tue Jul 12 21:22:28 GMT 2005


Author: oscar
Date: 2005-07-12 21:22:28 +0000 (Tue, 12 Jul 2005)
New Revision: 2311

Modified:
   plog/trunk/class/action/admin/admindeletecommentaction.class.php
   plog/trunk/class/action/admin/admineditcommentsaction.class.php
   plog/trunk/class/action/admin/adminedittrackbacksaction.class.php
   plog/trunk/class/action/admin/adminmarkcommentaction.class.php
   plog/trunk/class/dao/article.class.php
   plog/trunk/class/dao/articlecomments.class.php
   plog/trunk/class/dao/commentscommon.class.php
   plog/trunk/class/view/admin/adminarticlecommentslistview.class.php
   plog/trunk/class/view/admin/adminarticletrackbackslistview.class.php
   plog/trunk/templates/admin/editcomments.template
   plog/trunk/templates/admin/edittrackbacks.template
Log:
added two new pages in the admin interface that allow to see all comments and all trackbacks in one single page, instead of accessing them via the "posts" page. The "comments" page is already working fine but the "trackbacks" page still needs some work.

Modified: plog/trunk/class/action/admin/admindeletecommentaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admindeletecommentaction.class.php	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/class/action/admin/admindeletecommentaction.class.php	2005-07-12 21:22:28 UTC (rev 2311)
@@ -37,7 +37,7 @@
 				
 			$view = new AdminPostsListView( $this->_blogInfo );
 			$view->setErrorMessage( $this->_locale->tr("error_deleting_comments"));
-			$this->setValidationErrorView( $view );			
+			$this->setValidationErrorView( $view );
         }
 		
 		/**
@@ -68,21 +68,28 @@
 			$successMessage = "";
 			$totalOk = 0;
 			
-			// if we can't even load the article, then forget it...
-			$articles = new Articles();
-			$article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
-			if( !$article ) {
-				$this->_view = new AdminPostsListView( $this->_blogInfo );
-				$this->_view->setErrorMessage( $this->_locale->tr("error_fetching_post" ));
-				$this->setCommonData();
-				
-				return false;
+			if( $articleId > 0 ) {
+				// if we can't even load the article, then forget it...
+				$articles = new Articles();
+				$article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
+				if( !$article ) {
+					$this->_view = new AdminPostsListView( $this->_blogInfo );
+					$this->_view->setErrorMessage( $this->_locale->tr("error_fetching_post" ));
+					$this->setCommonData();
+					
+					return false;
+				}
 			}
+			else {
+				// there was no article, so this probably was the view that shows all comments...
+				$article = null;
+			}
 			
 			// loop through the comments and remove them
             foreach( $this->_commentIds as $commentId ) {
             	// fetch the comment
-                $comment = $comments->getPostComment( $this->_articleId, $commentId );
+                //$comment = $comments->getPostComment( $this->_articleId, $commentId );
+				$comment = $comments->getComment( $commentId );
 				
 				if( !$comment ) {
 					$errorMessage .= $this->_locale->pr("error_deleting_comment2", $commentId);
@@ -91,23 +98,35 @@
 					// fire the pre-event
 					$this->notifyEvent( EVENT_PRE_COMMENT_DELETE, Array( "comment" => &$comment ));
 					
-					if( !$comments->deletePostComment( $article->getId(), $commentId ))
+					// check if the comment really belongs to this blog...
+					$article = $comment->getArticle();
+					if( $article->getBlogId() != $this->_blogInfo->getId()) {
+						// if not, then we shouldn't be allowed to remove anything!
 						$errorMessage .= $this->_locale->pr("error_deleting_comment", $comment->getTopic())."<br/>";
+					}
 					else {
-						$totalOk++;
-						if( $totalOk < 2 )
-							$successMessage .= $this->_locale->pr("comment_deleted_ok", $comment->getTopic())."<br/>";
-						else
-							$successMessage = $this->_locale->pr("comments_deleted_ok", $totalOk );
+						if( !$comments->deletePostComment( $article->getId(), $commentId ))
+							$errorMessage .= $this->_locale->pr("error_deleting_comment", $comment->getTopic())."<br/>";
+						else {
+							$totalOk++;
+							if( $totalOk < 2 )
+								$successMessage .= $this->_locale->pr("comment_deleted_ok", $comment->getTopic())."<br/>";
+							else
+								$successMessage = $this->_locale->pr("comments_deleted_ok", $totalOk );
 							
-						// fire the post-event
-						$this->notifyEvent( EVENT_POST_COMMENT_DELETE, Array( "comment" => &$comment ));
+							// fire the post-event
+							$this->notifyEvent( EVENT_POST_COMMENT_DELETE, Array( "comment" => &$comment ));
+						}
 					}
 				}
             }
 
 			// if everything fine, then display the same view again with the feedback
-            $this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $article ));
+			if( $this->_articleId == 0 )
+				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => null ));
+			else
+				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $article ));
+				
 			if( $successMessage != "" ) {
 				$this->_view->setSuccessMessage( $successMessage );
 				// clear the cache

Modified: plog/trunk/class/action/admin/admineditcommentsaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admineditcommentsaction.class.php	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/class/action/admin/admineditcommentsaction.class.php	2005-07-12 21:22:28 UTC (rev 2311)
@@ -23,11 +23,15 @@
         	$this->AdminAction( $actionInfo, $request );
 			
 			// data validation
-			$this->registerFieldValidator( "articleId", new IntegerValidator());
+			$this->registerFieldValidator( "articleId", new IntegerValidator(), true);
 			$this->registerFieldValidator( "showStatus", new IntegerValidator(), true);
 			$view = new AdminPostsListView( $this->_blogInfo );
 			$view->setErrorMessage( $this->_locale->tr("error_fetching_comments"));
 			$this->setValidationErrorView( $view );
+			
+			// we do this so that AdminEditTrackbacksAction can basically extend this class and provide
+			// a different view... it will allow us to save some extra code!
+			$this->_viewClass = "AdminArticleCommentsListView";
         }
 
         /**
@@ -37,21 +41,29 @@
         {
 			// get the validated parameters from the request
         	$articleId = $this->_request->getValue( "articleId" );
+			if( $articleId && $articleId > 0 ) {
+				$articles = new Articles();
+				$article = $articles->getBlogArticle( $articleId, $this->_blogInfo->getId());
+				if( !$article ) {
+					$this->_view = new AdminPostsListView( $this->_blogInfo );
+					$this->_view->setErrorMessage( $this->_locale->tr("error_fetching_post" ));				
+				}			
+				else
+					$this->_view = new $this->_viewClass( $this->_blogInfo, Array( "article" => $article,
+																							  "showStatus" => $showStatus ));			
+			}
+			else {
+				// if there is no article id, then we will show all comments from all posts...
+				$this->_view = new $this->_viewClass( $this->_blogInfo, Array( "article" => null,
+																						  "showStatus" => $showStatus ));							
+			}
+			
 			$showStatus = $this->_request->getValue( "showStatus" );
 			
-			$articles = new Articles();
-			$article = $articles->getBlogArticle( $articleId, $this->_blogInfo->getId());
-			if( !$article ) {
-				$this->_view = new AdminPostsListView( $this->_blogInfo );
-				$this->_view->setErrorMessage( $this->_locale->tr("error_fetching_post" ));				
-			}
-			else
-				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $article,
-																						  "showStatus" => $showStatus ));
             $this->setCommonData();
 
             // better to return true if everything fine
             return true;
         }
     }
-?>
+?>
\ No newline at end of file

Modified: plog/trunk/class/action/admin/adminedittrackbacksaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminedittrackbacksaction.class.php	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/class/action/admin/adminedittrackbacksaction.class.php	2005-07-12 21:22:28 UTC (rev 2311)
@@ -1,6 +1,6 @@
 <?php
 
-	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/action/admin/admineditcommentsaction.class.php" );
     include_once( PLOG_CLASS_PATH."class/view/admin/adminarticletrackbackslistview.class.php" );
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" );
     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
@@ -11,7 +11,7 @@
      *
      * Action that shows a list of all the trackbacks for a given post
      */
-    class AdminEditTrackbacksAction extends AdminAction 
+    class AdminEditTrackbacksAction extends AdminEditCommentsAction 
 	{
 
     	/**
@@ -20,39 +20,9 @@
          */
         function AdminEditTrackbacksAction( $actionInfo, $request )
         {
-        	$this->AdminAction( $actionInfo, $request );
+        	$this->AdminEditCommentsAction( $actionInfo, $request );
 			
-			// data validation
-			$this->registerFieldValidator( "articleId", new IntegerValidator());
-			$view = new AdminPostsListView( $this->_blogInfo );
-			$this->setValidationErrorView( $view );
+			$this->_viewClass = "AdminArticleTrackbacksListView";
         }
-
-        /**
-         * Carries out the specified action
-         */
-        function perform()
-        {
-			// get the validated parameters from the request
-        	$articleId = $this->_request->getValue( "articleId" );
-			$articles = new Articles();
-			$article = $articles->getBlogArticle( $articleId, $this->_blogInfo->getId());
-			
-			$status = $this->_request->getValue( "showStatus" );
-			if( $status == "" ) $status = COMMENT_STATUS_ALL;
-			
-			if( !$article ) {
-				$this->_view = new AdminPostsListView( $this->_blogInfo );
-				$this->_view->setErrorMessage( $this->_locale->tr("error_fetching_post" ));
-			}
-			else 
-				$this->_view = new AdminArticleTrackbacksListView( $this->_blogInfo, Array( "article" => $article,
-				                                                                            "showStatus" => $status ));
-		
-            $this->setCommonData();
-
-            // better to return true if everything fine
-            return true;
-        }
     }
 ?>

Modified: plog/trunk/class/action/admin/adminmarkcommentaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminmarkcommentaction.class.php	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/class/action/admin/adminmarkcommentaction.class.php	2005-07-12 21:22:28 UTC (rev 2311)
@@ -6,11 +6,11 @@
     include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
     include_once( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" );
-	include_once( PLOG_CLASS_PATH."class/view/admin/adminarticlecommentslistview.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminarticlecommentslistview.class.php" );
 	
-    /**
-     * \ingroup Action
-     * @private
+    /**
+     * \ingroup Action
+     * @private
      *     * sets the spam status for a post
      */
     class AdminMarkCommentAction extends AdminAction
@@ -51,14 +51,15 @@
             $articles = new Articles();
 
             // fetch the comment
-            $this->_comment = $articleComments->getPostComment( $articleId, $commentId );
+            $this->_comment = $articleComments->getComment( $commentId );
             if( !$this->_comment )
             	return false;
 
-            // fetch the article
-            $this->_article = $articles->getBlogArticle( $this->_comment->getArticleId(), $blogId );
-            if( !$this->_article )
-            	return false;
+			$this->_article = $this->_comment->getArticle();
+			
+			// check that the comment really belongs to this blog
+			if( $this->_blogInfo->getId() != $this->_article->getBlog())
+				return false;
 
             return true;
         }
@@ -71,7 +72,10 @@
 			// throw the pre-event
 			$this->notifyEvent( EVENT_PRE_MARK_SPAM_COMMENT, Array( "commentId" => $this->_commentId ));
 			
-           	$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $this->_article ));
+			if( $this->_articleId == 0 )
+				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => null ));
+			else
+				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $this->_article ));			
 			
         	$comments = new ArticleComments();
             if( !$comments->updateCommentStatus( $this->_commentId, COMMENT_STATUS_SPAM )) {
@@ -88,7 +92,7 @@
 
                 // before exiting, we should get the comment and train the filter
                 // to recognize this as spam...
-                $comment = $comments->getPostComment( $this->_articleId, $this->_commentId );
+                $comment = $comments->getComment( $this->_commentId );
                 $bayesian = new BayesianFilterCore();
 
                 $bayesian->untrain( $this->_blogInfo->getId(),
@@ -122,7 +126,10 @@
 			// throw the pre-event
 			$this->notifyEvent( EVENT_PRE_MARK_NO_SPAM_COMMENT, Array( "commentId" => $this->_commentId ));
 		
-           	$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $this->_article ));
+			if( $this->_articleId == 0 )
+				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => null ));
+			else
+				$this->_view = new AdminArticleCommentsListView( $this->_blogInfo, Array( "article" => $this->_article ));			
 		
         	$comments = new ArticleComments();
             if( !$comments->updateCommentStatus( $this->_commentId, COMMENT_STATUS_NONSPAM )) {
@@ -139,7 +146,7 @@
 
                 // before exiting, we should get the comment and train the filter
                 // to recognize this as spam...
-                $comment = $comments->getPostComment( $this->_articleId, $this->_commentId );
+                $comment = $comments->getComment( $this->_commentId );
                 $bayesian = new BayesianFilterCore();
                 
                 $bayesian->untrain( $this->_blogInfo->getId(),
@@ -181,7 +188,7 @@
             	// if things don't match... (like trying to set the status of an article
                 // from another blog, then quit...)
             	$this->_view = new AdminPostsListView( $this->_blogInfo );
-                $this->_view->setErrorMessage( $this->_locale->tr("error_incorrect_comment_id"));
+                $this->_view->setErrorMessage( $this->_locale->tr("error_incorrect_comment_id"));
                 $this->setCommonData();
                 return false;
             }
@@ -199,4 +206,4 @@
             return $result;
         }
     }
-?>
+?>
\ No newline at end of file

Modified: plog/trunk/class/dao/article.class.php
===================================================================
--- plog/trunk/class/dao/article.class.php	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/class/dao/article.class.php	2005-07-12 21:22:28 UTC (rev 2311)
@@ -90,7 +90,6 @@
 			$this->_fields = null;
 			$this->_trackbacks = null;
 			$this->_userInfo = null;
-			$this->_comments = Array();
 
             //print_r($this);
 		}
@@ -266,7 +265,7 @@
 		function getComments( $onlyActive = true )
 		{
 			// load the comments if they haven't been loaded yet
-			if( is_null($this->_comments) ) {    
+			if( is_null($this->_comments) ) {
 				include_once( PLOG_CLASS_PATH.'class/dao/articlecomments.class.php' );			
 				$userComments =  new ArticleComments();
 				$blogSettings = $this->_blogInfo->getSettings();
@@ -562,7 +561,7 @@
 		function getTotalComments( $onlyActive = true )
 		{
 			// trigger the loading of the comments
-			$this->getComments( $onlyActive );
+			$this->getComments( $onlyActive );			
 		
 			if( $onlyActive ) {
 				$num = 0;

Modified: plog/trunk/class/dao/articlecomments.class.php
===================================================================
--- plog/trunk/class/dao/articlecomments.class.php	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/class/dao/articlecomments.class.php	2005-07-12 21:22:28 UTC (rev 2311)
@@ -78,78 +78,6 @@
 														 $userUrl, $clientIp, COMMENT_TYPE_COMMENT ));
         }
 
-        /**
-         * code factored out and made to be reused through several functions here...
-         */
-        function _fillCommentInformation( $row )
-        {
-            require_once( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
-            require_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
-        	// ---
-            // this stuff is another disgusting hack to make comments
-            // be aware of time differences that may have been set by
-            // users in their blogs... actually, it will make the whole
-            // thing run a little bit slower because for every article
-            // that we fetch, we need to know the time difference
-            // and that means, additional accesses to the database :(
-            // But hey, users demand these things and we are not in the position
-            // to deny anything, are we? :P
-            // ---
-            // at the same time, we're going to brake some of our "nicely"
-            // implemented bussiness logic with the query below, bypassing all
-            // our objects and directly fetching info from the database, just for
-            // the sake of being able to do things with a single query rather
-            // than needing at least two to do the same. We would have to first
-            // find to which blog the given article belongs and then use another
-            // query to find its settings... If we do it this way, we can still
-            // do it in one query and get a nice BlogSettings object with the
-            // information that we need. Dirty but works :S
-            // ---
-            $prefix = $this->getPrefix();
-            $date = $row["date"];
-            $articleId = $row["article_id"];
-
-            // let's try and keep some kind of cache for this...
-            if( empty($this->_blogSettings[$articlId])) {
-            	$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";
-                $result = $this->Execute( $query );
-				if( !$result ) 
-					return false;
-				
-                $tmpRow = $result->FetchRow();
-                $blogSettings = Blogs::getBlogSettingsFromField( $tmpRow["settings"] );
-                $this->_blogSettings[$articleId] = $blogSettings;
-            }
-            else {
-            	$blogSettings = $this->_blogSettings[$articleId];
-            }
-
-            $timeDiff = $blogSettings->getValue( "time_offset" );
-            // now that we've got the time difference, we can
-            // calculate what would the "real" date...
-            $date = Timestamp::getDateWithOffset( $date, $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"] );
-
-            return $comment;
-        }
-
 		/**
 		 * 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'
@@ -222,9 +150,22 @@
 		 * @param maxItems
 		 * @return An array of ArticleComment objects
 		 */
-		function getBlogComments( $blogId, $maxItems = 0, $articleStatus = POST_STATUS_PUBLISHED )
+		function getBlogComments( $blogId, $order = COMMENT_ORDER_NEWEST_FIRST, $status = COMMENT_STATUS_ALL, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
 		{
-			return( CommentsCommon::getBlogComments( $blogId, $maxItems, $articleStatus, COMMENT_TYPE_COMMENT ));
+			return( CommentsCommon::getBlogComments( $blogId, $order, COMMENT_TYPE_COMMENT, $status, $page, $itemsPerPage ));
 		}
+		
+        /**
+         * Returns the total number of comments for a given blog
+		 *
+		 * @param artId the post id
+		 * @param status
+		 * @return The number of comments
+         */		
+		function getNumBlogComments( $blogId, $status = COMMENT_STATUS_ALL, $type = COMMENT_TYPE_ANY )
+        {
+			return( CommentsCommon::getNumBlogComments( $blogId, $status, $type ));
+		}
+
 	}
 ?>

Modified: plog/trunk/class/dao/commentscommon.class.php
===================================================================
--- plog/trunk/class/dao/commentscommon.class.php	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/class/dao/commentscommon.class.php	2005-07-12 21:22:28 UTC (rev 2311)
@@ -108,7 +108,7 @@
 			else
 				$query .= " ORDER BY date ASC";
 			
-            $result = $this->Execute( $query, $page, $itemsPerPage );
+            $result = $this->Execute( $query, $page, $itemsPerPage );			
 
             if( !$result )
             	return Array();
@@ -148,7 +148,7 @@
 				$comment = $this->_fillCommentInformation( $row );
 				
                 $comments[] = $comment;
-			}
+			}			
 
 			return $comments;
 		}
@@ -237,13 +237,35 @@
 			if( $status != COMMENT_STATUS_ALL )
 				$cond .= " AND status = '".Db::qstr($status)."'";
 			if( $type != COMMENT_TYPE_ANY )
-				$query .= " AND type = '".Db::qstr($type)."'";
-				
+				$query .= " AND type = '".Db::qstr($type)."'";				
 
 			// get the number of items and return it to the caller
 			return( $this->getNumItems( $table, $cond ));		
         }
+		
+        /**
+         * Returns the total number of comments for a given blog
+		 *
+		 * @param artId the post id
+		 * @param status
+		 * @return The number of comments
+         */
+        function getNumBlogComments( $blogId, $status = COMMENT_STATUS_ALL, $type = COMMENT_TYPE_ANY )
+        {
+			// create the table name
+			$prefix = $this->getPrefix();
+			$table = "{$prefix}articles_comments c, {$prefix}articles a";
+			// and the condition if any...
+			$cond = "a.blog_id = '".Db::qstr($blogId)."' AND c.article_id = a.id";
+			if( $status != COMMENT_STATUS_ALL )
+				$cond .= " AND c.status = '".Db::qstr($status)."'";
+			if( $type != COMMENT_TYPE_ANY )
+				$cond .= " AND c.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
          */
@@ -380,9 +402,8 @@
 			          
 
             return $this->Execute( $query );
-        }
+        }		
 		
-		
 		/**
 		 * returns a single comment, identified by its identifier
 		 *
@@ -415,25 +436,25 @@
 		 * @param maxItems
 		 * @return An array of ArticleComment objects
 		 */
-		function getBlogComments( $blogId, $maxItems = 0, $articleStatus = POST_STATUS_PUBLISHED, $type = COMMENT_TYPE_ANY )
+		function getBlogComments( $blogId, $order = COMMENT_ORDER_NEWEST_FIRST, $status = COMMENT_STATUS_ALL, $type = COMMENT_TYPE_ANY, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
 		{
 			$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)."'";
+			$query = "SELECT c.*
+			          FROM {$prefix}articles_comments c, {$prefix}articles a
+			          WHERE a.blog_id = '".Db::qstr($blogId)."' AND a.id = c.article_id";
+            if( $status != COMMENT_STATUS_ALL )
+            	$query .= " AND status = $status";
 			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 );
+				$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 false;
 				
@@ -454,14 +475,78 @@
 			return $comments;
 		}
 		
-		/**
+        /**
+         * code factored out and made to be reused through several functions here...
+		 *
 		 * @private
-		 */
+         */
         function _fillCommentInformation( $row )
         {
-			throw( new Exception( "This method must be implemented by child classes!" ));
-			
-			die();
-		}
+            require_once( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
+            require_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+        	// ---
+            // this stuff is another disgusting hack to make comments
+            // be aware of time differences that may have been set by
+            // users in their blogs... actually, it will make the whole
+            // thing run a little bit slower because for every article
+            // that we fetch, we need to know the time difference
+            // and that means, additional accesses to the database :(
+            // But hey, users demand these things and we are not in the position
+            // to deny anything, are we? :P
+            // ---
+            // at the same time, we're going to brake some of our "nicely"
+            // implemented bussiness logic with the query below, bypassing all
+            // our objects and directly fetching info from the database, just for
+            // the sake of being able to do things with a single query rather
+            // than needing at least two to do the same. We would have to first
+            // find to which blog the given article belongs and then use another
+            // query to find its settings... If we do it this way, we can still
+            // do it in one query and get a nice BlogSettings object with the
+            // information that we need. Dirty but works :S
+            // ---
+            $prefix = $this->getPrefix();
+            $date = $row["date"];
+            $articleId = $row["article_id"];
+
+            // let's try and keep some kind of cache for this...
+            if( empty($this->_blogSettings[$articlId])) {
+            	$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";
+                $result = $this->Execute( $query );
+				if( !$result ) 
+					return false;
+				
+                $tmpRow = $result->FetchRow();
+                $blogSettings = Blogs::getBlogSettingsFromField( $tmpRow["settings"] );
+                $this->_blogSettings[$articleId] = $blogSettings;
+            }
+            else {
+            	$blogSettings = $this->_blogSettings[$articleId];
+            }
+
+            $timeDiff = $blogSettings->getValue( "time_offset" );
+            // now that we've got the time difference, we can
+            // calculate what would the "real" date...
+            $date = Timestamp::getDateWithOffset( $date, $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"] );
+
+            return $comment;
+        }
 	}
-?>
+?>
\ No newline at end of file

Modified: plog/trunk/class/view/admin/adminarticlecommentslistview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminarticlecommentslistview.class.php	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/class/view/admin/adminarticlecommentslistview.class.php	2005-07-12 21:22:28 UTC (rev 2311)
@@ -18,14 +18,19 @@
 		var $_commentStatus;	
 		var $_page;
 	
-		function AdminArticleCommentsListView( $blogInfo, $params = Array())
+		function AdminArticleCommentsListView( $blogInfo, $params = Array(), $type = COMMENT_TYPE_COMMENT )
 		{
-			$this->AdminTemplatedView( $blogInfo, "editcomments" );
+			if( $type == COMMENT_TYPE_COMMENT )
+				$this->AdminTemplatedView( $blogInfo, "editcomments" );
+			else
+				$this->AdminTemplatedView( $blogInfo, "edittrackbacks" );
 			
 			$blogSettings = $blogInfo->getSettings();
-			$this->_locale =& Locales::getLocale( $blogSettings->getValue( "locale" ), "en_UK" );			
+			$this->_locale =& Locales::getLocale( $blogSettings->getValue( "locale" ), "en_UK" );	
 			
 			$this->_setParameters( $params );
+			
+			$this->_type = $type;
 
 			$this->_page = $this->getCurrentPageFromRequest();
 		}
@@ -37,7 +42,7 @@
 		{
 			// fetch the article id
 			$this->_article = $params["article"];
-			
+						
 			// load the status
 			$this->_commentStatus = $params["showStatus"];
 			if( !ArticleCommentStatus::isValidStatus( $this->_commentStatus )) 
@@ -50,26 +55,54 @@
 		function render()
 		{
 			// load the comments and throw the correct event
-			$comments = new ArticleComments();
-			$postComments = $comments->getPostComments( $this->_article->getId(),
-														COMMENT_ORDER_NEWEST_FIRST,
-														$this->_commentStatus, 
-														$this->_page, 
-														DEFAULT_ITEMS_PER_PAGE );
+			$comments = new CommentsCommon();
+			if( $this->_article ) {
+				// load only the comments of the given post
+				$postComments = $comments->getPostComments( $this->_article->getId(),
+															COMMENT_ORDER_NEWEST_FIRST,
+															$this->_commentStatus, 
+															$this->_type,
+															$this->_page, 
+															DEFAULT_ITEMS_PER_PAGE );
+				// number of comments
+				$numPostComments = $comments->getNumPostComments( $this->_article->getId(), 
+				                                                  $this->_commentStatus,
+																  $this->_type );
+				// id of the article, for the pager...
+				$articleId = $this->_article->getId();
+			}
+			else {
+				// load all comments given the current status
+				$postComments = $comments->getBlogComments( $this->_blogInfo->getId(),
+				                                            COMMENT_ORDER_NEWEST_FIRST,
+				                                            $this->_commentStatus,
+															$this->_type,
+														    $this->_page,
+														    DEFAULT_ITEMS_PER_PAGE );
+				// number of comments
+				$numPostComments = $comments->getNumBlogComments( $this->_blogInfo->getId(),
+				                                                  $this->_commentStatus,
+																  $this->_type );
+				// no article id...
+				$articleId = 0;
+			}
 			$this->notifyEvent( EVENT_COMMENTS_LOADED, Array( "comments", &$postComments ));
-			// number of comments
-			$numPostComments = $comments->getNumPostComments( $this->_article->getId(), $this->_commentStatus );
+			
+			if( $this->_type == COMMENT_TYPE_COMMENT )
+				$pagerUrl = "?op=editComments";
+			else
+				$pagerUrl = "?op=editTrackbacks";
 
 			if( $this->_commentStatus > -1 )
-				$pagerUrl = "?op=editComments&amp;articleId=".$this->_article->getId()."&amp;showStatus=".$this->_commentStatus."&amp;page=";
+				$pagerUrl .= "&amp;articleId={$articleId}&amp;showStatus=".$this->_commentStatus."&amp;page=";
 			else
-				$pagerUrl = "?op=editComments&amp;articleId=".$this->_article->getId()."&amp;page=";
+				$pagerUrl .= "&amp;articleId={$articleId}&amp;page=";
 				
 			// calculate the pager url
 			$pager = new Pager( $pagerUrl,
 					    $this->_page,
 					    $numPostComments,
-					    DEFAULT_ITEMS_PER_PAGE );
+					    DEFAULT_ITEMS_PER_PAGE );					
 														
 			// get a list with all the different comment status
 			$statusList = ArticleCommentStatus::getStatusList( true );

Modified: plog/trunk/class/view/admin/adminarticletrackbackslistview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminarticletrackbackslistview.class.php	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/class/view/admin/adminarticletrackbackslistview.class.php	2005-07-12 21:22:28 UTC (rev 2311)
@@ -1,8 +1,6 @@
 <?php
 
-	include_once( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );	
 	include_once( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" );
 	include_once( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
     include_once( PLOG_CLASS_PATH."class/dao/articlecommentstatus.class.php" );		
@@ -13,71 +11,11 @@
      *
 	 * shows a list with all the trackbacks received for a certain article
 	 */
-	class AdminArticleTrackbacksListView extends AdminTemplatedView
+	class AdminArticleTrackbacksListView extends AdminArticleCommentsListView
 	{
-		var $_article;
-		var $_tbStatus;
-	
 		function AdminArticleTrackbacksListView( $blogInfo, $params = Array())
 		{
-			$this->AdminTemplatedView( $blogInfo, "edittrackbacks" );
-			
-			$this->_setParameters( $params );
-						
-			// page
-			$this->_page = $this->getCurrentPageFromRequest();
+			$this->AdminArticleCommentsListView( $blogInfo, $params, COMMENT_TYPE_TRACKBACK );
 		}
-		
-		/**
-		 * @private
-		 */
-		function _setParameters( $params )
-		{
-			// fetch the article id
-			$this->_article = $params["article"];
-			
-			// load the status
-			$this->_tbStatus = $params["showStatus"];
-			if( !ArticleCommentStatus::isValidStatus( $this->_tbStatus )) 
-				$this->_tbStatus = COMMENT_STATUS_ALL;			
-		}		
-		
-		/**
-		 * show the contents of the view
-		 */
-		function render()
-		{
-			$trackbacks = new Trackbacks();
-			// get the trackbacks
-
-			$postTrackbacks = $trackbacks->getArticleTrackbacks( $this->_article->getId(), 
-			                                                     $this->_tbStatus, 
-																 $this->_page, 
-																 DEFAULT_ITEMS_PER_PAGE );
-			$this->notifyEvent( EVENT_TRACKBACKS_LOADED, Array( "trackbacks" => &$postTrackbacks ));
-			$this->setValue( "trackbacks", $postTrackbacks);
-			// and the total number of trackbacks
-			$numTrackbacks = count( $postTrackbacks );
-			
-			// create and export the pager to the view
-			if( $this->_tbStatus == COMMENT_STATUS_ALL )
-				$url = "?op=editTrackbacks&amp;articleId=".$this->_article->getId()."&amp;page=";
-			else
-				$url = "?op=editTrackbacks&amp;articleId=".$this->_article->getId()."&amp;showStatus=".$this->_tbStatus."&amp;page=";
-				
-			$pager = new Pager( $url,
-			                    $this->_page,
-								$numTrackbacks,
-								DEFAULT_ITEMS_PER_PAGE );
-			$this->setValue( "pager", $pager );
-			// get a list with all the different comment status
-			$statusList = ArticleCommentStatus::getStatusList( true );			
-			$this->setValue( "commentstatus", $statusList );
-			$this->setValue( "currentstatus", $this->_tbStatus );			
-				
-			// pass the common data to the templates
-			$this->setValue( "post", $this->_article );
-			parent::render();
-		}
 	}
-?>
+?>
\ No newline at end of file

Modified: plog/trunk/templates/admin/editcomments.template
===================================================================
--- plog/trunk/templates/admin/editcomments.template	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/templates/admin/editcomments.template	2005-07-12 21:22:28 UTC (rev 2311)
@@ -1,11 +1,11 @@
 {include file="$admintemplatepath/header.template"}
-{include file="$admintemplatepath/navigation.template" showOpt=editPosts title=$locale->tr("editComments")}
+{include file="$admintemplatepath/navigation.template" showOpt=editComments title=$locale->tr("editComments")}
         <div id="list_nav_bar">
             <div id="list_nav_select">		
 
                 <form id="showBy" action="admin.php" method="post">
                 <fieldset>
-                <legend>{$locale->tr("show_by")}</legend>
+                <legend>{$locale->tr("show_by")} ({if $post}{$post->getTopic()}{/if})</legend>
 
                     <div class="list_nav_option">
                     <label for="showStatus">{$locale->tr("status")}</label>
@@ -15,15 +15,14 @@
                      <option value="{$status}" {if $currentstatus == $status} selected="selected"{/if}>{$locale->tr($name)}</option>
                      {/foreach}
                     </select>
-                    </div>
+                    </div>                    
 					
                     <div class="list_nav_option">
                     <br />
                     <input type="hidden" name="op" value="editComments" />
-					<input type="hidden" name="articleId" value="{$post->getId()}" />
+					<input type="hidden" name="articleId" value="{if $post}{$post->getId()}{else}0{/if}" />
                     <input type="submit" name="show" value="{$locale->tr("show")}" class="submit" />
                     </div>
-
                 </fieldset>
                 </form>
             </div>
@@ -78,13 +77,13 @@
                         </td>						
                         <td>
                             <div class="list_action_button">
-                            <a href="?op=deleteComment&amp;commentId={$comment->getId()}&amp;articleId={$post->getId()}"><img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete")}" /></a>
+                            <a href="?op=deleteComment&amp;commentId={$comment->getId()}&amp;articleId={if $post}{$post->getId()}{else}0{/if}"><img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete")}" /></a>
 							{if $comment->getStatus() == 0}
-							    <a href="?op=markComment&amp;mode=1&amp;articleId={$comment->getArticleId()}&amp;commentId={$comment->getId()}">
+							    <a href="?op=markComment&amp;mode=1&amp;articleId={if $post}{$comment->getArticleId()}{else}0{/if}&amp;commentId={$comment->getId()}">
 								 <img src="imgs/admin/icon_spam-16.png" alt="{$locale->tr("mark_as_spam")}" />
 								</a>
 							{elseif $comment->getStatus() == 1}
-								<a href="?op=markComment&amp;mode=0&amp;articleId={$comment->getArticleId()}&amp;commentId={$comment->getId()}">
+								<a href="?op=markComment&amp;mode=0&amp;articleId={if $post}{$comment->getArticleId()}{else}0{/if}&amp;commentId={$comment->getId()}">
 								 <img src="imgs/admin/icon_nospam-16.png" alt="{$locale->tr("mark_as_no_spam")}" />
 								</a>
 							{/if}
@@ -103,8 +102,8 @@
         <div id="list_action_bar">
 	    {include file="$admintemplatepath/adminpager.template" style=list}
             <input type="submit" name="delete" value="{$locale->tr("delete")}" class="submit" />
-			<input type="hidden" name="articleId" value="{$post->getId()}" />
+			<input type="hidden" name="articleId" value="{if $post}{$post->getId()}{else}0{/if}" />
             <input type="hidden" name="op" value="deleteComments" />
         </div>
         </form>
-{include file="$admintemplatepath/footer.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file

Modified: plog/trunk/templates/admin/edittrackbacks.template
===================================================================
--- plog/trunk/templates/admin/edittrackbacks.template	2005-07-12 21:21:18 UTC (rev 2310)
+++ plog/trunk/templates/admin/edittrackbacks.template	2005-07-12 21:22:28 UTC (rev 2311)
@@ -1,6 +1,5 @@
 {include file="$admintemplatepath/header.template"}
-{assign var=postTitle value=$post->getTopic()}
-{include file="$admintemplatepath/navigation.template" showOpt=editPosts title=$locale->tr("editTrackbacks")}
+{include file="$admintemplatepath/navigation.template" showOpt=editTrackbacks title=$locale->tr("editTrackbacks")}
         <div id="list_nav_bar">
             <div id="list_nav_select">		
 
@@ -21,7 +20,7 @@
                     <div class="list_nav_option">
                     <br />
                     <input type="hidden" name="op" value="editTrackbacks" />
-					<input type="hidden" name="articleId" value="{$post->getId()}" />
+					{if $post}<input type="hidden" name="articleId" value="{$post->getId()}" />{/if}
                     <input type="submit" name="show" value="{$locale->tr("show")}" class="submit" />
                     </div>
 
@@ -49,7 +48,7 @@
                     </tr>
                 </thead>
                 <tbody>
-                   {foreach from=$trackbacks item=trackback}
+                   {foreach from=$comments item=trackback}
                     <tr class="{cycle values="odd,even"}">
                         <td>
                             <input class="checkbox" type="checkbox" name="trackbackIds[{$trackback->getId()}]" id="checks_1" value="{$trackback->getId()}" />
@@ -58,10 +57,10 @@
                             {$trackback->getTopic()}
                         </td>
                         <td>
-                            {$trackback->getExcerpt()|escape:html}
+                            {$trackback->getText()|escape:html}
                         </td>
                         <td>
-                            <a href="{$trackback->getUrl()}">{$trackback->getBlogName()}</a>
+                            <a href="{$trackback->getUserUrl()}">{$trackback->getUserName()}</a>
                         </td>
                         <td>
                             {assign var=date value=$trackback->getDateObject()}
@@ -77,13 +76,13 @@
                         </td>														                
                         <td>
                             <div class="list_action_button">
-                             <a href="?op=deleteTrackback&amp;articleId={$post->getId()}&amp;trackbackId={$trackback->getId()}"><img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete_trackback")}" /></a>
+                             <a href="?op=deleteTrackback&amp;articleId={if $post}{$post->getId()}{else}0{/if}&amp;trackbackId={$trackback->getId()}"><img src="imgs/admin/icon_delete-16.png" alt="{$locale->tr("delete_trackback")}" /></a>
 							{if $trackback->getStatus() == 0}
-							    <a href="?op=markTrackback&amp;mode=1&amp;articleId={$trackback->getArticleId()}&amp;trackbackId={$trackback->getId()}">
+							    <a href="?op=markTrackback&amp;mode=1&amp;articleId={if $post}{$post->getId()}{else}0{/if}&amp;trackbackId={$trackback->getId()}">
 								 <img src="imgs/admin/icon_spam-16.png" alt="{$locale->tr("mark_as_spam")}" />
 								</a>
 							{elseif $trackback->getStatus() == 1}
-								<a href="?op=markTrackback&amp;mode=0&amp;articleId={$trackback->getArticleId()}&amp;trackbackId={$trackback->getId()}">
+								<a href="?op=markTrackback&amp;mode=0&amp;articleId={if $post}{$post->getId()}{else}0{/if}&amp;trackbackId={$trackback->getId()}">
 								 <img src="imgs/admin/icon_nospam-16.png" alt="{$locale->tr("mark_as_no_spam")}" />
 								</a>
 							{/if}							 
@@ -97,7 +96,7 @@
         <div id="list_action_bar">
             {include file="$admintemplatepath/adminpager.template" style=list}
             <input type="submit" name="delete" value="{$locale->tr("delete")}" class="submit" />
-			<input type="hidden" name="articleId" value="{$post->getId()}" />
+			<input type="hidden" name="articleId" value="{if $post}{$post->getId()}{else}0{/if}" />
             <input type="hidden" name="op" value="deleteTrackbacks" />
         </div>
 	</form>




More information about the pLog-svn mailing list