1<?php 2 3die(__FILE__.' no longer required'); 4 5/* 6 * wikitomellel 7 * Simon Brüchner, 19.11.2007, 2010, 24.01.2013 8 */ 9function mellelconvert($wikiMarkup, $zip = true) { 10 define(MELLEL_UEBERSCHRIFT, '--UEBERSCHRIFT--'); 11 define(MELLEL_KLAMMER, '--KLAMMER--'); 12 define(MELLEL_HIGHLIGHT, '--HIGHLIGHT--'); 13 define(MELLEL_TEMPLATE_CONTENT, '{{CONTENT}}'); 14 15 /** 16 * Callback to cleanup wiki markup 17 * Remove unnecessary stuff (headings, empty rows) 18 */ 19 function cleanup($data) { 20 return $data; 21 22 // do not ignore empty spaces! 23 if (strlen(trim($data)) > 0) { 24 return $data; 25 } 26 } 27 28 $template = dirname(__FILE__).DIRECTORY_SEPARATOR.'template.txt'; 29 $wikiMarkup = $wikiMarkup; 30 $template = file_get_contents($template); 31 $rowbreak = "\n"; 32 33 34 $wikiMarkup = explode($rowbreak, $wikiMarkup); 35 $wikiMarkup = array_filter($wikiMarkup, 'cleanup'); 36 37 38 $patternNote = "~\(\((.+)\)\)~U"; 39 $patternBold = "~\*\*(.+)\*\*~U"; 40 $patternItalic = "~//(.+)//~U"; 41 42 $mellelMarkup = ''; 43 foreach ($wikiMarkup as $row) { 44 $row = /*trim*/(utf8_encode($row)); 45 46 $row = str_replace("\n", '', $row); 47 $row = str_replace(' & ', ' & ', $row); 48 $row = str_replace('<>', MELLEL_KLAMMER, $row); 49 $row = str_replace('</hi>', MELLEL_HIGHLIGHT, $row); 50 $row = str_replace('<hi #ffff00>', MELLEL_HIGHLIGHT, $row); 51 $row = str_replace('<hi #ff0000>', MELLEL_HIGHLIGHT, $row); 52 $row = str_replace('<hi #ffa500>', MELLEL_HIGHLIGHT, $row); 53 $row = str_replace('<hi #fa8072>', MELLEL_HIGHLIGHT, $row); 54 $row = str_replace('<hi #ffc0cb>', MELLEL_HIGHLIGHT, $row); 55 $row = str_replace('<hi #dda0dd>', MELLEL_HIGHLIGHT, $row); 56 $row = str_replace('<hi #800080>', MELLEL_HIGHLIGHT, $row); 57 $row = str_replace('<hi #ff00ff>', MELLEL_HIGHLIGHT, $row); 58 $row = str_replace('<hi #c0c0c0>', MELLEL_HIGHLIGHT, $row); 59 $row = str_replace('<hi #00ffff>', MELLEL_HIGHLIGHT, $row); 60 $row = str_replace('<hi #008080>', MELLEL_HIGHLIGHT, $row); 61 $row = str_replace('<hi #6495ed>', MELLEL_HIGHLIGHT, $row); 62 $row = str_replace('<hi #87ceeb>', MELLEL_HIGHLIGHT, $row); 63 $row = str_replace('<hi #7fffd4>', MELLEL_HIGHLIGHT, $row); 64 $row = str_replace('<hi #98fb98>', MELLEL_HIGHLIGHT, $row); 65 $row = str_replace('<hi #00ff00>', MELLEL_HIGHLIGHT, $row); 66 $row = str_replace('<hi #008000>', MELLEL_HIGHLIGHT, $row); 67 $row = str_replace('<hi #808000>', MELLEL_HIGHLIGHT, $row); 68 $row = strip_tags($row); 69 70 if (!strstr($row, '**') AND !strstr($row, '//') AND !strstr($row, '((')) { 71 if (substr($row, 0, 2) !== '==') { 72 $row = '<p style="ps-0" dir="ltr"><c style="cs-0">'.$row.'</c></p>'; 73 } else { 74 // Headline 75 if (substr($row, 0, 6) === '======') { 76 $row = '<p style="ps-2" dir="ltr"><c style="cs-5">'./*trim*/(str_replace('=', '', $row)).'</c></p>'; 77 } else { 78 $row = '<p style="ps-3" dir="ltr"><c style="cs-1">'./*trim*/(str_replace('=', '', $row)).'</c></p>'; 79 } 80 } 81 } else { 82 $pregResultNote = null; 83 $pregResultBold = null; 84 $pregResultItalic = null; 85 86 // Bold 87 preg_match_all($patternBold, $row, $pregResultBold); 88 if ($pregResultBold[1]) { 89 $row = preg_replace($patternBold, "</c><c style=\"cs-1\">$1</c><c style=\"cs-0\">", $row); 90 } 91 92 // Italic 93 preg_match_all($patternItalic, $row, $pregResultItalic); 94 if ($pregResultItalic[1]) { 95 $row = preg_replace($patternItalic, "</c><c style=\"cs-4\">$1</c><c style=\"cs-0\">", $row); 96 } 97 98 // Footnote 99 preg_match_all($patternNote, $row, $pregResultNote); 100 if ($pregResultNote[1]) {// <c style='cs-1'><note stream='nsm-0'><p style='ps-1' dir='ltr'><c style='cs-2'>Footnote content</c></p></note></c> 101 $row = preg_replace($patternNote, "</c><c style='cs-1'><note stream='nsm-0'><p style='ps-1' dir='ltr'><c style='cs-2'>$1</c></p></note></c><c style='cs-0'>", $row); 102 } 103 104 $row = '<p style="ps-0" dir="ltr"><c style="cs-0">'.$row.'</c></p>'; 105 } 106 $mellelMarkup .= $row; 107 } 108 $mellelMarkup = str_replace(MELLEL_TEMPLATE_CONTENT, $mellelMarkup, $template); 109 110// if ($zip AND class_exists('ZipArchive')) { 111// 112// $zip = new ZipArchive(); 113// 114// $tmpZipFile = tempnam(sys_get_temp_dir().'/', 'aaa_inge_wiki_2_mellel_render_'); 115// $res = $zip->open($tmpZipFile, ZipArchive::CREATE); 116// if ($res === TRUE) { 117// $zip->addFromString('main.xml', $mellelMarkup); 118// $zip->addFromString('.redlex', ''); 119// $zip->close(); 120// 121// $mellelMarkup = file_get_contents($tmpZipFile); 122// @unlink($tmpZipFile); 123// } 124// } 125 126 127 $mellelMarkup = microtime().$mellelMarkup; 128 129 return $mellelMarkup; 130} 131