]> git.mjollnir.org Git - s9y.git/commitdiff
backport
authorgarvinhicking <garvinhicking>
Mon, 12 Dec 2005 08:50:17 +0000 (08:50 +0000)
committergarvinhicking <garvinhicking>
Mon, 12 Dec 2005 08:50:17 +0000 (08:50 +0000)
include/admin/import.inc.php
include/admin/importers/movabletype.inc.php
include/functions.inc.php

index 731451c9e1fae6870078527f754ab36b12233586..f03915d77e2eabf0a5b25b444e6ec52bd4d72cdb 100644 (file)
@@ -13,12 +13,29 @@ if (!serendipity_checkPermission('adminImport')) {
 /* This won't do anything if safe-mode is ON, but let's try anyway since importing could take a while */
 @set_time_limit(0);
 
-/* For later use */
+/* Class construct. Each importer plugin must extend this class. */
 class Serendipity_Import {
     var $trans_table = '';
 
-    function getImportNotes() { return ""; }
+/**
+ * Return textual notes of an importer plugin
+ *
+ * If an importer plugin needs to show any notes on the userinterface, those can be returned in this method.
+ *
+ * @access public
+ * @return string  HTML-code of a interface/user hint
+ */
+    function getImportNotes() { 
+        return ""; 
+    }
 
+/**
+ * Get a list of available charsets the user can choose from. Depends on current language of the blog.
+ *
+ * @access public
+ * @param  boolean   If set to true, returns the option "UTF-8" as first select choice, which is then preselected. If false, the current language of the blog will be the default.
+ * @return array     Array of available charsets to choose from
+ */
     function getCharsets($utf8_default = true) {
         $charsets = array();
         
@@ -41,6 +58,13 @@ class Serendipity_Import {
         return $charsets;
     }
 
+/**
+ * Decodes/Transcodes a string according to the selected charset, and the charset of the blog
+ *
+ * @access public
+ * @param  string   input string to convert
+ * @return string   converted string
+ */
     function &decode($string) {
         // xml_parser_* functions to recoding from ISO-8859-1/UTF-8
         if (LANG_CHARSET == 'ISO-8859-1' || LANG_CHARSET == 'UTF-8') {
@@ -70,10 +94,27 @@ class Serendipity_Import {
         }
     }
 
+/**
+ * Decode/Transcode a string with the indicated translation table (member property). Useful for transcoding HTML entities to native characters.
+ *
+ * @access public
+ * @param  string   input string
+ * @return string   output string
+ */
     function strtr($data) {
         return strtr($this->decode($data), $this->trans_table);
     }
 
+/**
+ * Decode/Transcode an array of strings.
+ *
+ * LONG
+ *
+ * @access public
+ * @see $this->strtr()
+ * @param   array   input array
+ * @return  array   output array
+ */
     function strtrRecursive($data) {
         foreach ($data as $key => $val) {
             if (is_array($val)) {
@@ -86,6 +127,15 @@ class Serendipity_Import {
         return $data;
     }
     
+/**
+ * Get the transcoding table, depending on whether it was enabled for the instance of the importer plugin
+ *
+ * The member property $this->trans_table will be filled with the output of this function
+ *
+ * @access public
+ * @see    $this->strtr()
+ * @return null
+ */
     function getTransTable() {
         if (!serendipity_db_bool($this->data['use_strtr'])) {
             $this->trans_table = array();
@@ -101,6 +151,14 @@ class Serendipity_Import {
         }
     }
 
+/**
+ * Execute a DB query on the source database of the import, instead of a DB query on the target database
+ *
+ * @access public
+ * @param  string       SQL Query
+ * @param  ressource    DB connection resource
+ * @return ressource    SQL response
+ */
     function &nativeQuery($query, $db = false) {
         global $serendipity;
 
@@ -172,7 +230,7 @@ if (isset($serendipity['GET']['importFrom']) && serendipity_checkFormToken()) {
     $dir        = opendir($importpath);
     $list       = array();
     while (($file = readdir($dir)) !== false ) {
-        if (!is_file($importpath . $file)) {
+        if (!is_file($importpath . $file) || !preg_match('@.php$@', $file)) {
             continue;
         }
 
@@ -206,4 +264,3 @@ if (isset($serendipity['GET']['importFrom']) && serendipity_checkFormToken()) {
 }
 
 /* vim: set sts=4 ts=4 expandtab : */
-?>
index 712968bda7c3a608375314e45006c6fd5c9e08d1..5572bfed1330929e214881964a9600dd5b9b2e45 100644 (file)
@@ -56,7 +56,7 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
     function debug($string) {
         static $debug = null;
         static $c = 0;
-        
+
         if ($debug === null) {
             if ($this->data['debug'] == 'true') {
                 $debug = true;
@@ -64,13 +64,13 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
                 $debug = false;
             }
         }
-        
+
         if ($debug) {
             $c++;
             echo '#' . $c . ' [' . date('d.m.Y H:i.s') . '] ' . $string . "<br />\n";
         }
     }
-    
+
     function getImportNotes(){
         $notes = array();
         if (!class_exists('serendipity_event_nl2br')){
@@ -94,10 +94,11 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
     function doEntryWork(&$mt_entry, &$tasks){
         global $serendipity;
 
+        $authors = array();
         $entry = array();
         $entry['categories'] = array();
         $entryprops = array();
-        
+
         $this->debug("doEntryWork: " . print_r($mt_entry, true));
 
         foreach($mt_entry as $name => $data) {
@@ -198,7 +199,7 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
                 $parsed_entry['s9y_body'] .= $line . "\n";
             }
         }
-        
+
         foreach($parsed_entry as $name => $data){
             $data = trim($data);
             $name = trim($name);
@@ -227,7 +228,8 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
                         $comment['timestamp'] = time();
                     }
                     break;
-                    
+
+                case 'REPLY':
                 case 'TITLE':
                     break;
 
@@ -253,7 +255,6 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
         // memory on large blogs
         //$contents   = file_get_contents($_FILES['serendipity']['tmp_name']['import']['mt_dat']);
 
-        $authors    = array();
         $this->categories = serendipity_fetchCategories();
         $tasks      = array();
 
@@ -265,8 +266,6 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
             $fh = fopen($_FILES['serendipity']['tmp_name']['import']['mt_dat'], 'r');
         }
 
-        $n = 0;
-
         $entry        = array();
         $el           = "";
         $c_el         = "";
@@ -276,8 +275,10 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
         $nofetch      = false;
         while (!feof($fh)) {
             if ($nofetch === false) {
+                $this->debug('Next line');
                 $line = $this->decode(fgets($fh, 8192));
             } else {
+                $this->debug('NO Next line');
                 // Keep line from previous run.
                 $nofetch = false;
             }
@@ -299,7 +300,7 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
                     $el = $c_el = "";
                 }
             }
-            
+
             if ($skip && (!preg_match('/^--------/', $line))) {
                 $this->debug("No next section match, and skip is activated. Skipping '$line'");
                 continue;
@@ -317,6 +318,7 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
                 $is_trackback = false;
             } elseif (preg_match('/^-----/', $line)) {
                 $this->debug("New section match. Current EL: $el");
+                unset($el); # DEBUG!
                 if (empty($el)) {
                     $line = $this->decode(fgets($fh, 8192));
                     $this->debug("Inspecting next line: $line");
@@ -364,7 +366,7 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
                     $this->debug("Still in subsection of previous run: $c_el.");
                     $content = trim($line);
                 }
-                
+
                 if (!empty($content)) {
                     if ($is_comment || $is_trackback) {
                         $this->debug("Appending to comments: $line");
@@ -391,11 +393,20 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
                     $entry['authorid'] = $serendipity['authorid'];
                     $entry['author']   = $serendipity['realname'];
                 }
+                
+                if (!isset($entry['isdraft'])) {
+                    $entry['isdraft'] = 'false';
+                }
+
+                if (!isset($entry['allow_comments'])) {
+                    $entry['allow_comments'] = 'true';
+                }
+
                 $comments   = $entry['s9y_comments'];
                 $entryprops = $entry['props'];
                 unset($entry['props']);
                 unset($entry['s9y_comments']);
-                
+
                 if ( !is_int($r = serendipity_updertEntry($entry)) ) {
                     echo '<div class="serendipityAdminMsgError">' . $r . '</div>';
                 } else {
index e739a4eccd5c9f9a10c8d59b68cd6e59c5e201ec..722451c287a7b98147c44bcc018fdf5c2c700bf8 100644 (file)
@@ -297,7 +297,7 @@ function serendipity_sendMail($to, $subject, $message, $fromMail, $headers = NUL
     $headers[] = 'Message-ID: <'. md5(microtime() . uniqid(time())) .'@'. $_SERVER['HTTP_HOST'] .'>';
     $headers[] = 'MIME-Version: 1.0';
     $headers[] = 'Precedence: bulk';
-    $headers[] = 'Content-Type: text/plain; charset="' . LANG_CHARSET .'"';
+    $headers[] = 'Content-Type: text/plain; charset=' . LANG_CHARSET;
 
     return mail($to, $subject, $message, implode("\n", $headers));
 }