2017 © Pedro Peláez
 

cakephp-plugin cakephp3-media

Media plugin for CakePHP 3

image

romano83/cakephp3-media

Media plugin for CakePHP 3

  • Thursday, December 17, 2015
  • by Romano83
  • Repository
  • 4 Watchers
  • 7 Stars
  • 417 Installations
  • JavaScript
  • 1 Dependents
  • 0 Suggesters
  • 6 Forks
  • 5 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Media plugin for CakePHP 3

Build Status Coverage Status, (*1)

About

The aim of this plugin is to give you the ability to create and associate any kind of medias in your application. This plugin is the adapation from Grafikart's Media Plugin for CakePHP 3., (*2)

Overview

Installation

Requirements

Steps to install

  • Run :
composer require romano83/cakephp3-media
  • Import The file config\schema\medias.sql in your database

How to use

In your config\bootstrap.php file, add this line, (*3)

Plugin::load('Media', ['bootstrap' => false, 'routes' => true]);

Security purpose

By default, the plugin is blocked for everyone. To set proper permissions, you can implement canUploadMedia() method in your YourApp\AppController. For exemple :, (*4)

public function canUploadMedias($model, $id){
    if($model === 'YourApp\Model\Table\UsersTable' && $id == $this->Auth->user('id')){
        return true; // Everyone can upload medias for their own records
    }
    return $this->Auth->user('role') == 'admin'; // Admins have all rights
}

Behavior

To use this plugin, you must load the MediaBehavior in your tables. Form instance, if you want to manage medias for your posts :, (*5)

addBehavior(
            'Media.Media', [
                'path' => 'img/upload/%y/%m/%f',    // default upload path relative to webroot folder (see below for path parameters)
                'extensions' => ['jpg', 'png'],     // array of authorized extensions (lowercase)
                'limit' => 0,                       // limit number of upload file. Default: 0 (no limit)
                'max_width' => 0,                   // maximum authorized width for uploaded pictures. Default: 0 (no limitation) 
                'max_height' => 0,                  // maximum authorized height for uploaded pictures. Default: 0 (no limitation)
                'size' => 0                         // maximum autorized size for uploaded pictures (in kb). Default: 0 (no limitation)
            ]
        );
    }
}
```
For the path option, you have numerous parameters :
* %y        Year
* %m        Month
* %f        Sluggified filename
* %id       Media Id
* %cid      Media Id /100
* %mid      Media Id /1000

### Helper

In order to add media upload and edit capabilities in your views, you can use `MediaHelper`.

To do so, add in your `AppController` 
```php
loadHelper( 'Media.Media' );
    }
}
```

For example, you can add an iframe to manage medias: 
```php
= $this->Media->iframe('Model', 'ID'); ?>

Or you can add text editor (tinymce for instance) inside form :, (*6)

= $this->Form->create(); ?>
= $this->Media->tinymce($fieldname, 'Model', 'Id', array $options); ?>
= $this->Form->end(); ?>

This method take the same array $options than native FormInput helper., (*7)

Thumb

If you want to add thumb for your posts, you must add media_id field in your 'Model' database table., (*8)

Notice

In order to upload pictures, you should implement draft system for your model., (*9)

ToDo

  • Add the ability to edit a media when clicked;
  • Add resize, crop, flip and rotate functions;
  • Finish unit test...

How to contribute

  • You have find a bug ? You can open an issue
    • Clearly describe the issue including steps to reproduce when it is a bug.
    • Make sure you fill in the earliest version that you know has the issue.
    • Screenshots and code exemple are welcome in the issues.
  • You want to implement a new feature or fix a bug ? Please follow this guide :
    • Your code must follow the Coding Standard of CakePHP. Check the cakephp-codesniffer repository to setup the CakePHP standard.
    • You must add Test Cases for your new feature. Test Cases ensure that the application will continue to working in the future.
    • Your PR should be on the dev branch.

Special thanks

  • Grafikart for the first version of this plugin !

The Versions

17/12 2015

dev-dev

dev-dev

Media plugin for CakePHP 3

  Sources   Download

The Requires

  • php >=5.4.0

 

The Development Requires

plugin cakephp media

17/12 2015

dev-master

9999999-dev

Media plugin for CakePHP 3

  Sources   Download

The Requires

  • php >=5.4.0

 

The Development Requires

plugin cakephp media