Categories
Development

Simple Mobile Detection Redirect

Been working on a simple mobile version of a website I’d done for a client in the past recently. We can a user on most popular mobile devices to be automatically redirected to the mobile version of the site when they visit the main website.

So I went way back to some User-Agent sniffing to accomplish this. I thought I was done with the whole User-Agent redirecting different versions of site’s, but in this case it does work really well.

Just collect the User-Agent header using PHP there run it against a switch statement for each mobile device we’re checking against.

Just look for an instance of a device specific string using preg_match() in PHP.

iPod/iPhone and Android example:

case (preg_match('/ipod/i', $user_agent) || preg_match('/iphone/i', $user_agent));
        header('Location: ' . $redirect);
	exit;
break;
 
case (preg_match('/android/i', $user_agent));
        header('Location: ' . $redirect);
	exit;
break;
Categories
Development

Closure Compiler

I’ve been using minimizing tools on my Javascript files for quite some time now. Most notably YUI Compressor, and it does an awesome job for me. Excellent job minimizing Javascript as well as CSS files.

Recently I’ve give Closure Compiler a try at Javascript compression and have been pleased with the results so far. It not only minimizes and obfuscates files, but also compiles them as well.

The rewritten code it spits out is not suitable for human reading, so be sure you always keep an original of the source to be modified. I have typically been saving 24% off the original file size. That’s typically 2x the compression I’d get if I simply gzipped the file.

Very cool tool, try it out.

Categories
Development

Took care of pesky Smart Quotes with utf8_encode()

For the longest time I’ve had our writers at work who always copy from Word docs with Smart Quotes have our RSS feed balk when it encountered the Smart Quotes. I took many stabs attempting to replace them with standard quotes to no avail. It was one of those problems where I never really devoted a great deal of time at solving as it didn’t occur often enough to take me completely away from whatever issue I was then working on.

I just realized that the PHP utf8_encode() function which encodes an ISO-8859-1 string to UTF-8 does just that. Just a simple little function that’s been around a very long time was there just and I had overlooked it.

Now I just apply that function before outputting the data and so far so good. Just figured I’d share if someone else was running into this same issue.

Categories
Development

Automatic WordPress Backup

I just downloaded and installed the very cool Automatic WordPress Backup plugin. It automatically backups your WordPress blog to the Amazon S3 service. Since I already have an S3 account (which is awesome too by the way), this was an ideal solution for me.

Downloaded, install and setup took no more that 5 minutes tops. Not only was this incredibly easy to setup and manage, but it’s great to have backups not on the same server as my host or kept locally either. The only potential drawback would be that your host must be a Linux server, but this of course is not a problem for me.

If you have WordPress blog and an Amazon S3 account then this is most highly recommended.

Categories
Development

YUI 3 Awesomeness

I’ve been a huge fan of the YUI Library for quite some time now, using it in some form in almost all of my web projects done over the last 2+ years. Every now and then, I’m pleasantly surprised in just how useful it can be to me as a developer.

For instance, recently I’ve been working on building an application that will need an easy to use sortable list, that will fire off an event upon the list order changing. As simple as this sounds, it would require a lot of coding and cross browser testing to pull this one off with just javascript alone.

YUI 3 allowed me to accomplish the above in just a few minutes. I’m not even going to try to guess just how much time it’d of taken me to do on my own.

I made use of the Sortable Utility to make and unordered list sortable in just a few lines of code.

First I just added the YUI seed file to my page:

<script src="http://yui.yahooapis.com/3.1.1/build/yui/yui-min.js" type="text/javascript"><!--mce:0--></script>

Then just added a simple div and unordered list to my page:

 

Things I want

    • puppy dog

 

  • ice cream

 

 

  • G.I. Joe USS Flagg Aircraft Carrier

 

 

  • Lego bricks

 

 

  • iPad

 

 

  • Infinity Gauntlet

 

 

  • world peace

 

 

  • Star Scream

 

 

  • waffles

 

 

  • pb&j sandwich

 

 

And added the script that brings the unordered list to life:

YUI().use('sortable', function(Y) {
    var sortable = new Y.Sortable({
        container: '#want-list',
        nodes: 'li',
        opacity: '.1'
    });
});

That was it, a fully user sortable list!

I also needed this list to fire an event when a list item order had been changed. The Drag & Drop (DD) Utility has some nifty events that conveniently work with the Sortable Utility. So, I just added the following to my above script:

var doSomething = function() {
    	alert('do something');
	};
	Y.DD.DDM.on('drop:hit', doSomething);

When a drop:hit event occurs, it calls the doSomething function. In this case the doSomething function fires up an alert that says “do something”. It’s pretty basic and a rather useless alert, but it does demo what I’m working to do.

Again, YUI 3 is so awesome, that I easily spent more time writing up this little post than I did in making my above requirements happen. That’s really amazing to me. YUI 3 documentation is great, tons of examples there too.

Categories
Development

Indulge in Avalon

Indulge in AvalonLaunched the really cool website www.indulgeinavalon for the folks at the 7 Mile Business Community Association, it’s showcase for businesses in Avalon, NJ. This project was a lot of fun to work on, and the clients were great. They approached me with a very solid plan and and visual design, theyreally knew what they needed done.

Since they needed a site that they would be able to easily maintain, and this is 2010 after all, we decided that building it on the Joomla! CMS would be best for them. I’ve been using Joomla! a great deal recently to meet clients needs, and it’s really worked great for them too. It truly is amazing what open source offers.

The client also had a unique need to manage their properties in a way that didn’t exist in the Joomla! CMS. So I built them a custom component to handle that functionality. It was great, it makes use of Joomla’s built in admin, so it looks completely like the CMS interface, the client didn’t have to learn something completely new.

The component allows the client to add/update/delete business listings, and upload a photo that is automatically resized for them on upload. I used the WideImage library to handle the image resizing. I was thoroughly impressed with WideImage and highly recommend it and will surely be using it again.

The greatest part about this component to me was that I didn’t have to explain how to use it to the client, they just logged in and knew exactly what to do. As a developer, that’s the highest compliment I can think of is when somebody doesn’t notice your work because it just worked.

The site also makes use of the YUI2 CSS Grids for the site layout. I’ve been a huge fan of the YUI library in general, and found myself using them in yet another project (actually can’t think of the last project I haven’t really used YUI).

Since launching, the client has extended the text in the main navigation bar. It’s bumping a link to a new line, so I think I might contact them with a way to improve that. But besides that they’re doing an excellent job managing the site and it was a true pleasure working with them.

Check out www.indulgeinavalon.com