Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit van Aaken authored and Gerrit van Aaken committed Mar 22, 2010
0 parents commit 5b03611
Show file tree
Hide file tree
Showing 6 changed files with 15,612 additions and 0 deletions.
150 changes: 150 additions & 0 deletions cache/0f1f4a38168074df15ae9effd5cd5cac.spc

Large diffs are not rendered by default.

364 changes: 364 additions & 0 deletions cache/3518fd9af4843e230f4310e9279a0461.spc

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions index.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
// Get functions;
require_once('lib/functions.php');
require_once('lib/simplepie.inc');

// Get Flick feed
$feed = new SimplePie('http://api.flickr.com/services/feeds/photos_public.gne?id=44285591@N04&lang=de-de&format=rss_200&limit=5','cache',300);
$feed->handle_content_type();

// Get Twitter feed
$tweets = new SimplePie('http://twitter.com/statuses/user_timeline/57088055.rss','cache',300);
$tweets->handle_content_type();
?>



<!-- Show Flickr Images -->
<div id="flickr">
<ul>
<?php for ($i = 0; $i < 5; $i++): ?>
<li><?php $item = $feed->get_item($i); print $item->get_description(); ?></li>
<?php endfor; ?>
</ul>
</div>


<!-- Show Twitter messages -->
<div id="twitter">
<ul>
<?php foreach ($tweets->get_items() as $tweet): ?>
<li>
<strong><a class="permalink" href="<?php echo $tweet->get_permalink(); ?>"><?php echo reldate(strtotime($tweet->get_date())); ?></a></strong>
<?php print preparetweet( $tweet->get_description() ); ?>
</li>
<?php endforeach; ?>
</ul>
</div>
53 changes: 53 additions & 0 deletions lib/functions.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

// Prepare tweets and auto-detect hyperlinks, hashtags and usernames
function preparetweet($ret) {
$ret = substr($ret, strpos($ret, ": ")+1);
$ret = preg_replace_callback('#(?<=[\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&~/\-=?@\[\](+]|[.,;:](?![\s<])|(?(1)\)(?![\s<])|\)))+)#is', 'clickable_url', $ret);
$ret = preg_replace_callback('|(#[a-zA-Z0-9_ŠšŸ€…†§]*)|is', 'clickable_hashtag', $ret);
$ret = preg_replace_callback('|(@[a-zA-Z0-9_ŠšŸ€…†§]*)|is', 'clickable_username', $ret);
return trim($ret);
}

function clickable_hashtag($matches) {
$origin = trim($matches[0]);
return '<a target="_blank" class="hashtag" href="http://search.twitter.com/search?q=&tag='.substr($origin, 1).'">'.$origin.'</a>';
}

function clickable_username($matches) {
$origin = trim($matches[0]);
return '<a target="_blank" class="username" href="http://twitter.com/'.substr($origin, 1).'">'.$origin.'</a>';
}

function clickable_url($matches) {
$url = $matches[2];
if ( empty($url) )
return $matches[0];
return $matches[1] . "<a class='link' href=\"$url\">$url</a>";
}

// Turn date to relative string
function reldate($input, $now = false) {
if (!$now) { $now = time(); }
$diff = $now - $input;
if ($diff < 3600) {
$value = floor($diff / 60);
$unit = "Minute";
$unit2 = "Minuten";
} elseif ($diff < 86400) {
$value = floor($diff / 3600);
$unit = "Stunde";
$unit2 = "Stunden";
} else {
$value = floor($diff / 86400);
$unit = "Tag";
$unit2 = "Tagen";
}
if ($value == 1) {
return "vor ".$value." ".$unit;
} else {
return "vor ".$value." ".$unit2;
}
}

?>
Loading

0 comments on commit 5b03611

Please sign in to comment.