1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Inserts another template into the current one |
---|
5 | * <pre> |
---|
6 | * * file : the resource name of the template |
---|
7 | * * cache_time : cache length in seconds |
---|
8 | * * cache_id : cache identifier for the included template |
---|
9 | * * compile_id : compilation identifier for the included template |
---|
10 | * * data : data to feed into the included template, it can be any array and will default to $_root (the current data) |
---|
11 | * * assign : if set, the output of the included template will be saved in this variable instead of being output |
---|
12 | * * rest : any additional parameter/value provided will be added to the data array |
---|
13 | * </pre> |
---|
14 | * This software is provided 'as-is', without any express or implied warranty. |
---|
15 | * In no event will the authors be held liable for any damages arising from the use of this software. |
---|
16 | * |
---|
17 | * @author Jordi Boggiano <j.boggiano@seld.be> |
---|
18 | * @copyright Copyright (c) 2008, Jordi Boggiano |
---|
19 | * @license http://dwoo.org/LICENSE Modified BSD License |
---|
20 | * @link http://dwoo.org/ |
---|
21 | * @version 1.1.0 |
---|
22 | * @date 2009-07-18 |
---|
23 | * @package Dwoo |
---|
24 | */ |
---|
25 | function Dwoo_Plugin_include(Dwoo_Core $dwoo, $file, $cache_time = null, $cache_id = null, $compile_id = null, $data = '_root', $assign = null, array $rest = array()) |
---|
26 | { |
---|
27 | if ($file === '') { |
---|
28 | return; |
---|
29 | } |
---|
30 | |
---|
31 | if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) { |
---|
32 | // resource:identifier given, extract them |
---|
33 | $resource = $m[1]; |
---|
34 | $identifier = $m[2]; |
---|
35 | } else { |
---|
36 | // get the current template's resource |
---|
37 | $resource = $dwoo->getTemplate()->getResourceName(); |
---|
38 | $identifier = $file; |
---|
39 | } |
---|
40 | |
---|
41 | try { |
---|
42 | $include = $dwoo->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id); |
---|
43 | } catch (Dwoo_Security_Exception $e) { |
---|
44 | return $dwoo->triggerError('Include : Security restriction : '.$e->getMessage(), E_USER_WARNING); |
---|
45 | } catch (Dwoo_Exception $e) { |
---|
46 | return $dwoo->triggerError('Include : '.$e->getMessage(), E_USER_WARNING); |
---|
47 | } |
---|
48 | |
---|
49 | if ($include === null) { |
---|
50 | return $dwoo->triggerError('Include : Resource "'.$resource.':'.$identifier.'" not found.', E_USER_WARNING); |
---|
51 | } elseif ($include === false) { |
---|
52 | return $dwoo->triggerError('Include : Resource "'.$resource.'" does not support includes.', E_USER_WARNING); |
---|
53 | } |
---|
54 | |
---|
55 | if (is_string($data)) { |
---|
56 | $vars = $dwoo->readVar($data); |
---|
57 | } else { |
---|
58 | $vars = $data; |
---|
59 | } |
---|
60 | |
---|
61 | if (count($rest)) { |
---|
62 | $vars = $rest + $vars; |
---|
63 | } |
---|
64 | |
---|
65 | $clone = clone $dwoo; |
---|
66 | $out = $clone->get($include, $vars); |
---|
67 | |
---|
68 | if ($assign !== null) { |
---|
69 | $dwoo->assignInScope($out, $assign); |
---|
70 | } |
---|
71 | |
---|
72 | foreach ($clone->getReturnValues() as $name => $value) { |
---|
73 | $dwoo->assignInScope($value, $name); |
---|
74 | } |
---|
75 | |
---|
76 | if ($assign === null) { |
---|
77 | return $out; |
---|
78 | } |
---|
79 | } |
---|