Path: blob/master/src/applications/diffusion/view/DiffusionPatternSearchView.php
12242 views
<?php12final class DiffusionPatternSearchView extends DiffusionView {34private $path;5private $matches;6private $pattern;78public function setPath($path) {9$this->path = $path;10return $this;11}1213public function setMatches(array $matches) {14$this->matches = $matches;15return $this;16}1718public function setPattern($pattern) {19$this->pattern = $pattern;20return $this;21}2223public function render() {24$drequest = $this->getDiffusionRequest();25$path = $this->path;26$pattern = $this->pattern;27$rows = array();2829foreach ($this->matches as $result) {30list($line, $string) = $result;3132$matches = null;33$count = @preg_match_all(34'('.$pattern.')u',35$string,36$matches,37PREG_OFFSET_CAPTURE);3839if (!$count) {40$output = ltrim($string);41} else {42$output = array();43$cursor = 0;44$length = strlen($string);45foreach ($matches[0] as $match) {46$offset = $match[1];47if ($cursor != $offset) {48$output[] = array(49'text' => substr($string, $cursor, ($offset - $cursor)),50'highlight' => false,51);52}53$output[] = array(54'text' => $match[0],55'highlight' => true,56);57$cursor = $offset + strlen($match[0]);58}59if ($cursor != $length) {60$output[] = array(61'text' => substr($string, $cursor),62'highlight' => false,63);64}6566if ($output) {67$output[0]['text'] = ltrim($output[0]['text']);68}6970foreach ($output as $key => $segment) {71if ($segment['highlight']) {72$output[$key] = phutil_tag('strong', array(), $segment['text']);73} else {74$output[$key] = $segment['text'];75}76}77}7879$string = phutil_tag(80'pre',81array('class' => 'PhabricatorMonospaced phui-source-fragment'),82$output);8384$href = $drequest->generateURI(array(85'action' => 'browse',86'path' => $path,87'line' => $line,88));8990$rows[] = array(91phutil_tag('a', array('href' => $href), $line),92$string,93);94}9596$path_title = Filesystem::readablePath($this->path, $drequest->getPath());9798$href = $drequest->generateURI(99array(100'action' => 'browse',101'path' => $this->path,102));103104$title = phutil_tag('a', array('href' => $href), $path_title);105106107$table = id(new AphrontTableView($rows))108->setClassName('remarkup-code')109->setHeaders(array(pht('Line'), pht('String')))110->setColumnClasses(array('n', 'wide'));111112$header = id(new PHUIHeaderView())113->setHeader($title);114115$box = id(new PHUIObjectBoxView())116->setHeader($header)117->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)118->setTable($table);119120return $box->render();121}122123124}125126127