* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBAjax'); /** * Simple AJAX stub: Comment * * Allow to call method via AJAX request * * @version 0.2.0 * @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); $limit = $this->req->get('limit', 0); return $this->doBrowse($namespace, $xid, $goto, $limit); } /** * 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); $limit = $this->req->get('limit', 0); $this->comment->setNamespace($namespace)->setXId($xid); $comment = $this->req->get('comment', ''); if (empty($comment)) { return $this->doBrowse($namespace, $xid); } $id = $this->comment->add($comment); if (!empty($id)) { $this->tmpl->addGlobalVar('comment_approved', intval($this->comment->isApproved())); } return $this->doBrowse($namespace, $xid, 0, $limit); } /** * 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(); $goto = $this->req->get('commentgoto', 0); $limit = $this->req->get('limit', 0); return $this->doBrowse($namespace, $xid, $goto, $limit); } /** * 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 * @param int $limit * @return string comment list HTML */ protected function doBrowse($namespace = '', $xid = 0, $goto = 0, $limit = 0) { $this->comment->setNamespace($namespace)->setXId($xid); $this->comment->useForm(intval($this->req->get('showform', 1))); if (empty($limit)) { $limit = null; } $info = array(); $list = $this->comment->browse($info, $goto, $limit); $info['xid_js'] = str_replace('-', '_', $info['xid']); $this->loadTemplates($namespace); $this->tmpl->addGlobalVars($info, 'pager_'); $this->tmpl->addRows('list_entry', $list); return $this->tmpl->getParsedTemplate('snippet'); } }