[pLog-svn] r6880 - in plugins/branches/lifetype-1.2: . mtexport mtexport/class mtexport/class/action mtexport/class/view mtexport/locale mtexport/templates

pwestbro at devel.lifetype.net pwestbro at devel.lifetype.net
Mon May 4 05:49:16 EDT 2009


Author: pwestbro
Date: 2009-05-04 05:49:16 -0400 (Mon, 04 May 2009)
New Revision: 6880

Added:
   plugins/branches/lifetype-1.2/mtexport/
   plugins/branches/lifetype-1.2/mtexport/class/
   plugins/branches/lifetype-1.2/mtexport/class/action/
   plugins/branches/lifetype-1.2/mtexport/class/action/adminmtexportpluginexportblogaction.class.php
   plugins/branches/lifetype-1.2/mtexport/class/action/adminmtexportpluginsettingsaction.class.php
   plugins/branches/lifetype-1.2/mtexport/class/view/
   plugins/branches/lifetype-1.2/mtexport/class/view/adminmtexportpluginsettingsview.class.php
   plugins/branches/lifetype-1.2/mtexport/locale/
   plugins/branches/lifetype-1.2/mtexport/locale/locale_en_UK.php
   plugins/branches/lifetype-1.2/mtexport/pluginmtexport.class.php
   plugins/branches/lifetype-1.2/mtexport/readme.txt
   plugins/branches/lifetype-1.2/mtexport/templates/
   plugins/branches/lifetype-1.2/mtexport/templates/pluginsettings.template
Log:
Initial checkin of a plugin that will create a Movable Type Import format
file
http://www.sixapart.com/movabletype/docs/mtimport

This is useful if you want to import it into WordPress


Added: plugins/branches/lifetype-1.2/mtexport/class/action/adminmtexportpluginexportblogaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/mtexport/class/action/adminmtexportpluginexportblogaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/mtexport/class/action/adminmtexportpluginexportblogaction.class.php	2009-05-04 09:49:16 UTC (rev 6880)
@@ -0,0 +1,236 @@
+<?php
+
+lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+lt_include( PLOG_CLASS_PATH."plugins/mtexport/class/view/adminmtexportpluginsettingsview.class.php" ); 
+
+class AdminMTExportPluginExportBlogAction extends AdminAction 
+{
+	
+  var $_cacheFolder;
+  var $_pluginEnabled;
+  var $_notifyGoogle;
+  var $_fileLocation; 
+
+
+  /**
+   * Constructor. If nothing else, it also has to call the constructor of the parent
+   * class, BlogAction with the same parameters
+   */
+  function AdminMTExportPluginExportBlogAction( $actionInfo, $request )
+  {
+
+    $this->AdminAction( $actionInfo, $request );
+
+    $config =& Config::getConfig();
+
+
+    $this->_cacheFolder = $config->getValue('temp_folder');
+    $this->_cacheFolder = $this->_cacheFolder.'/mtexport/'.$this->_blogInfo->getId();
+    if( !File::exists( $this->_cacheFolder )) {
+      File::createDir( $this->_cacheFolder, 0755 );
+    }
+
+	  
+  }
+		
+  function validate()
+  {
+    return true;
+  }
+
+
+  function htmlButTags($str) {
+    // Take all the html entities
+    $caracteres = get_html_translation_table(HTML_ENTITIES);
+    // Find out the "tags" entities
+    $remover = get_html_translation_table(HTML_SPECIALCHARS);
+    // Spit out the tags entities from the original table
+    $caracteres = array_diff($caracteres, $remover);
+    // Translate the string....
+    $str = strtr($str, $caracteres);
+    // And that's it!
+    // oo now amps
+    $str = preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&amp;" , $str);
+       
+    return $str;
+  } 
+
+  function exportBlog()
+  {
+    lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php");
+	     
+    // articles object
+    $articles = new Articles;
+    $users = new Users;
+
+    // This kind of sucks.
+    // We can't get all the articles and get the comments as we will run 
+    // out of memory.  But what we are going to do is get
+    // the first article, and then we will call getBlogNextArticle to go through the rest
+    // Unfortunately, there is no easy way to get the first article without getting the 
+    // whole list of articles
+    $list = $articles->getBlogArticles(
+                                       $this->_blogInfo->getId(),
+                                       -1,  // date
+                                       -1, // Get all articles
+                                       0,  // all categories
+                                       POST_STATUS_PUBLISHED  // only published articles
+                                       );
+
+    // Save this to a compressed file.
+    $exportFile = $this->_cacheFolder."/mt-export.txt";
+    $fd = fopen($exportFile,'w');
+
+
+    if ( $fd && isset($list) && ( count($list) > 0 ) ) {
+
+        // Get the first post
+        $item = $list[count($list) - 1 ];
+
+        unset( $list );
+
+        // Iterate over the posts and create an entry for each.
+        while ( $item ) {
+          // Get the user of this post
+          $userId = $item->getUserId();
+          $userInfo = $users->getUserInfoFromId($userId);
+
+          $username = $userInfo->getUserName();
+          fwrite( $fd, "AUTHOR: " . $username . "\n" );
+          unset( $username );
+          
+          // Write the title of the post
+          fwrite( $fd, "TITLE: " . $item->getTopic() . "\n" );
+
+          // The date of the post
+          $dateObject =  $item->getDateObject();
+          // Get the unix time stamp
+            $time = $dateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
+            unset( $dateObject );
+            $articleDate = date("m/d/Y G:i", $time);
+            unset( $time );
+            fwrite( $fd, "DATE: " . $articleDate . "\n" );
+            unset( $articleDate );
+
+            // Categories
+            $categories = $item->getCategories();
+            foreach ( $categories as $cat )
+              {
+                fwrite( $fd, "CATEGORY: " . $cat->getName() . "\n");
+              }
+            unset( $categories);
+		
+            // Status 
+            // Since we are only looking at published items, we should default his to plublish
+            fwrite( $fd, "STATUS: publish\n");
+
+            // Allow comments
+            $allowComments = $item->getCommentsEnabled() ? 1 : 0;
+            fwrite( $fd, "ALLOW COMMENTS: " . $allowComments . "\n");
+            unset($allowComments);
+            fwrite ( $fd, "-----\n");
+
+		     
+            // Body
+            fwrite ( $fd, "BODY:\n");
+            fwrite ( $fd, $this->htmlButTags($item->getIntroText()));
+            fwrite ( $fd, "\n-----\n");
+
+            // extended body
+            if ( $item->hasExtendedText() ) {
+              fwrite ( $fd, "EXTENDED BODY:\n");
+              fwrite ( $fd, $this->htmlButTags($item->getExtendedText()) );
+              fwrite ( $fd, "\n-----\n");
+            }
+		     
+            
+            // Comments
+            $comments = $item->getComments();
+            foreach ( $comments as $comment ) {
+
+              fwrite ( $fd, "COMMENT:\n");
+              $commentUserName = $comment->getUserName();
+              if ( $commentUserName && $commentUserName != "" ) {
+                fwrite ( $fd, "AUTHOR: " . $commentUserName . "\n" );
+
+              }
+              unset($commentUserName);
+
+              $commentDateObject =  $comment->getDateObject();
+              // Get the unix time stamp
+              $commentTime = $commentDateObject->getTimestamp(DATE_FORMAT_UNIXTIME);
+              unset($commentDateObject);
+              $commentDate = date("m/d/Y G:i", $commentTime);
+              unset($commentTime);
+              fwrite( $fd, "DATE: " . $commentDate . "\n" );
+              unset($commentDate);
+
+              // user email
+              $commentUserEmail = $comment->getUserEmail();
+              if ( $commentUserEmail && $commentUserEmail != "" ) {
+                fwrite ( $fd, "EMAIL: " . $commentUserEmail . "\n" );
+                unset($commentUserEmail);
+              }
+
+              // url
+              $commentUserUrl = $comment->getUserUrl();
+              if ($commentUserUrl && $commentUserUrl != "") {
+                fwrite ( $fd, "URL: " . $commentUserUrl . "\n" );
+                unset($commentUserUrl);
+              }
+              
+              // client ip address
+              fwrite ( $fd, "IP: " . $comment->getClientIp() . "\n" );
+              fwrite ( $fd, $this->htmlButTags( $comment->getText()) );
+
+              fwrite ( $fd, "\n-----\n"); 
+              unset( $comment);
+             
+            }
+
+
+            // End of the post item
+
+            fwrite ( $fd, "--------\n");
+
+            $nextArticle = $articles->getBlogNextArticle( $item );
+            unset ($item);
+            $item = $nextArticle;
+          }
+        fclose( $fd );
+      }
+
+    if( File::isReadable( $exportFile ) )
+      File::chMod( $exportFile, 0644 );
+
+    $this->_fileLocation = $exportFile;
+    return true;
+	
+  }
+		
+  /**
+   * Carries out the specified action
+   */
+  function perform()
+  {
+    // export the blogs
+	  
+    if( !$this->exportBlog( )) {
+      $this->_view = new AdminMTExportPluginSettingsView( $this->_blogInfo );
+      $this->_view->setErrorMessage( $this->_locale->tr("export_unsuccessful"));
+      $this->setCommonData();
+
+      return false;                       
+    }
+
+    $this->_view = new AdminMTExportPluginSettingsView( $this->_blogInfo );
+    $this->_view->setSuccessMessage( $this->_locale->tr("export_saved_successful"));			
+    $this->setCommonData();
+			
+    // clear the cache
+    CacheControl::resetBlogCache( $this->_blogInfo->getId());					
+            
+    return true;		
+  }
+}
+?>

Added: plugins/branches/lifetype-1.2/mtexport/class/action/adminmtexportpluginsettingsaction.class.php
===================================================================
--- plugins/branches/lifetype-1.2/mtexport/class/action/adminmtexportpluginsettingsaction.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/mtexport/class/action/adminmtexportpluginsettingsaction.class.php	2009-05-04 09:49:16 UTC (rev 6880)
@@ -0,0 +1,31 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+        lt_include( PLOG_CLASS_PATH."plugins/mtexport/class/view/adminmtexportpluginsettingsview.class.php" ); 
+
+    class AdminMTExportPluginSettingsAction extends AdminAction 
+	{
+
+    	/**
+         * Constructor. If nothing else, it also has to call the constructor of the parent
+         * class, BlogAction with the same parameters
+         */
+        function AdminMTExportPluginSettingsAction( $actionInfo, $request )
+        {
+        	$this->AdminAction( $actionInfo, $request );
+        }
+
+        /**
+         * Carries out the specified action
+         */
+        function perform()
+        {
+      	   $this->_view = new AdminMTExportPluginSettingsView( $this->_blogInfo );
+
+            $this->setCommonData();
+
+            // better to return true if everything fine
+            return true;
+        }
+    }
+?>

Added: plugins/branches/lifetype-1.2/mtexport/class/view/adminmtexportpluginsettingsview.class.php
===================================================================
--- plugins/branches/lifetype-1.2/mtexport/class/view/adminmtexportpluginsettingsview.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/mtexport/class/view/adminmtexportpluginsettingsview.class.php	2009-05-04 09:49:16 UTC (rev 6880)
@@ -0,0 +1,21 @@
+<?php
+	
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+	/**
+	 * implements the main view of the feed reader plugin
+	 */
+	class AdminMTExportPluginSettingsView extends AdminPluginTemplatedView
+	{
+
+		function AdminMTExportPluginSettingsView( $blogInfo )
+		{
+			$this->AdminPluginTemplatedView( $blogInfo, "mtexport", "pluginsettings" );
+		}
+		
+		function render()
+		{
+			parent::render();
+		}
+	}
+?>

Added: plugins/branches/lifetype-1.2/mtexport/locale/locale_en_UK.php
===================================================================
--- plugins/branches/lifetype-1.2/mtexport/locale/locale_en_UK.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/mtexport/locale/locale_en_UK.php	2009-05-04 09:49:16 UTC (rev 6880)
@@ -0,0 +1,18 @@
+<?php
+$messages["mtexportPluginSettings"] = "Movable Type Export";
+
+$messages["mtexport_plugin"] = "Movable Type Export Plugin";
+
+$messages["export_saved_successful"] = "Export successful";
+$messages["export_unsuccessful"] = "Export unsuccessful";
+
+$messages["mtexport_description"] = "This plugin will export the posts and comments for this blog";
+
+$messages["mtexport_export_blog"] = "Export";
+
+$messages["label_configuration"] = "Configuration";
+$messages["label_enable"] = "Enable";
+$messages["label_notify_google_enable"] = "Notify Google";
+
+$messages["link_to_sitemap"] = "Link to your sitemap: ";
+?>

Added: plugins/branches/lifetype-1.2/mtexport/pluginmtexport.class.php
===================================================================
--- plugins/branches/lifetype-1.2/mtexport/pluginmtexport.class.php	                        (rev 0)
+++ plugins/branches/lifetype-1.2/mtexport/pluginmtexport.class.php	2009-05-04 09:49:16 UTC (rev 6880)
@@ -0,0 +1,61 @@
+<?php
+lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+
+
+/**
+ * implements notification of
+ */
+class PluginMTExport extends PluginBase
+{
+  var $cacheFolder;
+
+  function PluginMTExport( $source = "" )
+  {
+    $this->PluginBase( $source );
+
+    $this->id = "mtexport";
+    $this->desc = "Exports a blog to a <a href='http://www.sixapart.com/movabletype/docs/mtimport'>Movable Type Import Format</a> file.";
+    $this->author = "Paul Westbrook";
+    $this->locales = Array( "en_UK" );
+    $this->version = "20090504";
+
+    if( $source == "admin" )
+      $this->initAdmin();
+  }
+
+  function initAdmin()
+  {
+    // register an action that will allow users to see which comments have not been
+    // accepted yet
+    $this->registerAdminAction( "mtexportPluginSettings", "AdminMTExportPluginSettingsAction" );
+    $this->registerAdminAction( "mtexportPluginExportBlog", "AdminMTExportPluginExportBlogAction" );
+
+    // add a menu entry
+    $menu =& Menu::getMenu();
+    if( !$menu->entryExists( "/menu/controlCenter/manageIntegrationPlugins" ))
+      $this->addMenuEntry( "/menu/controlCenter", "manageIntegrationPlugins", "", "", true, false );
+    $this->addMenuEntry( "/menu/controlCenter/manageIntegrationPlugins", "mtexportPluginSettings", "admin.php?op=mtexportPluginSettings", "", true, false );
+  }
+
+  function register()
+  {
+    $config =& Config::getConfig();
+
+    $this->cacheFolder = $config->getValue('temp_folder');
+    $this->cacheFolder = $this->cacheFolder.'/mtexport/'.$this->blogInfo->getId();
+    if( !File::exists( $this->cacheFolder )) {
+      File::createDir( $this->cacheFolder, 0755 );
+    }
+
+    $blogSettings = $this->blogInfo->getSettings();
+  }
+
+
+  function getPluginConfigurationKeys()
+  {
+    return (Array()
+            );
+  }
+
+}
+?>

Added: plugins/branches/lifetype-1.2/mtexport/readme.txt
===================================================================
--- plugins/branches/lifetype-1.2/mtexport/readme.txt	                        (rev 0)
+++ plugins/branches/lifetype-1.2/mtexport/readme.txt	2009-05-04 09:49:16 UTC (rev 6880)
@@ -0,0 +1,22 @@
+Plugin: Movable Type Export
+Author: paul at westbrooks.org
+Release Date: 20090504
+Version: 20070504
+
+
+Exports a LifeType blog to a MovableType Import Format file.  This can be
+useful when transitioning to WordPress blog software 
+
+When installed, this plugin is accessible in the Integration Management
+section of the LifeType blog's Control Panel
+
+When the Export button is clicked, a mt-export.txt file is saved in the
+tmp/mtexport/<blogid> directory of your LifeType's install location.
+
+
+TO DO:
+1) Export trackbacks
+2) Configuration on what data should be exported
+3) Link to the mt-export.txt file, or automatically make the browser
+   download the file
+

Added: plugins/branches/lifetype-1.2/mtexport/templates/pluginsettings.template
===================================================================
--- plugins/branches/lifetype-1.2/mtexport/templates/pluginsettings.template	                        (rev 0)
+++ plugins/branches/lifetype-1.2/mtexport/templates/pluginsettings.template	2009-05-04 09:49:16 UTC (rev 6880)
@@ -0,0 +1,20 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=mtexportPluginSettings title=$locale->tr("mtexport_plugin")}
+<form name="mtexportPluginSettings" method="post">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("mtexport_plugin")}</legend>  
+  {include file="$admintemplatepath/successmessage.template"}
+  {include file="$admintemplatepath/errormessage.template"}   
+  <div class="formHelp">
+   {$locale->tr("mtexport_description")}
+  </div>
+
+ </fieldset>  
+
+ <div class="buttons">
+  <input type="hidden" name="op" value="mtexportPluginExportBlog" />
+  <input type="submit" name="{$locale->tr("mtexport_export_blog")}" value="{$locale->tr("mtexport_export_blog")}" />
+ </div>
+</form>
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}



More information about the pLog-svn mailing list