<?php
// $Id: rdf_export.module,v 1.1 2008/02/11 21:54:18 arto Exp $
/**
 * rdf_export.module - Exports Drupal data in various RDF formats.
 *
 * @author Arto Bendiken <http://bendiken.net/>
 * @copyright Copyright (c) 2007-2008 Arto Bendiken. All rights reserved.
 * @license GPL <http://creativecommons.org/licenses/GPL/2.0/>
 * @package rdf.module
 * @subpackage rdf_export.module
 */

//////////////////////////////////////////////////////////////////////////////
// Core API hooks

/**
 * Implementation of hook_perm().
 */
function rdf_export_perm() {
  return array('export RDF data');
}

/**
 * Implementation of hook_menu().
 */
function rdf_export_menu() {
  return array(
    // Administer >> Content management >> RDF data
    'admin/content/rdf/export' => array(
      'title' => 'Export data',
      'type' => MENU_LOCAL_TASK,
      'weight' => 30,
      'access arguments' => array('export RDF data'),
      'page callback' => 'drupal_get_form',
      'page arguments' => array('rdf_export_admin_screen'),
      'file' => 'rdf_export.admin.inc',
    ),
    // Export site information
    'rdf' => array(
      'title' => 'RDF',
      'type' => MENU_CALLBACK,
      'access callback' => 'user_access',
      'access arguments' => array('access RDF data'),
      'page callback' => 'rdf_export_site',
      'file' => 'rdf_export.pages.inc',
    ),
    // Export user information
    'user/%/rdf' => array(
      'title' => 'RDF',
      'type' => MENU_CALLBACK,
      'access callback' => 'user_access',
      'access arguments' => array('access RDF data'),
      'page callback' => 'rdf_export_entity',
      'page arguments' => array('user', 1),
      'file' => 'rdf_export.pages.inc',
    ),
    // Export node information
    'node/%/rdf' => array(
      'title' => 'RDF',
      'type' => MENU_CALLBACK,
      'access callback' => 'user_access',
      'access arguments' => array('access RDF data'),
      'page callback' => 'rdf_export_entity',
      'page arguments' => array('node', 1),
      'file' => 'rdf_export.pages.inc',
    ),
  );
}

/**
 * Implementation of hook_init().
 */
function rdf_export_init() {
  if (user_access('access RDF data')) {
    rdf_add_autodiscovery_link(t('RDF'), url('rdf'));
  }
}

/**
 * Implementation of hook_user().
 */
function rdf_export_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'view':
      if (user_access('access RDF data')) {
        rdf_add_autodiscovery_link(t('RDF'), url('user/' . $account->uid . '/rdf'));
      }
      break;
  }
}

/**
 * Implementation of hook_nodeapi().
 */
function rdf_export_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'view':
      if (user_access('access RDF data')) {
        rdf_add_autodiscovery_link(t('RDF'), url('node/' . $node->nid . '/rdf'));
      }
      break;
  }
}

//////////////////////////////////////////////////////////////////////////////
// RDF API hooks

/**
 * Implementation of hook_rdf_formats().
 */
function rdf_export_rdf_formats() {
  return array(
    'rdf+xml' => array(
      'title'       => t('RDF/XML'),
      'link'        => 'http://www.w3.org/TR/rdf-syntax-grammar/',
      'mime_type'   => 'application/rdf+xml',
      'encoding'    => 'utf-8',
      'file_ext'    => 'rdf',
      'serialize'   => 'rdf_serialize_xml',
      'file'        => 'rdf_export.inc',
    ),
    'trix' => array(
      'title'       => t('TriX'),
      'link'        => 'http://www.w3.org/2004/03/trix/',
      'mime_type'   => 'application/trix',
      'encoding'    => 'utf-8',
      'file_ext'    => 'xml',
      'serialize'   => 'rdf_serialize_trix',
      'file'        => 'rdf_export.inc',
    ),
    'turtle' => array(
      'title'       => t('Turtle'),
      'link'        => 'http://www.dajobe.org/2004/01/turtle/',
      'mime_type'   => 'application/x-turtle',
      'encoding'    => 'utf-8',
      'file_ext'    => 'ttl',
      'serialize'   => 'rdf_serialize_turtle',
      'file'        => 'rdf_export.inc',
    ),
    'ntriples' => array(
      'title'       => t('N-Triples'),
      'link'        => 'http://www.w3.org/TR/rdf-testcases/#ntriples',
      'mime_type'   => 'text/plain', // TODO: any semi-standardized alternative?
      'encoding'    => 'ascii',
      'file_ext'    => 'nt',
      'serialize'   => 'rdf_serialize_ntriples',
      'file'        => 'rdf_export.inc',
    ),
  );
}
