Closed (duplicate)
Project:
Feeds Tamper
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
24 Oct 2010 at 17:47 UTC
Updated:
13 Aug 2013 at 22:40 UTC
Jump to comment: Most recent file
Comments
Comment #1
guillaumev commentedHi,
I needed the same functionality and wrote a patch to create it. Attaching it here...
Comment #2
mitchell commentedFYI: Similar discussion in #786208: Support PHP module.
Comment #3
guillaumev commentedCorrecting an issue with my patch...
opensanta > can you explain what this is about ?
Comment #4
mitchell commented@guillaumev: AFAICT, the general sentiment around the community is that enabling the php module opens up unnecessary security holes in Drupal. This is what I was pointing out by linking to the bad_judgement discussion. Another issue with putting code in the database is that it can lead to problems with development, as well as deployment. The convention in this case is to put your custom code in a site specific module along with your other custom functionality. Even more awesome though would be to generalize the functionality that you added and submit it as a patch or another module that everyone can use.
Comment #5
guillaumev commented@opensanta: thanks a lot for the explanation (to be honest I like a lot better your second post with the explanation than the first one, though :-) ). I will create a plugin for the functionality and send it to the Feeds Tamper module in an issue.
So, should this issue be marked as closed (won't fix) ?
Comment #6
architectJpres commentedWhen you say functionality, does this mean only for a specific feature set or "transformation" ?
Does this mean the possibility of using custom php code is not possible?
Comment #7
guillaumev commentedarchitectJpres > I'm doing a feeds_tamper plugin which takes an OpenID as a parameter and needs to look up in the authmap table to return the uid of the corresponding user. The code by itself is very simple:
Comment #8
architectJpres commentedYes okay, thats an interesting use case. How would you plan on integrating this functionality into feeds tamper? As a plugin for feeds tamper, or a plugin directly to the feeds module?
Perhaps there is an easy way to allow feeds tamper to take on additional plugins using PHP? or perhaps you would be so kind to elaborate how you create the module.
Unfortunately our use case is more obscure as we call for a custom datatable field. We have to concatenate 3 feilds and more...
Comment #9
nicolash commentedQuick pointer to how to add a custom Feeds Tamper plugin: #982066: Example of hook_feeds_tamper_plugins()
Comment #10
brycesenz commented@architectJpres -
I wrote a similar custom plugin (attached), which might work for your use case. It allows you to use any mapped field in your PHP code, and uses drupal_eval to execute the code.
Comment #11
twistor commentedI'm not entirely opposed to a php eval plugin. My reluctance stems from losing potential plugin ideas from people writing one off scripts instead of proper plugins. Although undocumented, plugins are rather simple to write and should be the preferred method of using even simple custom code.
Comment #12
uwe_a commentedSome things cannot be done without a php eval plugin, maybe a suggestion to conribute code can be set there, but in my case for example my code is specific to my structure, basically to compute nid to be used in a node reference field based on a cck field value. i support integrating this into feeds tamper.
Comment #13
uwe_a commentedI'm using php_compute by brycesenz, i have multiple values, and im trying to get/return them, maybe this is not the correct location to ask this, but does that code allow that ?
please ...
EDIT: i did it by writing my own plugin !
Comment #14
tekken commentedI get the following error using the php_compute plugin:
Fatal error: Cannot use object of type FeedsImporter as array in /sites/all/modules/feeds_tamper/plugins/php_compute.inc on line 18EDIT: line 9 has to be changed to:
function feeds_tamper_php_compute_form($importer, $element_key, $settings)Comment #15
tekken commentedI couldn't access the $field variable using the php_compute plugin because it uses drupal_eval. This patch turned out to work better for my purposes because it gives access to the field.
Comment #16
zazinteractive commentedIt works the first time I make the plugin but any changes I make to the php code are not used. It still uses the old code
Comment #17
zmz commentedtekken
>EDIT: line 9 has to be changed to:
>function feeds_tamper_php_compute_form($importer, $element_key, $settings)
thx
----
by the way,
what syntax of php_compute.zip
in two (or three) simple examples
plz share
Comment #18
brycesenz commented@zmz - I'm not entirely sure what you're asking regarding syntax. What are you trying to do? Frankly, writing custom plugins is pretty easy, so you might just have better luck going that route (as demonstrated by post #13)
Comment #19
zmz commentedthx
done with pure php
Comment #20
millenniumtreeThanks very much for this! Sometimes, you just gotta CODE IT!!
I created a little stub module with a couple of parser functions in it so I could modify the title and description fields, conditionally for certain feed URLs. It was working great, except that it would bomb on certain feed items.
Here's what the code looked like.
A description with a single quote would fail miserably, writing a PHP error out to the description instead of the feed item content.
If I switched to double quotes, I had the same problem, but with different feed items.
To solve this, I had to somehow store the contents of the token into a variable, without using quotes!
I came up with an awesome, but somewhat ugly, little hack.
* Open an output buffer with ob_start().
* Close the PHP tag so we can print the token as raw text
* Re-open the PHP tag
* Save the buffer contents to a variable with ob_get_contents()
* Clear the buffer with ob_end_clean() so it doesn't get printed.
Now we can pass our $description variable into the parser function.
Yeah, of course there is a more elegant way to do this by fixing the plugin itself, but I needed a solution right away and this works like a charm!
"But my mom says I'm cool." --Milhouse
Comment #21
lookatthosemoose commentedFor my PHP code, I had to use:
<?php return call_user_func('custom_module_do_whatever',$field);?>instead of
<?php return custom_module_do_whatever($field);?>In order to get access to the $field variable. I found in the latter example, the value of $field was NULL when inside the custom_module_do_whatever() function.
Comment #22
puhig commentedHi,
From Feeds OAI , i have a $fiels with some id's but whent it is imported i want to get its description so i do it :
It's ok, but when it return a array on cck is stored 'Array', not data
Comment #23
lookatthosemoose commentedWhat you'll need to do is use eval() to turn the string that is returned by feeds_tamper into an array (feeds_tamper can ONLY return a string)
So your feeds_tamper php looks like:
Then, whereever you are using the results of the feeds_tamper php, you need to use eval()
to turn the literal string representation of the array into an actual array like:
That'll set the value of $myarray to the array represented by $value.
Then,
The function you will likely looking that receives back the response from feeds tamper is feeds mapper hook.
For whatever mapper you are using, there will be a function hook_feeds_set_target($node, $target, $value) in the .inc file.
I was using nodereference... see code below:
Comment #24
cyrilg commentedHere is the patch taken from comment #10 and including the modification from comment #14. The following allows to use drush in your make file to apply the patch :
;patch to add php_compute plugins to feeds_tamper
projects[feeds_tamper][patch][] = "http://drupal.org/files/issues/php_compute.patch"
Comment #25
dgastudio commentedi'm sorry, but after apply the patch, php_compute widget doesnt appear.
up. sorry, my fault, it's for d6.
Can somebody reroll this patch for d7? thanks
Comment #26
kenorb commented#1297968: Plugin: Execute PHP Code