/
class.T.php
70 lines (60 loc) · 1.73 KB
/
class.T.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
67
68
69
70
<?php
class T {
/**************** PRIVATE ****************/
private static $_aJs = [];
private static $_aCss = [];
private static function _findJsFile($sTemplate) {
if ($aDirs = M::TEMPLATE_JS()) {
foreach ($aDirs as $sDir) {
$sPath = M::PROJECT_ROOT() . '/' . $sDir . '/tpl.' . $sTemplate . '.js';
if (file_exists($sPath)) {
self::$_aJs[$sTemplate] = $sPath;
return;
}
}
}
}
private static function _findCssFile($sTemplate) {
if ($aDirs = M::TEMPLATE_CSS()) {
foreach ($aDirs as $sDir) {
$sPath = M::PROJECT_ROOT() . '/' . $sDir . '/tpl.' . $sTemplate . '.css';
if (file_exists($sPath)) {
self::$_aCss[$sTemplate] = $sPath;
return;
}
}
}
}
/**************** PUBLIC ****************/
public static function __callStatic($sTemplate, $aArgs) {
if ($aDirs = M::TEMPLATE_PHP()) {
foreach ($aDirs as $sDir) {
$sPath = M::PROJECT_ROOT() . '/' . $sDir . '/tpl.' . $sTemplate . '.php';
if (file_exists($sPath)) {
self::_findJsFile($sTemplate);
self::_findCssFile($sTemplate);
if (isset($aArgs[0])) {
print Processor::evalString(file_get_contents($sPath), $aArgs[0]);
}
return;
}
}
}
throw new Exception("Template \"$sTemplate\" is not found");
}
public static function getJs() {
$sJs = '';
foreach (self::$_aJs as $sTemplate => $sFileName) {
$sJs .= "/***** $sTemplate *****/\n" . file_get_contents($sFileName) . "\n";
}
return $sJs;
}
public static function getCss() {
$sCss = '';
foreach (self::$_aCss as $sTemplate => $sFileName) {
$sCss .= "/***** $sTemplate *****/\n" . file_get_contents($sFileName) . "\n";
}
return $sCss;
}
}
?>