/**
  * Approve a comment
  */
 function approveComment()
 {
     Doo::loadModel('Comment');
     $c = new Comment();
     $c->id = intval($this->params['cid']);
     $comment = $c->find(array('limit' => 1, 'select' => 'id, post_id'));
     //if not exists, show error
     if ($comment == Null) {
         return 404;
     }
     //change status to Approved
     $comment->status = 1;
     $comment->update(array('field' => 'status'));
     Doo::loadModel('Post');
     Doo::autoload('DooDbExpression');
     //Update totalcomment field in Post
     $p = new Post();
     $p->id = $comment->post_id;
     $p->totalcomment = new DooDbExpression('totalcomment+1');
     $p->update(array('field' => 'totalcomment'));
     $data['rootUrl'] = Doo::conf()->APP_URL;
     $data['title'] = 'Comment Approved!';
     $data['content'] = "<p>Comment is approved successfully!</p>";
     $data['content'] .= "<p>View the comment <a href=\"{$data['rootUrl']}article/{$p->id}#comment{$comment->id}\">here</a></p>";
     $this->render('admin_msg', $data);
 }
Exemplo n.º 2
0
 /**
  * short hand of Doo::autoload()
  * @param string $class_name
  */
 public function autoload($class_name)
 {
     Doo::autoload($class_name);
 }
Exemplo n.º 3
0
 function newComment()
 {
     foreach ($_POST as $k => $v) {
         $_POST[$k] = trim($v);
     }
     if ($_POST['url'] == 'http://' || empty($_POST['url'])) {
         unset($_POST['url']);
     }
     //strip html tags in comment
     if (!empty($_POST['content'])) {
         $_POST['content'] = strip_tags($_POST['content']);
     }
     Doo::loadModel('Comment');
     $c = new Comment($_POST);
     $this->prepareSidebar();
     // 'skip' is same as DooValidator::CHECK_SKIP
     if ($error = $c->validate('skip')) {
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->data['title'] = 'Oops! Error Occured!';
         $this->data['content'] = '<p style="color:#ff0000;">' . $error . '</p>';
         $this->data['content'] .= '<p>Go <a href="javascript:history.back();">back</a> to post.</p>';
         $this->render('error', $this->data);
     } else {
         Doo::autoload('DooDbExpression');
         $c->createtime = new DooDbExpression('NOW()');
         $c->insert();
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->render('comment', $this->data);
     }
 }