/** * POST /issues/comment/save * Save a comment * * @param \Base $f3 * @throws \Exception */ public function comment_save($f3) { $post = $f3->get("POST"); $issue = new \Model\Issue(); $issue->load($post["issue_id"]); if (!$issue->id || empty($post["text"])) { if ($f3->get("AJAX")) { $this->_printJson(array("error" => 1)); } else { $f3->reroute("/issues/" . $post["issue_id"]); } return; } if ($f3->get("POST.action") == "close") { $issue->close(); } $comment = \Model\Issue\Comment::create(array("issue_id" => $post["issue_id"], "user_id" => $this->_userId, "text" => trim($post["text"])), !!$f3->get("POST.notify")); if ($f3->get("AJAX")) { $this->_printJson(array("id" => $comment->id, "text" => \Helper\View::instance()->parseText($comment->text, array("hashtags" => false)), "date_formatted" => date("D, M j, Y \\a\\t g:ia", \Helper\View::instance()->utc2local(time())), "user_name" => $f3->get('user.name'), "user_username" => $f3->get('user.username'), "user_email" => $f3->get('user.email'), "user_email_md5" => md5(strtolower($f3->get('user.email'))))); return; } else { $f3->reroute("/issues/" . $comment->issue_id); } }
} } // Find issue IDs in subject preg_match("/\\[#([0-9]+)\\] -/", $header->subject, $matches); // Get issue instance $issue = new \Model\Issue(); if (!empty($matches[1])) { $issue->load(intval($matches[1])); } if (!$issue->id) { $subject = trim(preg_replace("/^((Re|Fwd?):\\s)*/i", "", $header->subject)); $issue->load(array('name=? AND deleted_date IS NULL AND closed_date IS NULL', $subject)); } if ($issue->id) { if (trim($text)) { $comment = \Model\Issue\Comment::create(array('user_id' => $from_user->id, 'issue_id' => $issue->id, 'text' => $text)); $log->write(sprintf("Added comment %s on issue #%s - %s", $comment->id, $issue->id, $issue->name)); } } else { $issue = \Model\Issue::create(array('name' => $header->subject, 'description' => $text, 'author_id' => $from_user->id, 'owner_id' => $owner, 'status' => 1, 'type_id' => 1)); $log->write(sprintf("Created issue #%s - %s", $issue->id, $issue->name)); } // Add other recipients as watchers if (!empty($header->cc) || count($header->to) > 1) { if (!empty($header->cc)) { $watchers = array_merge($header->to, $header->cc); } else { $watchers = $header->to; } foreach ($watchers as $more_people) { $watcher_email = $more_people->mailbox . '@' . $more_people->host;
public function single_comments_post($f3, $params) { $issue = new \Model\Issue(); $issue->load($params["id"]); if (!$issue->id) { $f3->error(404); return; } $data = array("issue_id" => $issue->id, "user_id" => $this->_userId, "text" => $f3->get("POST.text")); $comment = \Model\Issue\Comment::create($data); $this->_printJson($comment->cast()); }