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: 55:
56: public function __construct(&$aCfg, &$aClientCfg, $bSanityCheck = false) {
57:
58: if (isset(self::$bSmartyInstanciated) && self::$bSmartyInstanciated) {
59: throw new cException("cSmartyFrontend class is intended to be used as singleton. Do not instanciate multiple times.");
60: }
61:
62: if (!is_array($aCfg)) {
63: throw new cInvalidArgumentException(__CLASS__ . " " . __FUNCTION__ . " Parameter 1 invalid.");
64: }
65:
66: if (!is_array($aClientCfg)) {
67: throw new cInvalidArgumentException(__CLASS__ . " " . __FUNCTION__ . " Parameter 2 invalid.");
68: }
69:
70: self::$oSmarty = new cSmartyWrapper();
71: self::$aDefaultPaths = array(
72: 'template_dir' => $aClientCfg['module']['path'],
73: 'cache_dir' => $aClientCfg['cache']['path'] . 'templates_c',
74: 'compile_dir' => $aClientCfg['cache']['path'] . 'templates_c'
75: );
76:
77:
78: if (!is_dir(self::$aDefaultPaths['compile_dir'])) {
79: mkdir(self::$aDefaultPaths['compile_dir'], cDirHandler::getDefaultPermissions());
80: }
81:
82:
83: if ($bSanityCheck) {
84: foreach (self::$aDefaultPaths as $key => $value) {
85: if (!file_exists($value)) {
86: throw new cException(sprintf("Class %s Error: Folder %s does not exist. Please create.", __CLASS__, $value));
87: }
88: if ($key == 'cache' || $key == 'compile_dir') {
89: if (!is_writable($value)) {
90: throw new cException(sprintf("Class %s Error: Folder %s is not writable. Please check for sufficient rights.", __CLASS__, $value));
91: }
92: }
93: }
94: }
95:
96: self::resetPaths();
97: self::$bSmartyInstanciated = true;
98: }
99:
100: 101: 102: 103: 104:
105: public function __clone() {
106: throw new cException("cSmartyFrontend class is intended to be used as singleton. Do not clone.");
107: }
108:
109: 110: 111: 112:
113: public function __destruct() {
114: self::$bSmartyInstanciated = false;
115: }
116:
117: 118: 119: 120: 121: 122: 123: 124:
125: public static function getInstance($bResetTemplate = false) {
126: if (!isset(self::$oSmarty)) {
127:
128: throw new cException("Smarty singleton not instantiated yet.");
129: }
130: if ($bResetTemplate) {
131: self::$oSmarty = new cSmartyWrapper();
132: self::resetPaths();
133: }
134: return self::$oSmarty;
135: }
136:
137: 138: 139:
140: public static function resetPaths() {
141: self::$oSmarty->setTemplateDir(self::$aDefaultPaths['template_dir']);
142: self::$oSmarty->setCacheDir(self::$aDefaultPaths['cache_dir']);
143: self::$oSmarty->setCompileDir(self::$aDefaultPaths['compile_dir']);
144: }
145:
146: }
147: