Example #1
0
 /**
  * Add new comment to database
  *
  * @access  public
  * @param   array
  * @return  array or false
  */
 public function add_comment($data)
 {
     extract($data);
     //get the page
     $_data['page'] = $this->xss(empty($page) ? $this->currentURL() : $page);
     //get the ip
     $_data['author_ip'] = \Request::server('REMOTE_ADDR');
     //get user agent
     $_data['agent'] = \Request::server('HTTP_USER_AGENT');
     //check for comment parent
     $_data['parent'] = empty($parent) ? 0 : $parent;
     $_data['date'] = date("Y-m-d H:i:s", time());
     if (!empty($reply) and is_numeric($reply)) {
         $_data['parent'] = $data['reply'];
     }
     //comment content
     if (empty($comment)) {
         $this->set_error('empty_com');
     } else {
         $_data['comment'] = $this->xss($comment);
     }
     //Comment status
     $_data['status'] = self::$config['comment_status'];
     $_data['user_id'] = $user_id;
     if (empty($this->errors)) {
         $data = array($_data['comment'], $_data['author_ip']);
         if (isset($_data['author'])) {
             $data[] = $_data['author'];
         }
         $db = new Database();
         if ($db->insert('comments', $_data)) {
             $data = array('id' => $db->get_id(), 'user_id' => $user_id, 'author' => isset($_data['author']) ? $_data['author'] : '', 'date' => $_data['date'], 'comment' => $_data['comment'], 'status' => $_data['status']);
             $data = $this->process_comment($data);
             return $data;
         } else {
             $this->set_error('error');
         }
     }
     return FALSE;
 }