Exemplo n.º 1
0
     if (!$hide) {
         $pdfhtml .= "<!-- Start of module content -->\n<h3>{$instancelogo} {$fullinstancename}</h3>\n";
     }
     // Render the module.
     $requesturl = $CFG->wwwroot . "/local/compile/mod/" . $mod->modname . "/compile.php?id=" . $mod->id;
     $htmlpage = compile_get_mod_html($requesturl);
     if ($compilepdf) {
         // Need to remove references to dynamically generated images, because they can break the external PDF engine.
         $htmlpage = preg_replace('/<img.*?class="userpicture.*?>/', '', $htmlpage);
         // Get rid of any references to 'Separate Groups'.
         $htmlpage = preg_replace('/<div class="groupselector">.*?<\\/form><\\/div>/', '', $htmlpage);
         $htmlpage = compile_update_image_source($htmlpage, $mod->modname, $mod->id, 'pluginfile.php');
         $htmlpage = compile_update_image_source($htmlpage, $mod->modname, $mod->id, 'file.php');
         $pdfhtml .= $htmlpage;
     } else {
         $htmlpage = compile_remove_blacklisted_links($htmlpage, $compilepdf);
         // Remove blacklisted links completely.
         $pdfhtml .= $htmlpage;
     }
 } else {
     // Have Moodle render the module's output as a complete HTML page, which we will
     // strip down to content afterward.
     if ($compilepdf) {
         $pdfhtml .= "<!-- Start of module content -->\n<h3>{$fullinstancename}</h3>\n";
     } else {
         $pdfhtml .= "<!-- Start of module content -->\n<h3>{$instancelogo} {$fullinstancename}</h3>\n";
     }
     // Render the module.
     $requesturl = $CFG->wwwroot . "/mod/" . $mod->modname . "/view.php?id=" . $mod->id;
     $htmlpage = compile_get_mod_html($requesturl);
     // Remove header, footer, and other uncompilable elements.
Exemplo n.º 2
0
/**
 * Clean up some common issues in Moodle-rendered module output HTML.
 *
 * @author Gerald Albion
 * @param string $htmlpage The HTML to be cleaned up
 * @param boolean $compilepdf TRUE if the compile target is PDF
 * @return string The cleaned-up HTML.
 */
function compile_cleanup_rendered($htmlpage, $compilepdf)
{
    define('HTAG_LIMIT', 120);
    // How far into the rendered module to look for redundant headers.
    // We're only interested in the content of the page, so we use a regular expression to select it.
    preg_match('/<span id="maincontent">.*?<\\/span>(.*)<\\/div>.*?<\\/div>.*?<\\/section>/ims', $htmlpage, $content);
    // Initialize regex matches array.
    $cleaned = array();
    // Using a second regex to get rid of the final </div> tag.
    $tempcontent = array_key_exists(1, $content) ? $content[1] : '';
    preg_match('/(.*)\\t*<\\/div>\\t*/ims', $tempcontent, $cleaned);
    $tempcleaned = array_key_exists(1, $cleaned) ? $cleaned[1] : '';
    // Added by ga 2014-02-25.
    // Remove redundant headers:
    // If there is an <h2> or <h3> in the first 120 chars, strip it.
    // Allow for the possibility of up to two of each.
    $tempcleaned = compile_strip_first_tag($tempcleaned, '<h2>', '</h2>', HTAG_LIMIT);
    $tempcleaned = compile_strip_first_tag($tempcleaned, '<h3>', '</h3>', HTAG_LIMIT);
    $tempcleaned = compile_strip_first_tag($tempcleaned, '<h2>', '</h2>', HTAG_LIMIT);
    $tempcleaned = compile_strip_first_tag($tempcleaned, '<h3>', '</h3>', HTAG_LIMIT);
    // Remove spurious <doctype>.
    $tempcleaned = compile_strip_first_tag($tempcleaned, '<doctype', '</doctype>');
    // Fix unbalanced <div> elements.
    $tempcleaned = compile_fix_unbalanced_divs($tempcleaned);
    // Remove admin links.
    $tempcleaned = compile_remove_admin_links($tempcleaned);
    $tempcleaned = compile_remove_blacklisted_links($tempcleaned, $compilepdf);
    // Remove blacklisted links completely.
    return $tempcleaned;
}