Tech, Gaming and Food Enthusiast
Archive for August, 2010
Cropping images with CodeIgniter and jQuery
Aug 27th
The art to having a website with decent imagery is to allow the user/administrator to crop the images. Despite advancing web technologies, I still cannot trust a computer to scale, resize or crop an image without the resulting image being of someones foot.
There are certain ‘off-the-shelf’ products, mainly for ASP.net, with very little introduced into PHP, so I had to build my own using helpful libraries and plugins.
The Cropping
Writing a JavaScript cropping tool from scratch is no small challenge, getting a bug-free environment where all of the calculations are perfect can take weeks of hairless programming sessions and various mental breakdowns! And with my hair still in tact and mental capacity intact I implemented jCrop (I let someone else do the hard work). I am continuously reminding people that reinventing the wheel is both a waste of time, energy and sanity but the odds are against you. If a plugin is popular then the chances are that their solution will be 10 times better than yours as theirs have probably evolved over several months if not years!
Implementing oAuth Twitter with Code Igniter
Aug 25th
On August 31st Twitter will be axing basic auth GET requests, which is being overtaken by the more secure oAuth, there are a few tutorials out there on how to use oAuth and how to get started creating an app with CodeIgniter, but not many with actually helpful advice so here is my 2 penneth.
How to get started with oAuth
Detecting Mobile devices with WURFL and PHP
Aug 23rd
The Wireless Universal Resource File (WURFL) is an open source device library which describes itself as follows:
The WURFL is an “ambitious” configuration file that contains info about all known Wireless devices on earth. Of course, new devices are created and released at all times. While this configuration file is bound to be out of date one day after each update, chances are that the WURFL lists all of the WAP devices you can purchase in the nearest shops.
This configuration can be combined with their shiny new PHP and Java API’s to interrogate the user’s UAProf or USERAGENT strings to pin point the type of device the user is browsing on.
So how do we use it. The first step is to set the WURFL config file (wurfl-config.xml) which may look something like this.
Then to use the API, for this example I will be using the PHP API.
<?php
require_once 'WURFL_installation_root/WURFL/WURFLManagerProvider.php';
$wConf = 'Relative path to wurfl-config.xml';
$wManager = WURFL_WURFL_ManagerProvider::getWURFLManager($wConf);
$info = $wManager->getDeviceForHttpRequest($_SERVER);
?>
This code will load a large object of UAProf information which can be interrogated using the WURFL API functions (See Documentation).
It is so simple but very powerful and accurate, I would highly suggest giving it a try:
Codeigniter Database session fix
Aug 23rd
For weeks I tolerated the annoyance of CodeIgniter’s Session library logging my out continuously, saying to myself “I works…kind of… ill fix it later”. Eventually the problem started affecting AJAX method calls, large file uploads and simple CRUD operation forms so I began trawling the internet for a fix.
After hours and hours, I found that there was no _reliable_ fix to the database sessions library and that the answer was, DON’T USE DATABASES.
I found this extremely helpful library fix: CI_Native_Session.