예제 #1
0
파일: Url.php 프로젝트: patrova/omeka-s
 /**
  * Ingest from a URL.
  *
  * Accepts the following non-prefixed keys:
  *
  * + ingest_url: (required) The URL to ingest. The idea is that some URLs
  *   contain sensitive data that should not be saved to the database, such
  *   as private keys. To preserve the URL, remove sensitive data from the
  *   URL and set it to o:source.
  * + store_original: (optional, default true) Whether to store an original
  *   file. This is helpful when you want the media to have thumbnails but do
  *   not need the original file.
  *
  * {@inheritDoc}
  */
 public function ingest(Media $media, Request $request, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     if (!isset($data['ingest_url'])) {
         $errorStore->addError('error', 'No ingest URL specified');
         return;
     }
     $uri = new HttpUri($data['ingest_url']);
     if (!($uri->isValid() && $uri->isAbsolute())) {
         $errorStore->addError('ingest_url', 'Invalid ingest URL');
         return;
     }
     $file = $this->getServiceLocator()->get('Omeka\\File');
     $file->setSourceName($uri->getPath());
     $this->downloadFile($uri, $file->getTempPath());
     $fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
     $hasThumbnails = $fileManager->storeThumbnails($file);
     $media->setHasThumbnails($hasThumbnails);
     if (!isset($data['store_original']) || $data['store_original']) {
         $fileManager->storeOriginal($file);
         $media->setHasOriginal(true);
     }
     $media->setFilename($file->getStorageName());
     $media->setMediaType($file->getMediaType());
     if (!array_key_exists('o:source', $data)) {
         $media->setSource($uri);
     }
 }
예제 #2
0
 protected function isValid($value)
 {
     try {
         $uri = new Http($value);
         return $uri->isValid() && $uri->isAbsolute() && $uri->getFragment() === null;
     } catch (InvalidArgumentException $e) {
         return false;
     }
 }
예제 #3
0
파일: IIIF.php 프로젝트: patrova/omeka-s
 public function ingest(Media $media, Request $request, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     if (!isset($data['o:source'])) {
         $errorStore->addError('o:source', 'No IIIF Image URL specified');
         return;
     }
     $source = $data['o:source'];
     //Make a request and handle any errors that might occur.
     $uri = new HttpUri($source);
     if (!($uri->isValid() && $uri->isAbsolute())) {
         $errorStore->addError('o:source', "Invalid url specified");
         return false;
     }
     $client = $this->getServiceLocator()->get('Omeka\\HttpClient');
     $client->setUri($uri);
     $response = $client->send();
     if (!$response->isOk()) {
         $errorStore->addError('o:source', sprintf("Error reading %s: %s (%s)", $type, $response->getReasonPhrase(), $response->getStatusCode()));
         return false;
     }
     $IIIFData = json_decode($response->getBody(), true);
     if (!$IIIFData) {
         $errorStore->addError('o:source', 'Error decoding IIIF JSON');
         return;
     }
     //Check if valid IIIF data
     if ($this->validate($IIIFData)) {
         $media->setData($IIIFData);
         // Not IIIF
     } else {
         $errorStore->addError('o:source', 'URL does not link to IIIF JSON');
         return;
     }
     //Check API version and generate a thumbnail
     //Version 2.0
     if (isset($IIIFData['@context']) && $IIIFData['@context'] == 'http://iiif.io/api/image/2/context.json') {
         $URLString = '/full/full/0/default.jpg';
         // Earlier versions
     } else {
         $URLString = '/full/full/0/native.jpg';
     }
     if (isset($IIIFData['@id'])) {
         $fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
         $file = $this->getServiceLocator()->get('Omeka\\File');
         $this->downloadFile($IIIFData['@id'] . $URLString, $file->getTempPath());
         $hasThumbnails = $fileManager->storeThumbnails($file);
         if ($hasThumbnails) {
             $media->setFilename($file->getStorageName());
             $media->setHasThumbnails(true);
         }
     }
 }
예제 #4
0
파일: Youtube.php 프로젝트: patrova/omeka-s
 public function ingest(Media $media, Request $request, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     if (!isset($data['o:source'])) {
         $errorStore->addError('o:source', 'No YouTube URL specified');
         return;
     }
     $uri = new HttpUri($data['o:source']);
     if (!($uri->isValid() && $uri->isAbsolute())) {
         $errorStore->addError('o:source', 'Invalid YouTube URL specified');
         return;
     }
     switch ($uri->getHost()) {
         case 'www.youtube.com':
             if ('/watch' !== $uri->getPath()) {
                 $errorStore->addError('o:source', 'Invalid YouTube URL specified, missing "/watch" path');
                 return;
             }
             $query = $uri->getQueryAsArray();
             if (!isset($query['v'])) {
                 $errorStore->addError('o:source', 'Invalid YouTube URL specified, missing "v" parameter');
                 return;
             }
             $youtubeId = $query['v'];
             break;
         case 'youtu.be':
             $youtubeId = substr($uri->getPath(), 1);
             break;
         default:
             $errorStore->addError('o:source', 'Invalid YouTube URL specified, not a YouTube URL');
             return;
     }
     $fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
     $file = $this->getServiceLocator()->get('Omeka\\File');
     $url = sprintf('http://img.youtube.com/vi/%s/0.jpg', $youtubeId);
     $this->downloadFile($url, $file->getTempPath());
     $hasThumbnails = $fileManager->storeThumbnails($file);
     $media->setData(['id' => $youtubeId, 'start' => $request->getValue('start'), 'end' => $request->getValue('end')]);
     if ($hasThumbnails) {
         $media->setFilename($file->getStorageName());
         $media->setHasThumbnails(true);
     }
 }
예제 #5
0
 /**
  * Check if ssl is forced or not
  *
  * @param EventInterface $event Mvc event
  *
  * @return null|Zend\Http\PhpEnvironment\Response
  */
 public function check(EventInterface $event)
 {
     $coreConfig = $event->getApplication()->getServiceManager()->get('CoreConfig');
     $matchedRouteName = $event->getRouteMatch()->getMatchedRouteName();
     $request = $event->getRequest();
     $uri = $request->getUri();
     if ($matchedRouteName === 'cms') {
         if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_frontend_ssl')) {
             $newUri = new Uri($coreConfig->getValue('secure_frontend_base_path'));
             $newUri->setScheme('https');
         } else {
             $newUri = new Uri($coreConfig->getValue('unsecure_frontend_base_path'));
         }
     } else {
         if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_backend_ssl')) {
             $newUri = new Uri($coreConfig->getValue('secure_backend_base_path'));
             $newUri->setScheme('https');
         } else {
             $newUri = new Uri($coreConfig->getValue('unsecure_backend_base_path'));
         }
     }
     if (!empty($newUri) and $newUri->isValid() and ($newUri->getHost() != '' and $uri->getHost() != $newUri->getHost()) or $newUri->getScheme() != '' and $uri->getScheme() != $newUri->getScheme()) {
         $uri->setPort($newUri->getPort());
         if ($newUri->getHost() != '') {
             $uri->setHost($newUri->getHost());
         }
         if ($newUri->getScheme() != '') {
             $uri->setScheme($newUri->getScheme());
         }
         $response = $event->getResponse();
         $response->setStatusCode(302);
         $response->getHeaders()->addHeaderLine('Location', $request->getUri());
         $event->stopPropagation();
         return $response;
     }
 }
예제 #6
0
 public function testValidHostTypesWithUnderScore()
 {
     $uri = new HttpUri('http://zf2_app.local');
     $this->assertTrue($uri->isValid());
 }
예제 #7
0
 /**
  * Return the base website URI
  *
  * Either returns whatever was configured, or works it out from the current request
  * @return HttpUri
  */
 public function getWebsiteUri()
 {
     if ($this->website) {
         return $this->website;
     }
     $uri = $this->getOptions()->getWebsiteUrl();
     if (!empty($uri)) {
         $website = new HttpUri($uri);
     } else {
         $website = new HttpUri();
         if (isset($_SERVER['HTTP_HOST'])) {
             $website->setHost($_SERVER['HTTP_HOST']);
         }
         $website->setScheme('http');
         if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' || isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
             $website->setScheme('https');
         }
     }
     if (!$website->isValid()) {
         throw new Exception\RuntimeException('Cannot determine current host');
     }
     $this->website = $website;
     return $website;
 }
예제 #8
0
파일: OEmbed.php 프로젝트: patrova/omeka-s
 /**
  * Make a request and handle any errors that might occur.
  *
  * @param string $url URL to request
  * @param string $type Type of URL (used to compose error messages)
  * @param ErrorStore $errorStore
  */
 protected function makeRequest($url, $type, ErrorStore $errorStore)
 {
     $uri = new HttpUri($url);
     if (!($uri->isValid() && $uri->isAbsolute())) {
         $errorStore->addError('o:source', "Invalid {$type} specified");
         return false;
     }
     $client = $this->getServiceLocator()->get('Omeka\\HttpClient');
     $client->setUri($uri);
     $response = $client->send();
     if (!$response->isOk()) {
         $errorStore->addError('o:source', sprintf("Error reading %s: %s (%s)", $type, $response->getReasonPhrase(), $response->getStatusCode()));
         return false;
     }
     return $response;
 }