You are here

Diego F. Roldán's blog

Cross Domain Access to JSON Data Returned by Drupal's Hook Menu

In this article I will talk about how I access JSON data processed by a Drupal Hook Menu's page callback from a remote domain. The idea here is that sometimes we want to take advantage of Drupal powerful Hook Menu (hook_menu) system to register paths and handle the processing of data for that page request.



First, I'll add a menu item so that we can register the path that when access will return an object in JSON format. for this example, I will use the name mymodule to refer to the module where all the code will be saved.

Handle PHP & JavaScript Global Variables in Drupal

Declaring and accessing PHP and JavaScript globals is not as straight forward as I thought it would be. first of all I'm going to go over how I first tried to implement PHP and JavaScript global variables and then what actually worked for me in Drupal 5 and 6.

Handle PHP & JavaScript Global Variables in Drupal

The PHP documentation on global variables - can be found inside the Variable Scope section - implies that if a variable is used within the context of a global variable, then the scope of this variable will span to includes and required files.

cURL vs. getimagesize vs. file_get_contents


The geimagesize() function allows us to determine the dimensions of an image, as well as the file type e.g. JPG, GIF, PNG. and the HTTP Content Type. Though this function is listed under the GD and Image Functions, this function does not require the GD image library.


This function will return an array containing the image information including the HTTP Content Type or MIME type which helps deliver images with a valid content-type header, or FALSE if the image information was not retrieved.

Setting Apache Virtual Hosts on Windows & Mac

Virtual Host

Setting up virtual hosts gives us the flexibility of setting up multiple hosts on a local machine, in other words we can use this method to host more than one domain name on the same machine, including of course on servers running locally. Usually when you setup Apache, you dump all your sites under htdocs and then you access them on your browser by using localhost/[directory-name]. Although this is good, sometimes its not convenient. For instance, when using CMS applications such Drupal or WordPress Mu, you might want to be able to setup multiple sites under the same local installation so that it mimics your live site installation.

To setup multiple hosts, we're gonna edit two files under both Windows and Mac. One of this files will be used to create the hosts, and the other will be used to map the hosts to our local IP address. Also, in order to modify these files you must use an account with administrator permissions.

Drupal Node API & Node Load

Node Load3>


Using the node_load function is really cool because it gives you access to all the data associated with a node, but excessive use of this function can be costly. There are several things we must know about what the node_load does.

First, all calls to this function will invoke all the hook_nodeapi functions defined by all modules that have been loaded at that point. The way node_load does this is by invoking the function node_invoke_nodeapi.


When it comes to programming and web development, choosing the right editor really makes all the difference. While searching for an editor, I looked for reliability, open community and lots plugins - that been said, only two words come to mind... Eclipse Galileo. Out of the box, Eclipse Galileo comes with editing support for PHP, XML, HTML, JavaScript, CSS and even Java and file extensions such PHP include files. Download Eclipse Galileo from here.

Syntax Coloring