[pLog-svn] r694 - plog/trunk

oscar at devel.plogworld.net oscar at devel.plogworld.net
Sat Jan 8 17:21:11 GMT 2005


Author: oscar
Date: 2005-01-08 17:21:11 +0000 (Sat, 08 Jan 2005)
New Revision: 694

Modified:
   plog/trunk/xmlrpc.php
Log:
added support for media objects (resources) via the metaweblog API, thanks to user 'pwestbro' from the forums (see http://www.plogworld.net/forums/viewtopic.php?p=7201#7201)

Modified: plog/trunk/xmlrpc.php
===================================================================
--- plog/trunk/xmlrpc.php	2005-01-08 17:16:33 UTC (rev 693)
+++ plog/trunk/xmlrpc.php	2005-01-08 17:21:11 UTC (rev 694)
@@ -35,6 +35,7 @@
 	include_once( PLOG_CLASS_PATH."class/dao/users.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/gallery/dao/galleryresources.class.php" );
 	
 
     // init database
@@ -649,7 +650,85 @@
             return new IXR_Error(-1, 'You did not provide the correct password');
         }
     }
+	
+    function metaWeblogNewMediaObject($args)
+    {
+        global $users, $articles, $blogsG;
+        /*
+            "userid" =>
+            "dateCreated" =>
+            "content" =>
+            "postid" =>
+        */
+        $blogid     = $args[0];
+        $username   = $args[1];
+        $password   = $args[2];
+        $file       = $args[3];
 
+        $erg = $users->getUserInfo($username,$password);
+        if ($erg != false)
+        {
+            // Save this file to the tmp directory
+            
+            // Create a temp file
+            // Get the temp directory
+            /**if (!$tmp_dir = get_cfg_var('upload_tmp_dir')) {
+                $tmp_dir = dirname(tempnam('/tmp', ''));
+            }*/
+			$config =& Config::getConfig();
+			$tmp_dir = $config->getTempFolder();
+            
+            // Remove all characters that would need to be urlencoded
+            // This may not be necessary, but this was causing problems when given file
+            // names with spaces in it.
+            $tempFile = ereg_replace("[^a-zA-Z0-9._-]", "_", basename($file['name']));
+            // Make the tmp name
+            $tempFile = $tmp_dir . '/' . $tempFile;
+
+            // Open the file
+            if (!$handle = fopen( $tempFile, "wb" ) ) {
+                return new IXR_Error(-1, 'Could not open file');
+            }    
+            
+            // It appears that the data has already been decoded, no need to call base64_decode
+            $decodedBits = $file['bits'];
+            // Write the data to the file
+            if ( fwrite( $handle, $decodedBits ) === false ) {
+                return new IXR_Error(-1, 'Could not write to file');
+            }
+
+            // Close the file
+            fclose($handle);
+            
+            // let the gallery library do its work...
+        	$resources = new GalleryResources();
+
+            // Get the first album for this blog
+            $albums = new GalleryAlbums();
+            // get the list of albums for this blog
+            $albumArray = $albums->getUserAlbums( $blogid );
+            if ( $albumArray == NULL || count( $albumArray ) == 0 ) {
+                return new IXR_Error(-1, 'Could not find album');
+            }
+            
+            // Add the resource to the first album
+            $resId = $resources->addResourceFromDisk( $blogid, $albumArray[0]->getId(),
+                                                     basename($file['name']), $tempFile );
+            // Get the resource from the id
+            $resource = $resources->getResource( $resId, $blogid, $albumArray[0]->getId() );
+            // Now we need to get the url for the resource
+            $blogInfo = $blogsG->getBlogInfo( $blogid );
+            $url = $blogInfo->getBlogRequestGenerator();
+            
+            $ret = $url->resourceDownloadLink( $resource );
+                        
+            return $ret;
+        } else
+        {
+            return new IXR_Error(-1, 'You did not provide the correct password');
+        }
+    }	
+
     function getUserInfo($args)
     {
         $appkeyp    = $args[0];
@@ -740,7 +819,8 @@
             "metaWeblog.editPost"       => "metaWeblogEditPost",
             "metaWeblog.getPost"        => "metaWeblogGetPost",
             "metaWeblog.getRecentPosts" => "metaWeblogGetRecentPosts",
-            "metaWeblog.getCategories"  => "metaWeblogGetCategories"
+            "metaWeblog.getCategories"  => "metaWeblogGetCategories",
+            "metaWeblog.newMediaObject" => "metaWeblogNewMediaObject"			
     	    )
 	);
     } else




More information about the pLog-svn mailing list