Created
December 5, 2012 11:06
-
-
Save asanchez75/4214775 to your computer and use it in GitHub Desktop.
plugin for Feeds Tamper to write php code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Set field to default value. | |
*/ | |
$plugin = array( | |
'form' => 'feeds_tamper_php_form', | |
'callback' => 'feeds_tamper_php_callback', | |
'name' => 'Execute php code', | |
'multi' => 'direct', | |
'category' => 'Other', | |
); | |
function feeds_tamper_php_form($importer, $element_key, $settings) { | |
$form = array(); | |
$form['php'] = array( | |
'#type' => 'textarea', | |
'#title' => t('PHP code'), | |
'#default_value' => isset($settings['php']) ? $settings['php'] : '', | |
'#description' => t('This code will be executed. Use $field as value of this field. Do not use < ?php and ? >. <br />For example, use: return substr($field, 0, 10);'), | |
); | |
return $form; | |
} | |
function feeds_tamper_php_callback($source, $item_key, $element_key, &$field, $settings) { | |
$field = feeds_tamper_php_value($settings['php'], $field); | |
} | |
function feeds_tamper_php_value($code, $field) { | |
ob_start(); | |
$code = eval($code); | |
ob_end_flush(); | |
return $code; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment