[pLog-svn] r2291 - plog/branches/plog-1.0.2/class/action/admin

mark at devel.plogworld.net mark at devel.plogworld.net
Fri Jul 8 09:14:41 GMT 2005


Author: mark
Date: 2005-07-08 09:14:39 +0000 (Fri, 08 Jul 2005)
New Revision: 2291

Modified:
   plog/branches/plog-1.0.2/class/action/admin/adminaddpostaction.class.php
   plog/branches/plog-1.0.2/class/action/admin/adminpostmanagementcommonaction.class.php
   plog/branches/plog-1.0.2/class/action/admin/adminsendtrackbacksaction.class.php
   plog/branches/plog-1.0.2/class/action/admin/adminupdatepostaction.class.php
Log:
Implement send trackback directly (without auto-discovery), this feature can help pLog to send trackback to MSNSpace or Others. http://bugs.plogworld.net/view.php?id=621

Modified: plog/branches/plog-1.0.2/class/action/admin/adminaddpostaction.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/action/admin/adminaddpostaction.class.php	2005-07-06 10:30:01 UTC (rev 2290)
+++ plog/branches/plog-1.0.2/class/action/admin/adminaddpostaction.class.php	2005-07-08 09:14:39 UTC (rev 2291)
@@ -49,6 +49,7 @@
         	$this->registerField( "commentsEnabled" );
         	$this->registerField( "customField" );
         	$this->registerField( "postDateTime" );
+        	$this->registerField( "trackbackUrls" );        	
         }
 
 		/**
@@ -140,16 +141,26 @@
                     // and now check what to do with the trackbacks
                     if( $this->_sendTrackbacks ) {
                     	// get the links from the text of the post
-        				$links = StringUtils::getLinks( stripslashes($article->getText()));
+        				$postLinks = StringUtils::getLinks( stripslashes($article->getText()));
 
+		                // get the real trackback links from trackbackUrls
+		                $trackbackLinks = Array();
+		                foreach(explode( "\r\n", $this->_trackbackUrls ) as $host ) {
+		                	trim($host);
+		                	if( $host != "" && $host != "\r\n" && $host != "\r" && $host != "\n" )
+		                    	array_push( $trackbackLinks, $host );
+		                }
+
         				// if no links, there is nothing to do
-        				if( count($links) == 0 ) {
+        				if( count($postLinks) == 0 && count($trackbackLinks) == 0 ) {
         					$this->_view = new AdminPostsListView( $this->_blogInfo );
+			                $this->_view->setErrorMessage( $this->_locale->tr("error_no_trackback_links_sent"));
         				}
         				else {
             				$this->_view = new AdminTemplatedView( $this->_blogInfo, "sendtrackbacks" );
             				$this->_view->setValue( "post", $article );
-            				$this->_view->setValue( "postlinks", $links );
+            				$this->_view->setValue( "postLinks", $postLinks );
+							$this->_view->setValue( "trackbackLinks", $trackbackLinks );            				
          				}
                     }
                     $this->_view->setSuccessMessage( $message );

Modified: plog/branches/plog-1.0.2/class/action/admin/adminpostmanagementcommonaction.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/action/admin/adminpostmanagementcommonaction.class.php	2005-07-06 10:30:01 UTC (rev 2290)
+++ plog/branches/plog-1.0.2/class/action/admin/adminpostmanagementcommonaction.class.php	2005-07-08 09:14:39 UTC (rev 2291)
@@ -26,6 +26,7 @@
         var $_previewPost;
         var $_addPost;
         var $_commentsEnabled;
+        var $_trackbackUrls;
         // stuff about the date
         var $_postYear;
         var $_postMonth;
@@ -127,6 +128,7 @@
 			$this->_sendPings = $this->_request->getValue( "sendPings" );			
             $this->_postId       = $this->_request->getValue( "postId" );
             $this->_commentsEnabled = $this->_request->getValue( "commentsEnabled" );
+            $this->_trackbackUrls = $this->_request->getValue( "trackbackUrls" );
 				
 			// fetch the custom fields
 			$this->_customFields = $this->_request->getValue( "customField" );	

Modified: plog/branches/plog-1.0.2/class/action/admin/adminsendtrackbacksaction.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/action/admin/adminsendtrackbacksaction.class.php	2005-07-06 10:30:01 UTC (rev 2290)
+++ plog/branches/plog-1.0.2/class/action/admin/adminsendtrackbacksaction.class.php	2005-07-08 09:14:39 UTC (rev 2291)
@@ -16,7 +16,8 @@
     class AdminSendTrackbacksAction extends AdminAction 
 	{
 
-    	var $_postLink;
+    	var $_postLinks;
+    	var $_trackbackLinks;
         var $_postId;
         var $_locale;
 
@@ -27,58 +28,99 @@
         function AdminSendTrackbacksAction( $actionInfo, $request )
         {
         	$this->AdminAction( $actionInfo, $request );
-
-		$this->registerFieldValidator( "postId", new IntegerValidator());
-		$this->registerFieldValidator( "postLink", new ArrayValidator());
-		$view = new AdminPostsListView( $this->_blogInfo );
-		$view->setErrorMessage( $this->_locale->tr("error_no_trackback_links_sent"));
-		$this->setValidationErrorView( $view );
         }
 
-	/*
+		function validate()
+		{
+			// fetch the validated data
+			$this->_postLinks = $this->_request->getValue( "postLink" );
+			$this->_trackbackLinks = $this->_request->getValue( "trackbackLink" );
+			$this->_postId = $this->_request->getValue( "postId" );
+			
+			$intval = new IntegerValidator();
+			if( !$intval->validate( $this->_postId ) ) {
+                $this->_view = new AdminPostsListView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_incorrect_article_id"));
+                $this->setCommonData();
+
+                return false;				
+			}
+			
+			$arrryval = new ArrayValidator();
+			if( !$arrryval->validate( $this->_postLinks ) && !$arrryval->validate( $this->_trackbackLinks ) ) {
+                $this->_view = new AdminPostsListView( $this->_blogInfo );
+                $this->_view->setErrorMessage( $this->_locale->tr("error_no_trackback_links_sent"));
+                $this->setCommonData();
+
+                return false;
+            }   
+			
+			return true;
+		}        
+
+		/*
          * Carries out the specified action
          */
         function perform()
         {
-		// fetch the validated data
-		$this->_trackbacks = $this->_request->getValue( "postLink" );
-		$this->_postId = $this->_request->getValue( "postId" );
-
             // we need to have the post
             $articles = new Articles();
             $post     = $articles->getBlogArticle( $this->_postId, $this->_blogInfo->getId());
-            // and now start sending the trackback pings
-            $tbClient = new TrackbackClient();
-            $results = $tbClient->sendTrackbacks( $this->_trackbacks, $post, $this->_blogInfo);
+            
             // now check the results and give the user the possiblity to retry again with the
             // ones that had some problem.
             $errors = false;
 
-            $trackbackLinks = Array();
-            foreach( $results as $result ) {
-            	if( $result["status"] == TRACKBACK_FAILED) {
-                	// add them again to the list of hosts
-                    $errors = true;
-                    array_push( $trackbackLinks, $result["url"] );
-                }
-                else if( $result["status"] == TRACKBACK_SUCCESS ) {
-                	if( $message == "" ) $message = $this->_locale->tr("trackbacks_sent_ok")."<br/><br/>";
-                    $message .= "<a href=\"".$result["url"]."\">".$result["url"]."</a><br/>";
-                }
-                else if( $result["status"] == TRACKBACK_UNAVAILABLE ) {
-                    $message .= $this->_locale->tr("trackbacks_no_trackback")."<a href=\"".$result["url"]."\">".$result["url"]."</a><br/>";
-                }
-            }
+            // and now start sending the trackback pings
+            $tbClient = new TrackbackClient();
+            $postLinks = Array();
+            $trackbackLinks = Array();            
+			
+			if ( count($this->_postLinks) != 0 ) {
+	            $autoDiscoverResults = $tbClient->sendTrackbacks( $this->_postLinks, $post, $this->_blogInfo);
 
+	            foreach( $autoDiscoverResults as $result ) {
+	            	if( $autoDiscoverResults["status"] == TRACKBACK_FAILED) {
+	                	// add them again to the list of hosts
+	                    $errors = true;
+	                    array_push( $postLinks, $result["url"] );
+	                }
+	                else if( $result["status"] == TRACKBACK_SUCCESS ) {
+	                	if( $message == "" ) $message = $this->_locale->tr("trackbacks_sent_ok")."<br/><br/>";
+	                    $message .= "<a href=\"".$result["url"]."\">".$result["url"]."</a><br/>";
+	                }
+	                else if( $result["status"] == TRACKBACK_UNAVAILABLE ) {
+	                    $message .= $this->_locale->tr("trackbacks_no_trackback")."<a href=\"".$result["url"]."\">".$result["url"]."</a><br/>";
+	                }
+	            }
+	        }
+
+			if ( count($this->_trackbackLinks) != 0 ) {
+	            $directPingResults = $tbClient->sendDirectTrackbacks( $this->_trackbackLinks, $post, $this->_blogInfo);
+	
+	            foreach( $directPingResults as $result ) {
+	            	if( $result["status"] == TRACKBACK_FAILED) {
+	                	// add them again to the list of hosts
+	                    $errors = true;
+	                    array_push( $trackbackLinks, $result["url"] );
+	                }
+	                else if( $result["status"] == TRACKBACK_SUCCESS ) {
+	                	if( $message == "" ) $message = $this->_locale->tr("trackbacks_sent_ok")."<br/><br/>";
+	                    $message .= "<a href=\"".$result["url"]."\">".$result["url"]."</a><br/>";
+	                }
+	            }
+			}
+			
             // if there were errors, we let the user try again
             if( $errors ) {
             	if( $message != "" )
                 	$message .= "<br/>";
             	$message .= $this->_locale->tr("error_sending_trackbacks");
-         	$this->_view = new AdminTemplatedView( $this->_blogInfo, "sendtrackbacks" );
+         		$this->_view = new AdminTemplatedView( $this->_blogInfo, "sendtrackbacks" );
                 $this->_view->setErrorMessage( $message );
                 $this->_view->setValue( "post", $post);
-                $this->_view->setValue( "postlinks", $trackbackLinks );
+                $this->_view->setValue( "postLinks", $postLinks );
+                $this->_view->setValue( "trackbackLinks", $trackbackLinks );
                 $this->setCommonData();
             }
             else {

Modified: plog/branches/plog-1.0.2/class/action/admin/adminupdatepostaction.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/action/admin/adminupdatepostaction.class.php	2005-07-06 10:30:01 UTC (rev 2290)
+++ plog/branches/plog-1.0.2/class/action/admin/adminupdatepostaction.class.php	2005-07-08 09:14:39 UTC (rev 2291)
@@ -52,7 +52,8 @@
         	$this->registerField( "postId" );
         	$this->registerField( "commentsEnabled" );
         	$this->registerField( "customField" );
-        	$this->registerField( "postDateTime" );        	
+        	$this->registerField( "postDateTime" );   
+        	$this->registerField( "trackbackUrls" );     	
         }
 
         /**
@@ -141,7 +142,16 @@
 			
 			// if the "send xmlrpc pings" checkbox was enabled, do something about it...
 			if( $post->getStatus() == POST_STATUS_PUBLISHED ) {
-				$links = StringUtils::getLinks( stripslashes($post->getText()));				
+				// get the links from the text of the post
+				$postLinks = StringUtils::getLinks( stripslashes($post->getText()));
+
+                // get the real trackback links from trackbackUrls
+                $trackbackLinks = Array();
+                foreach(explode( "\r\n", $this->_trackbackUrls ) as $host ) {
+                	trim($host);
+                	if( $host != "" && $host != "\r\n" && $host != "\r" && $host != "\n" )
+                    	array_push( $trackbackLinks, $host );
+                }
 				
 				if( $this->_sendPings ) {
 					$message .= "<br/><br/>".$this->sendXmlRpcPings();
@@ -149,14 +159,16 @@
 				// and now check what to do with the trackbacks
 				if( $this->_sendTrackbacks ) {					
 					// if no links, there is nothing to do
-					if( count($links) == 0 ) {
+					if( count($postLinks) == 0 && count($trackbackLinks) == 0 ) {
 						$this->_view = new AdminPostsListView( $this->_blogInfo );
+		                $this->_view->setErrorMessage( $this->_locale->tr("error_no_trackback_links_sent"));
 					}
 					else {
 						$this->_view = new AdminTemplatedView( $this->_blogInfo, "sendtrackbacks" );
 						// get the links from the text of the post
 						$this->_view->setValue( "post", $post );
-						$this->_view->setValue( "postlinks", $links );
+						$this->_view->setValue( "postLinks", $postLinks );
+						$this->_view->setValue( "trackbackLinks", $trackbackLinks );
 					}
 				}
 			}




More information about the pLog-svn mailing list