2011-03-18 04:05:23 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Extension to provide a search interface when applied to ContentController
|
|
|
|
*
|
|
|
|
* @package cms
|
|
|
|
* @subpackage search
|
|
|
|
*/
|
|
|
|
class ContentControllerSearchExtension extends Extension {
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $allowed_actions = array(
|
2011-03-18 04:05:23 +01:00
|
|
|
'SearchForm',
|
|
|
|
'results',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Site search form
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function SearchForm() {
|
2011-03-18 04:05:23 +01:00
|
|
|
$searchText = _t('SearchForm.SEARCH', 'Search');
|
|
|
|
|
|
|
|
if($this->owner->request && $this->owner->request->getVar('Search')) {
|
|
|
|
$searchText = $this->owner->request->getVar('Search');
|
|
|
|
}
|
|
|
|
|
2011-10-26 07:35:51 +02:00
|
|
|
$fields = new FieldList(
|
2011-03-18 04:05:23 +01:00
|
|
|
new TextField('Search', false, $searchText)
|
|
|
|
);
|
2011-10-26 07:35:51 +02:00
|
|
|
$actions = new FieldList(
|
2011-03-18 04:05:23 +01:00
|
|
|
new FormAction('results', _t('SearchForm.GO', 'Go'))
|
|
|
|
);
|
|
|
|
$form = new SearchForm($this->owner, 'SearchForm', $fields, $actions);
|
|
|
|
$form->classesToSearch(FulltextSearchable::get_searchable_classes());
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function results($data, $form, $request) {
|
2011-03-18 04:05:23 +01:00
|
|
|
$data = array(
|
|
|
|
'Results' => $form->getResults(),
|
|
|
|
'Query' => $form->getSearchQuery(),
|
|
|
|
'Title' => _t('SearchForm.SearchResults', 'Search Results')
|
|
|
|
);
|
|
|
|
return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
|
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|