*/ WBClass::load('WBHtml_JS'); /** * Show Latest Note * * Latest user comment * * @version 0.2.0 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Notelatest extends patTemplate_Function { /** * name of the function * @access private * @var string */ public $_name = 'Notelatest'; /** * tell that this function has to be executed during runtime * @var string */ public $_type = PATTEMPLATE_FUNCTION_RUNTIME; /** * comments * @var WBDatasource_Comment */ protected $comment; /** * template engine * @var patTemplate */ protected $tmpl; /** * call the function * * @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 * @todo reconsider how to load JavaScript-Class: Comment */ public function call($params, $content) { // content must be the xid $content = trim($content); if (empty($content)) { return ''; } // numeric ID if (!preg_match('/^\d+$/', $content)) { return ''; } // namespace is required if (!isset($params['namespace']) || empty($params['namespace'])){ return ''; } // show form element if (isset($params['showform'])){ $params['showform'] = intval($params['showform']); } else { $params['showform'] = 1; } // init comments $this->comment = WBClass::create('WBDatasource_Comment'); $this->comment->setNamespace($params['namespace'])->setXId($content); $this->comment->useForm($params['showform']); $this->initTemplate($params); $this->tmpl->addGlobalVars($this->comment->getLatest()); $this->tmpl->addGlobalVar('content', $content); return $this->tmpl->getParsedTemplate('snippet'); } /** * start and setup template engine * * Load patTemplate, add important global variables and attributes * and finally load template * @param array $params */ protected function initTemplate($params) { $this->tmpl = WBClass::create('patTemplate'); // allow to transport placeholder to surrounding templates $this->tmpl->setDefaultAttribute('unusedvars', 'ignore'); $this->tmpl->addGlobalVars($params, 'att_'); // load template $this->tmpl->readTemplatesFromInput(sprintf('Comment/Latest/%s.tmpl', $params['namespace'])); } }