Drupal Hooks and Functions I Can't Live Without

Archive of Drupal's Hooks and API functions I constantly use. This blog will be updated regularly since it is used widely for reference.

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.

HOOK MENU

hook_menu

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

getimagesize()

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.

Usage

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>

node_load

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.

ECLIPSE + PHP + ANYEDIT

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

Gothic Girl Vector Illustration

An early attempt to trace a photo under Adobe Illustrator. The illustration was entirely trace using the Pen Tool and path manipulation to achieve the curves. For simplicity the illustration uses only solid colors.

Hellion 3D Game Artwork

As part of a school thesis, a 3D developer asked me if I could come out with some design concepts for his game titled "Hellion". The game had the concept of a futuristic industrial city. The game was showcased during the thesis presentation in 2005 at New York's School of Visual Arts. Since I had the total freedom to design, I definitely wanted a design that complimented the environment and concept of the game.

Pages