/** * @covers media_subdef::get_type */ public function testGet_type() { $this->assertEquals(\media_subdef::TYPE_IMAGE, self::$objectPresent->get_type()); }
/** * * @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; }
private function listEmbeddableMedia(Request $request, \record_adapter $record, \media_subdef $media) { if (!$media->is_physically_present()) { return null; } if ($this->getAuthenticator()->isAuthenticated()) { $acl = $this->getAclForUser(); if ($media->get_name() !== 'document' && false === $acl->has_access_to_subdef($record, $media->get_name())) { return null; } if ($media->get_name() === 'document' && !$acl->has_right_on_base($record->getBaseId(), 'candwnldhd') && !$acl->has_hd_grant($record)) { return null; } } if ($media->get_permalink() instanceof \media_Permalink_Adapter) { $permalink = $this->listPermalink($media->get_permalink()); } else { $permalink = null; } $urlTTL = (int) $request->get('subdef_url_ttl', $this->getConf()->get(['registry', 'general', 'default-subdef-url-ttl'])); if ($urlTTL < 0) { $urlTTL = -1; } $issuer = $this->getAuthenticatedUser(); 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(), 'substituted' => $media->is_substituted(), 'created_on' => $media->get_creation_date()->format(DATE_ATOM), 'updated_on' => $media->get_modification_date()->format(DATE_ATOM), 'url' => $this->generateSubDefinitionUrl($issuer, $media, $urlTTL), 'url_ttl' => $urlTTL]; }
/** * @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()]; }
/** * @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()]; }