PHP
PHP Retweeting Twitter Bot Using Streaming API Search Results
Submitted by badzilla on Fri, 16/03/2012 - 21:23The introduction of the Twitter Streaming API now provides the Twitter developer with an accurate method of obtaining real-time search results. Previously the developer would have had to use the existing REST service which is not guaranteed to provide either timely or thorough results. The new Streaming API can be used with basic authentication based on an existing account, whilst the REST API requires the more complex OAuth method of authentication.
Armed with this knowledge I decided to develop a Twitter Bot with the following functionality:
Drupal 6: user_badges_taxonomy Module
Submitted by badzilla on Sun, 15/01/2012 - 13:59The motivation for this module came from a shortcoming of the functionality of the user_badges module and the thread http://drupal.org/node/1144296 questioning the usage of the vocabulary feature in the user_badges module. It appears that this enables the assignment of badges to users for arbitrary achievements. For instance, a client of mine is a political campaigning organisation and it would be cool to assign badges to those activists who attend campaigns.
PHP Algorithm to Evenly Distribute Items into 3 Columns
Submitted by badzilla on Tue, 09/11/2010 - 16:27This is the second time in my PHP career I've needed this so thought I'd commit it to a blog for easy access next time and save myself some brain MIPS. I want to evenly distribute items into three piles, making sure that no pile can have more than 1 extra item, and should a pile need 1 more than the other piles, then the item should go to the left-most first. This is better explained by way of a diagram. My pile of items is shown as letters of the alphabet.
A A
AB A,B
ABC A,B,C
ABCD AB,C,D
ABCDE AB,CD,E
ABCDEF AB,CD,EF
ABCDEFG ABC,DE,FG
ABCDEFGH ABC,DEF,GH
ABCDEFGHI ABC,DEF,GHI
PHP Convert Decimal UK Currency To Pounds Shillings Pence
Submitted by badzilla on Mon, 04/10/2010 - 10:23I came across an unusual problem the other day. Whilst developing a PHP book / magazine cataloguing system I wanted to output the cover prices of the items that were pre-decimalisation (1971) in the old UK pounds / shillings / pence format.
For a reminder, particularly for those born later than the mid sixties who will have no recollection of the olden days, the British currency had 12 pennies (d) to the shilling [s] and there were 20 shillings to the pound (£). That makes a total of 240 pennies in a pound.
PHP Zend Framework REST Server Tutorial under Apache + Linux
Submitted by badzilla on Sun, 15/08/2010 - 13:47The Zend Framework lends itself to web services due to the bundled classes which come with the Framework. It is ideal both for consuming services (client) and exposing services (server). With this tutorial we'll put together a working REST server using the Framework. If you haven't completed my earlier tutorial on creating a Zend Framework Hello World, you should read it now since we'll be using it as our starting point.
For those who haven't completed the earlier tutorial, make sure you:
PHP Zend Framework Hello World Tutorial under Apache + Linux
Submitted by badzilla on Mon, 09/08/2010 - 23:20The following tutorial shows the steps involved in creating a simple Hello World example for the free PHP Zend Framework using Apache server on a Linux openSUSE platform. I am assuming here you are familiar with the concept of the Model-View-Controller (MVC) - if not, click on the link and do some mugging up on Wikipedia.
Drupal 6 Programmatically Create image_gallery Images in PHP
Submitted by badzilla on Fri, 19/02/2010 - 19:42Or since image_gallery items are just images with a taxonomy tag in a vocabulary called Image Galleries, a subtitle could be Programmatically Create Images and Tag with image_gallery. In this tutorial we are going to create a small module which contains the code to create the images and has a button on a form to effect the creation. I will foreground the actual copying code so you can cut and paste it into your own module development.
Drupal 6 SMS Framework: Esendex PHP5 SOAP Gateway
Submitted by badzilla on Wed, 30/12/2009 - 20:57Drupal 6 SMS Framework enables the sending of SMS from a Drupal 6 website, through a suitable bureau service. The 'glue' between the SMS Framework module and the chosen SMS bureau is called a 'gateway'. Each bureau needs the development of a dedicated gateway, and currently there are few available. In reality, the only gateways for Drupal 6 are Clickatell and a generic email facility.
openSUSE 11.2: Downgrade PHP 5.3 to 5.2
Submitted by badzilla on Mon, 07/12/2009 - 16:16PHP 5.3 is bundled with openSUSE 11.2 which, if you are a Drupal developer, is not a good thing. As of PHP 5.3 the function ereg_replace() is deprecated - and this function is used heavily in Drupal 6 core along with many community modules. I performed the openSUSE upgrade to 11.2, and decided to see what the net result would be with respect to my Drupal development. Drupal generates a load of warnings, most of which are more annoyances than problems, but image_cache doesn't work and I have a dependency on that module so decided to downgrade from PHP 5.3 to PHP 5.2.
Singleton Pattern and the T_PAAMAYIM_NEKUDOTAYIM Error
Submitted by badzilla on Tue, 03/11/2009 - 13:33Whilst developing some code for a price comparison website, I came across a PHP error I hadn't seen before.
[Sat Apr 17 09:08:25 2010] [error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /srv/www/htdocs/compare/sites/all/modules/compare/includes/merchants/merchantMaster.inc on line 224, referer: http://localhost/compare/What the dickens is T_PAAMAYIM_NEKUDOTAYIM? It turns out this means 'missing double dots' in Hebrew, and is in reference to the '::' scope identifier in objects.