librefm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Librefm-commits] [1278] Add RDFa and Microformats to album and track pa


From: Toby Inkster
Subject: [Librefm-commits] [1278] Add RDFa and Microformats to album and track pages.
Date: Thu, 07 May 2009 15:34:48 +0000

Revision: 1278
          http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1278
Author:   tobyink
Date:     2009-05-07 15:34:48 +0000 (Thu, 07 May 2009)
Log Message:
-----------
Add RDFa and Microformats to album and track pages. Improve RDFa and 
Microformat usage on artist pages.

Modified Paths:
--------------
    trunk/nixtape/album.php
    trunk/nixtape/data/Track.php
    trunk/nixtape/themes/librefm/templates/album.tpl
    trunk/nixtape/themes/librefm/templates/artist.tpl
    trunk/nixtape/themes/librefm/templates/track.tpl
    trunk/nixtape/track.php
    trunk/nixtape/utils/linkeddata.php

Modified: trunk/nixtape/album.php
===================================================================
--- trunk/nixtape/album.php     2009-05-07 13:43:51 UTC (rev 1277)
+++ trunk/nixtape/album.php     2009-05-07 15:34:48 UTC (rev 1278)
@@ -28,6 +28,7 @@
 $artist = new Artist($album->artist_name);
 
 $smarty->assign("name", $album->name);
+$smarty->assign("id", $album->id);
 $smarty->assign("artist", $artist);
 $smarty->assign("album", $album);
 $aAlbumTracks = $album->getTracks();

Modified: trunk/nixtape/data/Track.php
===================================================================
--- trunk/nixtape/data/Track.php        2009-05-07 13:43:51 UTC (rev 1277)
+++ trunk/nixtape/data/Track.php        2009-05-07 15:34:48 UTC (rev 1278)
@@ -26,6 +26,7 @@
 require_once($install_path . "/data/Server.php");
 require_once($install_path . "/resolve-external.php");
 require_once($install_path . "/licenses.php");
+require_once($install_path . '/utils/linkeddata.php');
 
 /**
  * Represents track data
@@ -35,6 +36,7 @@
 class Track {
 
        public $name, $artist_name, $album_name, $mbid, $duration, $streamable, 
$license, $downloadurl, $streamurl;
+       public $id;
 
        private $_playcount = false, $_listenercount = false;
 
@@ -63,6 +65,8 @@
                        $this->licenseurl = $row["license"];
                        $this->downloadurl = 
resolve_external_url($row["downloadurl"]);
                        $this->streamurl = 
resolve_external_url($row["streamurl"]);
+                       
+                       $this->id = identifierTrack(null, $this->artist_name, 
$this->name, $this->album_name, null, $this->mbid, null, null);
                }
 
        }

Modified: trunk/nixtape/themes/librefm/templates/album.tpl
===================================================================
--- trunk/nixtape/themes/librefm/templates/album.tpl    2009-05-07 13:43:51 UTC 
(rev 1277)
+++ trunk/nixtape/themes/librefm/templates/album.tpl    2009-05-07 15:34:48 UTC 
(rev 1278)
@@ -1,14 +1,21 @@
 {include file='header.tpl'}
 
-<h2><a href="{$artist->getURL()}">{$artist->name}</a> - {$name}</h2>
+<div about="{$id}" typeof="mo:Record" class="haudio">
 
-<a rel="foaf:page" href="{$album->getURL()}">
-<span{if $album->image != false} about="{$album->id}" 
rel="foaf:depiction"{/if}>
-<img class="album photo" {if $album->image == false} 
src="{$base_url}/i/qm160.png"{else}src="{$album->image}"{/if}
- 
alt="{$album->name|escape:'html':'UTF-8'}"title="{$album->name|escape:'html':'UTF-8'}"
 width="160" />
-</span>
-</a>
+       <h2>
+               <span rel="foaf:maker" rev="foaf:made" class="contributor">
+                       <a about="{$artist->id}" typeof="mo:MusicArtist" 
property="foaf:name" class="url fn org"
+                               rel="foaf:page" rev="foaf:primaryTopic" 
href="{$artist->getURL()}">{$artist->name}</a>
+                       </span>
+                       &#8212; 
+                       <span class="album" property="dc:title" rel="foaf:page" 
rev="foaf:primaryTopic" resource="">{$name}</span>
+       </h2>
 
+       <div{if $album->image != false} rel="foaf:depiction"{/if}>
+               <img {if $album->image == false} 
src="{$base_url}/i/qm160.png"{else} class="photo" src="{$album->image}"{/if}
+                       alt="{$album->name|escape:'html':'UTF-8'}" 
title="{$album->name|escape:'html':'UTF-8'}" width="160" />
+       </div>
+
 {include file='player.tpl'}
 
 <script type="text/javascript">
@@ -25,13 +32,15 @@
        {/if}
 </script>
 
-<ul id="tracks">
+<ul id="tracks" rel="mo:track">
        {section name=i loop=$tracks}
-       <li>
-               <a href="{$tracks[i]->getURL()}">{$tracks[i]->name}</a>
+       <li about="{$tracks[i]->id}" typeof="mo:Track" class="item">
+               <a class="fn url" href="{$tracks[i]->getURL()}" rel="foaf:page" 
property="dc:title">{$tracks[i]->name}</a>
        </li>
        {/section}
 </ul>
 
+</div>
+
 <div class="cleaner">&nbsp;</div>
 {include file='footer.tpl'}

Modified: trunk/nixtape/themes/librefm/templates/artist.tpl
===================================================================
--- trunk/nixtape/themes/librefm/templates/artist.tpl   2009-05-07 13:43:51 UTC 
(rev 1277)
+++ trunk/nixtape/themes/librefm/templates/artist.tpl   2009-05-07 15:34:48 UTC 
(rev 1278)
@@ -1,6 +1,6 @@
 {include file='header.tpl'}
 
-<div about="{$id}" typeof="mo:MusicalArtist">
+<div about="{$id}" typeof="mo:MusicArtist">
 
        <div class="vcard">
                <h2 class="fn org" property="foaf:name" rel="foaf:page" 
rev="foaf:primaryTopic" resource="">{$name}</h2>
@@ -15,14 +15,14 @@
                        <dl>
                                <dt>
                                        <a rel="foaf:page" 
href="{$albums[i]->getURL()}">
-                                               <span{if $albums[i]->image != 
false} about="{$albums[i]->id}" rel="foaf:depiction"{/if}>
+                                               <span{if $albums[i]->image != 
false} about="{$albums[i]->id}" rel="foaf:depiction"{/if}>
                                                        <img class="album 
photo" {if $albums[i]->image == false} 
src="{$base_url}/i/qm160.png"{else}src="{$albums[i]->image}"{/if}
                                                        
alt="{$albums[i]->name|escape:'html':'UTF-8'}"
                                                        
title="{$albums[i]->name|escape:'html':'UTF-8'}" width="160" />
                                                </span>
                                        </a>
                                </dt>
-                               <dd 
class="description">{$albums[i]->getPlayCount()} plays</dd>
+                               <dd class="description" 
property="rdfs:comment">{$albums[i]->getPlayCount()} plays</dd>
                        </dl>
                </li>
                {/section}

Modified: trunk/nixtape/themes/librefm/templates/track.tpl
===================================================================
--- trunk/nixtape/themes/librefm/templates/track.tpl    2009-05-07 13:43:51 UTC 
(rev 1277)
+++ trunk/nixtape/themes/librefm/templates/track.tpl    2009-05-07 15:34:48 UTC 
(rev 1278)
@@ -1,46 +1,62 @@
 {include file='header.tpl'}
 
-<h2>{$track->name}</h2><br />
+<div about="{$track->id|escape:'html':'UTF-8'}" typeof="mo:Track" 
typeof="haudio">
 
-{include file='player.tpl'}
-<script type="text/javascript">
-       var playlist = [{ldelim}"artist" : "{$track->artist_name}", "album" : 
"{$track->album_name}", "track" : "{$track->name}", "url" : 
"{$track->streamurl}"{rdelim}];
-       {if isset($this_user)}
-       playerInit(playlist, "{$this_user->getScrobbleSession()}", false);
-       {else}
-       playerInit(playlist, false, false);
-       {/if}
-</script>
-<br />
+       <h2 property="dc:title" class="fn" rel="foaf:page" 
rev="foaf:primaryTopic" resource="">{$track->name|escape:'html':'UTF-8'}</h2>
 
+       {include file='player.tpl'}
+       <script type="text/javascript">
+               var playlist = [{ldelim}"artist" : "{$track->artist_name}", 
"album" : "{$track->album_name}", "track" : "{$track->name}", "url" : 
"{$track->streamurl}"{rdelim}];
+               {if isset($this_user)}
+               playerInit(playlist, "{$this_user->getScrobbleSession()}", 
false);
+               {else}
+               playerInit(playlist, false, false);
+               {/if}
+       </script>
 
-<b>Artist: <a href="{$artisturl}">{$track->artist_name}</a></b><br />
-<b>Album: <a href="{$albumurl}">{$track->album_name}</a></b><br />
-{if $track->mbid != ""}
-<b>MusicBrainz ID: <a 
href="http://musicbrainz.org/track/{$track->mbid}.html">{$track->mbid}</a></b><br
 />
-{/if}
-<br />
-<a href="{$track->licenseurl}"><img 
src="{$base_url}/themes/librefm/images/licenses/{$track->license}.png" /></a>
+       <dl>
+               <dt>Artist:</dt>
+               <dd rel="foaf:maker" rev="foaf:made" class="contributor vcard">
+                       <a about="{$artist->id|escape:'html':'UTF-8'}" 
typeof="mo:MusicArtist" property="foaf:name" class="url fn org"
+                               rel="foaf:page" rev="foaf:primaryTopic" 
href="{$artist->getURL()|escape:'html':'UTF-8'}">{$artist->name|escape:'html':'UTF-8'}</a>
+               </dd>
+               <dt>Album:</dt>
+               <dd rev="mo:track">
+                       <a about="{$album->id|escape:'html':'UTF-8'}" 
typeof="mo:Record" property="dc:title" class="album"
+                               rel="foaf:page" rev="foaf:primaryTopic" 
href="{$album->getURL()|escape:'html':'UTF-8'}">{$album->name|escape:'html':'UTF-8'}</a>
+               </dd>
+               {if $track->mbid != ""}
+               <dt>MusicBrainz ID:</dt>
+               <dd>
+                       <a rel="mo:musicbrainz" rev="foaf:primaryTopic" 
href="http://musicbrainz.org/track/{$track->mbid}.html"
+                               class="url">{$track->mbid}</a>
+               </dd>
+               {/if}
+       </dl>
 
-<ul id="tracks">
-{if !empty($track->duration)}<li> Duration: {$track->duration}</li>{/if}
-  <li>
-      Playcount: {$track->getPlayCount()}
-  </li>
-  <li>
-      Listeners: {$track->getListenerCount()}
-  </li>
-  <li>
+       {if $track->licenseurl && $track->license}
+       <p><a rel=":license" href="{$track->licenseurl}"><img 
src="{$base_url}/themes/librefm/images/licenses/{$track->license}.png" 
/></a></p>
+       {/if}
 
-      Albums containing this track:
-{section name=i loop=$albums}
-<span{if $albums[i]->image != false} about="{$albums[i]->id}"{/if}>
-<img class="album photo" {if $albums[i]->image == false} 
src="{$base_url}/i/qm160.png"{else}src="{$albums[i]->image}"{/if}
- 
alt="{$albums[i]->name|escape:'html':'UTF-8'}"title="{$albums[i]->name|escape:'html':'UTF-8'}"
 width="160" />
-</span>
-{/section}
-
-  </li>
-</ul>
+       <ul>
+               {if !empty($track->duration)}<li property="mo:durationXSD" 
datatype="xsd:duration" content="PT{$track->duration}S">Duration: 
{$track->duration}</li>{/if}
+               <li property="rdfs:comment">Playcount: 
{$track->getPlayCount()}</li>
+               <li property="rdfs:comment">Listeners: 
{$track->getListenerCount()}</li>
+       </ul>
+  
+       <h3>Albums containing this track:</h3>
+       <div rev="mo:track">
+       {section name=i loop=$albums}
+       
+               <span about="{$albums[i]->id|escape:'html':'UTF-8'}" 
typeof="mo:Record" property="dc:title" 
content="{$albums[i]->name|escape:'html':'UTF-8'}">
+                       <a rel="foaf:page" rev="foaf:primaryTopic" 
href="{$albums[i]->getURL()|escape:'html':'UTF-8'}">
+                               <img {if $albums[i]->image == false} 
src="{$base_url}/i/qm160.png"{else}src="{$albums[i]->image|escape:'html':'UTF-8'}"
 rev="foaf:depiction" resource="{$albums[i]->id|escape:'html':'UTF-8'}"{/if}
+                                       
alt="{$albums[i]->name|escape:'html':'UTF-8'}" 
title="{$albums[i]->name|escape:'html':'UTF-8'}" width="160" />
+                       </a>
+               </span>
+       {/section}
+       </div>
+  
+</div>
 <div class="cleaner">&nbsp;</div>
 {include file='footer.tpl'}

Modified: trunk/nixtape/track.php
===================================================================
--- trunk/nixtape/track.php     2009-05-07 13:43:51 UTC (rev 1277)
+++ trunk/nixtape/track.php     2009-05-07 15:34:48 UTC (rev 1278)
@@ -26,11 +26,13 @@
 require_once('data/TagCloud.php');
 
 $track = new Track(urldecode($_GET['track']), urldecode($_GET['artist']));
+$smarty->assign("track", $track);
 
+$album = new Album($track->album_name, $track->artist_name);
+$smarty->assign("album", $album);
 
-$smarty->assign("track", $track);
-$smarty->assign("albumurl", Server::getAlbumURL($track->artist_name, 
$track->album_name));
-$smarty->assign("artisturl", Server::getArtistURL($track->artist_name));
+$artist = new Artist($track->artist_name);
+$smarty->assign("artist", $artist);
 
 // no idea how this would be track-relevant
 $aTagCloud = TagCloud::GenerateTagCloud(TagCloud::scrobblesTable(), 'artist');

Modified: trunk/nixtape/utils/linkeddata.php
===================================================================
--- trunk/nixtape/utils/linkeddata.php  2009-05-07 13:43:51 UTC (rev 1277)
+++ trunk/nixtape/utils/linkeddata.php  2009-05-07 15:34:48 UTC (rev 1278)
@@ -1,31 +1,45 @@
 <?php
 
+/* Libre.fm -- a free network service for sharing your music listening habits
+
+   Copyright (C) 2009 Free Software Foundation, Inc
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Affero General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Affero General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+/**
+ * Generates linked data URIs for various concepts including scrobble events,
+ * artists, albums and tracks. General technique is to create a dbtune.org
+ * URI if we have the appropriate MusicBrainz ID. Otherwise, create a URI
+ * based on the scrobble time if known. Lastly, create one based on the 
libre.fm
+ * artist page.
+ */
+
+require_once($install_path . 'data/Server.php');
+
 function identifierScrobbleEvent ($username, $artist, $track, $album, $time, 
$mbid=NULL, $ambid=NULL, $lmbid=NULL)
 {
-       global $base_url;
-
        if (!($username && $artist && $track && $time))
                return null;
 
        $microhash = substr(md5($artist . '//' . $track), 0, 4);
-       return $base_url . sprintf('/user/%s#%s.%s', rawurlencode($username), 
rawurlencode($time), rawurlencode($microhash));
+       return sprintf('%s#%s.%s', Server::getUserURL($username), 
rawurlencode($time), rawurlencode($microhash));
 }
 
-function identifierTrack ($username, $artist, $track, $album, $time, 
$mbid=NULL, $ambid=NULL, $lmbid=NULL)
-{
-       if (!empty($mbid))
-       {
-               return 
sprintf('http://dbtune.org/musicbrainz/resource/track/%s', strtolower($mbid));
-       }
-       else
-       {
-               return identifierScrobbleEvent($username, $artist, $track, 
$album, $time, $mbid, $ambid, $lmbid) . '.track';
-       }
-}
-
 function identifierArtist ($username, $artist, $track, $album, $time, 
$mbid=NULL, $ambid=NULL, $lmbid=NULL)
 {
-       # Eventually look up MBIDs from Artists table?
        if (!empty($ambid))
        {
                return 
sprintf('http://dbtune.org/musicbrainz/resource/artist/%s', strtolower($ambid));
@@ -34,13 +48,11 @@
        $u = identifierScrobbleEvent($username, $artist, $track, $album, $time, 
$mbid, $ambid, $lmbid) . '.artist';
        if ($u != '.artist') return $u;
 
-       global $base_url;
-       return $base_url . sprintf('/artist/%s#artist', rawurlencode($artist));
+       return sprintf('%s#artist', Server::getArtistURL($artist));
 }
 
 function identifierAlbum ($username, $artist, $track, $album, $time, 
$mbid=NULL, $ambid=NULL, $lmbid=NULL)
 {
-       # Eventually look up MBIDs from Artists table?
        if (!empty($lmbid))
        {
                return 
sprintf('http://dbtune.org/musicbrainz/resource/record/%s', strtolower($lmbid));
@@ -49,7 +61,20 @@
        $u = identifierScrobbleEvent($username, $artist, $track, $album, $time, 
$mbid, $ambid, $lmbid) . '.album';
        if ($u != '.album') return $u;
 
-       global $base_url;
-       return $base_url . sprintf('/artist/%s/album/%s#this', 
rawurlencode($artist), rawurlencode($album));
+       return sprintf('%s#album', Server::getAlbumURL($artist, $album));
 }
 
+function identifierTrack ($username, $artist, $track, $album, $time, 
$mbid=NULL, $ambid=NULL, $lmbid=NULL)
+{
+       if (!empty($mbid))
+       {
+               return 
sprintf('http://dbtune.org/musicbrainz/resource/track/%s', strtolower($mbid));
+       }
+
+       $u = identifierScrobbleEvent($username, $artist, $track, $album, $time, 
$mbid, $ambid, $lmbid) . '.track';
+       if ($u != '.track') return $u;
+       
+       return sprintf('%s#track', Server::getTrackURL($artist, $album, 
$track));
+}
+
+





reply via email to

[Prev in Thread] Current Thread [Next in Thread]