Path: blob/master/src/applications/differential/render/DifferentialChangesetOneUpMailRenderer.php
12256 views
<?php12final class DifferentialChangesetOneUpMailRenderer3extends DifferentialChangesetRenderer {45public function isOneUpRenderer() {6return true;7}89protected function getRendererTableClass() {10return 'diff-1up-mail';11}1213public function getRendererKey() {14return '1up-mail';15}1617protected function renderChangeTypeHeader($force) {18return null;19}2021protected function renderUndershieldHeader() {22return null;23}2425public function renderShield($message, $force = 'default') {26return null;27}2829protected function renderPropertyChangeHeader() {30return null;31}3233public function renderTextChange(34$range_start,35$range_len,36$rows) {3738$primitives = $this->buildPrimitives($range_start, $range_len);39return $this->renderPrimitives($primitives, $rows);40}4142protected function renderPrimitives(array $primitives, $rows) {43$out = array();4445$viewer = $this->getUser();46$old_bright = $viewer->getCSSValue('old-bright');47$new_bright = $viewer->getCSSValue('new-bright');4849$context_style = array(50'background: #F7F7F7;',51'color: #74777D;',52'border-style: dashed;',53'border-color: #C7CCD9;',54'border-width: 1px 0;',55);5657$context_style = implode(' ', $context_style);5859foreach ($primitives as $k => $p) {60$type = $p['type'];61switch ($type) {62case 'old':63case 'new':64case 'old-file':65case 'new-file':66$is_old = ($type == 'old' || $type == 'old-file');6768if ($is_old) {69if ($p['htype']) {70$style = "background: {$old_bright};";71} else {72$style = null;73}74} else {75if ($p['htype']) {76$style = "background: {$new_bright};";77} else {78$style = null;79}80}8182$out[] = array(83'style' => $style,84'render' => $p['render'],85'text' => (string)$p['render'],86);87break;88case 'context':89// NOTE: These are being included with no text so they get stripped90// in the header and footer.91$out[] = array(92'style' => $context_style,93'render' => '...',94'text' => '',95);96break;97default:98break;99}100}101102// Remove all leading and trailing empty lines, since these just look kind103// of weird in mail.104foreach ($out as $key => $line) {105if (!strlen(trim($line['text']))) {106unset($out[$key]);107} else {108break;109}110}111112$keys = array_reverse(array_keys($out));113foreach ($keys as $key) {114$line = $out[$key];115if (!strlen(trim($line['text']))) {116unset($out[$key]);117} else {118break;119}120}121122// If the user has commented on an empty line in the middle of a bunch of123// other empty lines, emit an explicit marker instead of just rendering124// nothing.125if (!$out) {126$out[] = array(127'style' => 'color: #888888;',128'render' => pht('(Empty.)'),129);130}131132$render = array();133foreach ($out as $line) {134$style = $line['style'];135$style = "padding: 0 8px; margin: 0 4px; {$style}";136137$render[] = phutil_tag(138'div',139array(140'style' => $style,141),142$line['render']);143}144145$style_map = id(new PhabricatorDefaultSyntaxStyle())146->getRemarkupStyleMap();147148$styled_body = id(new PhutilPygmentizeParser())149->setMap($style_map)150->parse((string)hsprintf('%s', $render));151152return phutil_safe_html($styled_body);153}154155}156157158