[pLog-svn] r4306 - plugins/branches/lifetype-1.1/editcomments/class/action

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Thu Nov 16 04:29:23 GMT 2006


Author: jondaley
Date: 2006-11-16 04:29:21 +0000 (Thu, 16 Nov 2006)
New Revision: 4306

Modified:
   plugins/branches/lifetype-1.1/editcomments/class/action/adminupdatecommentaction.class.php
Log:
now works with new caching stuff

Modified: plugins/branches/lifetype-1.1/editcomments/class/action/adminupdatecommentaction.class.php
===================================================================
--- plugins/branches/lifetype-1.1/editcomments/class/action/adminupdatecommentaction.class.php	2006-11-16 04:12:54 UTC (rev 4305)
+++ plugins/branches/lifetype-1.1/editcomments/class/action/adminupdatecommentaction.class.php	2006-11-16 04:29:21 UTC (rev 4306)
@@ -14,17 +14,29 @@
     var $_commentId;
     var $_articleId;
 	var $_op;
+    var $_authorEmail;
+    var $_authorUrl;
+    var $_authorName;
+    var $_commentText;
+    var $_commentTopic;
+    var $_commentNormalizedText;
+    var $_commentNormalizedTopic;
+    var $_commentStatus;
+    var $_commentDateTime;
+    var $_commentIp;
     
     function AdminUpdateCommentAction($actionInfo, $request){
         $this->AdminAction($actionInfo, $request);
 
-        $this->_commentId = $this->_request->getValue("commentId");
-        $this->_articleId = $this->_request->getValue("articleId");
         $this->_op = $actionInfo->getActionParamValue();
         if($this->_request->getValue("cancel")){
             $this->_op = "cancel";
         }
-        
+
+            // articleId is needed, even on a cancel operation
+        $this->registerFieldValidator("articleId", new IntegerValidator());
+        $this->_articleId = $this->_request->getValue( "articleId" );
+
         if($this->_op == "updateComment"){
             $view = new AdminEditCommentView($this->_blogInfo, $commentId);
 
@@ -32,43 +44,43 @@
             $this->registerFieldValidator("commentText", new StringValidator());
             $this->registerFieldValidator("authorName", new StringValidator());
             $this->registerFieldValidator("commentStatus", new IntegerValidator());
-                // no validation??  
-            $this->registerField("commentTopic");
-            $this->registerField("authorEmail");
-            $this->registerField("authorUrl");
+            $this->registerFieldValidator("commentTopic", new StringValidator(), true);
+            $this->registerFieldValidator("authorEmail", new EmailValidator(), true);
+            $this->registerFieldValidator("authorUrl", new HttpUrlValidator(), true);
+                // no validation...
             $this->registerField("commentDateTime");
             $this->registerField("commentIp");
             
             $view->setErrorMessage( $this->_locale->tr("invalid_data"));
             $this->setValidationErrorView( $view );
+            $this->_fetchFields();
         }
     }
+    
 
-    function _updateComment($id, $topic, $text, $user_name, $user_email,
-                            $user_url, $client_ip, $status, $date){
-        if(!ArticleCommentStatus::isValidStatus($status))
-            return false;
-
-        $prefix = Db::getPrefix();
-        $filter = new TextFilter();
-        $db =& Db::getDb();
+    function _fetchFields(){
+        include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+        $this->_commentId = $this->_request->getValue("commentId");
+            // TODO, be able to change parent?  drop down list?
+            //$this->_parentId  = $this->_request->getValue( "parentId" );
+            //if( $this->_parentId == null || $this->_parentId == "" )
+            //$this->_parentId = 0;
+        $this->_authorEmail = Textfilter::filterAllHTML($this->_request->getValue( "authorEmail" ));
+        $this->_authorUrl   = Textfilter::filterAllHTML($this->_request->getValue( "authorUrl" ));
+        if( (strlen($this->_authorUrl) != 0) &&
+            ereg('^https?://',$this->_authorUrl) == false)
+        {
+            $this->_authorUrl = "http://".$this->_authorUrl;
+        }
+        $this->_authorName  = Textfilter::filterAllHTML($this->_request->getValue( "authorName" ));
+        $this->_commentText = trim($this->_request->getValue( "commentText" ));
+        $this->_commentTopic = Textfilter::filterAllHTML($this->_request->getValue( "commentTopic" ));
+        $this->_commentStatus = $this->_request->getValue("commentStatus");
+        $this->_commentIp = $this->_request->getValue("commentIp");
+        $this->_commentNormalizedTopic = Textfilter::normalizeText($this->_commentTopic);
+        $this->_commentNormalizedText = Textfilter::normalizeText($this->_commentText);
         
-        $query = "UPDATE ".$prefix."articles_comments ";
-        $query .= "set topic='".Db::qstr($topic)."', ";
-        $query .= "text='".Db::qstr($text)."', ";
-        $query .= "user_name='".Db::qstr($user_name)."', ";
-        $query .= "user_email='".Db::qstr($user_email)."', ";
-        $query .= "user_url='".Db::qstr($user_url)."', ";
-        $query .= "client_ip='".$client_ip."', ";
-        $query .= "status=".$status.", ";
-        $query .= "date='".$date->getTimestamp()."', ";
-        $query .= "normalized_text='".Db::qstr($filter->normalizeText($text))."', ";
-        $query .= "normalized_topic='".Db::qstr($filter->normalizeText($topic))."' ";
-        $query .= "WHERE id=".$id;
-//        print $query;
-        return($db->Execute( $query ));
-
-        return false;
+        $this->_commentDateTime = $this->_fetchCommentDateInformation();
     }
 
         // copied from AdminPostManagementCommon class
@@ -85,53 +97,65 @@
         $postTimestamp->setMonth($dateParts[1]);
         $postTimestamp->setYear($dateParts[2]);
 
-        return $postTimestamp;
+        return $postTimestamp->getTimestamp();
     }
 
     
     function perform(){
         if($this->_op == "updateComment"){
-            $topic = $this->_request->getValue("commentTopic");
-            $text = $this->_request->getValue("commentText");
-            $name = $this->_request->getValue("authorName");
-            $email = $this->_request->getValue("authorEmail");
-            $url = $this->_request->getValue("authorUrl");
-            $dateTime = $this->_fetchCommentDateInformation();
-            $status = $this->_request->getValue("commentStatus");
-            $ip = $this->_request->getValue("commentIp");
-            
-            if($this->_updateComment($this->_commentId, $topic, $text, $name, $email,
-                                     $url, $ip, $status, $dateTime)){
-                if($this->_articleId){
-                    $articles = new Articles();
-                    $article = $articles->getBlogArticle($this->_articleId,
-                                                         $this->_blogInfo->getId());
-                    $this->_view = new AdminEditCommentsView($this->_blogInfo,
-                                                             array("article" => $article));
+            $comments = new ArticleComments();
+            $comment = $comments->getComment($this->_commentId);
+            if(!$comment){
+                $this->_view = new AdminEditCommentView($this->_blogInfo, $id);
+                $this->_view->setErrorMessage( $this->_locale->tr("pluginEditCommentsFailed") );
+            }
+            else if(!ArticleCommentStatus::isValidStatus($this->_commentStatus)){
+                $this->_view = new AdminEditCommentView($this->_blogInfo, $id);
+                $this->_view->setErrorMessage( $this->_locale->tr("pluginEditCommentsFailed") );
+            }
+            else{
+                $comment->setTopic($this->_commentTopic);
+                $comment->setText($this->_commentText);
+                $comment->setUserName($this->_authorName);
+                $comment->setUserEmail($this->_authorEmail);
+                $comment->setUserUrl($this->_authorUrl);
+                $comment->setDate($this->_commentDateTime);
+                $comment->setStatus($this->_commentStatus);
+                $comment->setClientIp($this->_commentIp);
+                $comment->setNormalizedTopic($this->_commentNormalizedTopic);
+                $comment->setNormalizedText($this->_commentNormalizedText);
+                
+                if($comments->updateComment($comment)){
+                    if($this->_articleId){
+                        $articles = new Articles();
+                        $article = $articles->getBlogArticle($this->_articleId,
+                                                             $this->_blogInfo->getId());
+                        $this->_view = new AdminEditCommentsView($this->_blogInfo,
+                                                                 array("article" => $article));
+                    }
+                    else{
+                        $this->_view = new AdminPostsListView( $this->_blogInfo );
+                    }
+                    $this->_view->setSuccessMessage( $this->_locale->tr("pluginEditCommentsOk") );
+                    CacheControl::resetBlogCache( $this->_blogInfo->getId());
                 }
                 else{
-                    $this->_view = new AdminPostsListView( $this->_blogInfo );
+                    $this->_view = new AdminEditCommentView($this->_blogInfo, $id);
+                    $this->_view->setErrorMessage( $this->_locale->tr("pluginEditCommentsFailed") );
                 }
-                $this->_view->setSuccessMessage( $this->_locale->tr("pluginEditCommentsOk") );
-                CacheControl::resetBlogCache( $this->_blogInfo->getId());
             }
-            else{
-                $this->_view = new AdminEditCommentView($this->_blogInfo, $id);
-                $this->_view->setErrorMessage( $this->_locale->tr("pluginEditCommentsFailed") );
-            }
         }
         else if($this->_articleId){
-			$articles = new Articles();
-			$article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
-
+            $articles = new Articles();
+            $article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
+            
             $this->_view = new AdminEditCommentsView($this->_blogInfo, array("article" => $article));
             $this->_view->setSuccessMessage( $this->_locale->tr("pluginEditCommentsCancelled") );
         }
         else{
             $this->_view = new AdminPostsListView($this->_blogInfo);
         }
-        
-        
+
         $this->setCommonData();
     }
 }



More information about the pLog-svn mailing list