Download & Extend

Code Filter is not compatible with PHP filter

Project:Code Filter
Version:6.x-1.0
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work

Issue Summary

Discovered by Ryan in: http://drupal.org/node/190751#comment-694290

If you are using the php filter, codefilter will style the <?php ?> code blocks and won’t let php filter execute the php code in that block.

The reason for this is that codefilter uses the input filtering 'prepare' operation to convert <?php ?> blocks into [codefilter-php] blocks. While this prevents html filter from improperly styling the code, it also prevents php filter from executing the php.

Codefilter already has support for [?php ?] blocks that will get syntax highlighting. So we just have to figure out how to get php filter to execute the <?php ?> before the input filtering 'prepare' operation.

Comments

#1

I'm having this problem too. If I change the input format to PHP everything is correct, but then there is no codefilter in that format.

#2

Subscribing.

I'd really like for this to work.

#8

Priority:normal» minor

Spam posting will get you nowhere Extra posts were deleted.

#9

Spam will get me nowhere, hein? (what a let down).

One cannot delete one's posts here. My posts were 'damaged' by use of brackets with keyword 'php'. Like John said, they are implemented -- there is filtering done using brackets with 'php' -- although it's not documented. I simply cleared my posts since I could not delete them. I also submitted a patch, which, essentially, moved the 'prepare' stage code to a later stage, it fixed the problem at hand but broke other things. I recommend using the geshi module, Nancy, if you want to put php code in your nodes and still be able to provide code highlighting. It works with that other module.

#10

Priority:minor» normal

Ah, but I believe Geshi has problems with Glossary, which I maintain.

Sorry about the spam stuff. That's what it looked like to me. The webmasters got them deleted.

#11

Aehm, I don't really get why this is to problematic to solve: if the code filter module supports [?php ?] for styling php code, isn't that enough? Can't we just ignore the <?php ..?> tags then?

#12

I recommend using <php></php> for code highlighting.

#13

Of course, it's vain to wish for that. All previously submitted content would have to be updated.

I have moved away from Code Filter on my own site and married the geshi module.

#14

Oh, of course...

So what about a configurable option to let the admin chose if php tags should be captured or not? That would at least allow new sites to turn of the php tags.

#15

any updates on this?

#16

Version:5.x-1.x-dev» 6.x-1.0
Status:active» needs review

I think, it's possible make some checks on prepare stage. We check that phpfilter will used in current format and before codefilter. If it used before we will process only [?php ... ?] and will ignore <?php ... ?>.
This is solution:
Replace 'prepere' stage by:

<?php
case 'prepare':
     
$backtrace = debug_backtrace();
     
//dpm($backtrace);
     
$format = -1;
      foreach (
$backtrace as $function_call) {
                if (
$function_call['function'] == 'check_markup') {
                   
$format = $function_call['args'][1];
                }
            }
           
$codefilter=false;
           
$phpfilter=false;
            if(
$format!=-1){
               
$filters = filter_list_format($format);
                foreach (
$filters as $filter) {
                    if(
$filter->module=="codefilter"){
                       
$codefilter=true;
                    }else    if(
$filter->module=='php'&&!$codefilter){
                       
$phpfilter=true;
                    }
                }
            }
     
$text = preg_replace('@<code>(.+?)</code>@se', "codefilter_escape('$1', 'code')", $text);
     
$text = preg_replace('@[\[](\?php|%)(.+?)(\?|%)[\]]@se', "codefilter_escape('$2', 'php')", $text);
      if(!
$phpfilter){
         
$text = preg_replace('@[\<](\?php|%)(.+?)(\?|%)[\>]@se', "codefilter_escape('$2', 'php')", $text);
      }
      return
$text;
?>

Or maybe better ignore <?php ... ?> with out checking filter sequence?

#17

Title:php filter incompatible with codefilter» Code Filter is not compatible with PHP filter

I am not sure there are sites where the PHP filter and Code Filter are both enabled in the same input format.
Clearly the input filters conflict with each other as PHP filter tries to execute what Code Filter tries to highlight; plus, Code Filter preprocesses the text, and this doesn't allow to the PHP filter to execute the code.

#18

Status:needs review» needs work

<?php
      $backtrace
= debug_backtrace();
     
//dpm($backtrace);
     
$format = -1;
      foreach (
$backtrace as $function_call) {
                if (
$function_call['function'] == 'check_markup') {
                   
$format = $function_call['args'][1];
                }
            }
?>

$format is passed as parameter to hook_filter(); that code is not necessary.

<?php
 
if($filter->module=="codefilter"){
   
$codefilter=true;
  }
?>

As the code is being executed from Code Filter, there is no reason to check if the module is being executed.

nobody click here