special filter behavior for teaser
I have a client using img_assist to add inline images. They want thumbnails of images to appear in teaser views, and larger images to appear when the entire node body is shown. Others have requested the same sort of thing here: http://drupal.org/node/107801. I was hoping to accomplish this by hacking the img_assist filter to change its behavior when a teaser is being generated as opposed to a full body. But this information (whether a teaser is being generated or not) is not available in hook_filter. Is there any way for me to accomplish this? I cannot think of a clean way so I wonder, should more parameters be passed to the check_markup and hook_filter functions? Apologies if this is a FAQ, and thanks for any advice, -Dave
Is there any way for me to accomplish this? I cannot think of a clean way so I wonder, should more parameters be passed to the check_markup and hook_filter functions?
This has been proposed many times and the past and has been rejected so far: the point of the filter system is to translate markup. In order for it to work in all situations, it must be agnostic about its context. Sure, some things could be hacked in if we pass in a node or comment, but there are already other mechanisms in place that are much better for this. Nodeapi offers plenty of opportunities for altering nodes, especially now that node output is structured. Steven Wittens
They want thumbnails of images to appear in teaser views, and larger images to appear when the entire node body is shown.
The best way IMO is to use CCK and imagefield/imagecache. Then you have an "image" field and can call a different imagecache preset in your node-content_whatever.tpl.php file when $teaser is true/false. This is what I have used in the past for this functionality and works quite well. If you need to use img_assist (using inline images), you could do this in hook_nodeapi() as Steven says and shrink down any images, but this method is a bit clunkier. Rob Roy Barreca Founder and COO Electronic Insight Corporation http://www.electronicinsight.com rob@electronicinsight.com Dave Cohen wrote:
I have a client using img_assist to add inline images. They want thumbnails of images to appear in teaser views, and larger images to appear when the entire node body is shown. Others have requested the same sort of thing here: http://drupal.org/node/107801.
I was hoping to accomplish this by hacking the img_assist filter to change its behavior when a teaser is being generated as opposed to a full body. But this information (whether a teaser is being generated or not) is not available in hook_filter.
Is there any way for me to accomplish this? I cannot think of a clean way so I wonder, should more parameters be passed to the check_markup and hook_filter functions?
Apologies if this is a FAQ, and thanks for any advice,
-Dave
Op dinsdag 6 februari 2007 08:19, schreef Rob Barreca:
The best way IMO is to use CCK and imagefield/imagecache. Then you have an "image" field and can call a different imagecache preset in your node-content_whatever.tpl.php file when $teaser is true/false. This is what I have used in the past for this functionality and works quite well.
No. We have two ways in general: inline, and metadata. What you propose is metadata, what Dave wants/needs is inline. Lets not confuse the two. The camp that want the node/comment/foobar objects to be passed to the filter have so far lost the battle (see Stevens comment) for good reasons (IMO). But. Right now, you see all the more advanced filters being implemented as _nodeapi, and not as filters. A bad, bad result, IMO. Much worse then the argument of 'clean implementation'. We see (rather popular) modules such as inline.module being real performance drainers on your site. Also the filter tips can no longer be used properly, and you don't ave the filter available in filter settings. I think that Dave is best off using that method too, here. Its unfortunate, its a performance problemn, and the interface becomes clumsy (filter tips cannot be reused etc) but at least it works. ;) Look for an example at inline module. http://drupal.org/project/inline Bèr -- Drupal, Ruby on Rails and Joomla! development: webschuur.com | Drupal hosting: www.sympal.nl
No. We have two ways in general: inline, and metadata. What you propose is metadata, what Dave wants/needs is inline. Lets not confuse the two.
Correct, that's why I added this footer to my original message. Just wanted to throw the metadata approach out there in case he wasn't aware of it.
If you need to use img_assist (using inline images), you could do this in hook_nodeapi() as Steven says and shrink down any images, but this method is a bit clunkier. In terms of the performance issues, the image regeneration could be in a form_alter #submit handler before node_submit() fires and then the processed teaser would overwrite Drupal's generated teaser allowing us to cache the resized image teaser. Or, am I missing something?
From node_submit(): <?php // Auto-generate the teaser, but only if it hasn't been set (e.g. by a // module-provided 'teaser' form item). if (!isset($node->teaser)) { $node->teaser = isset($node->body) ? node_teaser($node->body, isset($node->format) ? $node->format : NULL) : ''; } ?> Rob Roy Barreca Founder and COO Electronic Insight Corporation http://www.electronicinsight.com rob@electronicinsight.com Bèr Kessels wrote:
Op dinsdag 6 februari 2007 08:19, schreef Rob Barreca:
The best way IMO is to use CCK and imagefield/imagecache. Then you have an "image" field and can call a different imagecache preset in your node-content_whatever.tpl.php file when $teaser is true/false. This is what I have used in the past for this functionality and works quite well.
No. We have two ways in general: inline, and metadata. What you propose is metadata, what Dave wants/needs is inline. Lets not confuse the two.
The camp that want the node/comment/foobar objects to be passed to the filter have so far lost the battle (see Stevens comment) for good reasons (IMO).
But.
Right now, you see all the more advanced filters being implemented as _nodeapi, and not as filters. A bad, bad result, IMO. Much worse then the argument of 'clean implementation'.
We see (rather popular) modules such as inline.module being real performance drainers on your site. Also the filter tips can no longer be used properly, and you don't ave the filter available in filter settings.
I think that Dave is best off using that method too, here. Its unfortunate, its a performance problemn, and the interface becomes clumsy (filter tips cannot be reused etc) but at least it works. ;) Look for an example at inline module. http://drupal.org/project/inline
Bèr
Thanks for the feedback, everyone. Since my interest is with inline images, placed with img_assist, in drupal 4.7, I came up with this snippet which is working so far... function custom_nodeapi(&$node, $op, $a3, $a4) { if ($op == 'view') { // For teasers, show thumbnails, not full images if ($a3) { //drupal_set_message("custom_nodeapi($op)" . dpr($node->teaser, 1)); // modify the img tags inserted by img_assist $teaser = preg_replace('/<img src="([^"]*)\.([^\."]*)\.([^\."]*)" ([^>]*) class="image ([^"]*)"([^>]*)>/', '<img src="$1.thumbnail.$3" $4 class="image thumbnail" />', $node->teaser); //drupal_set_message("new teaser: " . dpr($teaser, 1)); $node->teaser = $teaser; } } } Will post the same to the drupal forum. -Dave On Monday 05 February 2007 05:05, Dave Cohen wrote:
I have a client using img_assist to add inline images. They want thumbnails of images to appear in teaser views, and larger images to appear when the entire node body is shown. Others have requested the same sort of thing here: http://drupal.org/node/107801.
I was hoping to accomplish this by hacking the img_assist filter to change its behavior when a teaser is being generated as opposed to a full body. But this information (whether a teaser is being generated or not) is not available in hook_filter.
Is there any way for me to accomplish this? I cannot think of a clean way so I wonder, should more parameters be passed to the check_markup and hook_filter functions?
Apologies if this is a FAQ, and thanks for any advice,
-Dave
participants (4)
-
Bèr Kessels -
Dave Cohen -
Rob Barreca -
Steven Wittens