*/ /** * patTemplate-function list of addressbook entries * * @version 0.2.0 * @package Wombat * @subpackage patTemplate */ class patTemplate_Function_Newsletter extends patTemplate_Function { /** * Name of the function * @var string */ public $_name = 'Newsletter'; /** * Tell that this function has to be executed during runtime * @var string */ public $_type = PATTEMPLATE_FUNCTION_RUNTIME; /** * Template Engine * @var patTemplate */ private $tmpl; /** * Subscriber * @var WBDatasource_Newsletter_Subscriber */ private $sub; /** * Call the function * * Simply show newsletter registration form, depending on current user * * @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) { $this->tmpl = WBClass::create('patTemplate'); $paramsDef = array( 'tmpl' => 'default', 'class' => '' ); $params = array_merge($paramsDef, $params); $this->tmpl->addGlobalVars($params); $this->sub = WBClass::create('WBDatasource_Newsletter_Subscriber'); $user = WBUser::getCurrent(); $sub = false; if ($user->isAuthenticated()) { $this->sub->setUser($user); $this->tmpl->addGlobalVars($user->getData(), 'user_current_'); $sub = $this->sub->loadByUser(); } $suf = 'New'; if (!empty($sub)) { $this->tmpl->addGlobalVars($this->sub->get(), 'sub_'); $suf = 'Sub'; } $this->tmpl->readTemplatesFromInput('Newsletter/Register/' . $params['tmpl'] . $suf. '.tmpl'); return $this->tmpl->getParsedTemplate('snippet'); } }