Beispiel #1
0
/**
 * Runs the first stage of the Phorum template processing. In this stage,
 * all (static) {include <template>} statements are recursively resolved.
 * After resolving all includes, a complete single template is constructed.
 * During this process, the function will keep track of all file
 * dependencies for the constructed template.
 *
 * @param $infile - The template file to process.
 * @param $include_depth - Current include depth (only for recursive call).
 * @param $deps - File dependencies (only for recursive call)
 * @param $include_once - Already include pages (only for recursive call)
 * @return $template - The constructed template data.
 * @return $dependencies - An array containing file dependencies for the
 *     created template data. The keys are filenames and the values are
 *     file modification times.
 */
function phorum_import_template_pass1($infile, $include_depth = 0, $deps = array(), $include_once = array())
{
    $include_depth++;
    if ($include_depth > PHORUM_TEMPLATES_MAX_INCLUDE_DEPTH) {
        trigger_error("phorum_import_template_pass1: the include depth has passed " . "the maximum allowed include depth of " . PHORUM_TEMPLATES_MAX_INCLUDE_DEPTH . ". Maybe some circular " . "include loop was introduced? If not, then you can raise the " . "value for the PHORUM_TEMPLATES_MAX_INCLUDE_DEPTH definition " . "in " . htmlspecialchars(__FILE__) . ".", E_USER_ERROR);
    }
    $deps[$infile] = filemtime($infile);
    $template = phorum_read_file($infile);
    // Process {include [once] "page"} statements in the template.
    preg_match_all("/\\{include\\s+(.+?)\\}/is", $template, $matches);
    for ($i = 0; $i < count($matches[0]); $i++) {
        $tokens = phorum_tokenize_statement($matches[1][$i]);
        // Find out if we have a static value for the include statement.
        // Dynamic values are handled in pass 2.
        $only_once = false;
        if (strtolower($tokens[0]) == "once" && isset($tokens[1])) {
            $only_once = true;
            array_shift($tokens);
        }
        list($page, $type) = phorum_templatevalue_to_php(NULL, $tokens[0]);
        if ($type == "variable" || $type == "constant") {
            continue;
        }
        // Since $value contains PHP code now, we have to resolve that
        // code into a real value.
        eval("\$page = {$page};");
        if ($only_once && isset($include_once[$page])) {
            $replace = '';
        } else {
            list($subout, $subin) = phorum_get_template_file($page);
            if ($subin == NULL) {
                $replace = phorum_read_file($subout);
            } else {
                list($replace, $deps) = phorum_import_template_pass1($subin, $include_depth, $deps, $include_once);
            }
            $include_once[$page] = true;
        }
        $template = str_replace($matches[0][$i], $replace, $template);
    }
    return array($template, $deps);
}
Beispiel #2
0
                 $r['cache_key'] = $mtime;
                 $module_registrations[$id]['cache_key'] = $mtime;
             }
             break;
         case "template":
             // We load the parsed template into memory. This will refresh
             // the cached template file if required. This is the easiest
             // way to make this work correctly for nested template files.
             ob_start();
             include phorum_get_template($m[2]);
             $module_registrations[$id]['content'] = ob_get_contents();
             ob_end_clean();
             // We use the mtime of the compiled template as the cache
             // key if no specific cache key was set.
             if (!isset($r['cache_key'])) {
                 list($m[2], $php, $tpl) = phorum_get_template_file($m[2]);
                 $mtime = @filemtime($php);
                 $r['cache_key'] = $mtime;
                 $module_registrations[$id]['cache_key'] = $mtime;
             }
             break;
         case "function":
             if (!isset($r['cache_key'])) {
                 trigger_error("css_register hook: module registration error: " . "\"cache_key\" field missing for source " . "\"{$r['source']}\" in module \"{$r['module']}\".");
                 exit(1);
             }
             break;
     }
 } else {
     trigger_error("css_register hook: module registration error: " . "illegal format for source definition \"{$r['source']}\" " . "in module \"{$r['module']}\".");
     exit(1);
Beispiel #3
0
/**
 * Returns the PHP file to include for a template file. This function will
 * automatically compile .tpl files if no compiled template is available.
 *
 * If the format for the template file is <module>::<template>, then
 * the template is loaded from the module's directory. The directory
 * structure for storing module templates is the same as for the
 * main templates directory, only it is stored within a module's
 * directory:
 *
 * <phorum_dir>/mods/templates/<template name>/<page>.tpl
 *
 * @param $page - The template base name (e.g. "header", "css", etc.).
 * @return $phpfile - The PHP file to include for showing the template.
 */
function phorum_get_template($page)
{
    // This might for example happen if a template contains code like
    // {INCLUDE template} instead of {INCLUDE "template"}.
    if ($page === NULL || $page == "") {
        print "<h1>Phorum Template Error</h1>";
        print "phorum_get_template() was called with an empty page name.<br/>";
        print "This might indicate a template problem.<br/>";
        if (function_exists('debug_print_backtrace')) {
            print "Here's a backtrace that might help finding the error:";
            print "<pre>";
            debug_print_backtrace();
            print "</pre>";
        }
        exit(1);
    }
    list($page, $phpfile, $tplfile) = phorum_get_template_file($page);
    // No template to pre-process.
    if ($tplfile == NULL) {
        return $phpfile;
    }
    // Pre-process template if the output file isn't available.
    if (!file_exists($phpfile)) {
        require_once "./include/templates.php";
        phorum_import_template($page, $tplfile, $phpfile);
    }
    return $phpfile;
}