#!/usr/bin/php $md5sum) { fwrite($fp, $filename . " " . $md5sum . "\n"); } fclose($fp); // convert from tomboy markup to dokuwiki markup function convertWikiMarkup($markup) { // one little hack: first line of each tomboy page is the h1 $markup = preg_replace('/^(.*?)'."\n/",'$1'."\n", $markup); // now simple regexp replaces with tomboy and dokuwiki markup $markup = preg_replace('/(.*)<\\/bold>/','**$1**', $markup); $markup = preg_replace('/(.*)<\\/italic>/','//$1//', $markup); $markup = preg_replace('/(.*)<\\/strikethrough>/','$1', $markup); $markup = preg_replace('/(.*)<\\/highlight>/','##$1##', $markup); $markup = preg_replace('/(.*)<\\/size:small>/','(($1))', $markup); $markup = preg_replace('/(.*)<\\/size:large>/','===== $1 =====', $markup); $markup = preg_replace('/(.*)<\\/size:huge>/','====== $1 ======', $markup); // one last thing: if it is not a hX, we need a "\\ " for creating newlines at each line $lines = explode("\n", $markup); for($i=0; $i"; } } // XML Handler function function endElement($parser, $name) { global $wiki, $allowedTags; if($name == "NOTE-CONTENT" && $wiki["noteContent_search"] == 1) { unset($wiki["noteContent_search"]); $wiki["noteContent"] = convertWikiMarkup($wiki["noteContent"]); } if($name == "TITLE" && $wiki["title_search"] == 1) { unset($wiki["title_search"]); } if(in_array(strtolower($name), $allowedTags)) { $wiki["noteContent"] .= ""; } } // XML Handler function function characterData($parser, $data) { global $wiki; if($wiki["noteContent_search"] == 1) { $wiki["noteContent"] .= $data; } if($wiki["title_search"] == 1) { $wiki["title"] .= $data; } } function mkdir_recursive($path, $rights = 0777) { echo "mkdir " . $path . "\n"; $folder_path = array( strstr($path, '.') ? dirname($path) : $path); while(!@is_dir(dirname(end($folder_path))) && dirname(end($folder_path)) != '/' && dirname(end($folder_path)) != '.' && dirname(end($folder_path)) != '') array_push($folder_path, dirname(end($folder_path))); while($parent_folder_path = array_pop($folder_path)) if(!@mkdir($parent_folder_path, $rights)) user_error("Can't create folder \"$parent_folder_path\"."); mkdir($path); } // main function which does all the work function sync_page($path) { global $wiki, $dokuwiki_datapath, $dokuwiki_namespace, $dokuwiki_username, $whitelist, $blacklist; // analyse tomboy's XML page $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = fopen($path, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); fclose($fp); $target = str_replace(" ", "_", strtolower($wiki["title"])); if(in_array($target, $blacklist)) return; if(count($whitelist) && !in_array($target, $whitelist)) return ; echo "syncing " . $target . "\n"; $target_filename = $target . ".txt"; $namespace = str_replace(":", "/", $dokuwiki_namespace); // make sure directories exist! if(!file_exists($dokuwiki_datapath."pages/".$namespace)) { mkdir_recursive($dokuwiki_datapath."pages/".$namespace); } if(!file_exists($dokuwiki_datapath."attic/".$namespace)) { mkdir_recursive($dokuwiki_datapath."attic/".$namespace); } if(!file_exists($dokuwiki_datapath."meta/".$namespace)) { mkdir_recursive($dokuwiki_datapath."meta/".$namespace); } if($namespace) $namespace .= "/"; // file was changed in tomboy, so copy old page to attic and overwrite if(file_exists($dokuwiki_datapath."pages/".$namespace.$target_filename) && filesize($dokuwiki_datapath."pages/".$namespace.$target_filename) != strlen($wiki["noteContent"])) { $target_filename_attic = str_replace(" ", "_", strtolower($wiki["title"]).".".time().".txt.gz"); // compress old data $data = implode("", file($dokuwiki_datapath."pages/".$namespace.$target_filename)); $gzdata = gzencode($data, 9); $fp = fopen($dokuwiki_datapath."attic/".$namespace.$target_filename_attic, "w"); fwrite($fp, $gzdata); fclose($fp); // write new data if (!($fp = fopen($dokuwiki_datapath."pages/".$namespace . $target_filename, "w"))) { die("could not open dokuwiki data directory for writing"); } fwrite($fp, $wiki["noteContent"]); fclose($fp); $changelog = time() . "\t127.0.0.1\tE\t".str_replace("/",":",$namespace).$target."\t" . $dokuwiki_username."\n"; // write to global changelog if (!($fp = fopen($dokuwiki_datapath."meta/_dokuwiki.changes", "a"))) { die("could not open dokuwiki changes file for writing"); } fwrite($fp, $changelog); fclose($fp); // write to page changelog if (!($fp = fopen($dokuwiki_datapath."meta/".$namespace.$target.".changes", "a"))) { die("could not open page changes file for writing"); } fwrite($fp, $changelog); fclose($fp); } else { if (!($fp = fopen($dokuwiki_datapath."pages/".$namespace.$target_filename, "w"))) { die("could not open dokuwiki data directory for writing"); } fwrite($fp, $wiki["noteContent"]); fclose($fp); } } ?>