From 9f7ef8998db24fe650f20c1b239c6391538bc8ab Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Mon, 3 Apr 2017 16:46:46 -0400 Subject: [PATCH] Add %%lookfor%% token support to search forwarding. --- config/vufind/searchbox.ini | 5 ++++- module/VuFind/src/VuFind/Controller/CombinedController.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/config/vufind/searchbox.ini b/config/vufind/searchbox.ini index 365da2ad6e1..d6f8e48ee8e 100644 --- a/config/vufind/searchbox.ini +++ b/config/vufind/searchbox.ini @@ -9,7 +9,10 @@ combinedHandlers = false ; of settings with the following keys: ; ; type[] = "VuFind" for an internal search module or "External" for an external URL -; target[] = Search class ID for "VuFind" type, URL for "External" type +; target[] = Search class ID for "VuFind" type, URL for "External" type; by default, +; the user's search terms will be appended to the end of the URL in +; "External" mode. You may use a %%lookfor%% placeholder string in the +; URL to force the query to be injected at a specific position. ; label[] = Label for this value (subject to translation) [CombinedHandlers] type[] = VuFind diff --git a/module/VuFind/src/VuFind/Controller/CombinedController.php b/module/VuFind/src/VuFind/Controller/CombinedController.php index 0aef4b7790b..50fe00b8452 100644 --- a/module/VuFind/src/VuFind/Controller/CombinedController.php +++ b/module/VuFind/src/VuFind/Controller/CombinedController.php @@ -245,7 +245,10 @@ class CombinedController extends AbstractSearch return $this->redirect()->toUrl($base . '?' . http_build_query($params)); case 'External': $lookfor = $this->params()->fromQuery('lookfor'); - return $this->redirect()->toUrl($target . urlencode($lookfor)); + $finalTarget = (false === strpos($target, '%%lookfor%%')) + ? $target . urlencode($lookfor) + : str_replace('%%lookfor%%', urlencode($lookfor), $target); + return $this->redirect()->toUrl($finalTarget); default: // If parameters are completely missing, just redirect to home instead // of throwing an error; this is possibly a misbehaving crawler that -- GitLab