root/releases/0.1.1b/units/templates/template_draw.php

Revision 2, 2.3 kB (checked in by sven, 3 years ago)

importing elgg-0.1.1a

Line 
1 <?php
2
3     // Draw a page element using a specified template (or, if the template is -1, the default)
4     // $parameter['template'] = the template ID, $parameter['element'] = the template element,
5     // all other $parameter[n] = template elements
6
7     // Initialise global template variable, which contains the default template
8         global $template;
9         
10     // Initialise global template ID variable, which contains the template ID we're using
11         global $template_id;
12         global $page_owner;
13         
14         global $page_template_cache;
15         
16         
17     // Get template details
18         if (!isset($template_id)) {
19             if (!isset($page_owner) || $page_owner == -1) {
20                 $template_id = -1;
21             } else {
22                 // if (!isset($_SESSION['template_id_cache'][$page_owner])) {
23                     $template_id = db_query("select template_id from users where ident = " . $page_owner);
24                     if (sizeof($template_id) > 0) {
25                         $template_id = $template_id[0]->template_id;
26                     } else {
27                         $template_id = -1;
28                     }
29                 // }
30                 // $template_id = $_SESSION['template_id_cache'][$page_owner];
31             }
32         }
33         
34     // Template ID override
35         if (isset($_REQUEST['template_preview'])) {
36             $template_id = (int) $_REQUEST['template_preview'];
37         }
38         
39     // Grab the template content
40         if ($template_id == -1) {
41             $template_element = $template[$parameter['context']];   
42         } else {
43             $template_context = addslashes($parameter['context']);
44                 if (!isset($page_template_cache[$parameter['context']])) {
45                     $result = db_query("select * from template_elements where template_id = $template_id and name = '$template_context'");
46                     $page_template_cache[$parameter['context']] = $result;
47                 } else {
48                     $result = $page_template_cache[$parameter['context']];
49                 }
50                 if (sizeof($result) > 0) {
51                     $template_element = stripslashes($result[0]->content);
52                 } else {
53                     $template_element = $template[$parameter['context']];
54                 }
55         }
56
57     // Substitute elements
58
59         $functionbody = "
60             \$passed = array(".var_export($parameter,true).",\$matches[1], " . $template_id . ");
61             return run('templates:variables:substitute', \$passed);
62         ";
63         
64         // $template_element = run("templates:variables:substitute",array($parameter,$template_element));
65         $body = preg_replace_callback("/\{\{([A-Za-z_0-9]*)\}\}/i",create_function('$matches',$functionbody),$template_element);
66         
67         $run_result = $body;
68         
69 ?>
Note: See TracBrowser for help on using the browser.