コード例 #1
0
function templates_draw($parameter)
{
    // Draw a page element using a specified template (or, if the template is -1, the default)
    // $parameter['template'] = the template ID, $parameter['element'] = the template element,
    // all other $parameter[n] = template elements
    // Initialise global template variable, which contains the Default_Template
    global $template;
    // Initialise global template ID variable, which contains the template ID we're using
    global $template_name;
    global $page_owner;
    global $CFG;
    global $page_template_cache;
    $run_result = '';
    if ($parameter['context'] === 'topmenuitem') {
        // error_log("templates_draw pcontext " . print_r($parameter,1));
    }
    // Get template details
    if (!isset($template_name)) {
        if (!isset($page_owner) || $page_owner == -1) {
            $template_name = "Default_Template";
        } else {
            if (!($template_name = user_info('template_name', $page_owner))) {
                $template_name = "Default_Template";
            }
        }
    }
    // Template ID override
    $t = optional_param('template_preview');
    if (!empty($t)) {
        $template_name = $t;
    }
    // TODO: Load templates on demand with backward compatibility
    templates_load_context($parameter['context']);
    // Grab the template content
    if ($template_name == "Default_Template" || $parameter['context'] != "css" && $parameter['context'] != "pageshell") {
        $template_element = $template[$parameter['context']];
    } else {
        if (!isset($page_template_cache[$parameter['context']])) {
            if ($result = get_template_element($template_name, $parameter['context'])) {
                $page_template_cache[$parameter['context']] = $result;
            } else {
                $page_template_cache[$parameter['context']] = $template[$parameter['context']];
            }
        } else {
            $result = $page_template_cache[$parameter['context']];
        }
        if (!empty($result)) {
            $template_element = $result->content;
        } else {
            $template_element = $template[$parameter['context']];
        }
    }
    if (!empty($CFG->templates->variables_substitute) && !empty($CFG->templates->variables_substitute[$parameter['context']])) {
        if (is_array($CFG->templates->variables_substitute[$parameter['context']])) {
            foreach ($CFG->templates->variables_substitute[$parameter['context']] as $sub_function) {
                $template_element .= $sub_function($vars);
            }
        } elseif (is_callable($CFG->templates->variables_substitute[$parameter['context']])) {
            $template_element .= $CFG->templates->variables_substitute[$parameter['context']]($vars);
        }
    }
    if ($parameter['context'] === 'topmenuitem') {
        // error_log("templates_draw pcontext " . print_r($template_element));
    }
    // Substitute elements
    $functionbody = "\n            \$passed = array(" . var_export($parameter, true) . ",\$matches[1], '" . $template_name . "');\n            return templates_variables_substitute(\$passed);\n        ";
    // $template_element = templates_variables_substitute(array($parameter,$template_element));
    $body = preg_replace_callback("/\\{\\{([A-Za-z_0-9: ]*)\\}\\}/i", create_function('$matches', $functionbody), $template_element);
    $run_result = $body;
    return $run_result;
}
コード例 #2
0
ファイル: templates.php プロジェクト: pzingg/saugus_elgg
function templates_draw($parameter)
{
    // Draw a page element using a specified template (or, if the template is -1, the default)
    // $parameter['template'] = the template ID, $parameter['element'] = the template element,
    // all other $parameter[n] = template elements
    // Initialise global template variable, which contains the default template
    global $template;
    // Initialise global template ID variable, which contains the template ID we're using
    global $template_id;
    global $page_owner;
    global $page_template_cache;
    $run_result = '';
    if ($parameter['context'] === 'topmenuitem') {
        // error_log("templates_draw pcontext " . print_r($parameter,1));
    }
    // Get template details
    if (!isset($template_id)) {
        if (!isset($page_owner) || $page_owner == -1) {
            $template_id = -1;
        } else {
            // if (!isset($_SESSION['template_id_cache'][$page_owner])) {
            if (!($template_id = get_field('users', 'template_id', 'ident', $page_owner))) {
                $template_id = -1;
            }
            // }
            // $template_id = $_SESSION['template_id_cache'][$page_owner];
        }
    }
    // Template ID override
    $t = optional_param('template_preview', 0, PARAM_INT);
    if (!empty($t)) {
        $template_id = $t;
    }
    // Grab the template content
    if ($template_id == -1 || $parameter['context'] != "css" && $parameter['context'] != "pageshell") {
        $template_element = $template[$parameter['context']];
    } else {
        $template_context = addslashes($parameter['context']);
        if (!isset($page_template_cache[$parameter['context']])) {
            $result = get_template_element($template_id, $template_context);
            $page_template_cache[$parameter['context']] = $result;
        } else {
            $result = $page_template_cache[$parameter['context']];
        }
        if (!empty($result)) {
            $template_element = stripslashes($result->content);
        } else {
            $template_element = $template[$parameter['context']];
        }
    }
    if ($parameter['context'] === 'topmenuitem') {
        // error_log("templates_draw pcontext " . print_r($template_element));
    }
    // Substitute elements
    $functionbody = "\r\n            \$passed = array(" . var_export($parameter, true) . ",\$matches[1], " . $template_id . ");\r\n            return templates_variables_substitute(\$passed);\r\n        ";
    // $template_element = templates_variables_substitute(array($parameter,$template_element));
    $body = preg_replace_callback("/\\{\\{([A-Za-z_0-9]*)\\}\\}/i", create_function('$matches', $functionbody), $template_element);
    $run_result = $body;
    return $run_result;
}