This is a list of plugins for the Feeds Tamper contributed module.

Date/time

String to Unix timestamp

Take a string containing an English date format and convert it into a Unix Timestamp. See the PHP Manual on strtotime for examples of valid strings.

Unix timestamp to Date

Converts a Unix timestamp to a date string using PHP's date() function.

Filter

Keyword filter

Only import (or do not import) items that contain a list of specific words/phrases

Required field

Make this field required. If it is empty, the feed item will not be saved.

HTML

HTML entity decode

Convert all HTML entities such as & and " to & and ".

HTML entity encode

Convert all HTML special characters such as > and & to > and &.

Make URLs absolute

Make URLs in markup absolute. (i.e. <a href="/stuff/things"> to <a href="http://example.com/stuff/things">).

Strip tags

Remove all HTML tags except a user-specified list.

List

Explode

Break up sequenced data into an array with the option of setting a limit to the number of items returned. For example, "a, b, c" would get broken up into the array('a', 'b', 'c').

Filter empty items

If there are no values for a multi-valued field this plugin removes the empty row for this field. Else labels will show up even though there aren't any values for it.

Implode

Join array elements into a string using an user-specified "glue". For example, array('a', 'b', 'c') with glue "," would become "a, b, c".

Unique

Makes the elements in a multivalued field unique.

Number

Cast to integer

Convert a user-specified string to an integer.

Format a number

Add a user-specified number of decimal places, decimal point, and thousands separator.

Mathematical operation

Add, subtract, multiply or divide a number.

Other

Calculate hash

Makes the value a hash of the values being imported. This allows for importing content that does not have a unique ID.

Copy source value

Copy the selected source to or from another source in the feed.

Country to ISO code

Converts a field from a country name string to the two character ISO Alpha-2 code.

Entity Field Query finder

Searches for an entity based on a property or field of that entity and returns the entity id.

Full U.S. state name to abbrev.

Converts a string from a U.S. full state name name string to the two character abbreviation. For example, "alabama" will be converted to "AL".

Rewrite

Rewrite the source using token-based replacement. Each source in the feed is available as a token and available to append or reorder into a single string.

Example: [sku] is a number and a image string can be created from it.
http://example.com/sites/all/files/images/[sku].jpg

Set default value

Set a static default value for the field.

Text

Convert case

Convert to "Title Case", "lower case", or "UPPER CASE".

Convert to boolean

Convert a user-specified string to boolean, with the option of specifying what to do in the case of no match.

Find replace

Find and replace a user-specified word/phrase.

Find replace REGEX

Find and replace a user-specified string using REGEX with an option to limit the number of replacements. See the PHP Manual on PCRE Pattern Syntax for a complete reference, or RegexPal for a quick tester.
NB: Regex syntax must enclosure by "/"
Example: /[^a-Z]/
Field Tamper Regex

Format string

Formats a string using PHP's sprintf() function.

Pad a string

Increase the length of a string to a minimum value using a user-specified string on the right, left, or both sides.

Trim

Trim a user-specified string from the left, right, or both sides of the source.

Truncate

Limit the source to a user-specified number of characters, with the option of adding ellipses to the end of the truncated text.

URL Decode

Decodes an URL-encoded string using PHP's urldecode() function.

URL Encode

URL-encodes a string using PHP's urlencode() function.

AttachmentSize
drupal field tamper plugin regex.png38.76 KB

Comments

miltonsp’s picture

The 'Convert to boolean' plug-in does not work out-of-the-box in Drupal 7.
Here is a small patch to make it work.

Index: .../feeds/feeds_tamper/plugins/convert_boolean.inc
===================================================================
--- ... /feeds/feeds_tamper/plugins/convert_boolean.inc	
+++ ... /feeds/feeds_tamper/plugins/convert_boolean.inc	
@@ -79,11 +79,11 @@
     $match_field = drupal_strtolower($match_field);
   }
   if ($match_field == $settings['true_value']) {
-    $field = TRUE;
+    $field = 1;
     return;
   }
   if ($match_field == $settings['false_value']) {
-    $field = FALSE;
+    $field = 0;
     return;
   }
   if ($settings['no_match'] == 'pass') {

This has been fixed in version 7.x-1.x-dev.

FiNeX’s picture

@miltonsp: hi, you should fill a bug report in order to get it fixed.

Thanks for the support!

spanac’s picture

Thanks, that worked for Boolean values :)

eliaspallanzani’s picture

will be usefull

leewoodman’s picture

How do i reference the "Copy source value" in another plugin on the same field? i want to copy the RSS description field into two targets. 1 target for field_body and 1 target for field_image. I want to copy source value to field_image and then using Feeds Tamper PHP run a REGEX to extract a jpg image from field_body to use in field_image.
thanks
lee

miltonsp’s picture

At times, you may want the output of a field to be dependent on another field. That is, if the controlling field is 'false', the current field output should be blank.

The 'dependency' plugin will allow you to select the controlling field.

Here is the code for dependency.inc :

<?php

/**
 * @file
 * Dependency of field value on another field that returns a boolean value. 
 * If the dependent field is false or null, then blank output of current field.
 */

$plugin = array(
  'form'     => 'feeds_tamper_dependency_form',
  'callback' => 'feeds_tamper_dependency_callback',
  'name'     => 'Dependency',
  'multi'    => 'skip',
  'category' => 'Text',
);

function feeds_tamper_dependency_form($importer, $element_key, $settings) {
  $form = array();
  $replace = array();

  foreach (feeds_tamper_get_unique_source_list($importer) as $source) {
    $replace[] = '[' . $source . ']';
  }

  $form['text'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter controlling field (Select only one from the list of Available Dependant Fields)'),
    '#description' => t('Choose controlling field. If that field is false the output of the current field will be empty. Copy and paste one of the fields below into this text box.'),
    '#size' => 40,
    '#default_value' => isset($settings['text']) ? $settings['text'] : '',
  );
  $form['help'] = array(
    '#type' => 'fieldset',
    '#title' => t('Available Dependant Fields'),
    '#description'  => t('Choose one of these fields as the controlling field. If "false", the base field will produce a null output. Copy and paste one of the fields below into the text box above.'),
    '#collapsed' => FALSE,
    '#collapsible' => FALSE,
    '#value' => theme('item_list', array('items' => $replace)),
  );
  return $form;
}

function feeds_tamper_dependency_callback($result, $item_key, $element_key, &$field, $settings, $source) {

  $item = $result->items[$item_key];
  foreach ($item as $key => $value) {
    if ('[' . $key . ']' == $settings['text']) {    
      $field_dependency = $value;
      break;
    }
  }
  
  $field = ($field_dependency == 'false' || !$field_dependency) ? "" : $field;
}

To install this code, encapsulate this code in 'dependency.inc' and place it in the feeds_tamper/plugins/ directory.

miltonsp’s picture

diff -rupN feeds_tamper/plugins/dependency.inc new/plugins/dependency.inc
--- feeds_tamper/plugins/dependency.inc	1969-12-31 19:00:00.000000000 -0500
+++ new/plugins/dependency.inc	2014-06-02 14:14:17.000000000 -0400
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * @file
+ * Dependency of field value on another field that returns a boolean value. 
+ * If the dependent field is false or null, then blank output of current field.
+ */
+
+$plugin = array(
+  'form'     => 'feeds_tamper_dependency_form',
+  'callback' => 'feeds_tamper_dependency_callback',
+  'name'     => 'Dependency',
+  'multi'    => 'skip',
+  'category' => 'Text',
+);
+
+function feeds_tamper_dependency_form($importer, $element_key, $settings) {
+  $form = array();
+  $replace = array();
+
+  foreach (feeds_tamper_get_unique_source_list($importer) as $source) {
+    $replace[] = '[' . $source . ']';
+  }
+
+  $form['text'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Enter controlling field (Select only one from the list of Available Dependant Fields)'),
+    '#description' => t('Choose controlling field. If that field is false the output of the current field will be empty. Copy and paste one of the fields below into this text box.'),
+    '#size' => 40,
+    '#default_value' => isset($settings['text']) ? $settings['text'] : '',
+  );
+  $form['help'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Available Dependant Fields'),
+    '#description'  => t('Choose one of these fields as the controlling field. If "false", the base field will produce a null output. Copy and paste one of the fields below into the text box above.'),
+    '#collapsed' => FALSE,
+    '#collapsible' => FALSE,
+    '#value' => theme('item_list', array('items' => $replace)),
+  );
+  return $form;
+}
+
+function feeds_tamper_dependency_callback($result, $item_key, $element_key, &$field, $settings, $source) {
+
+  $item = $result->items[$item_key];
+  foreach ($item as $key => $value) {
+    if ('[' . $key . ']' == $settings['text']) {    
+      $field_dependency = $value;
+      break;
+    }
+  }
+  
+  $field = ($field_dependency == 'false' || !$field_dependency) ? "" : $field;
+  // debug
+  // error_log("From " . basename(__FILE__). " line " .__LINE__. ":  \$field_dependency: " .  print_r($field_dependency, 1));
+  // error_log("From " . basename(__FILE__). " line " .__LINE__. ":  \$field: " .  print_r($field, 1));
+
+}

MediaFormat’s picture

For newbs.

Add plugin: Execute php code
PHP Code: return stripslashes($field);

aus007’s picture

Below Mentioned is just a single field . Any experts please suggest , how do I only filter out the BRAND - "ASDA Furniture " from this.

s:947:"O:8:"stdClass":14:{s:7:"Binding";s:14:"Kitchen & Home";s:5:"Brand";s:16:"ASDA Furniture";s:3:"EAN";s:13:"5055721699496";s:7:"EANList";O:8:"stdClass":1:{s:14:"EANListElement";s:13:"5055721699496";}s:7:"Feature";a:5:{i:0;s:68:"APPROX 10 INCH COIL SPRING MEMORY FOAM MATTRESS + 14 INCH DIVAN BASE";i:1;s:57:"12.5 GAUGE SPRING WITH 4CM VISCO MEMORY FOAM LAYER ON TOP";i:2;s:31:"MEETS ALL UK SAFETY REGULATIONS";i:3;s:24:"UK FIRE RETARDANT BS7177";i:4;s:57:"MANUFACTURED BY JOSEPH INTERNATIONAL FOR BED EXPRESS ONLY";}s:5:"Label";s:16:"Joseph Furniture";s:12:"Manufacturer";s:16:"Joseph Furniture";s:5:"Model";s:16:"DLOLMEMBCBRDDB50";s:12:"ProductGroup";s:7:"Kitchen";s:15:"ProductTypeName";s:24:"HOME_FURNITURE_AND_DECOR";s:9:"Publisher";s:16:"Joseph Furniture";s:4:"Size";s:22:"UK King (150 x 200 cm)";s:6:"Studio";s:16:"Joseph Furniture";s:5:"Title";s:88:"DIVAN BED WITH 10 INCH MEMORY FOAM QUILTED MATTRESS - ALL SIZES AVAILABLE (5'0 kingsize)";}";

calebtr’s picture

This looks like serialized PHP. You can use unserialize() to transform it into a stdClass object.

See above for executing PHP.