public function GoogleSiteSearch::getSearchHead in Google Site Search 7
Same name and namespace in other branches
- 6 includes/GoogleSiteSearch.inc \GoogleSiteSearch::GetSearchHead()
Get a head to the search results.
Return value
string The search head HTML code.
File
- includes/
GoogleSiteSearch.inc, line 422 - GSS module site search inc file.
Class
- GoogleSiteSearch
- Class for interaction with Google Site Search.
Code
public function getSearchHead() {
// Get total pages.
$total_results = $this
->getTotalResults();
$page_size = $this
->getPageSize();
$current_page = $this
->getCurrentPage();
$show_start = $page_size * $current_page + 1;
$show_end = $page_size * $current_page + $page_size;
if ($show_end > $total_results) {
$show_end = $total_results;
}
$html = '<div class="searchhead">';
if (variable_get('gss_labels', TRUE) == 1) {
// Adding the tabs for the search labels.
$html .= '<span>' . t('Show only results of type:') . '</span><ul>';
// Checking which one is the active tab.
$active_html_first_element = '';
// There is no faceted search.
if (strpos($this->query, 'more:') === FALSE) {
// Then the first element is active.
$active_html_first_element = 'class="active"';
$term_from_query = '';
}
else {
$query_parts = explode(':', $this->query);
// In this case we store the category to check later.
$term_from_query = end($query_parts);
}
// Resume $this->query to its original value (no categories).
$this->query = current(explode(' more:', $this->query));
// First item will always be the original query.
$html .= '<li>' . '<a ' . $active_html_first_element . ' href=' . urlencode($this->query) . '>' . t('All results') . '</a>' . '</li>';
// Loop to create all remaining categorized tabs / queries.
if ($total_results > 0) {
foreach ($this->categories as $category) {
// Do not inherit from previous loop...
$active_html_others = '';
if ($category['label'] == $term_from_query) {
$active_html_others = 'class="active"';
}
// Builds up the path to the tab links.
$new_query = urlencode($this->query) . '+more%3A' . $category['label'];
$html .= '<li><a ' . $active_html_others . ' href=' . $new_query . '>' . t($category['anchor_text'], array(), array(
'context' => 'gss:search-result:filter',
)) . '</a></li>';
}
}
$html .= '</ul>';
}
if (variable_get('gss_number_of_results', TRUE) == 1 && $total_results !== 0) {
$html .= t('Shows @show_start to @show_end of approximately @total_results hits', array(
'@show_start' => $show_start,
'@show_end' => $show_end,
'@total_results' => $this->approxTotalResults,
));
}
$html .= '</div>';
// Return search head.
return $html;
}