Daan is sweet to Kelley and delegates himself TestCMS code reflection
[ssproject1617.git] / testcms-final-anon / system / classes / template.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 class Template {
4
5 private static $path;
6
7 public static function path($path = '') {
8 if(empty($path)) {
9 return static::$path;
10 }
11
12 static::$path = $path;
13 }
14
15 private static function parse($file, $data) {
16 // render content into response
17 ob_start();
18
19 // extract vars
20 extract($data, EXTR_SKIP);
21
22 require $file;
23
24 Response::append(ob_get_contents());
25
26 ob_end_clean();
27 }
28
29 public static function render($template, $data = array()) {
30 // get default theme
31 $theme = Config::get('metadata.theme');
32
33 // load global theming functions but not for the admin template
34 if(strpos(static::$path, 'system/admin/theme') === false) {
35 require PATH . 'system/functions/articles.php';
36 require PATH . 'system/functions/comments.php';
37 require PATH . 'system/functions/helpers.php';
38 require PATH . 'system/functions/menus.php';
39 require PATH . 'system/functions/metadata.php';
40 require PATH . 'system/functions/pages.php';
41 require PATH . 'system/functions/posts.php';
42 require PATH . 'system/functions/search.php';
43 require PATH . 'system/functions/users.php';
44 }
45
46 // load theme functions
47 if(file_exists(static::$path . 'functions.php')) {
48 require static::$path . 'functions.php';
49 }
50
51 // render files
52 foreach(array('includes/header', $template, 'includes/footer') as $file) {
53 $filepath = static::$path . $file . '.php';
54
55 if(file_exists($filepath) === false) {
56 throw new ErrorException('Theme file <strong>themes/' . $theme . '/' . $file . '.php</strong> not found.');
57 }
58
59 static::parse($filepath, $data);
60 }
61 }
62
63 }