📄 movabletype.inc.php
字号:
<?php # $Id: movabletype.inc.php 1028 2006-03-27 11:17:11Z garvinhicking $# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)# All rights reserved. See LICENSE file for licensing details/***************************************************************** * MovableType Importer, by Evan Nemerson * *****************************************************************/switch ($serendipity['lang']) { case 'de': @define('IMPORTER_MT_WARN_PLUGIN', 'Bitte installieren Sie das Plugin "%s"'); @define('IMPORTER_MT_NOTE', 'Falls Sie weiter machen, ohne die Plugins zu installieren, werden m鰃licherweise Zeilenumbr點he falsch importiert (verdoppelt oder entfernt)'); break; case 'en': default: @define('IMPORTER_MT_WARN_PLUGIN', 'Please install the plugin "%s"'); @define('IMPORTER_MT_NOTE', 'If you continue without installing those plugins, line breaks may be incorrectly imported (doubled or removed)'); break;}class Serendipity_Import_MovableType extends Serendipity_Import { var $info = array('software' => 'MovableType'); var $data = array(); var $inputFields = array(); function Serendipity_Import_MovableType($data) { $this->data = $data; $this->inputFields = array(array('text' => MT_DATA_FILE, 'type' => 'file', 'name' => 'mt_dat'), array('text' => FORCE, 'type' => 'bool', 'name' => 'mt_force', 'default' => 'true'), array('text' => CHARSET, 'type' => 'list', 'name' => 'charset', 'value' => 'UTF-8', 'default' => $this->getCharsets(true)), array('text' => ACTIVATE_AUTODISCOVERY, 'type' => 'bool', 'name' => 'autodiscovery', 'default' => 'false'), array('text' => 'Debugging', 'type' => 'bool', 'name' => 'debug', 'default' => 'false') ); } function debug($string) { static $debug = null; static $c = 0; if ($debug === null) { if ($this->data['debug'] == 'true') { $debug = true; } else { $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')){ $notes[] = sprintf(IMPORTER_MT_WARN_PLUGIN, 'serendipity_event_nl2br'); } if (!class_exists('serendipity_event_entryproperties')){ $notes[] = sprintf(IMPORTER_MT_WARN_PLUGIN, 'serendipity_event_entryproperties'); } if (count($notes) > 0){ return '<ul><li>'.implode('</li><li>', $notes).'</li></ul>'.IMPORTER_MT_NOTE; } } function validateData() { return sizeof($this->data); } function getInputFields() { return $this->inputFields; } function toTime($string) { $ts = strtotime($string); $this->debug('Calling strtotime(' . $string . ') = ' . $ts); if ($ts <= 1) { // Match strings like: "11/16/2005 00:14:53 PM" if (preg_match('@([01][0-9])/([0-3][0-9])/([0-9]{4}) ([0-2][0-9]):([0-5][0-9]):([0-5][0-9]) (P|A|F|E)M@i', $string, $match)) { if ($match[7] == 'P' || $match[7] == 'E') { // Post mediam, add 12 hours. $match[4] = $match[4] + 12; } $ts = mktime($match[4], $match[5], $match[6], $match[1], $match[2], $match[3]); $this->debug('Matched string date format: ' . $ts); } } if ($ts <= 1) { $ts = time(); } return $ts; } 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) { $name = trim($name); if (is_string($data)) { $data = trim($data); } $this->debug($name . ': "' . print_r($data, true) . '"'); switch($name) { case 's9y_comments': $entry['s9y_comments'] = $data; break; case 'AUTHOR': if ( !isset($authors[$data]) ) { $au_inf = serendipity_fetchAuthor($data); if ( !is_array($au_inf) ) { $tasks[] = sprintf(CREATE_AUTHOR, htmlspecialchars($data)); $tasks[] = 'Input array is: ' . print_r($data, true) . '<br />Return is: ' . print_r($au_inf, true) . '<br />'; $au_inf = serendipity_fetchAuthor($serendipity['authorid']); } $authors[$data] = $au_inf[0]; } $entry['authorid'] = $authors[$data]['authorid']; $entry['author'] = $authors[$data]['username']; break; case 'TITLE': $entry['title'] = $data; break; case 'STATUS': $entry['isdraft'] = ($data == 'Publish') ? 'false' : 'true'; break; case 'ALLOW COMMENTS': $entry['allow_comments'] = ($data == '1') ? 'true' : 'false'; break; case 'DATE': $entry['timestamp'] = $this->totime($data); break; case 's9y_body': case 'BODY': $entry['body'] = $data; break; case 's9y_extended': case 'EXTENDED BODY': $entry['extended'] = $data; break; case 'CONVERT BREAKS': $entryprops['nl2br'] = ($data == '1') ? true : false; break; case 'PRIMARY CATEGORY': case 'CATEGORY': $categories = explode("\0", $data); #echo '<pre>' . print_r($this->categories, true) . '</pre>'; foreach($categories AS $data) { $data = trim($data); $cat_found = false; if (is_array($this->categories)) { for ( $y=0 ; $y<sizeof($this->categories) ; $y++ ) { echo '"' . $this->categories[$y]['category_name'] . '" == "' . $data . '"<br />'; if ( $this->categories[$y]['category_name'] == $data ) { $cat_found = true; break; } } if ($cat_found) { if (!in_array($this->categories[$y]['categoryid'], $entry['categories']) ) { //$entries[$n]['categories'][] = $categories[$y]['categoryid']; $entry['categories'][] = $this->categories[$y]['categoryid']; } } else { $tasks[] = sprintf(CREATE_CATEGORY, htmlspecialchars($data)); } } } break; } } $entry['props'] = $entryprops; return $entry; } function doCommentWork(&$mt_entry, &$tasks, $type = 'NORMAL'){ $comment = array( 'parent_id' => 0, 'status' => 'approved', 'subscribed' => 'false', 'type' => $type, 'body' => '' ); $this->debug("MT_ENTRY: " . print_r($mt_entry, true)); $parsed_entry = array(); $unparsed_entry = explode("\n", $mt_entry[$type == 'NORMAL' ? 'COMMENT' : 'PING']); foreach($unparsed_entry AS $line) { if (preg_match('/^([A-Z\s]+):\s+(.*)$/', $line, $match)) { $parsed_entry[$match[1]] = $match[2]; } else { $parsed_entry['s9y_body'] .= $line . "\n"; } } foreach($parsed_entry as $name => $data){ $data = trim($data); $name = trim($name); switch($name) { case 'EMAIL': $comment['email'] = $data; break; case 'URL':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -