示例#1
0
 /**
  * If a previous search is recorded in the session, return a link to it;
  * otherwise, return a blank string.
  *
  * @param string $link   Text to use as body of link
  * @param string $prefix Text to place in front of link
  * @param string $suffix Text to place after link
  *
  * @return string
  */
 public function __invoke($link, $prefix = '', $suffix = '')
 {
     $last = $this->memory->retrieve();
     if (!empty($last)) {
         $escaper = $this->getView()->plugin('escapeHtml');
         return $prefix . '<a href="' . $escaper($last) . '">' . $link . '</a>' . $suffix;
     }
     return '';
 }
 public function getEscapedLinkOnly()
 {
     $last = $this->memory->retrieve();
     if (!empty($last)) {
         $escaper = $this->getView()->plugin('escapeHtml');
         return $last;
     }
     return '';
 }
示例#3
0
 /**
  * Handle event. Add config values
  *
  * @param EventInterface $event Search pre event
  *
  * @return EventInterface
  */
 public function onSearchPre(EventInterface $event)
 {
     $backend = $event->getTarget();
     if ($backend === $this->backend) {
         $params = $event->getParam('params');
         if ($params) {
             // Set highlighting parameters unless explicitly disabled:
             $hl = $params->get('hl');
             if (!isset($hl[0]) || $hl[0] != 'false') {
                 // Add hl.q for non query events
                 if (!$event->getParam('query', false)) {
                     $lastSearch = $this->memory->retrieve();
                     if ($lastSearch) {
                         $urlParams = parse_url($lastSearch);
                         if (isset($urlParams['query'])) {
                             parse_str($urlParams['query'], $queryParams);
                             if (isset($queryParams['lookfor'])) {
                                 $params->set('hl.q', '*:"' . addslashes($queryParams['lookfor']) . '"');
                             }
                         }
                     }
                 }
                 // All all highlight config fields
                 foreach ($this->config as $key => $value) {
                     $params->set('hl.' . $key, $value);
                 }
             }
         }
     }
     return $event;
 }
示例#4
0
 /**
  * Retrieve the last sort option used.
  *
  * @param string $context Context of search (usually search class ID).
  *
  * @return string
  */
 public function getLastSort($context)
 {
     return $this->memory->retrieveLastSetting($context, 'sort');
 }
示例#5
0
 /**
  * Test disabling the memory.
  *
  * @return void
  */
 public function testDisable()
 {
     $mem = new Memory();
     $url = 'http://test';
     $mem->rememberSearch($url);
     $this->assertEquals($url, $mem->retrieveSearch());
     $mem->disable();
     $mem->rememberSearch('http://ignoreme');
     $this->assertEquals($url, $mem->retrieveSearch());
 }
示例#6
0
 /**
  * Update the remembered "last search" in the session.
  *
  * @param \VuFind\Search\Base\Results $search Search object to remember.
  *
  * @return void
  */
 protected function rememberSearch($search)
 {
     $baseUrl = $this->getController()->url()->fromRoute($search->getOptions()->getSearchAction());
     Memory::rememberSearch($baseUrl . $search->getUrlQuery()->getParams(false));
 }
示例#7
0
 /**
  * Handle search history display && purge
  *
  * @return mixed
  */
 public function historyAction()
 {
     // Force login if necessary
     $user = $this->getUser();
     if ($this->params()->fromQuery('require_login', 'no') !== 'no' && !$user) {
         return $this->forceLogin();
     }
     // Retrieve search history
     $search = $this->getTable('Search');
     $searchHistory = $search->getSearches($this->getServiceLocator()->get('SessionManager')->getId(), is_object($user) ? $user->id : null);
     // Build arrays of history entries
     $saved = $unsaved = array();
     // Loop through the history
     foreach ($searchHistory as $current) {
         $minSO = unserialize($current->search_object);
         // Saved searches
         if ($current->saved == 1) {
             $saved[] = $minSO->deminify($this->getSearchManager());
         } else {
             // All the others...
             // If this was a purge request we don't need this
             if ($this->params()->fromQuery('purge') == 'true') {
                 $current->delete();
                 // We don't want to remember the last search after a purge:
                 Memory::forgetSearch();
             } else {
                 // Otherwise add to the list
                 $unsaved[] = $minSO->deminify($this->getSearchManager());
             }
         }
     }
     return $this->createViewModel(array('saved' => $saved, 'unsaved' => $unsaved));
 }