I looked for another way to retrieve $node because I need it also when a default image is used in a CCK imagefield, i.e. there is no unique image file assigned to the node and the actual imagecache_actions_node_from_filepath fails.

I retrieve the $nid from the referer url; in fact, this is the url of the node that refers to the image (also the default CCK image). I don't know if this is an universal solution that fits well for all cases but it could be added to the actual code.

It works both for sites urls like http://www.yoursite.com/node/17 and http://www.yoursite.com/drupaldir/node/17

Code follows, bye

=== CODE ===
$referer = referer_uri();
$path = parse_url($referer, PHP_URL_PATH);
$elements = explode('/', ltrim($path, '/'));

if($elements[0] == 'node' && is_numeric($elements[1])) {
$nid = $elements[1];
} elseif ($elements[1] == 'node' && is_numeric($elements[2])) {
$nid = $elements[2];
}

return node_load($nid);
=== CODE ===

Comments

dman’s picture

I understand why that could help in a few cases, and is probably just fine for your case, but it's not a generic case when nodes can appear in blocks, views, or teasers. Nor will it survive an imagecache UI 'rebuild derivatives' action.

Doing it this way will work the first time you create a node, assuming that 'save' takes you immediately to 'view' the new node (which is most common), but it's not a data-based action.

I'm interested in how we can solve the actual issue :
"there is no unique image file assigned to the node and the actual imagecache_actions_node_from_filepath fails."
I understand what you mean.
I've not considered how to handle 'default' images from imagefield. That's an odd one. I think there will be issues if two nodes use the same image in that case, surely the first result would be cached and the rest would get the results generated by the first?

mlocatelli’s picture

I use a content type with a CCK image field with a default image set + imagecache actions. If an image is set (uploaded) everything works well. Problems comes when no image is set and the default image is used, and the preset is node dependant, e.g. add the title of the node to the image.
I found 2 issues:
1) imagecache is not able to retrieve the $node, as I posted above
2) the same image is shared among all the nodes, your last point

I think that imagecache will work the right way when issue 2 will be solved.
In fact, I think that issue 2 is not a matter of imagecache: the last do the proper actions because when the default image is used the same url is requested: same url -> same derivative image.

On the other hand, I think that issue 2 is not a matter of CCK image field. In fact, it is a good design choice to share the same image when this is the default image.

Headackes comes when CCK image field + default image + imagecache dynamic/node dependant actions are put together. I think that the proper design choice is to leave both imagecache and imagefield untouched because they just have the proper behavior.

I'll try to achieve the proper "configuration" by means of rules; my plan is to:
1) create a copy of the default image (set in CCK image field) with a unique filename (incremental or nid dependant)
2) set the image field value of the current node to the created image
all when the node is saved and no image has been uploaded by the user.

In this manner the node has a unique image (based on the default image) and the derivative will be unique too.

fietserwin’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

D6 EOL. This module's D6 issues already haven't received any attention for over a year. Closing them all unconditionally now.