diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/AbstractSyndetics.php b/module/VuFind/src/VuFind/Theme/Root/Helper/AbstractSyndetics.php index a9dbcfa1d98fc908e75b3153075bfd16fb58a381..83b31de9fc1cb0df7d082c33acc476e8f62967e6 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/AbstractSyndetics.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/AbstractSyndetics.php @@ -102,6 +102,44 @@ abstract class AbstractSyndetics extends AbstractHelper return $isbn; } + /** + * Retrieve results for the providers specified. + * + * @param string $isbn ISBN to use for lookup + * @param string $providers Provider configuration + * + * @return array + */ + protected function getResults($isbn, $providers) + { + $results = array(); + if (!$this->setIsbn($isbn)) { + return $results; + } + + // Fetch from provider + $providers = explode(',', $providers); + foreach ($providers as $provider) { + $parts = explode(':', trim($provider)); + $provider = strtolower($parts[0]); + $func = 'load' . ucwords($provider); + $key = $parts[1]; + try { + $results[$provider] = method_exists($this, $func) + ? $this->$func($key) : false; + // If the current provider had no valid data, store nothing: + if (empty($results[$provider])) { + unset($results[$provider]); + } + } catch (\Exception $e) { + // Ignore exceptions: + unset($results[$provider]); + } + } + + return $results; + } + /** * Get an HTTP client * diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/AuthorNotes.php b/module/VuFind/src/VuFind/Theme/Root/Helper/AuthorNotes.php index 1758ce3f6a7b1b00387f40316fb5cb2c993ae964..c243f22d076f213804cbe30540d2cf59ceea475c 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/AuthorNotes.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/AuthorNotes.php @@ -48,35 +48,9 @@ class AuthorNotes extends AbstractSyndetics */ public function __invoke($isbn) { - if (!$this->setIsbn($isbn)) { - return array(); - } - - $results = array(); - - // Fetch from provider - if (isset($this->config->Content->authorNotes)) { - $providers = explode(',', $this->config->Content->authorNotes); - foreach ($providers as $provider) { - $parts = explode(':', trim($provider)); - $provider = strtolower($parts[0]); - $func = 'load' . ucwords($provider); - $key = $parts[1]; - try { - $results[$provider] = method_exists($this, $func) - ? $this->$func($key) : false; - // If the current provider had no valid notes, store nothing: - if (empty($results[$provider])) { - unset($results[$provider]); - } - } catch (\Exception $e) { - // Ignore exceptions: - unset($results[$provider]); - } - } - } - - return $results; + $providers = isset($this->config->Content->authorNotes) + ? $this->config->Content->authorNotes : ''; + return $this->getResults($isbn, $providers); } /** diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/Excerpt.php b/module/VuFind/src/VuFind/Theme/Root/Helper/Excerpt.php index f0ff97963e0465fb84c2bed37e6043f784e42853..300b6a891653157e88cb264f3ffd732a230d9c1c 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/Excerpt.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/Excerpt.php @@ -48,35 +48,9 @@ class Excerpt extends AbstractSyndetics */ public function __invoke($isbn) { - if (!$this->setIsbn($isbn)) { - return array(); - } - - $results = array(); - - // Fetch from provider - if (isset($this->config->Content->excerpts)) { - $providers = explode(',', $this->config->Content->excerpts); - foreach ($providers as $provider) { - $parts = explode(':', trim($provider)); - $provider = strtolower($parts[0]); - $func = 'load' . ucwords($provider); - $key = $parts[1]; - try { - $results[$provider] = method_exists($this, $func) ? - $this->$func($key) : false; - // If the current provider had no valid excerpts, store nothing: - if (empty($results[$provider])) { - unset($results[$provider]); - } - } catch (\Exception $e) { - // Ignore exceptions: - unset($results[$provider]); - } - } - } - - return $results; + $providers = isset($this->config->Content->excerpts) + ? $this->config->Content->excerpts : ''; + return $this->getResults($isbn, $providers); } /** diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/Reviews.php b/module/VuFind/src/VuFind/Theme/Root/Helper/Reviews.php index ac2aa160b54ad4f1e663eab94a67e0353b8f000a..d4cd48b790549a08e2ee99497a4310b5d6c0239e 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/Reviews.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/Reviews.php @@ -48,35 +48,9 @@ class Reviews extends AbstractSyndetics */ public function __invoke($isbn) { - if (!$this->setIsbn($isbn)) { - return array(); - } - - $results = array(); - - // Fetch from provider - if (isset($this->config->Content->reviews)) { - $providers = explode(',', $this->config->Content->reviews); - foreach ($providers as $provider) { - $parts = explode(':', trim($provider)); - $provider = strtolower($parts[0]); - $func = 'load' . ucwords($provider); - $key = $parts[1]; - try { - $results[$provider] = method_exists($this, $func) ? - $this->$func($key) : false; - // If the current provider had no valid excerpts, store nothing: - if (empty($results[$provider])) { - unset($results[$provider]); - } - } catch (\Exception $e) { - // Ignore exceptions: - unset($results[$provider]); - } - } - } - - return $results; + $providers = isset($this->config->Content->reviews) + ? $this->config->Content->reviews : ''; + return $this->getResults($isbn, $providers); } /** diff --git a/module/VuFind/src/VuFind/Theme/Root/Helper/VideoClips.php b/module/VuFind/src/VuFind/Theme/Root/Helper/VideoClips.php index 522e6e3ceab64f48545fdf4eba2f90fa83950b8b..c1f9da03fae9db69aaf9f58787ccb2a021b3613c 100644 --- a/module/VuFind/src/VuFind/Theme/Root/Helper/VideoClips.php +++ b/module/VuFind/src/VuFind/Theme/Root/Helper/VideoClips.php @@ -48,35 +48,9 @@ class VideoClips extends AbstractSyndetics */ public function __invoke($isbn) { - if (!$this->setIsbn($isbn)) { - return array(); - } - - $results = array(); - - // Fetch from provider - if (isset($this->config->Content->videoClips)) { - $providers = explode(',', $this->config->Content->videoClips); - foreach ($providers as $provider) { - $parts = explode(':', trim($provider)); - $provider = strtolower($parts[0]); - $func = 'load' . ucwords($provider); - $key = $parts[1]; - try { - $results[$provider] = method_exists($this, $func) ? - $this->$func($key) : false; - // If the current provider had no valid clips, store nothing: - if (empty($results[$provider])) { - unset($results[$provider]); - } - } catch (\Exception $e) { - // Ignore exceptions: - unset($results[$provider]); - } - } - } - - return $results; + $providers = isset($this->config->Content->videoClips) + ? $this->config->Content->videoClips : ''; + return $this->getResults($isbn, $providers); } /**