Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 93 lines (67 sloc) 1.634 kb
0981403 @iamcal made the photo widget work - very similar to the browser widget
authored
1 <?
2 include('include/init.php');
3
4
5 #
6 # get data
7 #
8
9 $tag_enc = AddSlashes($_GET['tag']);
10 $tag_row = db_single(db_fetch("SELECT * FROM tube_photocache WHERE tag='$tag_enc'"));
11
12 $refresh = 1;
13 $cache_age = 60 * 60; # 1 hour in seconds
14
15 if ($tag_row['id']){
16 if ($tag_row['date_update'] + $cache_age > time()){
17 $refresh = 0;
18 }
19 }
20
21
22 #
23 # refresh data from flickr is necessary
24 #
25
26 if ($refresh){
27
28 $url = "http://www.flickr.com/services/feeds/photos_public.gne?tags=".urlencode($_GET['tag'])."&format=rss_200";
29 $feed = implode('', file($url));
30
31 if ($tag_row['id']){
32 db_update('tube_photocache', array(
33 'date_update' => time(),
34 'data' => AddSlashes($feed),
35 ), "tag='$tag_enc'");
36 }else{
37 db_insert('tube_photocache', array(
38 'tag' => $tag_enc,
39 'date_update' => time(),
40 'data' => AddSlashes($feed),
41 ));
42 }
43 }else{
44 $feed = $tag_row['data'];
45 }
46
47
48 #
49 # parse data
50 #
51
52 preg_match_all('!<item>.*?</item>!si', $feed, $matches);
53
54 $photos = array();
55
56 foreach ($matches[0] as $match){
57 preg_match('!<link>(.*?)</link>!', $match, $m);
58 $link = $m[1];
59
60 preg_match('!<title>(.*?)</title>!', $match, $m);
61 $title = $m[1];
62
63 preg_match('!http://farm(.*?)_m\.jpg!', $match, $m);
64 $src = "http://farm$m[1]_s.jpg";
65
66 $photos[] = array(
67 "title" => $title,
68 "link" => $link,
69 "src" => $src,
70 );
71
72 }
73
74 $smarty->assign('photos', $photos);
75 $smarty->assign('tag', $_GET['tag']);
76
77
78 #
79 # test mode just returns the html. easier for seeing the raw html
80 #
81
82 if ($_GET['test']){
83 $smarty->display('inc_photos_html.txt');
84 exit;
85 }
86
87
88 #
89 # output
90 #
91
92 $smarty->display('js_photos.txt');
93 ?>
Something went wrong with that request. Please try again.