[pLog-svn] r6905 - in plugins/branches/lifetype-1.2/moblog: class/action class/log class/moblog install locale templates

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Thu Jun 18 11:11:07 EDT 2009


Author: jondaley
Date: 2009-06-18 11:11:07 -0400 (Thu, 18 Jun 2009)
New Revision: 6905

Modified:
   plugins/branches/lifetype-1.2/moblog/class/action/adminmoblogpluginupdatesettingsaction.class.php
   plugins/branches/lifetype-1.2/moblog/class/log/mobloglogger.class.php
   plugins/branches/lifetype-1.2/moblog/class/moblog/moblogrequest.class.php
   plugins/branches/lifetype-1.2/moblog/install/moblog.php
   plugins/branches/lifetype-1.2/moblog/locale/locale_en_UK.php
   plugins/branches/lifetype-1.2/moblog/templates/pluginsettings.template
Log:
allow specifying articles and global articles in the email/post request.  The global article part isn't quite done, and there is some debugging code still in this version, but I don't like not checking in stuff every once in a while

Modified: plugins/branches/lifetype-1.2/moblog/class/action/adminmoblogpluginupdatesettingsaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/moblog/class/action/adminmoblogpluginupdatesettingsaction.class.php	2009-06-18 13:22:57 UTC (rev 6904)
+++ plugins/branches/lifetype-1.2/moblog/class/action/adminmoblogpluginupdatesettingsaction.class.php	2009-06-18 15:11:07 UTC (rev 6905)
@@ -18,11 +18,11 @@
 		function AdminMoblogPluginUpdateSettingsAction( $actionInfo, $request )
 		{
 			$this->AdminAction( $actionInfo, $request );
-        	$this->registerFieldValidator("categoryIds", new ArrayValidator(new IntegerValidator()));
+        	$this->registerFieldValidator("categoryIds", new ArrayValidator(new IntegerValidator(true)));
         	$this->registerFieldValidator("pluginEnabled", new IntegerValidator(), true);
         	$this->registerFieldValidator("albumId", new IntegerValidator());
         	$this->registerFieldValidator("resourcePreviewType", new IntegerValidator());
-        	$this->registerFieldValidator("globalArticleCategoryId", new IntegerValidator());
+        	$this->registerFieldValidator("globalArticleCategoryId", new IntegerValidator(true));
 
 			$view = new AdminMoblogPluginSettingsView( $this->_blogInfo, $this->_userInfo );
         	$view->setErrorMessage( $this->_locale->tr("moblog_error_updating_settings"));

Modified: plugins/branches/lifetype-1.2/moblog/class/log/mobloglogger.class.php
===================================================================
--- plugins/branches/lifetype-1.2/moblog/class/log/mobloglogger.class.php	2009-06-18 13:22:57 UTC (rev 6904)
+++ plugins/branches/lifetype-1.2/moblog/class/log/mobloglogger.class.php	2009-06-18 15:11:07 UTC (rev 6905)
@@ -16,7 +16,7 @@
 			if( MOBLOG_DEBUG ) {
 				lt_include( PLOG_CLASS_PATH."class/logger/loggermanager.class.php" );
 				$logger =& LoggerManager::getLogger();
-				$logger->debug( $message );		
+				$logger->debug( $message );
 			}
 		}
 	}

Modified: plugins/branches/lifetype-1.2/moblog/class/moblog/moblogrequest.class.php
===================================================================
--- plugins/branches/lifetype-1.2/moblog/class/moblog/moblogrequest.class.php	2009-06-18 13:22:57 UTC (rev 6904)
+++ plugins/branches/lifetype-1.2/moblog/class/moblog/moblogrequest.class.php	2009-06-18 15:11:07 UTC (rev 6905)
@@ -16,6 +16,8 @@
         var $_topic;
         var $_user;
         var $_pass;
+        var $_globalCategory;
+        var $_articleCategories;
         var $_blogId;
         var $_blogName;
         var $_attachments;
@@ -41,6 +43,10 @@
             isset( $request["blogId"] ) ? $this->_blogId = $request["blogId"] : $this->_blogId = "";
             isset( $request["user"] ) ? $this->_user = $request["user"] : $this->_user = "";
             isset( $request["password"] ) ? $this->_pass = $request["password"] : $this->_pass = "";
+            isset( $request["articleCategories"] ) ?
+                $this->_articlecategories = $request["articleCategories"] : $this->_articlecategories = "";
+            isset( $request["globalCategory"] ) ?
+                $this->_globalcategory = $request["globalCategory"] : $this->_globalcategory = "";
             
             
             // parse the mime message
@@ -96,38 +102,50 @@
             //$body = strtr($body,"\xE2\x80\xA9","\n\n\n");
             $body = str_replace("\xE2\x80\xA9","\n",$body);
             
-            //We try to find out where the line containing the title is at...
+                // find the inline topic/title
             if (preg_match("/^topic:(.*)/mi", $body, $title)) {
                 //And put the title var in the proper place
                 $this->_topic = trim($title[1]);
             }
-            
-            //We repeat the same trick as above... for all vars wanted
+                // find user
             if (preg_match("/^user:(.*)/mi", $body, $user)) {
                 $this->_user = trim($user[1]); 
             }       
-            
-                // remove pass or password
+                // find pass or password
             if (preg_match("/^pass(?:word)?:(.*)/mi", $body, $password)) {
                 $this->_pass = trim($password[1]);
             }
-
-            // we can either specify a blog id...
+                // find cat, cats, category, or categories
+            if (preg_match("/^cat(?:s|egor(?:y|ies)?)?:(.*)/mi", $body, $articlecategories)) {
+                $this->_articlecategories = trim($articlecategories[1]);
+            }
+                // find globalcat or globalcategory
+            if (preg_match("/^globalcat(?:egory)?:(.*)/mi", $body, $globalcategory)) {
+                $this->_globalcategory = trim($globalcategory[1]);
+            }
+                // find blogid
             if (preg_match("/^blogid:(.*)/mi", $body, $blog)) {
                 $this->_blogId = trim($blog[1]); 
             }
-            
-            // ...or a blog name
+                // find blog(name)
             if (preg_match("/^blog:(.*)/mi", $body, $blogname)) {
                 $this->_blogName = trim($blogname[1]); 
             }
+
+                // Sanitize the data
+            $this->_articlecategories = explode(",", preg_replace("/^0-9,/", "", $this->_articlecategories));
+            $this->_globalcategory = preg_replace("/^0-9/", "", $this->_globalcategory);
+
+                // TODO: sanitize/validate the rest of the data too
             
-            //We strip out all the lines we already used, and use what's left as the body
+                //We strip out all the lines we already used, and use what's left as the body
             $body = str_replace($title[0], "", $body);		
             $body = str_replace($user[0], "", $body);
             $body = str_replace($password[0], "", $body);
             $body = str_replace($blog[0], "", $body );
             $body = str_replace($blogname[0], "", $body );            
+            $body = str_replace($articlecategories[0], "", $body );            
+            $body = str_replace($globalcategory[0], "", $body );            
             
             // strip off a standard .sig. Properly formed .sigs start with '-- ' on a new line.
             list($body, $sig) = explode("\n-- ", $body);
@@ -136,8 +154,8 @@
                 $body = str_replace( $str, '', $body );
             }
             
+            $body = trim($body);            
             MoblogLogger::log( "parseBody ---> body = $body" );
-            $body = trim($body);            
             $this->_body .= $body;
         }
         
@@ -276,6 +294,16 @@
             return $this->_pass;
         }
         
+        function getArticleCategories()
+        {
+            return $this->_articlecategories;
+        }
+        
+        function getGlobalCategory()
+        {
+            return $this->_globalcategory;
+        }
+        
         function getTopic()
         {
             if ( MOBLOG_FORCE_ENCODE_TO_UTF8 )

Modified: plugins/branches/lifetype-1.2/moblog/install/moblog.php
===================================================================
--- plugins/branches/lifetype-1.2/moblog/install/moblog.php	2009-06-18 13:22:57 UTC (rev 6904)
+++ plugins/branches/lifetype-1.2/moblog/install/moblog.php	2009-06-18 15:11:07 UTC (rev 6905)
@@ -1,5 +1,7 @@
 <?php
 
+ini_set("display_errors", "true");
+
     // define the entry point
 if (!defined( "PLOG_CLASS_PATH" )) {
     $path = dirname(__FILE__);
@@ -66,11 +68,17 @@
     // 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( "pass = '".$request->getPassword()."'");
 MoblogLogger::log( "blog id = ".$request->getBlogId());
+MoblogLogger::log( "blog name = ".$request->getBlogName());
 MoblogLogger::log( "topic = ".$request->getTopic());
 MoblogLogger::log( "reply to = ".$request->getReplyTo());
 MoblogLogger::log( "body = ".$request->getBody());
+foreach($request->getArticleCategories() as $category){
+    MoblogLogger::log( "request article category = $category");
+}
+print_r($request->getArticleCategories());
+MoblogLogger::log( "request global category = ".$request->getGlobalCategory());
     
     //
     // start processing the message...
@@ -100,31 +108,22 @@
     //
 $blogs = new Blogs();
 if( $request->getBlogId() == "" ) {
-        // user gave a blog name instead of a blog id
-    $allBlogs = $blogs->getAllBlogs( BLOG_STATUS_ACTIVE, ALL_BLOG_CATEGORIES );
-    if( $allBlogs ) {
-        $found = false;
-        $blogName = stripslashes($request->getBlogName());
-        while( !$found && !empty($allBlogs)) {
-            $blogInfo = array_pop( $allBlogs );
-            if( strcasecmp($blogInfo->getBlog(), $blogName) == 0 ) {
-                $found = true;
-                MoblogLogger::log( "Blog '".$blogInfo->getBlog()."' found with id = '".$blogInfo->getId()."'");
-            }
-        }
-            
-        if( !$found ) {
-            $response = new MoblogResponse( $request->getReplyTo(),
-                                            "LifeType Moblog: Error",
-                                            "Incorrect blog."
-                                            );
-            MoblogLogger::log( "Blog ".$request->getBlogId()." does not exist." );
-            $response->send();         
-            return false;                
-        }
+        // user gave a blog name instead of a blog id (if he didn't, we'll get an error)
+    $blogInfo = $blogs->getBlogInfoByName($request->getBlogName());
+    if( !$blogInfo ) {
+        $response = new MoblogResponse( $request->getReplyTo(),
+                                        "LifeType Moblog: Error",
+                                        "Incorrect blog name.  Please specify the blogId or blogName."
+                                        );
+        MoblogLogger::log( "Blog ".$request->getBlogName()." is not valid." );
+        $response->send();         
+        return false;    
     }
 }
 else {
+        // TODO: we should check the blogDomain too -
+        // that way the blogId / name doesn't have to be specified at all,
+        // if the site is using custom domains.
     $blogInfo = $blogs->getBlogInfo( $request->getBlogId());
     if( !$blogInfo ) {
         $response = new MoblogResponse( $request->getReplyTo(),
@@ -165,29 +164,47 @@
     $response->send();         
     return false;
 }
-    
-    //
-    // if everything's correct, then we can proceed to find if the category 
-    // chosen by the user exists. Since there is no way to fetch a category by its name,
-    // we'll have to fetch them all and loop through them
-    //
+
+    // check the specified categories to make sure they exist
 $articleCategories = new ArticleCategories();    
     // load the category as defined in the plugin settings page
 $requestedCategoryIds = $blogSettings->getValue( "plugin_moblog_article_category_id" );
-
-    // old method, is without a category
+// old method is with just one category
 if(!is_array($requestedCategoryIds)){
     $requestedCategoryIds = array($requestedCategoryIds);
 }
 
-$verifiedCategoryIds = array();
-foreach($requestedCategoryIds as $catId){
-    $category = $articleCategories->getCategory( $catId, $blogInfo->getId());
-    if(!$category)
-        continue;
-    $verifiedCategoryIds[] = $category->getId();
+$verifiedSettingsCategoryIds = array();
+$verifiedEmailCategoryIds = array();
+$acceptArticleCategories = false;
+foreach($requestedCategoryIds as $settingsCatId){
+        // a "fake" category which means that the category will be specified
+        // by the POSTed data.  (if "override" and other categories are specified,
+        // it means that the category *might* be specified in the email)
+    if($settingsCatId == -1){
+        $acceptArticleCategories = true;
+        foreach($request->getArticleCategories() as $emailCatId){
+            $category = $articleCategories->getCategory($emailCatId, $blogInfo->getId());
+            if(!$category)
+                continue;
+            $verifiedEmailCategoryIds[] = $category->getId();
+        }
+    }
+    else{
+        $category = $articleCategories->getCategory($settingsCatId, $blogInfo->getId());
+        if(!$category)
+            continue;
+        $verifiedSettingsCategoryIds[] = $category->getId();
+    }
 }
 
+// If the user specified categories in the email (and the blog settings allow them to override
+// the settings), they will take precedence
+if(count($verifiedEmailCategoryIds))
+    $verifiedCategoryIds = $verifiedEmailCategoryIds;
+else
+    $verifiedCategoryIds = $verifiedSettingsCategoryIds;
+
 if(!count($verifiedCategoryIds)){
         // 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
@@ -205,6 +222,10 @@
     return false;
 }
 
+foreach($verifiedCategoryIds as $catId){
+    MoblogLogger::log( "final article category = $catId");
+}
+
     //
     // finally, add the resources to the database
     //
@@ -314,7 +335,10 @@
     // enable or disable comments by default depending on the current config
 $commentsEnabled = $blogSettings->getValue( "comments_enabled" );
 $article->setCommentsEnabled( $commentsEnabled );
-    
+
+MoblogLogger::log( "done, would publish if not debugging");
+die;
+
 $result = $articles->addArticle( $article );
     
     // add an article notification

Modified: plugins/branches/lifetype-1.2/moblog/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/moblog/locale/locale_en_UK.php	2009-06-18 13:22:57 UTC (rev 6904)
+++ plugins/branches/lifetype-1.2/moblog/locale/locale_en_UK.php	2009-06-18 15:11:07 UTC (rev 6905)
@@ -16,6 +16,7 @@
 $messages["moblog_image_preview_type_help"] = "When embedding images in moblogged posts, how should the image be embedded?'";
 $messages['moblog_global_article_category_help'] = 'Which site-wide category should articles be posted in?';
 $messages["moblog_error_updating_settings"] = "There was an error updating the settings.";
+$messages["moblog_specify_in_email"] = "Specify in message";
 
 //
 // Moblog Batch Strings

Modified: plugins/branches/lifetype-1.2/moblog/templates/pluginsettings.template
===================================================================
--- plugins/branches/lifetype-1.2/moblog/templates/pluginsettings.template	2009-06-18 13:22:57 UTC (rev 6904)
+++ plugins/branches/lifetype-1.2/moblog/templates/pluginsettings.template	2009-06-18 15:11:07 UTC (rev 6905)
@@ -19,6 +19,7 @@
    <label for="categoryIds">{$locale->tr("posts")}</label>
    <div class="formHelp">{$locale->tr("moblog_articles_help")}</div>
    <select name="categoryIds[]" multiple="multiple" size="5">
+     <option value="-1" {foreach from=$categoryIds item=categoryId}{if -1 == $categoryId} selected="selected" {/if}{/foreach}>{$locale->tr("moblog_specify_in_email")}</option>
     {foreach from=$categories item=category}
      <option value="{$category->getId()}" {foreach from=$categoryIds item=categoryId}{if $category->getId() == $categoryId} selected="selected" {/if}{/foreach}>{$category->getName()}</option>
 	{/foreach}
@@ -28,6 +29,7 @@
 	<div class="formHelp">{$locale->tr("moblog_global_article_category_help")}</div>
     <select name="globalArticleCategoryId" id="globalArticleCategoryId">
 	  <option value="0" {if 0 == $globalArticleCategoryId} selected="selected" {/if}>{$locale->tr("none")}</option>
+	  <option value="-1" {if -1 == $globalArticleCategoryId} selected="selected" {/if}>{$locale->tr("moblog_specify_in_email")}</option>
       {foreach from=$globalArticleCategories item=globalArticleCategory}
         <option value="{$globalArticleCategory->getId()}" {if $globalArticleCategory->getId() == $globalArticleCategoryId} selected="selected" {/if}>{$globalArticleCategory->getName()}</option>
       {/foreach}



More information about the pLog-svn mailing list