Tag Archives: PHP

Links for December 29th through January 28th

Links for December 29th through January 28th:

Also tagged , , , , , | Comments closed

Elegant Grunge 1.0 released

A significant update to my WordPress theme, Elegant Grunge, has been released. New features and fixes include:

  • Configurable sidebars! Choose from no sidebar, a sidebar on the right (the standard layout), or a double sidebar on the right!
  • Support for WP 2.7 paginated and threaded comments
  • Support for a custom header image – just enter a URL to an image, typically a transparent PNG, and it will appear in the header instead of the text (SEO friendly)
  • Some bug, compatibility and i18n fixes


p>Note: If you have problems with this theme, please post your question at the WordPress forums. Please don’t contact me directly, as I don’t have the resources to help you.

Also tagged , , | Comments closed

RSS aggregation for PHP

I have written a mechanism in PHP that can take several RSS feeds, filter and manipulate them, and re-display them in either RSS or straight HTML.

This can also manipulate content (through the preg_replace function, and configurable per-feed), such as removing names from Twitter entries. I’m using it on to show all relevant items from both this blog and my Twitter feed automatically, as an alternative to creating a separate blog. I’m also using it on this blog, to incorporate blog entries and Twitter postings.

It uses the MagpieRSS RSS parser for PHP, which provides some nice functionality, including caching.

Here’s the code:

To use it, unzip it to somewhere in your webroot, then edit aggregate.php and possibly rss.php to set your configuration. Make sure that either the aggregate directory is writable, or create a ‘cache’ directory within and make that writeable, to enable caching. Point your web browser to the rss.php file to immediately view an RSS feed aggregating your supplied feeds. To add a link to the RSS from a website, add it in the header:

<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="" />

To include content in a website, the provided render_aggregate_items function will do most of the work, or you can write your own rendering code. You just have to include the file, use the functions to obtain and draw the content, and then provide your own CSS styling. Example:

<div class="items">

A more comprehensive example is in sample.php.

The code is GPL, so use it however you want – keep the header comments there, though.

Also tagged , | Comments closed

Links for November 13th through November 17th

Links for November 13th through November 17th:

  • How to Price Your iPhone App out of Existence Write-up on the dangers of pricing an iPhone app too low, and the need to 'correct' the market
  • Open Radar Community-driven, open Apple bug reports
  • Free Australian Postcode location data "…Both the original CSV is available zipped below and contains Postcode, Suburb, Latitude and Longitude, a MySQL dump of the data is also available in a Zip file below. You can also download the PHP functions we coded to interface with the MySQL database. Simply call the postcode_dist() function with the two postcodes as shown in the example and you'll have a result in Kilometers returned quite quickly, these functions are freely available under the BSD licence."
Also tagged , , , , , , | Comments closed

A OS X service to encode HTML characters

I find myself frequently writing HTML code in comment forms which support use of HTML formatting, which means that I have to encode the html entities if I want them to show up (as in representing ‘>’ with ‘&gt;’, for example).

This gets rather tiresome, particularly if there’s a fair chunk of text to encode by hand.

I used the always-useful ThisService app with a short PHP script which does a htmlspecialchars() on whatever’s passed to it, to create a OS X service called ‘Encode HTML‘. Put it in your Library/Services directory, possibly log out and back in again, and you’ll be set.

Select the text to encode, click the system menu, Services, Encode HTML, and it’ll be automatically encoded in place.

Also tagged , , | Comments closed

Some useful mini-plugins for WordPress

Originally for my own use, I put together a couple of WordPress plugins, which I thought I’d make available in case they were useful to anyone else.

Google AdSense shortcode

This is the simplest plugin, which provides an ‘adsense’ shortcode to output a Google ad. To use it, use Google’s tools to create the ad, then paste it into the php file where indicated, then put {adsense} (replace the curly braces with square brackets) in posts/pages where you want the ad to appear (remove the spaces around the square brackets).

And now for a demo + shameless attempt at monetization:

Media player

This one is useful if you occasionally post a video file on your blog, and host it locally. If you use video more frequently, there are plugins that probably are more suited, but I personally didn’t want the overhead, and I wanted to store videos in the standard upload locations, instead of having a separate repository, which seems to be what other plugins do.

This one uses the JW FLV player, provided in the plugin. Use something like:

{media source="" width="400" height="308" preview=""}

(replace the curly braces with square brackets)

I used this just the other day on a post demonstrating the output of the simulator I’ve written for my PhD.

Music player

This is the plugin that renders the content for my music page, as well as providing mini-players for other posts. Give it a path to a directory, and it will display all mp3 files in that directory with flash players based on the XSPF Web Music Player. Recently-added mp3 files will be marked as ‘New’. Use something like:

{musiclist path="path/to/my/music"}

(replace the curly braces with square brackets; add optional nolink=”true” parameter to avoid linking to the mp3 files from their titles)

For just one track, use:

{audio source="path/to/audio.mp3"}

Also tagged , | Comments closed

Twitter posting lists with images


Recently I released some code to discover and embed Twinkle images linked from Twitter postings, and released a modification to Ricardo González’s Twitter for WordPress plugin which uses it.

I’ve now implemented support for Twitpic as well.

Grab the modified WordPress plugin here:

After installation, add the widget and make sure ‘Discover images’ is ticked.

For non-Wordpress users, the base code is also available here:

Include it in your twitter list source code, and use it as a filter for the message content. Something like:

$message = TwitterImageUtil::processContent($message, $mysql_database_handle);

Some configuration is possible – see the header comments for more details.

The code will create a thumbnail of the image, and store it locally. It’ll also cache the results in a MySQL database for speed. It supports Lightbox, too – just supply the relevant flag to turn it on.


  • Version 0.2.6: Bugfix for posts with both images and @mentions
  • Version 0.2.5: Bugfix from prior version, plus compatibility fix for Twitpic changes
  • Version 0.2.4: Updated to match Twitter for WordPress v1.9.2: Compatibility fix for WP 2.7
  • Version 0.2.3: Another update, chasing the moving target that is Twitpic
  • Version 0.2.2: Updated to match Twitpic’s new image storage using Amazon S3.
Also tagged , , , | Comments closed

Advanced web templating with PHP and regular expressions

This post describes a method to gain more control over the styling of images for web templates/blog themes, using a bit of Regular Expression magic. This is the technique used for my recent theme, Elegant Grunge.

You’ve just designed the most beautiful template ever – pleasing composition, clean lines, smooth colours and gradients and an awesome typeface. You apply it as the theme for your blog, or release it to the community, and there is much rejoicing.Example of the 'SH Trocadero' WordPress theme with image

Then you or someone else inconsiderately puts a photograph into a post – disaster! That nasty square of graphic just destroyed your composition, and the page is unbalanced and suddenly looks terrible.

Images are particularly tricky to make work with a theme, mostly because they’re so unpredictable. With text, it’s easy to control the way it looks. With images, they can be any colour or shape, many of which will break the composition of a theme, especially if the design elements of the theme contains irregular lines.

A big impediment to making images work is the limitations introduced by the current versions of CSS: All you can really do is provide a square border, possibly with some padding. That’s it, unless you’re willing to manually add tons of markup around images every time – and willing to make your users do it, if you’ve released a theme.Example of images in the "Green Light" WordPress theme

Some people will carefully Photoshop-up their images to make them fit – Webdemar (who made the theme I first used on my blog) does this, for example, and it looks great. That’s a lot of work, though, especially if you make frequent posts with images!

If you’re a theme designer, there’s an easier way to make images work.

Read More »

Also tagged , , , , | Comments closed