From 3c0a822d6526b731e93c0f6bb5aa8bf10341172e Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 22 Mar 2011 17:41:55 -0700 Subject: [PATCH] Improve search result formatting slightly. --- .../search/PhabricatorSearchController.php | 26 +++++++++++++++++-- .../search/controller/search/__init__.php | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/applications/search/controller/search/PhabricatorSearchController.php b/src/applications/search/controller/search/PhabricatorSearchController.php index a7b4f75b4b..037c7ec114 100644 --- a/src/applications/search/controller/search/PhabricatorSearchController.php +++ b/src/applications/search/controller/search/PhabricatorSearchController.php @@ -159,10 +159,18 @@ class PhabricatorSearchController extends PhabricatorSearchBaseController { ->loadHandles(); $results = array(); foreach ($handles as $handle) { - $results[] = '

'.$handle->renderLink().'

'; + $results[] = + '

'. + phutil_render_tag( + 'a', + array( + 'href' => $handle->getURI(), + ), + $this->emboldenQuery($handle->getName(), $query->getQuery())). + '

'; } $results = - '
'. + '
'. implode("\n", $results). '
'; } else { @@ -181,4 +189,18 @@ class PhabricatorSearchController extends PhabricatorSearchBaseController { )); } + private function emboldenQuery($str, $query) { + $query = preg_split("/\s+/", $query); + $query = array_filter($query); + $str = phutil_escape_html($str); + foreach ($query as $word) { + $word = phutil_escape_html($word); + $str = preg_replace( + '/('.preg_quote($word, '/').')/i', + '\1', + $str); + } + return $str; + } + } diff --git a/src/applications/search/controller/search/__init__.php b/src/applications/search/controller/search/__init__.php index 83ea025bb2..7fd276befe 100644 --- a/src/applications/search/controller/search/__init__.php +++ b/src/applications/search/controller/search/__init__.php @@ -18,6 +18,7 @@ phutil_require_module('phabricator', 'view/form/base'); phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/layout/panel'); +phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'utils');