We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit eb9c40e0 authored by tobyink's avatar tobyink

WebID finder

parent 5f0cc026
......@@ -161,3 +161,10 @@ function ajaxLoading (l)
$('#loading').hide();
}
}
function webidLookup ()
{
window.open("/webid-finder-ws/form.php?javascript=id",
"webid-finder",
"status=1,location=1,resizable=1,scrollbars=1,width=560,height=400");
}
\ No newline at end of file
......@@ -43,7 +43,10 @@
</tr>
<tr>
<th align="right" valign="top"><label for="id">WebID (FOAF):</label></th>
<td><input name="id" id="id" value="{$id|escape:'html':'UTF-8'}" /></td>
<td>
<input name="id" id="id" value="{$id|escape:'html':'UTF-8'}" />
<input type="button" onclick="webidLookup();" value="?" />
</td>
<td><a href="#dfn_id" rel="glossary">What's this?</a></td>
</tr>
<tr>
......
<html>
<head>
<title>Find your WebID</title>
<style type="text/css">
body
{
background: #900;
color: white;
font-family: "Bitstream Vera Sans", "Helvetica", "Arial", sans-serif;
}
.form-end
{
text-align: center;
}
ul
{
padding: 0;
margin: 0;
list-style: none;
}
ul li, div.success
{
margin: 0 0 8px 0;
padding: 8px;
background: white;
color: black;
border-radius: 6px;
-o-border-radius: 6px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
}
ul li .radio
{
position: relative;
top: -20px;
}
ul li label b
{
position: relative;
left: 18px;
top: -16px;
font-size: 110%;
}
input
{
font-size: 95%;
}
input.wide
{
width: 100%;
}
.options_panel
{
margin: 8px;
padding: 8px;
background: #ffd;
border-radius: 6px;
-o-border-radius: 6px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
font-size: 80%;
}
</style>
</head>
<body>
<h1>WebID Finder</h1>
<?php
if ($_REQUEST['submit'])
{
ini_set('include_path', '.:/usr/lib64/php/:' . ini_get('include_path'));
require_once 'guts.php';
switch ($_REQUEST['source'])
{
case 'laconica' :
$info = getFromLaconica( $_REQUEST[ $_REQUEST['source'] ] );
break;
case 'foaf' :
$info = getFromFOAF( $_REQUEST[ $_REQUEST['source'] ] );
break;
case 'opera' :
$info = getFromMyOpera( $_REQUEST[ $_REQUEST['source'] ] );
break;
case 'web' :
$info = getFromWebsite( $_REQUEST[ $_REQUEST['source'] ] );
break;
case 'email' :
$info = getFromEmail( $_REQUEST[ $_REQUEST['source'] ] );
break;
default :
$info = getBestGuess( $_REQUEST[ $_REQUEST['source'] ] );
}
if ($info['WebID'])
{
print "<div class=\"success\">\n";
printf("<p>Found a WebID%s:<br /><tt id=\"webid\" title=\"%s\">%s</tt></p>\n",
(empty($info['Name']) ? '' : (' for ' . htmlentities($info['Name']))),
htmlentities($info['WebID']),
htmlentities($info['WebID']));
if (!empty($_REQUEST['javascript']))
{
print "<script type=\"text/javascript\">\n";
print "function UseIt() { window.opener.document.getElementById('"
. htmlentities($_REQUEST['javascript'])
. "').value = document.getElementById('webid').title; }\n";
print "</script>\n";
print "<p><a href=\"javascript:UseIt();\">Use this WebID</a></p>\n";
}
print "</div>\n";
print "</body>\n";
print "</html>\n";
exit;
}
}
?>
<form action="" method="post">
<ul>
<li>
<input class="radio" type="radio" name="source" value="foaf" id="src_foaf" />
<label for="src_foaf">
<img src="foaf.png" alt="">
<b>Your FOAF File</b>
</label>
<div id="options_foaf" class="options_panel">
<label for="foaf">Enter your FOAF file URL.</label>
<br /><input class="wide text" name="foaf" id="foaf" />
</div>
</li>
<li>
<input class="radio" type="radio" name="source" value="laconica" id="src_laconica" />
<label for="src_laconica">
<img src="laconica.png" alt="">
<b>Your Laconica / identi.ca Account</b>
</label>
<div id="options_laconica" class="options_panel">
<label for="laconica">Enter your identi.ca user name or the URL of your profile page on another laconica site.</label>
<br /><input class="wide text" name="laconica" id="laconica" />
</div>
</li>
<li>
<input class="radio" type="radio" name="source" value="opera" id="src_opera" />
<label for="src_opera">
<img src="opera.png" alt="">
<b>Your &#8220;My Opera&#8221; Account</b>
</label>
<div id="options_opera" class="options_panel">
<label for="opera">Enter your my.opera.com user name.</label>
<br /><input class="wide text" name="opera" id="opera" />
</div>
</li>
<li>
<input class="radio" type="radio" name="source" value="web" id="src_web" />
<label for="src_web">
<img src="web.png" alt="">
<b>Your Website</b>
</label>
<div id="options_web" class="options_panel">
<label for="web">Enter your website address.</label>
<br /><input class="wide text" name="web" id="web" />
</div>
</li>
<li>
<input class="radio" type="radio" name="source" value="email" id="src_email" />
<label for="src_email">
<img src="email.png" alt="">
<b>Your E-mail Address</b>
</label>
<div id="options_email" class="options_panel">
<label for="email">Enter your e-mail address (don't worry, we won't keep it).</label>
<br /><input class="wide text" name="email" id="email" />
</div>
</li>
</ul>
<div class="form-end">
<input type="hidden" name="javascript" value="<?php echo htmlentities($_REQUEST['javascript']) ?>" />
<input type="hidden" name="submit" value="1" />
<input name="search" value="search" alt="Search" type="image" src="Search.png" />
</div>
</form>
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function Initio ()
{
var OptionsPanels = $(".options_panel");
OptionsPanels.hide();
$(".radio").each( function (i) {
this.onclick = Expando;
});
}
function Expando ()
{
$(".radio").each( function (i) {
if (this.checked)
$("#options_" + this.value).show();
else
$("#options_" + this.value).hide();
});
}
Initio();
</script>
</body>
</html>
<?php
require 'arc/ARC2.php';
if ( !function_exists('json_decode') )
{
function json_decode($content, $assoc=false)
{
require_once 'Services/JSON.php';
if ( $assoc )
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
else
$json = new Services_JSON;
return $json->decode($content);
}
}
if ( !function_exists('json_encode') )
{
function json_encode($content)
{
require_once 'Services/JSON.php';
$json = new Services_JSON;
return $json->encode($content);
}
}
function _resolve_relative_url ($absolute, $relative)
{
$p = parse_url($relative);
if($p["scheme"])
return $relative;
extract(parse_url($absolute));
$path = dirname($path);
if($relative{0} == '/')
{
$cparts = array_filter(explode("/", $relative));
}
else
{
$aparts = array_filter(explode("/", $path));
$rparts = array_filter(explode("/", $relative));
$cparts = array_merge($aparts, $rparts);
foreach($cparts as $i => $part)
{
if($part == '.')
{
$cparts[$i] = null;
}
elseif($part == '..')
{
$cparts[$i - 1] = null;
$cparts[$i] = null;
}
}
$cparts = array_filter($cparts);
}
$path = implode("/", $cparts);
$url = "";
if($scheme)
$url = "$scheme://";
if($user)
{
$url .= "$user";
if ($pass)
$url .= ":$pass";
$url .= "@";
}
if($host)
$url .= "$host/";
$url .= $path;
return $url;
}
function _http ($uri)
{
if (function_exists('curl_init'))
{
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec($ch);
curl_close($ch);
return ob_get_clean();
}
elseif (function_exists('parse_url'))
{
$_uri = parse_url($uri);
if (! $_uri['port'])
$_uri['port'] = 80;
if (! ($nh = fsockopen($_uri['host'], $_uri['port'], $errno, $errstr, 20)) )
{
header("Content-Type: text/plain");
die("Could not open network connection! ($errno - $errstr)\r\n");
}
fwrite($nh, "GET {$_uri[path]}?{$_uri[query]} HTTP/1.0\r\n"
. "Host: {$_uri['host']}\r\n"
. "Connection: close\r\n\r\n"
);
while (!feof($nh))
{
$output .= fgets($nh, 128);
}
fclose($nh);
// Remove HTTP header.
return substr(strstr($output, "\r\n\r\n"), 4);
}
return null;
}
function getFromLaconica ($account)
{
if (!preg_match('/^https?:\/\//i', $account ))
$account = "http://identi.ca/{$account}";
preg_replace('/\/$/', '', $account);
$foaf = $account . "/foaf";
return getFromFOAF($foaf);
}
function getFromFOAF ($foaf, $knownHomepage = NULL, $data = NULL)
{
$parser = ARC2::getRDFParser();
if (empty($data))
$parser->parse($foaf);
else
$parser->parse($foaf, $data);
$index = $parser->getSimpleIndex();
if ($index[$foaf]['http://xmlns.com/foaf/0.1/primaryTopic'][0])
{
$webid = $index[$foaf]['http://xmlns.com/foaf/0.1/primaryTopic'][0];
}
if (!$webid)
{
foreach ($index as $subject => $dummy)
{
if ($index[$subject]['http://xmlns.com/foaf/0.1/homepage'])
{
foreach ($index[$subject]['http://xmlns.com/foaf/0.1/homepage'] as $homepage)
{
if ($homepage == $knownHomepage || $homepage == $foaf)
{
$webid = $subject;
break 2;
}
}
}
if ($index[$subject]['http://xmlns.com/foaf/0.1/weblog'])
{
foreach ($index[$subject]['http://xmlns.com/foaf/0.1/weblog'] as $homepage)
{
if ($homepage == $knownHomepage)
{
$webid = $subject;
break 2;
}
}
}
}
}
if ($webid)
{
$r = array(
'WebID' => $webid,
'Pages' => $index[$webid]['http://xmlns.com/foaf/0.1/homepage'],
'Name' => $index[$webid]['http://xmlns.com/foaf/0.1/name'][0]
);
if (substr($r['WebID'], 0, 2) == '_:')
$r['WebID'] = 'http://thing-described-by.org/?'.$foaf;
return $r;
}
return null;
}
function getFromMyOpera ($account)
{
return array(
'WebID' => "http://my.opera.com/{$account}/xml/foaf#me",
'Pages' => array("http://my.opera.com/{$account}/")
);
}
function getFromWebsite ($url)
{
$str = _http($url);
if (preg_match('/xmlns\:[A-Za-z0-9\.\_\-]+\=.?http...xmlns.com.foaf.0.1/', $str))
{
$r = getFromFOAF($url, $url, $str);
if ($r['WebID'])
return $r;
}
$doc = new DOMDocument();
$e = error_reporting(1);
$doc->loadHTML( $str );
error_reporting($e);
$links = $doc->getElementsByTagName('link');
foreach ($links as $l)
{
if ( preg_match('/\b(meta)\b/i', $l->getAttribute('rel')) )
{
$foaf = _resolve_relative_url($url, $l->getAttribute('href'));
$info = getFromFOAF($foaf, $url);
if ($info['WebID'])
return $info;
}
}
return getFromGoogleSocialGraphAPI($url);
}
function getFromGoogleSocialGraphAPI ($url)
{
$api = "http://socialgraph.apis.google.com/lookup?pretty=1&sgn=1&edi=1&edo=1&fme=1&q={$url}";
$data = json_decode( _http($api) , 1 );
$canon = $data['canonical_mapping'][$url];
if (substr($canon, 0, 3) == 'sgn')
{
return array(
'WebID' => $canon ,
'Homepages' => array($url)
);
}
}
function getFromEmail ($addr)
{
if (! substr($addr, 0, 7) == 'mailto:')
$addr = 'mailto:' . $addr;
return array(
'WebID' => 'http://foaf.me/mbox/' . sha1(strtolower($addr)) . '#me'
);
}
function getBestGuess ($string)
{
if (preg_match('#^http://identi.ca/([^/]+)#i', $string, $matches))
return getFromLaconica($string);
elseif (preg_match('/\@/', $string))
return getFromEmail($email);
return getFromWebsite($string);
}
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment