Oo-regexp-export.php
<?
- Export article to OO format
- - only does document.php transform and its own wiki markup
# Main wiki->oo parser function ooParse($text) { $script = $GLOBALS['xwScript']; $bToken = ':-:'.'bullet'.':-:';
# Convert problem quotes and dashes $text = str_replace('–','-',$text); $text = preg_replace('/“|�/','"',$text);
# TODO ; :
# *text (pre) $text = preg_replace("/\\n(\\*+) *(.+?)$/m", "$bToken\\1\\2$bToken", $text);
$xml = ; foreach (explode("\n\n", trim(htmlentities($text))) as $text) {
# text $text = preg_replace("/(.+?)/s", "<text:span text:style-name=\"T2\">\\1</text:span>", $text);
# text $text = preg_replace("/(.+?)/s", "<text:span text:style-name=\"T1\">\\1</text:span>", $text);
# anchor $text = preg_replace("/\\[\\[Wikipedia:([^\\|\\]]+)\\|([^\\]]*)]]/", "<text:a xlink:type=\"simple\" xlink:href=\"http://en.wikipedia.org/wiki/\\1\">\\2</text:a>", $text);
# anchor $text = preg_replace("/\\[\\[([^\\|\\]]+)\\|([^\\]]*)]]/", "<text:a xlink:type=\"simple\" xlink:href=\"$script/\\1\">\\2</text:a>", $text);
# article $text = preg_replace("/\\[\\[([^\\]]+)]]/", "<text:a xlink:type=\"simple\" xlink:href=\"$script/\\1\">\\1</text:a>", $text);
# [url anchor] $text = preg_replace("/\\[([^ \\]]+) +([^\\]]*)]/", "<text:a xlink:type=\"simple\" xlink:href=\"\\1\">\\2</text:a>", $text);
# [url] $text = preg_replace("/\\[([^\\]]+)]/", "<text:a xlink:type=\"simple\" xlink:href=\"\\1\">\\1</text:a>", $text);
$xml .= "<text:p text:style-name=\"Text body\">$text</text:p>\n"; }
# *text (post) $xml= preg_replace("/$bToken\\*+(.*?)$bToken/m", "<text:list-item><text:p text:style-name=\"P12\">\\1</text:p></text:list-item>", $xml); $xml= preg_replace("/(?<!<\\/text:list-item>)(<text:list-item>)/", "</text:p>\n<text:unordered-list text:style-name=\"L1\">\\1", $xml); $xml= preg_replace("/(<\\/text:list-item>)(?!<text:list-item>)/", "\\1</text:unordered-list>\n<text:p text:style-name=\"Text body\">", $xml);
#
$xml = str_replace('<hr></text:p>', "</text:p>\n<text:p text:style-name=\"P13\" />\n", $xml); $xml = str_replace('<hr>', "</text:p>\n<text:p text:style-name=\"P13\" />\n<text:p text:style-name=\"Text body\">", $xml);
# $xml = str_replace(' ', ' ', $xml);
return $xml; }
$htdocs = $GLOBALS['_SERVER']['DOCUMENT_ROOT']; $error = false;
- Create a unique working folder and copy OO doc file-template to new file in it
mkdir($tmp = "$htdocs/wiki/tmp/".uniqid('export')); copy("$htdocs/wiki/xmlwiki/doc-template.sxw", $sxw = "$tmp/sxw");
- Zip compression library - www.phpconcept.net/pclzip/
define('PCLZIP_TEMPORARY_DIR', "$tmp/"); require_once("$htdocs/wiki/xmlwiki/lib/pclzip/pclzip.lib.php");
- Get OO content template article
$xml = xwArticleContent('oo-doc-template.xml');
- Insert our document info into existing tokens
$xml = str_replace('Title', str_replace('_',' ',$title), $xml); $xml = str_replace('Version', 'Exported by '.$GLOBALS['xwUserName'].' on '.date('d M Y').' at '.date('H:i:s'), $xml);
- $xml = str_replace('My-Header', "$script/$title", $xml); # this is in styles
- Build mian document body
- - the match splits the article into sections at headings, extracting heading, level & text
$body = ; $last = 0;
if (preg_match_all('/