2010-10-04 06:32:48 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Extension to provide a search interface when applied to ContentController
|
2010-10-13 05:53:12 +02:00
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage search
|
2010-10-04 06:32:48 +02:00
|
|
|
*/
|
|
|
|
class ContentControllerSearchExtension extends Extension {
|
2010-10-13 03:14:27 +02:00
|
|
|
static $allowed_actions = array(
|
|
|
|
'SearchForm',
|
|
|
|
'results',
|
|
|
|
);
|
|
|
|
|
2010-10-04 06:32:48 +02:00
|
|
|
/**
|
|
|
|
* Site search form
|
|
|
|
*/
|
|
|
|
function SearchForm() {
|
2010-10-15 02:30:30 +02:00
|
|
|
$searchText = ($s = $this->owner->request->getVar('Search')) ? $s : _t('SearchForm.SEARCH', 'Search');
|
2010-10-04 06:32:48 +02:00
|
|
|
$fields = new FieldSet(
|
2010-10-15 02:30:30 +02:00
|
|
|
new TextField('Search', false, $searchText)
|
2010-10-04 06:32:48 +02:00
|
|
|
);
|
|
|
|
$actions = new FieldSet(
|
2010-10-15 02:30:30 +02:00
|
|
|
new FormAction('results', _t('SearchForm.GO', 'Go'))
|
2010-10-04 06:32:48 +02:00
|
|
|
);
|
|
|
|
return new SearchForm($this->owner, 'SearchForm', $fields, $actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process and render search results.
|
|
|
|
*
|
|
|
|
* @param array $data The raw request data submitted by user
|
|
|
|
* @param SearchForm $form The form instance that was submitted
|
|
|
|
* @param SS_HTTPRequest $request Request generated for this action
|
|
|
|
*/
|
|
|
|
function results($data, $form, $request) {
|
|
|
|
$data = array(
|
|
|
|
'Results' => $form->getResults(),
|
|
|
|
'Query' => $form->getSearchQuery(),
|
2010-10-15 02:30:30 +02:00
|
|
|
'Title' => _t('SearchForm.SearchResults', 'Search Results')
|
2010-10-04 06:32:48 +02:00
|
|
|
);
|
|
|
|
return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
|
|
|
|
}
|
|
|
|
}
|