/** * Generate an extract based on the content being searched and the search * terms. An extract is based on a number of snippets, joined together by * ellipses. By default, we will attempt to generate three snippets, each with * length sixty characters. * * The returned extract will have the terms highlighted. * * Note that this code is very inefficient, and just serves as a quick demo of * the possibilities. * * @param string $content The content that has been searched. * @param string $search_terms The search terms. * @param integer $number_of_snippets The number of snippets to make up the extract. * @param integer $snippet_length The length of each snippet. * @return string The extract. * @author Joe Freeman */ function search_extract($content, $search_terms, $number_of_snippets = 3, $snippet_length = 60) { if (!is_array($search_terms)) { $search_terms = explode(' ', $search_terms); } // This is going to be our collection of snippets $snippets = array(); // Start at the beginning of the string $next_start = 0; // Do this for each snippet foreach (range(0, $number_of_snippets) as $count) { // If we run out of content, then just give up if ($next_start > strlen($content)) { break; } // Find the first occurance of any of the search terms $start = strlen($content); foreach ($search_terms as $term) { $start = min($start, stripos($content, $term, $next_start)); } // Try and include the word before this one $start = strrpos(substr($content, 0, $start - 1), ' '); // Next time round, we'll start looking at the end of this snippet $next_start = $start + $snippet_length; // At the snippet to the extract and highlight the terms $extract[$count] = search_highlight(trim(substr($content, $start, $snippet_length)), $search_terms); } // Stick all of the snippets together to make up the extract return implode(' … ', $extract) . '…'; }
<?php global $cgi; loader_import('news.Story'); loader_import('news.Functions'); $story = new NewsStory(); if (!empty($parameters['story'])) { // view story $obj = $story->get($parameters['story']); if (!$obj) { echo template_simple('not_found.spt', array('error' => $story->error)); return; } if (!empty($parameters['highlight'])) { loader_import('saf.Misc.Search'); $obj->body = search_bar($parameters['highlight'], '/index/news-search-action') . search_highlight($obj->body, $parameters['highlight']); $obj->highlight = $parameters['highlight']; } $pages = news_page_split($obj->body); if (!$cgi->pagenum) { $cgi->pagenum = 1; } $obj->body = news_page_nav($pages, $cgi->pagenum, $obj->id, $parameters['highlight']); $obj->pagenum = $cgi->pagenum; if (appconf('comments')) { $obj->comments = true; loader_import('news.Comment'); $c = new NewsComment(); $c->orderBy('ts asc'); $obj->commentList = $c->find($obj->id); if (!$obj->commentList) {
/** * * @global array $TEXT * @global array $MENU * @global array $HEADING * @global array $MESSAGE * @global array $globals several global vars * @global datadase $database * @global wb $wb * @global string $global_name * @param int $block * @return void */ function page_content($block = 1) { // Get outside objects global $TEXT, $MENU, $HEADING, $MESSAGE; global $globals; global $database; global $wb; $admin = $wb; if ($wb->page_access_denied == true) { echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS']; return; } if ($wb->page_no_active_sections == true) { echo $MESSAGE['FRONTEND']['SORRY_NO_ACTIVE_SECTIONS']; return; } if (isset($globals) and is_array($globals)) { foreach ($globals as $global_name) { global ${$global_name}; } } // Make sure block is numeric if (($block = intval($block)) == 0) { $block = 1; } // Include page content if (!defined('PAGE_CONTENT') or $block != 1) { $page_id = intval($wb->page_id); if ($wb instanceof frontend && !$wb->page_is_visible($wb->page)) { // SOLVED dw2015 return; } // First get all sections for this page $sql = 'SELECT `section_id`, `module`, `publ_start`, `publ_end` '; $sql .= 'FROM `' . TABLE_PREFIX . 'sections` '; $sql .= 'WHERE `page_id`=' . $page_id . ' AND `block`=' . $block . ' '; $sql .= 'ORDER BY `position`'; if (!($query_sections = $database->query($sql))) { return; } // If none were found, check if default content is supposed to be shown if ($query_sections->numRows() == 0) { if ($wb->default_block_content == 'none') { return; } if (is_numeric($wb->default_block_content)) { $page_id = $wb->default_block_content; } else { $page_id = $wb->default_page_id; } $sql = 'SELECT `section_id`, `module`, `publ_start`, `publ_end` '; $sql .= 'FROM `' . TABLE_PREFIX . 'sections` '; $sql .= 'WHERE `page_id`=' . $page_id . ' AND `block`=' . $block . ' '; $sql .= 'ORDER BY `position`'; if (!($query_sections = $database->query($sql))) { return; } // Still no cotent found? Give it up, there's just nothing to show! if ($query_sections->numRows() == 0) { return; } } // Loop through them and include their module file while ($section = $query_sections->fetchRow(MYSQLI_ASSOC)) { // skip this section if it is out of publication-date $now = time(); if (!(($now <= $section['publ_end'] || $section['publ_end'] == 0) && ($now >= $section['publ_start'] || $section['publ_start'] == 0))) { continue; } $section_id = $section['section_id']; $module = $section['module']; $sec_anchor = ''; if (defined('SEC_ANCHOR') && SEC_ANCHOR != '') { $sec_anchor = '<a class="section_anchor" id="' . SEC_ANCHOR . $section_id . '" ></a>'; } // check if module exists - feature: write in errorlog if (is_readable(WB_PATH . '/modules/' . $module . '/view.php')) { // make a anchor for every section. // fetch content -- this is where to place possible output-filters (before highlighting) ob_start(); // fetch original content require WB_PATH . '/modules/' . $module . '/view.php'; $content = ob_get_clean(); if (function_exists('OutputFilterApi')) { $content = OutputFilterApi('OpF?arg=section&module=' . $module . '&page_id=' . $page_id . '§ion_id=' . $section_id, $content); } } else { continue; } // highlights searchresults if (isset($_GET['searchresult']) && is_numeric($_GET['searchresult']) && !isset($_GET['nohighlight']) && isset($_GET['sstring']) && !empty($_GET['sstring'])) { $arr_string = explode(" ", $_GET['sstring']); if ($_GET['searchresult'] == 2) { // exact match $arr_string[0] = str_replace("_", " ", $arr_string[0]); } echo search_highlight($content, $arr_string); } else { echo PHP_EOL . $sec_anchor . PHP_EOL . $content; } } } else { // Searchresults! But also some special pages, // e.g. guestbook (add entry), news (add comment) uses this ob_start(); // fetch original content require PAGE_CONTENT; $content = ob_get_clean(); // Apply Filters if (function_exists('OutputFilterApi')) { $content = OutputFilterApi('OpF?arg=special', $content); } echo $content; } }
konten yang cocok dengan kata <b>'<?php echo urldecode($key['search_terms']); ?> '</b>.</p> <legend></legend> <ul> <?php foreach ($key['results'] as $result) { ?> <li><a href="<?php echo site_url($result->url); ?> "> <h3><?php echo search_highlight(strip_tags($result->title), urldecode($key['search_terms'])); ?> </h3></a> <?php echo search_extract(strip_tags($result->content), urldecode($key['search_terms'])); ?> </li> <legend></legend> <?php } ?> </ul> <?php //echo $this->pagination->create_links();
function search_highlight($needle, $haystack) { $ind = stripos($haystack, $needle); $len = strlen($needle); if ($ind !== false) { return substr($haystack, 0, $ind) . '<span class="yellow nopadding">' . substr($haystack, $ind, $len) . "</span>" . search_highlight($needle, substr($haystack, $ind + $len)); } else { return $haystack; } }
if (count($results)) { ?> <?php foreach ($results as $result) { ?> <div class="search-result"> <h3><a href="#"><?php echo search_extract($result->caption, $search_terms); ?> </a></h3> <a href="<?php echo $result->file; ?> " class="search-link"><?php echo search_highlight($result->file, $search_terms); ?> </a> <p> <?php echo search_extract($result->description, $search_terms); ?> </p> <p></p> <hr> </div> <?php } ?> <?php } else {
echo icon('rightarrow', 16, $strNext) . "</a> "; } else { echo "{$strNext}"; } echo "</p>"; echo "<table align='center' width='80%'>"; $filter['domain'] = 'incident'; echo "<tr>" . colheader(id, $strID, $sort, $order, $filter); echo colheader(incident, $strIncident, $sort, $order, $filter); echo colheader(result, $strResult, $sort, $order, $filter); //echo colheader(score, $strScore, $sort, $order, $filter); echo colheader(date, $strDate, $sort, $order, $filter); $shade = 'shade1'; while ($row = mysql_fetch_object($incidentresult)) { $url = "javascript:incident_details_window('{$row->id}', 'incident{$row->id}')"; echo "<tr class='{$shade}'>\n <td><a href=\"incident_details.php?id={$row->id}\">{$row->id}</a></td>\n <td><a href=\"{$url}\">" . search_highlight($row->title, $search) . "</a></td>\n <td>" . search_highlight($row->bodytext, $search) . "</td>\n <td>" . ldate($CONFIG['dateformat_datetime'], $row->timestamp) . "</td></tr>"; if ($shade == 'shade1') { $shade = 'shade2'; } else { $shade = 'shade1'; } } echo "</table>"; } //SITE RESULTS $sitesql = "SELECT *,MATCH (name) AGAINST ('{$search}' IN BOOLEAN MODE) AS score "; $sitesql .= "FROM `{$dbSites}` as s "; $sitesql .= "WHERE MATCH (name) AGAINST ('{$search}' IN BOOLEAN MODE) "; if ($domain == 'sites' and !empty($sort)) { if ($sort == 'id') { $sitesql .= "ORDER BY k.title ";
page_title(intl_get('Search')); } if (!empty($parameters['query'])) { loader_import('saf.GUI.Pager'); $res = $y->query($parameters['query'], $cgi->offset); if (!$res) { page_title('Search Error'); echo '<p>' . $y->error . '</p>'; return; } elseif (isset($res['Error'])) { page_title('Search Error'); echo '<p>' . $res['Error']['Message'] . '</p>'; return; } $parameters['results'] = array(); foreach ($res['ResultSet']['Result'] as $result) { $result['CacheUrl'] = $result['Cache']['Url']; $result['CacheSize'] = ysearch_filter_size($result['Cache']['Size']); $result['Title'] = ysearch_filter_title($result['Title']); $result['Title'] = search_highlight($result['Title'], $cgi->query); $result['Summary'] = search_highlight($result['Summary'], $cgi->query); $parameters['results'][] = $result; } $pg = new Pager($cgi->offset, 25, $res['ResultSet']['totalResultsAvailable']); $pg->setUrl(site_current() . '?query=%s&site=%s', $parameters['query'], $parameters['site']); $pg->getInfo(); template_simple_register('pager', $pg); echo template_simple('search_results.spt', $parameters); } else { echo template_simple('search_form.spt'); }
$p->limit(appconf('limit')); $p->offset($cgi->offset); $list = $p->getThread($cgi->post); if (!empty($cgi->highlight)) { $highlight = '?highlight=' . $cgi->highlight; } else { $highlight = '?highlight='; } $pg = new Pager($cgi->offset, appconf('limit'), $p->total); $pg->setUrl(site_prefix() . '/index/siteforum-list-action/post.%s' . $highlight, $cgi->post); $pg->getInfo(); if (!$cgi->topic) { $cgi->topic = $list[0]->topic_id; } $t = new SiteForum_Topic(); $topic = $t->getTitle($cgi->topic); $subject = $list[0]->subject; if (!empty($cgi->highlight)) { loader_import('saf.Misc.Search'); echo search_bar($cgi->highlight, '/index/sitesearch-app?ctype=siteforum_post&show_types=yes'); $queries = search_split_query($cgi->highlight); foreach (array_keys($list) as $key) { $list[$key]->body = search_highlight($list[$key]->body, $queries); } } page_title($subject); template_simple_register('pager', $pg); echo template_simple('message_list.spt', array('forum_name' => appconf('forum_name'), 'topic' => $topic, 'subject' => $subject, 'list' => $list, 'sitesearch' => @file_exists('inc/app/sitesearch/data/sitesearch.pid'))); if (appconf('template')) { page_template(appconf('template')); }
/** * If you would like search terms to be automatically highlighted in your * web pages, add 'filter 1 = "body: saf.Misc.Search"' to the modes.php file * in your template set, under the appropriate output mode. * * @param string * @return string * @package Misc */ function saf_misc_search_content_filter($body) { global $cgi; if (!empty($cgi->highlight)) { return search_bar($cgi->highlight) . search_highlight($body, $cgi->highlight); } else { if (isset($_SERVER['HTTP_REFERER']) and $_SERVER['HTTP_REFERER'] != '') { $keywords = get_searchengine_keywords($_SERVER['HTTP_REFERER']); if ($keywords) { return search_bar(implode(' ', $keywords)) . search_highlight($body, $keywords); } } } return $body; }
"> <?php $the_title = search_highlight(trim(get_search_query()), get_the_title()); echo $the_title; ?> </a></h5> <!-- / blog headline--> <?php if (get_the_excerpt()) { ?> <!-- blog text--> <?php $the_excerpt = apply_filters('the_content', get_the_excerpt()); $the_excerpt = search_highlight(trim(get_search_query()), $the_excerpt); echo $the_excerpt; ?> <!-- /blog text--> <?php } ?> </div> <div class="clear"></div> </div> <div class="space margin-b20"></div>
<?php foreach ($results as $result) { ?> <article> <a href="<?php echo $result->url(); ?> "> <h2 class="delta"><?php echo $result->title()->smartypants(); ?> </h2> <!-- With sarch keyword highlighting --> <p><?php echo search_highlight(excerpt($result->text()), $search->query(), 10); ?> </p> <!-- Without sarch keyword highlighting --> <!-- <p><?php echo excerpt($result->text()); ?> </p> --> <p class="SearchResults-url"><?php echo html($result->url()); ?> </p> </a> </article>