*/ WBClass::load('WBHtml_JS'); /** * Add User Note * * Simple template function to add list of user's comments * * @version 0.2.0 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Note extends patTemplate_Function { /** * name of the function * @access private * @var string */ public $_name = 'Note'; /** * 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; } //WBHtml_JS::add('WB/Ajax/Comment'); // init comments $this->comment = WBClass::create('WBDatasource_Comment'); $this->comment->setNamespace($params['namespace'])->setXId($content); $this->comment->useForm($params['showform']); $goto = 0; if (isset($params['goto']) && !empty($params['goto'])) { $goto = intval($params['goto']); } $limit = null; if (isset($params['limit']) && !empty($params['limit'])) { $limit = intval($params['limit']); } $info = array(); $list = $this->comment->browse($info, $goto, $limit); $this->initTemplate($params); $this->tmpl->addGlobalVars($info, 'pager_'); $this->tmpl->addRows('list_entry', $list); 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'); // add user data WBClass::load('WBUser'); $user = WBUser::getCurrent(); if ($user->isAuthenticated()) { $this->tmpl->addGlobalVars($user->getData(), 'user_current_'); $groups = array(); foreach ($user->getGroups() as $gid => $gname) { $groups[$gname] = '1'; } $this->tmpl->addGlobalVars($groups, 'user_current_group_'); } // load template $this->tmpl->readTemplatesFromInput(sprintf('Comment/%s.tmpl', $params['namespace'])); } }