Giter Site home page Giter Site logo

bmcclure / cakephp-media-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mariuswilms/media

60.0 60.0 24.0 3.29 MB

A CakePHP (2.0) plugin enabling transfer/manipulation/embedding of files in 23 ways.

License: Other

PHP 99.54% CSS 0.23% JavaScript 0.23%

cakephp-media-plugin's People

Contributors

adriengibrat avatar bmcclure avatar drewisme avatar gbokiau avatar gmomchilov avatar iamduncan avatar jmillerdesign avatar mariuswilms avatar olistockman avatar rchavik avatar ricog avatar sitedyno avatar slywalker avatar thomheymann avatar vstabile 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  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

cakephp-media-plugin's Issues

Problem with plugin actions structure

Strict (2048): Declaration of TransferBehavior::setup() should be compatible with ModelBehavior::setup(Model $model, $config = Array) [APP/Plugin/Media/Model/Behavior/TransferBehavior.php, line 62]

Warning (2): Invalid argument supplied for foreach() [APP/Plugin/Media/Model/Behavior/GeneratorBehavior.php, line 162]

I couldn't get the Generator behavior to work, and I believe it is in part due to a typo on line 160.

$filter = Configure::read('Media.filter.' . Mime_Type::guessName($file));;

Configure::read('Media.filter.') is empty.

Configure::read('Media.filter') returns the expected list of filters.

I changed it to:

    $filter = Configure::read('Media.filter');
    $filter = $filter['default'][Mime_Type::guessName($file)];

And got it to write the images as expected. Perhaps I have an implementation error?

Thumbnails not being generated

When I upload an image, only the original is sent to media/transfer/img. No thumbnails are being created.

I downloaded the zip yesterday so I have the most up to date version. I am running 2.2.4 cake. The only lines I changed were the ones I mentioned in the issue about images not displaying in view which were lines 107 and 119 in the plugin bootstrap.php because the images were being uploaded in a folder outside of webroot. I don't think these small changes have anything to do with the thumbnails being generated.

No uploads in static dir

Hi,

My uploads are writing to the transfer directory within webroot however are not being moved to the static folder after complete. I've edited bootstrap.php as suggested in issue #30 with no luck. I then reverted to the original bootstrap.php and edited GeneratorBehavior.php as suggested in issue #31, still not getting completed uploads moved from transfer to static directory. Any suggestions?

Move core.php

In the cake-2.0 branch, there is a case issue with the config folder. config/core.php should be moved to Config/core.php.

Videos not Working

when I try to use the embed or embedAsObject methods of the MediaHelper, nothing is displayed. In fact, when I view the source of my page, it looks like a video embed is never even attempted.

saveAll not working correctly in case validation is involved

I'm currently in the process of overhauling the whole package. I've stumbeld over #22 and reimplemented the old behavior including 1.3 branch backwards compatibility (need to write some more tests for this), this was what actually made me to do all this, once it was implemented I wanted to write some tests, so I had to fix the test suite, and then one thing lead to another...

I've made everything Cake 2.x, PHP 5.x, PHPUnit and Windows compatible, updated the documenation, adjusted the coding style, fixed some validation, fixed some tests, added some new ones, and much more (I'm going to make it public as soon as I'm done). And while fixing the Attachment test I've noticed that saveAll isn't quite working, not only because the test itself is incorrect (the files to be transfered are stored under the CakePHP TMP folder, but the Attachment model validation doesn't include this path in the location validation), but because of changes in CakePHP regarding saving and validation.

While CakePHP 1.x triggered validation twice, ie it first validated only, and then validated again before the save operation, CakePHP 2.x triggers validation only once. Why is this a problem you may ask? Well, after 2 days of nearly no sleep I figured that the problem is that the Media plugin prepares the files in the Model::beforeValidate() callback, stores the preparation results (TransferBehaviour::_prepare()) on the model, and reuses these results for the transfer (TransferBehaviour::transfer()).

The problem with this is, that with multiple files that belong to the same model, each file overwrites the result of the previous file in the validation stage, causing the transfer in the saving stage to use the prepared settings of the last file from the validation stage, which leads to multiple files using the same destination, causing version creation to fail. In CakePHP 1.x the additional validation before each save operation triggered the preparation of the file again, causing the correct data to be stored for transer.

So, since I know what the problem is, why don't I fix it? Well, I'm kinda tired, the last two days were pretty stressful, and I have a lot of other work to do too. So while I'm going to fix it later on if no one else does it, I would be very thankful if at least someone could have a look at this, check whether I'm correct and maybe throw in some ideas on what would be the best way to fix this.

It would be pretty easy to force preparation of the file again in TransferBehaviour::transfer() (I've tested it, it works), however I'm not sure whether this is a good idea at all.

Travis integration and backwards compatibility

I've noticed that Travis is enabled for this repository, but it's not working as it's missing an appropriate configuration.

I've played with it a little bit and figured a configuration that works with all the latest CakePHP 2.x.x builds:

https://github.com/ndm2/CakePHP-Media-Plugin/blob/f6257c9eff501c0e29545aadf44afd26f61b3c1f/.travis.yml
https://travis-ci.org/ndm2/CakePHP-Media-Plugin/builds/13637928

Though it requires suppressing E_NOTICE for 2.0.x builds as of PHP 5.4, since some of the overwritten method signatures have changed (haven't yet figured a proper way to apply suppression only to the builds using PHP => 5.4).

I guess it's debatable whether trying to keep a branch compatible over that many versions is a good thing, so I thought I'd bring this up for discussion.

Personally I think backwards compatibility is generally nice to have, especially for legacy applications, and as long as it doesn't require too much jumping through hoops, I would prefer this over maintaining multiple branches.

Deleting /releasing images

I am using the plugin with a hasmany/grouping set up and using the supplied attachments element - adding attachments works fine, no problem at all, however when I try and delete/release an attachment using the checkbox it fails to delete the attachment.

Am I missing something obvious?

Can I supply any more info to help narrow this down? Happy to try and help fix it!

Fatal error:

During the installation steps:
require APP . 'Plugin' . DS . 'Media' . DS . 'Config' . DS . 'core.php';

The Config directory doesn't contain the file named core.php

include - APP/Config/bootstrap.php, line 74
Configure::bootstrap() - CORE/Cake/Core/Configure.php, line 92
require - CORE/Cake/bootstrap.php, line 146
ShellDispatcher::_bootstrap() - CORE/Cake/Console/ShellDispatcher.php, line 131
ShellDispatcher::_initEnvironment() - CORE/Cake/Console/ShellDispatcher.php, line 101
ShellDispatcher::__construct() - CORE/Cake/Console/ShellDispatcher.php, line 57
ShellDispatcher::run() - CORE/Cake/Console/ShellDispatcher.php, line 68
[main] - CORE/Cake/Console/cake.php, line 43PHP Fatal error: require() [http://php.net/function.require]: Failed opening required '/home/lnxg33k/Desktop/scratch/work/synapse/CTF/Plugin/Media/Config/core.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/lnxg33k/Desktop/scratch/work/synapse/CTF/Config/bootstrap.php on line 74

Fatal error: require() [http://php.net/function.require]: Failed opening required '/home/lnxg33k/Desktop/scratch/work/synapse/CTF/Plugin/Media/Config/core.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/lnxg33k/Desktop/scratch/work/synapse/CTF/Config/bootstrap.php on line 74

File Upload shoud be required

I have a file upload, but i want that it is a mandatory field, so the file upload is required.

In my model I tried this:

public $validate = array(
'file' => array(
'required' => true,
'extension' => array('rule' => array('checkExtension', false, array('jpg', 'jpeg', 'png', 'tif', 'tiff', 'gif'))),
'mimeType' => array('rule' => array('checkMimeType', false, array('image/jpeg', 'image/png', 'image/tiff', 'image/gif')))
)
);

But an error occurs in TransferBehavior.php:

public function setup($Model, $settings = array()) {
/* If present validation rules get some sane default values */
if (isset($Model->validate['file'])) {
$default = array('allowEmpty' => true, 'required' => false, 'last' => true);

        foreach ($Model->validate['file'] as &$rule) {
            $rule = array_merge($default, $rule);
        }
    }

...

This line fails
$rule = array_merge($default, $rule);
I think because it tries to merge my "required" with the "required" which is defined in this method.
So, of course I can change the $default, but it is not very nice especially updating the plugin, I have to change it every time :-(

Are there any better solutions?

Deleting all versions of an image

I upload an image and generate automatically different versions.
Deleting a record which has an image, should also delete all versions of this image.

So I found this tutorial:
https://github.com/davidpersson/media/blob/next/docs/TUTORIAL

There is a function:
public function beforeDelete($cascade = true)

This one is called, but this line returns an error:
$versions = array_keys(Configure::read('Media.filter.' . $name));
This is caused by
Configure::read('Media.filter.' . $name)

$name is "image", so the call is
Configure::read('Media.filter.image')
and this returns NULL.

So the question is, why?
In my Plugin/Media/Config/core.php I did not change these lines, so it should work?

Configure::write('Media.filter', array('default' => array(
'audio' => compact('s', 'm'),
'document' => compact('s', 'm'),
'generic' => array(),
'image' => compact('s', 'm'),
'video' => compact('s', 'm')
)));

Is there a problem because of CakePHP 2.0?

Not able to display images in the view

Hi,

I am trying to use this plugin to upload pictures in a website that am building but am encountering some challenges.

First off when i execute the command "cake Media.Media init", this is what happens
1

The image above shows that the transfer directory is been created outside the webroot directory. When I upload images there been saved in that directory.

Now the problem comes when I try to display, the view does not get the image in the path specified as it tends to check in webroot folder. It does not find the transfer directory and thus displays nothing.

Please help

Image is not uploaded to transfer folder

I have CakePHP 2.0.2 and the latest version of yours CakePHP Media Plugin.

I uploaded all files to 'app/Plugin/media' and I created these directory by myself:

  • app/Plugin/media/filter/
  • app/Plugin/media/static/
  • app/Plugin/media/transfer/

Each folder has these subfolders:
-- aud/
-- doc/
-- gen/
-- img/
-- vid/

In 'app/Config/core.php' I added this line
require_once(APP.'Plugin'.DS.'media'.DS.'Config'.DS.'core.php');
in the last line of this core.php file.

And this line in 'app/Config/bootstrap.php':
CakePlugin::load('Media');

In my 'app/View/Regions/add.ctp':

Form->create('Region', array('type' => 'file')); echo $this->Form->input('name'); echo $this->Form->input('file', array('type' => 'file')); echo $this->Form->end('Add Region'); ?>

In the Model 'app/Model/Region.php', I added this lne:
var $actsAs = array('Media.Transfer');

In 'app/Controller/RegionsController.php':

public function add() {
if ($this->request->is('post')) {
debug($this->request->data);
}
}

The data has all the image data:

Array
(
[Region] => Array
(
[name] => ddd
[file] => Array
(
[name] => test.jpg
[type] => image/jpeg
[tmp_name] => /var/www/test/phptmp/phpNGHHYm
[error] => 0
[size] => 51827
)
)
)

Now I read in the tutorial file which is located under 'app/Plugin/media/docs/TUTORIAL':

If you now go and repeat submitting the file via the add form, this
time the file should end up being stored below webroot/media/transfer
in img/clipboard.jpg.

But in my case, there is no test.jpg image in this folder, and there is no error message. So what's the problem?
I also added .htaccess files with content
Order deny,allow
Deny from all
but that should not be the problem.

Anyone an idea?

Should MediaHelper::embed()/embedAsObject() support URLs additionally to file paths?

So while trying to implement #42, I've noticed that it looks like MediaHelper::embed() and MediaHelper::embedAsObject() were somehow expected to not only take file paths, but also (absolute) URLs.

While the parameter documentation only speaks of absolute or relative file paths, MediaHelper::_sources() actually checks whether the passed path is a URL (let's ignore for a moment that the parameter order is wrong, of course the haystack needs to come first):

if (strpos('://', $path) !== false) {
    $file = parse_url($url, PHP_URL_PATH);
}

if (strpos('://', $path) !== false) {

However, this won't work, first of all the code never reaches the point where the path is tested for being an absolute URL, as it will fail here first:

if (!$url = $this->url($path, $full)) {
    return false;
}

if (!$url = $this->url($path, $full)) {

But let's assume something magic ✨ happens and the URL would make it through this check and the wrongly called strpos, and both $path and $url would actually contain an URL like http://example.com/media/static/img/image-png.png.

It would then extract the /media/static/img/image-png.png part and use this as the file path, and again, it would fail, as it would look for /media/static/img/image-png.png in the filesystem, and this is most likely not be the absolute path to the file (additionally this might trigger an open_basedir restriction error).

So now I'm a little bit lost here, not just because it doesn't work and it's pretty hard to tell how this might have been supposed to work, but also because I'm wondering whether MediaHelper::embed()/embedAsObject() supporting URLs would be a good idea at all?

Improve helper's error reporting

Currently, when MediaHelper doesn't find an image, it returns an empty string without any further warning (even when debug is on).
When the 'media' folder is missing or wrongly configured, the Helper outputs a php notice: 'Undefined variable: dirname'

I think it would be a benefit for usability to have more helpful error reporting for these kinds of errors.

MediaHelper should encode URLs

I think URLs should be percent-encoded by default, and additionally entity-encoded for use in MediaHelper::embed() and MediaHelper::embedAsObject().

By default the uploaded files should be realtively safe, the filename is being sent through Inflector::slug(), the directory name is retrieved from hard-coded values, the extension however could hold problematic chars (in case possible validation rules allow this), just like the paths supplied to MediaHelper, they could contain anything. Non-user uploaded files however should not be expected to be named safely.

So I'd suggest that MediaHelper::webroot() and MediaHelper::url() should return a percent-encoded URL, and MediaHelper::embed() and MediaHalper::embedAsObject() should additionally entity-encode them on their own. That way one could still easily use the URLs in a non-HTML context, without having to decode possible entities.

When it comes to percent-encoding we are facing the same "problem" here as the CakePHP core, it's rather complicated to take of the chars %, # and ?, see cakephp/cakephp#2238. I think the helper should take the same approach as the Cake core for now, and do not care about %, # and ?, but just do basic encoding of the URLs path components.

Any thoughts on this?

using 'url' option with embed() method no longer makes a link

Hey guys,

haven't been able to minutely follow all the recent commits (I've seen some discussion about a url parameter, don't know if this is at all related)

Since MediaHelper now extends HtmlHelper function, linking an image to an url no longer works; HtmlHelper::link() now calls MediaHelpers::url() instead of Helper::url().

Linking images to urls is done by adding an 'url' parameter in the embed() options array. https://github.com/bmcclure/CakePHP-Media-Plugin/blob/cake-2.0/View/Helper/MediaHelper.php#L185

The created link thus has an empty href attribute

issue with generator behavior

What I'm trying to do:
I want to create a view where the user can re-crop images handled by the media plugin

Setup:
All mediafiles are stored by the Attachment Model which is based of the one shipped with the Mediaplugin.
Other Models can use the Attachment Model to store mediafiles.

My Attempt:
Step 1 (View/Attachments/admin_edit.ctp): Gather cropdata, data will injected to the form via javascript
Step 2 (Controller/AttachmentsController.php)
        2.1: Save attachment data
        2.2: if attachment data was saved: process cropdata with use of $this->Attachment->makeVersion($file, $instructions);
        2.3: redirect to attachments indexview using  $this->redirect(array($admin = true, 'controller' => 'attachments', 'action' => 'index'));

Issue:
My general attempt is working, so all images get croped like i want them to but the following redirect isn't fired, instead a weird redirect to current action is executed somewhere.
I narrowed it down to the makeVersion() method, when i comment that out, the attachment gets still saved and the redirect is working like it's supposed to.

So it seems that makeVersion() has some weird sideeffect.

Since i get redirected it is really hard to debug because i cannot inspect the request or check for errors.
I tried with using debug();exit; to narrow it further down inside of the makeVersion() method but i really don't get this, theres no redirects called anywhere inside.

Code:
https://github.com/KingLoui/mediatest/blob/master/app/Controller/AttachmentsController.php

Thanks in advance for your effort!
Cheers
Matthias

BTW: I altered the crop function from the mediaplugin and added 4 optional parameters so i can crop the images with my data from jcrop, so don't get confused by the functioncall in makeversion.
Since there wasn't a suitable cropfunction built in i assume no one ever tried what i do with the plugin??

Problems with TransferBehavior::checkExtension

The current code is:

// if (!MediaValidation::extension(${$type}['extension'], $deny, $allow)) {
// return false;
// }

But if we use that code, then the extension is double checked and finally the method returns false. It should be:

        if (!MediaValidation::extension(${$type}['basename'], $deny, $allow)) {
            return false;
        }   

so pathinfo() inside Validation utility (cakephp core Utility) works Fine.

Thanks

Restructure included 'mm' library

I don't want to mess with davidpersson's mm library itself, because it's a separate project that I want to remain compatible with as long as it aligns with my goals. I don't want to have to maintain it, and it seems to work well.

The main problem I have with it, however, is it is in a non-standard package directory (Lib/mm/src/) instead of something more like Lib/MM/. Since underneath the src directory it is using Cake's package naming structure, it still works in Lib, but it just feels a little bit wrong.

Anyway, the main thing that should be changed is the way it's being included throughout the plugin. Previously it was manually including the files wherever they were used, but we should switch to an App::uses call instead since they can be lazy-loaded and potentially show a slight gain if any of the classes are not actually needed.

I had initially tried to implement some App::uses lines which are still in the plugin now, but I didn't fully understand the syntax and how it differed from App::import so I am nearly positive the lines do nothing.

Adding the media plugin behaviours prevents edit/delete of record

If I add the code:

//media plugin behaviors
var $actsAs = array(
'Media.Transfer',
'Media.Coupler',
'Media.Generator'
);

to my model then I can no longer edit or delete the records. If I remove it then the fields provided by the media manager are not populate.

Update installation documentation

Installation documentation on step 3 says

CakePlugin::load('Media');
require APP . 'Plugin' . DS . 'Media' . DS . 'Config' . DS . 'core.php';

instead of

CakePlugin::load('Media');
require APP . 'Plugin' . DS . 'Media' . DS . 'Config' . DS . 'bootstrap.php';

Documentation issue

I've discovered your plugin right now and steped trough the installation documentation. In the last section under the "Installation" headline you are using the shell command:

chmod 777 -R webroot/media/{transfer,filter}

I'm not sure how it works on windows but on linux you have to enter following to get it work:
chmod -R 777 webroot/media/{transfer,filter}

Nothing special ;)

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.