lyMediaManagerPlugin
0.5.2beta
for sf 1.4sf 1.3 and Doctrine
MIT
The plugin offers a simple web interface to upload and manage images, documents and other media files directly from the backend of your symfony application. File upload and file browsing features can be easily integrated into the TinyMCE editor.
Developers
License
Copyright (c) 2010 Massimo Giagnoni
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.
lyMediamanagerPlugin is partially derivative work of sfAssetsLibraryPlugin (MIT license).
Copyright (c) 2008 Ma Generation, Francois Zaninotto, Gabriele Santini, William Garcia
lyMediaManagerPlugin
The plugin offers a simple web interface to upload and manage images, documents and other media files directly from the backend of your symfony application. File upload and file browsing features can be easily integrated into the TinyMCE editor.
lyMediaManagerPlugin is inspired to sfAssetsLibraryPlugin for Propel, but some of its features have not been ported yet while others have been reimplemented in a different way.
This plugin is being developed to be included in Lyra CMS (also under development), but it's a standard plugin that can be used in any symfony project with no dependencies except sfThumbnailPlugin, needed to generate thumbnails.
This is currently a beta release, play with it, please report me any error and feel free to suggest improvements
Installation
Automatic installation
lyMediaManagerPlugin can be quickly installed with the symfony command plugin:install (you must have PEAR installed on your system).
php symfony plugin:install --stability=beta lyMediaManagerPlugin
sfThumbnailPlugin is also needed to generate thumbnails of images.
php symfony plugin:install sfThumbnailPlugin
Manual installation
Alternatively you can uncompress the .tgz package inside the plugins directory of your symfony project. If you have Subversion installed you can also install the plugin by checking out the source code from the repository: cd to the plugins directory of your symfony project and execute
svn checkout http://svn.symfony-project.com/plugins/lyMediaManagerPlugin/trunk lyMediaManagerPlugin
If you choose the manual installation another two steps are needed. Plugins must be enabled in your project configuration class. Example:
//%project_dir%/config/ProjectConfigurationClass.class.php
...
public function setup()
{
$this->enablePlugins('sfDoctrinePlugin');
$this->enablePlugins('sfThumbnailPlugin');
$this->enablePlugins('lyMediaManagerPlugin');
}
...
Plugin assets must be published with the following symfony command
php symfony plugin:publish-assets
Building models and tables
Then we need to generate plugin model classes and corresponding database tables.
php symfony doctrine:build --all
Keep in mind that this will erase all your data and rebuild everything from scratch. Before executing the statement above you may want to backup your database and restore it thereafter.
Enabling plugin modules
lyMediaManagerPlugin contains two modules: lyMediaAsset, lyMediaFolder. Both must be enabled in settings.yml file (usually in your backend application). Example.
#%project_dir%/apps/backend/config/settings.yml
all:
.settings:
enabled_modules: [default, lyMediaAsset, lyMediaFolder]
Initializing folder tree
lyMediaManagerPlugin provides a custom task to create the media library root directory inside the web directory of your project and the corresponding root node in the database. By default this directory will be called media: see configuration below if you prefer a different name.
php symfony media:create-root
This command should be executed by an user of the same group of the http server, if this is not possible chmod/chown the media library root directory so that is writable by the http server.
Go to default page
Assuming that you are testing the plugin on localhost and you have enabled modules in your backend application, visit
http://localhost/backend.php/ly_media_asset
to go to the module default page.
Configuration
Some configuration parameters can be set inside the app.yml file of your application. Example.
#%project_dir%/apps/backend/config/app.yml
all:
lyMediaManager:
# root directory name (used by task media:create-root)
media_root: media
# thumbnails settings
thumbnails:
small:
width: 84
height: 84
# forces thumbnail size to fixed width/height values
shave: true
medium:
width: 194
height: 152
# name of folder where thumbnails will be created
thumbnail_folder: thumbs
# thumbnails will be created only for these mime-types
create_thumbnails_for: [image/jpeg,image/png,image/gif]
# only files with these extensions can be uploaded
allowed_extensions: [jpg,png,gif,txt]
# only files of these mime-types can be uploaded
mime_types: [image/jpeg,image/png,image/gif,text/plain]
Note: small and medium size thumbnails are used by the plugin itself and should not be removed. More thumbnails of desired sizes can be created for use in your application.
Synchronize task
A dedicated task is available to synchronize the media library database with the contents of a directory.
php symfony media:synchronize ./web/uploads/medias --application=backend
All folders and files in './web/uploads/medias' (a relative path, but you can specify an absolute path as well) that are not present in the media library will be added and a corresponding record created in the database. Thumbnails will be automatically generated for files of mime-types indicated in plugin configuration (see parameter create_thumbnails_for).
php symfony media:synchronize ./web/uploads/medias --removeOrphanAssets --application=backend
Same as above, but in addition every file that is present in the media library without a corresponding file in './web/uploads/medias' will be removed from the media library.
php symfony media:synchronize ./web/uploads/medias --removeOrphanFolders --application=backend
This time every folder in the media library without a corresponding folder in the directory will be removed. If something it's not clear, play with the task in a development environment to see the effect of these switches.
Todo
- Complete this README :)
- i18n
- Improve user interface
- Support other plugins for thumbnail generation (sfImageTransformPlugin)
- Add more tests