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

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


Author: jondaley
Date: 2009-06-18 11:51:34 -0400 (Thu, 18 Jun 2009)
New Revision: 6907

Modified:
   plugins/branches/lifetype-1.2/moblog/install/moblog.php
Log:
removed debug code.  Added GlobalArticleCategory (can be specified in the control center or in the email)

Modified: plugins/branches/lifetype-1.2/moblog/install/moblog.php
===================================================================
--- plugins/branches/lifetype-1.2/moblog/install/moblog.php	2009-06-18 15:17:11 UTC (rev 6906)
+++ plugins/branches/lifetype-1.2/moblog/install/moblog.php	2009-06-18 15:51:34 UTC (rev 6907)
@@ -38,6 +38,7 @@
 lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" ); 
 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+lt_include( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" );
 lt_include( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );	
 lt_include( PLOG_CLASS_PATH."class/file/fileupload.class.php" );
     
@@ -77,7 +78,6 @@
 foreach($request->getArticleCategories() as $category){
     MoblogLogger::log( "request article category = $category");
 }
-print_r($request->getArticleCategories());
 MoblogLogger::log( "request global category = ".$request->getGlobalCategory());
     
     //
@@ -166,8 +166,13 @@
 }
 
     // check the specified categories to make sure they exist
-$verifiedCategoryIds = getArticleCategories($request, $blogInfo);
+if(!$verifiedCategoryIds = getArticleCategories($request, $blogInfo))
+    return false;
 
+// globalCategoryId is optional in LifeType.  this will be set to false
+// if it isn't specified (or is incorrect)
+$globalCategoryId = getGlobalCategory($request, $blogSettings);
+
     // 
     // finally, add the resources to the database
     //
@@ -278,15 +283,15 @@
 $commentsEnabled = $blogSettings->getValue( "comments_enabled" );
 $article->setCommentsEnabled( $commentsEnabled );
 
-MoblogLogger::log( "done, would publish if not debugging");
-die;
+if($globalCategoryId)
+    $article->setGlobalCategoryId($globalCategoryId);
 
 $result = $articles->addArticle( $article );
     
     // add an article notification
 $notifications = new ArticleNotifications();
 $notifications->addNotification( $result, $blogInfo->getId(), $userInfo->getId());
-    
+
     // reset the cache in case it is enabled
 CacheControl::resetBlogCache( $blogInfo->getId());    
     
@@ -309,6 +314,9 @@
     }
     $response = new MoblogResponse( $request->getReplyTo(), $locale->tr("moblog_mailsubject"), $responseBody ); 
     MoblogLogger::log( "Post was successfully added to the database." );
+
+        // TODO: we should send regular events
+        //notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article )); 
 }
 $response->send();
     
@@ -351,8 +359,8 @@
         }
     }
     
-// If the user specified categories in the email (and the blog settings allow them to override
-// the settings), they will take precedence
+        // 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
@@ -381,4 +389,44 @@
 
     return $verifiedCategoryIds;
 }
-?>
+
+
+
+function getGlobalCategory($request, $blogSettings){
+        // check the specified categories to make sure they exist
+    $articleCategories = new GlobalArticleCategories();    
+        // load the category as defined in the plugin settings page
+    $settingsCategoryId = $blogSettings->getValue( "plugin_moblog_global_article_category_id" );
+    $requestCategoryId = $request->getGlobalCategory();
+    
+        // a "fake" category which means that the category will be specified
+        // by the POSTed data.
+    if($settingsCategoryId == -1){
+        $category = $articleCategories->getGlobalArticleCategory($requestCategoryId);
+    }
+    else{
+        $category = $articleCategories->getGlobalArticleCategory($settingsCategoryId);
+    }
+
+    if(!$category){
+            // 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 global category does not exist."
+                                        );
+        $msg = "User '".$request->getUser()."' tried to use global category: '";
+        if($settingCategoryId == -1)
+            $msg .= "REQUEST: ".$requestCategoryId;
+        else
+            $msg .= "SETTINGS: ".$settingsCategoryId;
+        $msg .= "' which does not exist.";
+        MoblogLogger::log($msg);
+        $response->send(); 
+        return false;
+    }
+    
+    MoblogLogger::log( "final global category = ".$category->getId());
+
+    return $category->getId();
+}



More information about the pLog-svn mailing list