[pLog-svn] r2008 - in plugins/trunk: . moblog/class/moblog

oscar at devel.plogworld.net oscar at devel.plogworld.net
Fri May 13 20:28:16 GMT 2005


Author: oscar
Date: 2005-05-13 20:28:15 +0000 (Fri, 13 May 2005)
New Revision: 2008

Modified:
   plugins/trunk/moblog.php
   plugins/trunk/moblog/class/moblog/moblogrequest.class.php
Log:
Some cleanup but more importantly, it is now possible to specify a default blogId and user name to which posts should be added, instead of typing too much in the MMS/email message sent.

Modified: plugins/trunk/moblog/class/moblog/moblogrequest.class.php
===================================================================
--- plugins/trunk/moblog/class/moblog/moblogrequest.class.php	2005-05-13 19:42:44 UTC (rev 2007)
+++ plugins/trunk/moblog/class/moblog/moblogrequest.class.php	2005-05-13 20:28:15 UTC (rev 2008)
@@ -24,14 +24,22 @@
         var $_attachments;
         var $_help;
         
-        function MoblogRequest( $message )
+        function MoblogRequest( $request )
         {
             $this->Object();
         
-            $this->_message = $message;
+            $this->_message = $request["message"];
+            // it is possible to specify a default user id in the POSTed email message via
+            // curl, so that the amount of stuff that we need to type in the email is reduced
+            // to only the user password. This basically means that email addresses configured to be used
+            // by a default user and blog id cannot be used as 'gateways'
+            $this->_blogId = $request["blogId"];
+            $this->_user = $request["user"];
             
+            MoblogLogger::log( "From REQUEST: user = ".$this->_user." - blogId = ".$this->_blogId );
+            
             // parse the mime message
-            $decode = new Mail_mimeDecode( $message, "\r\n" );
+            $decode = new Mail_mimeDecode( $this->_message, "\r\n" );
             $structure = $decode->decode(Array(
                                              "include_bodies" => true,
                                              "decode_bodies"  => true,
@@ -86,13 +94,8 @@
             //We repeat the same trick as above... for all vars wanted
             if (preg_match("/^user:(.*)/mi", $body, $user)) {
                 $this->_user = trim($user[1]); 
-            }
+            }       
             
-            //We repeat the same trick as above... for all vars wanted
-            if (preg_match("/^host:(.*)/mi", $body, $host)) {
-                $this->_host = trim($host[1]); 
-            }            
-            
             // in case ppl are lazy and use pass instead of password
             if (preg_match("/^pass:(.*)/mi", $body, $pass)) {
                 $this->_pass = trim($pass[1]);
@@ -227,11 +230,6 @@
             return $this->_topic;
         }
         
-        function getCategory()
-        {
-            return $this->_category;
-        }
-        
         function getBody()
         {
             return $this->_body;
@@ -242,19 +240,9 @@
             return $this->_replyAddress;
         }
         
-        function getHost()
-        {
-            return $this->_host;
-        }
-        
         function getAttachments()
         {
             return $this->_attachments;
         }
-        
-        function isHelpRequest()
-        {
-            return( $this->_user == "" && $this->_pass == "" );
-        }
     }
 ?>
\ No newline at end of file

Modified: plugins/trunk/moblog.php
===================================================================
--- plugins/trunk/moblog.php	2005-05-13 19:42:44 UTC (rev 2007)
+++ plugins/trunk/moblog.php	2005-05-13 20:28:15 UTC (rev 2008)
@@ -28,25 +28,6 @@
 	include_once( PLOG_CLASS_PATH."plugins/moblog/class/moblog/moblogconstants.properties.php" );
 	include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" ); 
     
-//// help message sent to users requesting it ////
-    $helpMessage = <<< EOD
-pLog Moblog
------------
-Send a message with the following format ('start' and 'end' messages not included!):
-
-<<<<< start of moblog message format >>>>>
-
-USER: your-plog-username
-PASS: your-plog-password
-BLOG: your-plog-blog-name
-
-<<<<< end of moblog message format >>>>>
-
-The must be sent as plain text, and it can include as many attachment as needed.
-EOD;
-///////////////////////
-
-    
     // initialize the logging system
     MoblogLogger::log( "-- Initialized");
     
@@ -65,29 +46,17 @@
     
     MoblogLogger::log("-- message --");
     MoblogLogger::log($message);
-    MoblogLogger::log("-- end --");    
+    MoblogLogger::log("-- end --");
     
     // parse the message
-    $request = new MoblogRequest( $message );
+    $request = new MoblogRequest( $request );
     
-    MoblogLogger::log("here?");
-    
-    // check if it's a help message
-    if( $request->isHelpRequest()) {
-        $response = new MoblogResponse( $request->getReplyTo(),
-                                        "pLog Moblog: Help",
-                                        $helpMessage );
-        $response->send();
-        die();
-    }
-    
     // let's see what we get...    
     MoblogLogger::log( "user = '".$request->getUser()."'");
     // uncomment the following if you want to see passwords... :)
     //MoblogLogger::log( "pass = ".$request->getPassword()."'");
     MoblogLogger::log( "blog id = ".$request->getBlogId());
     MoblogLogger::log( "topic = ".$request->getTopic());
-    MoblogLogger::log( "category = ".$request->getCategory());
     MoblogLogger::log( "reply to = ".$request->getReplyTo());
     MoblogLogger::log( "body = ".$request->getBody());
     
@@ -190,33 +159,17 @@
     // we'll have to fetch them all and loop through them
     //
     $articleCategories = new ArticleCategories();    
-    if( $request->getCategory()) {
-        $categories = $articleCategories->getBlogCategories( $blogInfo->getId());
-        $found = false;
-        while( !$found && !empty($categories)) {
-            $category = array_pop( $categories );
-            if( strcasecmp($category->getName(),$request->getCategory()) == 0 ) {
-                $found = true;
-                MoblogLogger::log( "Category '".$category->getName()."' found with id = '".$category->getId()."'");
-            }
-        }
-    }
-    else {
-        // load the category as defined in the plugin settings page
-        $categoryId = $blogSettings->getValue( "plugin_moblog_article_category_id" );
-        $category = $articleCategories->getCategory( $categoryId, $blogInfo->getId());
-        // check if the category was loaded just fine
-        $found = ( $category != null );
-    }
-    
+    // load the category as defined in the plugin settings page
+    $categoryId = $blogSettings->getValue( "plugin_moblog_article_category_id" );
+    $category = $articleCategories->getCategory( $categoryId, $blogInfo->getId());
     // if there was no such category, we should send an error and to make it more useful, send
     // as part of the error message the list of available categories
-    if( !$found ) {
+    if( !$category ) {
         $response = new MoblogResponse( $request->getReplyTo(),
                                   "pLog Moblog: Error",
                                   "The category does not exist."
                                 );
-        MoblogLogger::log( "User '".$request->getUser()."' tried to use category '".$request->getCategory().
+        MoblogLogger::log( "User '".$request->getUser()."' tried to use category '".$categoryId.
                      "' which does not exist.");
         $response->send(); 
     }
@@ -231,14 +184,13 @@
     $t = new Timestamp();    
     $albumId = $blogSettings->getValue( "plugin_moblog_gallery_resource_album_id" );
     $album = $albums->getAlbum( $albumId, $blogInfo->getId());
-    $found = ( $album != null );
-    
-    if( !$found ) {
+    // check if the album was loaded    
+    if( !$album ) {
         $response = new MoblogResponse( $request->getReplyTo(),
                                   "pLog Moblog: Error",
                                   "The album does not exist."
                                 );
-        MoblogLogger::log( "User '".$request->getUser()."' tried to use category '".$request->getCategory().
+        MoblogLogger::log( "User '".$request->getUser()."' tried to use album '".$albumId.
                      "' which does not exist.");
         $response->send(); 
     }




More information about the pLog-svn mailing list