Commit 6df35710 authored by tobyink's avatar tobyink

Beginning to do some more interesting stuff with location data;

added notes for a couple of other external dependencies.
parent bf516d85
Other external dependencies which are currently bundled within the nixtape source tree:
- jQuery 1.3.2
- ARC2
......@@ -25,7 +25,8 @@ require_once($install_path . '/data/Track.php');
require_once($install_path . '/data/User.php');
require_once($install_path . "/data/sanitize.php");
require_once($install_path . '/utils/linkeddata.php');
require_once($install_path . "/resolve-external.php");
require_once($install_path . '/utils/arc/ARC2.php');
require_once($install_path . "/resolve-external.php"); // why isn't this in a subdir?
require_once($install_path . '/licenses.php'); // why isn't this in a subdir?
/**
......@@ -300,4 +301,56 @@ class Server {
}
}
static function getLocationDetails($name) {
global $mdb2;
if (!$name)
return array();
$res = $mdb2->query('SELECT * FROM Places WHERE location_uri=' . $mdb2->quote($name, 'text'));
if($res->numRows()) {
$rv = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
if (! ($rv['latitude'] && $rv['longitude'] && $rv['country'])) {
$parser = ARC2::getRDFXMLParser();
$parser->parse($name);
$index = $parser->getSimpleIndex();
$rv = array(
'latitude' => $index[$name]['http://www.w3.org/2003/01/geo/wgs84_pos#lat'][0],
'longitude' => $index[$name]['http://www.w3.org/2003/01/geo/wgs84_pos#long'][0],
'country' => strtoupper(substr($index[$name]['http://www.geonames.org/ontology#inCountry'][0], -2))
);
$mdb2->query(sprintf('UPDATE Places SET latitude=%f, longitude=%f, country=%s WHERE location_uri=%s',
(float)$rv['latitude'],
(float)$rv['longitude'],
$mdb2->quote($rv['country'], 'text'),
$mdb2->quote($name, 'text')));
}
}
else {
$parser = ARC2::getRDFXMLParser();
$parser->parse($name);
$index = $parser->getSimpleIndex();
$rv = array(
'latitude' => $index[$name]['http://www.w3.org/2003/01/geo/wgs84_pos#lat'][0],
'longitude' => $index[$name]['http://www.w3.org/2003/01/geo/wgs84_pos#long'][0],
'country' => strtoupper(substr($index[$name]['http://www.geonames.org/ontology#inCountry'][0], -2))
);
$mdb2->query(sprintf('INSERT INTO Places VALUES (%s, %f, %f, %s)',
$mdb2->quote($name, 'text'),
(float)$rv['latitude'],
(float)$rv['longitude'],
$mdb2->quote($rv['country'], 'text')));
}
return $rv;
}
}
......@@ -75,18 +75,7 @@ class User {
function save ()
{
global $mdb2;
if (!empty($this->location_uri))
{
$res = $mdb2->query('SELECT * FROM Places WHERE location_uri = ' . $mdb2->quote($this->location_uri, 'text'));
if(! $res->numRows())
{
$mdb2->query('INSERT INTO Places VALUES (' . $mdb2->quote($this->location_uri, 'text') . ')');
}
}
$q = sprintf("UPDATE Users SET "
. "email=%s, " # Send a confirmation email first??
. "password=%s, "
......
......@@ -23,6 +23,7 @@ require_once('database.php');
require_once('templating.php');
require_once('data/User.php');
require_once('data/TagCloud.php');
require_once('data/Server.php');
if(!isset($_GET['user']) && $logged_in == false) {
$smarty->assign('error', 'Error!');
......@@ -43,6 +44,7 @@ if(isset($user->name)) {
$smarty->assign('homepage', $user->homepage);
$smarty->assign('location', $user->location);
$smarty->assign('location_uri', $user->location_uri);
$smarty->assign('geo', Server::getLocationDetails($user->location_uri));
$aUserScrobbles = $user->getScrobbles(20);
if (!PEAR::isError ($aUserScrobbles)) {
$smarty->assign('scrobbles', $aUserScrobbles);
......
......@@ -30,6 +30,11 @@
{/if}
<dd rel="foaf:based_near">
<span{if $location_uri} about="{$location_uri|escape:'html':'UTF-8'}"{/if} class="label" property="rdfs:comment">{$location|escape:'html':'UTF-8'}</span>
<!--
{$geo.latitude}
{$geo.longitude}
{$geo.country}
-->
</dd>
<dd class="note" property="bio:olb">{$bio|escape:'html':'UTF-8'}</dd>
</dl>
......@@ -61,11 +66,7 @@
<ul class="gobbles" about="{$id|escape:'html':'UTF-8'}" rev="gob:user">
{section name=i loop=$scrobbles}
{if $scrobbles[i].license > 0}
<li class="play libre" about="{$scrobbles[i].id|escape:'html':'UTF-8'}" typeof="rss:item gob:ScrobbleEvent" rel="gob:track_played">
{else}
<li class="play" about="{$scrobbles[i].id|escape:'html':'UTF-8'}" typeof="rss:item gob:ScrobbleEvent" rel="gob:track_played">
{/if}
<li class="play {if $scrobbles[i].license > 0}libre{/if}" about="{$scrobbles[i].id|escape:'html':'UTF-8'}" typeof="rss:item gob:ScrobbleEvent" rel="gob:track_played">
<div about="{$scrobbles[i].id_track|escape:'html':'UTF-8'}" typeof="mo:Track" class="haudio">
<div rev="mo:track">
<div about="{$scrobbles[i].id_album|escape:'html':'UTF-8'}" typeof="mo:Record"{if $scrobbles[i].album} property="dc:title" content="{$scrobbles[i].album|escape:'html':'UTF-8'}"{/if}>
......
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