| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 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 |
|
|---|
| 11 |
global $template_id; |
|---|
| 12 |
global $page_owner; |
|---|
| 13 |
|
|---|
| 14 |
global $page_template_cache; |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
if (!isset($template_id)) { |
|---|
| 19 |
if (!isset($page_owner) || $page_owner == -1) { |
|---|
| 20 |
$template_id = -1; |
|---|
| 21 |
} else { |
|---|
| 22 |
|
|---|
| 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 |
|
|---|
| 35 |
if (isset($_REQUEST['template_preview'])) { |
|---|
| 36 |
$template_id = (int) $_REQUEST['template_preview']; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 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 |
|
|---|
| 58 |
|
|---|
| 59 |
$functionbody = " |
|---|
| 60 |
\$passed = array(".var_export($parameter,true).",\$matches[1], " . $template_id . "); |
|---|
| 61 |
return run('templates:variables:substitute', \$passed); |
|---|
| 62 |
"; |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
$body = preg_replace_callback("/\{\{([A-Za-z_0-9]*)\}\}/i",create_function('$matches',$functionbody),$template_element); |
|---|
| 66 |
|
|---|
| 67 |
$run_result = $body; |
|---|
| 68 |
|
|---|
| 69 |
?> |
|---|