'. $field['key'] .': '. search_excerpt($keys, $field['value']);
}
}
// put everything into the $results array
$title = reset($item['fields']);
$results[] = array(
'link' => gallery_generate_url(array('itemId' => $item['itemId']), FALSE),
'title' => empty($title['value']) ? t('Gallery item: Untitled') : $title['value'],
'snippet' => implode('
', $excerpt),
'thumbnail' => $thumbnail,
);
}
}
if ($html_head) {
drupal_set_html_head(implode("\n", array_unique($html_head)));
}
return $results;
}
}
/**
* Function _gallery_search_pager_search().
*/
function _gallery_search_pager_search(&$keys, $limit = 10, $element = 0) {
// adapted version of the pager_query() function (from /includes/pager.inc)
// for use with the Gallery2 search() function
//
global $pager_page_array, $pager_total, $pager_total_items;
$page = isset($_GET['page']) ? $_GET['page'] : '';
// convert comma-separated $page to an array, used by other functions.
$pager_page_array = explode(',', $page);
// we calculate the total of pages as ceil(items / limit).
$count = _gallery_search_perform($keys);
$pager_total_items[$element] = $count['count'];
$pager_total[$element] = ceil($pager_total_items[$element] / $limit);
$pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
return _gallery_search_perform($keys, $pager_page_array[$element] * $limit, $limit);
}
/**
* Function _gallery_search_perform().
*/
function _gallery_search_perform(&$keys, $offset = 0, $limit = -1) {
list($search_interface, $options) = _gallery_search_init();
if (!$search_interface) {
return array();
}
// extract query parameters
if ($fields = search_query_extract($keys, 'fields')) {
$keys = trim(preg_replace('/\s+fields:[\w,]*/', '', $keys));
}
$fields = $fields ? array_flip(explode(',', $fields)) : $options;
foreach ($fields as $key => $value) {
$fields[$key] = $key;
}
// perform the actual search
list($ret, $matches) = $search_interface->search($fields, $keys, $offset, $limit);
if ($ret) {
gallery_error(t('Error invoking search() method.'), $ret);
return array();
}
return $matches;
}
/**
* Function _gallery_search_form().
*/
function _gallery_search_form(&$form) {
list($search_interface, $options) = _gallery_search_init();
if (!count($options)) {
return;
}
// extend search form
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced search'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#attributes' => array('class' => 'search-advanced'),
);
$form['advanced']['fields'] = array(
'#type' => 'checkboxes',
'#title' => t('Only the following fields'),
'#prefix' => '
Total Number of Matches: @count
', array('@count' => $results['count'])); unset($results['count']); // arrange items as table $rows = array(); $results = array_chunk($results, $items_per_row); foreach ($results as $item_row) { $row = array(); foreach ($item_row as $item) { $row[] = array('data' => theme('gallery_search_item', $item)); } $rows[] = $row; } $output .= theme('table', array(), $rows); $output .= ''. $item['snippet'] .'
' : '') .'