Example #1
0
 /**
  * Load bookcover from cache or remote provider and display if possible.
  *
  * @return bool        True if image loaded, false on failure.
  */
 protected function fetchFromAPI()
 {
     // Check that we have at least one valid identifier:
     $ids = $this->getIdentifiers();
     if (empty($ids)) {
         return false;
     }
     // Set up local file path:
     $this->localFile = $this->determineLocalFile($ids);
     if (is_readable($this->localFile)) {
         // Load local cache if available
         $this->contentType = 'image/jpeg';
         $this->image = file_get_contents($this->localFile);
         return true;
     } else {
         if (isset($this->config->Content->coverimages)) {
             $providers = explode(',', $this->config->Content->coverimages);
             foreach ($providers as $provider) {
                 $provider = explode(':', trim($provider));
                 $apiName = strtolower(trim($provider[0]));
                 $key = isset($provider[1]) ? trim($provider[1]) : null;
                 try {
                     $handler = $this->apiManager->get($apiName);
                     // Is the current provider appropriate for the available data?
                     if ($handler->supports($ids)) {
                         if ($url = $handler->getUrl($key, $this->size, $ids)) {
                             $success = $this->processImageURLForSource($url, $handler->isCacheAllowed(), $apiName);
                             if ($success) {
                                 return true;
                             }
                         }
                     }
                 } catch (\Exception $e) {
                     $this->debug(get_class($e) . ' during processing of ' . $apiName . ': ' . $e->getMessage());
                 }
             }
         }
     }
     return false;
 }
Example #2
0
 /**
  * Test expected interface.
  *
  * @return void
  *
  * @expectedException        Zend\ServiceManager\Exception\RuntimeException
  * @expectedExceptionMessage Plugin ArrayObject does not belong to VuFind\Content\AbstractCover
  */
 public function testExpectedInterface()
 {
     $pm = new PluginManager(null);
     $pm->validatePlugin(new \ArrayObject());
 }