You are here

biblio_citeproc.module in Bibliography Module 6.2

File

modules/CiteProc/biblio_citeproc.module
View source
<?php

function biblio_citeproc_menu() {
  global $user;
  $items = array();
  $items['admin/settings/biblio/citeproc'] = array(
    'title' => 'CiteProc',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'biblio_citeproc_style_manager_form',
    ),
    'access arguments' => array(
      'administer biblio',
    ),
    'file' => 'biblio_citeproc.admin.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 12,
  );
  $items['admin/settings/biblio/citeproc/styles'] = array(
    'title' => 'CiteProc Style Manager',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'biblio_citeproc_style_manager_form',
    ),
    'access arguments' => array(
      'administer biblio',
    ),
    'file' => 'biblio_citeproc.admin.inc',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 12,
  );
  $items['admin/settings/biblio/citeproc/styles/%/edit'] = array(
    'title' => 'CiteProc Style Editor',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'biblio_citeproc_csl_editor',
      5,
    ),
    'access arguments' => array(
      'administer biblio',
    ),
    'file' => 'biblio_citeproc.admin.inc',
    'type' => MENU_CALLBACK,
    'weight' => 12,
  );
  $items['admin/settings/biblio/citeproc/map'] = array(
    'title' => 'CSL Field Mapper',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'biblio_admin_io_mapper_form',
      'csl',
      FALSE,
    ),
    'access arguments' => array(
      'administer biblio',
    ),
    'file' => '../../includes/biblio.admin.inc',
    'type' => MENU_LOCAL_TASK,
    'weight' => 12,
  );
  return $items;
}
function biblio_citeproc_theme() {
  return array(
    'biblio_citeproc_style' => array(
      'function' => 'theme_biblio_citeproc_style',
      'file' => 'biblio_citeproc.module',
      'arguments' => array(
        'node',
        'base' => 'biblio',
        'style_name' => 'classic',
        'inline' => FALSE,
      ),
    ),
    'biblio_citeproc_style_manager_form' => array(
      'render element' => 'form',
    ),
  );
}
function biblio_citeproc_theme_registry_alter(&$theme_registry) {
  $theme_registry['biblio_style'] = $theme_registry['biblio_citeproc_style'];
}
function theme_biblio_citeproc_style($node, $base = 'biblio', $style_name = NULL, $inline = false) {
  static $citeproc;
  global $language;
  $cached = NULL;
  module_load_include('inc', 'biblio_citeproc', 'CSL');
  if (!$citeproc) {
    $csl_id = $style_name ? $style_name : biblio_get_style();
    if (strpos($csl_id, '.csl') === FALSE) {

      // try to convert old style names to csl...
      if (in_array($csl_id, array(
        'ama',
        'apa',
        'cse',
        'ieee',
        'mla',
        'vancouver',
      ))) {
        $csl_id .= '.csl';
      }
      elseif ($csl_id == 'chicago') {
        $csl_id = 'chicago-fullnote-bibliography.csl';
      }
      else {
        $csl_id = '';
        $message = t('An invalid style "@style" was selected, please check your "CiteProc" style settings.', array(
          '@style' => $csl_id,
        ));
        drupal_set_message($message, 'error');
      }
    }
    if (!empty($csl_id)) {
      $csl = db_fetch_object(db_query("SELECT parent,csl FROM {biblio_citeproc_styles} WHERE filename = '%s'", $csl_id));
      if (!isset($csl->csl)) {
        drupal_set_message(t('Biblio-CiteProc could not fetch the style file: @csl_id from the database.', array(
          '@csl_id' => $csl_id,
        )), 'error');
        return;
      }
      if (!empty($csl->parent)) {
        $csl_file_contents = db_result(db_query("SELECT csl FROM {biblio_citeproc_styles} WHERE id = '%s'", $csl->parent));
        if (!$csl_file_contents) {
          drupal_set_message(t('Biblio-CiteProc could not fetch the parent style file: @csl_id from the database.', array(
            '@csl_id' => $csl->parent,
          )), 'error');
          return;
        }
      }
      else {
        $csl_file_contents = $csl->csl;
      }

      //    $cslid = $csl_file_name . '-' . $language->language;
      //    $cached = cache_get($cslid, 'cache_biblio_csl_object');
      if (!$cached) {
        $citeproc = new citeproc($csl_file_contents, $language->language);

        //      cache_set($cslid, $citeproc, 'cache_biblio_csl_object');
      }
      else {
        $citeproc = $cached->data;
      }
    }
  }
  $styled_node = $citeproc
    ->render($node);
  return $styled_node . filter_xss($node->biblio_coins, array(
    'span',
  ));
}