| // +---------------------------------------------------------------------------+ // $Id: ManagerTemplate.html,v 1.2 2005/04/17 02:15:02 demian Exp $ require_once SGL_MOD_DIR . '/comment/classes/CommentContainer.php'; /** * Type your class description here ... * * @package comment * @author Alouicious Bird */ class CommentMgr extends SGL_Manager { function CommentMgr() { SGL::logMessage(null, PEAR_LOG_DEBUG); parent::SGL_Manager(); $this->pageTitle = 'Comment Manager'; $this->template = 'commentMgrList.html'; $this->_aActionsMapping = array( 'add' => array('add'), 'insert' => array('insert', 'redirectToDefault'), 'list' => array('list'), 'delete' => array('delete', 'redirectToDefault'), 'view' => array('view'), ); } function validate($req, &$input) { SGL::logMessage(null, PEAR_LOG_DEBUG); $this->validated = true; $input->error = array(); $input->pageTitle = $this->pageTitle; $input->masterTemplate = $this->masterTemplate; $input->template = $this->template; $input->action = ($req->get('action')) ? $req->get('action') : 'list'; $input->aDelete = $req->get('frmDelete'); $input->submitted = $req->get('submitted'); $input->seagull_uri = $req->get('seagull_uri'); $input->parent_id = $req->get('parent_id'); $input->comment_id = $req->get('comment_id'); $input->comment = (object)$req->get('comment'); // if receiving post if ($input->submitted) { if (empty($input->comment->name)) { $input->comment->name = SGL_String::translate('Guest'); } if (empty($input->comment->subject)) { $aErrors['subject'] = 'Please, specify subject for your post'; } if (empty($input->comment->comment)) { $aErrors['comment'] = 'Please, specify body for your post'; } if (empty($input->comment->parent_id)) { // this is ok, posting a root message $input->comment->parent_id = null; } if (empty($input->seagull_uri)) { // "fatal" error not coming through valid form or page $aErrors['seagull_uri'] = 'Fatal error, go to homepage and try again'; } } // if errors have occured if (isset($aErrors) && count($aErrors)) { SGL::raiseMsg('Please fill in the indicated fields'); $input->error = $aErrors; print_r($aErrors); $input->template = 'commentMgrAdd.html'; $this->validated = false; } } function _cmd_add(&$input, &$output) { SGL::logMessage(null, PEAR_LOG_DEBUG); $output->pageTitle = 'Add a comment'; $output->template = 'commentMgrAdd.html'; if(isset($input->comment->seagull_uri)) { $output->seagull_uri = $input->comment->seagull_uri; } elseif (isset($input->parent_id)) { $parent = new Comment; $parent->get($input->parent_id); $output->seagull_uri = $parent->seagull_uri; $output->comment = new Comment(); $output->comment->subject = "Re:" . $parent->subject; $output->comment->parent_id = $parent->comment_id; } else { $output->seagull_uri = $input->seagull_uri; } // only guest users have name field $output->showNameField = (SGL_GUEST == SGL_Session::getUserType()) ? true : false; } function _cmd_insert(&$input, &$output) { SGL::logMessage(null, PEAR_LOG_DEBUG); $cc = new CommentContainer($input->seagull_uri); $cc->saveComment( $input->comment->subject, $input->comment->comment, $input->comment->parent_id, $input->comment->name); SGL::raiseMsg('new Comment added succesfully'); // API currently sucks or I'm stupid :-( $redir = $this->conf['site']['baseUrl']; if ($this->conf['site']['frontScriptName']) $redir .= '/'.$this->conf['site']['frontScriptName']; $redir .= '/' . $input->seagull_uri; SGL_HTTP::redirect($redir); } function _cmd_list(&$input, &$output) { SGL::logMessage(null, PEAR_LOG_DEBUG); $cc = new CommentContainer($input->seagull_uri); $output->comments = $cc->getComments(); } function _cmd_delete(&$input, &$output) { SGL::logMessage(null, PEAR_LOG_DEBUG); } function _cmd_view(&$input, &$output) { SGL::logMessage(null, PEAR_LOG_DEBUG); $output->template = 'commentMgrView.html'; $cc = new CommentContainer(null, $input->comment_id); $cc->buildTree(); $output->comment = $cc->getComment($input->comment_id); $output->comment->comment = nl2br($output->comment->comment); $output->children = $output->comment->getChildTreeAsHtmlSnippet(); // API currently sucks or I'm stupid :-( $redir = $this->conf['site']['baseUrl']; if ($this->conf['site']['frontScriptName']) $redir .= '/'.$this->conf['site']['frontScriptName']; $redir .= '/' . $input->seagull_uri; $output->redir = $redir; } } ?>