[pLog-svn] r6906 - plugins/branches/lifetype-1.2/moblog/install

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


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

Modified:
   plugins/branches/lifetype-1.2/moblog/install/moblog.php
Log:
refactored

Modified: plugins/branches/lifetype-1.2/moblog/install/moblog.php
===================================================================
--- plugins/branches/lifetype-1.2/moblog/install/moblog.php	2009-06-18 15:11:07 UTC (rev 6905)
+++ plugins/branches/lifetype-1.2/moblog/install/moblog.php	2009-06-18 15:17:11 UTC (rev 6906)
@@ -166,70 +166,12 @@
 }
 
     // 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 with just one category
-if(!is_array($requestedCategoryIds)){
-    $requestedCategoryIds = array($requestedCategoryIds);
-}
+$verifiedCategoryIds = getArticleCategories($request, $blogInfo);
 
-$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
-    $response = new MoblogResponse( $request->getReplyTo(),
-                                    "LifeType Moblog: Error",
-                                    "The categories do not exist."
-                                    );
-    $msg = "User '".$request->getUser()."' tried to use category: '";
-    foreach($requestedCategoryIds as $catId){
-        $msg .= $catId . ",";
-    }
-    $msg .= "' which does not exist.";
-    MoblogLogger::log($msg);
-    $response->send(); 
-    return false;
-}
-
-foreach($verifiedCategoryIds as $catId){
-    MoblogLogger::log( "final article category = $catId");
-}
-
-    //
+    // 
     // finally, add the resources to the database
     //
-    
+
     // first, create a new album to hold these attachments
 $albums = new GalleryAlbums();
 $userAlbums = $albums->getUserAlbums( $blogInfo->getId());
@@ -372,4 +314,71 @@
     
     // end of it...
 MoblogLogger::log( "-- End");    
+
+
+
+function getArticleCategories($request, $blogInfo){
+    $blogSettings = $blogInfo->getSettings();
+    
+        // 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 with just one category
+    if(!is_array($requestedCategoryIds)){
+        $requestedCategoryIds = array($requestedCategoryIds);
+    }
+    
+    $verifiedSettingsCategoryIds = array();
+    $verifiedEmailCategoryIds = array();
+    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){
+            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
+        $response = new MoblogResponse( $request->getReplyTo(),
+                                        "LifeType Moblog: Error",
+                                        "The categories do not exist."
+                                        );
+        $msg = "User '".$request->getUser()."' tried to use category: '";
+        foreach($requestedCategoryIds as $catId){
+            $msg .= $catId . ",";
+        }
+        $msg .= "' which does not exist.";
+        MoblogLogger::log($msg);
+        $response->send(); 
+        return false;
+    }
+    
+    foreach($verifiedCategoryIds as $catId){
+        MoblogLogger::log( "final article category = $catId");
+    }
+
+    return $verifiedCategoryIds;
+}
 ?>



More information about the pLog-svn mailing list