*/ WBClass::load('WBCache'); /** * patTemplate-function to display rendered datasource * * Simple template function to add datasource * * @version 0.3.1 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Datasource extends patTemplate_Function { /** * name of the function * @access private * @var string */ public $_name = 'Datasource'; /** * tell that this function has to be executed during runtime * @var string */ public $_type = PATTEMPLATE_FUNCTION_RUNTIME; /** * template engine * @var patTemplate */ protected $tmpl; /** * Call the function * * Parameter: * - ttl (7200) time in seconds to cache result, use 0 to disable cache * * @access public * @param array $params parameters of the function (= attributes of the tag) * @param string $content inside tag * @return string content to insert into the template */ public function call($params, $content) { // content must be the datasource $datasource = trim($content); if (empty($datasource)) { return ''; } $params = array_merge(array( 'ttl' => 7200 ), $params); $cid = ''; if (0 < $params['ttl']) { $cid = sprintf('%s-%s-%s', $content, patI18n::getLocale(), serialize($params)); $html = WBCache::get($cid); if ($html) { return $html; } } $randy = WBClass::create('WBDatasource_Renderer_HTML'); $randy->setConfig($params); $ds = WBClass::create('WBDatasource_View'); $ds->addVars($params); $ds->setRenderer($randy); $ds->render($datasource); $html = $randy->GetHtml(); if (empty($cid)) { return $html; } WBCache::set($cid, $html, array('ttl' => $params['ttl'])); return $html; } }