Compare commits

..

No commits in common. '196d4c45c5f70ef7a163831dd0a654afa7db33b1' and 'adac1fca75513cb57ef80d0cab587535e527457b' have entirely different histories.

  1. 4
      modules/roblib_search_eds/js/eds_results_article.js
  2. 4
      modules/roblib_search_eds/js/eds_results_book.js
  3. 6
      modules/roblib_search_eds/roblib_search_eds.info.yml
  4. 6
      modules/roblib_search_eds/roblib_search_eds.libraries.yml
  5. 17
      modules/roblib_search_eds/roblib_search_eds.module
  6. 4
      modules/roblib_search_eds/roblib_search_eds.routing.yml
  7. 44
      modules/roblib_search_eds/src/Controller/RoblibSearchEdsController.php
  8. 50
      modules/roblib_search_eds/src/Form/EdsSettingsForm.php
  9. 145
      modules/roblib_search_eds/src/Lib/EBSCOAPI.php
  10. 7
      modules/roblib_search_eds/src/Lib/EBSCODocument.php
  11. 3
      modules/roblib_search_eds/src/Lib/EBSCOResponse.php
  12. 1
      modules/roblib_search_eds/src/Lib/sanitizer.class.php
  13. 22
      modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php
  14. 22
      modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php
  15. 4
      modules/solr_site/js/solr_site_bestbet.js
  16. 4
      modules/solr_site/js/solr_site_results.js
  17. 7
      modules/solr_site/roblib_search_solr_site.info.yml
  18. 6
      modules/solr_site/roblib_search_solr_site.libraries.yml
  19. 82
      modules/solr_site/roblib_search_solr_site.module
  20. 4
      modules/solr_site/roblib_search_solr_site.routing.yml
  21. 42
      modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php
  22. 14
      modules/solr_site/src/Form/SolrsiteSettingsForm.php
  23. 13
      modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php
  24. 13
      modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php
  25. 8
      roblib_search.info.yml
  26. 19
      roblib_search.module
  27. 2
      roblib_search.routing.yml
  28. 36
      src/Controller/RoblibSearchController.php
  29. 10
      src/Form/RoblibSearchForm.php
  30. 10
      src/Form/RoblibSearchSettingsForm.php
  31. 5
      src/Plugin/Block/RoblibSearchBoxBlock.php
  32. 10
      src/Plugin/Block/RoblibSearchOtherSourcesBlock.php
  33. 20
      theme/theme.inc

4
modules/roblib_search_eds/js/eds_results_article.js

@ -1,8 +1,6 @@
Drupal.behaviors.roblib_search_eds_articles = {
attach: function (context, settings) {
// Run once, when the results container appears. The block may be
// rendered later by BigPipe, so don't rely on context being document.
if (once('roblib-search-eds-articles', '#roblib-search-content-eds-articles', context).length) {
if (context == document) {
$query = drupalSettings.path.currentPath.replace('roblib_search/', '');
$url = settings.eds_article_search_url + $query;
article_profile = settings.eds_article_profile;

4
modules/roblib_search_eds/js/eds_results_book.js

@ -1,8 +1,6 @@
Drupal.behaviors.roblib_search_eds = {
attach: function (context, settings) {
// Run once, when the results container appears. The block may be
// rendered later by BigPipe, so don't rely on context being document.
if (once('roblib-search-eds-books', '#roblib-search-content-eds', context).length) {
if (context == document) {
$query = drupalSettings.path.currentPath.replace('roblib_search/', '');
$url = settings.eds_book_search_url + $query;
book_profile = settings.eds_book_profile;

6
modules/roblib_search_eds/roblib_search_eds.info.yml

@ -3,6 +3,6 @@ type: module
configure: roblib_search_eds.settings
description: Implements the Roblib Search EDS book and article results
package: Roblib Search
core_version_requirement: ^10 || ^11
dependencies:
- roblib_search:roblib_search
core_version_requirement: ^9 || ^10
dependancies:
- roblib_search

6
modules/roblib_search_eds/roblib_search_eds.libraries.yml

@ -6,10 +6,7 @@ eds-book:
js:
js/eds_results_book.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
- core/once
eds-article:
version: 1.x
css:
@ -18,8 +15,5 @@ eds-article:
js:
js/eds_results_article.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
- core/once

17
modules/roblib_search_eds/roblib_search_eds.module

@ -5,14 +5,13 @@
* Implementation of Roblib search for searching EDSAPI (EBSCO) targets.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_theme().
*/
function roblib_search_eds_theme($existing, $type, $theme, $path) {
$modulePath = \Drupal::service('extension.list.module')->getPath('roblib_search');
$spinner_path = '/' . $modulePath . '/img/spinner.gif';
$modulePath = \Drupal::service('module_handler')->getModule('roblib_search')
->getPath();
$spinner_path = '/' . $modulePath . "/img/spinner.gif";
return [
'roblib_search_eds_books' => [
'variables' => ['query' => NULL, 'spinner_path' => $spinner_path],
@ -25,10 +24,14 @@ function roblib_search_eds_theme($existing, $type, $theme, $path) {
/**
* Implements hook_help().
*
* @param type $path
* @param type $arg
* @return type
*/
function roblib_search_eds_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.roblib_search_eds':
function roblib_search_eds_help($path, $arg) {
switch ($path) {
case 'admin/help#roblib_search_eds':
return t(
'<p>
provides a EDSAPI target for the Roblib search module. This target uses javascript

4
modules/roblib_search_eds/roblib_search_eds.routing.yml

@ -10,7 +10,7 @@ roblib_search_eds.article_search:
defaults:
_controller: '\Drupal\roblib_search_eds\Controller\RoblibSearchEdsController::articleResults'
_title: 'Roblib Search EDS Articles'
query: null
query: '[a-zA-Z\s]+'
requirements:
_permission: 'access content'
@ -19,7 +19,7 @@ roblib_search_eds.book_search:
defaults:
_controller: '\Drupal\roblib_search_eds\Controller\RoblibSearchEdsController::bookResults'
_title: 'Roblib Search EDS Articles'
query: null
query: '[a-zA-Z\s]+'
requirements:
_permission: 'access content'

44
modules/roblib_search_eds/src/Controller/RoblibSearchEdsController.php

@ -4,25 +4,28 @@ namespace Drupal\roblib_search_eds\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\roblib_search_eds\Lib\EBSCOAPI;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Controller returning EDS search results as JSON.
* Controller for d3 graphs.
*/
class RoblibSearchEdsController extends ControllerBase {
/**
* Returns EDS article results as JSON.
* Print JSON.
*
*/
public function articleResults($query = NULL) {
return JsonResponse::fromJsonString($this->eds_get_results($query, 'Articles'));
print $this->eds_get_results($query, 'Articles');
exit();
}
/**
* Returns EDS book results as JSON.
* Print JSON.
*
*/
public function bookResults($query = NULL) {
return JsonResponse::fromJsonString($this->eds_get_results($query, 'Books'));
print $this->eds_get_results($query, 'Books');
exit();
}
/**
@ -34,14 +37,16 @@ class RoblibSearchEdsController extends ControllerBase {
* @return string
* A JSON string
*/
public function eds_get_results($query = NULL, $type = 'Articles') {
$config = $this->config('roblib_search_eds.settings');
$request = \Drupal::request();
function eds_get_results($query = NULL, $type = 'Articles') {
//drupal_add_css(drupal_get_path('module', 'roblib_search_eds') . '/css/roblib_search_eds.theme.css');
$config = \Drupal::config('roblib_search_eds.settings');
// Url parameters.
if (!isset($query)) {
$query = $request->query->get('roblib_query');
if (!isset($query)) {
return '{}';
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
return '';
}
}
$limiters = '';
@ -57,7 +62,7 @@ class RoblibSearchEdsController extends ControllerBase {
$query = '(' . $query . ') ' . $limiters;
$search = array('lookfor' => $query, 'type' => 'ALLFields', 'index' => 'AllFields', 'q' => 'ebsco/results', 'op' => 'Search');
$eds_api = new EBSCOAPI($eds_config);
$is_local_ip = $eds_api->connector()->isGuestIPAddress($request->getClientIp());
$is_local_ip = $eds_api->connector()->isGuestIPAddress($_SERVER["REMOTE_ADDR"]);
$eds_api->isGuest(FALSE);
$output = $eds_api->apiSearch($search, $filters, 1, $number_per_page);
@ -74,8 +79,8 @@ class RoblibSearchEdsController extends ControllerBase {
* @return string
* The limiters to append to the query.
*/
public function get_eds_query_limiters($type) {
$config = $this->config('roblib_search_eds.settings');
function get_eds_query_limiters($type) {
$config = \Drupal::config('roblib_search_eds.settings');
$limiters = 'n';
switch ($type) {
case 'Articles':
@ -92,9 +97,9 @@ class RoblibSearchEdsController extends ControllerBase {
return $limiters;
}
public function build_eds_config_arr($type) {
$ebsco_config = [];
$roblib_search_config = $this->config('roblib_search_eds.settings');
function build_eds_config_arr($type) {
$ebsco_config = array();
$roblib_search_config = \Drupal::config('roblib_search_eds.settings');
$ebsco_config['user'] = $roblib_search_config->get('eds_user');
$ebsco_config['password'] = $roblib_search_config->get('eds_pass');
//get the local ips allowed from ebsco
@ -106,9 +111,6 @@ class RoblibSearchEdsController extends ControllerBase {
$ebsco_config['rest_url'] = $roblib_search_config->get('eds_rest_url');
$ebsco_config['guest'] = $roblib_search_config->get('eds_guest');
$ebsco_config['autocomplete'] = '';
$ebsco_config['interface'] = '';
$ebsco_config['organization'] = '';
$ebsco_config['log'] = 0;
return $ebsco_config;
}

50
modules/roblib_search_eds/src/Form/EdsSettingsForm.php

@ -23,96 +23,96 @@ class EdsSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('roblib_search_eds.settings');
$config = \Drupal::config('roblib_search_eds.settings');
/* $form['eds_rest_url'] = array(
'#type' => 'textfield',
'#title' => $this->t('EDS Rest endpoint'),
'#title' => t('EDS Rest endpoint'),
'#default_value' => $config->get('eds_rest_url'),
'#description' => $this->t('The base EDS URL, for example https://eds-api.ebscohost.com/edsapi/rest'),
'#description' => t('The base EDS URL, for example https://eds-api.ebscohost.com/edsapi/rest'),
'#required' => TRUE,
);
$form['eds_auth_url'] = array(
'#type' => 'textfield',
'#title' => $this->t('EDS Auth endpoint'),
'#title' => t('EDS Auth endpoint'),
'#default_value' => $config->get('eds_auth_url'),
'#description' => $this->t('The EDS Auth endpoint, for example https://eds-api.ebscohost.com/Authservice/rest'),
'#description' => t('The EDS Auth endpoint, for example https://eds-api.ebscohost.com/Authservice/rest'),
'#required' => TRUE,
);
$form['eds_user'] = array(
'#type' => 'textfield',
'#title' => $this->t('EDS user'),
'#title' => t('EDS user'),
'#default_value' => $config->get('eds_user'),
'#description' => $this->t('EDS user, for example username'),
'#description' => t('EDS user, for example username'),
'#required' => TRUE,
);
$form['eds_pass'] = array(
'#type' => 'textfield',
'#title' => $this->t('EDS password'),
'#title' => t('EDS password'),
'#default_value' => $config->get('eds_pass'),
'#description' => $this->t('EDS password, for example password'),
'#description' => t('EDS password, for example password'),
'#required' => TRUE,
);
$form['eds_guest'] = array(
'#type' => 'textfield',
'#title' => $this->t('EDS Guest access'),
'#title' => t('EDS Guest access'),
'#default_value' => $config->get('eds_guest'),
'#description' => $this->t('EDS Guest access, y = guest access, n = not a guest'),
'#description' => t('EDS Guest access, y = guest access, n = not a guest'),
'#required' => TRUE,
);*/
$form['eds_local_ip'] = array(
'#type' => 'textfield',
'#title' => $this->t('EDS Local IP'),
'#title' => t('EDS Local IP'),
'#default_value' => $config->get('eds_local_ip'),
'#description' => $this->t('Local IP address prefix, i. 137.149.'),
'#description' => t('Local IP address prefix, i. 137.149.'),
'#required' => TRUE,
);
$form['eds_article_profile'] = array(
'#type' => 'textfield',
'#title' => $this->t('EDS Article profile'),
'#title' => t('EDS Article profile'),
'#default_value' => $config->get('eds_article_profile'),
'#description' => $this->t('EDS profile, for example edsapi'),
'#description' => t('EDS profile, for example edsapi'),
'#required' => TRUE,
);
$form['eds_book_profile'] = array(
'#type' => 'textfield',
'#title' => $this->t('EDS Book profile'),
'#title' => t('EDS Book profile'),
'#default_value' => $config->get('eds_book_profile'),
'#description' => $this->t('EDS Book profile, for example apilite'),
'#description' => t('EDS Book profile, for example apilite'),
'#required' => TRUE,
);
$form['eds_num_results'] = array(
'#type' => 'textfield',
'#title' => $this->t('Number of results to return'),
'#title' => t('Number of results to return'),
'#default_value' => $config->get('eds_num_results'),
'#description' => $this->t('The number of results to display in the Bento box, usurally 5'),
'#description' => t('The number of results to display in the Bento box, usurally 5'),
'#required' => TRUE,
);
$form['eds_article_limiters'] = array(
'#type' => 'textarea',
'#title' => $this->t('The limiters for Article searches'),
'#title' => t('The limiters for Article searches'),
'#default_value' => $config->get('eds_article_limiters'),
'#description' => $this->t('Specify the Publication Types to use as limiters for Article searches. Formatted similar to
'#description' => t('Specify the Publication Types to use as limiters for Article searches. Formatted similar to
AND (PT Article OR PT Magazines OR PT News OR PT Academic Journals OR PT Conference Materials)'),
'#required' => TRUE,
);
$form['eds_book_limiters'] = array(
'#type' => 'textarea',
'#title' => $this->t('The limiters for Books and Media searches'),
'#title' => t('The limiters for Books and Media searches'),
'#default_value' => $config->get('eds_book_limiters'),
'#description' => $this->t('Specify the Publication Types to use as limiters for Article searches. Formatted similar to
'#description' => t('Specify the Publication Types to use as limiters for Article searches. Formatted similar to
AND (PT Book OR PT Video OR PT Audio'),
'#required' => TRUE,
);
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
'#value' => t('Save'),
'#button_type' => 'primary',
];
return $form;
@ -129,7 +129,7 @@ class EdsSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->configFactory()->getEditable('roblib_search_eds.settings');
$config = \Drupal::configFactory()->getEditable('roblib_search_eds.settings');
//$config->set('eds_rest_url', $form_state->getValue('eds_rest_url'))->save();
//$config->set('eds_auth_url', $form_state->getValue('eds_auth_url'))->save();
//$config->set('eds_user', $form_state->getValue('eds_user'))->save();

145
modules/roblib_search_eds/src/Lib/EBSCOAPI.php

@ -119,6 +119,76 @@ class EBSCOAPI {
$this->config = $config;
}
/**
* Setter / Getter for authentication token.
*
* @param string The authentication token
*
* @return string or none
*
* @access public
*/
public function authenticationToken(){
$autocompleteTokenTimeOut = time();
$authenticationTimeout = 0;
//$authenticationTimeout;
// $autocompleteUrl = '';
// $token = '';
// $timeout = '';
// $autoToken = '';
// //$autocompleteTokenTimeOut = '';
// //$autocompleteTokenTimeOut;
// $autocompleteTokenTimeOut = 0;
// $autocompleteCustId ='';
if (isset($_SESSION["authenticationToken"])){
$token = $_SESSION["authenticationToken"];
$authenticationTimeout = $_SESSION["authenticationTimeout"]-600;
$timeout = $_SESSION["authenticationTimeout"];
$autocompleteUrl = $_SESSION["autocompleteUrl"];
$autoToken = $_SESSION["autocompleteToken"];
$autocompleteTokenTimeOut = $_SESSION["autocompleteTokenTimeOut"];
$autocompleteCustId = $_SESSION["autocompleteCustId"];
}else{
$result = $this->apiAuthenticationToken();
$_SESSION["authenticationToken"]= $result['authenticationToken'];
$_SESSION["authenticationTimeout"]= $result['authenticationTimeout'];
$_SESSION['autocompleteUrl'] = $result['autocompleteUrl'];
$_SESSION['autocompleteToken'] = $result['autocompleteToken'];
$_SESSION["autocompleteTokenTimeOut"]= $result['autocompleteTokenTimeOut'];
$_SESSION['autocompleteCustId'] = $result['autocompleteCustId'];
}
if(time()-$autocompleteTokenTimeOut >= $authenticationTimeout){
$result = $this->apiAuthenticationToken();
$_SESSION["authenticationToken"]= $result['authenticationToken'];
$_SESSION["authenticationTimeout"]= $result['authenticationTimeout'];
$_SESSION['autocompleteUrl'] = $result['autocompleteUrl'];
$_SESSION['autocompleteToken'] = $result['autocompleteToken'];
$_SESSION["autocompleteTokenTimeOut"]= $result['autocompleteTokenTimeOut'];
$_SESSION['autocompleteCustId'] = $result['autocompleteCustId'];
$result = array(
'authenticationToken' => $token,
'authenticationTimeout' => $timeout,
'autocompleteUrl' => $autocompleteUrl,
'autocompleteToken' => $autoToken,
'autocompleteTokenTimeOut' => $autocompleteTokenTimeOut,
'autocompleteCustId' => $autocompleteCustId
);
return $result['authenticationToken'];
}else{
return $this->token;
}
}
/**
* Setter / Getter for session token.
*
@ -203,7 +273,8 @@ class EBSCOAPI {
* @access protected
*/
protected function request($action, $params = NULL, $attempts = 5) {
$sessionToken = $this->sessionToken();
//$authenticationToken = $this->authenticationToken();
$sessionToken = $this->apiSessionToken();//$this->sessionToken();
// If authentication token is missing then the session token is missing too, so get both tokens
// If session token is missing then the authentication token may be invalid, so get both tokens.
@ -220,8 +291,7 @@ class EBSCOAPI {
// Any change of the isGuest should request a new session
// (and don't terminate the current request if there was an error during the session request
// since it's not that important)
$storedGuest = $this->readSession('isGuest');
if ($storedGuest !== '' && $storedGuest != $this->connector()->isGuest()) {
if ($this->isGuest() != $this->connector()->isGuest()) {
$this->apiSessionToken();
}
@ -249,11 +319,8 @@ class EBSCOAPI {
}
break;
case EBSCOConnector::EDS_SESSION_TOKEN_MISSING:
case EBSCOConnector::EDS_SESSION_TOKEN_INVALID:
$this->deleteSession('sessionToken');
$this->sessionToken = NULL;
$result = $this->apiSessionToken();
$result = $this->apiAuthenticationAndSessionToken();
if ($this->isError($result)) {
// Any error should terminate the request immediately
// in order to prevent infinite recursion.
@ -303,7 +370,6 @@ class EBSCOAPI {
//$headers = array(
// 'x-authenticationToken: '.$this->authenticationToken(),
//);
$headers = [];
$response = $this->connector()->requestSessionToken($headers);
// Raise the exception so that any code running this method should exit immediately.
@ -314,7 +380,6 @@ class EBSCOAPI {
$result = $this->response($response)->result();
if (is_string($result)) {
$this->sessionToken($result);
$this->writeSession('isGuest', $this->connector()->isGuest());
return $result;
}
else {
@ -709,68 +774,36 @@ class EBSCOAPI {
}
/**
* How long (seconds) EDS values are cached for.
*
* EDS sessions time out after a period of inactivity, so keep this short.
* An expired token is also detected and replaced by request().
*/
const CACHE_LIFETIME = 900;
/**
* Builds the cache ID for a key, scoped to the EDS profile in use.
* Store the given object into session.
*
* @param string $key
* The key used for the value.
*
* @return string
* The cache ID.
*/
protected function cacheId($key) {
$profile = $this->config['profile'] ?? '';
return 'roblib_search_eds:' . $profile . ':' . $key;
}
/**
* Store the given value in the Drupal cache.
* The key used for reading the value.
* @param object $value
* The object stored in session.
*
* EDS tokens are obtained via IP authentication of the web server, so they
* are shared by all visitors rather than stored in each user's PHP session
* ($_SESSION is not persisted by Drupal and would start sessions for
* anonymous users, defeating the page cache).
* @return none
*
* @param string $key
* The key used for reading the value.
* @param mixed $value
* The value to store.
* @access protected
*/
protected function writeSession($key, $value) {
if (!empty($key) && !empty($value)) {
\Drupal::cache()->set($this->cacheId($key), $value, time() + self::CACHE_LIFETIME);
$_SESSION['EBSCO'][$key] = $value;
}
}
/**
* Read the value having the given key from the Drupal cache.
* Read from session the object having the given key.
*
* @param string $key
* The key used for reading the value.
* The key used for reading the object.
*
* @return mixed
* The cached value, or an empty string if there is none.
*/
protected function readSession($key) {
$cache = \Drupal::cache()->get($this->cacheId($key));
return $cache ? $cache->data : '';
}
/**
* Remove the value having the given key from the Drupal cache.
* @return object
*
* @param string $key
* The key of the value to remove.
* @access protected
*/
protected function deleteSession($key) {
\Drupal::cache()->delete($this->cacheId($key));
protected function readSession($key) {
$value = isset($_SESSION['EBSCO'][$key]) ? $_SESSION['EBSCO'][$key] : '';
return $value;
}
/**
@ -783,7 +816,7 @@ class EBSCOAPI {
* @access protected
*/
protected function isError($object) {
return $object instanceof EBSCOException;
return is_a($object, 'EBSCOException');
}
}

7
modules/roblib_search_eds/src/Lib/EBSCODocument.php

@ -54,13 +54,6 @@ class EBSCODocument {
*/
private $params = array();
/**
* The citation style terms (declared to avoid PHP 8.2+ dynamic properties).
*
* @var array|null
*/
private $citationStylesTerms = NULL;
/**
* The associative array of EBSCO results returned by a Search API call
* #global array.

3
modules/roblib_search_eds/src/Lib/EBSCOResponse.php

@ -358,7 +358,8 @@ class EBSCOResponse
if (isset($record->RecordInfo->BibRecord->BibRelationships->HasContributorRelationships)) {
foreach ($record->RecordInfo->BibRecord->BibRelationships->HasContributorRelationships->HasContributor as $contributor) {
$nameFull = (string) ($contributor->PersonEntity?->Name?->NameFull ?? '');
$nameFull = $contributor->PersonEntity->Name->NameFull ?
(string) $contributor->PersonEntity->Name->NameFull : '';
$result['RecordInfo']['BibRelationships']['HasContributorRelationships'][] = array(
'NameFull' => $nameFull,

1
modules/roblib_search_eds/src/Lib/sanitizer.class.php

@ -43,7 +43,6 @@ class HTML_Sanitizer {
*/
private $_allowedTags;
private $_allowJavascriptEvents;
private $_allowDOMEvents;
private $_allowJavascriptInUrls;
private $_allowObjects;
private $_allowScript;

22
modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php

@ -3,7 +3,6 @@
namespace Drupal\roblib_search_eds\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
/**
* Provides EDS Article search results.
@ -30,6 +29,7 @@ class RoblibSearchEdsArticles extends BlockBase {
];
return [
'#theme' => 'roblib_search_eds_articles',
'query' => $query,
'#attached' => [
'library' => [
'roblib_search_eds/eds-article'
@ -41,21 +41,13 @@ class RoblibSearchEdsArticles extends BlockBase {
/**
* {@inheritdoc}
*
* The block only renders a placeholder and settings; results are fetched
* client side from uncached JSON endpoints, so the markup can be cached.
* Setting max-age 0 here would make BigPipe stream the block in later.
*/
public function getCacheTags() {
return Cache::mergeTags(parent::getCacheTags(), ['config:roblib_search_eds.settings']);
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
// The search URL in drupalSettings includes the scheme and host.
return Cache::mergeContexts(parent::getCacheContexts(), ['url.site']);
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
}
}

22
modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php

@ -3,7 +3,6 @@
namespace Drupal\roblib_search_eds\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
/**
* Provides EDS book search results.
@ -30,6 +29,7 @@ class RoblibSearchEdsBooks extends BlockBase {
];
return [
'#theme' => 'roblib_search_eds_books',
//'query' => $query,
'#attached' => [
'library' => [
'roblib_search_eds/eds-book'
@ -41,21 +41,13 @@ class RoblibSearchEdsBooks extends BlockBase {
/**
* {@inheritdoc}
*
* The block only renders a placeholder and settings; results are fetched
* client side from uncached JSON endpoints, so the markup can be cached.
* Setting max-age 0 here would make BigPipe stream the block in later.
*/
public function getCacheTags() {
return Cache::mergeTags(parent::getCacheTags(), ['config:roblib_search_eds.settings']);
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
// The search URL in drupalSettings includes the scheme and host.
return Cache::mergeContexts(parent::getCacheContexts(), ['url.site']);
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
}

4
modules/solr_site/js/solr_site_bestbet.js

@ -1,8 +1,6 @@
Drupal.behaviors.roblib_search_solr_bestbet_results = {
attach: function (context, settings) {
// Run once, when the results container appears. The block may be
// rendered later by BigPipe, so don't rely on context being document.
if (once('roblib-search-solr-bestbet', '#roblib-search-content-solr-site-bestbet', context).length) {
if (context == document) {
query = drupalSettings.path.currentPath.replace('roblib_search/', '');
solrUrl = settings.solr_site_search_url + query;
baseUrl = settings.solr_bestbet_base_url + query;

4
modules/solr_site/js/solr_site_results.js

@ -1,8 +1,6 @@
Drupal.behaviors.roblib_search_solr_site_results = {
attach: function (context, settings) {
// Run once, when the results container appears. The block may be
// rendered later by BigPipe, so don't rely on context being document.
if (once('roblib-search-solr-results', '#roblib-search-content-solr-site-results', context).length) {
if (context == document) {
unencoded_query = drupalSettings.path.currentPath.replace('roblib_search/', '');
query = encodeURIComponent(unencoded_query);
solrUrl = settings.solr_site_search_url + query;

7
modules/solr_site/roblib_search_solr_site.info.yml

@ -3,7 +3,6 @@ type: module
configure: roblib_search_solr_site.settings
description: Implements the Roblib Search for local Solr site bento results
package: Roblib Search
core_version_requirement: ^10 || ^11
dependencies:
- roblib_search:roblib_search
- search_api:search_api
core_version_requirement: ^9 || ^10
dependancies:
- roblib_search

6
modules/solr_site/roblib_search_solr_site.libraries.yml

@ -6,16 +6,10 @@ solr-site:
js:
js/solr_site_results.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
- core/once
solr-bestbet:
version: 1.x
js:
js/solr_site_bestbet.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
- core/once

82
modules/solr_site/roblib_search_solr_site.module

@ -2,17 +2,18 @@
/**
* @file
* Implementation of Roblib search for the local Solr (Search API) site index.
* Implementation of Roblib search for searching several targets.
*/
/**
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_theme().
*/
function roblib_search_solr_site_theme($existing, $type, $theme, $path) {
$modulePath = \Drupal::service('extension.list.module')->getPath('roblib_search');
$spinner_path = '/' . $modulePath . '/img/spinner.gif';
$modulePath = \Drupal::service('module_handler')->getModule('roblib_search')
->getPath();
$spinner_path = '/' . $modulePath . "/img/spinner.gif";
return [
'roblib_search_solr_site_results' => [
'variables' => ['solr_type' => 'results', 'spinner_path' => $spinner_path],
@ -23,12 +24,77 @@ function roblib_search_solr_site_theme($existing, $type, $theme, $path) {
];
}
/**
* Send the query to solr but limit the results so it doesn't include certain content.
*
* Print json and exit so the javascript can consume the json.
*
* @param string $query
* The solr search string.
*/
/*function roblib_search_solr_site_results($query) {
print roblib_search_solr_site_get_results($query, '-bundle:bestbet');
exit();
}*/
/**
* Send the query to solr but limit the results so it only includes content of type bestbet.
*
* Print json and exit so the javascript can consume the json.
*
* @param string $query
* The solr search string.
*/
/*function roblib_search_solr_site_bestbet($query) {
$query = str_replace('"', '', $query);
$json = roblib_search_solr_site_get_results("sort_label:$query", 'bundle:bestbet');
$json = roblib_search_solr_site_add_url($json);
print $json;
exit();
}*/
/**
*
* Updates the json passed in with a url directly to the target of the link field.
* This information is not in solr as it comes from a custom field.
*
*
* @param string $json
* The json string returned from the solr query.
*
* @return string
* json we got from solr with an updated url directly to the target of the link field
*/
/*function roblib_search_solr_site_add_url($json) {
$responses = json_decode($json);
foreach ($responses->response->docs as &$doc) {
$nid = $doc->entity_id;
// The link field is a complex field and we get the text in solr but not the actual url.
// Since best best will only every return one result it's not much overhead to load the node
// and get the value of the link field. probably less overhead then installing additional
// modules to get the url in solr.
$node = node_load($nid);
$url = $node->field_link['und'][0]['url'];
$doc->url = $url;
}
return json_encode($responses);
}
*/
/**
* Implements hook_help().
*/
function roblib_search_solr_site_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.roblib_search_solr_site':
return t('<p>Provides a Solr target for the Roblib search module.</p>');
function roblib_search_solr_site_help($path, $arg) {
switch ($path) {
case 'admin/help#roblib_search_solr_site':
return t(
'<p>
provides a Solr target for the Roblib search module
</p>'
);
}
}

4
modules/solr_site/roblib_search_solr_site.routing.yml

@ -10,7 +10,7 @@ roblib_search_solr_site.bestbet_search:
defaults:
_controller: '\Drupal\roblib_search_solr_site\Controller\RoblibSearchSolrsiteController::bestbetResults'
_title: 'Roblib Search Bestbet'
query: null
query: '[a-zA-Z\s]+'
requirements:
_permission: 'access content'
@ -19,6 +19,6 @@ roblib_search_solr_site.general_search:
defaults:
_controller: '\Drupal\roblib_search_solr_site\Controller\RoblibSearchSolrsiteController::generalResults'
_title: 'Roblib Search Solr Site Search'
query: null
query: '[a-zA-Z\s]+'
requirements:
_permission: 'access content'

42
modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php

@ -3,26 +3,28 @@
namespace Drupal\roblib_search_solr_site\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\search_api\Entity\Index;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Controller returning Search API (Solr) site results as JSON.
* Controller for d3 graphs.
*/
class RoblibSearchSolrsiteController extends ControllerBase {
/**
* Returns best bet results as JSON.
* Print JSON.
*
*/
public function bestbetResults($query = NULL) {
return new JsonResponse($this->getResults($query, 'BestBet'));
print $this->getResults($query, 'BestBet');
exit();
}
/**
* Returns general site results as JSON.
* Print JSON.
*
*/
public function generalResults($query = NULL) {
return new JsonResponse($this->getResults($query, 'General'));
print $this->getResults($query, 'General');
exit();
}
/**
@ -31,20 +33,24 @@ class RoblibSearchSolrsiteController extends ControllerBase {
* The search term(s) to send to Solr.
* @param string type
* The type of search, either BestBet or General.
* @return array
* The results, ready to be JSON encoded.
* @return string
* A JSON string
*/
public function getResults($queryString = NULL, $solr_type = 'General') {
function getResults($queryString = NULL, $solr_type = 'General') {
global $base_url;
$config = \Drupal::config('roblib_search_solr_site.settings');
// Url parameters.
if (!isset($queryString)) {
$queryString = \Drupal::request()->query->get('roblib_query');
if (!isset($queryString)) {
return [];
if (isset($_GET['roblib_query'])) {
$queryString = $_GET['roblib_query'];
}
else {
return '';
}
}
//$queryString = urlencode($queryString);
// TODO make the index configurable.
$index = Index::load('library');
$index = \Drupal\search_api\Entity\Index::load('library');
$query = $index->query();
// Change the parse mode for the search.
@ -87,7 +93,6 @@ class RoblibSearchSolrsiteController extends ControllerBase {
}
$titles = $title->getValues();
$output['results'][$id]['title'] = reset($titles);
$bodyOutput = '';
$body = $result->getField('body')->getValues();
if (!empty($body)) {
$bodyOutput = strip_tags($body[0]->getText());
@ -95,11 +100,11 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$bodyOutput = substr($bodyOutput, 0, 499) . '...';
}
}
$output['results'][$id]['body'] = $bodyOutput;
$output['results'][$id]['body'] = empty($bodyOutput) ? '' : $bodyOutput;
//$rendered_items = $result->getField('rendered_item')->getValues();
// $output['rendered_item'] = $rendered_items[0]->getText();
$summarys = $result->getField('summary')->getValues();
$output['results'][$id]['summary'] = empty($summarys) ? '' : reset($summarys);
$output['results'][$id]['summary'] = empty($summmarys) ? '' : reset($summarys);
$type = $result->getField('type')->getValues();
$output['results'][$id]['type'] = reset($type);
$urls = $result->getField('url')->getValues();
@ -112,7 +117,8 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$output['results'][$id]['field_link'] = empty($links) ? '' : $links;
}
return $output;
echo json_encode($output);
exit();
}
}

14
modules/solr_site/src/Form/SolrsiteSettingsForm.php

@ -23,26 +23,26 @@ class SolrsiteSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('roblib_search_solr_site.settings');
$config = \Drupal::config('roblib_search_solr_site.settings');
$form['solr_site_url'] = array(
'#type' => 'textfield',
'#title' => $this->t('Solr URL'),
'#title' => t('Solr URL'),
'#default_value' => $config->get('solr_site_url'),
'#description' => $this->t('The base Solr URL, for example /search/node?keys='),
'#description' => t('The base Solr URL, for example /search/node?keys='),
'#required' => TRUE,
);
$form['solr_site_num_results'] = array(
'#type' => 'textfield',
'#title' => $this->t('Number of results to return'),
'#title' => t('Number of results to return'),
'#default_value' => $config->get('solr_site_num_results'),
'#description' => $this->t('The number of results to display in the Bento box'),
'#description' => t('The number of results to display in the Bento box'),
'#required' => TRUE,
);
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
'#value' => t('Save'),
'#button_type' => 'primary',
];
return $form;
@ -59,7 +59,7 @@ class SolrsiteSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->configFactory()->getEditable('roblib_search_solr_site.settings');
$config = \Drupal::configFactory()->getEditable('roblib_search_solr_site.settings');
$config->set('solr_site_url', $form_state->getValue('solr_site_url'))->save();
$config->set('solr_site_num_results', $form_state->getValue('solr_site_num_results'))->save();
}

13
modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php

@ -3,7 +3,6 @@
namespace Drupal\roblib_search_solr_site\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
/**
* Provides EDS Article search results.
@ -40,13 +39,13 @@ class RoblibSearchSolrSiteBestbet extends BlockBase {
/**
* {@inheritdoc}
*
* The block only renders a placeholder and settings; results are fetched
* client side from uncached JSON endpoints, so the markup can be cached.
* Setting max-age 0 here would make BigPipe stream the block in later.
*/
public function getCacheTags() {
return Cache::mergeTags(parent::getCacheTags(), ['config:roblib_search_solr_site.settings']);
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
}
}

13
modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php

@ -3,7 +3,6 @@
namespace Drupal\roblib_search_solr_site\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
/**
* Provides EDS book search results.
@ -42,13 +41,13 @@ class RoblibSearchSolrsiteGeneral extends BlockBase {
/**
* {@inheritdoc}
*
* The block only renders a placeholder and settings; results are fetched
* client side from uncached JSON endpoints, so the markup can be cached.
* Setting max-age 0 here would make BigPipe stream the block in later.
*/
public function getCacheTags() {
return Cache::mergeTags(parent::getCacheTags(), ['config:roblib_search_solr_site.settings']);
public function getCacheMaxAge() {
// Reading dynamic content from external source so no caching.
if (\Drupal::currentUser()->isAnonymous()) {
// Anonymous user...
return 0;
}
}
}

8
roblib_search.info.yml

@ -1,8 +1,10 @@
name: Roblib Search
type: module
core_version_requirement: ^10 || ^11
core_version_requirement: ^9 || ^10
configure: roblib_search.settings
description: Provides a search form and fires a hook when the search is submitted. Other modules should implement the search functionality by implementing the correct hooks.
package: Roblib Search
dependencies:
- message:message
dependancies:
- drupal:views_ui
- drupal:message

19
roblib_search.module

@ -5,8 +5,6 @@
* Implementation of Roblib search for searching several targets.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_theme().
*/
@ -22,12 +20,23 @@ function roblib_search_theme($existing, $type, $theme, $path) {
}
/**
* Implements hook_init().
*/
/*function roblib_search_init() {
drupal_add_js(drupal_get_path('module', 'roblib_search') . '/js/imagesloaded.pkg.min.js');
drupal_add_js(drupal_get_path('module', 'roblib_search') . '/js/roblib_search.js');
drupal_add_css(drupal_get_path('module', 'roblib_search') . '/css/jquery.qtip.min.css');
}*/
/**
* Implements hook_help().
*/
function roblib_search_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.roblib_search':
function roblib_search_help($path, $arg) {
switch ($path) {
case 'admin/help#roblib_search':
return t(
'<p>
The Roblib Search is a module to allow searching across multiple targets.

2
roblib_search.routing.yml

@ -11,7 +11,7 @@ roblib_search.landing_page:
defaults:
_controller: '\Drupal\roblib_search\Controller\RoblibSearchController::searchResults'
_title: 'Roblib Search Landing Page'
query: null
query: '[a-zA-Z\s]+'
options:
no_cache: 'TRUE'
requirements:

36
src/Controller/RoblibSearchController.php

@ -2,43 +2,35 @@
namespace Drupal\roblib_search\Controller;
use Drupal\Component\Utility\Html;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Component\Utility\Html;
/**
* Controller for the Roblib Search landing page.
* Controller for d3 graphs.
*/
class RoblibSearchController extends ControllerBase {
/**
* Display the search results landing page.
* Display the markup.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
* @param string|null $query
* The search query from the path.
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* A renderable array, or a redirect when a roblib_query parameter is used.
* @return array
* A renderable array.
*/
public function searchResults(Request $request, $query = NULL) {
$roblib_query = $request->query->get('roblib_query');
if (!empty($roblib_query)) {
$roblib_query = str_replace('/', ' ', $roblib_query);
$roblib_query = trim(Html::decodeEntities($roblib_query));
if (empty($roblib_query)) {
$this->messenger()->addMessage($this->t('Please Enter a valid search string.'));
public function searchResults($query = NULL) {
if ($query = $_GET['roblib_query']) {
$query = str_replace('/', ' ',$query);
$query = trim(Html::decodeEntities($query));
if(empty($query)) {
\Drupal::messenger()->addMessage($this->t('Please Enter a valid search string.'));
$url = Url::fromRoute('roblib_search.landing_page');
}
else {
$url = Url::fromRoute('roblib_search.landing_page', ['query' => $roblib_query]);
} else {
$url = Url::fromRoute('roblib_search.landing_page', ['query' => $query]);
}
return new RedirectResponse($url->toString());
}
return [
return [
'#theme' => 'roblib_search_results',
'#query' => $query,
];

10
src/Form/RoblibSearchForm.php

@ -4,6 +4,7 @@ namespace Drupal\roblib_search\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
use Drupal\message\Entity\Message;
@ -26,7 +27,12 @@ class RoblibSearchForm extends FormBase{
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$query = $this->getRequest()->query->get('roblib_query', '');
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
$query = '';
}
$form['simple'] = array(
'#type' => 'container',
'#attributes' => array(
@ -44,7 +50,7 @@ class RoblibSearchForm extends FormBase{
);
$form['simple']['submit'] = array(
'#type' => 'submit',
'#value' => $this->t('search')
'#value' => t('search')
);
return $form;
}

10
src/Form/RoblibSearchSettingsForm.php

@ -23,17 +23,17 @@ class RoblibSearchSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('roblib_search.settings');
$config = \Drupal::config('roblib_search.settings');
$form['search_panel_page'] = array(
'#type' => 'textfield',
'#title' => $this->t('Path to the roblib search panel page'),
'#title' => t('Path to the roblib search panel page'),
'#default_value' => $config->get('search_panel_page'),
'#description' => $this->t('The Path to the Roblib Search Panel, for example /roblib/panel'),
'#description' => t('The Path to the Roblib Search Panel, for example /roblib/panel'),
'#required' => TRUE,
);
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
'#value' => t('Save'),
'#button_type' => 'primary',
];
return $form;
@ -50,7 +50,7 @@ class RoblibSearchSettingsForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->configFactory()->getEditable('roblib_search.settings');
$config = \Drupal::configFactory()->getEditable('roblib_search.settings');
$config->set('search_panel_page', $form_state->getValue('search_panel_page'))->save();
}

5
src/Plugin/Block/RoblibSearchBoxBlock.php

@ -3,7 +3,6 @@
namespace Drupal\roblib_search\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\roblib_search\Form\RoblibSearchForm;
/**
* Provides a search form.
@ -20,6 +19,8 @@ class RoblibSearchBoxBlock extends BlockBase {
* {@inheritdoc}
*/
public function build() {
return \Drupal::formBuilder()->getForm(RoblibSearchForm::class);
$form = \Drupal::formBuilder()->getForm('\Drupal\roblib_search\Form\RoblibSearchForm');
return $form;
}
}

10
src/Plugin/Block/RoblibSearchOtherSourcesBlock.php

@ -18,10 +18,11 @@ class RoblibSearchOtherSourcesBlock extends BlockBase {
/**
* {@inheritdoc}
*/
///roblib_search/
public function build() {
$prefix = '/roblib_search/';
$query = \Drupal::request()->getRequestUri();
if (str_starts_with($query, $prefix)) {
$query = $_SERVER['REQUEST_URI'];
if (substr($query, 0, strlen($prefix)) == $prefix) {
$query = substr($query, strlen($prefix));
}
return [
@ -30,11 +31,8 @@ class RoblibSearchOtherSourcesBlock extends BlockBase {
];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// Don't cache this block.
// don't cache this block
return 0;
}

20
theme/theme.inc

@ -0,0 +1,20 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*function roblib_search_preprocess_roblib_search_other_sources(&$variables) {
global $base_url;
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
$query = $_GET['roblib_query'];
}
else {
$query = '';
}
}
$variables['query'] = urlencode($query);
}*/
?>
Loading…
Cancel
Save