');"><?php echo __('Attach a file'); ?> </button> <?php } ?> </h4> <?php include_template('publish/attachments', array('article' => $article, 'attachments' => $attachments)); ?> </div> <div id="article_comments"> <h4> <?php echo __('Article comments (%count)', array('%count' => TBGComment::countComments($article->getID(), TBGComment::TYPE_ARTICLE))); ?> <?php if ($tbg_user->canPostComments() && (TBGContext::isProjectContext() && !TBGContext::getCurrentProject()->isArchived() || !TBGContext::isProjectContext())) { ?> <button id="comment_add_button" class="button button-silver" onclick="TBG.Main.Comment.showPost();"><?php echo __('Post comment'); ?> </button> <?php } ?> </h4> <?php include_template('main/comments', array('target_id' => $article->getID(), 'mentionable_target_type' => 'article', 'target_type' => TBGComment::TYPE_ARTICLE, 'show_button' => false, 'comment_count_div' => 'article_comment_count', 'forward_url' => make_url('publish_article', array('article_name' => $article->getName())))); ?>
public function runAddComment(TBGRequest $request) { $i18n = TBGContext::getI18n(); $comment_applies_type = $request['comment_applies_type']; try { if (!$this->getUser()->canPostComments()) { throw new Exception($i18n->__('You are not allowed to do this')); } if (!trim($request['comment_body'])) { throw new Exception($i18n->__('The comment must have some content')); } $comment = new TBGComment(); $comment->setTitle(''); $comment->setContent($request->getParameter('comment_body', null, false)); $comment->setPostedBy($this->getUser()->getID()); $comment->setTargetID($request['comment_applies_id']); $comment->setTargetType($request['comment_applies_type']); $comment->setReplyToComment($request['reply_to_comment_id']); $comment->setModuleName($request['comment_module']); $comment->setIsPublic((bool) $request['comment_visibility']); $comment->setSyntax($request['comment_body_syntax']); $comment->save(); if ($comment_applies_type == TBGComment::TYPE_ISSUE) { $issue = TBGIssuesTable::getTable()->selectById((int) $request['comment_applies_id']); if (!$request->isAjaxCall() || $request['comment_save_changes']) { $issue->setSaveComment($comment); $issue->save(); } else { TBGEvent::createNew('core', 'TBGComment::createNew', $comment, compact('issue'))->trigger(); } } elseif ($comment_applies_type == TBGComment::TYPE_ARTICLE) { $article = TBGArticlesTable::getTable()->selectById((int) $request['comment_applies_id']); TBGEvent::createNew('core', 'TBGComment::createNew', $comment, compact('article'))->trigger(); } switch ($comment_applies_type) { case TBGComment::TYPE_ISSUE: $comment_html = $this->getTemplateHTML('main/comment', array('comment' => $comment, 'issue' => TBGContext::factory()->TBGIssue($request['comment_applies_id']))); break; case TBGComment::TYPE_ARTICLE: $comment_html = $this->getTemplateHTML('main/comment', array('comment' => $comment)); break; default: $comment_html = 'OH NO!'; } } catch (Exception $e) { if ($request->isAjaxCall()) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $e->getMessage())); } else { TBGContext::setMessage('comment_error', $e->getMessage()); TBGContext::setMessage('comment_error_body', $request['comment_body']); TBGContext::setMessage('comment_error_title', $request['comment_title']); TBGContext::setMessage('comment_error_visibility', $request['comment_visibility']); } } if ($request->isAjaxCall()) { return $this->renderJSON(array('title' => $i18n->__('Comment added!'), 'comment_data' => $comment_html, 'continue_url' => $request['forward_url'], 'commentcount' => TBGComment::countComments($request['comment_applies_id'], $request['comment_applies_type']))); } if (isset($comment) && $comment instanceof TBGComment) { $this->forward($request['forward_url'] . "#comment_{$request['comment_applies_type']}_{$request['comment_applies_id']}_{$comment->getID()}"); } else { $this->forward($request['forward_url']); } }
public function countUserComments() { if ($this->_num_user_comments === null) { $this->_num_user_comments = TBGComment::countComments($this->getID(), TBGComment::TYPE_ISSUE, false); } return (int) $this->_num_user_comments; }
<input type="hidden" name="forward_url" value="<?php echo $forward_url; ?> "> <?php echo __('%create_comment% or %cancel%', array('%create_comment%' => '<input type="submit" class="comment_addsave" value="' . __('Create comment') . '" />', '%cancel%' => '<a href="javascript:void(0);" onClick="$(\'comment_add\').hide();$(\'comment_add_button\').show();">' . __('cancel') . '</a>')); ?> </div> </form> </div> </div> <?php } ?> <div class="faded_out comments_none" id="comments_none" <?php if (TBGComment::countComments($target_id, $target_type) != 0) { ?> style="display: none;"<?php } ?> ><?php echo __('There are no comments'); ?> </div> <div id="comments_box"> <?php foreach (TBGComment::getComments($target_id, $target_type) as $comment) { ?> <?php $options = array('comment' => $comment); if (isset($issue)) {
public function runAddComment(TBGRequest $request) { $i18n = TBGContext::getI18n(); $comment = null; $comment_applies_type = $request->getParameter('comment_applies_type'); try { if (!TBGContext::getUser()->canPostComments()) { throw new Exception($i18n->__('You are not allowed to do this')); } else { if ($request->getParameter('comment_body') == '') { throw new Exception($i18n->__('The comment must have some content')); } if ($comment_applies_type == TBGComment::TYPE_ISSUE && !$request->isAjaxCall()) { $this->comment_lines = array(); $this->comment = ''; TBGEvent::listen('core', 'TBGIssue::save', array($this, 'listenIssueSaveAddComment')); $issue = TBGContext::factory()->TBGIssue($request->getParameter('comment_applies_id')); $issue->save(false); } if (empty($this->comment) == false) { // prevent empty lines when only user comment $comment_body = $this->comment . "\n\n" . $request->getParameter('comment_body', null, false); } else { $comment_body = $request->getParameter('comment_body', null, false); } $comment = new TBGComment(); $comment->setTitle($i18n->__('Untitled comment')); $comment->setContent($comment_body); $comment->setPostedBy(TBGContext::getUser()->getID()); $comment->setTargetID($request->getParameter('comment_applies_id')); $comment->setTargetType($request->getParameter('comment_applies_type')); $comment->setModuleName($request->getParameter('comment_module')); $comment->setIsPublic((bool) $request->getParameter('comment_visibility')); $comment->save(); switch ($comment_applies_type) { case TBGComment::TYPE_ISSUE: $comment_html = $this->getTemplateHTML('main/comment', array('comment' => $comment, 'issue' => TBGContext::factory()->TBGIssue($request->getParameter('comment_applies_id')))); break; case TBGComment::TYPE_ARTICLE: $comment_html = $this->getTemplateHTML('main/comment', array('comment' => $comment)); break; default: $comment_html = 'OH NO!'; } if ($comment_applies_type == TBGComment::TYPE_ISSUE) { $issue = TBGContext::factory()->TBGIssue($request->getParameter('comment_applies_id')); TBGEvent::createNew('core', 'TBGComment::createNew', $issue, array('comment' => $comment))->trigger(); $issue->save(); } } } catch (Exception $e) { if ($request->isAjaxCall()) { return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage())); } else { TBGContext::setMessage('comment_error', $e->getMessage()); TBGContext::setMessage('comment_error_body', $request->getParameter('comment_body')); TBGContext::setMessage('comment_error_title', $request->getParameter('comment_title')); TBGContext::setMessage('comment_error_visibility', $request->getParameter('comment_visibility')); } } if ($request->isAjaxCall()) { return $this->renderJSON(array('title' => $i18n->__('Comment added!'), 'comment_data' => $comment_html, 'continue_url' => $request->getParameter('forward_url'), 'commentcount' => TBGComment::countComments($request->getParameter('comment_applies_id'), $request->getParameter('comment_applies_type')))); } if ($comment instanceof TBGComment) { $this->forward($request->getParameter('forward_url') . "#comment_{$request->getParameter('comment_applies_type')}_{$request->getParameter('comment_applies_id')}_{$comment->getID()}"); } else { $this->forward($request->getParameter('forward_url')); } }