Beispiel #1
0
function phorum_get_template( $page, $is_include = false )
{
    $PHORUM = $GLOBALS["PHORUM"];

    if ( ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) && isset( $PHORUM['user']['user_template'] ) && !empty($PHORUM['user']['user_template'])) {
        $PHORUM['template'] = $PHORUM['user']['user_template'];
    }

    // If no user template is set or if the template folder cannot be found,
    // fallback to the default template.
    if (empty($PHORUM["template"]) || !file_exists("./templates/{$PHORUM['template']}")) {
        $PHORUM["template"] = $PHORUM["default_template"];
    }

    $tpl = "./templates/$PHORUM[template]/$page";
    // check for straight PHP file
    if ( file_exists( "$tpl.php" ) ) {
        $phpfile = "$tpl.php";
    } else {
        // not there, look for a template
        $tplfile = "$tpl.tpl";
        $safetemplate = str_replace("-", "_", $PHORUM["template"]);
        $safepage = str_replace("-", "_", $page);
        $phpfile = "$PHORUM[cache]/tpl-$safetemplate-$safepage-" .
               ($is_include ? "include" : "toplevel") . "-" .
               md5( dirname( __FILE__ ) ) . ".php";

        if ( $is_include || !file_exists( $phpfile ) ) {
            include_once "./include/templates.php";
            phorum_import_template( $tplfile, $phpfile );
        }
    }

    return $phpfile;
}
Beispiel #2
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;
}