You are here

function codefilter_filter in Code Filter 5

Same name and namespace in other branches
  1. 6 codefilter.module \codefilter_filter()

Implementation of hook_filter()

File

./codefilter.module, line 114

Code

function codefilter_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(
        0 => t('Code filter'),
      );
    case 'description':
      return t('Allows users to post code verbatim using <code> and <?php ?> tags.');
    case 'prepare':

      /* Note: we replace <code> </code>, <?php ?>, [?php ?], <% %>, and [% %]
         to prevent other filters from acting on them. */
      $text = preg_replace('@<code>(.+?)</code>@se', "codefilter_escape('\$1', 'code')", $text);
      $text = preg_replace('@[\\[<](\\?php|%)(.+?)(\\?|%)[\\]>]@se', "codefilter_escape('\$2', 'php')", $text);
      return $text;
    case 'process':
      $text = preg_replace('@\\[codefilter_code\\](.+?)\\[/codefilter_code\\]@se', "codefilter_process_code('\$1')", $text);
      $text = preg_replace('@\\[codefilter_php\\](.+?)\\[/codefilter_php\\]@se', "codefilter_process_php('\$1')", $text);
      return $text;
    default:
      return $text;
  }
}