1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
14:
15: 16: 17: 18: 19: 20:
21: class cSmartyFrontend {
22:
23: 24: 25: 26: 27:
28: protected static $oSmarty;
29:
30: 31: 32: 33: 34:
35: public static $bSmartyInstanciated = false;
36:
37: 38: 39: 40: 41:
42: protected static $aDefaultPaths = array();
43:
44: 45: 46: 47: 48: 49: 50: 51: 52: 53:
54: public function __construct(&$aCfg, &$aClientCfg, $bSanityCheck = false) {
55:
56: if (isset(self::$bSmartyInstanciated) && self::$bSmartyInstanciated) {
57: throw new cException("cSmartyFrontend class is intended to be used as singleton. Do not instanciate multiple times.");
58: }
59:
60: if (!is_array($aCfg)) {
61: throw new cInvalidArgumentException(__CLASS__ . " " . __FUNCTION__ . " Parameter 1 invalid.");
62: }
63:
64: if (!is_array($aClientCfg)) {
65: throw new cInvalidArgumentException(__CLASS__ . " " . __FUNCTION__ . " Parameter 2 invalid.");
66: }
67:
68: self::$oSmarty = new cSmartyWrapper();
69: self::$aDefaultPaths = array(
70: 'template_dir' => $aClientCfg['module']['path'],
71: 'cache_dir' => $aClientCfg['cache']['path'] . 'templates_c',
72: 'compile_dir' => $aClientCfg['cache']['path'] . 'templates_c'
73: );
74:
75:
76: if (!is_dir(self::$aDefaultPaths['compile_dir'])) {
77: mkdir(self::$aDefaultPaths['compile_dir'], 0777);
78: }
79:
80:
81: if ($bSanityCheck) {
82: foreach (self::$aDefaultPaths as $key => $value) {
83: if (!file_exists($value)) {
84: throw new cException(sprintf("Class %s Error: Folder %s does not exist. Please create.", __CLASS__, $value));
85: }
86: if ($key == 'cache' || $key == 'compile_dir') {
87: if (!is_writable($value)) {
88: throw new cException(sprintf("Class %s Error: Folder %s is not writable. Please check for sufficient rights.", __CLASS__, $value));
89: }
90: }
91: }
92: }
93:
94: self::resetPaths();
95: self::$bSmartyInstanciated = true;
96: }
97:
98: 99: 100: 101: 102:
103: public function __clone() {
104: throw new cException("cSmartyFrontend class is intended to be used as singleton. Do not clone.");
105: }
106:
107: 108: 109: 110:
111: public function __destruct() {
112: self::$bSmartyInstanciated = false;
113: }
114:
115: 116: 117: 118: 119: 120: 121: 122:
123: public static function getInstance($bResetTemplate = false) {
124: if (!isset(self::$oSmarty)) {
125:
126: throw new cException("Smarty singleton not instantiated yet.");
127: }
128: if ($bResetTemplate) {
129: self::$oSmarty = new cSmartyWrapper();
130: self::resetPaths();
131: }
132: return self::$oSmarty;
133: }
134:
135: 136: 137:
138: public static function resetPaths() {
139: self::$oSmarty->setTemplateDir(self::$aDefaultPaths['template_dir']);
140: self::$oSmarty->setCacheDir(self::$aDefaultPaths['cache_dir']);
141: self::$oSmarty->setCompileDir(self::$aDefaultPaths['compile_dir']);
142: }
143:
144: }
145:
146: ?>