Modify the request file rather than the request URL, for better compatibility with other plugins

This commit is contained in:
pontus.horn
2016-07-06 13:53:52 +02:00
parent 00056fde62
commit b244625842

View File

@@ -28,7 +28,6 @@ class PicoSearch extends AbstractPicoPlugin
public function onRequestUrl(&$url) public function onRequestUrl(&$url)
{ {
if (preg_match('/^(.+\/)?search\/([^\/]+)(\/.+)?$/', $url, $matches)) { if (preg_match('/^(.+\/)?search\/([^\/]+)(\/.+)?$/', $url, $matches)) {
$url = $matches[1] . 'search' . ($matches[3] ?: '');
$this->search_terms = urldecode($matches[2]); $this->search_terms = urldecode($matches[2]);
if (!empty($matches[1])) { if (!empty($matches[1])) {
@@ -37,6 +36,35 @@ class PicoSearch extends AbstractPicoPlugin
} }
} }
/**
* If accessing search results, {@link Pico::discoverRequestFile()} will have failed since
* the search terms are included in the URL but do not map to a file. Therefore,
*
* @see Pico::discoverRequestFile()
* @param string &$url request URL
* @return void
*/
public function onRequestFile(&$file)
{
if ($this->search_terms) {
$pico = $this->getPico();
// Aggressively strip out any ./ or ../ parts from the search area before using it
// as the folder to look in. Should already be taken care of previously, but just
// as a safeguard to make sure nothing slips through the cracks.
if ($this->search_area) {
$folder = str_replace('\\', '/', $this->search_area);
$folder = preg_replace('~\b../~', '', $folder);
$folder = preg_replace('~\b./~', '', $folder);
}
$temp_file = $pico->getConfig('content_dir') . ($folder ?: '') . 'search' . $pico->getConfig('content_ext');
if (file_exists($temp_file)) {
$file = $temp_file;
}
}
}
/** /**
* If accessing search results, filter the $pages array to pages matching the search terms. * If accessing search results, filter the $pages array to pages matching the search terms.
* *