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