Posts Tagged ‘HTML’
Displaying your latest statuses from Twitter February 6th, 2013
After a couple of years at IE I’ve moved on to pastures new and started work as a technical consultant at Farringdon based tech agency Amido. This move has allowed me to finally return to the LAMP stack after a two year absence and it feels good. In celebration of that here’s a little PHP something.
Latest Tweets from @scriptic
Amazing long weekend in Bude, sun, sea and sand!
May 06, 2013
Mouse Taxidermy! The new @WeAreAmido London office mascot. http://t.co/GNnOxPMTxG
May 03, 2013
Feeling pretty virtuous after first cycle commute into central London this morning. Hope my legs are up to the return journey.
May 01, 2013
So at some point between me implementing my new theme and a couple of weeks ago the Twitter feed on this site stopped working. After a little investigation I discovered that Twitter have changed the way their APIs work so I had to rebuild the functionality in my theme. Now with version 1.1 of the Twitter API it’s nice and easy, as long as you use OAUTH, to embed tweets on your page ready formatted with all the bells and whistles in place. It looks great but I guess not everyone, including me, wants that – so, after some very brief research garnered no results in regards to returning just a block of HTML for the status rather than the whole widget, I decided to cobble something together myself. A process which I shall share with you now.
First off, I didn’t do all this alone – I used the very handy tmhOAuth library by Matt Harris to take care of the authentication stuff, so you’ll need to grab that before we begin (it’s also included in this handy download of all the code you see here ready to go). While we’re on the subject you’ll also need to do all the Twitter application prep work before this’ll work. You can learn about that here.
So once you’ve got all that sorted we need to write some code. First off you need to call the Twitter API and grab your JSON object using ‘user_timeline’. The two variables in the request are your Twitter username and count, which is the number of tweets you wish to return.
<?php // Require files from the OAuth library require 'tmhOAuth.php'; require 'tmhUtilities.php'; function getTweets(){ //OAuth $tmhOAuth = new tmhOAuth(array( 'consumer_key' => 'YOUR CONSUMER KEY', 'consumer_secret' => 'YOUR CONSUMER SECRET', 'user_token' => 'YOUR USER TOKEN', 'user_secret' => 'YOUR USER SECRET', )); // Request $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array('screen_name' => 'username', 'count' => 3)); $response = json_decode($tmhOAuth->response['response']); } ?> |
So that’ll return a handy JSON object with everything you need to retrieve your Twitter stream, now if you want to just embed Twitters beautiful widgets you can grab the status ID from that object and use oembed but all I want is the tweet text and the date. Fortunately both of these are included in the object and can be extracted like so:
<?php foreach($response as $obj){ echo $obj->text . '<br />'; echo $obj->created_at . '<br /><br />'; } <? |
All good, except you’ll notice that all you have is a couple of raw text strings, for my purposes I’d like the time stamp to be a little simpler and obviously I’d like all the hash-tags, mentions and links to be in-tact and working. So date first – we can just write a little function to extract and re-order the bits you want.
<?php echo formatdate($obj->created_at); function formatdate($date){ $dateseg = explode(' ', $date); return $dateseg[1] . ' ' . $dateseg[2] . ', ' . $dateseg[5]; } ?> |
This just explodes the date string into separate elements and then reorders it into a nice simple ‘Jan 09, 2013’ type format. When that’s done we need to tackle the more complicated task of ensuring all the links come out intact. Fortunately that JSON object we retreived earlier contains all the information you need to do that – each hash-tag, mention and link has it’s own little array containing display text, shortened link and full link – so all we need to do is scan through our tweet and do some text replacing:
<?php echo formattweet($obj->entities->urls, $obj->entities->user_mentions, $obj->entities->hashtags, $obj->text); function formattweet($links, $mentions, $hashtags, $tweet){ $buildtweet = $tweet; foreach($links as $link){ $buildtweet = str_replace($link->url, '<a href="' . $link->url . '" target="_blank">' . $link->display_url . '</a>', $buildtweet); } foreach($mentions as $mention){ $buildtweet = str_replace($mention->screen_name, '<a href="http://twitter.com/' . $mention->screen_name . '" target="_blank">' . $mention->screen_name . '</a>', $buildtweet); } foreach($hashtags as $hashtag){ $buildtweet = str_replace($hashtag->text, '<a href="http://twitter.com/search?q=%23' . $hashtag->text . '&src=hash" target="_blank">' . $hashtag->text . '</a>', $buildtweet); } return $buildtweet; } ?> |
And now we have a nice simple block of HTML containing your tweet which you can embed and display any way you like. Which is exactly what I’ve done at the top of this post and, when I get around to it, on the sidebar of this theme. If you happen to know that there’s a much simpler, ready made, way of achieving this then please let me know so I can take this post down and save myself some embarrassment.
Thanks all!
Three Column Stretchy HTML layout November 2nd, 2012
OK first off, apologies for the delay between posts there. As I’m still working at IE at the moment I’m still not getting to do a lot of work that I can actually stick on this blog and what with the wedding this year and all I haven’t done an awful lot of work in my free time either. With that in mind I’ve decided, instead of adding some new content, I’ll just fill the gap for now with something recycled from CoderSphere. When I originally posted about the CoderSphere project I said I would transfer some stuff over so here goes.
I’ve always struggled to achieve a good stretchy layout – two static width side columns and a stretchy middle – and, until I came to accept JavaScript as an inevitability, it’s something I avoided.
You see the issue for me with this layout was that, due to the absolutely positioned sidebars, it was practically impossible to achieve properly without using some JavaScript to ensure that the heights all matched up and the rest of the page flowed correctly. For CoderSphere I decided the time had come when this was no longer an issue and so I built the HTML, added some emergency ‘no JS’ CSS and then created a little JS snippet to make sure everything worked as it should. All of this I detail below.
So first off – the basic HTML structure:
<div class="container">
<div class="left">Left Column</div>
<div class="middle">Centre Column</div>
<div class="right">Right Column</div>
</div> |
Here we have a container div and then my three stretchy columns. the left and right columns are fixed width, absolutely positioned elements and the central div will stretch to fill the rest of the space, to do this however it needs some CSS:
.container { position:relative; margin:10px; min-width:300px; } .container div { border:1px solid #999999; padding:10px; } .left { position:absolute; left:0; top:0; width:80px; } .middle { margin:0 110px; } .right { position:absolute; right:0; top:0; width:80px; } |
Here’s the result:
It’s hard to see the actual result here as I have a fixed width container around it but try it yourself and you’ll see.
So now everything’s sorted. Simple eh? unfortunately there’s a problem. Because the two side columns are positioned absolutely if the content in either of those happens to be longer than the content in the central column they will overlap anything beneath them in your page layout (for example your page footer, sitemap etc…).
I fixed this in two ways. First I put together some CSS, to be included in the event that JavaScript is disabled on the page, that will do a basic but ugly job of ensuring this isn’t a problem:
.left { max-height:600px; overflow-y:scroll; } .right { max-height:600px; overflow-y:scroll; } .middle { min-height:600px; } |
So this will ensure that the central column is always as tall, or taller, than either of the two side columns. The drawback of this as a sole solution is that you’ll have ugly vertical scrollbars on the two sidebars if their content happens to be greater than 600px high. So, as I mentioned, we only include this if JS is unavailable:
<noscript><link rel="stylesheet" href="nojs.css" /></noscript> |
And then we write some JavaScript to do a much more elegant job of it:
$(document).ready(function() { sizeColumns(); $(window).resize(function(){ sizeColumns(); }); }); function sizeColumns(){ $('.left, .middle, .right').removeAttr('style'); var hArray = [$('.left').outerHeight(), $('.middle').outerHeight(), $('.right').outerHeight()]; var maxHeight = 0; for(var key in hArray){ if(hArray[key] > maxHeight){ maxHeight = hArray[key]; } } $('.central-column').css('height' , (maxHeight + 20) + 'px'); } |
This basically loops through the three divs, checks which one is tallest and then ensures that the central, content column matches the height (and adds a little more for good measure). It also ensures it re-fires on page resize. So now we have our flexible, three column layout with everything flowing into place nicely beneath – as seen on CoderSphere.
A jQuery accordion plug-in August 23rd, 2012
Today I finished building a beautiful jQuery accordion plug-in which hopefully will end up in a suite of plug-ins and jQuery bits and pieces in the companies new product offering next year.
This is quite a long post but my other jQuery posts have all been a bit boring so I thought I’d make a bit more out of this one and add some more examples, instructions etc.
The plug-in works best when attached to a <dl> HTML element although as long as you structure your code in a similar way you can use anything you like with a bit of tweaking of the parameters.
Example 1
The list below is what you will get if you apply the plugin to a <dl> without changing any parameters.
- Item title One
- Item content One
- Item title Two
- Item content Two
- Item title Three
- Item content Three
Example 1 code
$('#list1').siAccordian();
Example 2
Now one with a few of the parameters set for a slightly fancier experience.
- Item One here’s a non clickable sub heading
- List content One
- Item Two here’s a link that wont expand the list
- List content Two
- Item Three
- List content Three
Example 2 code
$('#list2').siAccordian({
instigateElement : ' > a:first-child',
startOpen : 0,
collapseSiblings : true,
animate : true,
openClass : 'contract'
});
So there it is. There are a few more parameters to play around with, they’re all listed in the JS file. Most notably there’s a ‘save state’ parameter which will use a cookie to remember the state of the list when you navigate away from the page so that when you return the page is as you left it.
As I said at the beggining I’ve literally finished this today and it has yet to go through proper QA so there are doubtless a few bugs. Please download the files and have a play with it, but please let me know if you find any bugs and if you don’t mind, leave the credits in the JS file in-tact.
Cheers, Scriptic
CoderSphere June 27th, 2012

www.coderpshere.com
Several months ago myself and Sean McAlinden, a colleague of mine, came up with an idea for a site where web developers and professionals like ourselves could build themselves an online profile. So we built www.coderpshere.com, it started out as a basic blogging tool and the idea was we would keep expanding the functionality until it became, basically, a place for everything. We quickly added code snippet functionality, an image gallery, a wiki and a private favourites repository.
You can see all this in action at the site, however, for now, we have decided to remove the public sign up aspect of the site so it is no longer accessible to any old Tom, Dick and Harry. This is largely due to concerns about whether we had thought through things like scalability and how much time we could afford to spend actually supporting the site properly. So for now it’s just a site where Sean and I can start to build up our own store of code snippets and how to’s. If you can see potential and desperately want to be an early adopter though please drop me an email or comment via this blog and I’ll see what I can do.

As for the tech involved – the site is built with the Razor MVC engine for .net and although I was acting as designer and front ender on this and didn’t get involved with much of the back end nitty gritty it was great to get a bit of experience in it. The front end, of course, is HTML / CSS with the odd bit of JQuery for form styling and validation (it’s also the first time I’ve used AdSense).
I’ll probably be writing a number of blog posts around CoderSphere over the next few months so keep checking for updates. There’s also a couple of posts I’ve written on my CoderSphere blog which I’ll be replicating here fairly soon. Also, if you like, you can follow CoderSphere on Twitter.
Wedpings! February 18th, 2012

www.wedpings.com/siandkasia
Sorry for the gap, and no Christmas post – a terrible state of affairs. Never mind though, here’s something to cheer you up – it’s our wedding page. The first entry on wedpings.com. A little side project for me which I intend to turn into a sort of social network for wedding planning. There’s not much there at the moment, as you’ll see if you visit the home page, but the intention is to start adding features soon. User accounts, wedding list organisation and RSVPs, photo galleries, venue information and maps – that sort of thing. To be honest I haven’t really spec’d it out yet but hopefully i’ll get round to it eventually. Drop me an email if you’d be interested in using such a service
.
For now our page is just a bit of HTML and jQuery with a simple RSVP form – it just sends us an email with a yes or no. Nothing fancy but I was quite pleased with the design. Hopefully in a few months there’ll be a new Wedpings post announcing a proper site. We’ll see.
To the happy couple!