1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-01 03:02:43 +01:00
phorge-phorge/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentQuoteController.php
Chad Little b5bd4c65c2 Update transactions for handleRequest
Summary: Updates Transactions for handleRequest

Test Plan: Leave Comment, View Raw, Delete, Quote, etc.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T8628

Differential Revision: https://secure.phabricator.com/D14629
2015-12-02 07:59:36 -08:00

62 lines
1.6 KiB
PHP

<?php
final class PhabricatorApplicationTransactionCommentQuoteController
extends PhabricatorApplicationTransactionController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$phid = $request->getURIData('phid');
$xaction = id(new PhabricatorObjectQuery())
->withPHIDs(array($phid))
->setViewer($viewer)
->executeOne();
if (!$xaction) {
return new Aphront404Response();
}
if (!$xaction->getComment()) {
return new Aphront404Response();
}
if ($xaction->getComment()->getIsRemoved()) {
return new Aphront400Response();
}
if (!$xaction->hasComment()) {
return new Aphront404Response();
}
$content = $xaction->getComment()->getContent();
$content = rtrim($content, "\r\n");
$content = phutil_split_lines($content, true);
foreach ($content as $key => $line) {
if (strlen($line) && ($line[0] != '>')) {
$content[$key] = '> '.$line;
} else {
$content[$key] = '>'.$line;
}
}
$content = implode('', $content);
$author = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs(array($xaction->getComment()->getAuthorPHID()))
->executeOne();
$ref = $request->getStr('ref');
if (strlen($ref)) {
$quote = pht('In %s, %s wrote:', $ref, '@'.$author->getName());
} else {
$quote = pht('%s wrote:', '@'.$author->getName());
}
$content = ">>! {$quote}\n{$content}";
return id(new AphrontAjaxResponse())->setContent(
array(
'quoteText' => $content,
));
}
}