Archive for the PHP Category

A problem which often arises when writing Drupal themes, modules, etc. is making sure there are no ‘hard-coded’ paths in our code. To help new users on their quest to writing quality Drupal code I list here the most used API functions to get paths in a portable way:

  • global $base_url - A global variable which stores your sites URL, typically http://www.<your_site>.com. This variable is set in your settings.php configuration file. This is not very portable and maybe in the future Drupal has a function for this.
  • base_path() - Returns the base URL path of the Drupal installation. At the very least, this will always default to /. This is used, for example when you want to add a resource relative to your base_url. For example like so: drupal_set_html_head(’<style type=”text/css” media=”all”>@import “‘. base_path() . drupal_get_path(’module’, ’system’) .’/system.css”;</style>’);
  • conf_path() - Based on your sites URL tries to find the most appropiate settings.php (site configuration file). To read how it works see Drupals API documentation
  • drupal_get_path($type, $name) - Returns the path to a system item (module, theme, etc.). The $type argument can be ‘theme’, ‘theme_engine’ or ‘module’ and $name the name of the item for which you want the path. To get an absolute path you need to prefix the $DOCUMENT_ROOT (the document root of your drupal installation).
  • path_to_theme() - This points to your theme’s path on the local filesystem. Usually $DOCUMENT_ROOT/themes/<your_theme> or $DOCUMENT_ROOT/sites/<your_site>/themes/<your_theme>
  • path_to_engine() - Returns the path to the currently selected engine.

To learn a bit more search for this terms in the API search box or ‘use the source, Luke!’.

PHP Hacks - written by Jack HerringtonRecently we bought a copy of the O’Reilly book “PHP Hacks” written by Jack Herrington. Inspired by his many wonderful hacks and the need to convert CSV values into SQL Insert statements I wrote a simple PHP script to do the job. To use it simply drop it in your webserver and point a browser to it. Fire up your favorite spreadsheet (Openoffice, right?), create a table (remember to use the first rows for the column names) then cut-n-paste the table into the textarea, hit Submit and Voilá: your spreadsheet data is converted into SQL inserts. Have fun!

(more…)

At Easytech we are using Drupal for projects which require a CMS (Content Management System). It’s very powerful, full of modules to extend the functionality and written in PHP which is a Language for which we have a lot of programming experience. For a project we are working on we used the Related Content module. This module allows you to link a particular piece of content (a node in Drupal parlance) to other content such as images, videos, audios, etc. One problem with the current implementation of the module is that it wasn’t designed to work when you have lots of content on the site. The patch we currently submitted to Drupal fixes this by separating the Related Content into a tab and adding a filter to be able to quickly locate content items. Here’s a screenshot:

This is how the new features looks like

If you are interested in getting the patch its here. In case you want to download a patched version of the module I have included a tar file with the latest version as an attachment in this posting. Try it out and send feedback to: miquel <at> easytech <dot> com <dot> ar.

Here’s a tar file with the patched version to try out: relatedcontent-5.x-1.1-patch.tar.gz. To install it just download it and untar it in the modules/contrib directory of your Drupal installation.

  • english

One of our latest projects here in Easytech was done using PHP as our programming language and Oracle as our Database. We had a lot of experience coding in PHP and developing with the Oracle Database but none using both together. The project turned out to be a great one but there isn’t a lot of information on the web since most PHP applications use MySQL or PostgreSQL as their database. Today I was looking at what blogs where available on the Oracle site and came across Christopher Cross’s blog which has a lot of interesting information for PHP developers. In it I found links to two interesting presentations: “Leveraging the Power of Oracle with PHP: Taking Advantage of the Database” and ” PHP and Performance” and a link to a book called “The Underground PHP and Oracle Manual” written by Christopher himself and Alison Holloway which covers PHP and Oracle development. For more references on using PHP and Oracle visit the PHP section in the Oracle Technology Network.