-
Notifications
You must be signed in to change notification settings - Fork 5
/
view.php
executable file
·66 lines (59 loc) · 1.48 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require_once ('vtpl/vtpl.php') ;
#[\AllowDynamicProperties]
class View
{
/**
* private variable that holds the instance handle
*/
static private $instance = NULL;
/**
* This is the only way to get a instantce of the class
*/
static function get_instance() {
if (self :: $instance === NULL)
{
self :: $instance = new view(); //create class instance
}
return self :: $instance;
}
function set($array) {
if ($array)
foreach($array as $key => $value) {
$this->$key = $value;
}
}
/**
* Declare the constructor private to avoid object initialization, this is a singleton
*/
private function __construct() {
}
private function recompile($filename, $file) {
$vtpl = new Vtpl();
$vtpl->addTemplatePath(PATH . '/templates/');
$vtpl->htmlPath = PATH . '/html/';
$vtpl->loadHtmlTemplate($filename);
$vtpl->loadTemplateFileFromPath(str_replace('.html','.tpl',$filename));
$vtpl->saveCompiledTemplate($file);
}
/**
* Renders the specified file (html)
*
* @param string @filename
*/
function render( $filename = null ) {
$file = PATH . '/compiled_templates/' . $filename;
$htmlFile = PATH . '/html/'. $filename;
$templateFile = PATH . '/templates/'. str_replace('.html','.tpl',$filename);
if (
!file_exists($file)
|| (max(@filemtime($htmlFile),
@filemtime($templateFile))
> @filemtime($file))
|| (defined('VTPL_DEBUG') && VTPL_DEBUG))
{
self :: recompile($filename, $file);
}
include_once($file);
}
}