本文整理汇总了PHP中PMF_Utils::setHighlightedString方法的典型用法代码示例。如果您正苦于以下问题:PHP PMF_Utils::setHighlightedString方法的具体用法?PHP PMF_Utils::setHighlightedString怎么用?PHP PMF_Utils::setHighlightedString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PMF_Utils
的用法示例。
在下文中一共展示了PMF_Utils::setHighlightedString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderSearchResult
/**
* Renders the result page for the main search page
*
* @param PMF_Search_Resultset $resultSet PMF_Search_Resultset object
* @param integer $currentPage Current page number
*
* @return string
*/
public function renderSearchResult(PMF_Search_Resultset $resultSet, $currentPage)
{
$html = '';
$confPerPage = $this->_config->get('records.numberOfRecordsPerPage');
$numOfResults = $resultSet->getNumberOfResults();
$totalPages = ceil($numOfResults / $confPerPage);
$lastPage = $currentPage * $confPerPage;
$firstPage = $lastPage - $confPerPage;
if ($lastPage > $numOfResults) {
$lastPage = $numOfResults;
}
if (0 < $numOfResults) {
$html .= sprintf("<p>%s</p>\n", $this->plurals->GetMsg('plmsgSearchAmount', $numOfResults));
if (1 < $totalPages) {
$html .= sprintf("<p><strong>%s%d %s %s</strong></p>\n", $this->translation['msgPage'], $currentPage, $this->translation['msgVoteFrom'], $this->plurals->GetMsg('plmsgPagesTotal', $totalPages));
}
$html .= "<ul class=\"phpmyfaq-search-results\">\n";
$counter = $displayedCounter = 0;
foreach ($resultSet->getResultset() as $result) {
if ($displayedCounter >= $confPerPage) {
break;
}
$counter++;
if ($counter <= $firstPage) {
continue;
}
$displayedCounter++;
// Set language for current category to fetch the correct category name
$this->Category->setLanguage($result->lang);
$categoryInfo = $this->Category->getCategoriesFromArticle($result->id);
$question = PMF_Utils::chopString($result->question, 15);
$answerPreview = PMF_Utils::chopString(strip_tags($result->answer), 25);
$searchterm = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']', '"'), '', $this->searchterm);
$searchterm = preg_quote($searchterm, '/');
$searchItems = explode(' ', $searchterm);
if (PMF_String::strlen($searchItems[0]) > 1) {
foreach ($searchItems as $item) {
if (PMF_String::strlen($item) > 2) {
$question = PMF_Utils::setHighlightedString($question, $item);
$answerPreview = PMF_Utils::setHighlightedString($answerPreview, $item);
}
}
}
// Build the link to the faq record
$currentUrl = sprintf('%s?%saction=artikel&cat=%d&id=%d&artlang=%s&highlight=%s', PMF_Link::getSystemRelativeUri(), $this->sessionId, $result->category_id, $result->id, $result->lang, urlencode($searchterm));
$oLink = new PMF_Link($currentUrl, $this->_config);
$oLink->text = $question;
$oLink->itemTitle = $oLink->tooltip = $result->question;
$html .= "<li>";
$html .= sprintf("<strong>%s</strong>: %s<br />", $categoryInfo[0]['name'], $oLink->toHtmlAnchor());
$html .= sprintf("<small class=\"searchpreview\"><strong>%s</strong> %s...</small>\n", $this->translation['msgSearchContent'], $answerPreview);
$html .= "</li>";
}
$html .= "</ul>\n";
if (1 < $totalPages) {
$html .= $this->pagination->render();
}
} else {
$html = $this->translation['err_noArticles'];
}
return $html;
}
示例2: sprintf
$answer = $oGlossary->insertItemsIntoContent($faq->faqRecord['content']);
// Set the path of the current category
$categoryName = $category->getPath($currentCategory, ' » ', true);
$changeLanguagePath = PMF_Link::getSystemRelativeUri() . sprintf('?%saction=artikel&cat=%d&id=%d&artlang=%s', $sids, $currentCategory, $faq->faqRecord['id'], $LANGCODE);
$oLink = new PMF_Link($changeLanguagePath);
$oLink->itemTitle = $faq->getRecordTitle($faq->faqRecord['id'], false);
$changeLanguagePath = $oLink->toString();
$highlight = PMF_Filter::filterInput(INPUT_GET, 'highlight', FILTER_SANITIZE_STRIPPED);
if (!is_null($highlight) && $highlight != "/" && $highlight != "<" && $highlight != ">" && PMF_String::strlen($highlight) > 3) {
$highlight = str_replace("'", "´", $highlight);
$highlight = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']'), '', $highlight);
$highlight = preg_quote($highlight, '/');
$searchItems = explode(' ', $highlight);
foreach ($searchItems as $item) {
$question = PMF_Utils::setHighlightedString($question, $item);
$answer = PMF_Utils::setHighlightedString($answer, $item);
}
}
// Hack: Apply the new SEO schema to those HTML anchors to
// other faq records (Internal Links) added with WYSIWYG Editor:
// href="index.php?action=artikel&cat=NNN&id=MMM&artlang=XYZ"
// Search for href attribute links
$oLnk->resetPool();
$oLnk->parse_string($answer);
$fixedContent = str_replace('href="#', sprintf('href="index.php?action=artikel&lang=%s&cat=%d&id=%d&artlang=%s#', $LANGCODE, $currentCategory, $faq->faqRecord['id'], $LANGCODE), $answer);
$oLnk->resetPool();
$oLnk->parse_string($fixedContent);
// Search for href attributes only
$linkArray = $oLnk->getUrlpool();
if (isset($linkArray['href'])) {
foreach (array_unique($linkArray['href']) as $_url) {
示例3: sprintf
$thema = $oGlossary->insertItemsIntoContent($thema);
// Set the path of the current category
$categoryName = $categoryLayout->renderBreadcrumb($categoryPath);
$changeLanguagePath = PMF_Link::getSystemRelativeUri() . sprintf('?%saction=artikel&cat=%d&id=%d&artlang=%s', $sids, $currentCategory, $faq->faqRecord['id'], $LANGCODE);
$oLink = new PMF_Link($changeLanguagePath);
$oLink->itemTitle = $faq->getRecordTitle($faq->faqRecord['id'], false);
$changeLanguagePath = $oLink->toString();
$highlight = PMF_Filter::filterInput(INPUT_GET, 'highlight', FILTER_SANITIZE_STRIPPED);
if (!is_null($highlight) && $highlight != "/" && $highlight != "<" && $highlight != ">" && PMF_String::strlen($highlight) > 3) {
$highlight = str_replace("'", "´", $highlight);
$highlight = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']'), '', $highlight);
$highlight = preg_quote($highlight, '/');
$searchItems = explode(' ', $highlight);
foreach ($searchItems as $item) {
$thema = PMF_Utils::setHighlightedString($thema, $item);
$content = PMF_Utils::setHighlightedString($content, $item);
}
}
// Hack: Apply the new SEO schema to those HTML anchors to
// other faq records (Internal Links) added with WYSIWYG Editor:
// href="index.php?action=artikel&cat=NNN&id=MMM&artlang=XYZ"
// Search for href attribute links
$oLnk->resetPool();
$oLnk->parse_string($content);
$fixedContent = str_replace('href="#', sprintf('href="index.php?action=artikel&lang=%s&cat=%d&id=%d&artlang=%s#', $LANGCODE, $currentCategory, $faq->faqRecord['id'], $LANGCODE), $content);
$oLnk->resetPool();
$oLnk->parse_string($fixedContent);
// Search for href attributes only
$linkArray = $oLnk->getUrlpool();
if (isset($linkArray['href'])) {
foreach (array_unique($linkArray['href']) as $_url) {
示例4: renderSearchResult
/**
* Renders the result page for the main search page
*
* @param PMF_Search_Resultset $resultSet PMF_Search_Resultset object
* @param integer $currentPage Current page number
*
* @return string
*/
public function renderSearchResult(PMF_Search_Resultset $resultSet, $currentPage)
{
$html = '';
$confPerPage = PMF_Configuration::getInstance()->get('main.numberOfRecordsPerPage');
$numOfResults = $resultSet->getNumberOfResults();
$totalPages = ceil($numOfResults / $confPerPage);
$lastPage = $currentPage * $confPerPage;
$firstPage = $lastPage - $confPerPage;
if ($lastPage > $numOfResults) {
$lastPage = $numOfResults;
}
if (0 < $numOfResults) {
$html .= sprintf("<p>%s</p>\n", $this->plurals->GetMsg('plmsgSearchAmount', $numOfResults));
if (1 < $totalPages) {
$html .= sprintf("<p><strong>%s%d %s %s</strong></p>\n", $this->translation['msgPage'], $currentPage, $this->translation['msgVoteFrom'], $this->plurals->GetMsg('plmsgPagesTotal', $totalPages));
}
$html .= "<ul class=\"phpmyfaq_ul\">\n";
foreach ($resultSet->getResultset() as $result) {
$categoryName = $this->categoryLayout->renderBreadcrumb(array($result->category_id));
$question = PMF_Utils::chopString($result->question, 15);
$answerPreview = PMF_Utils::chopString(strip_tags($result->answer), 25);
$searchterm = str_replace(array('^', '.', '?', '*', '+', '{', '}', '(', ')', '[', ']', '"'), '', $this->searchterm);
$searchterm = preg_quote($searchterm, '/');
$searchItems = explode(' ', $searchterm);
if (PMF_String::strlen($searchItems[0]) > 1) {
foreach ($searchItems as $item) {
if (PMF_String::strlen($item) > 2) {
$question = PMF_Utils::setHighlightedString($question, $item);
$answerPreview = PMF_Utils::setHighlightedString($answerPreview, $item);
}
}
}
// Build the link to the faq record
$currentUrl = sprintf('%s?%saction=artikel&cat=%d&id=%d&artlang=%s&highlight=%s', PMF_Link::getSystemRelativeUri(), $this->sessionId, $result->category_id, $result->id, $result->lang, urlencode($searchterm));
$oLink = new PMF_Link($currentUrl);
$oLink->text = $oLink->itemTitle = $oLink->tooltip = $result->question;
$html .= sprintf("<li><strong>%s</strong>: %s<br /><div class=\"searchpreview\"><strong>%s</strong> %s...</div><br /></li>\n", $categoryName, $oLink->toHtmlAnchor(), $this->translation['msgSearchContent'], $answerPreview);
}
$html .= "</ul>\n";
if (1 > $totalPages) {
$html .= $this->pagination->render();
}
} else {
$html = $this->translation['err_noArticles'];
}
return $html;
}