Feature #2132 - Implementing automatic (when it is needed) inclusion of the script ASCIIMathML.js when a wiki-page is converted as full html document, stored in the Documents tool.

skala
Ivan Tcholakov 14 years ago
parent 601c373a5c
commit 3eb6125ecf
  1. 42
      main/inc/lib/text.lib.php
  2. 9
      main/wiki/wiki.inc.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('/<span[^>]*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('/<embed([^>]*?)>/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');
}
}

@ -1716,7 +1716,7 @@ function export2doc($wikiTitle, $wikiContents, $groupId)
{CSS}
/*]]>*/
</style>
</head>
{ASCIIMATHML_SCRIPT}</head>
<body dir="{TEXT_DIRECTION}">
{CONTENT}
</body>
@ -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))
? '<script src="'.api_get_path(TO_REL, SCRIPT_ASCIIMATHML).'" type="text/javascript"></script>'."\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)
{

Loading…
Cancel
Save