Posted by Geir19 on December 16, 2010 at 12:11pm
4 followers
| Project: | WYSIWYG image upload - Inline images for your WYSIWYG |
| Version: | 6.x-2.9 |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
| Issue tags: | filefield_paths, token |
Issue Summary
I see that only the $uid variable can be used to set the upload path inside "admin/settings/wysiwyg_imageupload". I would love to be able to use tokens in the path configuration (in the same manner as the "FileField Paths" module permits). It would be great if node tokens can be used (nid or any other node id-based tokens defined personally).
A thing that we need to consider before proceeding is this:
Would the nid already be available before submitting the node ?!
Let us say that I proceed to create new content: e.g. "node/add/story" and I add an image using the WYSIWYG button. Where would the file be uploaded ?! There is no nid yet ?!
We need to answer this before we continue.
Comments
#1
Update:
It looks like that the image files get uploaded to the server (to their intended paths) already before the new node is saved.
I suspect that there is no node id available already before submitting the node for the first time.
Two options:
- Making it possible to delay the upload process to the time of node submission. or
- Save node for the first time and then start uploading images.
#2
The second case is pretty much work. You will upload the files beforehand ( thats the case anyway ) and will need to move them arround afterwards ( using the e.g. nid as token ).
Please make this completely optional, as it makes the whole story a lot more complicated.
#3
You mean to move the files already during the process of saving the node for the first time ?! I am not sure how to do that. I don't know at what stage the nid will become available during that process. Where to put the code, which file ?
For now, I have relied alternatively on placing the files according to yyyy/mm/dd (current time). I have defined a normal php variable as Y/m/d/ and then attached it to $dest on line 64 (wysiwyg_imageupload.file.inc).
Works fine. It will look more logical than being based on node id's like these:
/00/02/55
for node number 255. for example.
BTW: impressing! I mean all the nice look, imagecache integration, styles, paths. It must be ported to SEVEN and EIGHT!
#4
Well iam not sure what you are doing currently, but token support means, you have all tokens available in that context. Can be the current data, user, username, sitename whatever tokens you have for.
You always have the nid in the nodeapi "update" hook, thats were you will need to move them arround.
#5
Thanks for the valuable information that is needed for further development. I am going, with God's will, to look into this later.
#6
I needed node type specific file paths for a project I am working on so I have taken a stab at filefield_paths token integration. Attached is a submodule that will get this working. It needs some work though.
What this does:
Adds a config fieldset on each node type for setting filefield_paths settings for that node type (WYSIWYG Image Upload Paths Settings). If ffp settings are not enabled for that node type the default WYSIWYG image upload settings will be used. Actually, the default WIU settings are alwaysed used, my module just moves the file from that directory after the node is saved.
FFP and WIU do the bulk of the work here, I just tapped into their APIs with a few hooks. There is not much code.
Some issues I'm still trying to work out:
1. There is an issue with the input filter cache. On save of the node, the file IS moved into the correct ffp directory, but it appears that the input filter cache is written first and the image path in the html is the imagecached file from the original path. This goes away once you clear your cache and it's served form the new, correct directory.
2. Due to the order in which some of the hooks execute, you need to manually change the module weight of ffp and this module. On my local install I have fpp set to 40 and this module to 30. More on this here: http://drupal.org/node/641252 and here: http://drupal.org/node/635854
3. One of the issues I came across was, since with WIU you can reuse a file in other nodes, and ffp uses node data for the path, what to do with the path when an image is in multiple nodes. In this case, when there are duplicate fid references in the entities table, I decided to only move or rewrite filenames if the iid is the lowest of all the duplicates. Meaning that this was the original node it was inserted into and should derive its path from that nodes data.
I hope someone finds this useful. Or may even help in testing or fixing bugs. :)
Thanks.
#7
Great contribution, thanks! Iam currently high on load, maybe someone else can test this=
#8
I think I've sorted out the input filter cache issue. This actually addresses 1 and 2 above.
Attached is a new module.
- I've added an install file which will set the weights of FFP and my module (WIUP)
to 40 and 41 respectively so the hooks execute in the order needed.
- I also am calling _wysiwyg_imageupload_reset_filter_cache() from hook_nodeapi() insert and update ops.
this however, is now called twice, once in the core WIU module and once here, so the filter cache actually gets built twice. I couldn't find another way to do it. Maybe we can check in WIU if this mod is installed and skip its cache clearing?
It seems to work on my local installation. Will keep you posted on anything I find, and would also love to hear some feedback once someone gets a chance to give it a spin.
Thanks again for this great mod, with this addon it's perfect for my project.
#9
I dont understand why we need that kind of a huge implementation for toke support?
All we need is running this before saving / moving the file to the destination + creating the folder if it is not there yet
<?phptoken_replace($original, $type = 'global', $object = NULL,
$leading = '[', $trailing = ']')
?>
In any case.
Could you please reroll the patch with proper code-styles ( coding module ) - would be awesome.
#10
An absolutely great addition, thank you!
#8 works just as intended for me.
The only potential problem I have discovered so far is if I try to organise the images into dynamically created directories, e.g. with tokens like "[nid]/[filefield-onlyname-original].[filefield-extension-original]".
This throws up two errors:
file system
"The selected file sites/default/files/wysiwyg_imageupload/myimage.jpg could not be uploaded, because the destination could not be found, or because its permissions do not allow the file to be written."
filefield_paths
"FileField Paths failed to move file (sites/default/files/wysiwyg_imageupload/myimage.jpg) to (images/64603/64603/myimage.jpg)."
This could be a permission problem, but I noticed that the nid (64603) is used TWICE in the latter path, and should only be once (it creates the path sites/default/files/images/64603 just fine, but doesn't move the image there). Everything works fine if I use tokens like "[nid]-[filefield-onlyname-original].[filefield-extension-original]", i.e. don't create any directories.
Anyway , thought you would want to know :)
Thanks again!