📄 movabletype.inc.php
字号:
$comment['url'] = $data; break; case 'IP': $comment['ip'] = $data; break; case 'AUTHOR': case 'BLOG NAME': $comment['author'] = $data; break; case 'DATE': $comment['timestamp'] = $this->toTime($data); break; case 'REPLY': case 'TITLE': break; default: $comment['body'] .= $data; } } $this->debug("S9Y_ENTRY: " . print_r($comment, true)); return $comment; } function import() { global $serendipity; $force = ($this->data['mt_force'] == 'true'); if ($this->data['autodiscovery'] == 'false') { $serendipity['noautodiscovery'] = 1; } // Rewritten to parse the file line by line. Can save quite some // memory on large blogs //$contents = file_get_contents($_FILES['serendipity']['tmp_name']['import']['mt_dat']); $this->categories = serendipity_fetchCategories(); $tasks = array(); $entries = array(); if (empty($_FILES['serendipity']['tmp_name']['import']['mt_dat'])) { $fh = fopen('/tmp/mt.dat', 'r'); } else { $fh = fopen($_FILES['serendipity']['tmp_name']['import']['mt_dat'], 'r'); } $entry = array(); $el = ""; $c_el = ""; $skip = false; $is_comment = false; $is_trackback = false; $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; } if ($is_comment || $is_trackback) { $this->debug("COMMENT/TRACKBACK mode is active."); if (preg_match('/^--------/', $line)) { $this->debug("Next full section requested."); $is_comment = $is_trackback = false; } elseif (preg_match('/^-----/', $line)) { $this->debug("Next partial section requested."); if ($is_trackback) { $this->debug("Parsing trackback."); $entry['s9y_comments'][] = $this->doCommentWork($comment, $tasks, 'TRACKBACK'); } elseif ($is_comment) { $this->debug("Parsing comment."); $entry['s9y_comments'][] = $this->doCommentWork($comment, $tasks, 'NORMAL'); } $el = $c_el = ""; } } if ($skip && (!preg_match('/^--------/', $line))) { $this->debug("No next section match, and skip is activated. Skipping '$line'"); continue; } if (preg_match('/^--------/', $line)) { // We found the end marker of the current entry. Add to entries-Array $this->debug("End marker found. Parsing full entry."); $entries[] = $this->doEntryWork($entry, $tasks); $entry = array(); $el = ""; $c_el = ""; $skip = false; $is_comment = false; $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"); $tline = trim($line); while (($is_comment || $is_trackback) && empty($tline)) { $line = $this->decode(fgets($fh, 8192)); $tline = trim($line); $this->debug("Continuing inspecting next line: $line"); } if (preg_match('/^--------/', $line)) { $this->debug('Next line is new element. End marker found. Parsing full entry.'); $entries[] = $this->doEntryWork($entry, $tasks); $entry = array(); $el = ""; $c_el = ""; $skip = false; $is_comment = false; $is_trackback = false; } elseif (preg_match('/^([A-Z\s]+):/', $line, $matches)) { $this->debug("Match result: $matches[1]"); if ($matches[1] == 'COMMENT') { $this->debug("Marking COMMENT."); $is_comment = true; $is_trackback = false; $comment = array(); $skip = false; } elseif ($matches[1] == 'PING') { $this->debug("Marking TRACKBACK"); $is_comment = false; $is_trackback = true; $comment = array(); $skip = false; } $this->debug("Setting EL to {$matches[1]}"); $el = $matches[1]; $c_el = ""; } else { $this->debug("Could not parse next line. Keeping it for next cycle."); $nofetch = true; } } else { $this->debug("Resetting EL to an empty string"); $el = $c_el = ""; } } elseif (empty($el)) { $this->debug("EL is empty. Line is '$line'"); $content = ""; if (preg_match('/^([A-Z\s]+):\s+(.*)$/s', $line, $matches)) { $this->debug("Section match {$matches[1]} found, input: {$matches[2]}"); $c_el = $matches[1]; $content = $matches[2]; } elseif (!empty($c_el)) { $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"); $comment[$c_el] = $content; } else { $this->debug("Appending to entry: $line"); if (isset($entry[$c_el])) { $entry[$c_el] .= "\0" . $content; } else { $entry[$c_el] = $content; } } } } elseif ($is_comment || $is_trackback) { $this->debug("Appending Line in current Element $el to comments: $line"); $comment[$el] .= $line; } else { $this->debug("Appending Line in current Element $el to entries: $line"); $entry[$el] .= $line; } } fclose($fh); if ( !sizeof($tasks) || $force == true ) { serendipity_db_begin_transaction(); foreach ($entries as $entry) { #echo '<pre>' . printR_($entry, true) . '</pre><br />'; #continue; if (empty($entry['authorid'])) { $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 { $this->debug('Saved entry ' . $r . ' (' . $entry['title'] . ')'); $entry['id'] = $r; foreach((array)$comments AS $comment) { $comment['entry_id'] = $r; if ($rc = serendipity_db_insert('comments', $comment)) { $cid = serendipity_db_insert_id('comments', 'id'); serendipity_approveComment($cid, $entry['id'], true); } else { echo '<div class="serendipityAdminMsgError">' . $rc . '</div>'; } } // Let the plugins do some additional stuff. Here it's used with // event_entryproperties in mind to setup the nl2br-stuff serendipity_plugin_api::hook_event('backend_import_entry', $entry, $entryprops); } } serendipity_db_end_transaction(true); return true; } else { return '<ul><li>'.implode('</li><li>', array_unique($tasks)).'</li></ul>'; } }}return 'Serendipity_Import_MovableType';?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -