当前位置: 首页>>代码示例>>PHP>>正文


PHP SearchResult::getCategorySnippet方法代码示例

本文整理汇总了PHP中SearchResult::getCategorySnippet方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchResult::getCategorySnippet方法的具体用法?PHP SearchResult::getCategorySnippet怎么用?PHP SearchResult::getCategorySnippet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SearchResult的用法示例。


在下文中一共展示了SearchResult::getCategorySnippet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: showHit

 /**
  * Format a single hit result
  *
  * @param SearchResult $result
  * @param array $terms Terms to highlight
  *
  * @return string
  */
 protected function showHit($result, $terms)
 {
     if ($result->isBrokenTitle()) {
         return '';
     }
     $title = $result->getTitle();
     $titleSnippet = $result->getTitleSnippet();
     if ($titleSnippet == '') {
         $titleSnippet = null;
     }
     $link_t = clone $title;
     Hooks::run('ShowSearchHitTitle', array(&$link_t, &$titleSnippet, $result, $terms, $this));
     $link = Linker::linkKnown($link_t, $titleSnippet);
     //If page content is not readable, just return the title.
     //This is not quite safe, but better than showing excerpts from non-readable pages
     //Note that hiding the entry entirely would screw up paging.
     if (!$title->userCan('read', $this->getUser())) {
         return "<li>{$link}</li>\n";
     }
     // If the page doesn't *exist*... our search index is out of date.
     // The least confusing at this point is to drop the result.
     // You may get less results, but... oh well. :P
     if ($result->isMissingRevision()) {
         return '';
     }
     // format redirects / relevant sections
     $redirectTitle = $result->getRedirectTitle();
     $redirectText = $result->getRedirectSnippet();
     $sectionTitle = $result->getSectionTitle();
     $sectionText = $result->getSectionSnippet();
     $categorySnippet = $result->getCategorySnippet();
     $redirect = '';
     if (!is_null($redirectTitle)) {
         if ($redirectText == '') {
             $redirectText = null;
         }
         $redirect = "<span class='searchalttitle'>" . $this->msg('search-redirect')->rawParams(Linker::linkKnown($redirectTitle, $redirectText))->text() . "</span>";
     }
     $section = '';
     if (!is_null($sectionTitle)) {
         if ($sectionText == '') {
             $sectionText = null;
         }
         $section = "<span class='searchalttitle'>" . $this->msg('search-section')->rawParams(Linker::linkKnown($sectionTitle, $sectionText))->text() . "</span>";
     }
     $category = '';
     if ($categorySnippet) {
         $category = "<span class='searchalttitle'>" . $this->msg('search-category')->rawParams($categorySnippet)->text() . "</span>";
     }
     // format text extract
     $extract = "<div class='searchresult'>" . $result->getTextSnippet($terms) . "</div>";
     $lang = $this->getLanguage();
     // format description
     $byteSize = $result->getByteSize();
     $wordCount = $result->getWordCount();
     $timestamp = $result->getTimestamp();
     $size = $this->msg('search-result-size', $lang->formatSize($byteSize))->numParams($wordCount)->escaped();
     if ($title->getNamespace() == NS_CATEGORY) {
         $cat = Category::newFromTitle($title);
         $size = $this->msg('search-result-category-size')->numParams($cat->getPageCount(), $cat->getSubcatCount(), $cat->getFileCount())->escaped();
     }
     $date = $lang->userTimeAndDate($timestamp, $this->getUser());
     $fileMatch = '';
     // Include a thumbnail for media files...
     if ($title->getNamespace() == NS_FILE) {
         $img = $result->getFile();
         $img = $img ?: wfFindFile($title);
         if ($result->isFileMatch()) {
             $fileMatch = "<span class='searchalttitle'>" . $this->msg('search-file-match')->escaped() . "</span>";
         }
         if ($img) {
             $thumb = $img->transform(array('width' => 120, 'height' => 120));
             if ($thumb) {
                 $desc = $this->msg('parentheses')->rawParams($img->getShortDesc())->escaped();
                 // Float doesn't seem to interact well with the bullets.
                 // Table messes up vertical alignment of the bullets.
                 // Bullets are therefore disabled (didn't look great anyway).
                 return "<li>" . '<table class="searchResultImage">' . '<tr>' . '<td style="width: 120px; text-align: center; vertical-align: top;">' . $thumb->toHtml(array('desc-link' => true)) . '</td>' . '<td style="vertical-align: top;">' . "{$link} {$redirect} {$category} {$section} {$fileMatch}" . $extract . "<div class='mw-search-result-data'>{$desc} - {$date}</div>" . '</td>' . '</tr>' . '</table>' . "</li>\n";
             }
         }
     }
     $html = null;
     $score = '';
     if (Hooks::run('ShowSearchHit', array($this, $result, $terms, &$link, &$redirect, &$section, &$extract, &$score, &$size, &$date, &$related, &$html))) {
         $html = "<li><div class='mw-search-result-heading'>" . "{$link} {$redirect} {$category} {$section} {$fileMatch}</div> {$extract}\n" . "<div class='mw-search-result-data'>{$size} - {$date}</div>" . "</li>\n";
     }
     return $html;
 }
开发者ID:D66Ha,项目名称:mediawiki,代码行数:96,代码来源:SpecialSearch.php


注:本文中的SearchResult::getCategorySnippet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。