Пример #1
0
');"><?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()))));
    ?>
Пример #2
0
 public function runUpdateIssueDetails(TBGRequest $request)
 {
     $this->forward403if(TBGContext::getCurrentProject()->isArchived());
     $this->error = false;
     try {
         $i18n = TBGContext::getI18n();
         $issue = TBGIssue::getIssueFromLink($request['issue_no']);
         if ($issue->getProject()->getID() != $this->selected_project->getID()) {
             throw new Exception($i18n->__('This issue is not valid for this project'));
         }
         if (!$issue instanceof TBGIssue) {
             die;
         }
         $workflow_transition = null;
         if ($passed_transition = $request['workflow_transition']) {
             //echo "looking for transition ";
             $key = str_replace(' ', '', mb_strtolower($passed_transition));
             //echo $key . "\n";
             foreach ($issue->getAvailableWorkflowTransitions() as $transition) {
                 //echo str_replace(' ', '', mb_strtolower($transition->getName())) . "?";
                 if (mb_strpos(str_replace(' ', '', mb_strtolower($transition->getName())), $key) !== false) {
                     $workflow_transition = $transition;
                     //echo "found transition " . $transition->getID();
                     break;
                 }
                 //echo "no";
             }
             if (!$workflow_transition instanceof TBGWorkflowTransition) {
                 throw new Exception("This transition ({$key}) is not valid");
             }
         }
         $fields = $request->getRawParameter('fields', array());
         $return_values = array();
         if ($workflow_transition instanceof TBGWorkflowTransition) {
             foreach ($fields as $field_key => $field_value) {
                 $classname = "TBG" . ucfirst($field_key);
                 $method = "set" . ucfirst($field_key);
                 $choices = $classname::getAll();
                 $found = false;
                 foreach ($choices as $choice_key => $choice) {
                     if (mb_strpos(str_replace(' ', '', mb_strtolower($choice->getName())), str_replace(' ', '', mb_strtolower($field_value))) !== false) {
                         $request->setParameter($field_key . '_id', $choice->getId());
                         break;
                     }
                 }
             }
             $request->setParameter('comment_body', $request['message']);
             $return_values['applied_transition'] = $workflow_transition->getName();
             if ($workflow_transition->validateFromRequest($request)) {
                 $retval = $workflow_transition->transitionIssueToOutgoingStepFromRequest($issue, $request);
                 $return_values['transition_ok'] = $retval === false ? false : true;
             } else {
                 $return_values['transition_ok'] = false;
                 $return_values['message'] = "Please pass all information required for this transition";
             }
         } elseif ($issue->isUpdateable()) {
             foreach ($fields as $field_key => $field_value) {
                 try {
                     if (in_array($field_key, array_merge(array('title', 'state'), TBGDatatype::getAvailableFields(true)))) {
                         switch ($field_key) {
                             case 'state':
                                 $issue->setState($field_value == 'open' ? TBGIssue::STATE_OPEN : TBGIssue::STATE_CLOSED);
                                 break;
                             case 'title':
                                 if ($field_value != '') {
                                     $issue->setTitle($field_value);
                                 } else {
                                     throw new Exception($i18n->__('Invalid title'));
                                 }
                                 break;
                             case 'description':
                             case 'reproduction_steps':
                                 $method = "set" . ucfirst($field_key);
                                 $issue->{$method}($field_value);
                                 break;
                             case 'status':
                             case 'resolution':
                             case 'reproducability':
                             case 'priority':
                             case 'severity':
                             case 'category':
                                 $classname = "TBG" . ucfirst($field_key);
                                 $method = "set" . ucfirst($field_key);
                                 $choices = $classname::getAll();
                                 $found = false;
                                 foreach ($choices as $choice_key => $choice) {
                                     if (str_replace(' ', '', mb_strtolower($choice->getName())) == str_replace(' ', '', mb_strtolower($field_value))) {
                                         $issue->{$method}($choice);
                                         $found = true;
                                     }
                                 }
                                 if (!$found) {
                                     throw new Exception('Could not find this value');
                                 }
                                 break;
                             case 'percent_complete':
                                 $issue->setPercentCompleted($field_value);
                                 break;
                             case 'owner':
                             case 'assignee':
                                 $set_method = "set" . ucfirst($field_key);
                                 $unset_method = "un{$set_method}";
                                 switch (mb_strtolower($field_value)) {
                                     case 'me':
                                         $issue->{$set_method}(TBGContext::getUser());
                                         break;
                                     case 'none':
                                         $issue->{$unset_method}();
                                         break;
                                     default:
                                         try {
                                             $user = TBGUser::findUser(mb_strtolower($field_value));
                                             if ($user instanceof TBGUser) {
                                                 $issue->{$set_method}($user);
                                             }
                                         } catch (Exception $e) {
                                             throw new Exception('No such user found');
                                         }
                                         break;
                                 }
                                 break;
                             case 'estimated_time':
                             case 'spent_time':
                                 $set_method = "set" . ucfirst(str_replace('_', '', $field_key));
                                 $issue->{$set_method}($field_value);
                                 break;
                             case 'milestone':
                                 $found = false;
                                 foreach ($this->selected_project->getMilestones() as $milestone) {
                                     if (str_replace(' ', '', mb_strtolower($milestone->getName())) == str_replace(' ', '', mb_strtolower($field_value))) {
                                         $issue->setMilestone($milestone->getID());
                                         $found = true;
                                     }
                                 }
                                 if (!$found) {
                                     throw new Exception('Could not find this milestone');
                                 }
                                 break;
                             default:
                                 throw new Exception($i18n->__('Invalid field'));
                         }
                     }
                     $return_values[$field_key] = array('success' => true);
                 } catch (Exception $e) {
                     $return_values[$field_key] = array('success' => false, 'error' => $e->getMessage());
                 }
             }
         }
         if (!$workflow_transition instanceof TBGWorkflowTransition) {
             $issue->getWorkflow()->moveIssueToMatchingWorkflowStep($issue);
         }
         if (!array_key_exists('transition_ok', $return_values) || $return_values['transition_ok']) {
             $comment = new TBGComment();
             $comment->setTitle('');
             $comment->setContent($request->getParameter('message', null, false));
             $comment->setPostedBy(TBGContext::getUser()->getID());
             $comment->setTargetID($issue->getID());
             $comment->setTargetType(TBGComment::TYPE_ISSUE);
             $comment->setModuleName('core');
             $comment->setIsPublic(true);
             $comment->setSystemComment(false);
             $comment->save();
             $issue->setSaveComment($comment);
             $issue->save();
         }
         $this->return_values = $return_values;
     } catch (Exception $e) {
         //$this->getResponse()->setHttpStatus(400);
         return $this->renderJSON(array('failed' => true, 'error' => $e->getMessage()));
     }
 }
        ?>
","<?php 
        echo $issue->getVotes();
        ?>
","<?php 
        echo str_replace('"', '\\"', html_entity_decode($issue->getDescription(), ENT_QUOTES, TBGContext::getI18n()->getCharset()));
        ?>
 ", "<?php 
        echo str_replace('"', '\\"', html_entity_decode($reproductionsteps, ENT_QUOTES, TBGContext::getI18n()->getCharset()));
        ?>
", "

<?php 
        if ($issue->getCommentCount() == 0) {
            echo '-';
        }
        foreach (TBGComment::getComments($issue->getFormattedIssueNo(), '1') as $comment) {
            ?>
		<?php 
            $options = compact('comment', 'comment_count_div');
            if (isset($issue)) {
                echo $comment->getPostedBy() . ' : ' . $comment->getContent() . ' ';
            }
            ?>
	<?php 
        }
        ?>
"
<?php 
    }
}
 /**
  * Transition an issue to the outgoing step, based on request data if available
  * 
  * @param TBGIssue $issue
  * @param TBGRequest $request 
  */
 public function transitionIssueToOutgoingStepFromRequest(TBGIssue $issue, $request = null)
 {
     $request = $request !== null ? $request : $this->_request;
     $this->getOutgoingStep()->applyToIssue($issue);
     if (!empty($this->_validation_errors)) {
         return false;
     }
     foreach ($this->getActions() as $action) {
         $action->perform($issue, $request);
     }
     if ($request->hasParameter('comment_body') && trim($request['comment_body'] != '')) {
         $comment = new TBGComment();
         $comment->setTitle('');
         $comment->setContent($request->getParameter('comment_body', null, false));
         $comment->setPostedBy(TBGContext::getUser()->getID());
         $comment->setTargetID($issue->getID());
         $comment->setTargetType(TBGComment::TYPE_ISSUE);
         $comment->setModuleName('core');
         $comment->setIsPublic(true);
         $comment->setSystemComment(false);
         $comment->save();
         $issue->setSaveComment($comment);
     }
     $issue->save();
 }
Пример #5
0
 public function componentDashboardViewRecentComments()
 {
     $this->comments = TBGComment::getRecentCommentsByAuthor($this->getUser()->getID());
 }
Пример #6
0
 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']);
     }
 }
    case TBGDashboard::DASHBOARD_VIEW_LAST_COMMENTS:
        ?>
		<div class="rounded_box lightgrey borderless cut_bottom dashboard_view_header" style="margin-top: 5px;">
			<?php 
        echo image_tag('collapse_small.png', array('id' => 'dashboard_' . $id . '_collapse', 'style' => 'float: left; margin: 3px 5px 0 2px;', 'onclick' => "\$('dashboard_{$id}').toggle(); this.src = (this.src == '" . image_url('collapse_small.png', false, 'core', false) . "') ? '" . image_url('expand_small.png', false, 'core', false) . "' : '" . image_url('collapse_small.png', false, 'core', false) . "'"));
        ?>
			<?php 
        echo __('Recent comments');
        ?>
		</div>
		<div id="dashboard_<?php 
        echo $id;
        ?>
">
		<?php 
        $comments = TBGComment::getRecentCommentsByAuthor($tbg_user->getID());
        ?>
		<?php 
        if (count($comments)) {
            ?>
			<table cellpadding=0 cellspacing=0 style="margin: 5px;">
				<?php 
            $prev_date = null;
            ?>
				<?php 
            foreach ($comments as $comment) {
                ?>
					<?php 
                $date = tbg_formatTime($comment->getPosted(), 5);
                ?>
					<?php 
Пример #8
0
			</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)) {
        $options['issue'] = $issue;
    }
    include_template('main/comment', $options);
    ?>
	<?php 
}
?>
</div>
Пример #9
0
 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;
 }
Пример #10
0
 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'));
     }
 }
Пример #11
0
 public function processIncomingEmailAccount(TBGIncomingEmailAccount $account, $limit = 25)
 {
     $count = 0;
     if ($emails = $account->getUnprocessedEmails()) {
         try {
             $current_user = TBGContext::getUser();
             foreach ($emails as $email) {
                 $user = $this->getOrCreateUserFromEmailString($email->from);
                 if ($user instanceof TBGUser) {
                     if (TBGContext::getUser()->getID() != $user->getID()) {
                         TBGContext::switchUserContext($user);
                     }
                     $message = $account->getMessage($email);
                     $data = $message->getBodyPlain() ? $message->getBodyPlain() : strip_tags($message->getBodyHTML());
                     if ($data) {
                         if (mb_detect_encoding($data, 'UTF-8', true) === false) {
                             $data = utf8_encode($data);
                         }
                         $new_data = '';
                         foreach (explode("\n", $data) as $line) {
                             $line = trim($line);
                             if ($line) {
                                 $line = preg_replace('/^(_{2,}|-{2,})$/', "<hr>", $line);
                                 $new_data .= $line . "\n";
                             } else {
                                 $new_data .= "\n";
                             }
                         }
                         $data = nl2br($new_data, false);
                     }
                     // Parse the subject, and obtain the issues.
                     $parsed_commit = TBGIssue::getIssuesFromTextByRegex(mb_decode_mimeheader($email->subject));
                     $issues = $parsed_commit["issues"];
                     // If any issues were found, add new comment to each issue.
                     if ($issues) {
                         foreach ($issues as $issue) {
                             $text = preg_replace('#(^\\w.+:\\n)?(^>.*(\\n|$))+#mi', "", $data);
                             $text = trim($text);
                             if (!$this->processIncomingEmailCommand($text, $issue, $user) && $user->canPostComments()) {
                                 $comment = new TBGComment();
                                 $comment->setContent($text);
                                 $comment->setPostedBy($user);
                                 $comment->setTargetID($issue->getID());
                                 $comment->setTargetType(TBGComment::TYPE_ISSUE);
                                 $comment->save();
                             }
                         }
                     } else {
                         if ($user->canReportIssues($account->getProject())) {
                             $issue = new TBGIssue();
                             $issue->setProject($account->getProject());
                             $issue->setTitle(mb_decode_mimeheader($email->subject));
                             $issue->setDescription($data);
                             $issue->setPostedBy($user);
                             $issue->setIssuetype($account->getIssuetype());
                             $issue->save();
                             // Append the new issue to the list of affected issues. This
                             // is necessary in order to process the attachments properly.
                             $issues[] = $issue;
                         }
                     }
                     // If there was at least a single affected issue, and mail
                     // contains attachments, add those attachments to related issues.
                     if ($issues && $message->hasAttachments()) {
                         foreach ($message->getAttachments() as $attachment_no => $attachment) {
                             echo 'saving attachment ' . $attachment_no;
                             $name = $attachment['filename'];
                             $new_filename = TBGContext::getUser()->getID() . '_' . NOW . '_' . basename($name);
                             if (TBGSettings::getUploadStorage() == 'files') {
                                 $files_dir = TBGSettings::getUploadsLocalpath();
                                 $filename = $files_dir . $new_filename;
                             } else {
                                 $filename = $name;
                             }
                             TBGLogging::log('Creating issue attachment ' . $filename . ' from attachment ' . $attachment_no);
                             echo 'Creating issue attachment ' . $filename . ' from attachment ' . $attachment_no;
                             $content_type = $attachment['type'] . '/' . $attachment['subtype'];
                             $file = new TBGFile();
                             $file->setRealFilename($new_filename);
                             $file->setOriginalFilename(basename($name));
                             $file->setContentType($content_type);
                             $file->setDescription($name);
                             $file->setUploadedBy(TBGContext::getUser());
                             if (TBGSettings::getUploadStorage() == 'database') {
                                 $file->setContent($attachment['data']);
                             } else {
                                 TBGLogging::log('Saving file ' . $new_filename . ' with content from attachment ' . $attachment_no);
                                 file_put_contents($new_filename, $attachment['data']);
                             }
                             $file->save();
                             // Attach file to each related issue.
                             foreach ($issues as $issue) {
                                 $issue->attachFile($file);
                             }
                         }
                     }
                     $count++;
                 }
             }
         } catch (Exception $e) {
         }
         if (TBGContext::getUser()->getID() != $current_user->getID()) {
             TBGContext::switchUserContext($current_user);
         }
     }
     $account->setTimeLastFetched(time());
     $account->setNumberOfEmailsLastFetched($count);
     $account->save();
     return $count;
 }