Skip to main content

Posts

Showing posts from 2011

Listing event handlers tied to DOM elements with jQuery and Firebug

I'm busy hacking a template from an existing source to fit into a new Cake backend.  The template is pretty well written but I need to update the way in which content is being loaded and displayed.  Currently the site loads the *entire* site into one page and then flipping the visibility of elements in order to simulate dynamic loading.  Of course this works fine for the demo site the template loads, but is not going to fly for a production site. I ran into the problem of having to work out where the event handlers are being declared for various elements on the page.  I was faced with the task of trekking through 15 files of Javascript.  Okay some are obviously not candidates (like jQuery.js itself) but that's still a mission. Luckily jQuery has an extra bit of goodness that made the task trivial.  It stores event handlers in the data attribute (read up about that here  http://api.jquery.com/jQuery.data/  ). Using Firebug you can open y...

Caching your Twitter feed on your website in PHP

Instead of reinventing the wheel I'm going to copy the script found at css-tricks.com ( click here ) function getTwitterStatus($userid){ $url = "http://twitter.com/statuses/user_timeline/$userid.xml?count=1"; $xml = simplexml_load_file($url) or die("could not connect"); foreach($xml->status as $status){ $text = $status->text; } echo $text; } //my user id kenrick1991 getTwitterStatus("kenrick1991"); I'm leaving the original author's Twitter ID in there, but obviously you'll change this to yours. This function will retrieve the most recent Tweet from your feed (see the "count=1" variable in the URL). But it will request this every time the page loads. The most simple caching strategy is to write your Twitter status to disk, and when your page loads check the timestamp of the file against the value returned by time(). If it exceeds whatever threshold you deem appropriate you ...

Microsoft Internet Explorer - a "special needs" browser

When developing a website I usually consider how long it will take to code the site, template it, and test it.  Then I add a whole lot of extra time to make it work in Internet Explorer. A Microsoft User - ready to use the interweb In a way Microsoft's refusal to believe that there is a world of computing outside of Redmond is a good thing - it means that I get more billable hours per project.  Of course those billable hours are spent in frustrating searches through Google to try and work out all of the various quirks and bugs in Internet Explorer. I tend to think of Microsoft Internet Explorer users as "special needs" kids who are being set loose in the playground that is the Internet.  Barely able to prevent themselves from drooling on their keyboards and eating their mouses they demand that websites conform to their special needs.  Standards such as Javascript DOM level 2, HTML5, CSS, CSS3 are pretty much ignored because their parent doesn't believe in mode...

CakePHP : Changing .htaccess to prevent one (or more) directory from being handled by Cake

This technique may be useful if for example you have decided to use Wordpress to handle your blog, rather than trying to code your own competing blog system. This .htaccess file is based on the CakePHP default but simply adds a rewrite rule to exclude the "blog" directory from Cake's control. <ifmodule mod_rewrite.c=""%gt; RewriteEngine on RewriteRule ^(blog).* - [NC,L] RewriteRule ^blog /blog [L] RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </ifmodule%gt; If you want to prevent Cake from controlling multiple directories you can simply modify the rewrite rule like such: RewriteRule ^(blog|my|other|directories|go|here).* - [NC,L] In order to accomplish this on an IIS server you can email sballmer@microsoft.com and ask for support in getting his expensive software to do what it says it does on the box.

CakePHP : Adding a file upload and adding a select list of URLs for users in a CMS

CakePHP automagically generates textboxes for users, but it's usually a project requirement that these boxes are "user friendly". Adding CK editor to CakePHP is easy, but lets go a few steps further and give it the ability to allow users to upload images directly into their content and to select a list of pages when creating a link. This article is based heavily on two articles ( Adding file upload in CK editor and Adding a ‘Link to local page from site’ field ) which I have simply modified to be CakePHP specific. So all credits to Ben Roberts and Zac. Step 1 - Adding CK editor to CakePHP with the FileManager plugin 1) Download CK editor from the official site and unzip it into your /app/webroot/js directory. To make things easy I put it in /app/webroot/ckeditor directory. 2) Download FCK editor from the same site.  It was at the bottom of the CK downloads page (because it is deprecated).  Unzip it to a temporary directory and copy the filemanager directory (fcke...

Hassles with Uniforum and co.za registration

Dreams of Technology foiled by pokey companies I've previously found that the Uniforum email form does not allow for providing more than a certain, fixed, number of nameservers.  Apparently nobody would ever require more than that number.  Well unless they're using a high availability DNS service (like www.dnsmadeeasy.com) that is.  If you happen to be using more nameservers than Uniforum has determined to be the maximum that South Africans need then they won't register your domain. More recently I've found that they don't like nameservers where the FQDN lookup doesn't match the reverse lookup.  This is pretty much understandable, but what I don't understand is why it was working for a particular host I use until a month ago and is now no longer working. I raised a support ticket with Uniforum and it took them a good couple of days to come back to me.  I wonder how a company that charges R 50 for every single co.za domain offers such poor service and ...