public
Description: A simple standalone lifestream script in PHP using SimplePie.
Homepage:
Clone URL: git://github.com/trey/lifestream.git
Click here to lend your support to: lifestream and make a donation at www.pledgie.com !
lifestream / lifestream.php
100644 75 lines (66 sloc) 2.692 kb
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
<?php
$twitter_user = '';
$feeds = array(
'http://blog.treypiepmeier.com/feed/',
'http://solutions.treypiepmeier.com/feed/',
'http://github.com/trey.atom'
);
 
function getClass($url)
{
// Create a CSS class name from the URL of the feed.
$class = parse_url($url, PHP_URL_HOST); // TODO use regex to get the hostname instead of this flakey PHP function.
$class = preg_replace("/www\./", "", $class); // Remove `www.`.
$class = preg_replace("/\.(com|org|net)/", "", $class); // Remove top level domains. Add more as you see fit.
$class = preg_replace("/\./", "_", $class); // Replace `.`s with `_`s.
return $class;
}
 
date_default_timezone_set('America/Chicago'); // Change this to your timezone.
require_once('simplepie.inc');
foreach ($feeds as $feed) {
$merge[] = new SimplePie($feed);
}
 
$merged = SimplePie::merge_items($merge, 0, 20); // Get the 20 most recent items.
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Someone's Lifestream</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
 
<h1>My Lifesteam</h1>
<?php
$thedate = '';
foreach ($merged as $item):
if ($thedate != $item->get_date('F j, Y')) {
$thedate = $item->get_date('F j, Y');
echo '<h2>' . $thedate . '</h2>';
}
$theclass = getClass($item->feed->get_permalink());
?>
<div class="item <?php echo $theclass; ?>">
<?php if (stripos($item->feed->get_permalink(), 'twitter.com') ): // This is a Tweet. ?>
 
<div class="content">
<?php
$tweet = $item->get_description();
// Tweet parsing mostly from Phwitter: http://jasontan.org/code/phwitter/
$tweet = preg_replace("/^" . $twitter_user . ":/", "", $tweet); // Strip username from begenning of Tweet.
$tweet = preg_replace("/(http|https|ftp):\/\/[^\s]*/i","<a href=\"$0\">$0</a>", $tweet); // Add links to URLs
$tweet = preg_replace("/@([a-zA-Z0-9_]*)/","<a href=\"http://twitter.com/$1\">$0</a>", $tweet); // Make @username a link to a username's profile.
echo $tweet;
?>
</div><!-- .content -->
 
<?php else: // Not Twitter ?>
 
<?php if (!stripos($item->feed->get_permalink(), 'tumblr.com') ): // Don't show titles on Tumblr posts. ?>
<h3><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h3>
<?php endif; ?>
<div class="content">
<?php echo $item->get_description(); ?>
</div><!-- .content -->
 
<?php endif; // end of Twitter check ?>
<div class="date"><small>Posted at <?php echo $item->get_date('g:i a'); ?></small></div>
</div><!-- .item -->
<?php endforeach; ?>
<div class="note"><a href="http://github.com/trey/lifestream/">Make your own Lifestream. &rarr;</a></div>
</body>
</html>