/**
  * Initialize smarty
  */
 protected function InitializeSmarty()
 {
     require_once GITPHP_SMARTYDIR . 'Smarty.class.php';
     $this->tpl = new Smarty();
     $this->tpl->error_reporting = E_ALL & ~E_NOTICE;
     $this->tpl->merge_compiled_includes = true;
     $this->tpl->addPluginsDir(GITPHP_INCLUDEDIR . 'smartyplugins');
     if ($this->config->GetValue('cache')) {
         $cacheDir = GITPHP_CACHEDIR . 'templates';
         if (file_exists($cacheDir)) {
             if (!is_dir($cacheDir)) {
                 throw new Exception($cacheDir . ' exists but is not a directory');
             } else {
                 if (!is_writable($cacheDir)) {
                     throw new Exception($cacheDir . ' is not writable');
                 }
             }
         } else {
             if (!mkdir($cacheDir, 0777)) {
                 throw new Exception($cacheDir . ' could not be created');
             }
             chmod($cacheDir, 0777);
         }
         $this->tpl->setCacheDir($cacheDir);
         $this->tpl->caching = Smarty::CACHING_LIFETIME_SAVED;
         if ($this->config->HasKey('cachelifetime')) {
             $this->tpl->cache_lifetime = $this->config->GetValue('cachelifetime');
         }
         $servers = $this->config->GetValue('memcache');
         if (isset($servers) && is_array($servers) && count($servers) > 0) {
             $this->tpl->registerCacheResource('memcache', new GitPHP_CacheResource_Memcache($servers));
             $this->tpl->caching_type = 'memcache';
         }
     }
 }