/** * @covers media_subdef::get_name */ public function testGet_name() { $this->assertTrue(in_array(self::$objectPresent->get_name(), ['thumbnail', 'preview'])); $this->assertTrue(in_array(self::$objectNotPresent->get_name(), ['thumbnail', 'preview'])); }
/** * * @return string */ public function get_page() { return $this->app->url('permalinks_permaview', ['sbas_id' => $this->media_subdef->get_sbas_id(), 'record_id' => $this->media_subdef->get_record_id(), 'subdef' => $this->media_subdef->get_name(), 'token' => $this->get_token()]); }
/** * * @param Application $app * @param \media_subdef $subdef * * @return boolean|string */ public static function watermark(Application $app, \media_subdef $subdef) { static $palette; if (null === $palette) { $palette = new RGB(); } $base_id = $subdef->get_record()->get_base_id(); if ($subdef->get_name() !== 'preview') { return $subdef->get_pathfile(); } if ($subdef->get_type() !== \media_subdef::TYPE_IMAGE) { return $subdef->get_pathfile(); } if (!$subdef->is_physically_present()) { return false; } $pathIn = $subdef->get_path() . $subdef->get_file(); if (!is_file($pathIn)) { return false; } $pathOut = $subdef->get_path() . 'watermark_' . $subdef->get_file(); // cache if (is_file($pathOut)) { return $pathOut; } $in_image = $app['imagine']->open($pathIn); $in_size = $in_image->getSize(); $in_w = $in_size->getWidth(); $in_h = $in_size->getHeight(); $wm_file = $app['root.path'] . '/config/wm/' . $base_id; if (file_exists($wm_file)) { $wm_image = $app['imagine']->open($wm_file); $wm_size = $wm_image->getSize(); $wm_w = $wm_size->getWidth(); $wm_h = $wm_size->getHeight(); if ($wm_w / $wm_h > $in_w / $in_h) { $wm_size = $wm_size->widen($in_w); } else { $wm_size = $wm_size->heighten($in_h); } $wm_image->resize($wm_size); $in_image->paste($wm_image, new Point($in_w - $wm_size->getWidth() >> 1, $in_h - $wm_size->getHeight() >> 1))->save($pathOut); } else { $collname = $subdef->get_record()->get_collection()->get_name(); $draw = $in_image->draw(); $black = $palette->color("000000"); $white = $palette->color("FFFFFF"); $draw->line(new Point(0, 1), new Point($in_w - 2, $in_h - 1), $black); $draw->line(new Point(1, 0), new Point($in_w - 1, $in_h - 2), $white); $draw->line(new Point(0, $in_h - 2), new Point($in_w - 2, 0), $black); $draw->line(new Point(1, $in_h - 1), new Point($in_w - 1, 1), $white); $fsize = max(8, (int) (max($in_w, $in_h) / 30)); $fonts = [$app['imagine']->font(__DIR__ . '/arial.ttf', $fsize, $black), $app['imagine']->font(__DIR__ . '/arial.ttf', $fsize, $white)]; $testbox = $fonts[0]->box($collname, 0); $tx_w = min($in_w, $testbox->getWidth()); $tx_h = min($in_h, $testbox->getHeight()); $x0 = max(1, $in_w - $tx_w >> 1); $y0 = max(1, $in_h - $tx_h >> 1); for ($i = 0; $i <= 1; $i++) { $x = max(1, ($in_w >> 2) - ($tx_w >> 1)); $draw->text($collname, $fonts[$i], new Point($x - $i, $y0 - $i), 0); $x = max(1, $in_w - $x - $tx_w); $draw->text($collname, $fonts[$i], new Point($x - $i, $y0 - $i), 0); $y = max(1, ($in_h >> 2) - ($tx_h >> 1)); $draw->text($collname, $fonts[$i], new Point($x0 - $i, $y - $i), 0); $y = max(1, $in_h - $y - $tx_h); $draw->text($collname, $fonts[$i], new Point($x0 - $i, $y - $i), 0); } } $in_image->save($pathOut); if (is_file($pathOut)) { return $pathOut; } return false; }
/** * @retrieve detailled informations about one suddef * * @param media_subdef $media * * @return array */ private function list_embedable_media(Application $app, \record_adapter $record, \media_subdef $media) { if (!$media->is_physically_present()) { return null; } if ($app['authentication']->isAuthenticated()) { if ($media->get_name() !== 'document' && false === $app['acl']->get($app['authentication']->getUser())->has_access_to_subdef($record, $media->get_name())) { return null; } if ($media->get_name() === 'document' && !$app['acl']->get($app['authentication']->getUser())->has_right_on_base($record->get_base_id(), 'candwnldhd') && !$app['acl']->get($app['authentication']->getUser())->has_hd_grant($record)) { return null; } } if ($media->get_permalink() instanceof \media_Permalink_Adapter) { $permalink = $this->list_permalink($media->get_permalink()); } else { $permalink = null; } return ['name' => $media->get_name(), 'permalink' => $permalink, 'height' => $media->get_height(), 'width' => $media->get_width(), 'filesize' => $media->get_size(), 'devices' => $media->getDevices(), 'player_type' => $media->get_type(), 'mime_type' => $media->get_mime()]; }
/** * @param User $issuer * @param \media_subdef $subdef * @param int $url_ttl * @return string */ private function generateSubDefinitionUrl(User $issuer, \media_subdef $subdef, $url_ttl) { $payload = ['iat' => time(), 'iss' => $issuer->getId(), 'sdef' => [$subdef->get_sbas_id(), $subdef->get_record_id(), $subdef->get_name()]]; if ($url_ttl >= 0) { $payload['exp'] = $payload['iat'] + $url_ttl; } /** @var SecretProvider $provider */ $provider = $this->app['provider.secrets']; $secret = $provider->getSecretForUser($issuer); return $this->app->url('media_accessor', ['token' => JWT::encode($payload, $secret->getToken(), 'HS256', $secret->getId())]); }
/** * @retrieve detailled informations about one suddef * * @param media_subdef $media * @return array */ protected function list_embedable_media(media_subdef $media) { if (!$media->is_physically_present()) { return null; } if ($media->get_permalink() instanceof media_Permalink_Adapter) { $permalink = $this->list_permalink($media->get_permalink()); } else { $permalink = null; } return ['name' => $media->get_name(), 'permalink' => $permalink, 'height' => $media->get_height(), 'width' => $media->get_width(), 'filesize' => $media->get_size(), 'devices' => $media->getDevices(), 'player_type' => $media->get_type(), 'mime_type' => $media->get_mime()]; }