public function getEscapedLinkOnly()
 {
     $last = $this->memory->retrieve();
     if (!empty($last)) {
         $escaper = $this->getView()->plugin('escapeHtml');
         return $last;
     }
     return '';
 }
示例#2
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 '';
 }
示例#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
 /**
  * Test disabling the memory.
  *
  * @return void
  */
 public function testDisable()
 {
     $mem = new Memory();
     $url = 'http://test';
     $mem->rememberSearch($url);
     $this->assertEquals($url, $mem->retrieve());
     $mem->disable();
     $mem->rememberSearch('http://ignoreme');
     $this->assertEquals($url, $mem->retrieve());
 }