Jump to:
| Project: | Services |
| Version: | 6.x-2.2 |
| Component: | Code |
| Category: | support request |
| Priority: | major |
| Assigned: | snelson |
| Status: | closed (won't fix) |
Issue Summary
Hi,
If the intention of the node.get method is to present a copy of a node, as an object, which can be presented to another Drupal installation over web services (which is how we are using it, and I guess is a popular use case) then it needs to change the way it works slightly. The node_load function runs the node body through the HTML filter, which means the node body presented by the method is not truly what is stored in the database table - it's not a perfect copy of the node any more. Ideally the node object should be passed as it is stored in the database. For a detailed example of why this causes a problem, please read this blog post:
http://www.drupaler.co.uk/blog/warning-node-module-and-teaser-weirdness/123
That said, it is useful to have things like the CCK data, which would not be available if you were not using node_load function, so perhaps node_load is still the way, but the node body should be replaced with a direct call to the revisions table to fetch the unformatted node body?
Anyway, the point is that the way node.get currently loads and presents nodes can cause an issue, as detailed in the above post. Thoughts welcome. =)
Comments
#1
To me, that's not the intention of services. Web services provide an abstraction layer between the consumer application and the website (be it Drupal or something else) itself. To accomplish this, I'm writing proxy methods that convert typical Drupal objects - with a lot of specific CCK data structures - into a simplified struct.
I just wanted to point out this use case.
So, I'd opt for a flexible solution that serves both use cases, being 'Drupal to Drupal' and 'Drupal to other'.
But I don't have a proposition (right now).. somebody else?
#2
I'd agree completely. You're right - there are use cases where the current behaviour would be desired. A true Drupal to Drupal node service will probably require a bit of thought. Perhaps node.get should stay as it is and a new node.getRaw method (or something like that) be created for Drupal to Drupal node object duplication?
#3
Actually, node_load is pretty much raw data. services_node_load() wraps node_load in node.get requests which runs the body through the filter. Removing this behavior and perhaps adding a node.view method would likely solve the problem. But, we'll have to make sure this is well documented in the next release for existing apps that may be depending on formatted body.
Greg, I just read your blog, post, you probably wanna kill me now :)
I'm just gonna go ahead and fix this.
Scott
#4
Committed to D5 and D6.
Removed filter on body and teaser in node.load and node.get, then added a new service called node.view to be able to load formatted node data.
#5
LOL, thanks for fixing. No death required. ;-)
#6
it might of been a better idea to make a new method to get the unformatted data, as lots of applications out there are currently counting on node.load / node.get to return formatted data and the ones that need unformatted data are already used to getting formatted data with node.load / node.get so they probably already have made a custom way around this
#7
Automatically closed -- issue fixed for 2 weeks with no activity.
#8
Hi,
I have been looking for a solution related to getting the output of a node containing HTML and PHP , when previewed in drupal it runs through the filter and returns a page with correct page layout and dynamic content. But when I am trying to access this node from a Remote application(Ruby on Rails) using REST SERVER, Services module then it returns the php code in json as it is without running the filter.
My index node contains the following code:
<?phpinclude($theme_path.'/api_list.php');
include($theme_path.'/node-index.tpl.php');
?>
and the remote application accesses the service using the following code and then parsing the body content.
http://mysite/services/rest/node/2.json
In this case, the json I am getting is as follows:
{"nid":"2","type":"page","language":"","uid":"1","status":"1","created":"1277122858","changed":"1282116304","comment":"1","promote":"1","moderate":"0",
"sticky":"0","tnid":"0","translate":"0","vid":"2","revision_uid":"1","title":"index","body":"\r\ninclude($theme_path.'\/api_list.php');\r\ninclude($theme_path.'\/node-index.tpl.php');\r\n","teaser":"\r\ninclude($theme_path.'\/api_list.php');\r\ninclude($theme_path.'\/node-index.tpl.php');}
you can see that the in body I am getting the as it is 'PHP code' instead of formatted output.
Can you please help me on this as I am looking for the solution from past 3days and reached no where :(
Regards
Deepti
#9
I am not going to go out of my way to support PHP input filter rendering. This is a massive security risk to your site, and beyond that there are much better ways to accomplish what you are trying to do using a custom module.
#10
Agreed with #9. It should return the raw node body. If you're putting PHP in there that isn't fail-safe that's your own problem. If yo'ure relying on PHP that much, you should highly consider making this a custom module page callback rather than a node.
#11
Thanks for the reply.
My next question is how can I expose a custom module to a remote application. I have a rails application which gets the dynamic data from drupal, so if I create a module how the communication between two applications be achieved...???
Thanks for help in advance.
Regards
Deepti
#12
No replies...:(
Please help!
#13
We'll reply when you start asking specific questions about the documentation you haven't read.
http://drupal.org/handbook/modules/services
Everything you need to know is there and it's linked to from the project home page.
You could start by looking at how other modules expose themselves via web services. There are countless examples. It isn't rocket science.
#14
Thanks for the reply.
I was already using Services module and this is where I started facing an issue. The Ruby on Rails based remote application fetches the static pages from my drupal application and it returned the page as expected. But when I did the same thing for dynamic pages, it didnt work. (since node.get gives the copy of node). For details of my problem Please refer above to #8