Code Monkey home page Code Monkey logo

media-bundle's Introduction

Symfony CMF Media Bundle

Build Status StyleCI Latest Stable Version Total Downloads

WARNING: Unmaintained To focus our efforts in the CMF project, this package is currently not maintained. Security fixes and submitted bug fixes will still be released, but no new features should be expected.

If you want to help co-maintaining this package, tell us in a GitHub issue or in the #symfony_cmf channel of the Symfony devs slack.

This bundle is part of the Symfony Content Management Framework (CMF) and licensed under the MIT License.

The MediaBundle provides a way to store and edit any media and provides a generic base of common interfaces and models that allow the user to build media management solutions for a CMS. Media can be images, binary documents (like pdf files), embedded movies, uploaded movies, MP3s, etc. The implementation of this bundle is very minimalistic and is focused on images and download files. If you need more functionality (like cdn, thumbnail generation, providers for different media types and more) take a look at SonataMediaBundle. The MediaBundle provides integration with SonataMediaBundle.

Requirements

Documentation

For the install guide and reference, see:

See also:

Contributing

Pull requests are welcome. Please see our CONTRIBUTING guide.

Unit and/or functional tests exist for this bundle. See the Testing documentation for a guide to running the tests.

Thanks to everyone who has contributed already.

media-bundle's People

Contributors

ahmadrabie avatar aramalipoor avatar blump avatar cordoval avatar dantleech avatar dbu avatar eiannone avatar electricmaxxx avatar emmanuelvella avatar kea avatar lsmith77 avatar lucasgranberg avatar mannew avatar nayzo avatar pamil avatar petk avatar rmsint avatar shieldo avatar sjopet avatar uwej711 avatar webberig avatar wouterj avatar wuestkamp avatar xabbuh avatar xleliberty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

media-bundle's Issues

Path contains backslash when adding folder using elfinder

I installed the mediabundle and configured the elfinder adapter, but when I add a folder, it doesn't display it. When I look at the database, it's being added but the path name contains backslashes, eg. /cms/media\test.

I suppose this hasn't been tested on a Windows machine ? :-)

improve integration with LiipImagineBundle

it would be good to have a way to ensure that the file format is included in the paths generated via LiipImagineBundle.

f.e.

{{ /cms/media/foo | imagine_filter('small_filter') }}

might then result in

/media/cache/small_filter/cms/media/foo

however this can cause issues with some web servers and reverse proxies, as they would then set the content type to text/plain.

so we need some solution which would allow forcing the format for the mimetype into the resulting URL.

see also #77 for how to convert the mimetype to an extension

allow deletion in image form type

follow up of doctrine/DoctrinePHPCRBundle#37 - @rmsint proposed to use a form listener and handling code to handle deleting an image again.

right now the only way to delete an image is by deleting the document containing the image. this follows the idea of http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html - if the image is null (meaning we did not upload a new one) that information is simply ignored.

the proposition is to have a listener to show a checkbox removeImage that is mapped to the document and calls setRemoveImage if checked, having a way to know that the user explicitly wanted to delete the image. rmsint wrote a gist for that: https://gist.github.com/rmsint/ad4d8804e3ae6fae2160

(ported over from doctrine/DoctrinePHPCRBundle#40 and not a show stopper for 1.0)

integrate MimeTypeExtensionGuesser

might make sense to provide a service for the core MimeTypeExtensionGuesser and maybe even inject it by default into the MediaRepository and ImageRepository

Generic approach to obtain id from path

We tried to find a generic approuch to obtian the id from a file path for ORM and phpcr. It smells, maybe we can find something better or can better drop it.

Currently named "fullPathId" and used in:

  • the Imagine loader adapter, here
  • the gaufrette adapter, here

investigate image/ file upload response

We abstracted the image / file upload for Create and other web editors in UploadFileHelper::getUploadResponse.

The logic is currently ported from the CreateBundle and improved at some points. We should investigate the response more, questions raised are:

  • I don't know much about how CkEditor works, so this may not be applicable, but shouldn't we be returning a "application/json" response and using a callback in the frontend to call functions rather than returning HTML? (dantleech)
    • We now return javascript directly for the ckeditor but could investigate when we implement the ckeditor for the CreateBundle - possibly also in combination with elfinder.
    • follow up of #27 (comment)
  • I wonder if it is a good idea to refer to an "editor" here. (in UploadFileHelper::getUploadResponse) Could we not use this upload thingy from a web form, or something else? (dantleech)
    • Can we think of a use case for this? (rmsint)
    • Current logic is here because we expected the automatic upload process mostly for web editors.
    • follow up of #40 (comment)

Problem while saving images Blocks

Hi all,
i'm trying to install cmf bundles into an existing application.
a lot of components are ok, but i got a problem with images.

When i save an image into phpcr ( doctrinedbal ) , content is not saved into proper binary format.

if i dump the saved node, i got this:

  • jcr:data = xffd8ffe000104a46494600010101006400640000ffdb004300010101010101010101010101010101010101010101010101010101010101010101010...

but datas should be something like:

  • jcr:data = ����JFIFdd��C��C...

I don't understand why the content is converted to hexa string.

if I install cmf-sandbox and test it, everything is fine.
I have checked all my configs against cmf-sandbox , but i can't find the problem.

Maybe someone have an idea ?

Thanks in advance

Xavier

WIP elfinder volume driver

I added a new branch 'elfinder' with the work on the volume driver I did so far.
Most basic functions like creating folders, uploading files, removing, moving, copy, download etc work. But because there is a lot to do still I figured it would be easier to add a branch then to do a pr.

Among the things that don't yet work are previewing, cropping/resizing and opening files in the browser. But I felt I got to a point people could try it out, review code and discuss design issues.

to run the code you have to:

fm_elfinder:
    locale: %locale%
    editor: simple
    connector:
        roots:      
            media:
                driver: cmf_media.adapter.elfinder.phpcr_driver
                path: /cms/media
                upload_allow: ['all']
                upload_max_size: 2M
  • navigate to http://you_sandbox_domain/app_dev.php/elfinder

Can't get elfinder adapter to work

I followed these instructions to install FMElfinderBundle. According to this, I must set "cmf_media.adapter.elfinder.phpcr_driver" as the driver in the configuration.

But this doesn't work: the elfinder page performs an AJAX call which returns following error:

{"error":["errConf","errNoVolumes"],"debug":["Driver "FM\ElFinderPHP\Driver\ElFinderVolume@cmf_media.adapter.elfinder.phpcr_driver" does not exists"]}

The documentation of FMElfinderBundle says:

driver - can be LocalFileSystem, FTP or MySQL2, currently supported only LocalFileSystem, default is LocalFileSystem

How can I get this to work ?

hard dependency on gd

we have a call on imagecreatefromstring which comes from gd. this bundle should not create a hard dependency on gd. https://github.com/symfony-cmf/MediaBundle/blob/master/Doctrine/Phpcr/Image.php#L63

i propose we change that to

  1. check if Imagine is available and if so use it to create an image (if we can - would we still need to know which image driver to use?)
  2. check if function_exists('imagecreatefromstring'); and use that as we do now
  3. leave width and height untouched (or set to 0?)

handle upload_max_filesize

we do not gracefully handle the situation when an uploaded image is bigger than upload_max_filesize. it looks like our ModelToFileTransformer->reverseTransform misses errorhandling.

we throw:
File '' not found 500 Internal Server Error - RuntimeException

in vendor/symfony-cmf/media-bundle/Symfony/Cmf/Bundle/MediaBundle/Doctrine/Phpcr/File.php at line 47  +
at File ->setFileContentFromFilesystem ('')
in vendor/symfony-cmf/media-bundle/Symfony/Cmf/Bundle/MediaBundle/Doctrine/Phpcr/File.php at line 123  +
at File ->copyContentFromFile (object(UploadedFile))
in vendor/symfony-cmf/media-bundle/Symfony/Cmf/Bundle/MediaBundle/Form/DataTransformer/ModelToFileTransformer.php at line 38  +
at ModelToFileTransformer ->reverseTransform (object(UploadedFile))
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 1003  +
at Form ->normToModel (object(UploadedFile))
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 609  +
at Form ->submit (object(UploadedFile), true)
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 552  +
at Form ->submit (object(Request))
in vendor/symfony/symfony/src/Symfony/Component/Form/Form.php at line 645  +
at Form ->bind (object(Request))
in vendor/sonata-project/admin-bundle/Sonata/AdminBundle/Controller/CRUDController.php at line 301  +
at CRUDController ->editAction (
...

phpcr file and its resource and lastModified

while migrating an older cmf website, i realized that we have a bit of a stupid situation. currently, we define both mix:created and mix:modified on the File. but nt:file only would have mix:created, while the mix:modified is part of the jcr:resource child.

don't ask me why its like this, but it is. the problem with the current thing we have is that we duplicate the "modified" information both in the file (which is nt:unstructured until we do #10) and the content which is jcr:resource
i think from our interfaces point of view, it totally makes sense that all of this is on the file itself. i suggest to remove the mixin and mapping, and overwrite the BaseMedia getter and setters for "modified" information in the phpcr file class to forward to the resource.

http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/nodetype/package-summary.html#mix:created

The path is out of the root path "/cms/media"

I'm using @PHPCR\Child to add a File object as a child to a Page document:

 /**
 * @PHPCR\Child(nodeName="brochure.pdf")
 * @var \Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\File
 */
private $brochure;

After I saved a PDF to the document, I used the 'cmf_media_download_file' function in Twig to generate a URL. The URL is:

http://localhost/app_dev.php/media/download/cms/pages/en/product1/brochure.pdf

When I click the link, I get following error:

The path "cms/pages/en/product1/brochure.pdf" is out of the root path "/cms/media" were the file system is located

I'm trying to follow an example given by @dbu at the PHP Benelux conference. I'm using this document as an example:
https://github.com/dbu/conference-tutorial/blob/11-media/src/Dbu/ConferenceBundle/Document/Speaker.php

How come this seems to work for images in the example project (like the portrait attribute of a Speaker), but not for a File ?

option to disable auto flush

in Adapter/Gaufrette/CmfMediaDoctrine.php we have to flush after each write as gaufrette clients expect a file system behaviour. on the other hand, most of the time there will only be one operation i guess? if we go though a web interface, we upload 1 file or delete 1 file or edit 1 file, not several at once. so i guess its not that important all in all.

as the write methods will be called by generic code not knowing or caring about the optional flush parameter, we should have another way to handle this. i would propose we have a global config option on this class whether to autoflush (expected gaufrette behaviour) or not and expose some sort of getObjectManager method so that the user can flush it if needed. such as a method setAutoFlush(false)

see also #5 and KnpLabs/Gaufrette#186

Sonata Admin?

should we add simple sonata admin classes for these documents? or do we point people to SonataMediaBundle?

i just notice that in the sonata admin tree, it would be nice to be able to click on the image and edit it. not sure if sonata media would always be the right thing or might provide too much to be always a good tool for this?

How to link a document to a .pdf file + filter on extension

Hi,

I spent time reading the doc and looking at the sandbox and right now I found how to link my document to an image with a 'cmf_media_image' form type but nothing for simple file.

When I try to use a file form type i have this error :
*
The form's view data is expected to be an instance of class Symfony\Component\HttpFoundation\File\File, but is an instance of class PHPCRProxies__CG__\Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\File. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms an instance of class PHPCRProxies__CG__\Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\File to an instance of Symfony\Component\HttpFoundation\File\File.
*

I need this to have a downloadable pdf file and a video.

I don't understand why there is no 'cmf_media_file' form type ?

And is there a way to limit to a list of file extension ?

Thanks a lot

Nico

Route download controller

The current routing.xml contains "/hello/{name}", so we need to define it.

Add route for download?
enable/disable this from config?

Improve error handling

Examples:

  • the upload service uses a media root path. If it does not exist the upload of an image will fail because the parent can not be found.
  • the cmf_create.persistence.phpcr.image.basepath and cmf_media.persistence.phpcr.media_basepath can mismatch, we should check that these are indepent and have no relation. However media-bundle services that get different root paths injected can also cause an issue. See symfony-cmf/symfony-cmf#186

When and where to throw an error to notify the developer of this?

Maybe validate the configuration, so the developer directly knows if the configuration is not correct. Or do some extra checks in the constructor of some services?

image require on new document but not when existing

when a file upload field is required, it means the user must re-upload an image each time he submits the form. to edit a document that has an image field, which is inconvenient. the intended behaviour is that if the parent entity is new, the image is required, but otherwise it is optional. i tried to make the phpcr_odm_image form type handle that but only found a horrible hack https://gist.github.com/dbu/5142035

see also discussion in https://groups.google.com/forum/?fromgroups#!topic/symfony2/CrooBoaAlO4

(this is an issue in the code ported over from DoctrinePHPCRBundle doctrine/DoctrinePHPCRBundle#43 - i think its no blocker for 1.0)

Imagine with Doctrine\Phpcr\Image documents

when i try to use imagine with an Image document, i get

Parameter "path" for route "_imagine_my_filter" must match ".+" ("" given) 
to generate a corresponding URL

it works if i add a __toString method to the image that returns $this->id. it seems like LiipImagineBundle is not expecting to be passed an object but only a path to an object. can we make that work? things go wrong inside CacheManager / WebPathResolver. could we use a different path resolver?

workaround: if i pass in the id instead of the Image document, things work so at least there is a workaround.

gd dependency

seems #74 did not catch everything. i did not follow up yet whether its a bad default or we still have a hard dependency on gd, but on a system without gd i get:

  [Imagine\Exception\RuntimeException]  
  Gd not installed                      

Exception trace:
 () at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/imagine/imagine/lib/Imagine/Gd/Imagine.php:42
 Imagine\Gd\Imagine->loadGdInfo() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/imagine/imagine/lib/Imagine/Gd/Imagine.php:35
 Imagine\Gd\Imagine->__construct() at /home/david/liip/symfony-cmf/cmf-sandbox/app/cache/dev/appDevDebugProjectContainer.php:4446
 appDevDebugProjectContainer->getLiipImagineService() at /home/david/liip/symfony-cmf/cmf-sandbox/app/bootstrap.php.cache:1973
 Symfony\Component\DependencyInjection\Container->get() at /home/david/liip/symfony-cmf/cmf-sandbox/app/cache/dev/appDevDebugProjectContainer.php:1821
 appDevDebugProjectContainer->getCmfMedia_Persistence_Phpcr_Subscriber_ImageDimensionsService() at /home/david/liip/symfony-cmf/cmf-sandbox/app/bootstrap.php.cache:1973
 Symfony\Component\DependencyInjection\Container->get() at /home/david/liip/symfony-cmf/cmf-sandbox/app/cache/dev/appDevDebugProjectContainer.php:2904
 appDevDebugProjectContainer->getDoctrinePhpcr_Odm_DefaultDocumentManagerService() at /home/david/liip/symfony-cmf/cmf-sandbox/app/bootstrap.php.cache:1973
 Symfony\Component\DependencyInjection\Container->get() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ManagerRegistry.php:35
 Symfony\Bridge\Doctrine\ManagerRegistry->getService() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/doctrine/common/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:228
 Doctrine\Common\Persistence\AbstractManagerRegistry->getManagers() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php:54
 Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer->warmUp() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php:47
 Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at /home/david/liip/symfony-cmf/cmf-sandbox/app/bootstrap.php.cache:2441
 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /home/david/liip/symfony-cmf/cmf-sandbox/app/bootstrap.php.cache:2212
 Symfony\Component\HttpKernel\Kernel->boot() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:70
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /home/david/liip/symfony-cmf/cmf-sandbox/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
 Symfony\Component\Console\Application->run() at /home/david/liip/symfony-cmf/cmf-sandbox/app/console:22

Interface structure

I' m implementing this elfinder driver class and I need something to represent a directory. I tried persisting an empty File but doctrine complains there's no content and throws an error.

Looking at the classes and interfaces I see the DirectoryInterface extends the FileInterface which looks odd to me. This means that a class that implements the DirectoryInterface now has to define some functions involving properties that a directory normally does not have a.o. getExtension, getContentType and copyContentFromFile, getDescription.

What is the idea about this structure and what is the correct way of dealing with directories?

Unable to save fields in File class

The current schema for the nt:file node type prevents us from persisting any additional fields in the File class. Only the 'content' property is accepted when you pass a value to size, extension or any other property an exception is thrown stating that the field is not allowed on a nt:file node.

Add interfaces for writing - define setters

In discussions we talked about this. The basic interfaces should be minimal as most places do not need to write.

Pro:

  • ensure write actions are possible by an implemented interface

Con:

  • writing is only in sonata admin and there we can trust people to only provide classes with setters.

Does not work with latest LiipImagineBundle

The constructor of https://github.com/liip/LiipImagineBundle/blob/master/Imagine/Data/Loader/AbstractDoctrineLoader.php

now expects different parameters as found in
https://github.com/symfony-cmf/MediaBundle/blob/master/Adapter/LiipImagine/CmfMediaDoctrineLoader.php

which results in

Argument 1 passed to Liip\ImagineBundle\Imagine\Data\Loader\AbstractDoctrineLoader::__construct() must implement interface Doctrine\Common\Persistence\ObjectManager, instance of Imagine\Gd\Imagine given

No cached content generated for thumbnail

I have installed and configured the MediaBundle with LiipImagineBundle with ImageMagick. I have configured a thumbnail filter to have a preview of the image.
The system generates a path (app_dev.php/media/cache/resolve/image_upload_thumbnail/cms/media/logo_1.jpg_1410747366_279676154.jpg) but it does not create the thumbnail file.
I am still trying trying to see what is missing in the configuration.
But I was expecting the system to have have the thumbnail generated before it outputs a web path to it.
If it cannot generate the thumbnail, maybe raising an exception could help to figure out what is missing.
After I create this issue I realised the same problem is mentionned in LiipImageBundle #499.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.