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

Revision 2, 2.4 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         if (!isset($page_template_cache)) {
17             $page_template_cache = array();
18         }
19         
20     // Get template details
21         if (!isset($template_id)) {
22             if (!isset($page_owner) || $page_owner == -1) {
23                 $template_id = -1;
24             } else {
25                 // if (!isset($_SESSION['template_id_cache'][$page_owner])) {
26                     $template_id = db_query("select template_id from users where ident = " . $page_owner);
27                     if (sizeof($template_id) > 0) {
28                         $template_id = $page_template_id[0]->template_id;
29                     } else {
30                         $template_id = -1;
31                     }
32                 // }
33                 // $template_id = $_SESSION['template_id_cache'][$page_owner];
34             }
35         }
36         
37     // Template ID override
38         if (isset($_REQUEST['template_preview'])) {
39             $template_id = (int) $_REQUEST['template_preview'];
40         }
41         
42     // Grab the template content
43         if ($template_id == -1) {
44             $template_element = $template[$parameter['context']];
45         } else {
46             $template_context = addslashes($parameter['context']);
47                 if (!isset($page_template_cache[$template_context])) {
48                     $page_template_cache[$template_context] = db_query("select * from template_elements where template_id = $template_id and name = '$template_context'");
49                 }
50                 
51                 $result = $page_template_cache[$template_context];
52                 echo "<pre>" . var_export($page_template_cache,true) . "</pre>";
53
54                 if (sizeof($result) > 0) {
55                     $template_element = stripslashes($result[0]->content);
56                 } else {
57                     $template_element = $template[$parameter['context']];
58                 }
59         }
60
61     // Substitute elements
62
63         $functionbody = "
64             \$passed = array(".var_export($parameter,true).",\$matches[1], " . $template_id . ");
65             return run('templates:variables:substitute', \$passed);
66         ";
67         
68         // $template_element = run("templates:variables:substitute",array($parameter,$template_element));
69         $body = preg_replace_callback("/\{\{([A-Za-z_0-9]*)\}\}/i",create_function('$matches',$functionbody),$template_element);
70         
71         $run_result = $body;
72         
73 ?>
Note: See TracBrowser for help on using the browser.