Hi,
Thanks for the module, seems to be a good idea...

When I'm using it, I get an error

warning: Invalid argument supplied for foreach() in C:\wamp\www\panels10\sites\all\modules\customfilter\customfilter.module(1004) : runtime-created function on line 5.

Comments

arhip’s picture

Hi. May I know when the error raised? It seems the error is in the filter (runtime created function), not the module. Can you attach the filter being used? And the sample input of course.

Thanks.

arhip’s picture

The error raises because of TOC filter, it has a line like this (line 5):

  foreach ($vars->headings as $heading) {

When there is no heading at all, this line will raise an error, since $vars->headings doesn't have value. Solution, you can change the TOC filter replacement code with this:

if (is_array($vars->headings) && count($vars->headings) > 0) {
  $result = '<div>';
  $result .= '<h2>Table of contents</h2>';

  $lastlevel = 0;
  foreach ($vars->headings as $heading) {
    if ($heading['level'] > $lastlevel) {
      for ($i = $heading['level']; $i > $lastlevel; $i--) {
        $result .= '<ol>';
       }
     }
    elseif ($heading['level'] < $lastlevel) {
      for ($i = $heading['level']; $i < $lastlevel; $i++) {
        $result .= '</li></ol>';
       }
     }
    else {
      $result .= '</li>';
     }

    $result .= "<li><a href=\"#{$heading['anchor']}\">{$heading['text']}</a>";
    $lastlevel = $heading['level'];
   }

  for ($i = 0; $i < $lastlevel; $i++)
    $result .= '</li></ol>';

  $result .= '</div>';
 }
else
  $result = '';

return $result;

Difference is, the new code checks first if there is array named $vars->headings, and check whether this array contains at least one element (the real MediaWiki will generate TOC when headings >= 4).

avpaderno’s picture

Category: bug » support
Status: Active » Fixed

The reported code comes from the filter sample that can be imported from customfilter_sample.xml. It's a sample filter that can be modified from the user, and it is given only like example of filters that can be created with this module.

I am setting the report as fixed because it got an answer.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.