rdf.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* GNU FM -- a free network service for sharing your music listening habits
  3. Copyright (C) 2009 Free Software Foundation, Inc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. require_once('config.php');
  16. require_once('utils/arc/ARC2.php');
  17. $page = $_GET['page'];
  18. $fmt = $_GET['fmt'];
  19. if (empty($fmt)) {
  20. $fmt = 'xml';
  21. }
  22. if (empty($page)) {
  23. die('Required parameter \'page\' not provided.');
  24. }
  25. $parser = ARC2::getSemHTMLParser(array('sem_html_formats' => 'rdfa'));
  26. $parser->parse($base_url . $page);
  27. $index = $parser->getSimpleIndex(0);
  28. $conf = array(
  29. 'ns' => array(
  30. 'xhv' => 'http://www.w3.org/1999/xhtml/vocab#',
  31. 'dc' => 'http://purl.org/dc/terms/',
  32. 'foaf' => 'http://xmlns.com/foaf/0.1/',
  33. 'bio' => 'http://purl.org/vocab/bio/0.1/',
  34. 'sioc' => 'http://rdfs.org/sioc/ns#',
  35. 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
  36. 'gob' => 'http://purl.org/ontology/last-fm/',
  37. 'mo' => 'http://purl.org/ontology/mo/',
  38. 'rss' => 'http://purl.org/rss/1.0/'
  39. )
  40. );
  41. switch ($fmt) {
  42. case 'xml' :
  43. header('Content-Type: application/rdf+xml');
  44. $ser = ARC2::getRDFXMLSerializer($conf);
  45. break;
  46. case 'ttl' :
  47. header('Content-Type: application/x-turtle');
  48. $ser = ARC2::getTurtleSerializer($conf);
  49. break;
  50. case 'rss' :
  51. header('Content-Type: application/rss+xml');
  52. $ser = ARC2::getRSS10Serializer($conf);
  53. break;
  54. case 'json' :
  55. if ($_GET['callback']) {
  56. header('Content-Type: text/javascript');
  57. } else {
  58. header('Content-Type: application/json');
  59. }
  60. $ser = ARC2::getRDFJSONSerializer($conf);
  61. break;
  62. case 'nt' :
  63. header('Content-Type: text/plain');
  64. $ser = ARC2::getNTriplesSerializer($conf);
  65. break;
  66. }
  67. if (isset($_GET['callback'])) {
  68. print $_GET['callback'] . '(';
  69. }
  70. print $ser->getSerializedIndex($index);
  71. if ($_GET['callback']) {
  72. print ');';
  73. }