本文整理汇总了PHP中Hubzero\Utility\String::highlight方法的典型用法代码示例。如果您正苦于以下问题:PHP String::highlight方法的具体用法?PHP String::highlight怎么用?PHP String::highlight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hubzero\Utility\String
的用法示例。
在下文中一共展示了String::highlight方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Highlight some text
*
* @param string $text Text to find phrases in
* @param integer $phrase Phrase to highlight
* @param array $options Options for highlighting
* @return string
* @throws \InvalidArgumentException If no text was passed
*/
public function __invoke($text = null, $phrase = null, $options = array())
{
if (null === $text) {
throw new \InvalidArgumentException(__METHOD__ . '(); No text passed.');
}
return String::highlight($text, $phrase, $options);
}
示例2: listTask
public function listTask()
{
$config = Component::params('com_search');
$query = new \Hubzero\Search\Query($config);
$terms = Request::getVar('terms', '*:*');
$limit = Request::getInt('limit', 10);
$start = Request::getInt('start', 0);
$sortBy = Request::getVar('sortBy', '');
$sortDir = Request::getVar('sortDir', '');
$type = Request::getVar('type', '');
$filters = Request::getVar('filters', array());
// Apply the sorting
if ($sortBy != '' && $sortDir != '') {
$query = $query->sortBy($sortBy, $sortDir);
}
if ($type != '') {
$query->addFilter('Type', array('hubtype', '=', $type));
}
// Administrators can see all records
$isAdmin = User::authorise('core.admin', 'com_users');
if ($isAdmin) {
$query = $query->query($terms)->limit($limit)->start($start);
} else {
$query = $query->query($terms)->limit($limit)->start($start)->restrictAccess();
}
// Perform the query
$query = $query->run();
$results = $query->getResults();
$numFound = $query->getNumFound();
$highlightOptions = array('format' => '<span class="highlight">\\1</span>', 'html' => false, 'regex' => "|%s|iu");
foreach ($results as &$result) {
$snippet = '';
foreach ($result as $field => &$r) {
if (is_string($r)) {
$r = strip_tags($r);
}
if ($field != 'url') {
$r = \Hubzero\Utility\String::highlight($r, $terms, $highlightOptions);
}
if ($field == 'description' || $field == 'fulltext' || $field == 'abstract') {
if (isset($result['description']) && $result['description'] != $result['fulltext']) {
$snippet .= $r;
}
}
}
$snippet = str_replace("\n", "", $snippet);
$snippet = str_replace("\r", "", $snippet);
$snippet = \Hubzero\Utility\String::excerpt($snippet, $terms, $radius = 200, $ellipsis = '…');
$result['snippet'] = $snippet;
}
$response = new stdClass();
$response->results = $results;
$response->total = $numFound;
$response->showing = count($results);
$response->success = true;
$this->send($response);
}
示例3: array
<?php
echo String::highlight($record->task->name, $this->filters['search'], array('html' => true));
?>
</div>
</div>
<div class="td last" title="<?php
echo $record->description;
?>
">
<div class="small-label"><?php
echo Lang::txt('COM_TIME_RECORDS_DESCRIPTION');
?>
:</div>
<div class="small-content">
<?php
echo String::highlight(String::truncate($record->description, 25), $this->filters['search'], array('html' => true));
?>
</div>
</div>
</div>
<?php
}
?>
<?php
if (!$this->records->count()) {
?>
<div class="tr">
<div colspan="7" class="td no_records"><?php
echo Lang::txt('COM_TIME_RECORDS_NONE_TO_DISPLAY');
?>
</div>
示例4: formatted
public function formatted($config = array('format' => 'apa'), $highlight = NULL)
{
//get hub specific details
$hub_name = \Config::get('sitename');
$hub_url = rtrim(\Request::base(), '/');
//get scope specific details
$coins_only = isset($config['coins_only']) ? $config['coins_only'] : "no";
$include_coins = isset($config['include_coins']) ? $config['include_coins'] : "no";
$c_type = 'journal';
$type = $this->relatedType->type;
switch (strtolower($type)) {
case 'book':
case 'inbook':
case 'conference':
case 'proceedings':
case 'inproceedings':
$c_type = "book";
break;
case 'journal':
case 'article':
case 'journal article':
$c_type = "journal";
break;
default:
break;
}
//var to hold COinS data
$coins_data = array("ctx_ver=Z39.88-2004", "rft_val_fmt=info:ofi/fmt:kev:mtx:{$c_type}", "rfr_id=info:sid/{$hub_url}:{$hub_name}");
//array to hold replace vals
$replace_values = array();
// get the template
// default to IEEE
try {
$format = \Components\Citations\Models\Format::oneOrFail($config['citationFormat']);
} catch (\Exception $e) {
$format = \Components\Citations\Models\Format::all()->where('style', 'LIKE', '%IEEE%')->row()->toObject();
}
//get the template keys
$template_keys = array("type" => "{TYPE}", "cite" => "{CITE KEY}", "ref_type" => "{REF TYPE}", "date_submit" => "{DATE SUBMITTED}", "date_accept" => "{DATE ACCEPTED}", "date_publish" => "{DATE PUBLISHED}", "author" => "{AUTHORS}", "editor" => "{EDITORS}", "title" => "{TITLE/CHAPTER}", "booktitle" => "{BOOK TITLE}", "chapter" => "{CHAPTER}", "journal" => "{JOURNAL}", "journaltitle" => "{JOURNAL TITLE}", "volume" => "{VOLUME}", "number" => "{ISSUE/NUMBER}", "pages" => "{PAGES}", "isbn" => "{ISBN/ISSN}", "issn" => "{ISSN}", "doi" => "{DOI}", "series" => "{SERIES}", "edition" => "{EDITION}", "school" => "{SCHOOL}", "publisher" => "{PUBLISHER}", "institution" => "{INSTITUTION}", "address" => "{ADDRESS}", "location" => "{LOCATION}", "howpublished" => "{HOW PUBLISHED}", "url" => "{URL}", "eprint" => "{E-PRINT}", "note" => "{TEXT SNIPPET/NOTES}", "organization" => "{ORGANIZATION}", "abstract" => "{ABSTRACT}", "year" => "{YEAR}", "month" => "{MONTH}", "search_string" => "{SECONDARY LINK}", "sec_cnt" => "{SECONDARY COUNT}");
/**
* Values used by COINs
*
* @var array
*/
$coins_keys = array('title' => 'rft.atitle', 'journaltitle' => 'rft.jtitle', 'date_publish' => 'rft.date', 'volume' => 'rft.volume', 'number' => 'rft.issue', 'pages' => 'rft.pages', 'issn' => 'rft.issn', 'isbn' => 'rft.isbn', 'type' => 'rft.genre', 'author' => 'rft.au', 'url' => 'rft_id', 'doi' => 'rft_id=info:doi/', 'author' => 'rft.au');
// form the formatted citation
foreach ($template_keys as $k => $v) {
if (!$this->keyExistsOrIsNotEmpty($k, $this) && $k != 'author') {
$replace_values[$v] = '';
} else {
$replace_values[$v] = $this->{$k};
//add to coins data if we can but not authors as that will get processed below
if (in_array($k, array_keys($coins_keys)) && $k != 'author') {
//key specific
switch ($k) {
case 'title':
break;
case 'doi':
$coins_data[] = $this->_coins_keys[$k] . $this->{$k};
break;
case 'url':
$coins_data[] = $this->_coins_keys[$k] . '=' . htmlentities($this->{$k});
break;
case 'journaltitle':
$jt = html_entity_decode($this->{$k});
$jt = !preg_match('!\\S!u', $jt) ? utf8_encode($jt) : $jt;
$coins_data[] = $this->_coins_keys[$k] . '=' . $jt;
break;
default:
$coins_data[] = $this->_coins_keys[$k] . '=' . $this->{$k};
}
}
if ($k == 'author') {
$a = array();
$auth = html_entity_decode($this->{$k});
$auth = !preg_match('!\\S!u', $auth) ? utf8_encode($auth) : $auth;
// prefer the use of the relational table
if ($this->relatedAuthors->count() > 0) {
$authors = $this->relatedAuthors;
$authorCount = $this->relatedAuthors->count();
} elseif ($auth != '' && $this->relatedAuthors->count() == 0) {
$author_string = $auth;
$authors = explode(';', $author_string);
$authorCount = count($authors);
} else {
$authorCount = 0;
$replace_values[$v] = '';
}
if ($authorCount > 0) {
foreach ($authors as $author) {
// for legacy profile handling
if (is_string($author)) {
preg_match('/{{(.*?)}}/s', $author, $matches);
if (!empty($matches)) {
$id = trim($matches[1]);
if (is_numeric($id)) {
$user = \User::getInstance($id);
if (is_object($user)) {
$a[] = '<a rel="external" href="' . \Route::url('index.php?option=com_members&id=' . $matches[1]) . '">' . str_replace($matches[0], '', $author) . '</a>';
} else {
//.........这里部分代码省略.........
示例5: formatReference
/**
* Formatting Resources
*
* @param object &$row Record to format
* @param string $link Parameter description (if any) ...
* @param string $highlight String to highlight
* @return string
*/
public static function formatReference(&$row, $link = 'none', $highlight = '')
{
$html = "\t" . '<p>';
if (self::keyExistsOrIsNotEmpty('author', $row)) {
$auths = explode(';', $row->author);
$a = array();
foreach ($auths as $auth) {
preg_match('/{{(.*?)}}/s', $auth, $matches);
if (isset($matches[0]) && $matches[0] != '') {
$matches[0] = preg_replace('/{{(.*?)}}/s', '\\1', $matches[0]);
$aid = 0;
if (is_numeric($matches[0])) {
$aid = $matches[0];
} else {
$zuser = \User::getInstance(trim($matches[0]));
if (is_object($zuser)) {
$aid = $zuser->get('id');
}
}
$auth = preg_replace('/{{(.*?)}}/s', '', $auth);
if ($aid) {
$a[] = '<a href="' . \Route::url('index.php?option=com_members&id=' . $aid) . '">' . trim($auth) . '</a>';
} else {
$a[] = trim($auth);
}
} else {
$a[] = trim($auth);
}
}
$row->author = implode('; ', $a);
$html .= stripslashes($row->author);
} elseif (self::keyExistsOrIsNotEmpty('editor', $row)) {
$html .= stripslashes($row->editor);
}
if (self::keyExistsOrIsNotEmpty('year', $row)) {
$html .= ' (' . $row->year . ')';
}
if (self::keyExistsOrIsNotEmpty('title', $row)) {
if (!$row->url) {
$html .= ', "' . stripslashes($row->title);
} else {
$html .= ', "<a href="' . self::cleanUrl($row->url) . '">' . String::highlight(stripslashes($row->title), $highlight) . '</a>';
}
}
if (self::keyExistsOrIsNotEmpty('journal', $row) || self::keyExistsOrIsNotEmpty('edition', $row) || self::keyExistsOrIsNotEmpty('booktitle', $row)) {
$html .= ',';
}
$html .= '"';
if (self::keyExistsOrIsNotEmpty('journal', $row)) {
$html .= ' <i>' . String::highlight(stripslashes($row->journal), $highlight) . '</i>';
} elseif (self::keyExistsOrIsNotEmpty('booktitle', $row)) {
$html .= ' <i>' . stripslashes($row->booktitle) . '</i>';
}
if ($row->type) {
switch ($row->type) {
case 'phdthesis':
$html .= ' (' . \Lang::txt('PhD Thesis') . ')';
break;
case 'mastersthesis':
$html .= ' (' . \Lang::txt('Masters Thesis') . ')';
break;
default:
break;
}
}
if (self::keyExistsOrIsNotEmpty('edition', $row)) {
$html = self::grammarCheck($html, ',');
$html .= ' ' . $row->edition;
}
if (self::keyExistsOrIsNotEmpty('chapter', $row)) {
$html = self::grammarCheck($html, ',');
$html .= ' ' . stripslashes($row->chapter);
}
if (self::keyExistsOrIsNotEmpty('series', $row)) {
$html = self::grammarCheck($html, ',');
$html .= ' ' . stripslashes($row->series);
}
if (self::keyExistsOrIsNotEmpty('publisher', $row)) {
$html = self::grammarCheck($html, ',');
$html .= ' ' . stripslashes($row->publisher);
}
if (self::keyExistsOrIsNotEmpty('address', $row)) {
$html = self::grammarCheck($html, ',');
$html .= ' ' . stripslashes($row->address);
}
if (self::keyExistsOrIsNotEmpty('volume', $row)) {
$html = self::grammarCheck($html, ',');
$html .= ' <b>' . $row->volume . '</b>';
}
if (self::keyExistsOrIsNotEmpty('number', $row)) {
$html = self::grammarCheck($html, ',');
$html .= ' <b>' . $row->number . '</b>';
//.........这里部分代码省略.........
示例6: array
echo Route::url($this->base . '&task=toggleactive&id=' . $task->id);
?>
"></a>
</div>
<div class="td">
<div class="small-label"><?php
echo Lang::txt('COM_TIME_TASKS_NAME');
?>
:</div>
<div class="small-content">
<a href="<?php
echo Route::url($this->base . '&task=edit&id=' . $task->id);
?>
">
<?php
echo String::highlight($task->name, $this->filters['search'], array('html' => true));
?>
</a>
</div>
</div>
<div class="td">
<div class="small-label"><?php
echo Lang::txt('COM_TIME_TASKS_HUB_NAME');
?>
:</div>
<div class="small-content">
<?php
echo $task->hub->name;
?>
</div>
</div>
示例7: formatResults
private function formatResults($results, $terms)
{
$highlightOptions = array('format' => '<b>\\1</b>', 'html' => false, 'regex' => "|%s|iu");
$snippetFields = array('description', 'fulltext', 'abstract');
// Format the results for the view
foreach ($results as &$result) {
// Event for special formatting
$override = Event::trigger('search.onFormatResult', array($result['hubtype'], &$result, $terms, $highlightOptions));
// Only allow one override per result
if (count($override) == 1) {
$override = $override[0];
}
if (empty($override)) {
//@FIXME: SOLR-specific
$result['title'] = $result['title'][0];
// Appends http(s)://
if (isset($result['url'])) {
$result['url'] = rtrim(Request::base(), "/") . $result['url'];
} else {
$result['url'] = '';
}
$snippet = '';
foreach ($result as $field => &$r) {
// Only work on strings
if (is_string($r)) {
$r = strip_tags($r);
}
// Highlight everything except the URL
if ($field != 'url') {
$r = \Hubzero\Utility\String::highlight($r, $terms, $highlightOptions);
}
/**
* Generate the snippet
* A snippet is the search result text which is displayed
**/
if (in_array($field, $snippetFields)) {
$snippet .= $r . " ";
}
}
// Do some filtering
$snippet = str_replace("\n", '', $snippet);
$snippet = str_replace("\r", '', $snippet);
$snippet = str_replace("<br/>", '', $snippet);
$snippet = str_replace("<br>", '', $snippet);
$snippet = \Hubzero\Utility\String::excerpt($snippet, $terms, $radius = 200, $ellipsis = '…');
$result['snippet'] = $snippet;
if (isset($result['author'])) {
$authorCnt = 1;
$authorString = '';
foreach ($result['author'] as $author) {
if ($authorCnt < count($result['author'])) {
$authorString .= $author;
$authorString .= ',';
} else {
$authorString .= $author;
}
$authorCnt++;
}
$result['authorString'] = $authorString;
}
} else {
$result = $override;
}
}
// End foreach results
return $results;
}