1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Checks whether an extended file has been modified, and if so recompiles the current template. This is for internal use only, do not use. |
---|
5 | * |
---|
6 | * This software is provided 'as-is', without any express or implied warranty. |
---|
7 | * In no event will the authors be held liable for any damages arising from the use of this software. |
---|
8 | * |
---|
9 | * @author Jordi Boggiano <j.boggiano@seld.be> |
---|
10 | * @copyright Copyright (c) 2008, Jordi Boggiano |
---|
11 | * @license http://dwoo.org/LICENSE Modified BSD License |
---|
12 | * @link http://dwoo.org/ |
---|
13 | * @version 1.1.0 |
---|
14 | * @date 2009-07-18 |
---|
15 | * @package Dwoo |
---|
16 | */ |
---|
17 | function Dwoo_Plugin_extendsCheck_compile(Dwoo_Compiler $compiler, $file) |
---|
18 | { |
---|
19 | preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m); |
---|
20 | $resource = $m[1]; |
---|
21 | $identifier = $m[2]; |
---|
22 | |
---|
23 | $tpl = $compiler->getDwoo()->templateFactory($resource, $identifier); |
---|
24 | |
---|
25 | if ($tpl === null) { |
---|
26 | throw new Dwoo_Compilation_Exception($compiler, 'Load Templates : Resource "'.$resource.':'.$identifier.'" not found.'); |
---|
27 | } elseif ($tpl === false) { |
---|
28 | throw new Dwoo_Compilation_Exception($compiler, 'Load Templates : Resource "'.$resource.'" does not support includes.'); |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | $out = '\'\';// checking for modification in '.$resource.':'.$identifier."\r\n"; |
---|
33 | |
---|
34 | $modCheck = $tpl->getIsModifiedCode(); |
---|
35 | |
---|
36 | if ($modCheck) { |
---|
37 | $out .= 'if (!('.$modCheck.')) { ob_end_clean(); return false; }'; |
---|
38 | } else { |
---|
39 | $out .= 'try { |
---|
40 | $tpl = $this->templateFactory("'.$resource.'", "'.$identifier.'"); |
---|
41 | } catch (Dwoo_Exception $e) { |
---|
42 | $this->triggerError(\'Load Templates : Resource <em>'.$resource.'</em> was not added to Dwoo, can not extend <em>'.$identifier.'</em>\', E_USER_WARNING); |
---|
43 | } |
---|
44 | if ($tpl === null) |
---|
45 | $this->triggerError(\'Load Templates : Resource "'.$resource.':'.$identifier.'" was not found.\', E_USER_WARNING); |
---|
46 | elseif ($tpl === false) |
---|
47 | $this->triggerError(\'Load Templates : Resource "'.$resource.'" does not support extends.\', E_USER_WARNING); |
---|
48 | if ($tpl->getUid() != "'.$tpl->getUid().'") { ob_end_clean(); return false; }'; |
---|
49 | } |
---|
50 | |
---|
51 | return $out; |
---|
52 | } |
---|