} else { $t->set_block('page', 'next_link_active', 'next_link_hide'); } } $ebook_body = ''; $ebook_head = ''; $dom = new DOMDocument(); @$dom->loadHTMLFile($basedir . $subsection_path[$current_sid][$current_ssid]); if (isset($_SESSION['glossary_terms_regexp']) and !empty($_SESSION['glossary_terms_regexp'])) { $xpath = new DOMXpath($dom); $textNodes = $xpath->query('//text()'); foreach ($textNodes as $textNode) { if (!empty($textNode->data)) { $new_contents = glossary_expand($textNode->data); if ($new_contents != $textNode->data) { $newdoc = new DOMDocument(); $newdoc->loadXML('<span>' . $new_contents . '</span>', LIBXML_NONET|LIBXML_DTDLOAD|LIBXML_DTDATTR); $newnode = $dom->importNode($newdoc->getElementsByTagName('span')->item(0), true); $textNode->parentNode->replaceChild($newnode, $textNode); } } } } foreach (array('link', 'style', 'script') as $tagname) { foreach ($dom->getElementsByTagName($tagname) as $element) { $ebook_head .= str_replace(array('<![CDATA[', ']]>'), array('', ''), dom_save_html($dom, $element)); } }
function standard_text_escape($text, $mathimg = '../../courses/mathimg/') { global $purifier; $text = preg_replace_callback('/\\[m\\].*?\\[\\/m\\]/s', 'math_unescape', $text); $html = $purifier->purify(mathfilter($text, 12, $mathimg)); if (!isset($_SESSION['glossary_terms_regexp'])) { return $html; } $dom = new DOMDocument(); // workaround because DOM doesn't handle utf8 encoding correctly. @$dom->loadHTML('<div>' . mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8') . '</div>'); $xpath = new DOMXpath($dom); $textNodes = $xpath->query('//text()'); foreach ($textNodes as $textNode) { if (!empty($textNode->data)) { $new_contents = glossary_expand($textNode->data); if ($new_contents != $textNode->data) { $newdoc = new DOMDocument(); $newdoc->loadXML('<span>' . $new_contents . '</span>', LIBXML_NONET | LIBXML_DTDLOAD | LIBXML_DTDATTR); $newnode = $dom->importNode($newdoc->getElementsByTagName('span')->item(0), true); $textNode->parentNode->replaceChild($newnode, $textNode); unset($newdoc); unset($newnode); } } } $base_node = $dom->getElementsByTagName('div')->item(0); // iframe hack return preg_replace(array('|^<div>(.*)</div>$|s', '#(<iframe [^>]+)/>#'), array('\\1', '\\1></iframe>'), dom_save_html($dom, $base_node)); }