New here? Then you may want to subscribe to my rss feed. :)

Why me??!?!

May 13th, 2008 | Posted in Rants, Wordpress | 3 Comments

It seems that somehow, somewhere, those ever so kind and nice hackers are targeting my site resulting in it breaking. Apologies for this, I am getting to the bottom of it. Little b******s!

Discuss this article »

Play a random mp3 file from a specific directory

June 4th, 2007 | Posted in Development, PHP, Wordpress | 13 Comments

In this post i discussed how to play random media files using wordtube by passing a comma delimited list of media ids.

Josh asked if there was a way of playing files from a specific directory rather than having to upload through wordtube and listing all media file ids.

Having helped Josh I thought it would be of use to others if I posted a little how to.

Firstly, you will need to download, install and activate coffee2code Random File plugin. This will randomly select a file from the specified directory and return it as a url ready to pass into the flash player.

Next, you need to download Flash Mediaplayer and upload mediaplayer.swf. For the sake of this how-to, I have uploaded it to the web root.

You will need to create the code to embed the flash player. Fortunately there is a wizard available here which will create all the code for you.

Copy paste the generated embed code and replace the file parameter value with a call to the random file plugin like so:

  1. <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  2. codebase= "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8"
  3. width="320" height="20"
  4. id="randomplayer">
  5.  
  6.         <param name=movie value="mediaplayer.swf">
  7.         <param name=quality value="high">
  8.         <param name=bgcolor value="#FFFFFF">
  9.         <param name=allowFullScreen value="false">
  10.         <param name=swLiveConnect value="true">
  11.         <param name=allowScriptAccess value="sameDomain">
  12.         <param name="FlashVars" value="file=<?php echo c2c_random_file(’/path_to_music_folder_relative_from_webroot’, ‘mp3′, ‘url’); ?>& width=320&height=20&displaywidth=320&displayheight=0
  13. &autostart=true&backcolor=0xFFFFFF">
  14.  
  15.         <embed type="application/x-shockwave-flash"
  16.         pluginspage="http://www.macromedia.com/go/getflashplayer"
  17.         width="320" height="20" bgcolor="#FFFFFF"
  18.         name="randomplayer"
  19.         src="mediaplayer.swf"
  20.         flashvars="file=<?php echo c2c_random_file(’/path_to_music_folder_relative_from_webroot’, ‘mp3′, ‘url’); ?>&width=320&height=20&displaywidth=320&displayheight=0 &autostart=true&backcolor=0xFFFFFF">
  21.         </embed>
  22.  
  23. </object>

Taken from plugin authors page:

The directory of random files must exist at the directory structure level of your WordPress installation or below. (i.e., if your site is installed on your server at /usr/local/htdocs/yoursite/www/journal/, then the directory of random files you specified will assume that as its base… so $dir=’randomfiles’ would be assumed to actually be: /usr/local/htdocs/yoursite/www/journal/randomfiles/)
Leading and trailing ‘/’ are unnecessary… ‘/randomfiles/’ == ‘/randomfiles’ == ‘randomfiles/’ == ‘randomfiles’

Finally, you need to place the code in one of your theme templates. Hopefully, you will have the player stream a random mp3 from a specified directory on every page load. If you encounter any problems then ask.

Discuss this article »

Wordpress Blogroll bug fix

May 10th, 2007 | Posted in Development, Wordpress | 

I recently added a new feature to the home page. The “Sites and Articles of Interest” section is built using the Blogroll manager. As well as displaying the title and description, I wanted to display the date links were posted. Referring to Wordpress documentation I learnt that passing show_updated=true to wp_list_bookmarks() as an argument would return the date formatted, but it didn’t.

Digging into admin-db.php I discovered that when links are saved, the link updated date value had been left out. Therefore all links were defaulting to the database fields default value of 00-00-0000 00:00:00. The php template which holds wp_list_bookmarks() function checks the first two characters of the date, if they equal “00″ then it does not display the date.

To display the date I had to add the date field and value to the Blogroll’s save link SQL query, which is found in admin-db.php.

Backup admin-db.php, then at around line 350…ish, replace:

  1. if ( $update ) {
  2.                 $wpdb->query("UPDATE $wpdb->links SET link_url=’$link_url’,
  3.                         link_name=’$link_name’, link_image=’$link_image’,
  4.                         link_target=’$link_target’, link_category=’$link_category’,
  5.                         link_visible=’$link_visible’, link_description=’$link_description’,
  6.                         link_rating=’$link_rating’, link_rel=’$link_rel’,
  7.                         link_notes=’$link_notes’, link_rss = ‘$link_rss’
  8.                         WHERE link_id=’$link_id’");
  9.         } else {
  10.                 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES(’$link_url’,'$link_name’, ‘$link_image’, ‘$link_target’, ‘$link_category’, ‘$link_description’, ‘$link_visible’, ‘$link_owner’, ‘$link_rating’, ‘$link_rel’, ‘$link_notes’, ‘$link_rss’)");
  11.                 $link_id = $wpdb->insert_id;
  12.         }

with

  1. $time = date(‘Y-m-d H:i:s’);
  2.         if ( $update ) {
  3.                 $wpdb->query("UPDATE $wpdb->links SET link_url=’$link_url’,
  4.                         link_name=’$link_name’, link_image=’$link_image’,
  5.                         link_target=’$link_target’,
  6.                         link_visible=’$link_visible’, link_description=’$link_description’,
  7.                         link_rating=’$link_rating’, link_rel=’$link_rel’,
  8.                         link_notes=’$link_notes’, link_rss = ‘$link_rss’,
  9.                         link_updated = ‘$time’
  10.                         WHERE link_id=’$link_id’");
  11.         } else {
  12.                 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss, link_updated) VALUES(’$link_url’,'$link_name’, ‘$link_image’, ‘$link_target’, ‘$link_description’, ‘$link_visible’, ‘$link_owner’, ‘$link_rating’, ‘$link_rel’, ‘$link_notes’, ‘$link_rss’,'$time’)");
  13.                 $link_id = $wpdb->insert_id;
  14.         }

Hope this helps others. Any problems then let me know.

Discuss this article »

Getting WP-Cache and WPAudioScrobbler to play together

April 7th, 2007 | Posted in Development, Wordpress | 1 Comment

One way to speed your wordpress site up is to make use of WP-Cache. One of the cool features of this plugin is the ability to dynamically load page elements. I wanted to be able to continue to load my Last.FM play list using WPAudioScrobbler whilst having the rest of the page load from a cached version on the server.

To achieve this you make use of two special tags, mclude and mfunc.

Unfortunately the documentation does not make it clear how to go about using the tags correctly, so through carefully analysing the code, deciphering the regular expression and a large chunk of trial and error I managed to get both WPAudioScrobbler and WP-Cache to co-exist.

From within the template displaying your Last.FM play list, replace:

  1. wpaudioscrobbler();

with

  1. < !–mclude wp-content/plugins/wpaudioscrobbler/wpaudioscrobbler.php–>
  2. < ?php include_once(ABSPATH . ‘/wp-content/plugins/wpaudioscrobbler/wpaudioscrobbler.php’); ?>
  3. < !–/mclude–>
  4. < !–mfunc wpaudioscrobbler()–>
  5. < ?php wpaudioscrobbler(); ?>
  6. < !–/mfunc–>

Note: for some unexplained reason, wordpress seems to replace a double hyphen with a minus symbol. If you copy and paste, remember to swap them back and remove the space after the opening < tag.

Discuss this article »

WP Plugin Fix: Customizable Post Listings

April 7th, 2007 | Posted in Development, Wordpress | 2 Comments

I wanted a way of listing the five most recent posts both below the actual post and on the home page. I discovered Customizable Post Listings which was an enhanced version of one developed by www.coffee2code.com that did exactly what I needed.

I encountered a small bug where it would not return the correct category link when using %post_categories_url% . It failed to return the actual category id (or name depending in your permalink structure). e.g. index.php?cat=

To correct the bug, on line 348 (or thereabouts) replace:

  1. $category_link = get_category_link( $category->category_id );

with

  1. $category_link = get_category_link( $category->cat_ID );

Discuss this article »