if (init_convert_tables($convert_tables_file)) { include ROOT_PATH . $convert_tables_file; } else { showmessage('<span style="color:red;font-size:14px;font-weight:bold">没有数据表可以转换</span>'); } $tables_keys = array_keys($convert_tables); if (empty($act)) { $backup_count = backup_tables($tables_keys); $extra = ' <input type="hidden" name="ecshop_charset" value="' . $ecshop_charset . '" /> <input type="hidden" name="mysql_charset" value="' . $mysql_charset . '" /> <input type="hidden" name="act" value="convert" /> <input type="hidden" name="table_name" value="' . $tables_keys[0] . '" />'; showmessage("数据库备份完成," . $backup_count . " 个原数据表均重命名为以 _bak 为后缀!", '?step=start', 'form', $extra); } else { convert_table(getgpc('table_name', 'P')); } } ob_end_flush(); function instheader() { global $charset, $tools_version; echo "<html><head>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset={$charset}\">" . "<title>ECShop 数据库编码转换工具{$tools_version}</title>" . "<style type=\"text/css\">\n a {\n color: #3A4273;\n text-decoration: none\n }\n\n a:hover {\n color: #3A4273;\n text-decoration: underline\n }\n\n body, table, td {\n color: #3A4273;\n font-family: Tahoma, Verdana, Arial;\n font-size: 12px;\n line-height: 20px;\n scrollbar-base-color: #E3E3EA;\n scrollbar-arrow-color: #5C5C8D\n }\n form {\n margin:0;\n padding:0\n }\n input {\n color: #085878;\n font-family: Tahoma, Verdana, Arial;\n font-size: 12px;\n background-color: #3A4273;\n color: #FFFFFF;\n scrollbar-base-color: #E3E3EA;\n scrollbar-arrow-color: #5C5C8D\n }\n\n .install {\n font-family: Arial, Verdana;\n font-size: 20px;\n font-weight: bold;\n color: #000000\n }\n\n .message {\n background: #E3E3EA;\n padding: 20px;\n }\n\n .altbg1 {\n background: #E3E3EA;\n }\n\n .altbg2 {\n background: #EEEEF6;\n }\n\n .header td {\n color: #FFFFFF;\n background-color: #3A4273;\n text-align: center;\n }\n\n .option td {\n text-align: center;\n }\n\n .redfont {\n color: #FF0000;\n }\n .p_indent{\n text-indent:2em;\n }\n div.msg{\n text-indent:2em;\n line-height:30px;\n height:30px;\n }\n </style>\n <script type=\"text/javascript\">\n function redirect(url) {\n window.location=url;\n }\n function \$(id) {\n return document.getElementById(id);\n }\n </script>\n </head>" . "<body bgcolor=\"#298296\" text=\"#000000\"><div id=\"append_parent\"></div>" . "<table width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#FFFFFF\" align=\"center\"><tr><td>" . "<table width=\"98%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"><tr>" . "<td class=\"install\" height=\"30\" valign=\"bottom\"><font color=\"#FF0000\">>></font> ECShop 数据库编码转换工具{$tools_version}" . "</td></tr><tr><td><hr noshade align=\"center\" width=\"100%\" size=\"1\"></td></tr><tr><td colspan=\"2\">"; } function instfooter() { echo "</td></tr><tr><td><hr noshade align=\"center\" width=\"100%\" size=\"1\"></td></tr>" . "<tr><td align=\"center\">" . "<b style=\"font-size: 11px\">Powered by <a href=\"http://www.ecshop.com\" target=\"_blank\"><span style=\"color:#FF6100\">ECShop</span>" . "</a></b> © 2005-2009 上海商派网络科技有限公司。<br /><br />" . "</td></tr></table></td></tr></table>" . "</body></html>"; } function showmessage($message, $url_forward = '', $msgtype = 'message', $extra = '', $delaymsec = 1000) { //以表单的形式显示信息
function _importer(&$event, $param) { if (auth_quickaclcheck($ID) < AUTH_EDIT) { return; } if ($event->data != 'doc2dw') { return; } if ($_FILES['doc']) { $pageName = $_POST["title"]; $nameSpace = $_POST["ns"]; if (!$nameSpace) { $nameSpace = "wiki"; } #Create temporary directory $tempDir = System::mktemp("-d word_upload"); $fileName = basename($_FILES['doc']['name']); $fileName = preg_replace("/ /", "_", $fileName); $agnosticFileName = preg_split("/\\./", $fileName); $agnosticFileName = $agnosticFileName[0]; if (move_uploaded_file($_FILES['doc']['tmp_name'], $tempDir . "/" . $fileName)) { #Convert the doc to HTML and MediaWiki $result = exec("export HOME=/tmp && cd " . $tempDir . " && convert_to_mediawiki " . $fileName); #Load html and MediaWiki $myWikiContent = file_get_contents($tempDir . "/" . $agnosticFileName . ".txt"); $myHTMLContent = file_get_contents($tempDir . "/" . $agnosticFileName . ".html"); #Replace nbsp by space $myWikiContent = preg_replace("/ /", " ", $myWikiContent); #Remove center tags $myWikiContent = preg_replace("/<center>/", " ", $myWikiContent); $myWikiContent = preg_replace("/<\\/center>/", " \n", $myWikiContent); #Remove buggy Toc tags $myWikiContent = preg_replace("/\\[#_Toc.*\\]/", " \n", $myWikiContent); #Convert from MediaWiki to dokuwiki $converter = new MediaWiki2DokuWiki_MediaWiki_SyntaxConverter($myWikiContent); $myWikiContent = $converter->convert(); #Remove buggy // $myWikiContent = preg_replace("/\\/\\//", "", $myWikiContent); #Get undernlined sentences from html and replace them in the wiki text $underlined_sentences = get_tagged_from_html($myHTMLContent, "underlined"); $myWikiContent = replace_from_list($myWikiContent, $underlined_sentences, "underlined"); #Get italic sentences from html and replace them in the wiki text $italic_sentences = get_tagged_from_html($myHTMLContent, "italic"); $myWikiContent = replace_from_list($myWikiContent, $italic_sentences, "italic"); #Get all the images from the html $myWikiContent = get_images_from_html($myHTMLContent, $myWikiContent); #Convert tables $raw_tables = array(); $good_tables = array(); preg_match_all("/\\{\\|(.*)\\|\\}/sU", $myWikiContent, $tables); foreach ($tables[1] as $match) { array_push($raw_tables, '{|' . $match . '|}'); array_push($good_tables, convert_table($match)); } $myWikiContent = str_replace($raw_tables, $good_tables, $myWikiContent); #Transform references into footnotes $myWikiContent = preg_replace_callback("/<ref.*>(.*)<\\/ref>/sU", "convert_footnote", $myWikiContent); #Remove junk <br/> tags $myWikiContent = preg_replace("/<br\\/>/", "\n", $myWikiContent); #Remove junk <references/> $myWikiContent = preg_replace("/----\n<references\\/>/", "", $myWikiContent); #Remove ** that does not have the corresponding closing ** $content_lines = explode(PHP_EOL, $myWikiContent); $myWikiContent = ""; foreach ($content_lines as $line) { $first = strpos($line, "**"); if ($first) { $second = strpos($line, "**", $first + 2); if (!$second) { $line = preg_replace("/\\*\\*/U", "", $line); } } $myWikiContent = $myWikiContent . $line . "\n"; } #Send the wiki page $username = $this->getConf('api_username'); $password = $this->getConf('api_password'); $client = new IXR_Client('http://localhost/dokuwiki/lib/exe/xmlrpc.php'); $ok = $client->query('dokuwiki.login', $username, $password); if ($ok) { $attrs = array('sum' => 'First try', 'minor' => false); $result = $client->query('wiki.putPage', $nameSpace . ':' . $pageName, $myWikiContent, $attrs); #Send all the images as attachements if ($handle = opendir($tempDir)) { while (false !== ($entry = readdir($handle))) { if (strpos($entry, '.png') !== false || strpos($entry, '.jpg') !== false || strpos($entry, '.gif') !== false) { $image_data = file_get_contents($tempDir . "/" . $entry, true); //$image_data = base64_encode($image_data); $image_data = new IXR_Base64($image_data); $attrs = array('ow' => true); $client->query('wiki.putAttachment', $entry, $image_data, $attrs); } } closedir($handle); } } } $event->data = $this->getConf('parserPostDisplay'); send_redirect(wl($nameSpace . ':' . $pageName, '', true, '&')); } }