I need a multi-page drupal form that requests an external xml api and displays the data on the second page of the multi-page form.
I'm new to drupal and I've been reading advices on here and on drupal.org. I think I can either use the computed field on cck or I write an module to do this. I think I will do both, first using the computed field then write a module later on to get things running sooner.
I need some advice on how to create a computed field that calls an external api. Do I use curl or is there a drupal function that I can use? What drupal documents would help me and is it possible to provide a simple snippets to help me get started?
example api call
https://my.example.com/XMLServices/xml?accessKey=&accountId=&form_var1=&form_var2=&form_var3=
Edit: I think its called REST api. I believe there are some modules that can help.
There are some computed field snippets here
Curl should get data (if it is restful) but you will still have to parse the result.
Personally I would go down the route of using a custom module and hook_nodeapi or hook_form_alter, rather than a computed field, as it sounds like you are wanting some quite custom functionality.
As for retrieving (and/or posting/putting) remote content from/to a REST interface (or anything else done via http), you should also take a look at the drupal_http_request() function. It can get you pretty far without having to go the curl route.
You can find a basic usage example in the aggregator_refresh() function in the aggregator module from Drupal core, where it is used to fetch RSS feeds.
Related
So I am building a small web app. I have set it all up on Ubuntu and I am using Wordpress. I want to use a plug-in called JSON API to pull in content from my Wordpress blog in an easy to read form and I want this to be updated to say have only 5 posts at a time being the 5 most recent ones. I’ve looked around and I was wondering if someone could help me and give me an idea on how to go about this? I am a complete beginner I have no previous experience I have not started typing any codes or anything like that because I'm not sure how to start it.
You have a few options here, and which one you choose really depends on what works for you.
WordPress has a built-in API, but this is not a JSON API, it's XML-RPC. It's pretty feature-rich and won't require you to write any code (on the WP side) to pull posts. More info here: http://codex.wordpress.org/XML-RPC_Support
Read directly from the database. This is probably a faster implementation if you're reading from the same box. Simply connect to the database WordPress uses and query the posts table directly.
Find a JSON API plugin that suits your needs. It's difficult to recommend any as you seem to have specific requirements. Try some, and see what works for you. The downside to this is you'll need to keep the plugin up-to-date, and you're using third-party code - I'll leave it up to you whether you believe that to be a bad thing or not.
Write your own! It should be relatively straightforward to write a small script to pull in posts from the WordPress database and spit out a well-formed JSON feed.
I am trying to integrate to a joomla project, a list of php pages setup that update their content from db, and give select options to the user, to navigate through this content. Select is also dynamic. All dynamic features work with url parsing.
For example, pageone.php gets some data from db and creates a list of selectable links to page2.php?data=fetcheddata. Page 2 gets url variables and performs queries to db to select the data.
How am I going to integrate this to Joomla? Should I make a module to include the basic php page, and how url parsing will then work? Should I make an i-frame wrapper? Please enlighten me..
You just described the way Joomla works. Depending on the content you want to present, there may already be an extension that does that, or at least does something close that can be modified. Without any more details it is hard to say, but what you are describing could probably be accomplished with a CCK http://extensions.joomla.org/extensions/news-production/content-construction. You could definitely do it with a combination of Chronoforms and Chrono Connectivity -
http://extensions.joomla.org/extensions/contacts-and-feedback/forms/1508
http://extensions.joomla.org/extensions/directory-a-documentation/faq/5661
If not, then you will probably need to code a component - http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
1) iframe solution is the easiest one. But it has its limitations...
2) you can write Joomla component (not a module) that will do the job, but I'm afraid in this case you will either have to switch to Joomla URL format... unless you find some trick how to workaround that.
If your site is not very complex a simple approach is to write your application in plain php, and integrate your Joomla template to your application so your visitors can't tell any difference. Then, you will place links from your Joomla to your application and vice-versa accordingly.
However, the best approach if you are more familiar with Joomla is to develop a component. Here you can understand the difference between Joomla Components, Modules and Plugins. Please read Joomla documentation for further understanding:
http://docs.joomla.org/Extension
http://docs.joomla.org/Component
I have a PHP app, and I want some of the latest data to be extracted and display on a Joomla portal. I just couldn't figure out, can I return an XML document or what is the best way to do?
You can return these information in XML format and for example: snJxml2xslt2joomla
You can also return these information in RSS format and use the standard RSS feed module to show it in Joomla!
Or do you want to show some information FROM the Joomla site on an other site?
I'll assume that you want to display the information within a module in Joomla. If that's the case, then you can write your own database connection code (or override Joomla's) and pull the data directly out of the PHP application's database (assuming it's in a database).
If it's not, then there are several RSS/XML parsers within Joomla that will work such as the XML-RPC.
I would suggest to run a cron job to pull a data on regular basis and insert it into your local joomla portal DB. This way you have greater control over what you'd want to do with the data.
This might not be the best solution though. It also greatly depends on the kind of information you'd want to bring across. XML could be a bit more involved in terms of getting the structure right and so on.
I am developing my first large Ubercart site, which needs to have a daily product database update from an existing xBase (DBF format). The conversion from DBF to MySQL/PHP is handled on the same server as the Drupal installation, using some custom scripting I have done, and works well. However, the next step is to get my script to talk to Drupal and update the product nodes with pricing/stock level/etc.
Googling hasn't resulted in any good hits, at least in PHP terms.
So how do I go about this? Can I just use a POST to a particular page in Drupal, ie RESTful, or do I have to use some more arcane xmlrpc method?
There's a couple ways to approach this. If you need to de-couple your import system from php you could create a api that would allow you products to be updated from an authenticated data provider.
http://drupal.org/project/services
The simpler method though is if your working in php you should bootstrap drupal and insert / update the nodes from php:
Here's a great howto on doing that: hxxp://www.group42.ca/drupal_command_line_script_template
I am a PHP and ExtJS user. I am looking into developing an application using a good PHP framework (CakePHP; good as in "I consider this good for me") and ExtJS version 3. What I would like to achieve is a complete Ext viewport with many grids and functions that would call PHP urls for retrieving data, saving data, edit/remove data (not just for grids, also for treepanel and such). I would like to use CakePHP as backend with all its capabilities for executing these functions. My first goal is to integrate the obAuth component (or any other secure authentification plugin for CakePHP) with an ExtJS 3 login interface. I am searching for the best method of combining these too so that I can easily restrict functions based on the usergroup access. I am thinking of a setup where the logged in user makes one post from Ext regarding the execution of a function and the CakePHP response made present as errors or notifiers through Ext alert boxes.
Do you think this is possible ? Any thoughts of an ideal config for this ?
Thank you.
If you're going back and forth between JavaScript and Cake a lot the first thing you might want to do is override or extend the default View class so it'll package variables you set in the controller automatically into a JSON array or whatever you prefer. That'll save you from having to make a view for each action and/or overriding the layout each time. Study cake/libs/view/view.php and/or cake/libs/view/media.php, you can create custom views in app/views/.
Make use of the RequestHandler Component a lot to reuse logic both for normal views and AJAX.
Beyond that it's normal JS with a PHP backend.
This is actually very easy. First, integrate the obAuth Component into a basic CakePHP install, to see if it works properly and doesn't have any strange quirks. Once that's done, get to work on your frontend.
Your frontend should be designed entirely with ExtJS components. Either design your frontend with ExtJS or via HTML templates, but try not to do both, as it gets confusing and hard to maintain. I recently did this, and every controller action had a view that set up the DOM with some basic elements (a header for the page, any divs I needed to bind components to, and the .js file that was specific to that page/view).
Then, make your application RESTful. All of your ExtJS components can read data from a DataStore (or can just take a URL as the data source), so you just give them the paths you'd like and you're done.
Check out Bancha, it integrates ExtJS 4 and CakePHP 2.
It does this by doing all the communication in the background using an completely implemented Ext.Direct for CakePHP.
cheers
Roland