/**
  * Recache "skin" file
  *
  * @access	public
  * @param	object		Template engine (if already loaded)
  * @return	string		Skin file class
  */
 public function recacheTemplateCache($engine = null)
 {
     //-----------------------------------------
     // Make sure we got the engine
     //-----------------------------------------
     if (!$engine) {
         require_once IPS_KERNEL_PATH . 'classTemplateEngine.php';
         $engine = new classTemplate(IPS_ROOT_PATH . 'sources/template_plugins');
     }
     //-----------------------------------------
     // Recache the blocks
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'ccs_template_blocks'));
     $outer = $this->DB->execute();
     while ($r = $this->DB->fetch($outer)) {
         $cache = array('cache_type' => 'block', 'cache_type_id' => $r['tpb_id']);
         $cache['cache_content'] = $engine->convertHtmlToPhp($r['tpb_name'], $r['tpb_params'], $r['tpb_content'], '', false, true);
         $hasIt = $this->DB->buildAndFetch(array('select' => 'cache_id', 'from' => 'ccs_template_cache', 'where' => "cache_type='block' AND cache_type_id={$r['tpb_id']}"));
         if ($hasIt['cache_id']) {
             $this->DB->update('ccs_template_cache', $cache, "cache_type='block' AND cache_type_id={$r['tpb_id']}");
         } else {
             $this->DB->insert('ccs_template_cache', $cache);
         }
     }
     //-----------------------------------------
     // Get templates
     //-----------------------------------------
     $templateBits = array();
     $this->DB->build(array('select' => '*', 'from' => 'ccs_template_cache', 'where' => "cache_type NOT IN('full','page')"));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $templateBits[] = $r['cache_content'];
     }
     //-----------------------------------------
     // Now create the pseudo-code
     //-----------------------------------------
     $_fakeClass = "<" . "?php\n\n";
     $_fakeClass .= "class skin_ccs_1 {\n\n";
     $_fakeClass .= "\n\n}";
     $fullFile = $engine->convertCacheToEval($_fakeClass, "skin_ccs", 1);
     $fullFile = str_replace("\n\n}", implode("\n\n", $templateBits) . "\n\n}", $fullFile);
     $cache = array('cache_type' => 'full', 'cache_type_id' => 0, 'cache_content' => $fullFile);
     $hasIt = $this->DB->buildAndFetch(array('select' => 'cache_id', 'from' => 'ccs_template_cache', 'where' => "cache_type='full'"));
     if ($hasIt['cache_id']) {
         $this->DB->update('ccs_template_cache', $cache, "cache_type='full'");
     } else {
         $this->DB->insert('ccs_template_cache', $cache);
     }
     return $fullFile;
 }