/**
  * Recache this block to the database based on content type and cache settings.
  *
  * @access	public
  * @param	array 				Block data
  * @param	bool				Return data instead of saving to database
  * @return	string				New cached content
  */
 public function recacheBlock($block, $return = false)
 {
     //-----------------------------------------
     // Save the template
     //-----------------------------------------
     $templateHTML = $this->_parseBlock($block);
     $template = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'ccs_template_blocks', 'where' => "tpb_name='block__custom_{$block['block_id']}'"));
     if ($template['tpb_id']) {
         $this->DB->update('ccs_template_blocks', array('tpb_content' => $templateHTML), 'tpb_id=' . $template['tpb_id']);
     } else {
         $template = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'ccs_template_blocks', 'where' => "tpb_name='block__custom'"));
         $this->DB->insert('ccs_template_blocks', array('tpb_name' => 'block__custom_' . $block['block_id'], 'tpb_content' => $templateHTML, 'tpb_params' => $template['tpb_params']));
         $template['tpb_id'] = $this->DB->getInsertId();
     }
     $cache = array('cache_type' => 'block', 'cache_type_id' => $template['tpb_id']);
     require_once IPS_KERNEL_PATH . 'classTemplateEngine.php';
     $engine = new classTemplate(IPS_ROOT_PATH . 'sources/template_plugins');
     $cache['cache_content'] = $engine->convertHtmlToPhp('block__custom_' . $block['block_id'], $template['tpb_params'], $templateHTML, '', false, true);
     $hasIt = $this->DB->buildAndFetch(array('select' => 'cache_id', 'from' => 'ccs_template_cache', 'where' => "cache_type='block' AND cache_type_id={$template['tpb_id']}"));
     //print_r($cache);exit;
     if ($hasIt['cache_id']) {
         $this->DB->update('ccs_template_cache', $cache, "cache_type='block' AND cache_type_id={$template['tpb_id']}");
     } else {
         $this->DB->insert('ccs_template_cache', $cache);
     }
     //-----------------------------------------
     // Recache the "skin" file
     //-----------------------------------------
     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
     $_pagesClass = new pageBuilder($this->registry);
     $_pagesClass->recacheTemplateCache($engine);
     $_pagesClass->loadSkinFile();
     $func = 'block__custom_' . $block['block_id'];
     $content = $this->registry->output->getTemplate('ccs')->{$func}($block['block_name'], $templateHTML);
     if (!$return and $block['block_cache_ttl']) {
         $this->DB->update('ccs_blocks', array('block_cache_output' => $content, 'block_cache_last' => time()), 'block_id=' . intval($block['block_id']));
     }
     return $content;
 }
 /**
  * Recache this block to the database based on content type and cache settings.
  *
  * @access	public
  * @param	array 				Block data
  * @param	bool				Return data instead of saving to database
  * @return	bool				Cache done successfully
  * @todo 	Finish this
  */
 public function recacheBlock($block, $return = false)
 {
     //-----------------------------------------
     // Load skin in case it's needed
     //-----------------------------------------
     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
     $pageBuilder = new pageBuilder($this->registry);
     $pageBuilder->loadSkinFile();
     $config = unserialize($block['block_config']);
     $content = '';
     require_once IPSLib::getAppDir('ccs') . '/sources/blocks/feed/data_sources/' . $config['feed'] . '.php';
     $_className = "feed_" . $config['feed'];
     $_class = new $_className($this->registry);
     $content = $_class->executeFeed($block);
     if (!$return) {
         $this->DB->update('ccs_blocks', array('block_cache_output' => $content, 'block_cache_last' => time()), 'block_id=' . intval($block['block_id']));
     }
     return $content;
 }
 /**
  * Recache a block
  *
  * @access	protected
  * @return	void
  */
 protected function _recacheAllBlocks()
 {
     //-----------------------------------------
     // Get skin
     //-----------------------------------------
     require_once IPSLib::getAppDir('ccs') . '/sources/pages.php';
     $pageBuilder = new pageBuilder($this->registry);
     $pageBuilder->recacheTemplateCache();
     $pageBuilder->loadSkinFile();
     $this->DB->build(array('select' => '*', 'from' => 'ccs_blocks'));
     $outer = $this->DB->execute();
     while ($block = $this->DB->fetch($outer)) {
         if ($block['block_type'] and file_exists(IPSLib::getAppDir('ccs') . '/sources/blocks/' . $block['block_type'] . '/admin.php')) {
             require_once IPSLib::getAppDir('ccs') . '/sources/blocks/adminInterface.php';
             require_once IPSLib::getAppDir('ccs') . '/sources/blocks/' . $block['block_type'] . '/admin.php';
             $className = "adminBlockHelper_" . $block['block_type'];
             $extender = new $className($this->registry);
             $extender->recacheBlock($block);
         }
     }
     //-----------------------------------------
     // Clear page caches
     //-----------------------------------------
     $this->DB->update('ccs_pages', array('page_cache' => null));
     $this->registry->output->global_message = $this->lang->words['all_blocks_recached'];
     $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . '&module=blocks&section=blocks');
 }