View source
<?php
function biblio_citeproc_install() {
drupal_install_schema('biblio_citeproc');
biblio_citeproc_install_default_styles();
_save_csl_maps();
}
function biblio_citeproc_uninstall() {
drupal_uninstall_schema('biblio_citeproc');
if (db_table_exists('biblio_type_maps')) {
db_query("DELETE FROM {biblio_type_maps} WHERE format = 'csl'");
}
}
function biblio_citeproc_requirements($phase) {
$requirements = array();
$t = get_t();
if ($phase == 'install') {
if (function_exists('mb_strtoupper')) {
$mbs_severity = REQUIREMENT_OK;
$mbs_desc = $t('PHP "Multibyte String" extension is enabled');
}
else {
$mbs_severity = REQUIREMENT_ERROR;
$mbs_desc = $t('Your PHP installation does not have the "Multibyte String" extension enabled, Biblio - CiteProc requires the Multibyte String extension');
}
$requirements['mbs'] = array(
'title' => $t('PHP Multibyte String'),
'severity' => $mbs_severity,
'description' => $mbs_desc,
);
if (!module_exists('biblio')) {
$requirements['biblio_crossref'] = array(
'title' => $t('Biblio'),
'description' => $t('The Biblio module must be installed first'),
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
function biblio_citeproc_schema() {
$schema['biblio_citeproc_styles'] = array(
'fields' => array(
'id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'filename' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'parent' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'summary' => array(
'type' => 'text',
'not null' => FALSE,
),
'csl' => array(
'type' => 'text',
'not null' => TRUE,
),
'sha1' => array(
'type' => 'varchar',
'length' => 40,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array(
'id',
),
);
return $schema;
}
function biblio_citeproc_install_default_styles() {
$record = array();
$dir = drupal_get_path('module', 'biblio_citeproc') . '/style';
$files = file_scan_directory($dir, '..*.csl$');
foreach ($files as $file) {
$csl = file_get_contents($file->filename);
$xml = simplexml_load_string($csl);
$parent = '';
foreach ($xml->info->link as $link) {
$attrs = $link
->attributes();
if (isset($attrs['rel']) && $attrs['rel'] == 'independent-parent') {
$parent = (string) $attrs['href'];
}
}
$record = array(
'filename' => basename($file->filename),
'parent' => $parent,
'title' => (string) $xml->info->title,
'summary' => (string) $xml->info->summary,
'csl' => $csl,
'sha1' => sha1($csl),
'id' => (string) $xml->info->id,
);
db_query("INSERT INTO {biblio_citeproc_styles} (filename, parent, title, summary, csl, sha1, id) VALUES ('%s', '%s', '%s', '%s', '%s', %b, '%s')", $record);
}
}
function _get_csl_type_map() {
$map['type_map'] = serialize(array(
'article' => '',
'article-magazine' => 106,
'article-newspaper' => 105,
'article-journal' => 102,
'bill' => 117,
'book' => 100,
'broadcast' => 111,
'chapter' => 101,
'entry' => '',
'entry-dictionary' => '',
'entry-encyclopedia' => '',
'figure' => '',
'graphic' => '',
'interview' => '',
'legislation' => 118,
'legal_case' => 128,
'manuscript' => 121,
'map' => 122,
'motion_picture' => 110,
'musical_score' => '',
'pamphlet' => '',
'paper-conference' => 103,
'patent' => 119,
'post' => '',
'post-weblog' => '',
'personal\\_communication' => 120,
'report' => 109,
'review' => '',
'review-book' => '',
'song' => '',
'speech' => '',
'thesis' => 108,
'treaty' => '',
'webpage' => 107,
));
$map['format'] = 'csl';
return $map;
}
function _get_csl_type_names() {
$map['type_names'] = serialize(array(
'article' => '',
'article-magazine' => "Magazine Article",
'article-newspaper' => "Newspaper Article",
'article-journal' => "Journal Article",
'bill' => 'Bill',
'book' => "Book",
'broadcast' => 'Broadcast',
'chapter' => "Book Section",
'entry' => '',
'entry-dictionary' => '',
'entry-encyclopedia' => '',
'figure' => '',
'graphic' => '',
'interview' => '',
'legislation' => 'Legislation',
'legal_case' => 'Legal Ruling',
'manuscript' => 'Manuscript',
'map' => 'Map',
'motion_picture' => "Film or Broadcast",
'musical_score' => '',
'pamphlet' => '',
'paper-conference' => "Conference Paper",
'patent' => "Patent",
'post' => '',
'post-weblog' => '',
'personal\\_communication' => 'Personal Communication',
'report' => "Report",
'review' => '',
'review-book' => '',
'song' => '',
'speech' => '',
'thesis' => "Thesis",
'treaty' => '',
'webpage' => "Web Page",
));
$map['format'] = 'csl';
return $map;
}
function _get_csl_field_map() {
$map['field_map'] = serialize(array(
'title' => 'title',
'container-title' => 'biblio_secondary_title',
'collection-title' => 'biblio_secondary_title',
'original-title' => 'biblio_alternate_title',
'publisher' => 'biblio_publisher',
'publisher-place' => 'biblio_place_published',
'original-publisher' => '',
'original-publisher-place' => '',
'archive' => '',
'archive-place' => '',
'authority' => '',
'archive_location' => '',
'event' => 'biblio_secondary_title',
'event-place' => 'biblio_place_published',
'page' => 'biblio_pages',
'page-first' => '',
'locator' => '',
'version' => 'biblio_edition',
'volume' => 'biblio_volume',
'number-of-volumes' => 'biblio_number_of_volumes',
'number-of-pages' => '',
'issue' => 'biblio_issue',
'chapter-number' => 'biblio_section',
'medium' => '',
'status' => '',
'edition' => 'biblio_edition',
'section' => 'biblio_section',
'genre' => '',
'note' => 'biblio_notes',
'annote' => '',
'abstract' => 'biblio_abst_e',
'keyword' => 'biblio_keywords',
'number' => 'biblio_number',
'references' => '',
'URL' => 'biblio_url',
'DOI' => 'biblio_doi',
'ISBN' => 'biblio_isbn',
'call-number' => 'biblio_call_number',
'citation-number' => '',
'citation-label' => 'biblio_citekey',
'first-reference-note-number' => '',
'year-suffix' => '',
'jurisdiction' => '',
'issued' => 'biblio_year',
'event' => 'biblio_date',
'accessed' => 'biblio_accessed',
'container' => 'biblio_date',
'original-date' => 'biblio_date',
'author' => 'biblio_contributors:1',
'editor' => 'biblio_contributors:2',
'translator' => 'biblio_contributors:3',
'recipient' => ':',
'interviewer' => ':',
'publisher' => 'biblio_publisher:',
'composer' => ':',
'original-publisher' => ':',
'original-author' => ':',
'container-author' => ':',
'collection-editor' => ':',
));
$map['format'] = 'csl';
return $map;
}
function _save_csl_maps() {
$typemap = _get_csl_type_map();
$typenames = _get_csl_type_names();
$fieldmap = _get_csl_field_map();
$maps = array_merge($typemap, $typenames, $fieldmap);
db_query("INSERT INTO {biblio_type_maps} (format,type_map,type_names,field_map) VALUES ('%s','%s','%s','%s')", array(
$maps['format'],
$maps['type_map'],
$maps['type_names'],
$maps['field_map'],
));
}
function _reset_csl_map($type = NULL) {
$count = db_result(db_query("SELECT COUNT(*) FROM {biblio_type_maps} WHERE format='csl'"));
if ($count && $type) {
$function = '_get_csl_' . $type;
if (!function_exists($function)) {
return;
}
$map = $function();
drupal_write_record('biblio_type_maps', $map, 'format');
}
else {
db_query("DELETE FROM {biblio_type_maps} WHERE format='csl'");
_save_csl_maps();
}
}
function biblio_citeproc_update_6001() {
$result = array();
drupal_uninstall_module('biblio_citeproc');
drupal_install_modules(array(
'biblio_citeproc',
));
return $result;
}
function biblio_citeproc_update_6002() {
$result = array();
_reset_csl_map();
return $result;
}
function biblio_citeproc_update_6003() {
$result = array();
$spec = array(
'type' => 'text',
'not null' => TRUE,
);
db_change_field($result, 'biblio_citeproc_styles', 'csl', 'csl', $spec);
return $result;
}