Loading rico1 and rico3 files
[infodrom/rico3] / examples / php / flickrPhotos.php
1 <?php
2 header("Cache-Control: no-cache");\r
3 header("Pragma: no-cache");\r
4 header("Expires: ".gmdate("D, d M Y H:i:s",time()+(-1*60))." GMT");\r
5 header("Content-type: text/xml");\r
6 echo "<"."?xml version='1.0' encoding='UTF-8'?".">\n";\r
7 \r
8 include("../../plugins/php/class.xml.parser.php");
9
10 // -----------------------------------------------------------------------------
11 // This script takes a "tags" parameter from the query string
12 // and returns a list of flickr photos with that tag in the Rico LiveGrid format
13 //
14 // PLEASE USE YOUR OWN FLICKR API KEY
15 // Get one at: http://flickr.com/services/
16 //
17 // Created by Matt Brown, Dec 2007
18 // -----------------------------------------------------------------------------
19
20 $flickrKey="3773d42a5766f0bd27caa1d584ae0bc9";\r
21 $id=isset($_GET["id"]) ? $_GET["id"] : "";\r
22 $tags=isset($_GET["tags"]) ? $_GET["tags"] : "";
23
24 echo "\n<ajax-response><response type='object' id='".$id."_updater'>";\r
25
26 print "\n<rows update_ui='true'>";
27
28 $url="http://api.flickr.com/services/rest/?method=flickr.photos.search";
29 $cnt=0;
30 if ($tags != "") {
31   $url.="&safe_search=1";
32   $url.="&tag_mode=all";
33   $url.="&sort=interestingness-desc";
34   $url.="&extras=date_taken,owner_name,geo,tags";
35   $url.="&tags=".$tags;
36   $url.="&api_key=".$flickrKey;
37   $parser = new xmlParser();
38   $parser->parse($url);
39   $status=$parser->output[0]['attrs']['STAT'];
40   
41   // FOR DEBUGGING PURPOSES
42   //print $status;
43   //print "<hr><pre>";
44   //print_r($parser->output);
45   //print "</pre>";
46
47   $content=&$parser->output[0]['child'][0]['child'];
48   foreach ($content as $item) {
49     if ($item['name'] == "PHOTO") {
50       print "<tr>";
51       // "_s" suffix specifies a 75x75 pixel format
52       $photourl="http://farm".$item['attrs']['FARM'].".static.flickr.com/".$item['attrs']['SERVER']."/".$item['attrs']['ID']."_".$item['attrs']['SECRET']."_s.jpg";
53       //print "<p><img src='".$photourl."'>";
54       print XmlCell($photourl);
55       print XmlCell($item['attrs']['TITLE']);
56       print XmlCell($item['attrs']['OWNERNAME']);
57       print XmlCell($item['attrs']['DATETAKEN']);
58       print XmlCell($item['attrs']['TAGS']);
59       print "</tr>";
60       $cnt++;
61     }
62   }
63 }
64
65 print "\n"."</rows>";\r
66 echo "\n</response></ajax-response>";
67
68 function XmlCell($value) {\r
69   return "<td>".htmlspecialchars($value)."</td>";\r
70 }\r
71
72 ?>