2011-01-30 10:37:36 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
final class DifferentialRevisionCommentView extends AphrontView {
|
|
|
|
|
|
|
|
|
|
private $comment;
|
|
|
|
|
private $handles;
|
2011-01-30 13:20:56 -08:00
|
|
|
private $markupEngine;
|
2011-01-31 18:05:20 -08:00
|
|
|
private $preview;
|
2011-01-30 10:37:36 -08:00
|
|
|
|
|
|
|
|
public function setComment($comment) {
|
|
|
|
|
$this->comment = $comment;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setHandles(array $handles) {
|
|
|
|
|
$this->handles = $handles;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-30 13:20:56 -08:00
|
|
|
public function setMarkupEngine($markup_engine) {
|
|
|
|
|
$this->markupEngine = $markup_engine;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-31 18:05:20 -08:00
|
|
|
public function setPreview($preview) {
|
|
|
|
|
$this->preview = $preview;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-30 10:37:36 -08:00
|
|
|
public function render() {
|
|
|
|
|
|
2011-01-30 13:20:56 -08:00
|
|
|
require_celerity_resource('phabricator-remarkup-css');
|
2011-01-30 10:37:36 -08:00
|
|
|
require_celerity_resource('differential-revision-comment-css');
|
|
|
|
|
|
|
|
|
|
$comment = $this->comment;
|
|
|
|
|
|
|
|
|
|
$action = $comment->getAction();
|
|
|
|
|
|
|
|
|
|
$action_class = 'differential-comment-action-'.phutil_escape_html($action);
|
|
|
|
|
|
2011-01-31 18:05:20 -08:00
|
|
|
if ($this->preview) {
|
|
|
|
|
$date = 'COMMENT PREVIEW';
|
|
|
|
|
} else {
|
|
|
|
|
$date = date('F jS, Y g:i:s A', $comment->getDateCreated());
|
|
|
|
|
}
|
2011-01-30 10:37:36 -08:00
|
|
|
|
2011-01-31 16:00:42 -08:00
|
|
|
$author = $this->handles[$comment->getAuthorPHID()];
|
|
|
|
|
$author_link = $author->renderLink();
|
2011-01-30 10:37:36 -08:00
|
|
|
|
2011-01-30 11:02:22 -08:00
|
|
|
$verb = DifferentialAction::getActionPastTenseVerb($comment->getAction());
|
2011-01-30 10:37:36 -08:00
|
|
|
$verb = phutil_escape_html($verb);
|
|
|
|
|
|
|
|
|
|
$content = $comment->getContent();
|
|
|
|
|
if (strlen(rtrim($content))) {
|
2011-01-31 16:00:42 -08:00
|
|
|
$title = "{$author_link} {$verb} this revision:";
|
2011-01-30 13:20:56 -08:00
|
|
|
$content =
|
|
|
|
|
'<div class="phabricator-remarkup">'.
|
|
|
|
|
$this->markupEngine->markupText($content).
|
|
|
|
|
'</div>';
|
2011-01-30 10:37:36 -08:00
|
|
|
} else {
|
|
|
|
|
$title = null;
|
|
|
|
|
$content =
|
|
|
|
|
'<div class="differential-comment-nocontent">'.
|
2011-01-31 16:00:42 -08:00
|
|
|
"<p>{$author_link} {$verb} this revision.</p>".
|
2011-01-30 10:37:36 -08:00
|
|
|
'</div>';
|
|
|
|
|
}
|
2011-01-31 18:05:20 -08:00
|
|
|
|
2011-01-31 16:00:42 -08:00
|
|
|
$background = null;
|
|
|
|
|
$uri = $author->getImageURI();
|
|
|
|
|
if ($uri) {
|
|
|
|
|
$background = "background-image: url('{$uri}');";
|
2011-01-31 18:05:20 -08:00
|
|
|
}
|
2011-01-30 10:37:36 -08:00
|
|
|
|
|
|
|
|
return
|
|
|
|
|
'<div class="differential-comment '.$action_class.'">'.
|
|
|
|
|
'<div class="differential-comment-head">'.
|
|
|
|
|
'<div class="differential-comment-date">'.$date.'</div>'.
|
|
|
|
|
'<div class="differential-comment-title">'.$title.'</div>'.
|
|
|
|
|
'</div>'.
|
2011-01-31 16:00:42 -08:00
|
|
|
'<div class="differential-comment-body" style="'.$background.'">'.
|
2011-01-30 10:37:36 -08:00
|
|
|
'<div class="differential-comment-core">'.
|
|
|
|
|
'<div class="differential-comment-content">'.
|
|
|
|
|
$content.
|
|
|
|
|
'</div>'.
|
|
|
|
|
'</div>'.
|
|
|
|
|
'</div>'.
|
|
|
|
|
'</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|