The sfMediaLibraryPlugin provides an easy-to-use interface to manage web assets (images, PDF documents, Flash objects, and so on). It also provides an extension to tinyMCE so that the media inclusion feature of rich text editors uses the assets uploaded through the plugin's module.

License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release 0.9.1 - 16/11/2007

Release 0.9.0 - 12/11/2007

Release 0.8.2 - 10/07/2007

Release 0.8.1 - 16/04/2007

Release 0.8.0 - 13/04/2007

sfMediaLibrary plugin

The sfMediaLibraryPlugin provides an easy-to-use interface to manage web assets (images, PDF documents, Flash objects, and so on). It also provides an extension to tinyMCE so that the media inclusion feature of rich text editors uses the assets uploaded through the plugin's module.

This plug-in consists of:

one module

one helper group

one JavaScript script

Screenshot

Installation

To install the plugin for a symfony project, the usual process is to use the symfony command line:

Alternatively, if you don't have PEAR installed, you can download the latest package attached to this plugin's wiki page and extract it under your project's plugins/ directory. You will also have to copy the contents of the myproject/plugins/sfMediaLibraryPlugin/web/ directory into a myproject/web/sfMediaLibraryPlugin/ directory.

By default, all uploaded files are stored in the uploads/assets directory under the web directory.
You can customize this directory by changing the upload_dir setting in app.yml (you must provide a relative path to the web directory):

all:
sfMediaLibrary:
upload_dir: media

In the above example, uploaded files will be in the web/media directory.

The sfMediaLibrary module

The module allows for the upload, renaming and deletion of all types of files (image, pdf, spreadsheet, etc). Click on an asset name to rename it, click on the trashcan icon to delete it.

You can create, rename and delete subdirectories as well, resulting in a real tree structure that will keep your media assets organized.

The module is fully i18n'ed, and the plugin comes with English, French, Spanish and Brazilian Portuguese translations.

Uploaded assets end up under the myproject/web/uploads/assets/ directory. This means that when you want to include them in a template with, for instance, an image_tag(), you must use an absolute path, as follows:

<?php echo image_tag('/uploads/assets/path_to_asset.suffix') ?>

Interface with the sfThumbnailPlugin

If the sfThumbnailPlugin is installed in your project, sfMediaLibrary will automatically use it to create thumbnail images of the images you upload. To deactivate this behavior, change the following setting in the app.yml:

all:
sfMediaLibrary:
use_thumbnails: true
thumbnails_dir: thumbnails

By default, thumbnail images are stored under a thumbnail/ subdirectory of the image directory. You can change the name of this directory through another setting of the app.yml:

all:
sfMediaLibrary:
thumbnails_dir: thumbnail

Using the media library with TinyMCE

If you want to use the sfMediaLibrary plugin as a replacement for tinyMCE's file browser for image insertion, you must first initiate the plugin with a helper in the template:

That's it, the TinyMCE file browser is now the sfMediaLibrary's one. I'm not sure if this is the case for everyone, but I had to add the advimage plugin to the list of tinymce plugins for it to fully work without javascript errors.

Tip: For use with an admin generated module, place the init_media_library() call in the _edit_header.php partial in the templates/ directory of the module. To define the callback in a generator.yml, do as follows:

Using the Media Library input_file helper

Traditionally, when an asset has to be referenced in a form, a file input is used (<input type='file'>). It allows the user to upload a file from his computer to the server, and this file can be further embedded in a rich text content.

Using the sfMediaLibrary, you can change this control into some sort of file input that wouldn't refer to the client's computer, but to the media library itself, or, to put it differently, to the files located in web/uploads/assets/. The plugin comes with a special helper for that purpose, the input_asset_tag(). Use is just like a regular input_tag():

The input is not a real file input tag, meaning that the chosen asset file will not be posted woth the request. It is iseless anyway, since the file is already on the server. Instead, the action will be able to retrieve the asset file path relative to the web root, exactly what is needed to display it.

Optionally, you can restrict the choice of possible assets in this input to images only, as follows: