Listing methods for all of your PHP objects for quick reference

July 23rd, 2010

Open Reference BookWhen managing or developing object orientated programming sites in PHP, I find that I frequently forget the names of methods that belong to classes. Even though I try to have a standard naming format – my memory still seems to fail :-(
So rather than run phpDocs over my objects continually, I knocked together this quick script to list all the methods in all my objects (I store all my objects in one directory). I call this file “_methodList.php” and keep it only on the development server. Here’s the code!
$dirpath = "/path/to/objects";
$dh = opendir($dirpath);
while (false !== ($file = readdir($dh))) {
//Don't list subdirectories
if (!is_dir("$dirpath/$file")) {
//only grab PHP files
if ((substr($file, -3)=="php")&&($file!="_methodList.php")){
echo $file."<br/>\n";
require_once($file);
$methArr = get_class_methods(substr($file, 0, -4));
if (sizeof($methArr) > 0){
foreach ($methArr as $method){
echo "-> ".$method."<br/>\n";
}
}
echo "<br/>";
}
}
}
closedir($dh);

Thanks to Honou for the opening graphic!

Share on Facebook

SEO QuickStart Guide in a Graphic for Beginners

July 17th, 2010

I’ve spent the past couple of years continually looking over Search Engine Optimisation (SEO) guides, blogs and tips from so many different sources, and while some have their own twist on the way things should be done, there are several core messages which keep coming through. I’m no SEO guru, but I try what I can, and I’ve summed up the core messages in this graphic below. If I’ve missed anything critical – then let me know! It’s a big graphic, but should be worth the wait :-)

SEO Visual Quickstart Guide for Beginners with things to do on your site, and off your site!

Special thanks go to the follow sites that I used information from:

SEOMoz.org, TheGoogleCache.com, GetClicky.com, ViktorViktoriaShop.com (for the great product graphic). If I’ve used your work and you don’t want me to, then let me know and I’ll blur you out of the graphic!

Share on Facebook

Arricah is born!

July 12th, 2010

Arricah My wife gave birth to our beautiful little girl on the 7th of July, and so I have been quite busy the past couple of weeks!

I will return to regular posting shortly!

Share on Facebook

How to migrate contacts from a Palm Treo 680 to a Nokia e71 without Outlook

June 24th, 2010

I recently switched from my Palm Treo 680 to a Nokia e71. It was a painful departure from a decade with Palm, but the phone is now old, and the battery life has begun to become a major issue during the normal working day.

The e71 has some great features over the Palm, but a couple of things I’ll definitely miss are the touch screen and the keyboard!

A hurdle that I came across during migration was my contacts. There didn’t seem to be a simple way to synchronise the two devices without hacking about with Outlook and some other garbage inbetween. I don’t run Windows, and so I don’t have Outlook. Short of spending ages trying to knock together a synchronisation profile in Ubuntu for both devices, I tried to find an easier way. It turns out, there is a very simple way that doesn’t seem to be well documented.

The process works like this:

  1. On the Palm Treo 680, go to your contacts menu, and under the category “All” – press the “Menu” button (bottom right key on the keyboard)
  2. Click “Send Category”
  3. Select “Email” or “Chatter”, or some other file transfer method that allows you to get the file to your Desktop
  4. You will then have a file called “All.vcf” on your desktop, this file now needs to be processed through my PHP vCardSplitter script. You can do this using PHP5-CLI, or if you don’t have this on your computer, then drop me a comment below to get in touch, and I’ll split the files for you
  5. Once your files are split, you then need to connect your Nokia phone to your computer in “Mass Storage Mode” and copy all the split VCF files onto the phone under the folder “/Other/Contacts”
  6. Safely disconnect your phone from the computer
  7. On the phone, go to the Contacts menu, click the Options button and select “Copy > From Memory Card”
  8. It will then begin copying all your contacts in their full glory to your phone! I had about 1500 contacts to copy across, and I started it just before I started writing this post, and it still isn’t done… (it takes a while)

You’re done! I don’t think the categories that were saved on the Palm are copied across, but at least you now have all your contacts, and all of their full vCard information with them. So this should have copied across email addresses, multiple phone numbers, addresses, etc.

As above – if you can’t execute PHP scripts on your own, then drop me a comment, and I’ll sort you out with a split up file and its outputs. There is a spam trapper running on my comments box below, so make sure you have JavaScript turned on when viewing this page!

Do you have an easier way to do this? If so, please let me know and I’ll link to your method from this post!!

Share on Facebook

Iterating through class constants in PHP

June 18th, 2010

I was breaking my head trying to figure out the best way to reference a particular set of constants in one of my objects so that I didnt’t unncessarily need to create a new database table. Fortunately, I found this thread about looping through class constants using reflectors.

As a summary, it can be done in a very small amount of code:
class test{
const CONSTANT = 'foo';
}
$t = new test;
$r = new ReflectionObject($t);
print_r($r->getConstants());

With the appropriate naming convention – everything else is easy!

Thanks to jpadie.

Share on Facebook

Tutorial on Creating Dynamic JavaScript Widgets for Third Party Sites

June 15th, 2010

One of the things I get asked a lot about are the JavaScript widgets that I make, that can be installed on third party websites. The VenueMirror VenueSearch widget at the top of this page is an example of this. The search bar is actually loaded through a JavaScript call that pulls the information from another server. This technique for loading content onto third party websites is not unusual, but it seems there are too few tutorials out there about how to do this. Firstly though – one must question why indeed you would do this.

Read the rest of this entry »

Share on Facebook

Creating Line Graphs in JPEG Format through PHP

May 25th, 2010

A while ago I wrote about making use of information collected by websites – I find graphs a great way to do this. And while there are lots of great graphing objects, or tools available today, it can be a hectic scene to try and find a free one that you want for basic use. So quick modifications to existing code can sometimes be exactly what you need! Below is the code that was used to create the graphs seen in that previous post.
Read the rest of this entry »

Share on Facebook

Useful Currency Information by Accident

May 12th, 2010

Pennies and Pounds If you run a website, have you ever noticed how much data it accumulates? Usually, quite by accident as well… I was poking through some old parts of the VenueMirror website today and stumbled across a feature that I had totally forgotten we had implemented. It is of course one of those features that the code makes use of everyday, but it has become so inherent that it gets taken for granted!

There is a need for our system to perform currency conversions as transactions can take place across multiple currencies, and so currency updater was created to provide live exchange rates. Our currency updater is quietly used by our currency and transaction objects, and so once built there’s very little need for us to even think about how it works! Essentially it collects the latest currency conversion rates and builds a currency table for the whole system to use. In the process though, it has collected historical currency data.

So I thought it would be interesting to render this data into charts that show how exchange rates fluctuate. I built a quick bit of PHP to take daily spot rates out of the data at 11.30am and see how they compared to the previous days! The images below are dynamic PHP images, and should show you exchange rates for ten days started from 25 days before yesterday!




The script takes parameters that allows it to be customised on how many data points it shows, which currencies it compares, and how many days into the past it should end. Tomorrow, I’ll post the source to the graphing code, and the tutorials that are available online for you to get more information from.

Cheers,
K
P.S: Thanks to Mukumbura for the opening photo!

Share on Facebook

Sending HTML composite email in PHP using objects!

May 4th, 2010

Photo of an American MailboxHave you ever tried to send HTML email using PHP? Sending plaintext email is quite straight forward and easy, and if you have the energy to write your own functions, sending HTML email can be pretty simple too. Half the problem is writing functions that can be ported around to different projects quickly and easily.

PHP Objects made this much easier to do, and since then I’ve been swapping objects in and out of various different parts of the code, and across different applications. I realised the other day that the one I make the most use of is my mail message object. So I thought I would open it up in the event that you also found it useful! Read the rest of this entry »

Share on Facebook

Friday Tip Blogging – Gifts

April 30th, 2010

Birthday party gift ideas!
There are some people that have great imaginations, or even fantastic insight, into what they can give as gifts to other people. On the other hand you get people like me who really struggle to come up with meaningful gifts.

There are all the usual options like flowers, chocolates, tickets to an event, or even a dinner – but what about that item that they can keep? What can you buy that isn’t edible, doesn’t die, and doesn’t get thrown away after a couple of weeks?

Gift items like that have to seem really personal, but also evolve with the person over time. If you buy a friend a CD, if its music they like, then they’ll probably keep it for a while – that is if they didn’t already have it. But how many CDs can you buy? And how long will that track or music last as their favourite song?

This is where the electronics world has come up with some awesome alternatives, that aren’t hugely expensive, but do say a lot to the person you are gifting the item to. I’ve put together some ideas below – if you have more, then please feel free to add them!

  1. Instead of a CD or one track, gift an iPod shuffle with preloaded music
    • The iPod shuffle is the cheapest iPod available
    • You can load tracks that you know they like (it doesn’t matter if they already have them!)
    • They can add/remove music whenever they like
    • It doesn’t matter if they have a bigger iPod because the shuffle can be used when they go to the gym or something like that!
    • This gift can seem very personal because of the preloaded music, and by virtue of the fact that the person is likely to continue using it!
  2. Instead of a photo frame, gift a digital photo frame with preloaded photos, or for a cheaper option make a collage, or custom desk-calendar!
    • Simple photo frames seem quite cheesy, and if not gifted with a photo in them, will probably sit in a drawer somewhere
    • Digital photo frames can range from the cheap to the pricey, but the net result is the same – a hugely personal feel
    • Photo collages are the cheapest – but they are a labour of love as they can take quite a while to put together!
    • If you can’t put together a collage, then you can select 12 great photos, and have it printed in a desk-calendar format! This gift lasts the whole year and the calendar can be made to start and end on their birthday!
    • Photos are an amazing thing when there are lots of them, as the memories are always fantastic!
  3. Rather than a t-shirt from a shop, what about a custom printed T-shirt?
    • There are hundreds of the same shirts or t-shirts with that one funny logo, or phrase, and everyone around wears them for a few weeks – that’s not personal!
    • Take a funny catch-phrase that has meaning between you and the friend, or you and the group, and get that printed on a t-shirt
    • Nobody else will have a copy of that t-shirt, and they’re likely to keep it for sentimentality!
    • Careful! Everyone in the group might want one!
  4. For the extravagant there’s always the option of naming a star after the person!
    • There are services that allow you to pick out a star and give the name of a person
    • You get a certificate that acknowledges the star has been officially named and can present this to them
    • This gift usually lasts hundreds of years!
  5. Donate to charity in their name
    • If you know they support a particular cause, then it is possible to donate to that cause under their name
    • The charity provides you with an acknowledgement of the gift and you can present that to them as well
    • This is one of my personal favourites as it makes more than one person happy!

If you have any additional ideas then please feel free to contribute!

Share on Facebook