define('__TYPECHO_ROOT_DIR__', dirname(__FILE__)); /** 定义插件目录(相对路径) */ define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins'); /** 定义模板目录(相对路径) */ define('__TYPECHO_THEME_DIR__', '/usr/themes'); /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/admin/'); /** 设置包含路径 */ @set_include_path(get_include_path() . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__); /** 载入API支持 */ require_once 'Typecho/Common.php'; /** 载入Response支持 */ require_once 'Typecho/Response.php'; /** 载入配置支持 */ require_once 'Typecho/Config.php'; /** 载入异常支持 */ require_once 'Typecho/Exception.php'; /** 载入插件支持 */ require_once 'Typecho/Plugin.php'; /** 载入国际化支持 */ require_once 'Typecho/I18n.php'; /** 载入数据库支持 */ require_once 'Typecho/Db.php'; /** 载入路由器支持 */ require_once 'Typecho/Router.php'; /** 程序初始化 */ Typecho_Common::init(); /** 定义数据库参数 */ $db = new Typecho_Db('Mysql', 'typecho_'); $db->addServer(array('host' => 'localhost', 'user' => 'root', 'password' => 'ad_pwd_min', 'charset' => 'utf8', 'port' => '3306', 'database' => 'winecat_typecho'), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__)); /** 定义插件目录(相对路径) */ define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins'); /** 定义模板目录(相对路径) */ define('__TYPECHO_THEME_DIR__', '/usr/themes'); /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/admin/'); /** 设置包含路径 */ @set_include_path(get_include_path() . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__); /** 载入API支持 */ require_once 'Typecho/Common.php'; /** 载入Response支持 */ require_once 'Typecho/Response.php'; /** 载入配置支持 */ require_once 'Typecho/Config.php'; /** 载入异常支持 */ require_once 'Typecho/Exception.php'; /** 载入插件支持 */ require_once 'Typecho/Plugin.php'; /** 载入国际化支持 */ require_once 'Typecho/I18n.php'; /** 载入数据库支持 */ require_once 'Typecho/Db.php'; /** 载入路由器支持 */ require_once 'Typecho/Router.php'; /** 程序初始化 */ Typecho_Common::init(); /** 定义数据库参数 */ $db = new Typecho_Db('Pdo_Mysql', 'typecho_'); $db->addServer(array('host' => 'localhost', 'user' => 'root', 'password' => 'DXjIR7^BDIDj%pkk', 'charset' => 'utf8', 'port' => '3306', 'database' => 'typecho'), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);
public function doImport() { $options = $this->widget('Widget_Options'); $dbConfig = $options->plugin('WordpressToTypecho'); /** 初始化一个db */ if (Typecho_Db_Adapter_Mysql::isAvailable()) { $db = new Typecho_Db('Mysql', $dbConfig->prefix); } else { $db = new Typecho_Db('Pdo_Mysql', $dbConfig->prefix); } /** 只读即可 */ $db->addServer(array('host' => $dbConfig->host, 'user' => $dbConfig->user, 'password' => $dbConfig->password, 'charset' => 'utf8', 'port' => $dbConfig->port, 'database' => $dbConfig->database), Typecho_Db::READ); /** 删除当前内容 */ $masterDb = Typecho_Db::get(); $this->widget('Widget_Abstract_Contents')->to($contents)->delete($masterDb->sql()->where('1 = 1')); $this->widget('Widget_Abstract_Comments')->to($comments)->delete($masterDb->sql()->where('1 = 1')); $this->widget('Widget_Abstract_Metas')->to($metas)->delete($masterDb->sql()->where('1 = 1')); $this->widget('Widget_Contents_Post_Edit')->to($edit); $masterDb->query($masterDb->delete('table.relationships')->where('1 = 1')); $userId = $this->widget('Widget_User')->uid; /** 获取时区偏移 */ $gmtOffset = idate('Z'); /** 转换全局变量 */ /** $rows = $db->fetchAll($db->select()->from('table.statics')); $static = array(); foreach ($rows as $row) { $static[$row['static_name']] = $row['static_value']; }*/ /** 转换文件 */ /**$files = $db->fetchAll($db->select()->from('table.files')); if (!is_dir(__TYPECHO_ROOT_DIR__ . '/usr/uploads/')) { mkdir(__TYPECHO_ROOT_DIR__ . '/usr/uploads/', 0766); } $pattern = array(); $replace = array(); foreach ($files as $file) { $path = __TYPECHO_ROOT_DIR__ . '/data/upload/' . substr($file['file_guid'], 0, 2) . '/' . substr($file['file_guid'], 2, 2) . '/' . $file['file_guid']; if (is_file($path)) { $file['file_time'] = empty($file['file_time']) ? $options->gmtTime : $file['file_time']; $year = idate('Y', $file['file_time']); $month = idate('m', $file['file_time']); $day = idate('d', $file['file_time']); if (!is_dir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}")) { mkdir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}", 0766); } if (!is_dir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}/{$month}")) { mkdir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}/{$month}", 0766); } if (!is_dir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}/{$month}/{$day}")) { mkdir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}/{$month}/{$day}", 0766); } $parts = explode('.', $file['file_name']); $ext = array_pop($parts); copy($path, __TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}/{$month}/{$day}/{$file['file_id']}.{$ext}"); $new = Typecho_Common::url("/usr/uploads/{$year}/{$month}/{$day}/{$file['file_id']}.{$ext}", $options->siteUrl); $old = Typecho_Common::url("/res/{$file['file_id']}/{$file['file_name']}", $static['siteurl'] . '/index.php'); $pattern[] = '/' . str_replace('\/index\.php', '(\/index\.php)?', preg_quote($old, '/')) . '/is'; $replace[] = $new; } } */ /** 转换评论 */ $i = 1; while (true) { $result = $db->query($db->select()->from('table.comments')->order('comment_ID', Typecho_Db::SORT_ASC)->page($i, 100)); $j = 0; while ($row = $db->fetchRow($result)) { $status = $row['comment_approved']; if ('spam' == $row['comment_approved']) { $status = 'spam'; } else { if ('0' == $row['comment_approved']) { $status = 'waiting'; } else { $status = 'approved'; } } $row['comment_content'] = preg_replace(array("/\\s*<p>/is", "/\\s*<\\/p>\\s*/is", "/\\s*<br\\s*\\/>\\s*/is", "/\\s*<(div|blockquote|pre|table|ol|ul)>/is", "/<\\/(div|blockquote|pre|table|ol|ul)>\\s*/is"), array('', "\n\n", "\n", "\n\n<\\1>", "</\\1>\n\n"), $row['comment_content']); $comments->insert(array('coid' => $row['comment_ID'], 'cid' => $row['comment_post_ID'], 'created' => strtotime($row['comment_date_gmt']) + $gmtOffset, 'author' => $row['comment_author'], 'authorId' => $row['user_id'], 'ownerId' => 1, 'mail' => $row['comment_author_email'], 'url' => $row['comment_author_url'], 'ip' => $row['comment_author_IP'], 'agent' => $row['comment_agent'], 'text' => $row['comment_content'], 'type' => empty($row['comment_type']) ? 'comment' : $row['comment_type'], 'status' => $status, 'parent' => $row['comment_parent'])); $j++; unset($row); } if ($j < 100) { break; } $i++; unset($result); } /** 转换Wordpress的term_taxonomy表 */ $terms = $db->fetchAll($db->select()->from('table.term_taxonomy')->join('table.terms', 'table.term_taxonomy.term_id = table.terms.term_id')->where('taxonomy = ? OR taxonomy = ?', 'category', 'post_tag')); foreach ($terms as $term) { $metas->insert(array('mid' => $term['term_taxonomy_id'], 'name' => $term['name'], 'slug' => 'post_tag' == $term['taxonomy'] ? Typecho_Common::slugName($term['name']) : $term['slug'], 'type' => 'post_tag' == $term['taxonomy'] ? 'tag' : 'category', 'description' => $term['description'], 'count' => $term['count'])); /** 转换关系表 */ $relationships = $db->fetchAll($db->select()->from('table.term_relationships')->where('term_taxonomy_id = ?', $term['term_taxonomy_id'])); foreach ($relationships as $relationship) { $masterDb->query($masterDb->insert('table.relationships')->rows(array('cid' => $relationship['object_id'], 'mid' => $relationship['term_taxonomy_id']))); } } /** 转换内容 */ $i = 1; while (true) { $result = $db->query($db->select()->from('table.posts')->where('post_type = ? OR post_type = ?', 'post', 'page')->order('ID', Typecho_Db::SORT_ASC)->page($i, 100)); $j = 0; while ($row = $db->fetchRow($result)) { $contents->insert(array('cid' => $row['ID'], 'title' => $row['post_title'], 'slug' => Typecho_Common::slugName(urldecode($row['post_name']), $row['ID'], 128), 'created' => strtotime($row['post_date_gmt']) + $gmtOffset, 'modified' => strtotime($row['post_modified_gmt']) + $gmtOffset, 'text' => $row['post_content'], 'order' => $row['menu_order'], 'authorId' => $row['post_author'], 'template' => NULL, 'type' => 'page' == $row['post_type'] ? 'page' : 'post', 'status' => 'publish' == $row['post_status'] ? 'publish' : 'draft', 'password' => $row['post_password'], 'commentsNum' => $row['comment_count'], 'allowComment' => 'open' == $row['comment_status'] ? '1' : '0', 'allowFeed' => '1', 'allowPing' => 'open' == $row['ping_status'] ? '1' : '0')); $j++; unset($row); } if ($j < 100) { break; } $i++; unset($result); } $this->widget('Widget_Notice')->set(_t("数据已经转换完成"), NULL, 'success'); $this->response->goBack(); }
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__)); /** 定义插件目录(相对路径) */ define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins'); /** 定义模板目录(相对路径) */ define('__TYPECHO_THEME_DIR__', '/usr/themes'); /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/admin/'); /** 设置包含路径 */ @set_include_path(get_include_path() . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__); /** 载入API支持 */ require_once 'Typecho/Common.php'; /** 载入Response支持 */ require_once 'Typecho/Response.php'; /** 载入配置支持 */ require_once 'Typecho/Config.php'; /** 载入异常支持 */ require_once 'Typecho/Exception.php'; /** 载入插件支持 */ require_once 'Typecho/Plugin.php'; /** 载入国际化支持 */ require_once 'Typecho/I18n.php'; /** 载入数据库支持 */ require_once 'Typecho/Db.php'; /** 载入路由器支持 */ require_once 'Typecho/Router.php'; /** 程序初始化 */ Typecho_Common::init(); /** 定义数据库参数 */ $db = new Typecho_Db('Mysql', 'mcblog_'); $db->addServer(array('host' => 'localhost', 'user' => 'mcblog', 'password' => 'mcblog123***', 'charset' => 'utf8', 'port' => '3306', 'database' => 'mcblog'), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__)); /** 定义插件目录(相对路径) */ define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins'); /** 定义模板目录(相对路径) */ define('__TYPECHO_THEME_DIR__', '/usr/themes'); /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/admin/'); /** 设置包含路径 */ @set_include_path(get_include_path() . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__); /** 载入API支持 */ require_once 'Typecho/Common.php'; /** 载入Response支持 */ require_once 'Typecho/Response.php'; /** 载入配置支持 */ require_once 'Typecho/Config.php'; /** 载入异常支持 */ require_once 'Typecho/Exception.php'; /** 载入插件支持 */ require_once 'Typecho/Plugin.php'; /** 载入国际化支持 */ require_once 'Typecho/I18n.php'; /** 载入数据库支持 */ require_once 'Typecho/Db.php'; /** 载入路由器支持 */ require_once 'Typecho/Router.php'; /** 程序初始化 */ Typecho_Common::init(); /** 定义数据库参数 */ $db = new Typecho_Db('Mysql', 'typecho_'); $db->addServer(array('host' => 'localhost', 'user' => 'root', 'charset' => 'utf8', 'port' => '3306', 'database' => 'development'), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);
<?php if (!defined('__TYPECHO_ROOT_DIR__')) { exit; } $success = true; try { $dbConfig = $options->plugin('MagikeToTypecho'); /** 初始化一个db */ if (Typecho_Db_Adapter_Mysql::isAvailable()) { $magikeDb = new Typecho_Db('Mysql', $dbConfig->prefix); } else { $magikeDb = new Typecho_Db('Pdo_Mysql', $dbConfig->prefix); } /** 只读即可 */ $magikeDb->addServer(array('host' => $dbConfig->host, 'user' => $dbConfig->user, 'password' => $dbConfig->password, 'charset' => 'utf8', 'port' => $dbConfig->port, 'database' => $dbConfig->database), Typecho_Db::READ); $rows = $magikeDb->fetchAll($magikeDb->select()->from('table.statics')); $static = array(); foreach ($rows as $row) { $static[$row['static_name']] = $row['static_value']; } } catch (Typecho_Db_Exception $e) { $success = false; } include 'header.php'; include 'menu.php'; ?> <div class="main"> <div class="body body-950"> <?php include 'page-title.php';
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__)); /** 定义插件目录(相对路径) */ define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins'); /** 定义模板目录(相对路径) */ define('__TYPECHO_THEME_DIR__', '/usr/themes'); /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/admin/'); /** 设置包含路径 */ @set_include_path(get_include_path() . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__); /** 载入API支持 */ require_once 'Typecho/Common.php'; /** 载入Response支持 */ require_once 'Typecho/Response.php'; /** 载入配置支持 */ require_once 'Typecho/Config.php'; /** 载入异常支持 */ require_once 'Typecho/Exception.php'; /** 载入插件支持 */ require_once 'Typecho/Plugin.php'; /** 载入国际化支持 */ require_once 'Typecho/I18n.php'; /** 载入数据库支持 */ require_once 'Typecho/Db.php'; /** 载入路由器支持 */ require_once 'Typecho/Router.php'; /** 程序初始化 */ Typecho_Common::init(); /** 定义数据库参数 */ $db = new Typecho_Db('Mysql', 'typecho_'); $db->addServer(array('host' => 'localhost', 'user' => 'adminzfiHCDG', 'password' => 'xs73pyEavu9R', 'charset' => 'utf8', 'port' => '3306', 'database' => 'typecho'), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);
$_dbConfig = array_filter($_dbConfig); $dbConfig = array(); foreach ($_dbConfig as $key => $val) { $dbConfig[strtolower(substr($key, 2))] = $val; } // 在特殊服务器上的特殊安装过程处理 if (_r('config')) { $replace = array_keys($dbConfig); foreach ($replace as &$key) { $key = '{' . $key . '}'; } $config = str_replace($replace, array_values($dbConfig), _r('config')); } if (!isset($config) && $success && !_r('created')) { $installDb = new Typecho_Db($adapter, _r('dbPrefix')); $installDb->addServer($dbConfig, Typecho_Db::READ | Typecho_Db::WRITE); /** 检测数据库配置 */ try { $installDb->query('SELECT 1=1'); } catch (Typecho_Db_Adapter_Exception $e) { $success = false; echo '<p class="message error">' . _t('对不起,无法连接数据库,请先检查数据库配置再继续进行安装') . '</p>'; } catch (Typecho_Db_Exception $e) { $success = false; echo '<p class="message error">' . _t('安装程序捕捉到以下错误: " %s ". 程序被终止, 请检查您的配置信息.', $e->getMessage()) . '</p>'; } } if ($success) { Typecho_Cookie::set('__typecho_config', base64_encode(serialize(array_merge(array('prefix' => _r('dbPrefix'), 'userName' => _r('userName'), 'userPassword' => _r('userPassword'), 'userMail' => _r('userMail'), 'adapter' => $adapter, 'siteUrl' => _r('userUrl')), $dbConfig)))); if (_r('created')) { header('Location: ./install.php?start');
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__)); /** 定义插件目录(相对路径) */ define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins'); /** 定义模板目录(相对路径) */ define('__TYPECHO_THEME_DIR__', '/usr/themes'); /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/admin/'); /** 设置包含路径 */ @set_include_path(get_include_path() . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__); /** 载入API支持 */ require_once 'Typecho/Common.php'; /** 载入Response支持 */ require_once 'Typecho/Response.php'; /** 载入配置支持 */ require_once 'Typecho/Config.php'; /** 载入异常支持 */ require_once 'Typecho/Exception.php'; /** 载入插件支持 */ require_once 'Typecho/Plugin.php'; /** 载入国际化支持 */ require_once 'Typecho/I18n.php'; /** 载入数据库支持 */ require_once 'Typecho/Db.php'; /** 载入路由器支持 */ require_once 'Typecho/Router.php'; /** 程序初始化 */ Typecho_Common::init(); /** 定义数据库参数 */ $db = new Typecho_Db('Mysql', 'ge_typecho_'); $db->addServer(array('host' => 'aa1tjiqq0rzjru2.cqk3lr4muuky.ap-southeast-1.rds.amazonaws.com', 'user' => 'def1984', 'charset' => 'utf8', 'port' => '3306', 'password' => 'gao13960850667', 'database' => 'gendb'), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__)); /** 定义插件目录(相对路径) */ define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins'); /** 定义模板目录(相对路径) */ define('__TYPECHO_THEME_DIR__', '/usr/themes'); /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/admin/'); /** 设置包含路径 */ @set_include_path(get_include_path() . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__); /** 载入API支持 */ require_once 'Typecho/Common.php'; /** 载入Response支持 */ require_once 'Typecho/Response.php'; /** 载入配置支持 */ require_once 'Typecho/Config.php'; /** 载入异常支持 */ require_once 'Typecho/Exception.php'; /** 载入插件支持 */ require_once 'Typecho/Plugin.php'; /** 载入国际化支持 */ require_once 'Typecho/I18n.php'; /** 载入数据库支持 */ require_once 'Typecho/Db.php'; /** 载入路由器支持 */ require_once 'Typecho/Router.php'; /** 程序初始化 */ Typecho_Common::init(); /** 定义数据库参数 */ $db = new Typecho_Db('Mysql', 'typecho_'); $db->addServer(array('host' => 'localhost', 'user' => 'root', 'password' => '123456', 'charset' => 'utf8', 'port' => '3306', 'database' => 'ups'), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);
public function doImport() { /* 获取配置 */ $options = $this->widget('Widget_Options'); $dbConfig = $options->plugin('EmlogToTypecho'); /* 初始化一个db */ if (Typecho_Db_Adapter_Mysql::isAvailable()) { $db = new Typecho_Db('Mysql', $dbConfig->prefix); } else { $db = new Typecho_Db('Pdo_Mysql', $dbConfig->prefix); } /* 只读即可 */ $db->addServer(array('host' => $dbConfig->host, 'user' => $dbConfig->user, 'password' => $dbConfig->password, 'charset' => 'utf8', 'port' => $dbConfig->port, 'database' => $dbConfig->database), Typecho_Db::READ); /* 删除当前内容 */ $masterDb = Typecho_Db::get(); $this->widget('Widget_Abstract_Contents')->to($contents)->delete($masterDb->sql()->where('1 = 1')); $this->widget('Widget_Abstract_Comments')->to($comments)->delete($masterDb->sql()->where('1 = 1')); $this->widget('Widget_Contents_Post_Edit')->to($edit); $masterDb->query($masterDb->delete('table.relationships')->where('1 = 1')); /* 获取 emlog 管理员信息 */ $emUser = $db->fetchRow($db->query($db->select()->from('table.user'))); $emUsername = $emUser['username']; $emNickname = $emUser['nickname']; /* 转换评论表 */ $i = 1; while (true) { $result = $db->query($db->select()->from('table.comment')->order('cid', Typecho_Db::SORT_ASC)->page($i, 100)); $j = 0; while ($row = $db->fetchRow($result)) { $status = ''; if ('y' == $row['hide']) { $status = 'waiting'; } else { $status = 'approved'; } if ($emUsername == $row['poster'] || $emNickname == $row['poster']) { $authorId = 1; } else { $authorId = 0; } $row['comment'] = preg_replace(array("/\\s*<p>/is", "/\\s*<\\/p>\\s*/is", "/\\s*<br\\s*\\/>\\s*/is", "/\\s*<(div|blockquote|pre|table|ol|ul)>/is", "/<\\/(div|blockquote|pre|table|ol|ul)>\\s*/is"), array('', "\n\n", "\n", "\n\n<\\1>", "</\\1>\n\n"), $row['comment']); $comments->insert(array('coid' => $row['cid'], 'cid' => $row['gid'], 'created' => $row['date'], 'author' => $row['poster'], 'authorId' => $authorId, 'ownerId' => 1, 'mail' => $row['mail'], 'url' => $row['url'], 'ip' => $row['ip'], 'agent' => NULL, 'text' => $row['comment'], 'type' => 'comment', 'status' => $status, 'parent' => $row['pid'])); $j++; unset($row); } if ($j < 100) { break; } $i++; unset($result); } /* 转换文章表 */ $i = 1; while (true) { $result = $db->query($db->select()->from('table.blog')->order('gid', Typecho_Db::SORT_ASC)->page($i, 100)); $j = 0; while ($row = $db->fetchRow($result)) { $type = ''; if ('page' == $row['type']) { $type = 'page'; } else { if ('y' == $row['hide']) { $type = 'post_draft'; } else { $type = 'post'; } } $contents->insert(array('cid' => $row['gid'], 'title' => $row['title'], 'slug' => Typecho_Common::slugName(urldecode($row['alias']), $row['gid']), 'created' => $row['date'], 'modified' => $row['date'], 'text' => $row['content'], 'order' => 0, 'authorId' => $row['author'], 'template' => NULL, 'type' => $type, 'status' => 'publish', 'password' => $row['password'], 'commentsNum' => $row['comnum'], 'allowComment' => 'n' == $row['allow_remark'] ? '0' : '1', 'allowPing' => 0, 'allowFeed' => '1')); $j++; unset($row); } if ($j < 100) { break; } $i++; unset($result); } /* 转换 metas 表 */ $sorts = $db->fetchAll($db->select()->from('table.sort')); foreach ($sorts as $sort) { $blogs = $db->fetchAll($db->select()->from('table.blog')->where('sortid = ?', $sort['sid'])); $masterDb->query($masterDb->insert('table.metas')->rows(array('mid' => $sort['sid'] + 1, 'name' => $sort['sortname'], 'slug' => $sort['alias'], 'type' => 'category', 'description' => $sort['description'], 'count' => count($blogs), 'parent' => 0 != $sort['pid'] ? $sort['pid'] + 1 : 0))); } unset($sorts); $emtags = $db->fetchAll($db->select()->from('table.tag')); foreach ($emtags as $emtag) { $gid = trim($emtag['gid'], ','); $gids = explode(',', $gid); $masterDb->query($masterDb->insert('table.metas')->rows(array('name' => $emtag['tagname'], 'slug' => Typecho_Common::slugName($emtag['tagname']), 'type' => 'tag', 'description' => NULL, 'count' => count($gids)))); } /* 转换关系表 */ $emblogs = $db->fetchAll($db->select()->from('table.blog')); foreach ($emblogs as $emblog) { $masterDb->query($masterDb->insert('table.relationships')->rows(array('cid' => $emblog['gid'], 'mid' => -1 == $emblog['sortid'] ? 1 : $emblog['sortid'] + 1))); } unset($emblogs); $tags = $masterDb->fetchAll($masterDb->select()->from('table.metas')->where('type = ?', 'tag')); foreach ($tags as $tag) { foreach ($emtags as $emtag) { if ($tag['name'] == $emtag['tagname']) { $gid = trim($emtag['gid'], ','); $gids = explode(',', $gid); foreach ($gids as $cid) { $masterDb->query($masterDb->insert('table.relationships')->rows(array('cid' => $cid, 'mid' => $tag['mid']))); } } } } unset($emtags); /* 更新附件地址 */ $emOptions = $db->fetchAll($db->select()->from('table.options')); $static = array(); foreach ($emOptions as $emOption) { $static[$emOption['option_name']] = $emOption['option_value']; } unset($emOptions); $static['blogurl']; $oldUrl = rtrim($static['blogurl'], '/') . '/content/uploadfile'; $path = defined('__TYPECHO_UPLOAD_DIR__') ? __TYPECHO_UPLOAD_DIR__ : '/usr/uploads'; $newUrl = rtrim($options->siteUrl, '/') . $path . '/emlog'; $sql = "UPDATE `" . $masterDb->getPrefix() . "contents` SET `text` = REPLACE(`text`,'" . $oldUrl . "','" . $newUrl . "');"; $masterDb->query($sql); $this->widget('Widget_Notice')->set(_t('数据已经转换完成'), NULL, 'success'); $this->response->goBack(); }
public function doImport() { $options = $this->widget('Widget_Options'); $dbConfig = $options->plugin('MagikeToTypecho'); /** 初始化一个db */ if (Typecho_Db_Adapter_Mysql::isAvailable()) { $db = new Typecho_Db('Mysql', $dbConfig->prefix); } else { $db = new Typecho_Db('Pdo_Mysql', $dbConfig->prefix); } /** 只读即可 */ $db->addServer(array('host' => $dbConfig->host, 'user' => $dbConfig->user, 'password' => $dbConfig->password, 'charset' => 'utf8', 'port' => $dbConfig->port, 'database' => $dbConfig->database), Typecho_Db::READ); /** 删除当前内容 */ $masterDb = Typecho_Db::get(); $this->widget('Widget_Abstract_Contents')->to($contents)->delete($masterDb->sql()->where('1 = 1')); $this->widget('Widget_Abstract_Comments')->to($comments)->delete($masterDb->sql()->where('1 = 1')); $this->widget('Widget_Abstract_Metas')->to($metas)->delete($masterDb->sql()->where('1 = 1')); $this->widget('Widget_Contents_Post_Edit')->to($edit); $this->widget('Widget_Abstract_Users')->to($users)->delete($masterDb->sql()->where('uid <> 1')); $masterDb->query($masterDb->delete('table.relationships')->where('1 = 1')); $userId = $this->widget('Widget_User')->uid; /** 转换用户 */ $rows = $db->fetchAll($db->select()->from('table.users')); foreach ($rows as $row) { if (1 != $row['user_id']) { $users->insert(array('uid' => $row['user_id'], 'name' => $row['user_name'], 'password' => $row['user_password'], 'mail' => $row['user_mail'], 'url' => $row['user_url'], 'screenName' => $row['user_nick'], 'created' => strtotime($row['user_register']), 'group' => array_search($row['user_group'], $this->widget('Widget_User')->groups))); } } /** 转换全局变量 */ $rows = $db->fetchAll($db->select()->from('table.statics')); $static = array(); foreach ($rows as $row) { $static[$row['static_name']] = $row['static_value']; } /** 转换文件 */ $files = $db->fetchAll($db->select()->from('table.files')); if (!is_dir(__TYPECHO_ROOT_DIR__ . '/usr/uploads/')) { mkdir(__TYPECHO_ROOT_DIR__ . '/usr/uploads/', 0766); } $pattern = array(); $replace = array(); foreach ($files as $file) { $path = __TYPECHO_ROOT_DIR__ . '/data/upload/' . substr($file['file_guid'], 0, 2) . '/' . substr($file['file_guid'], 2, 2) . '/' . $file['file_guid']; if (file_exists($path)) { $file['file_time'] = empty($file['file_time']) ? $options->gmtTime : $file['file_time']; $year = idate('Y', $file['file_time']); $month = idate('m', $file['file_time']); $day = idate('d', $file['file_time']); if (!is_dir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}")) { mkdir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}", 0766); } if (!is_dir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}/{$month}")) { mkdir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}/{$month}", 0766); } if (!is_dir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}/{$month}/{$day}")) { mkdir(__TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}/{$month}/{$day}", 0766); } $parts = explode('.', $file['file_name']); $ext = array_pop($parts); copy($path, __TYPECHO_ROOT_DIR__ . "/usr/uploads/{$year}/{$month}/{$day}/{$file['file_id']}.{$ext}"); $new = Typecho_Common::url("/usr/uploads/{$year}/{$month}/{$day}/{$file['file_id']}.{$ext}", $options->siteUrl); $old = Typecho_Common::url("/res/{$file['file_id']}/{$file['file_name']}", $static['siteurl'] . '/index.php'); $pattern[] = '/' . str_replace('\\/index\\.php', '(\\/index\\.php)?', preg_quote($old, '/')) . '/is'; $replace[] = $new; } } /** 转换评论 */ $i = 1; while (true) { $result = $db->query($db->select()->from('table.comments')->order('comment_id', Typecho_Db::SORT_ASC)->page($i, 100)); $j = 0; while ($row = $db->fetchRow($result)) { $comments->insert(array('coid' => $row['comment_id'], 'cid' => $row['post_id'], 'created' => $row['comment_date'], 'author' => $row['comment_user'], 'authorId' => $row['user_id'], 'ownerId' => $userId, 'mail' => $row['comment_email'], 'url' => $row['comment_homepage'], 'ip' => $row['comment_ip'], 'agent' => $row['comment_agent'], 'text' => $row['comment_text'], 'type' => $row['comment_type'], 'status' => $row['comment_publish'], 'parent' => $row['comment_parent'])); $j++; unset($row); } if ($j < 100) { break; } $i++; unset($result); } /** 转换分类 */ $cats = $db->fetchAll($db->select()->from('table.categories')); foreach ($cats as $cat) { $metas->insert(array('mid' => $cat['category_id'], 'name' => $cat['category_name'], 'slug' => $cat['category_postname'], 'description' => $cat['category_describe'], 'count' => 0, 'type' => 'category', 'order' => $cat['category_sort'])); } /** 转换内容 */ $i = 1; while (true) { $result = $db->query($db->select()->from('table.posts')->order('post_id', Typecho_Db::SORT_ASC)->page($i, 100)); $j = 0; while ($row = $db->fetchRow($result)) { $row['post_content'] = preg_replace(array("/\\s*<p>/is", "/\\s*<\\/p>\\s*/is", "/\\s*<br\\s*\\/>\\s*/is", "/\\s*<(div|blockquote|pre|table|ol|ul)>/is", "/<\\/(div|blockquote|pre|table|ol|ul)>\\s*/is"), array('', "\n\n", "\n", "\n\n<\\1>", "</\\1>\n\n"), $row['post_content']); $contents->insert(array('cid' => $row['post_id'], 'title' => $row['post_title'], 'slug' => $row['post_name'], 'created' => $row['post_time'], 'modified' => $row['post_edit_time'], 'text' => preg_replace($pattern, $replace, $row['post_content']), 'order' => 0, 'authorId' => $row['user_id'], 'template' => NULL, 'type' => $row['post_is_page'] ? 'page' : 'post', 'status' => $row['post_is_draft'] ? 'draft' : 'publish', 'password' => $row['post_password'], 'commentsNum' => $row['post_comment_num'], 'allowComment' => $row['post_allow_comment'], 'allowFeed' => $row['post_allow_feed'], 'allowPing' => $row['post_allow_ping'])); /** 插入分类关系 */ $edit->setCategories($row['post_id'], array($row['category_id']), !$row['post_is_draft']); /** 设置标签 */ $edit->setTags($row['post_id'], $row['post_tags'], !$row['post_is_draft']); $j++; unset($row); } if ($j < 100) { break; } $i++; unset($result); } $this->widget('Widget_Notice')->set(_t("数据已经转换完成"), NULL, 'success'); $this->response->goBack(); }
define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins'); /** 定义模板目录(相对路径) */ define('__TYPECHO_THEME_DIR__', '/usr/themes'); /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/admin/'); /** 定义CDN的路径(绝对路径) */ define('__TYPECHO_THEME_URL__', 'https://odoxnoqa2.qnssl.com'); /** 设置包含路径 */ @set_include_path(get_include_path() . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__); /** 载入API支持 */ require_once 'Typecho/Common.php'; /** 载入Response支持 */ require_once 'Typecho/Response.php'; /** 载入配置支持 */ require_once 'Typecho/Config.php'; /** 载入异常支持 */ require_once 'Typecho/Exception.php'; /** 载入插件支持 */ require_once 'Typecho/Plugin.php'; /** 载入国际化支持 */ require_once 'Typecho/I18n.php'; /** 载入数据库支持 */ require_once 'Typecho/Db.php'; /** 载入路由器支持 */ require_once 'Typecho/Router.php'; /** 程序初始化 */ Typecho_Common::init(); /** 定义数据库参数 */ $db = new Typecho_Db('Pdo_Mysql', 'wujunze_'); $db->addServer(array('host' => 'localhost', 'user' => 'XXYY', 'password' => 'DFHUHXXX', 'charset' => 'utf8', 'port' => '3306', 'database' => 'XXXXX'), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__)); /** 定义插件目录(相对路径) */ define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins'); /** 定义模板目录(相对路径) */ define('__TYPECHO_THEME_DIR__', '/usr/themes'); /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/qazwsx/'); /** 设置包含路径 */ @set_include_path(get_include_path() . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__); /** 载入API支持 */ require_once 'Typecho/Common.php'; /** 载入Response支持 */ require_once 'Typecho/Response.php'; /** 载入配置支持 */ require_once 'Typecho/Config.php'; /** 载入异常支持 */ require_once 'Typecho/Exception.php'; /** 载入插件支持 */ require_once 'Typecho/Plugin.php'; /** 载入国际化支持 */ require_once 'Typecho/I18n.php'; /** 载入数据库支持 */ require_once 'Typecho/Db.php'; /** 载入路由器支持 */ require_once 'Typecho/Router.php'; /** 程序初始化 */ Typecho_Common::init(); /** 定义数据库参数 */ $db = new Typecho_Db('Mysql', 'blog_'); $db->addServer(array('host' => '127.0.0.1', 'user' => 'root', 'password' => 'Gxt947171', 'charset' => 'utf8', 'port' => '3306', 'database' => 'blog'), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__)); /** 定义插件目录(相对路径) */ define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins'); /** 定义模板目录(相对路径) */ define('__TYPECHO_THEME_DIR__', '/usr/themes'); /** 后台路径(相对路径) */ define('__TYPECHO_ADMIN_DIR__', '/admin/'); /** 设置包含路径 */ @set_include_path(get_include_path() . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . '/var' . PATH_SEPARATOR . __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__); /** 载入API支持 */ require_once 'Typecho/Common.php'; /** 载入Response支持 */ require_once 'Typecho/Response.php'; /** 载入配置支持 */ require_once 'Typecho/Config.php'; /** 载入异常支持 */ require_once 'Typecho/Exception.php'; /** 载入插件支持 */ require_once 'Typecho/Plugin.php'; /** 载入国际化支持 */ require_once 'Typecho/I18n.php'; /** 载入数据库支持 */ require_once 'Typecho/Db.php'; /** 载入路由器支持 */ require_once 'Typecho/Router.php'; /** 程序初始化 */ Typecho_Common::init(); /** 定义数据库参数 */ $db = new Typecho_Db('Pdo_Mysql', 'wujunze_'); $db->addServer(array('host' => 'localhost', 'user' => 'root', 'password' => 'wu1017109588wu', 'charset' => 'utf8', 'port' => '3306', 'database' => 'wujunze'), Typecho_Db::READ | Typecho_Db::WRITE); Typecho_Db::set($db);