* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBAjax'); /** * Simple AJAX stub: Comment * * Allow to call method via AJAX request * * @version 0.1.1 * @package WB * @subpackage base */ class WBAjax_Comment extends WBAjax { /** * comment * @var WBDatasource_Comment */ protected $comment; /** * second construcotr * * Called by constructer of super class. * * @see include/WB/WBAjax#init() */ protected function init() { $this->comment = WBClass::create('WBDatasource_Comment'); } /** * browse comments * * The actual AJAX frontend. * * @uses doBrowse() * @return string comment list HTML */ protected function browse() { $namespace = $this->req->get('namespace', ''); $xid = $this->req->get('xid', 0); $goto = $this->req->get('commentgoto', 0); return $this->doBrowse($namespace, $xid, $goto); } /** * add comments * * @todo consider where to call htmlspecialchars: on save or on display * @todo solve problem of auto-approve when adding comments * @uses doBrowse() * @return string comment list HTML */ protected function add() { $namespace = $this->req->get('namespace', ''); $xid = $this->req->get('xid', 0); $this->comment->setNamespace($namespace)->setXId($xid); $comment = $this->req->get('comment', ''); if (empty($comment)) { return $this->doBrowse($namespace, $xid); } $this->comment->add($comment); $this->tmpl->addGlobalVar('comment_approved', intval($this->comment->isApproved())); return $this->doBrowse($namespace, $xid); } /** * approve comment * * @uses doBrowse() * @return string comment list HTML */ protected function approve() { $id = $this->req->get('id'); $this->comment->approve($id); $namespace = $this->comment->getNamespace(); $xid = $this->comment->getXid(); return $this->doBrowse($namespace, $xid); } /** * delete comment * * @uses doBrowse() * @return string comment list HTML */ protected function remove() { $id = $this->req->get('id'); $this->comment->delete($id); $namespace = $this->comment->getNamespace(); $xid = $this->comment->getXid(); return $this->doBrowse($namespace, $xid); } /** * browse comment * * Load comments and fill template wich comments and pager. The actual * template is loaded from file named as the given namespace. * * @param string $namespace * @param string $xid * @param int $goto * @return string comment list HTML */ protected function doBrowse($namespace = '', $xid = 0, $goto = 0) { $this->comment->setNamespace($namespace)->setXId($xid); $info = array(); $list = $this->comment->browse($info, $goto); $this->loadTemplates($namespace); $this->tmpl->addGlobalVars($info, 'pager_'); $this->tmpl->addRows('list_entry', $list); return $this->tmpl->getParsedTemplate('snippet'); } }