Etomite (basic) Flickr script

Flickr is a photo management and sharing application where you can upload your photos and share them.

This script displays someones public photos on any page in Etomite. Basic and simple flickr integration, shows public photos or favorite public photos.

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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 flickr-basic v0.1
 A Etomite script by bogge, bogge.com
 I take no responsibility for any thing, even if I'm to blame.
 
 Usage
 Get an yahoo API key, and enter it in the settings.
 [ [flickr-basic]] Shows 100 om my latest public photos. Change user in settings to show other photos.
 [ [flickr-basic?picsize=m&per_page=10]] Shows 10 small photos.
 [ [flickr-basic?picsize=t&per_page=2&nsid=XXXXXXXX@NXX]] Show 2 thumbnail photos of user X
 I think you get it...
 
 Settings
*/
$api_key = 'API_KEY_REQUIRED'; // API key (Required) www.flickr.com/services/api/keys/apply/
// Cache
$userequestcache = true; // Set to false to disable, using requestcache speeds up the script.
$usephotocache = false; // Set to true to enable.
$cachedir = isset($cachedir)? $cachedir: "cache/"; //cache location
$age = isset($age)? $age: "43200"; // 12h for the requests, not the photos.
 
// Format
$dateformat = isset($dateformat)? $dateformat: "%G-%m-%d %R"; // See strftime for other settings.
$picsize = isset($picsize)? $picsize: "s"; // "s" = small square 75x75, "t" = thumbnail, 100 on longest side, "m" = small, 240 on longest side, "b" = large, 1024 on longest side (only exists for very large original images)
 
// Extra information
$extras = isset($extras)? $extras: ""; // A comma-delimited list of extra information to fetch for each returned record. Currently supported fields are: license, date_upload, date_taken, owner_name, icon_server, last_update, geo, tags, machine_tags.
 
// Pages
$per_page = isset($per_page)? $per_page: "100"; // Number of photos to return per page. Default 100 pictures per page.
$page = isset($page)? $page: "1"; // The page of results to return. Default first page.
 
// User
$nsid = isset($nsid)? $nsid: "7786210@N02"; // Default user, nsid only.. 
 
// Action, What to do.
$method = isset($method)? $method: "flickr.people.getPublicPhotos"; // Defult method
// flickr.people.getPublicPhotos = Get a list of public photos for the given user.
// flickr.favorites.getPublicList = Returns a list of favorite public photos for the given user.
 
// Do not edit below
function EtomiteErrorHandler($errno, $errstr, $errfile, $errline)
{
    return true;
}
 
// build the API URL to call
 
$params = array(
	'api_key'	=> $api_key,
	'user_id'	=> $nsid,
	'method'	=> $method,
	'per_page'	=> $per_page,
	'page'		=> $page,
	'extras'	=> $extras,
	'format'	=> 'php_serial',
);
$encoded_params = array();
foreach ($params as $k => $v){
	$encoded_params[] = urlencode($k).'='.urlencode($v);
}
 
// call the API and decode the response
 
$url = "http://api.flickr.com/services/rest/?".implode('&', $encoded_params);
if ($userequestcache) {
//Cache start
	$old_error_handler = set_error_handler("EtomiteErrorHandler");
		$filename = $cachedir.md5($url);
		// default to fetch the file
		$fetch = true;
		// but if the file exists, don't fetch if it is recent enough
		if (file_exists($filename)) {
			$fetch = (filemtime($filename) < (time()-$age));
		}
		if ($fetch) {
			$rsp = @file_get_contents($url);
			if($rsp) {
				$fp_dst = fopen($filename,"w");
				if($fp_dst) {
					fwrite($fp_dst,$rsp);
					fclose($fp_dst);
				}else{
					fclose($filename);
					$rsp = @file_get_contents($filename);
				}
			}else{
				$rsp = @file_get_contents($filename);
			}
		}else{
			$rsp = @file_get_contents($filename);
		}
	restore_error_handler();
//Cache end
}else{
$rsp = @file_get_contents($url);
}
if (!$rsp) {
$output .= 'Error connecting to Flickr. Please try again later.';
}else{
$rsp_obj = unserialize($rsp);
 
// display the photo (or an error if it failed)
 
if ($rsp_obj['stat'] == 'ok'){
	$output .= 'Page: '.$rsp_obj['photos']['page'].' of '.$rsp_obj['photos']['pages'].' pages. 
';
	$output .= 'Number of photos on this page: '.$rsp_obj['photos']['perpage'].' of '.$rsp_obj['photos']['total'].' photos.
';
	foreach ($rsp_obj['photos']['photo'] as $photo) {
		$bildlink = 'http://www.flickr.com/photos/'.$photo['owner'].'/'.$photo['id'].'';
		$bildname = $photo['id'].'_'.$photo['secret'].'_'.$picsize.'.jpg';
		$bildsrc = 'http://farm'.$photo['farm'].'.static.flickr.com/'.$photo['server'].'/'.$bildname;
		if ($usephotocache) {
		//Cache start
		$old_error_handler = set_error_handler("EtomiteErrorHandler");
		    	$filename = $cachedir.$bildname;
		    	if (file_exists($filename)) {
				$file = $filename;
		    	}else{
				$fetchedpic = @file_get_contents($bildsrc);
				if($fetchedpic) {
					$fp_dst = fopen($filename,"w");
					if($fp_dst) {
						fwrite($fp_dst,$fetchedpic);
						fclose($fp_dst);
						$file = $filename;
					}else{
						$file = $bildsrc;
						fclose($filename);
					}
				}else{
					$file = $bildsrc;
				}
			}
		restore_error_handler();
		//Cache end
		}else{
			$file = $bildsrc;
		}
		$output .= '
<div style="float:left;"><a onclick="javascript:urchinTracker(\'/outgoing/'.$bildlink.'\')" href="'.$bildlink.'">';
		$output .= '<img title="'.$photo['title'].'" src="'.$file.'" alt="'.$photo['title'].'" /></a>
';
		if (isset($photo['license'])) {
			if ($photo['license'] == '1') {
				$license = '<a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">Attribution-NonCommercial-ShareAlike License</a>';
			}elseif ($photo['license'] == '2') {
				$license = '<a href="http://creativecommons.org/licenses/by-nc/2.0/">Attribution-NonCommercial License</a>';
			}elseif ($photo['license'] == '3') {
				$license = '<a href="http://creativecommons.org/licenses/by-nc-nd/2.0/">Attribution-NonCommercial-NoDerivs License</a>';
			}elseif ($photo['license'] == '4') {
				$license = '<a href="http://creativecommons.org/licenses/by/2.0/">Attribution License</a>';
			}elseif ($photo['license'] == '5') {
				$license = '<a href="http://creativecommons.org/licenses/by-sa/2.0/">Attribution-ShareAlike License</a>';
			}elseif ($photo['license'] == '6') {
				$license = '<a href="http://creativecommons.org/licenses/by-nd/2.0/">Attribution-NoDerivs License</a>';
			}else{
			$license = 'All rights reserved.';
			}
			$output .= 'License: '.$license.'
';
		}
		if (isset($photo['dateupload'])) { $photo['dateupload'] = strftime($dateformat,$photo['dateupload']); $output .= 'Date uploaded: '.$photo['dateupload'].'
';}
		if (isset($photo['datetaken'])) { $output .= 'Date taken: '.$photo['datetaken'].'
';}
		if (isset($photo['ownername'])) { $output .= 'Owner: '.$photo['ownername'].'
';}
		if (isset($photo['iconserver'])) {
			if ($photo['iconserver'] &gt; "0") {
				$output .= '<img src="http://farm'.$photo['iconfarm'].'.static.flickr.com/'.$photo['iconserver'].'/buddyicons/'.$nsid.'.jpg" alt="" width="48" height="48" />
';
			}else{
				$output .= '<img src="http://www.flickr.com/images/buddyicon.jpg" alt="" width="48" height="48" />
';
			}
		}
		if (isset($photo['lastupdate'])) { $photo['lastupdate'] = strftime($dateformat,$photo['lastupdate']); $output .= 'Last updated: '.$photo['lastupdate'].'
';}
		if (isset($photo['latitude'])) { $output .= 'Lat: '.$photo['latitude'].', Long: '.$photo['longitude'].', Acc: '.$photo['accuracy'].'
';}
		if (isset($photo['tags'])) { $output .= 'Tags: '.$photo['tags'].'
';}
		if (isset($photo['machine_tags'])) { $output .= 'Machine tags: '.$photo['machine_tags'].'
';}
		$output .= '</div>
';
	}
}else{
 
	$output = '
 
'.$rsp_obj['stat'].'
 
';
	$output = '
 
'.$rsp_obj['message'].'
 
';
}
}
return $output;

0 Responses

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.