[pLog-svn] r3995 - plog/branches/lifetype-1.1.1/class/net/xmlrpc

pwestbro at devel.lifetype.net pwestbro at devel.lifetype.net
Tue Sep 19 16:18:37 GMT 2006


Author: pwestbro
Date: 2006-09-19 16:18:36 +0000 (Tue, 19 Sep 2006)
New Revision: 3995

Modified:
   plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php
Log:
Added missing metaWeblogNewPost


Modified: plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php	2006-09-19 12:07:54 UTC (rev 3994)
+++ plog/branches/lifetype-1.1.1/class/net/xmlrpc/xmlrpcserver.class.php	2006-09-19 16:18:36 UTC (rev 3995)
@@ -165,6 +165,157 @@
 	            return new IXR_Error(-1, 'You did not provide the correct password');
 	        }
 		}
+		
+        function metaWeblogNewPost($args)
+        {
+			$users = new Users();
+			$articles = new Articles();
+			$category = new ArticleCategories();
+			$blogsG = new Blogs();
+
+            $blogid     = $args[0];
+            $username   = $args[1];
+            $password   = $args[2];
+            $content    = $args[3];
+            $publish    = $args[4]; // true post&publish | false post only
+            /*
+             int postid
+            */
+    
+            // -mhe todo security
+    
+            $auth = $users->authenticateUser( $username, $password);
+    
+            if ($auth)
+            {
+                if ($publish)
+                {
+                    $status = POST_STATUS_PUBLISHED;
+                } else
+                {
+                    $status = POST_STATUS_DRAFT;
+                }
+                
+                // Get the default category
+                //$cats = $category->getBlogCategories($blogid);
+                //foreach($cats as $cat)
+                //{
+                //    $idCategory = $cat->_id;
+                //    // Stop here, we have a category
+                //    break;
+                //}
+                
+                $title = $content["title"];
+                $body = $content["description"];
+                $catList = $content["categories"];
+                $categoryName = NULL;
+    
+                //
+                // :KLUDGE:
+                // not exactly the smartest and fastest bit of code ever but it seems to work :-)
+                //
+                $categories = Array();
+                $cats = $category->getBlogCategories($blogid);            
+    
+                // some protection again blogs without categories
+                if( !$cats ) {
+                    return new IXR_Error(-1, 'This blog does not have categories!');				
+                }
+    
+                if ( $catList != NULL )
+                {
+                    foreach( $catList as $categoryName ) {
+                        foreach( $cats as $blogCategory ) {
+                            $categoryName = trim($categoryName);
+                            if ( strcmp( $categoryName, $blogCategory->getName()) == 0 )
+                            {
+                                $categories[] = $blogCategory->getId();
+                            }
+                        }
+                    }
+                }
+                else {
+                    // if no category, let's pick a random one
+                    $blogCategory = array_pop( $cats );
+                    $categories[] = $blogCategory->getId();
+                }
+    
+                $userInfo = $users->getUserInfoFromUsername( $username );
+                
+                $article = new Article(
+                    $title,
+                    $body, // text
+                    $categories, // catid
+                    $userInfo->getId(), // userid
+                    $blogid, // blogid
+                    $status,
+                    0, // numread
+                    Array( "comments_enabled" => true ) // enable comments
+                );
+    
+               $dateCreated = $content['dateCreated'];
+               
+               // there must be a bug in the xmlrpc library, we're getting an object in $dateCreated
+               // that does not have a type or anyhting, but it still is an object... kinda weird. Anyway,
+               // clients like ecto do not allow to change the time an article is posted so this is not 
+               // too annoying, *yet*
+                if (!empty($dateCreated))
+                {
+                   // Convert the UTC time to local time, since articleDate is in local time
+                   $ar = localtime ( $dateCreated->getTimestamp() );
+                   $ar[5] += 1900; $ar[4]++;
+                   $localTimeStamp = gmmktime ( $ar[2], $ar[1], $ar[0], $ar[4], $ar[3], $ar[5], $ar[8] );
+                   $articleDate = date("YmdHis", $localTimeStamp);
+                } else
+                {
+                   $articleDate = date("YmdHis");
+                }
+                
+                $article->setDate($articleDate);
+                
+                $blogInfo = $blogsG->getBlogInfo( $blogid );
+                
+                
+                // Get the plugin manager
+                $plugMgr =& PluginManager::getPluginManager();
+                $plugMgr->setBlogInfo( $blogInfo );
+                $plugMgr->setUserInfo( $userInfo );
+                $plugMgr->loadPlugins();
+                // Send the PRE_POST_POST_ADD message
+                $plugMgr->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article ));            
+                
+                $postid = $articles->addArticle($article);
+                if ($postid != 0)
+                {
+                    // The post was successful
+                    
+                    // Send the EVENT_POST_POST_ADD messages to the plugins
+                    $plugMgr->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article ));
+                    
+                    CacheControl::resetBlogCache( $blogid );
+                    
+                    $blogSettings = $blogInfo->getSettings();
+                    
+                    // Add article notifcations if this is specified by the default setting.
+                    if ($blogSettings->getValue( "default_send_notification" ))
+                    {
+                        require_once( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
+    
+                        $artNotifications = new ArticleNotifications();
+                        $artNotifications->addNotification( $postid, $blogid, $userInfo->getId());
+                    }
+                    
+                    return sprintf( "%d", $postid );
+                } else
+                {
+                return new IXR_Error(-1, 'Internal error occured creating your post!');
+                }
+            } else
+            {
+                return new IXR_Error(-1, 'You did not provide the correct password');
+            }
+        }
+
 	
 		/**
 		 * @private



More information about the pLog-svn mailing list