View source
<?php
function biblio_xml_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'biblio_xml') . '/views',
);
}
function biblio_xml_menu() {
global $user;
$items = array();
$base = variable_get('biblio_base', 'biblio');
$items["{$base}/export/xml"] = array(
'title' => '',
'page callback' => 'biblio_xml_biblio_export',
'access callback' => 'user_access',
'access arguments' => array(
'show export links',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function biblio_xml_biblio_import_options() {
return array(
'biblio_xml' => t('EndNote XML'),
);
}
function biblio_xml_biblio_mapper_options() {
return array(
'endnote7' => array(
'title' => t('EndNote 7 XML'),
'export' => TRUE,
),
'endnote8' => array(
'title' => t('EndNote X3 XML'),
'export' => TRUE,
),
);
}
function biblio_xml_biblio_export_link_settings() {
return array(
'xml' => t('EndNote XML'),
);
}
function biblio_xml_link($type, $node = NULL, $teaser = FALSE) {
if ($type != 'node' || $node->type != 'biblio') {
return;
}
return biblio_xml_biblio_export_link($node->nid);
}
function biblio_xml_biblio_export_link($nid = NULL) {
$show_link = variable_get('biblio_export_links', array(
'xml' => TRUE,
));
if (!$show_link['xml'] || !biblio_access('export')) {
return array();
}
$base = variable_get('biblio_base', 'biblio');
$link = array(
'attributes' => array(
'title' => t("Click to download the EndNote XML formatted file"),
),
);
$link['href'] = "{$base}/export/xml/{$nid}";
$link['title'] = t('XML');
return array(
'biblio_xml' => $link,
);
}
function biblio_xml_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($node->type != 'biblio') {
return;
}
$callback = '_biblio_xml_' . str_replace(' ', '_', $op);
if (function_exists($callback)) {
return $callback($node, $a3, $a4);
}
return;
}
function _biblio_xml_delete($node) {
db_query('DELETE FROM {biblio_xml} WHERE nid = %d', $node->nid);
}
function _biblio_xml_insert($node) {
if (!isset($node->biblio_xml_md5)) {
return;
}
drupal_write_record('biblio_xml', $node);
}
function biblio_xml_biblio_import($file, $terms = array(), $batch = FALSE, $session_id = NULL, $save = TRUE, $string = FALSE) {
module_load_include('inc', 'biblio_xml', 'endnote_xml_parser');
$parser = new EndNoteXMLParser();
return $parser
->parse($file, $terms, $batch, $session_id);
}
function biblio_xml_biblio_export($nid = null) {
$nids = array();
if ($nid === null && isset($_SESSION['last_biblio_query']) && !empty($_SESSION['last_biblio_query'])) {
$query = $_SESSION['last_biblio_query'];
$params = $_SESSION['last_biblio_query_terms'];
$result = db_query($query, $params);
while ($node = db_fetch_object($result)) {
$nids[] = $node->nid;
}
}
elseif (!empty($nid)) {
$nids[] = $nid;
}
elseif (!count($nids)) {
return;
}
module_load_include('inc', 'biblio_xml', 'endnote8_export');
drupal_set_header('Content-type: application/xml; charset=utf-8');
drupal_set_header('Content-Disposition: attachment; filename="Biblio-EndNote' . $version . '.xml"');
print _endnote8_XML_export('', 'begin');
foreach ($nids as $nid) {
$node = node_load($nid, FALSE, TRUE);
if (variable_get('biblio_hide_bibtex_braces', 0)) {
$node->title = biblio_remove_brace($node->title);
}
print _endnote8_XML_export($node);
}
print _endnote8_XML_export('', 'end');
}
function biblio_xml_endnote8_map_reset($type = NULL) {
module_load_include('install', 'biblio_xml', 'biblio_xml');
_reset_endnote_xml_map('endnote8', $type);
}
function biblio_xml_endnote7_map_reset($type = NULL) {
module_load_include('install', 'biblio_xml', 'biblio_xml');
_reset_endnote_xml_map('endnote7', $type);
}