作者:ronnyl
项目:MediaBundl
/**
* @abstract
* @param \Sonata\MediaBundle\Model\MediaInterface $media
* @return string
*/
public function generatePath(MediaInterface $media)
{
$rep_first_level = (int) ($media->getId() / $this->firstLevel);
$rep_second_level = (int) (($media->getId() - ($rep_first_level * $this->firstLevel)) / $this->secondLevel);
return sprintf('%s/%04s/%02s', $media->getContext(), $rep_first_level + 1, $rep_second_level + 1);
}
作者:zapoyo
项目:core-bundl
/**
* {@inheritdoc}
*/
public function getBox(MediaInterface $media, array $settings)
{
$size = $media->getBox();
$skipBox = false;
$constraint = array_key_exists('constraint', $settings) && $settings['constraint'] === false;
if ($constraint && $size->getHeight() > $size->getWidth()) {
$settings['width'] = $settings['height'];
$this->mode = ImageInterface::THUMBNAIL_INSET;
$skipBox = true;
}
$hasWidth = array_key_exists('width', $settings) && $settings['width'] > 0;
$hasHeight = array_key_exists('height', $settings) && $settings['height'] > 0;
if (!$hasWidth && !$hasHeight) {
throw new \RuntimeException(sprintf('Width/Height parameter is missing in context "%s" for provider "%s". Please add at least one parameter.', $media->getContext(), $media->getProviderName()));
}
if ($hasWidth && $hasHeight && !$skipBox) {
return new Box($settings['width'], $settings['height']);
}
if (!$hasHeight) {
$settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth());
}
if (!$hasWidth) {
$settings['width'] = (int) ($settings['height'] * $size->getWidth() / $size->getHeight());
}
return $this->computeBox($size, $settings);
}
作者:novate
项目:SonataMediaBundl
/**
* Updates a media
*
* @param \Sonata\MediaBundle\Model\MediaInterface $media
* @param string $context
* @param string $providerName
* @return void
*/
public function save(MediaInterface $media, $context = null, $providerName = null)
{
if ($context) {
$media->setContext($context);
}
if ($providerName) {
$media->setProviderName($providerName);
}
$isNew = $media->getId() != null;
if ($isNew) {
$this->pool->getProvider($media->getProviderName())->prePersist($media);
} else {
$this->pool->getProvider($media->getProviderName())->preUpdate($media);
}
$this->dm->persist($media);
$this->dm->flush();
if ($isNew) {
$this->pool->getProvider($media->getProviderName())->postPersist($media);
} else {
$this->pool->getProvider($media->getProviderName())->postUpdate($media);
}
// just in case the pool alter the media
$this->dm->persist($media);
$this->dm->flush();
}
作者:novate
项目:SonataMediaBundl
/**
* @param \Sonata\MediaBundle\Model\MediaInterface $media
*
* @return string the file extension for the $media, or the $defaultExtension if not available
*/
protected function getExtension(MediaInterface $media)
{
$ext = $media->getExtension();
if (!is_string($ext) || strlen($ext) < 3) {
$ext = $this->defaultFormat;
}
return $ext;
}
作者:nicolasricc
项目:SonataMediaBundl
/**
* @param MediaInterface $media
*/
protected function fixBinaryContent(MediaInterface $media)
{
if (!$media->getBinaryContent()) {
return;
}
if (preg_match("/www.dailymotion.com\\/video\\/([0-9a-zA-Z]*)_/", $media->getBinaryContent(), $matches)) {
$media->setBinaryContent($matches[1]);
}
}
作者:nicolasricc
项目:SonataMediaBundl
/**
* @param MediaInterface $media
*/
protected function fixBinaryContent(MediaInterface $media)
{
if (!$media->getBinaryContent()) {
return;
}
if (preg_match("/vimeo\\.com\\/(video\\/|)(\\d+)/", $media->getBinaryContent(), $matches)) {
$media->setBinaryContent($matches[2]);
}
}
作者:gautier
项目:imh-websit
/**
* Replace 4/3 by 16/9 format
* Possible Formats :
* default
* mqdefault -> medium quality
* hqdefault -> high quality
* sddefault
* maxresdefault
*
* {@inheritdoc}
*/
public function getReferenceImage(MediaInterface $media)
{
$url = $media->getMetadataValue('thumbnail_url');
$pattern = '/\\bhqdefault\\b/i';
$sddefault_url = preg_replace($pattern, 'sddefault', $url);
//var_dump($sddefault_url);
//exit();
return $sddefault_url;
}
作者:ronnyl
项目:MediaBundl
public function getHelperProperties(MediaInterface $media, $format, $options = array())
{
$format_configuration = $this->getFormat($format);
return array_merge(array(
'title' => $media->getName(),
'src' => $this->generatePublicUrl($media, $format),
'width' => $format_configuration['width'],
), $options);
}
作者:rmzamor
项目:SonataMediaBundl
/**
* @param MediaInterface $media
*
* @return mixed
*/
protected function getRootCategory(MediaInterface $media)
{
if (!$this->rootCategories) {
$this->rootCategories = $this->container->get('sonata.classification.manager.category')->getRootCategories(false);
}
if (!array_key_exists($media->getContext(), $this->rootCategories)) {
throw new \RuntimeException(sprintf('There is no main category related to context: %s', $media->getContext()));
}
return $this->rootCategories[$media->getContext()];
}
作者:estebannov
项目:multimedi
/**
* {@inheritdoc}
*/
public function getHelperProperties(MediaInterface $media, $format, $options = array())
{
/*$getId3 = new GetId3();
$audio = $getId3
->setOptionMD5Data(true)
->setOptionMD5DataSource(true)
->setEncoding('UTF-8')
->analyze($this->root_dir . '/../web' .$this->generatePublicUrl($media, $format))
;*/
return array_merge(array('name' => $media->getName(), 'src' => $this->generatePublicUrl($media, $format), 'filesize' => $media->getMetadataValue('filesize'), 'fileformat' => $media->getMetadataValue('fileformat'), 'encoding' => $media->getMetadataValue('encoding'), 'mime_type' => $media->getMetadataValue('mime_type'), 'playtime_seconds' => $media->getMetadataValue('playtime_seconds'), 'playtime_string' => $media->getMetadataValue('playtime_string'), 'bitrate' => $media->getMetadataValue('bitrate'), 'audio_dataformat' => $media->getMetadataValue('audio_dataformat'), 'audio_codec' => $media->getMetadataValue('audio_codec'), 'audio_sample_rate' => $media->getMetadataValue('audio_sample_rate'), 'audio_channels' => $media->getMetadataValue('audio_channels'), 'audio_bits_per_sample' => $media->getMetadataValue('audio_bits_per_sample'), 'audio_lossless' => $media->getMetadataValue('audio_lossless'), 'audio_channelmode' => $media->getMetadataValue('audio_channelmode'), 'video_dataformat' => $media->getMetadataValue('video_dataformat'), 'video_resolution_x' => $media->getMetadataValue('video_resolution_x'), 'video_resolution_y' => $media->getMetadataValue('video_resolution_y'), 'video_fourcc' => $media->getMetadataValue('video_fourcc'), 'video_frame_rate' => $media->getMetadataValue('video_frame_rate'), 'video_codec' => $media->getMetadataValue('video_codec')), $options);
}
作者:symbi
项目:orangegate4-media-bundl
public function getFormatName(MediaInterface $media, $format)
{
if (in_array($format, array('admin', 'reference', 'orangegate'))) {
return $format;
}
$baseName = $media->getContext() . '_';
if (substr($format, 0, strlen($baseName)) == $baseName) {
return $format;
}
return $baseName . str_replace('-', '_', $format);
}
作者:NadirZenit
项目:NzSonataMediaBundl
protected function createQrCode(MediaInterface $media)
{
$path = tempnam(sys_get_temp_dir(), 'sonata_media_qrcode_reference') . '.' . $this->config['extension'];
$qrCode = new QrCode();
$qrCode->setText($media->getBinaryContent())->setSize($this->config['size'])->setPadding($this->config['padding'])->setErrorCorrection($this->config['error_correction'])->setForegroundColor($this->config['foreground'])->setBackgroundColor($this->config['background'])->setLabel($this->config['label'])->setLabelFontSize($this->config['label_size'])->setImageType($this->config['extension']);
if ($this->config['logo'] && is_file($this->config['logo'])) {
$qrCode->setLogo($this->config['logo']);
}
$qrCode->save($path);
return $path;
}
作者:novate
项目:SonataMediaBundl
/**
* {@inheritdoc}
*/
public function save(MediaInterface $media, $context = null, $providerName = null)
{
if ($context) {
$media->setContext($context);
}
if ($providerName) {
$media->setProviderName($providerName);
}
// just in case the pool alter the media
$this->em->persist($media);
$this->em->flush();
}
作者:rapeme
项目:init-cms-bundl
/**
* {@inheritdoc}
*/
protected function fixBinaryContent(MediaInterface $media)
{
if (!$media->getBinaryContent()) {
return;
}
if (strlen($media->getBinaryContent()) === 11) {
return;
}
if (preg_match("/^(?:http(?:s)?:\\/\\/)?(?:www\\.)?(?:youtu\\.be\\/|youtube\\.com\\/(?:(?:watch)?\\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\\/))([^\\#\\?&\"'>]+)/", $media->getBinaryContent(), $matches)) {
$media->setBinaryContent($matches[1]);
}
}
作者:serialke
项目:BugTracke
/**
* @param \Sonata\MediaBundle\Model\MediaInterface $media
*
* @return string
*/
public function generatePath(MediaInterface $media)
{
$segments = preg_split('#/#', $media->getId(), null, PREG_SPLIT_NO_EMPTY);
if (count($segments) > 1) {
// remove last part from id
array_pop($segments);
$path = join($segments, '/');
} else {
$path = '';
}
return $path ? sprintf('%s/%s', $media->getContext(), $path) : $media->getContext();
}
作者:helme
项目:SonataMediaBundl
/**
* @param \Sonata\MediaBundle\Model\MediaInterface $media
* @param \Gaufrette\File $in
* @param \Gaufrette\File $out
* @param string $format
* @param array $settings
* @return void
*/
public function resize(MediaInterface $media, File $in, File $out, $format, $settings)
{
if (!isset($settings['width'])) {
throw new \RuntimeException(sprintf('Width parameter is missing in context "%s" for provider "%s"', $media->getContext(), $media->getProviderClass()));
}
$image = $this->getAdapter()->load($in->getContent());
if ($settings['height'] == null) {
$size = $image->getSize();
$settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth());
}
$content = $image->thumbnail(new Box($settings['width'], $settings['height']), $this->getMode())->get($format);
$out->setContent($content);
}
作者:Infernosqua
项目:SonataMediaBundl
/**
* @throws InvalidArgumentException
*
* @param MediaInterface $media
* @param array $settings
*
* @return Box
*/
protected function computeBox(MediaInterface $media, array $settings)
{
if ($this->mode !== ImageInterface::THUMBNAIL_INSET && $this->mode !== ImageInterface::THUMBNAIL_OUTBOUND) {
throw new InvalidArgumentException('Invalid mode specified');
}
$size = $media->getBox();
$ratios = array($settings['width'] / $size->getWidth(), $settings['height'] / $size->getHeight());
if ($this->mode === ImageInterface::THUMBNAIL_INSET) {
$ratio = min($ratios);
} else {
$ratio = max($ratios);
}
return $size->scale($ratio);
}
作者:ingeniorwe
项目:symfo3c
/**
* {@inheritdoc}
*/
public function getHelperProperties(MediaInterface $media, $format, $options = array())
{
if ($format == 'reference') {
$box = $media->getBox();
} else {
$resizerFormat = $this->getFormat($format);
if ($resizerFormat === false) {
throw new \RuntimeException(sprintf('The image format "%s" is not defined.
Is the format registered in your ``sonata_media`` configuration?', $format));
}
$box = $this->resizer->getBox($media, $resizerFormat);
}
return array_merge(array('alt' => $media->getName(), 'title' => $media->getName(), 'src' => $this->generatePublicUrl($media, $format), 'width' => $box->getWidth(), 'height' => $box->getHeight()), $options);
}
作者:saberyouni
项目:Sonata-Projec
/**
* @param MediaInterface $metadata
* @param string $filename
*
* @return array
*/
protected function getAmazonBuilder(MediaInterface $media, $filename)
{
$adapter = $this->container->get($media->getProviderName())->getFilesystem()->getAdapter();
//handle special Replicate adapter
if ($adapter instanceof Replicate) {
$adapterClassNames = $adapter->getAdapterClassNames();
} else {
$adapterClassNames = array(get_class($adapter));
}
//for amazon s3
if (!in_array('Gaufrette\\Adapter\\AmazonS3', $adapterClassNames) || !$this->container->has('sonata.media.metadata.amazon')) {
return false;
}
return $this->container->get('sonata.media.metadata.amazon')->get($media, $filename);
}
作者:nicolasricc
项目:SonataMediaBundl
/**
* {@inheritdoc}
*/
public function generate(MediaProviderInterface $provider, MediaInterface $media)
{
$backend = $this->backend;
$id = $this->id;
$publish = function () use($backend, $media, $id) {
$backend->createAndPublish('sonata.media.create_thumbnail', array('thumbnailId' => $id, 'mediaId' => $media->getId(), 'providerReference' => $media->getProviderReference()));
};
// BC compatibility for missing EventDispatcher
if (null === $this->dispatcher) {
trigger_error('Since version 2.3.3, passing an empty parameter in argument 4 for __construct() in ' . __CLASS__ . ' is deprecated and the workaround for it will be removed in 3.0.', E_USER_DEPRECATED);
$publish();
} else {
$this->dispatcher->addListener('kernel.finish_request', $publish);
}
}