Looking through the forum there are appears to be an ongoing issue with teasers and nodes that have php code:

http://drupal.org/node/22040
http://drupal.org/node/18836

At this point in Drupal 4.6.x, it appears that the use of teasers with php nodes is still disabled. To get around this, I have disabled the php teaser filter in the node.module by commenting it out, and wonder if this was an advisable thing to do:

<code>
// We check for the presence of the PHP evaluator filter in the current                  
  // format. If the body contains PHP code, we do not split it up to prevent               
  // parse errors.                                                                         
//  if (isset($format)) {                                                                  
//    $filters = filter_list_format($format);                                              
//    if (isset($filters['filter/1']) && strpos($body, '<?') !== false) {                  
//      return $body;                                                                      
//    }                                                                                    
//  }     


I seldom use teaser with nodes that have php in them (most of the php I use in nodes calls Adsense includes). But need to use teasers to occasionally remove large chunks of preformatted code from front pages.

Am I setting myself up for unforseen problems by commenting out this php filter in node.module?

Comments

Simon Pole’s picture

Sorry, that post was truncated by characters in the quoted php. Here's what it should have been:

Looking through the forum there are appears to be an ongoing issue with teasers and nodes that have php code:

http://drupal.org/node/22040
http://drupal.org/node/18836

At this point in Drupal 4.6.x, it appears that the use of teasers with php nodes is still disabled. I have disabled the php teaser filter in the node.module by commenting it out, and wonder if this was an advisable thing to do:

// We check for the presence of the PHP evaluator filter in the current                  
  // format. If the body contains PHP code, we do not split it up to prevent               
  // parse errors.                                                                         
//  if (isset($format)) {                                                                  
//    $filters = filter_list_format($format);                                              
//    if (isset($filters['filter/1']) && strpos etc.
//      return $body;                                                                      
//    }                                                                                    
//  }     

I seldom use teaser with nodes that have php in them (most of the php I use in nodes calls Adsense includes). But need to use teasers to occasionally remove large chunks of preformatted code from front pages.

Am I setting myself up for unforseen problems by commenting out this php filter in node.module?

jsbthree’s picture

I'm slightly confused by it when you say you use teasers to remove preformated content. Can you give an example?

Simon Pole’s picture

Sorry, I should have been clearer.

Basically, I like to post bash shell scripts on the blog section of my Drupal website (using the "pre" -- preformatted tag) to surround the block of code. I don't necessary want a visitor on the blog "main page" to see this huge chunk of code though, so using the teaser "break" just before the script in the node removes it from the main page, and the reader has to click "read more" to see it.

From the links above, it looks like the node.module disables the teaser when it comes to php-enabled nodes that include "pre" and "code" tags. From what I read at the links, this seems to have been done to avoid problems parsing the "sample" code as real php.

Stupendous Tales
Speculative Fiction, Pulp Dreams

TurtleX’s picture

Maybe this will help - http://drupal.org/node/34315

Simon Pole’s picture

Thank you for the pointer. In the link, it looks a second teaser break "phpbreak" is created -- that is used only for php-coded nodes.

I can see this being very useful where you wanted to keep the two types of breaks separate.

If there was no need to keep them separate though -- if you only had one or a few users creating content -- wouldn't it be easier just to remove or comment out the php filter in node.module? That way, the standard "break" could be used for all types of nodes.

Stupendous Tales
Speculative Fiction, Pulp Dreams

twohills’s picture

The following code change to node.module seems to work fine. Simply replace one line as indicated

  if (isset($format)) {
    $filters = filter_list_format($format);
    if (isset($filters['filter/1']) && strpos($body, '<?') !== false) {
//      return $body;                                                                        // -
      $body = preg_replace( '#<?+^(?>)?>#' , '' , $body);                       //+
    }
  }

Instead of using the whole body as a teaser, and annoyingly leaving the <!--break--> in the text of the teaser, all that is required is to strip out any PHP code from the teaser, then continue through to the following code.

The only limitation of this that i can see is that if you have PHP code modifying the look and feel of the first part of the node that appears in the teaser, then the teaser is going to be the "default" version with no PHP code working.

One of you PHP aces might light to check my regular expression syntax but it works for my test cases.