Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
3.0 kB · 125 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126<?php
final class DiffusionPatternSearchView extends DiffusionView {
private $path; private $matches; private $pattern;
public function setPath($path) { $this->path = $path; return $this; }
public function setMatches(array $matches) { $this->matches = $matches; return $this; }
public function setPattern($pattern) { $this->pattern = $pattern; return $this; }
public function render() { $drequest = $this->getDiffusionRequest(); $path = $this->path; $pattern = $this->pattern; $rows = array();
foreach ($this->matches as $result) { list($line, $string) = $result;
$matches = null; $count = @preg_match_all( '('.$pattern.')u', $string, $matches, PREG_OFFSET_CAPTURE);
if (!$count) { $output = ltrim($string); } else { $output = array(); $cursor = 0; $length = strlen($string); foreach ($matches[0] as $match) { $offset = $match[1]; if ($cursor != $offset) { $output[] = array( 'text' => substr($string, $cursor, ($offset - $cursor)), 'highlight' => false, ); } $output[] = array( 'text' => $match[0], 'highlight' => true, ); $cursor = $offset + strlen($match[0]); } if ($cursor != $length) { $output[] = array( 'text' => substr($string, $cursor), 'highlight' => false, ); }
if ($output) { $output[0]['text'] = ltrim($output[0]['text']); }
foreach ($output as $key => $segment) { if ($segment['highlight']) { $output[$key] = phutil_tag('strong', array(), $segment['text']); } else { $output[$key] = $segment['text']; } } }
$string = phutil_tag( 'pre', array('class' => 'PhabricatorMonospaced phui-source-fragment'), $output);
$href = $drequest->generateURI(array( 'action' => 'browse', 'path' => $path, 'line' => $line, ));
$rows[] = array( phutil_tag('a', array('href' => $href), $line), $string, ); }
$path_title = Filesystem::readablePath($this->path, $drequest->getPath());
$href = $drequest->generateURI( array( 'action' => 'browse', 'path' => $this->path, ));
$title = phutil_tag('a', array('href' => $href), $path_title);
$table = id(new AphrontTableView($rows)) ->setClassName('remarkup-code') ->setHeaders(array(pht('Line'), pht('String'))) ->setColumnClasses(array('n', 'wide'));
$header = id(new PHUIHeaderView()) ->setHeader($title);
$box = id(new PHUIObjectBoxView()) ->setHeader($header) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setTable($table);
return $box->render(); }
}