Esempio n. 1
0
 /**
  * Send image data for display in the view
  *
  * @return \Zend\Http\Response
  */
 public function showAction()
 {
     $this->disableSessionWrites();
     // avoid session write timing bug
     $width = $this->params()->fromQuery('w');
     $height = $this->params()->fromQuery('h');
     // Use full-resolution image?
     $fullRes = $this->params()->fromQuery('fullres');
     $loader = $this->getLoader();
     $loader->setParams($width, $height, $fullRes);
     if ($id = $this->params()->fromQuery('id')) {
         $driver = $this->getRecordLoader()->load($id, 'Solr');
         $index = $this->params()->fromQuery('index');
         $this->getLoader()->loadRecordImage($driver, $index ? $index : 0);
         $response = parent::displayImage();
     } else {
         // Redirect book covers to VuFind's cover controller
         $response = parent::showAction();
     }
     // Add a filename to the headers so that saving an image defaults to a
     // sensible filename
     if ($response instanceof \Zend\Http\PhpEnvironment\Response) {
         $headers = $response->getHeaders();
         $contentType = $headers->get('Content-Type');
         if ($contentType && $contentType->match('image/jpeg')) {
             $params = $this->getImageParams();
             if (!empty($params['isbn'])) {
                 $filename = $params['isbn'];
             } elseif (!empty($params['issn'])) {
                 $filename = $params['issn'];
             } elseif (isset($driver)) {
                 if ($isbn = $driver->tryMethod('getCleanISBN')) {
                     $filename = $isbn;
                 } elseif ($issn = $driver->tryMethod('getCleanISSN')) {
                     $filename = $issn;
                 } else {
                     // Strip the data source prefix
                     $parts = explode('.', $driver->getUniqueID(), 2);
                     $filename = end($parts);
                 }
             } elseif (!empty($params['title'])) {
                 $filename = $params['title'];
             }
             if (isset($filename)) {
                 // Remove any existing extension
                 $filename = preg_replace('/\\.jpe?g/', '', $filename);
                 // Replace some characters for cleaner filenames and hopefully
                 // something that can be found with the search
                 $filename = preg_replace('/[^\\w_ -]/', ' ', $filename);
                 $filename .= '.jpg';
                 $headers->addHeaderLine('Content-Disposition', "inline; filename={$filename}");
             }
         }
     }
     return $response;
 }
Esempio n. 2
0
 /**
  * Send image data for display in the view
  *
  * @return \Zend\Http\Response
  */
 public function showAction()
 {
     $width = $this->params()->fromQuery('w');
     $height = $this->params()->fromQuery('h');
     $loader = $this->getLoader();
     $loader->setParams($width, $height);
     if ($id = $this->params()->fromQuery('id')) {
         $driver = $this->getRecordLoader()->load($id, 'Solr');
         $index = $this->params()->fromQuery('index');
         $this->getLoader()->loadRecordImage($driver, $index ? $index : 0);
         return parent::displayImage();
     } else {
         // Redirect book covers to VuFind's cover controller
         return parent::showAction();
     }
 }