Search This Blog

Saturday, April 19, 2008

Make a Yahoo Pipe and publish it using PHP

I really enjoy playing with the web and all the social tools. There is something that is quiet well advanced called Yahoo! Pipes. With Yahoo!Pipes you can reuse contents on the web and republish it in another form without programming.

Look at the following. The following Pipe allows me to collect 4 feeds (different places where you can comment my posts) and republish it as once.

To do that you drag & drop :
- 4 "Fetch Feed" Sources : you have to give the URL of the rss feed
- the "Union" Operator it merges the 4 feeds into 1
- the "Sort" Operator which allows to sort the new feed - by date descending for instance.

You can see the result of this Pipe here : Comments

There are much more drag&drops you can do. Check it out on Yahoo! Pipes by creating a new pipe.

After that what you want to exploit your new feed, you can burn it or obtain it as a bagde...


I personnaly use the PHP feature. The result can be streamed as a php array.

Here is the code I use to exploit my Yahoo! Pipe (download it here):

1 <!-- get comments via Yahoo Pipes -->

2

3 <?php

4

5 // Pipes Request

6 $req = 'http://pipes.yahoo.com/pipes/pipe.run?_id=YEJ5xyMG3RGadogljknRlg&_render=php';

7

8 // Make the request

9 $phpserialized = file_get_contents($req);

10

11 // Parse the serialized response

12 $phparray = unserialize($phpserialized);

13

14

15 echo "<table width=120 border=1>";

16 //Loop through all items of the feed

17 foreach ($phparray['value']['items'] as $item) {

18 //For all items :

19

20 //create a new table row

21 echo "<tr><td><div style=\"width:100%; overflow:hidden\"><small>";

22 echo "On ";

23

24 //print the day it was published

25 print_r($item['y:published']['day']);

26 echo "/";

27

28 //print the month it was published

29 print_r($item['y:published']['month']);

30 echo "/";

31

32 //print the year it was published

33 print_r($item['y:published']['year']);

34 echo ", ";

35

36 //print who wrote the item (it's a comment in my case

37 $name = $item['author']['name'];

38 echo "<b>";

39 //some more checks because sometimes the author is in its own tag

40 if (strlen($name)==1) print_r($item['author']);

41 else print_r($item['author']['name']);

42

43 echo "</b>";

44

45 echo " commented: ";

46 //write the description ofthe item within its link

47 echo "<a href=\"".$link."\">".$item['title']."</a>";

48 echo ":<br/>";

49

50

51 echo "</small></div></td></tr>";

52 //end of the row for this item

53

54 }//end of for each items

55

56 echo "</table>";

No comments: