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

rdf.php 2.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php

/* Libre.fm -- a free network service for sharing your music listening habits

   Copyright (C) 2009 Libre.fm Project

   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/>.

*/

require_once 'config.php';
require_once 'utils/arc/ARC2.php';

$page = $_GET['page'];
$fmt  = $_GET['fmt'];

28
if (empty($fmt)) $fmt = 'xml';
elleo's avatar
elleo committed
29
if (empty($page)) die('Required parameter \'page\' not provided.');
30 31

$parser = ARC2::getSemHTMLParser(array('sem_html_formats' => 'rdfa'));
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
$parser->parse($base_url . $page);
$index = $parser->getSimpleIndex(0);

$conf = array(
	'ns' => array(
		'xhv' => 'http://www.w3.org/1999/xhtml/vocab#',
		'dc' => 'http://purl.org/dc/terms/',
		'foaf' => 'http://xmlns.com/foaf/0.1/',
		'bio' => 'http://purl.org/vocab/bio/0.1/' ,
		'sioc' => 'http://rdfs.org/sioc/ns#',
		'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
		'gob' => 'http://purl.org/ontology/last-fm/',
		'mo' => 'http://purl.org/ontology/mo/',
		'rss' => 'http://purl.org/rss/1.0/'
		)
	);

switch ($fmt)
{
	case 'xml' :
elleo's avatar
elleo committed
52
		header('Content-Type: application/rdf+xml');
53 54 55
		$ser = ARC2::getRDFXMLSerializer($conf);
		break;
	case 'ttl' :
elleo's avatar
elleo committed
56
		header('Content-Type: application/x-turtle');
57 58 59
		$ser = ARC2::getTurtleSerializer($conf);
		break;
	case 'rss' :
elleo's avatar
elleo committed
60
		header('Content-Type: application/rss+xml');
61 62 63 64
		$ser = ARC2::getRSS10Serializer($conf);
		break;
	case 'json' :
		if ($_GET['callback'])
elleo's avatar
elleo committed
65
			{ header('Content-Type: text/javascript'); }
clint's avatar
clint committed
66
		else
elleo's avatar
elleo committed
67
			{ header('Content-Type: application/json'); }
68 69 70
		$ser = ARC2::getRDFJSONSerializer($conf);
		break;
	case 'nt' :
elleo's avatar
elleo committed
71
		header('Content-Type: text/plain');
72 73 74 75
		$ser = ARC2::getNTriplesSerializer($conf);
		break;
}

elleo's avatar
elleo committed
76
if ($_GET['callback']) {
77
	print $_GET['callback'] . '(';
elleo's avatar
elleo committed
78
}
79
print $ser->getSerializedIndex($index);
elleo's avatar
elleo committed
80
if ($_GET['callback']) {
81
	print ');';
elleo's avatar
elleo committed
82
}
clint's avatar
clint committed
83