= "HomePage/2004-01-01" ORDER BY phpwiki_page.id, version '; $result = mysql_query($query); if (!$result) die("Error: " . mysql_error()); $post = array('id' => -1); $links = array(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row['id'] != $post['id']) { // Insert last post. insert_post($post); // Start of next post. $post = $row; } else { // Newer content for current post. $post['content'] = $row['content']; } } insert_post($post); function insert_post($post) { if ($post['id'] == -1) return; $content = $post['content']; preg_match('{!!!\s*(.*)}', $content, $matches); $title = clean_wiki($matches[1]); $GLOBALS['links'] = array(); $content = convert_wiki(trim(strstr($content, "\n"))) . "\n\n"; foreach ($GLOBALS['links'] as $n => $link) { $content .= '[' . ($n+1) . ']: ' . $link . "\n"; } $date = gmdate('Y-m-d H:i:s', $post['mtime']+3600); $pagename = $post['pagename']; echo "Inserting $pagename...\n"; flush(); wp_insert_post(array('post_title' => $title, 'post_excerpt' => '', 'post_content' => $content, 'post_author' => 1, 'post_date' => $date, 'post_category' => array(1), 'post_status' => 'publish')); /* echo "************************************************************************\n"; echo $post['content'] . "\n"; echo "========================================================================\n"; echo "$title\n"; echo "------------------------------------------------------------------------\n"; echo "Date: $date\n"; echo "------------------------------------------------------------------------\n"; echo "$content\n"; echo "========================================================================\n"; echo "\n"; */ } function clean_wiki($str) { $str = preg_replace('{\[\s?(.*?)\s+\|\s+(.*?)\s+right\s*\]}s', '', $str); $str = preg_replace('{\[\s?(.*?)\s?\|\s?.*?\]}', '$1', $str); $str = preg_replace('{\s\'\'(\w+(\s\w+)*?)\'\'\s}s', '*$1*', $str); $str = preg_replace('{\s_(\w+(\s\w+)*?)_\s}s', '*$1*', $str); $str = preg_replace('{(.*?)}s', '`$1`', $str); $str = preg_replace('{=(\w+(\s\w+)*?)=}s', '`$1`', $str); $str = preg_replace('{mailto:(.*?@.*?)\w}', '<$1>', $str); $str = preg_replace('{(http://.*?)\w}', '<$1>', $str); $str = preg_replace('{\[IMDB:(.*?)\]}s', 'IMDB:$1', $str); $str = preg_replace('{\[ISBN:(.*?)\]}s', 'ISBN:$1', $str); $str = preg_replace('{\[DAIMI:(.*?)\]}s', 'DAIMI:$1', $str); $str = preg_replace('{\[RFC:(.*?)\]}s', 'RFC:$1', $str); $str = preg_replace('{\[PhpWiki:(.*?)\]}s', 'PhpWiki:$1', $str); return $str; } function convert_link($matches) { if (false !== ($key = array_search($matches[2], $GLOBALS['links']))) { return '[' . $matches[1] . '][' . ($key+1) . ']'; } else { $GLOBALS['links'][] = $matches[2]; return '[' . $matches[1] . '][' . count($GLOBALS['links']) . ']'; } } function convert_verbatim($matches) { return implode("\n ", explode("\n", $matches[1])); } function imdb_callback($matches) { return '[IMDB:' . $matches[1] . ' | ' . 'http://imdb.com/Title?' . rawurlencode($matches[1]) . ']'; } function convert_wiki($str) { $str = preg_replace_callback('{(.*?)}s', 'convert_verbatim', $str); $str = preg_replace_callback('{<\?plugin PhpHighlight(.*?)\?>}s', 'convert_verbatim', $str); $str = preg_replace('{http://gimpster.com/images(/news)?}', '/images', $str); $str = str_replace('gimpster@gimpster.com', 'mgeisler@mgeisler.net', $str); $str = preg_replace('{\[(.*?)\s?\|\s?MartinGeisler/Machine\]}s', '$1', $str); $str = preg_replace('{\[\s*(.*?)\s+\|\s+(.*?)\s+right\s*\]}', '', $str); $str = preg_replace('{(\s)\'\'(\w+(?:\s[\w?!.,]+)*?)\'\'(\s)}s', '$1*$2*$3', $str); $str = preg_replace('{(\s)_(\w+(?:\s[\w?!.,]+)*?)_(\s)}s', '$1*$2*$3', $str); $str = preg_replace('{(.*?)}s', '`$1`', $str); $str = preg_replace('{(\s)=(\w+(?:\s[\w?!.,]+)*?)=(\s)}s', '$1`$2`$3', $str); $str = preg_replace('{(?', $str); $str = preg_replace('{(?', $str); $str = preg_replace_callback('{\[IMDB:(.*?)\]}s', 'imdb_callback', $str); $str = preg_replace('{\[?ISBN:(\d+)\]?}s', '[ISBN:$1 | http://isbn.nu/$1]', $str); $str = preg_replace('{DAIMI:([\w~]+)}', '[DAIMI:$1]', $str); $str = preg_replace('{\[DAIMI:(.*?)\]}s', '[DAIMI:$1 | ' . 'http://daimi.au.dk/$1/]', $str); $str = preg_replace('{RFC:(\d+)?}s', '[RFC:$1 | ' . 'http://www.faqs.org/rfcs/rfc$1.html]', $str); $str = preg_replace('{PhpWiki:(\w+)}', '[PhpWiki:$1]', $str); $str = preg_replace('{\[PhpWiki:(.*?)\]}', '[PhpWiki:$1 | ' . 'http://phpwiki.sourceforge.net/phpwiki/$1]', $str); $str = preg_replace('{\bWiki:(\w+)}', '[Wiki:$1]', $str); $str = preg_replace('{\[Wiki:(.*?)\]}', '[Wiki:$1 | http://c2.com/cgi/wiki?$1]', $str); $str = preg_replace('{PhpShell}', '[PHP Shell][]', $str); $str = preg_replace('{PhpWeather}', '[PHP Weather][]', $str); $str = preg_replace('{SkejbyGård}', '[Skejbygård][]', $str); $str = preg_replace('{UniversityOfAarhus\]}', 'http://www.au.dk/]', $str); $str = preg_replace('{UniversityOfAarhus}', '[University of Aarhus | http://www.au.dk/]', $str); $str = preg_replace('{HomePage/(\d{4})-(\d\d)-(\d\d)\]}', '/$1/$2/$3/]', $str); $str = preg_replace('{PhpTutorial\]}', '/php-tutorial/]', $str); $str = preg_replace('{PhpTutorial}', '[PHP Tutorial | /php-tutorial/]', $str); $str = preg_replace('{MartinGeisler\]}', '/martin-geisler/]', $str); $str = preg_replace('{MartinGeisler/Schedule\]}', '/martin-geisler/schedule/]', $str); foreach (array(array('Martin', 'Geisler', '/martin-geisler/'), array('Mikkel', 'Krøigård', 'http://daimi.au.dk/~mk/'), array('Thomas', 'Mølhave', 'http://moelhave.dk/'), array('Lars', 'Petersen', 'http://daimi.au.dk/~aveng/'), array('Andreas', 'Danielsen'), array('Camilla', 'Johnsen'), array('Christina', 'Strøhl'), array('Martin', 'Justesen'), array('Svend', 'Sørensen', 'http://demosophia.net/'), array('Mia', 'Schneider'), array('Kristian', 'Kristensen', 'http://zianet.dk/'), array('Torben', 'Classen'), array('Jesper', 'Klintø'), array('Hanne', 'Enemark'), array('Olle', 'Hansen'), array('Nina', 'Ratenburg'), array('Mette', 'Bukhave'), array('Hilmar', 'Magnusson'), array('Kristoffer', 'Geisler'), array('Lars', 'Geisler', 'http://lgsoftware.dk/'), array('Marianne', 'Geisler', 'http://x-psyk.dk/'), array('The', 'Party', 'http://theparty.dk/') ) as $data) { if (count($data) == 3) { $a = '[$1 | ' . $data[2] . ']'; $b = '[' . $data[0] . ' ' . $data[1] . ' | ' . $data[2] . ']'; } else { $a = '$1'; $b = $data[0] . ' ' . $data[1]; } $str = preg_replace('{\[\s*(.*?)\s*\|\s*' . $data[0] . $data[1] . '\s*\]}s', $a, $str); $str = preg_replace('{' . $data[0] . $data[1] . '}', $b, $str); } $str = str_replace('~~', '~', $str); $str = preg_replace_callback('{\[\s*(.*?)\s*\|\s*(.*?)\s*\]}s', 'convert_link', $str); $pars = explode("\n\n", $str); $str = ''; foreach ($pars as $par) { $str .= "\n\n"; if (substr(trim($par, "\n"), 0, 4) == ' ') $str .= $par; else $str .= wordwrap(str_replace("\n", ' ', $par)); } return trim($str); } echo "\n\nAll done!\n"; ?>