Dotclear

source: inc/core/class.dc.twig.page.php @ 1014:65b07a8688ca

Revision 1014:65b07a8688ca, 1.3 KB checked in by JcDenis, 13 years ago (diff)

Use $core->page as new Twig environment

Line 
1<?php
2
3// common to public and admin sides @see inc/admin/prepend.php
4class dcTwigPage extends Twig_Environment
5{
6     protected $core;
7     protected $context = null;
8     
9     public function __construct($default_tpl_dir,$cache_dir,$context,$core)
10     {
11          $this->core =& $core;
12         
13          # Twig Loader
14          $loader = new Twig_Loader_Filesystem($this->checkDefaultTemplateDir($default_tpl_dir));
15         
16          # Twig Environment options
17          $options = array(
18               'auto_reload' => true,
19               'base_template_class' => 'Twig_Template',
20               'cache' => $this->setCacheDir($cache_dir),
21               'charset' => 'UTF-8',
22               'debug' => DC_DEBUG,
23               'optimizations' => -1
24          );
25         
26          # Twig Environment
27          parent::__construct($loader,$options);
28         
29          # Add context helper (public vs admin)
30          if ($context instanceof Twig_ExtensionInterface) {
31               $this->context = $context;
32               $this->addExtension($context);
33          }
34         
35          # Add form helper
36          $this->addExtension(new dcFormExtension($core));
37         
38          $this->clearCacheFiles();
39     }
40     
41     protected function checkDefaultTemplateDir($dir)
42     {
43          $dir = path::real($dir,false);
44         
45          return is_dir($dir) ? $dir : false;
46     }
47     
48     protected function setCacheDir($dir)
49     {
50          try {
51               $dir = path::real($dir,false);
52               files::makeDir($dir,true);
53               return $dir;
54          }
55          catch(Exception $e) { }
56         
57          return false;
58     }
59     
60     public function getContext()
61     {
62          return $this->context;
63     }
64}
65?>
Note: See TracBrowser for help on using the repository browser.

Sites map