When getting news from yahoo the alt attribute of an image is too long. This makes so that the teaser is trimmed in the middle of the alt attribute and as a consequence it brakes the html output.
My question is, where I need to put the code so that the teaser is passed to the db as i want to. The code I need to insert is this:

$patern = '/alt\=\"(.*?)\"/e';
$node->teaser = preg_replace($patern, "'alt=\"'.substr('$1', 0, 20).'...\"'" , $node->teaser);

but where? I tried to place it in node_template module, before the node_save call but it doesn't work.

Comments

tic2000’s picture

Status: Active » Fixed

I solved this. In leech.module I changed line 2235 from:

    $edit->teaser = ($item->teaser ? $item->teaser : node_teaser($edit->body, isset($edit->format) ? $edit->format : NULL));

to

    $patern = '/alt\=\"(.*?)\"/e';
    $edit->teaser = ($item->teaser ? $item->teaser : node_teaser(preg_replace($patern, "'alt=\"'.substr('$1', 0, 20).'...\"'" , $edit->body), isset($edit->format) ? $edit->format : NULL));
alex_b’s picture

Title: Teaser problem » Teaser gets cut off in a tag
Category: support » bug
Status: Fixed » Postponed (maintainer needs more info)

Hi - sorry, I have to re-open this.

I can't take this code into leech because it is a workaround that appears to fix the issue only in your particular case. When image tags get severed by the node_teaser() function, some other tags might get cut in pieces as well. Making the tag shorter only reduces the probability. Or am I missing something here?

There is some discussion about the latest patch for node_teaser() here: http://drupal.org/node/73910 . If you can verify a bug, your input would be very much appreciated on the Drupal issue tracker.

tic2000’s picture

The fact is like this. I have this html code in the body of a node created by leech:

<p><a href="http://us.rd.yahoo.com/dailynews/rss/china/*http://news.yahoo.com/s/afp/20070411/sc_afp/chinaspacesatellite"><img src="http://d.yimg.com/us.yimg.com/p/afp/20070411/capt.sge.nzo52.110407181555.photo00.photo.default-277x512.jpg?x=70&amp;y=130&amp;sig=cDFQZ7gKZfIgK6Sk3PcT7w--" alt="The launch platform housing a Long March carrier rocket can be seen at the Jiuquan Satellite launch center in Northwestern Gansu province, 2003. China on Wednesday successfully launched an advanced satellite to monitor the world's oceans, the latest effort in the nation's fast developing space programme, state press reported.(AFP/File)" align="left" border="0" height="130" width="70"></a>AFP - China on Wednesday successfully launched an advanced satellite to monitor the world's oceans, the latest effort in the nation's fast developing space programme, state press reported.</p>

Well, this body is trimmed by the teaser in middle of the alt attribute of the image. I don't think the problem is with node_teaser, since it's purpose is to trim text inserted by the user on that site and not content taken from somewhere else. The patches on that pages would shorten the teaser maybe but not necessarily will solve the problem. And in my case sure it won't, cause the image tag it's gone be broken anyway.
I know this is a particular case, and can only happen with images tags and maybe anchors tags to if there is a too long title, but still it's a problem.
What I'd do is to put an option in the setting page of the module so that the user can select if they want that code to do his job or not depending on what content they leech. But this is only my opinion, and the code I posted wasn't intended as a patch, but just a mare solution for people who may encounter the same problem.