init
[garradin.git] / include / libs / template_lite / internal / compile.compile_custom_function.php
1 <?php
2 /**
3 * Template Lite compile custom function - template internal module
4 *
5 * Type: template
6 * Name: compile_custom_function
7 */
8
9 function compile_compile_custom_function($function, $modifiers, $arguments, &$_result, &$object)
10 {
11 if ($function = $object->_plugin_exists($function, "function"))
12 {
13 $_args = $object->_parse_arguments($arguments);
14 foreach($_args as $key => $value)
15 {
16 if (is_bool($value))
17 {
18 $value = $value ? 'true' : 'false';
19 }
20 elseif (is_null($value))
21 {
22 $value = 'null';
23 }
24 elseif ($value[0] != '$' && $value[0] != '"')
25 {
26 $value = '"'.addslashes($value).'"';
27 }
28
29 $_args[$key] = "'$key' => $value";
30 }
31
32 if (is_array($function))
33 {
34 if (!is_string($function[0]))
35 {
36 throw new Template_Exception("Unsupported callback.");
37 }
38
39 $function = implode('::', $function);
40 }
41
42 $_result = '<?php echo ';
43 if (!empty($modifiers))
44 {
45 $_result .= $object->_parse_modifier($function . '(array(' . implode(',', (array)$_args) . '), $this)', $modifiers) . '; ';
46 }
47 else
48 {
49 $_result .= $function . '(array(' . implode(',', (array)$_args) . '), $this);';
50 }
51 $_result .= '?>';
52 return true;
53 }
54 else
55 {
56 return false;
57 }
58 }
59
60 ?>