diff --git a/main/inc/lib/text.lib.php b/main/inc/lib/text.lib.php index 5240e94189..cfbf854dd3 100755 --- a/main/inc/lib/text.lib.php +++ b/main/inc/lib/text.lib.php @@ -281,6 +281,44 @@ function api_fgetcsv($handle, $length = null, $delimiter = ',', $enclosure = '"' } +/* Functions for supporting ASCIIMathML mathematical formulas and ASCIIsvg maathematical graphics */ + +/** + * Dectects ASCIIMathML formula presence within a given html text. + * @param string $html The input html text. + * @return bool Returns TRUE when there is a formula found or FALSE otherwise. + */ +function api_contains_asciimathml($html) { + if (!preg_match_all('/]*class\s*=\s*[\'"](.*?)[\'"][^>]*>/mi', $html, $matches)) { + return false; + } + foreach ($matches[1] as $string) { + $string = ' '.str_replace(',', ' ', $string).' '; + if (preg_match('/\sAM\s/m', $string)) { + return true; + } + } + return false; +} + +/** + * Dectects ASCIIsvg graphics presence within a given html text. + * @param string $html The input html text. + * @return bool Returns TRUE when there is a graph found or FALSE otherwise. + */ +function api_contains_asciisvg($html) { + if (!preg_match_all('/]*?)>/mi', $html, $matches)) { + return false; + } + foreach ($matches[1] as $string) { + $string = ' '.str_replace(',', ' ', $string).' '; + if (preg_match('/sscr\s*=\s*[\'"](.*?)[\'"]/m', $string)) { + return true; + } + } + return false; +} + /* Miscellaneous text processing functions */ /** @@ -583,10 +621,10 @@ function get_last_week() { */ function get_week_from_day($date) { if (!empty($date)) { - $time = api_strtotime($date,'UTC'); + $time = api_strtotime($date,'UTC'); return date('W', $date); } else { - return date('W'); + return date('W'); } } diff --git a/main/wiki/wiki.inc.php b/main/wiki/wiki.inc.php index f3eb26d360..775152548a 100755 --- a/main/wiki/wiki.inc.php +++ b/main/wiki/wiki.inc.php @@ -1716,7 +1716,7 @@ function export2doc($wikiTitle, $wikiContents, $groupId) {CSS} /*]]>*/ - + {ASCIIMATHML_SCRIPT} {CONTENT} @@ -1737,7 +1737,12 @@ function export2doc($wikiTitle, $wikiContents, $groupId) $css = str_replace('images/', $root_rel.$css_path.$theme.'images/', $css); $css = str_replace('../../img/', $root_rel.'main/img/', $css); - $template = str_replace(array('{LANGUAGE}', '{ENCODING}', '{TEXT_DIRECTION}', '{TITLE}', '{CSS}'), array(api_get_language_isocode(), api_get_system_encoding(), api_get_text_direction(), $wikiTitle, $css), $template); + $asciimathmal_script = (api_contains_asciimathml($wikiContents) || api_contains_asciisvg($wikiContents)) + ? ''."\n" : ''; + + $template = str_replace(array('{LANGUAGE}', '{ENCODING}', '{TEXT_DIRECTION}', '{TITLE}', '{CSS}', '{ASCIIMATHML_SCRIPT}'), + array(api_get_language_isocode(), api_get_system_encoding(), api_get_text_direction(), $wikiTitle, $css, $asciimathmal_script), + $template); if (0 != $groupId) {