Commit | Line | Data |
---|---|---|
3deba037 TO |
1 | <?php |
2 | ||
1cd3ffa9 EM |
3 | /** |
4 | * Class CRM_Core_CodeGen_Util_Smarty | |
5 | */ | |
3deba037 TO |
6 | class CRM_Core_CodeGen_Util_Smarty { |
7 | /** | |
8 | * @var CRM_Core_CodeGen_Util_Smarty | |
9 | */ | |
10 | private static $singleton; | |
11 | ||
12 | /** | |
13 | * @return CRM_Core_CodeGen_Util_Smarty | |
14 | */ | |
15 | public static function singleton() { | |
16 | if (self::$singleton === NULL) { | |
17 | self::$singleton = new CRM_Core_CodeGen_Util_Smarty(); | |
18 | } | |
19 | return self::$singleton; | |
20 | } | |
21 | ||
3deba037 TO |
22 | private $compileDir; |
23 | ||
00be9182 | 24 | public function __destruct() { |
3deba037 TO |
25 | if ($this->compileDir) { |
26 | CRM_Core_CodeGen_Util_File::cleanTempDir($this->compileDir); | |
27 | } | |
28 | } | |
29 | ||
7a9ab499 EM |
30 | /** |
31 | * Get templates_c directory. | |
32 | * | |
33 | * @return string | |
34 | */ | |
00be9182 | 35 | public function getCompileDir() { |
3deba037 TO |
36 | if ($this->compileDir === NULL) { |
37 | $this->compileDir = CRM_Core_CodeGen_Util_File::createTempDir('templates_c_'); | |
38 | } | |
39 | return $this->compileDir; | |
40 | } | |
41 | ||
7a9ab499 | 42 | /** |
b7a48b7e | 43 | * Create a Smarty instance. |
7a9ab499 EM |
44 | * |
45 | * @return \Smarty | |
46 | */ | |
b7a48b7e | 47 | public function createSmarty() { |
90b9cb2c TO |
48 | $base = dirname(dirname(dirname(dirname(__DIR__)))); |
49 | ||
b7a48b7e TO |
50 | require_once 'Smarty/Smarty.class.php'; |
51 | $smarty = new Smarty(); | |
90b9cb2c | 52 | $smarty->template_dir = "$base/xml/templates"; |
be2fb01f | 53 | $smarty->plugins_dir = ["$base/packages/Smarty/plugins", "$base/CRM/Core/Smarty/plugins"]; |
b7a48b7e TO |
54 | $smarty->compile_dir = $this->getCompileDir(); |
55 | $smarty->clear_all_cache(); | |
56 | ||
57 | // CRM-5308 / CRM-3507 - we need {localize} to work in the templates | |
58 | ||
59 | require_once 'CRM/Core/Smarty/plugins/block.localize.php'; | |
60 | $smarty->register_block('localize', 'smarty_block_localize'); | |
61 | ||
62 | return $smarty; | |
3deba037 | 63 | } |
96025800 | 64 | |
ef10e0b5 | 65 | } |