Esempio n. 1
0
 public function generateSubdefs(\record_adapter $record, array $wanted_subdefs = null)
 {
     if (null === ($subdefs = $record->get_databox()->get_subdef_structure()->getSubdefGroup($record->get_type()))) {
         $this->logger->info(sprintf('Nothing to do for %s', $record->get_type()));
         return;
     }
     foreach ($subdefs as $subdef) {
         $subdefname = $subdef->get_name();
         if ($wanted_subdefs && !in_array($subdefname, $wanted_subdefs)) {
             continue;
         }
         $pathdest = null;
         if ($record->has_subdef($subdefname) && $record->get_subdef($subdefname)->is_physically_present()) {
             $pathdest = $record->get_subdef($subdefname)->get_pathfile();
             $record->get_subdef($subdefname)->remove_file();
             $this->logger->info(sprintf('Removed old file for %s', $subdefname));
             $record->clearSubdefCache($subdefname);
         }
         $pathdest = $this->generateSubdefPathname($record, $subdef, $pathdest);
         $this->logger->addInfo(sprintf('Generating subdef %s to %s', $subdefname, $pathdest));
         $this->generateSubdef($record, $subdef, $pathdest);
         if ($this->filesystem->exists($pathdest)) {
             $media = $this->mediavorus->guess($pathdest);
             \media_subdef::create($this->app, $record, $subdef->get_name(), $media);
         }
         $record->clearSubdefCache($subdefname);
         $this->app['dispatcher']->dispatch(RecordEvents::SUB_DEFINITION_CREATED, new RecordSubDefinitionCreatedEvent($record, $subdefname));
     }
     return $this;
 }
Esempio n. 2
0
 public function deliverContent(Request $request, \record_adapter $record, $subdef, $watermark, $stamp)
 {
     $file = $record->get_subdef($subdef);
     $pathOut = $file->get_pathfile();
     if ($watermark === true && $file->get_type() === \media_subdef::TYPE_IMAGE) {
         $pathOut = \recordutils_image::watermark($this->app, $file);
     } elseif ($stamp === true && $file->get_type() === \media_subdef::TYPE_IMAGE) {
         $pathOut = \recordutils_image::stamp($this->app, $file);
     }
     $disposition = $request->query->get('download') ? DeliverDataInterface::DISPOSITION_ATTACHMENT : DeliverDataInterface::DISPOSITION_INLINE;
     /** @var Response $response */
     $response = $this->deliverFile($pathOut, $file->get_file(), $disposition, $file->get_mime());
     if (in_array($subdef, array('document', 'preview'))) {
         $response->setPrivate();
         $this->logView($record, $request);
     } elseif ($subdef !== 'thumbnail') {
         try {
             if ($file->getDataboxSubdef()->get_class() != \databox_subdef::CLASS_THUMBNAIL) {
                 $response->setPrivate();
                 $this->logView($record, $request);
             }
         } catch (\Exception $e) {
             // Ignore exception
         }
     }
     $response->isNotModified($request);
     return $response;
 }
Esempio n. 3
0
 public function connect(Application $app)
 {
     $app['controller.datafiles'] = $this;
     $controllers = $app['controllers_factory'];
     $that = $this;
     $controllers->before(function (Request $request) use($app) {
         if (!$app['authentication']->isAuthenticated()) {
             $app->abort(403, sprintf('You are not authorized to access %s', $request->getRequestUri()));
         }
     });
     $controllers->get('/{sbas_id}/{record_id}/{subdef}/', function ($sbas_id, $record_id, $subdef, PhraseaApplication $app) use($that) {
         $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
         $record = new \record_adapter($app, $sbas_id, $record_id);
         $stamp = $watermark = false;
         if ($subdef != 'thumbnail') {
             $all_access = false;
             $subdefStruct = $databox->get_subdef_structure();
             if ($subdefStruct->getSubdefGroup($record->get_type())) {
                 foreach ($subdefStruct->getSubdefGroup($record->get_type()) as $subdefObj) {
                     if ($subdefObj->get_name() == $subdef) {
                         if ($subdefObj->get_class() == 'thumbnail') {
                             $all_access = true;
                         }
                         break;
                     }
                 }
             }
             if (!$record->has_subdef($subdef) || !$record->get_subdef($subdef)->is_physically_present()) {
                 throw new NotFoundHttpException();
             }
             if (!$app['acl']->get($app['authentication']->getUser())->has_access_to_subdef($record, $subdef)) {
                 throw new AccessDeniedHttpException(sprintf('User has not access to subdef %s', $subdef));
             }
             $stamp = false;
             $watermark = !$app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'nowatermark');
             if ($watermark && !$all_access) {
                 $subdef_class = $databox->get_subdef_structure()->get_subdef($record->get_type(), $subdef)->get_class();
                 if ($subdef_class == \databox_subdef::CLASS_PREVIEW && $app['acl']->get($app['authentication']->getUser())->has_preview_grant($record)) {
                     $watermark = false;
                 } elseif ($subdef_class == \databox_subdef::CLASS_DOCUMENT && $app['acl']->get($app['authentication']->getUser())->has_hd_grant($record)) {
                     $watermark = false;
                 }
             }
             if ($watermark && !$all_access) {
                 $repository = $app['EM']->getRepository('Phraseanet:BasketElement');
                 /* @var $repository BasketElementRepository */
                 $ValidationByRecord = $repository->findReceivedValidationElementsByRecord($record, $app['authentication']->getUser());
                 $ReceptionByRecord = $repository->findReceivedElementsByRecord($record, $app['authentication']->getUser());
                 if ($ValidationByRecord && count($ValidationByRecord) > 0) {
                     $watermark = false;
                 } elseif ($ReceptionByRecord && count($ReceptionByRecord) > 0) {
                     $watermark = false;
                 }
             }
         }
         return $that->deliverContent($app['request'], $record, $subdef, $watermark, $stamp, $app);
     })->bind('datafile')->assert('sbas_id', '\\d+')->assert('record_id', '\\d+');
     return $controllers;
 }
Esempio n. 4
0
 public function substitute(\record_adapter $record, $name, MediaInterface $media)
 {
     $newfilename = $record->get_record_id() . '_0_' . $name . '.' . $media->getFile()->getExtension();
     $subdef_def = false;
     if ($name == 'document') {
         $baseprefs = $record->get_databox()->get_sxml_structure();
         $pathhd = \p4string::addEndSlash((string) $baseprefs->path);
         $filehd = $record->get_record_id() . "_document." . strtolower($media->getFile()->getExtension());
         $pathhd = \databox::dispatch($this->fs, $pathhd);
         $this->fs->copy($media->getFile()->getRealPath(), $pathhd . $filehd, true);
         $subdefFile = $pathhd . $filehd;
         $meta_writable = true;
     } else {
         $type = $record->isStory() ? 'image' : $record->get_type();
         $subdef_def = $record->get_databox()->get_subdef_structure()->get_subdef($type, $name);
         if ($record->has_subdef($name) && $record->get_subdef($name)->is_physically_present()) {
             $path_file_dest = $record->get_subdef($name)->get_pathfile();
             $record->get_subdef($name)->remove_file();
             $record->clearSubdefCache($name);
         } else {
             $path = \databox::dispatch($this->fs, $subdef_def->get_path());
             $this->fs->mkdir($path, 0750);
             $path_file_dest = $path . $newfilename;
         }
         try {
             $this->alchemyst->turnInto($media->getFile()->getRealPath(), $path_file_dest, $subdef_def->getSpecs());
         } catch (MediaAlchemystException $e) {
             return;
         }
         $subdefFile = $path_file_dest;
         $meta_writable = $subdef_def->meta_writeable();
     }
     $this->fs->chmod($subdefFile, 0760);
     $media = $this->mediavorus->guess($subdefFile);
     \media_subdef::create($this->app, $record, $name, $media);
     $record->delete_data_from_cache(\record_adapter::CACHE_SUBDEFS);
     if ($meta_writable) {
         $record->write_metas();
     }
     if ($name == 'document') {
         $record->rebuild_subdefs();
     }
     $this->dispatcher->dispatch(RecordEvents::MEDIA_SUBSTITUTED, new RecordMediaSubstitutedEvent($record));
 }
Esempio n. 5
0
 public function displayTechnicalDatas(Application $app, $sbas_id, $record_id)
 {
     $record = new \record_adapter($app, $sbas_id, $record_id);
     try {
         $document = $record->get_subdef('document');
     } catch (\Exception $e) {
         $document = null;
     }
     return $app['twig']->render('prod/Tooltip/TechnicalDatas.html.twig', ['record' => $record, 'document' => $document]);
 }
 public function getAction(Request $request, $sbas_id, $record_id, $subdef)
 {
     $databox = $this->appbox->get_databox((int) $sbas_id);
     $record = new \record_adapter($this->app, $sbas_id, $record_id);
     $stamp = $watermark = false;
     if ($subdef != 'thumbnail') {
         $all_access = false;
         $subdefStruct = $databox->get_subdef_structure();
         if ($subdefStruct->getSubdefGroup($record->get_type())) {
             foreach ($subdefStruct->getSubdefGroup($record->get_type()) as $subdefObj) {
                 /** @var \databox_subdef $subdefObj */
                 if ($subdefObj->get_name() == $subdef) {
                     if ($subdefObj->get_class() == 'thumbnail') {
                         $all_access = true;
                     }
                     break;
                 }
             }
         }
         if (!$record->has_subdef($subdef) || !$record->get_subdef($subdef)->is_physically_present()) {
             throw new NotFoundHttpException();
         }
         if (!$this->acl->get($this->authentication->getUser())->has_access_to_subdef($record, $subdef)) {
             throw new AccessDeniedHttpException(sprintf('User has not access to subdef %s', $subdef));
         }
         $stamp = false;
         $watermark = !$this->acl->get($this->authentication->getUser())->has_right_on_base($record->get_base_id(), 'nowatermark');
         if ($watermark && !$all_access) {
             $subdef_class = null;
             try {
                 $subdef_class = $databox->get_subdef_structure()->get_subdef($record->get_type(), $subdef)->get_class();
             } catch (\Exception_Databox_SubdefNotFound $e) {
             }
             if ($subdef_class == \databox_subdef::CLASS_PREVIEW && $this->acl->get($this->authentication->getUser())->has_preview_grant($record)) {
                 $watermark = false;
             } elseif ($subdef_class == \databox_subdef::CLASS_DOCUMENT && $this->acl->get($this->authentication->getUser())->has_hd_grant($record)) {
                 $watermark = false;
             }
         }
         if ($watermark && !$all_access) {
             $repository = $this->app['repo.basket-elements'];
             $ValidationByRecord = $repository->findReceivedValidationElementsByRecord($record, $this->authentication->getUser());
             $ReceptionByRecord = $repository->findReceivedElementsByRecord($record, $this->authentication->getUser());
             if ($ValidationByRecord && count($ValidationByRecord) > 0) {
                 $watermark = false;
             } elseif ($ReceptionByRecord && count($ReceptionByRecord) > 0) {
                 $watermark = false;
             }
         }
     }
     return $this->deliverContent($request, $record, $subdef, $watermark, $stamp);
 }
Esempio n. 7
0
 public function deliverContent(Request $request, \record_adapter $record, $subdef, $watermark, $stamp, Application $app)
 {
     $file = $record->get_subdef($subdef);
     $pathOut = $file->get_pathfile();
     if ($watermark === true && $file->get_type() === \media_subdef::TYPE_IMAGE) {
         $pathOut = \recordutils_image::watermark($app, $file);
     } elseif ($stamp === true && $file->get_type() === \media_subdef::TYPE_IMAGE) {
         $pathOut = \recordutils_image::stamp($app, $file);
     }
     $log_id = null;
     try {
         $logger = $app['phraseanet.logger']($record->get_databox());
         $log_id = $logger->get_id();
         $referrer = 'NO REFERRER';
         if (isset($_SERVER['HTTP_REFERER'])) {
             $referrer = $_SERVER['HTTP_REFERER'];
         }
         $record->log_view($log_id, $referrer, $app['conf']->get(['main', 'key']));
     } catch (\Exception $e) {
     }
     $disposition = $request->query->get('download') ? DeliverDataInterface::DISPOSITION_ATTACHMENT : DeliverDataInterface::DISPOSITION_INLINE;
     $response = $app['phraseanet.file-serve']->deliverFile($pathOut, $file->get_file(), $disposition, $file->get_mime());
     $response->setPrivate();
     /* @var $response \Symfony\Component\HttpFoundation\Response */
     if ($file->getEtag()) {
         $response->setEtag($file->getEtag());
         $response->setLastModified($file->get_modification_date());
     }
     if (false === $record->is_grouping() && $subdef !== 'document') {
         try {
             if ($file->getDataboxSubdef()->get_class() == \databox_subdef::CLASS_THUMBNAIL) {
                 // default expiration is 5 days
                 $expiration = 60 * 60 * 24 * 5;
                 $response->setExpires(new \DateTime(sprintf('+%d seconds', $expiration)));
                 $response->setMaxAge($expiration);
                 $response->setSharedMaxAge($expiration);
                 $response->setPublic();
             }
         } catch (\Exception $e) {
         }
     }
     $response->isNotModified($request);
     return $response;
 }
Esempio n. 8
0
 protected function checkEmbed($embed, \record_adapter $record)
 {
     if ($embed['filesize'] === 0) {
         var_dump($embed);
     }
     $subdef = $record->get_subdef($embed['name']);
     $this->assertArrayHasKey("name", $embed);
     $this->assertArrayHasKey("permalink", $embed);
     $this->checkPermalink($embed['permalink'], $subdef);
     $this->assertArrayHasKey("height", $embed);
     $this->assertEquals($embed['height'], $subdef->get_height());
     $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['height']);
     $this->assertArrayHasKey("width", $embed);
     $this->assertEquals($embed['width'], $subdef->get_width());
     $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['width']);
     $this->assertArrayHasKey("filesize", $embed);
     $this->assertEquals($embed['filesize'], $subdef->get_size());
     $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_INT, $embed['filesize']);
     $this->assertArrayHasKey("player_type", $embed);
     $this->assertEquals($embed['player_type'], $subdef->get_type());
     $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $embed['player_type']);
     $this->assertArrayHasKey("mime_type", $embed);
     $this->assertEquals($embed['mime_type'], $subdef->get_mime());
     $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $embed['mime_type']);
     $this->assertArrayHasKey("devices", $embed);
     $this->assertEquals($embed['devices'], $subdef->getDevices());
     $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $embed['devices']);
 }
Esempio n. 9
0
 protected function processRecords(\record_adapter $record, $outfile, $caption)
 {
     if (!file_exists($record->get_subdef('document')->get_pathfile())) {
         return false;
     }
     $this->getService('filesystem')->copy($record->get_subdef('document')->get_pathfile(), $outfile);
     $dest_file = new \SplFileInfo($outfile);
     touch($dest_file->getPathname(), $record->get_creation_date()->format('U'), $record->get_modification_date()->format('U'));
     switch (strtolower($caption)) {
         case 'xml':
             $pathinfo = pathinfo($dest_file->getPathname());
             $xml = $this->container['serializer.caption']->serialize($record->get_caption(), CaptionSerializer::SERIALIZE_XML);
             $xml_file = dirname($outfile) . '/' . $pathinfo['filename'] . '.xml';
             file_put_contents($xml_file, $xml);
             break;
         default:
             break;
     }
     return true;
 }
Esempio n. 10
0
 /**
  * Return basic information about a record
  *
  * @param integer $bid base id
  * @param integer $rid record id
  * @param array   $tab config for the html table
  *
  * @return array
  */
 public function buildTabUserWhat($bid, $rid, $tab = false)
 {
     $this->initialize();
     $sbas_id = phrasea::sbasFromBas($this->app, $bid);
     try {
         $record = new record_adapter($this->app, $sbas_id, $rid);
     } catch (\Exception_Record_AdapterNotFound $e) {
         return $this->report;
     }
     $this->setDisplay($tab);
     $this->champ = ['photo', 'record_id', 'date', 'type', 'titre', 'taille'];
     $document = $record->get_subdef('document');
     $this->title = $this->app->trans('report:: Information sur l\'enregistrement numero %number%', ['%number%' => (int) $rid]);
     $x = $record->get_thumbnail();
     $this->result[] = ['photo' => "<img style='width:" . $x->get_width() . "px;height:" . $x->get_height() . "px;'\n                        src='" . $x->get_url() . "'>", 'record_id' => $record->get_record_id(), 'date' => $this->app['date-formatter']->getPrettyString($document->get_creation_date()), 'type' => $document->get_mime(), 'titre' => $record->get_title(), 'taille' => $document->get_size()];
     $this->setDisplayNav();
     $this->setReport();
     return $this->report;
 }