From: garvinhicking Date: Mon, 12 Dec 2005 08:50:17 +0000 (+0000) Subject: backport X-Git-Tag: 0.9.1~11 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0335a91b4fb1ce43c7ef6e06fbcdfbc28b50a5b6;p=s9y.git backport --- diff --git a/include/admin/import.inc.php b/include/admin/import.inc.php index 731451c..f03915d 100644 --- a/include/admin/import.inc.php +++ b/include/admin/import.inc.php @@ -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 : */ -?> diff --git a/include/admin/importers/movabletype.inc.php b/include/admin/importers/movabletype.inc.php index 712968b..5572bfe 100644 --- a/include/admin/importers/movabletype.inc.php +++ b/include/admin/importers/movabletype.inc.php @@ -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 . "
\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 '
' . $r . '
'; } else { diff --git a/include/functions.inc.php b/include/functions.inc.php index e739a4e..722451c 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -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)); }