2016-05-05 18:46:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialChangesetOneUpMailRenderer
|
|
|
|
extends DifferentialChangesetRenderer {
|
|
|
|
|
|
|
|
public function isOneUpRenderer() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getRendererTableClass() {
|
|
|
|
return 'diff-1up-mail';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRendererKey() {
|
|
|
|
return '1up-mail';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderChangeTypeHeader($force) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderUndershieldHeader() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderShield($message, $force = 'default') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderPropertyChangeHeader() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderFileChange(
|
|
|
|
$old_file = null,
|
|
|
|
$new_file = null,
|
|
|
|
$id = 0,
|
|
|
|
$vs = 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderTextChange(
|
|
|
|
$range_start,
|
|
|
|
$range_len,
|
|
|
|
$rows) {
|
|
|
|
|
|
|
|
$primitives = $this->buildPrimitives($range_start, $range_len);
|
|
|
|
return $this->renderPrimitives($primitives, $rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderPrimitives(array $primitives, $rows) {
|
|
|
|
$out = array();
|
2016-05-06 20:46:46 +02:00
|
|
|
|
2017-01-31 02:18:55 +01:00
|
|
|
$viewer = $this->getUser();
|
|
|
|
$old_bright = $viewer->getCSSValue('old-bright');
|
|
|
|
$new_bright = $viewer->getCSSValue('new-bright');
|
|
|
|
|
2016-05-12 18:59:07 +02:00
|
|
|
$context_style = array(
|
|
|
|
'background: #F7F7F7;',
|
|
|
|
'color: #74777D;',
|
|
|
|
'border-style: dashed;',
|
|
|
|
'border-color: #C7CCD9;',
|
|
|
|
'border-width: 1px 0;',
|
|
|
|
);
|
|
|
|
|
|
|
|
$context_style = implode(' ', $context_style);
|
|
|
|
|
2016-05-05 18:46:44 +02:00
|
|
|
foreach ($primitives as $k => $p) {
|
|
|
|
$type = $p['type'];
|
|
|
|
switch ($type) {
|
|
|
|
case 'old':
|
|
|
|
case 'new':
|
|
|
|
case 'old-file':
|
|
|
|
case 'new-file':
|
|
|
|
$is_old = ($type == 'old' || $type == 'old-file');
|
|
|
|
|
|
|
|
if ($is_old) {
|
|
|
|
if ($p['htype']) {
|
2017-01-31 02:18:55 +01:00
|
|
|
$style = "background: {$old_bright};";
|
2016-05-05 18:46:44 +02:00
|
|
|
} else {
|
|
|
|
$style = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($p['htype']) {
|
2017-01-31 02:18:55 +01:00
|
|
|
$style = "background: {$new_bright};";
|
2016-05-05 18:46:44 +02:00
|
|
|
} else {
|
|
|
|
$style = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 20:46:46 +02:00
|
|
|
$out[] = array(
|
|
|
|
'style' => $style,
|
|
|
|
'render' => $p['render'],
|
|
|
|
'text' => (string)$p['render'],
|
|
|
|
);
|
2016-05-05 18:46:44 +02:00
|
|
|
break;
|
2016-05-12 18:59:07 +02:00
|
|
|
case 'context':
|
|
|
|
// NOTE: These are being included with no text so they get stripped
|
|
|
|
// in the header and footer.
|
|
|
|
$out[] = array(
|
|
|
|
'style' => $context_style,
|
|
|
|
'render' => '...',
|
|
|
|
'text' => '',
|
|
|
|
);
|
|
|
|
break;
|
2016-05-05 18:46:44 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 20:46:46 +02:00
|
|
|
// Remove all leading and trailing empty lines, since these just look kind
|
|
|
|
// of weird in mail.
|
|
|
|
foreach ($out as $key => $line) {
|
|
|
|
if (!strlen(trim($line['text']))) {
|
|
|
|
unset($out[$key]);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$keys = array_reverse(array_keys($out));
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
$line = $out[$key];
|
|
|
|
if (!strlen(trim($line['text']))) {
|
|
|
|
unset($out[$key]);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the user has commented on an empty line in the middle of a bunch of
|
|
|
|
// other empty lines, emit an explicit marker instead of just rendering
|
|
|
|
// nothing.
|
|
|
|
if (!$out) {
|
|
|
|
$out[] = array(
|
|
|
|
'style' => 'color: #888888;',
|
|
|
|
'render' => pht('(Empty.)'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$render = array();
|
|
|
|
foreach ($out as $line) {
|
|
|
|
$style = $line['style'];
|
|
|
|
$style = "padding: 0 8px; margin: 0 4px; {$style}";
|
|
|
|
|
|
|
|
$render[] = phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'style' => $style,
|
|
|
|
),
|
|
|
|
$line['render']);
|
|
|
|
}
|
|
|
|
|
2016-05-05 18:46:44 +02:00
|
|
|
$style_map = id(new PhabricatorDefaultSyntaxStyle())
|
|
|
|
->getRemarkupStyleMap();
|
|
|
|
|
|
|
|
$styled_body = id(new PhutilPygmentizeParser())
|
|
|
|
->setMap($style_map)
|
2016-05-06 20:46:46 +02:00
|
|
|
->parse((string)hsprintf('%s', $render));
|
2016-05-05 18:46:44 +02:00
|
|
|
|
|
|
|
return phutil_safe_html($styled_body);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|