On importing Serialized flexifilter code, I get the error message:
warning: Invalid argument supplied for foreach() in /www/public_html/sites/all/modules/flexifilter/flexifilter.module on line 550.

Here's how:

  1. Add new flexifilter
  2. Enter Label: test
  3. Enter Description/filter tips: Test Description
  4. Create (which is successful)
  5. Edit test
  6. Click export, and select the Serialized flexifilter (for manual imports):
    a:9:{s:5:"label";s:4:"Test";s:11:"description";s:16:"Test Description";s:2:"id";s:1:"3";s:7:"enabled";b:1;s:8:"advanced";b:0;s:5:"delta";s:1:"1";s:5:"cache";s:1:"1";s:10:"components";a:2:{s:7:"id_next";i:32;s:9:"id_prefix";s:22:"flexifilter_component_";}s:3:"fid";s:3:"new";}
  7. Delete test filter
  8. Click Import a flexifilter
  9. Paste Serialized flexifilter code, and click import, produces the error:
    warning: Invalid argument supplied for foreach() in /www/public_html/sites/all/modules/flexifilter/flexifilter.module on line 550.

Comments

bigjim’s picture

had the same problem

with this simple filter

a:9:{s:5:"label";s:6:"simple";s:11:"description";s:22:"simple shortcuts";s:2:"id";s:1:"2";s:7:"enabled";b:1;s:8:"advanced";b:0;s:5:"delta";s:1:"1";s:5:"cache";s:1:"1";s:10:"components";a:4:{i:0;a:3:{s:5:"class";s:24:"flexifilter_text_replace";s:8:"settings";a:3:{s:4:"find";s:3:"d.o";s:7:"replace";s:10:"drupal.org";s:4:"step";s:7:"process";}s:2:"id";s:2:"30";}i:1;a:3:{s:5:"class";s:24:"flexifilter_text_replace";s:8:"settings";a:3:{s:4:"find";s:4:"civi";s:7:"replace";s:7:"CiviCRM";s:4:"step";s:7:"process";}s:2:"id";s:2:"31";}s:7:"id_next";i:32;s:9:"id_prefix";s:22:"flexifilter_component_";}s:3:"fid";s:3:"new";}

iantresman’s picture

I've also tried importing the corrected Link Formatting example, and the "Swear Filter" further down the page, and get the same error message.

Perhaps it is also worth mentioning that the page on which this error is displayed is:
admin/build/flexifilters/a/edit
...and also shows "page not found".

I'm running PHP 5.2.13 (with 48M memory limit) with mySQL 5.0.77.

ibaal’s picture

Same problem here.
The problem seems to be improper/missing unserialzation of the filter. Resulting in the foreach loop getting a string when it actually wants an array/list/whatever. I added $filter = unserialize($filter); as the first line of function flexifilter_save_filter($filter). (the function starts at line 490). I haven't studied the code enough to have any opinion if this is the proper place to add unserialization, but it seems to work for me.

sin’s picture

#3 works for importing:
MediaWiki Extended filter http://drupal.org/sandbox/risca/1200940

Just comment it out after import.

madmanmax’s picture

For those who get the error message:
It appears that the serialized flexifilter you entered was improperly formed. Please check the source.

The problem is that it tries to unserialize the import string but it fails. Your most likely candidate is if you have a big chunk of string but the string count is wrong. Example if you're trying to import the MediaWiki Extended filter my count was wrong for the code part.

How to find the right count? For the sake of example we'll assume the number of chars is invalid (5 instead of 4).

  • select only the piece of string that you think it's the culprit e.g. s:5:"step";
  • use var_dump which will return the number of characters (in this case 11)
  • now just deduct the number of characters outside the quotes (in this case 7)
  • finally you get the real number of chars: 4

If you passed this but instead get to a page not found: Page not found The requested page could not be found. and the link points to /admin/build/flexifilters/a/edit.
Solution: mentioned in comment 3.

// @file: flexifilter.module
function flexifilter_save_filter($filter) {
  /* Add this as the first line! */
  $filter = unserialize($filter);
  
  /* **********************
  * Rest of the code remains the same
  ********************** */
}

sdsheridan’s picture

Issue summary: View changes

Actually, i think the issue is in how the function gets called on import. The unserialisation is already done in the submit function for the import form, but then the serialised string is passed to the function flexifilter_save_filter() instead of the already unserialised array. The change should probably be in the function flexifilter_filter_input_form_submit() in file flexifilter.admin.inc as follows (with better-named variables):

function flexifilter_filter_input_form_submit($form, &$form_state) {
  $filter = unserialize($form_state['values']['flexifilter']);
  if ($filter) {
    drupal_goto('admin/build/flexifilters/' . flexifilter_save_filter($filter) . '/edit'); //PATCHED to permit importing properly
  }
  else {
    drupal_set_message(t('It appears that the serialized flexifilter you entered was improperly formed. Please check the source.'), 'error');
  }
}

And, if we want to get closer to Drupal coding standards, then we shouldn't be using a drupal_goto() call here (as that aborts any other submit handlers that may come after this one), but rather setting $form_state['redirect']. And while we're at it, a confirmation message would be nice too:

function flexifilter_filter_input_form_submit($form, &$form_state) {
  $filter = unserialize($form_state['values']['flexifilter']);
  if ($filter) {
    $form_state['redirect'] = 'admin/build/flexifilters/' . flexifilter_save_filter($filter) . '/edit'; //PATCHED to permit importing properly, and to adhere to Drupal standards around the Form API.
    drupal_set_message(t('Filter %name imported.', array('%name' => $filter['label'],)));
  }
  else {
    drupal_set_message(t('It appears that the serialized flexifilter you entered was improperly formed. Please check the source.'), 'error');
  }
}

Shawn