Created
April 26, 2009 16:18
-
-
Save onecrayon/102081 to your computer and use it in GitHub Desktop.
Changes homepage to your own in a Yahoo Pipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Script for converting a Yahoo Pipe's homepage URL into something more sensible | |
Requires cURL to be enabled | |
*/ | |
// CHANGE THESE VARIABLES | |
// In the link http://pipes.yahoo.com/pipes/pipe.run?_id=uCxBbzww3hGB9ClS6ycw5g&_render=php | |
// the pipe ID is uCxBbzww3hGB9ClS6ycw5g (everything after _id= and before &_render | |
$pipe_id = ''; | |
$home = ''; // Your homepage | |
$author = ''; // Your email address | |
// Pipes Request | |
$req = "http://pipes.yahoo.com/pipes/pipe.run?_id=$pipe_id&_render=php"; | |
$ch = curl_init(); | |
// set the url to fetch | |
curl_setopt($ch, CURLOPT_URL, $req); | |
// don't give me the headers just the content | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
// return the value instead of printing the response to browser | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$pipe = curl_exec($ch); | |
// remember to always close the session and free all resources | |
curl_close($ch); | |
// Parse the serialized response | |
$info = unserialize($pipe); | |
$info = $info['value']; | |
// This makes sure that all pubDates have the timezone info | |
// API dates were lacking timezones | |
preg_match('/-[0-9]{4}$/', $info['pubDate'], $matches); | |
$offset = $matches[0]; | |
header ("Content-Type:text/xml"); | |
echo '<?xml version="1.0" encoding="UTF-8"?>'; | |
// Make sure your server can handle the echo shortcut below | |
// Otherwise find `<?=` and replace with `<?php echo ` | |
?> | |
<rss version="2.0"><channel> | |
<title><?=$info['title']; ?></title><description><?=$info['description'];?></description> | |
<pubDate><?=$info['pubDate'];?></pubDate><generator><?=$info['generator'];?></generator> | |
<link><?=$home;?></link> | |
<?php foreach ($info['items'] as $item) : ?> | |
<item> | |
<title><?=$item['title'];?></title><description><![CDATA[<?=$item['description'];?>]]></description> | |
<link><?=$item['link'];?></link><guid isPermaLink="true"><?=$item['guid'];?></guid> | |
<pubDate><?=$item['pubDate'];?><?php if (strpos($item['pubDate'], $offset) === false) { echo ' ' . $offset; } ?></pubDate> | |
<author><?=$author;?></author> | |
<?php if (is_array($item['category'])) : ?> | |
<?php foreach ($item['category'] as $cat) : ?> | |
<category><?=$cat;?></category> | |
<?php endforeach; ?> | |
<?php elseif ($item['category']) : ?> | |
<category><?=$item['category'];?></category> | |
<?php endif; ?> | |
</item> | |
<?php endforeach; ?> | |
</channel></rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment