Exemplo n.º 1
0
/**
 * Converts a Phorum template into PHP code and writes the resulting code
 * to disk. This is the only call from templates.php that is called from
 * outside this file. All other functions are used internally for the
 * template compiling process.
 *
 * @param $page - The template page name (as used for phorum_get_template())
 * @param $infile - The template input file to process
 * @param $outfile - The PHP file to write the resulting code to.
 */
function phorum_import_template($page, $infile, $outfile)
{
    // Template pass 1:
    // Recursively process all template {include ...} statements, to
    // construct a single template data block.
    list($template, $dependencies) = phorum_import_template_pass1($infile);
    // Template pass 2:
    // Translate all other template statements into PHP code.
    $template = phorum_import_template_pass2($template);
    // Write the compiled template to disk.
    //
    // For storing the compiled template, we use two files. The first one
    // has some code for checking if one of the dependent files has been
    // updated and for rebuilding the template if this is the case.
    // This one loads the second file, which is the compiled template itself.
    //
    // This two-stage loading is needed to make sure that syntax
    // errors in a template file won't break the depancy checking process.
    // If both were in the same file, the complete file would not be run
    // at all and the user would have to clean out the template cache to
    // reload the template once it was fixed. This way user intervention
    // is never needed.
    $stage1file = $outfile;
    $stage2file = $outfile . "-stage2";
    $qstage1file = addslashes($stage1file);
    $qstage2file = addslashes($stage2file);
    // Output file for stage 1. This file contains code to check the file
    // dependencies. If one of the files that the template depends on is
    // changed, the template has to be rebuilt. Also rebuild in case the
    // second stage compiled template is missing.
    $checks = array();
    $checks[] = "!file_exists(\"{$qstage2file}\")";
    foreach ($dependencies as $file => $mtime) {
        $qfile = addslashes($file);
        $checks[] = "@filemtime(\"{$qfile}\") != {$mtime}";
    }
    $qpage = addslashes($page);
    $stage1 = "<?php\n      if (" . implode(" || ", $checks) . ") {\n          @unlink (\"{$qstage1file}\");\n          include(phorum_get_template(\"{$qpage}\"));\n          return;\n      } else {\n          include(\"{$qstage2file}\");\n      }\n      ?>";
    phorum_write_file($stage1file, $stage1);
    // Output file for stage 2. This file contains the compiled template.
    phorum_write_file($stage2file, $template);
}
Exemplo n.º 2
0
        }
        if ($r['where'] == 'before') {
            $before .= $before == '' ? $add : "\n\n{$add}";
        } else {
            $after .= "\n\n{$add}";
        }
    }
    $content = "{$before}\n{$base}\n{$after}";
    // Compress the CSS code.
    if (PHORUM_COMPRESS_CSS) {
        $content = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $content);
        $content = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $content);
    }
    if (!empty($PHORUM['cache_css'])) {
        require_once './include/templates.php';
        phorum_write_file($cache_file, $content);
    }
    // Send the CSS to the browser.
    header("Content-Type: text/css");
    print $content;
    // Exit here explicitly for not giving back control to portable and
    // embedded Phorum setups.
    exit(0);
}
// Find the modification time for the cache file.
$last_modified = @filemtime($cache_file);
// Check if a If-Modified-Since header is in the request. If yes, then
// check if the CSS code has changed, based on the filemtime() data from
// above. If nothing changed, then we can return a 304 header, to tell the
// browser to use the cached data.
if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {