Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial import of my old social-graph/rss/microformats project, extra…

…cted out of my website code in to it's own repo. It needs some cleaning up before it can run indepentantly, and some of the APIs it's using may be deprecated (social graph api has some https issues)
  • Loading branch information...
commit 6f5e13698792b5ff692168fce337a7924840d257 0 parents
@dsingleton authored
Showing with 381 additions and 0 deletions.
  1. +5 −0 .htaccess
  2. +83 −0 default.css
  3. +293 −0 index.php
5 .htaccess
@@ -0,0 +1,5 @@
+
+RewriteEngine on
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule ^(.*)$ index.php?profile=$1 [QSA,L]
83 default.css
@@ -0,0 +1,83 @@
+abbr {
+ text-decoration: none;
+ border: none;
+ display: block;
+}
+
+table {
+ font-size: .9em;
+ border: none;
+}
+
+tr.day th {
+ padding: 1.6em 0 .3em 5.3em;
+ text-align: left;
+ border-bottom: 2px solid #ccc;
+ font-size: 1em;
+}
+
+table tr:hover td,
+table tr:hover th.time {
+}
+
+table tr td a {
+ text-decoration: none;
+ line-height: 1.3;
+}
+
+table tr td a:hover {
+ text-decoration: underline;
+}
+
+table tr td.item {
+ padding-left: 0em;
+ padding-right: 1em;
+}
+
+tbody:hover {
+}
+
+tbody td,
+tbody th.time {
+ text-align: left;
+ border: none;
+ margin: 0;
+ padding: .4em 0 .3em;
+ vertical-align: top;
+ border-bottom: 1px solid #ccc;
+}
+
+tbody th.time {
+ border-bottom: none;
+ text-align: right;
+ padding-right: 1em;
+}
+
+ul.noFeeds {
+ margin: 1em 0;
+ padding: 0 0 0 10px;
+ list-style: none;
+}
+
+ul.noFeeds li {
+ margin: 0;
+ padding: .25em 0;
+}
+
+ul.noFeeds li img {
+ position: relative;
+ top: 3px;
+ margin-right: 5px;
+}
+
+div.vcard {
+ padding: .5em;
+ border: 1px solid #666;
+ background: #eee;
+}
+
+div.vcard img.logo {
+ float: right;
+ border: 1px solid #666;
+
+}
293 index.php
@@ -0,0 +1,293 @@
+<?php
+
+/*
+ Todo:
+
+ * Character encoding issues, track down cause, fix
+ * Fix bradfitz/adactio cass, slow, some feeds missing?
+ * normalise cache URLs rather than hashing, easier debuging, but potential collisions
+ * Join google group (http://groups.google.com/group/social-graph-api) and ask aout lack of flickr/other auto RSS
+ * List friends, linkable list for exploration, building towards friend agrigates.
+ * A Rules class (or somthing) to autocreate some feed urls (last.fm recent, and events?) Any other common ones that cn be constructed through URLS
+
+ * Human date, show year if not this year
+
+ URLs:
+
+ * http://code.google.com/apis/socialgraph/docs/api.html
+ * http://groups.google.com/group/social-graph-api
+ * http://tinyurl.com/2egz9s (Flickr userid lookup)
+ * http://tools.microformatic.com/
+*/
+
+date_default_timezone_set("Europe/London");
+//error_reporting(0);
+
+function ifnull($what, $else) { return $what ? $what : $else; }
+
+$socialGraphAPI = "http://socialgraph.apis.google.com/lookup?q=%s&fme=1&pretty=1";
+$hKitURL = "http://tools.microformatic.com/query/json/hkit/%s";
+
+$feeds = array();
+$list = array();
+
+$url = @$_GET['url'];
+$profileURL = preg_replace('/^(http[s]?:\/\/)([^\/]*)/i', '$1$2', $url);
+
+
+if ($profileURL && !preg_match('/http[s]?:\/\//', $profileURL)) {
+ $profileURL = 'http://' . $profileURL;
+}
+
+
+if ($profileURL) {
+ // Log access
+ // $log = fopen('access.log', 'a');
+ // fwrite($log, date('r') . "\t$profileURL\n");
+ // fclose($log);
+
+ // Up the hKit..
+ $hCardURL = sprintf($hKitURL, $profileURL);
+ $json = getCachedURL($hCardURL, 60 * 60 * 6);
+ $hCard = @array_shift(json_decode($json));
+
+ // $responseJSON = getCachedURL(sprintf($sgFriends, $profileURL), 60 * 60 * 6);
+ // $responsePHP = json_decode($responseJSON);
+
+ // Up the social graph
+ $sgURL = sprintf($socialGraphAPI, $profileURL);
+ $responseJSON = getCachedURL($sgURL, 60 * 60 * 6);
+ if (@$_GET['dumpJSON']) {
+ die($responseJSON);
+ }
+
+ $responsePHP = json_decode($responseJSON);
+
+ foreach($responsePHP->nodes as $siteURL => $siteProfile) {
+
+ if ($profileURL == $siteURL) {
+
+ }
+
+ $hasDomain = ($domain = parse_url($siteURL, PHP_URL_HOST));
+ $feed = @$siteProfile->attributes->rss;
+
+ // if ($hasDomain && !$feed) {
+ // if ($domain == 'www.last.fm') {
+ // $user = substr($siteURL, -11, 10);
+ // $feedURL = 'http://pipes.yahoo.com/pipes/pipe.run?_id=982b5cbb04dd3568eb973df43615520c&_render=rss&lastFmUser=%s';
+ // $feed = sprintf($feedURL, $user);
+ // }
+ // }
+ if ($hasDomain && $feed) {
+ $feeds[$domain] = $feed;
+ }
+ elseif ($siteURL) {
+ $noFeeds[$domain] = $siteURL;
+ }
+ }
+
+ $list = feedsToList($feeds);
+}
+
+function getCachedURL($url, $timeout = 900) // 15 min
+{
+ $oCache = Cache::instance();
+ $key = "lifestream:url:{$url}";
+
+ if (!$content = $oCache->get($key)) {
+ $ch = curl_init($url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
+ $content = curl_exec($ch);
+
+ $oCache->set($key, $content, $timeout);
+ }
+ return $content;
+}
+
+function feedsToList($feeds) {
+
+ $list = array();
+ foreach ($feeds as $name => $feed) {
+
+ $feedStr = getCachedURL($feed);
+ $rss = new DOMDocument();
+ @$rss->loadXML($feedStr);
+ foreach ($rss->getElementsByTagName("item") as $item) {
+
+ $dateField = $item->getElementsByTagName("pubDate")->item(0) ? 'pubDate' : 'date';
+ $date = strtotime(substr($item->getElementsByTagName($dateField)->item(0)->nodeValue, 0, 25));
+
+ $list[$date]["name"] = $name;
+
+ foreach (array('title', 'link') as $detail) {
+ $list[$date][$detail] = $item->getElementsByTagName($detail)->item(0)->nodeValue;
+ }
+ }
+ }
+ krsort($list);
+ return $list;
+}
+
+?>
+
+<style>
+table.activity {
+ font-size: 11px;
+}
+
+table.activity td,
+table.activity th {
+ padding: 5px 3px;
+ border-top: 1px solid #ddd;
+}
+
+table.activity tr.day th {
+ font-size: 14px;
+ text-align: left;
+ padding-top: 15px;
+ border-bottom: 0;
+ border-top: none;
+}
+</style>
+
+<article>
+ <h1>Activity derived from XFN</h1>
+
+ <?php if (!$profileURL) { ?>
+
+ <p>Enter a URL to search to the right, or try an example URL.</p>
+
+ <p>The first load for a URL might be a little slow, after that it will cache for a while;</p>
+ <ul>
+ <li><strong>RSS</strong> - Cached for 15 minutes</li>
+ <li><strong>hCard</strong>, <strong>Social Graph</strong> - Cached for 6 hours</li>
+ </ul>
+
+ <?php } else { ?>
+
+ <?php if (!$list) { ?>
+ <h3>Uh oh, couldn't find any feeds for your URL.</h3>
+
+ <p>First of all, this requires you to have some XFN <em>rel=me</em> marked up around the web (or a discoverable FOAF file). If you haven't got these then it won't work :(</p>
+
+ <p>Take a look at the <a href="<?php h($sgURL); ?>">Show SocialGraph API response</a>, if there are no claimed nodes then it's possible the API may not have indexed you properly, or not updated it's cache of your profile recently.</p>
+
+ <p>If you're pretty sure your site is right you it may be a parsing bug with the SocialGraph API, why not visit the <a href="http://groups.google.com/group/social-graph-api">mailing list</a> and let them know.</p>
+
+ <h4>Known Issues</h4>
+ <ul>
+ <li>Don't use your twitter account as a start point, they use <strong>rel="me nofollow"</strong> so it's rightfully not followed. Bad twitter.</li>
+ </ul>
+ <?php } ?>
+
+ <table class="hcalendar hfeed activity">
+ <tbody>
+ <?php $day = ""; ?>
+
+ <?php foreach ($list as $timestamp => $item) { ?>
+
+ <?php if ($day != ($this_day = date("F jS Y",$timestamp))) { ?>
+ </tbody>
+
+ <tbody>
+ <tr class="day">
+ <th colspan="3"><?php h($this_day); ?></th>
+ </tr>
+
+ <?php $day = $this_day; ?>
+
+ <?php } ?>
+
+ <tr class="vevent hentry">
+ <th class="time">
+ <abbr class="dtstart published" title="<?php h(date('c', $timestamp)); ?>">
+ <?php echo date("g:ia",$timestamp); ?>
+
+ </abbr>
+ </th>
+
+ <td class="item">
+ <a class="url summary entry-title" rel="bookmark" href="<?php h($item["link"]); ?>">
+ <?php echo htmlentities($item["title"]); ?>
+
+ </a>
+ </td class="site">
+ <td>
+ <?php printf('<img class="icon" src="/code/grabicon/?url=%s" alt="%s" title="%s" width="16" />', $item['name'], $item['name'], $item['name']); ?>
+
+ </td>
+ </tr>
+ <?php } ?>
+ </tbody>
+ </table>
+ <?php } ?>
+
+ <?php if ($profileURL) { ?>
+ <h3>URLs called</h3>
+ <ul>
+ <?php if (isset($hCardURL)) { ?>
+ <li><a href="<?php h($hCardURL)?>"><?php h($hCardURL) ?></a></li>
+ <?php } ?>
+ <?php if (isset($sgURL)) { ?>
+ <li><a href="<?php h($sgURL)?>"><?php h($sgURL) ?></a></li>
+ <?php } ?>
+ </ul>
+ <?php } ?>
+</article>
+
+<aside>
+
+ <h2>Try it</h2>
+ <br><br>
+ <form action="./" method="get">
+ <label for="lifestream_url">URL</label>
+ <input type="text" class="text" id="lifestream_profile" name="url" />
+
+ <input type="submit" class="submit" value="Go" />
+ </form>
+ <br>
+ <p>Or try one of these&hellip; <a href="?url=dsingleton.co.uk">dsingleton.co.uk</a>, <a href="?url=ben-ward.co.uk">ben-ward.co.uk</a>, <a href="?url=adactio.com">adactio.com</a>, <a href="?url=bradfitz.com">bradfitz.com</a></p>
+
+ <?php if (@$profileURL) { ?>
+
+ <h3>Activity for</h3>
+ <p><a href="<?php h($profileURL) ?>"><?php h($profileURL) ?></a></p>
+
+ <?php if (@$hCard->fn) { ?>
+ <div class="vcard">
+ <address>
+ <?php if (@$hCard->logo) { ?>
+ <img class="logo" src="<?php h($hCard->logo) ?>" alt="x" />
+ <?php } ?>
+ <a class="url fn" href="<?php h($profileURL); ?>">
+ <?php echo htmlentities($hCard->fn); ?>
+ </a>
+ </address>
+ </div>
+ <?php } else { ?>
+ <p>No hCard found :(</p>
+ <?php } ?>
+
+ <?php if ($feeds) { ?>
+ <p>
+ Available as
+ <a class="ical" href="webcal://suda.co.uk/projects/microformats/hcalendar/get-cal.php?uri=http://me.dsingleton.co.uk/code/lifestream/<?h(rawurlencode($profileURL)) ?>">iCal</a>
+ or
+ <a class="feed" href="feed://tools.microformatic.com/transcode/atom/hatom/<?php echo THIS_URL ?><?php h($profileURL); ?>">RSS</a>
+ </p>
+ <?php } ?>
+
+ <?php if (@$noFeeds) { ?>
+ <h3>Links without feeds</h3>
+ <ul class="noFeeds">
+ <?php foreach($noFeeds as $domain => $feed) { ?>
+ <li><img src="/code/grabicon?url=<?php h($feed) ?>" width="16" /> <a href="<?php h($feed) ?>"><?php h(ifnull($domain, $feed)) ?></a></li>
+ <?php } ?>
+ </ul>
+ <?php } ?>
+
+ <?php } ?>
+</aside>
Please sign in to comment.
Something went wrong with that request. Please try again.