You are here

protected static function FeedImport::applyFilter in Feed Import 7

Same name and namespace in other branches
  1. 7.2 feed_import.inc.php \FeedImport::applyFilter()

Filters a field

Parameters

mixed $field: A string or array of strings containing field value

array $filters: Filters to apply

Return value

mixed Filtered value of field

1 call to FeedImport::applyFilter()
FeedImport::createEntity in ./feed_import.inc.php
Create Entity object

File

./feed_import.inc.php, line 732
Feed import class for parsing and processing content

Class

FeedImport
@file Feed import class for parsing and processing content

Code

protected static function applyFilter($field, $filters) {
  $field_param = variable_get('feed_import_field_param_name', '[field]');
  foreach ($filters as &$filter) {
    $filter['#function'] = trim($filter['#function']);

    // Check if function exists, support static functions
    if (strpos($filter['#function'], '::') !== FALSE) {
      $filter['#function'] = explode('::', $filter['#function'], 2);
      if (!method_exists($filter['#function'][0], $filter['#function'][1])) {
        continue;
      }
    }
    else {
      if (!function_exists($filter['#function'])) {
        continue;
      }
    }

    // Set field value
    $key = array_search($field_param, $filter['#params']);
    $filter['#params'][$key] = $field;

    // Apply filter
    try {
      $field = call_user_func_array($filter['#function'], $filter['#params']);
    } catch (Exception $e) {

      // Just report this error. Nothing to handle.
    }
    $filter = NULL;
  }
  return $field;
}