August, 2009


21
Aug 09

Add your Ember images to your site!

This is a very quick post of how I added my Ember feed on the right.

1. The function

Simply use this function I created :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
function ember_thumbs( $options = null )
{
 
	# ARE THERE OPTIONS?
	
	if( !$options )
		return;
 
	$feed = 'http://emberapp.com/'.urlencode( $options['username'] ).'/images.rss';
 
	# CREATE NEW DOM DOCUMENT FOR EASE OF PARSING THE FEED
	
	$dom = new DOMDocument;
 
	# LOAD THE FEED
	
	$dom->loadXML( file_get_contents( $feed ) );
 
	# GRAB THE ITEMS FROM THE FEED
	
	$images = $dom->getElementsByTagName( 'item' );
 
	$imgs = array();
 
	# LOOP THROUGH EACH OF THE ITEMS
	
	foreach( $images as $image )
	{	
 
		# TEMP ARRAY
		
		$t = array();
 
		# LOOP THROUGH EACH CHILD NODE
		
		foreach( $image->childNodes as $child )
		{
 
			# IF THE CHILD HAS ATTRIBUTES, SUCH AS THE media:thumbnail TAG
		
			if ( $child->hasAttributes() ) 
			{
				$t[$child->nodeName] = array();
				$t[$child->nodeName]['nodeValue'] = $child->nodeValue;
				$attributes = $child->attributes;
				foreach( $attributes as $at => $att )
					$t[$child->nodeName][$at] = $att->nodeValue;
			} else
				$t[$child->nodeName] = $child->nodeValue;
		}
 
		# PUSH THE TEMP ARRAY INTO THE OVERALL ARRAY
		
		array_push( $imgs, $t );
	}
 
	# CONSTRUCT A STRING
	
	foreach( $imgs as $image )
		if( $i++ < $options['limit'] )
			$string .= '<a class="ember_image" href="'.$image['link'].'" title="'.$image['title'].'"><img src="'.$image['media:thumbnail']['url'].'" width="'.$options['size'].'" height="'.$options['size'].'" /></a>';
 
	# CLEAR FROM MEMORY
	
	unset( $temp );
 
	# RETURN THE STRING
	
	return $string;
 
}
?>

2. Using the function

To use the function, simply parse in an array of options, which are :

  • username
  • limit
  • size

For example :

1
2
3
4
5
6
7
<?php 
	echo ember_thumbs( array(
		'username' => 'curthard89',
		'limit' => 6,
		'size' => 92
	));
?>

Username being your username, limit being how many thumbs you want to display and size is the width and height of the image, once thats done, style till your heart is content.

If you have any questions or mods or anything be sure to leave a comment!


20
Aug 09

I am alive

Hola!

Its been a hell of along time since I posted anything on this blog. I wanted to post something a few days back and really hated the look and feel of the site…so I totally went and did it, I totally scrapped the other one and thus this new site was born. Although it says development blog at the top, this site will consist of geeky tutorials aswell, from the depths of the languages such as COCOA, ActionScript, JavaScript, PHP and anything else that seems to crop into my head. I plan on putting a tutorial on this site every week, or really anything thats rather geeky that I stumble across or have the urge to tell people about.