本文整理汇总了PHP中Hubzero\Utility\String::excerpt方法的典型用法代码示例。如果您正苦于以下问题:PHP String::excerpt方法的具体用法?PHP String::excerpt怎么用?PHP String::excerpt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hubzero\Utility\String
的用法示例。
在下文中一共展示了String::excerpt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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);
}