/* 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();
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') {
}
}
+/**
+ * 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)) {
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();
}
}
+/**
+ * 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;
$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;
}
}
/* vim: set sts=4 ts=4 expandtab : */
-?>
function debug($string) {
static $debug = null;
static $c = 0;
-
+
if ($debug === null) {
if ($this->data['debug'] == 'true') {
$debug = true;
$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')){
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) {
$parsed_entry['s9y_body'] .= $line . "\n";
}
}
-
+
foreach($parsed_entry as $name => $data){
$data = trim($data);
$name = trim($name);
$comment['timestamp'] = time();
}
break;
-
+
+ case 'REPLY':
case 'TITLE':
break;
// memory on large blogs
//$contents = file_get_contents($_FILES['serendipity']['tmp_name']['import']['mt_dat']);
- $authors = array();
$this->categories = serendipity_fetchCategories();
$tasks = array();
$fh = fopen($_FILES['serendipity']['tmp_name']['import']['mt_dat'], 'r');
}
- $n = 0;
-
$entry = array();
$el = "";
$c_el = "";
$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;
}
$el = $c_el = "";
}
}
-
+
if ($skip && (!preg_match('/^--------/', $line))) {
$this->debug("No next section match, and skip is activated. Skipping '$line'");
continue;
$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");
$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");
$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 {
$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));
}