James Garrett's Blog

You are currently browsing the Programming category.

Theming WHMCS – It’s EASY!

After reading several people struggling to theme WHMCS, I decided that I would write a brief tutorial to attempt to emphasize how easy this is if you read the directions and think it through.  First off, modifying the default them is *not* the easiest way to do it, you’re going to beat your head against the wall trying.  WHMCS has setup their system very simply.  Imagine the following php file-


This is an oversimplified version of how WHMCS works.  So here are the steps

  1. Setup a static design that you would like to use.
  2. Split the file around the main content area
  3. Copy/Paste everything above the main content into the header.tpl file for your skin
  4. Copy/Paste everything below the main content into the footer.tpl file for your skin.
  5. Replace meta variables (these can be found in /templates/default/header.tpl)
  6. Use FireBug to fix any minor issues in your css.

WHMCS uses the smarty template system.

Posted 9 years, 11 months ago.

Add a comment

Learning the Facebook Graph API

Earlier this month, I was approached by a software company to assist writing a Facebook application.  I hadn’t done this, however I have read about their powerful Graph API and was anxious to give it a shot. The first step was to learn to connect to the facebook API, which was greatly assisted by using the PHP SDK that has been written and released as open source. I’ll write a longer blog soon once I develop the application, but here’s the steps to begin writing your own external facebook application.

  1. Register your facebook application ( link )
  2. Download the Facebook PHP SDK (link)
  3. Read tutorials to learn the basics (click here for a good one)

Posted 10 years, 1 month ago.

Add a comment

Formatting Phone Number and Fixing User Input With PHP

Recently I was writing a franchise module for a shopping cart software that required franchise owners to input their phone number.  I’ve ran into the problem where no matter what instructions I’ve given, the franchise owners consistently like to format the phone number in their own unique way.  Rather than add 3 text boxes to where they have to tab between every part of the phone number, I wrote a quick and easy php script to handle all the leg work for me!

//Input example
//Output examples
//formatPhoneNum($phone_number, 1) outputs (999) 999-9999
// Inputting 999-9999 would cause the function to return “False”
function formatPhoneNum($phone_number, $style){
// Style 1 – (999) 999-9999
// Style 2 – 999-999-9999
// Style 3 – 999.999.9999
// Style 4 – 9999999999
$number = str_replace(array(‘(‘, ‘)’, ‘-‘, ‘ ‘), ”, $phone_number);
if (strlen($number) == 10){
$area = substr($number, 0, 3);
$first = substr($number, 3, 3);
$last = substr($number, 6);

case 1:
return “($area) $first-$last”;
case 2:
return “$area-$first-$last”;
case 3:
return “$area.$first.$last”;
case 4:
return “$area$first$last”;
// if the phone number was too long or too short
else {
return false;

Posted 11 years, 1 month ago.