diff --git a/plugins/biblio_style/abstract.inc b/plugins/biblio_style/abstract.inc index 354808f7..088519f9 100644 --- a/plugins/biblio_style/abstract.inc +++ b/plugins/biblio_style/abstract.inc @@ -70,6 +70,8 @@ abstract class BiblioStyleBase implements BiblioStyleInterface { /** * The Biblio entity. + * + * @return Biblio */ protected $biblio; diff --git a/plugins/biblio_style/endnote/BiblioStyleEndNoteXML8.php b/plugins/biblio_style/endnote/BiblioStyleEndNoteXML8.php index 314fce9e..00590a8d 100644 --- a/plugins/biblio_style/endnote/BiblioStyleEndNoteXML8.php +++ b/plugins/biblio_style/endnote/BiblioStyleEndNoteXML8.php @@ -258,9 +258,33 @@ public function importContributor(EntityMetadataWrapper $wrapper, $role, $name) /** * @inheritdoc + * + * @todo: Allow passing in options 'wrap' => TRUE, so we can remove the + * tag, */ public function render($options = array(), $langcode = NULL) { + $wrapper = entity_metadata_wrapper('biblio', $this->biblio); + + $writer = new XMLWriter(); + $writer->openMemory(); + $writer->startDocument('1.0','UTF-8'); + $writer->startElement("records"); + $writer->startElement("record"); + $this->addTitles($writer, $wrapper); + + // $writer->writeAttribute("ah", "OK"); + $writer->endElement(); + $writer->endElement(); + return $writer->outputMemory(true); + } + + public function addTitles(XMLWriter $writer, EntityDrupalWrapper $wrapper) { + $writer->startElement('titles'); + $writer->startElement('title'); + $writer->text($wrapper->label()); + $writer->endElement(); + $writer->endElement(); } /** @@ -367,3 +391,211 @@ public function getMapping() { return $return; } } + +function buildXML() { + $xml = new SimpleXMLElement(''); + $output = $xml->asXML(); + dpm($output); +} + +function _endnote8_XML_export($node, $part = 'record') { + $style_attr = 'face="normal" font="default" size="100%"'; + switch ($part) { + case 'begin': + $xml = ''; + $xml .= ""; + break; + case 'record': + $xml = ""; + $xml .= 'Drupal-Biblio'; + $xml .= "" . _endnote8_type_map($node->biblio_type) . ""; + unset($node->biblio_type); + // + $xml .= en8_add_contributors($node); + $xml .= en8_add_titles($node); + $xml .= en8_add_keywords($node); + $xml .= en8_add_dates($node); + $xml .= en8_add_urls($node); + + foreach ($node as $key => $value) { + $entag = en8_field_map($key); + if (!empty($entag) && !empty($value)) { + $xml .= "<" . $entag . '>"; + } + } + $xml .= ""; + break; + case 'end': + $xml = ''; + break; + } + return $xml; +} + +function en8_encode_font_faces(&$node) { + $search = array('', '', '', '', '', '', '', '', '', ''); + $replace = array( + '" :''; + $xml .= (!empty ($node->biblio_secondary_title)) ? '" :''; + $xml .= (!empty ($node->biblio_tertiary_title)) ? '" :''; + $xml .= (!empty ($node->biblio_alternate_title)) ? '" :''; + $xml .= (!empty ($node->biblio_short_title)) ? '" :''; + $xml .= (!empty ($node->biblio_translated_title)) ? '" :''; + $xml .= ''; + unset($node->title); + unset($node->biblio_secondary_title); + unset($node->biblio_tertiary_title); + unset($node->biblio_alternate_title); + unset($node->biblio_short_title); + unset($node->biblio_translated_title); + + return $xml; +} +function en8_add_urls(&$node) { + global $base_path; + $xml = ''; + // TODO: fix URLS + if (!empty($node->biblio_url)) { + $xml .= ""; + $xml .= '"; + $xml .= ""; + } + unset($node->biblio_url); + if (!empty ($node->upload) && count($node->upload['und']) && user_access('view uploaded files')) { + $xml .= ""; + foreach ($node->upload['und'] as $file) { + $xml .= '"; + } + $xml .= ""; + } + unset($node->upload['und']); + if (!empty($xml)) return "$xml"; + return ; +} + +function en8_add_dates(&$node) { + $xml = ''; + if (!empty($node->biblio_year) || !empty($node->biblio_date) ) { + $xml .= ''; + $xml .= (!empty($node->biblio_year)) ? '":''; + $xml .= (!empty($node->biblio_date)) ? '":''; + $xml .= ""; + } + unset($node->biblio_year); + unset($node->biblio_date); + return $xml; +} + +function en8_add_keywords(&$node) { + $kw_array = array(); + $xml = ''; + if (!empty($node->biblio_keywords)) { + foreach ($node->biblio_keywords as $term) { + $kw_array[] = trim($term); + } + } + if (!empty($kw_array)) { + $kw_array = array_unique($kw_array); + $xml .= ''; + foreach ($kw_array as $word) { + $xml .= '"; + } + $xml .= ""; + } + unset($node->biblio_keywords); + return $xml; +} + +function en8_add_contributors(&$node) { + $xml = ''; + $authors = biblio_get_contributor_category($node->biblio_contributors, 1); + if (!empty($authors)) { + $xml .= ""; + foreach ($authors as $auth) { + $xml .= '"; + } + $xml .= ""; + } + $authors = biblio_get_contributor_category($node->biblio_contributors, 2); + if (!empty($authors)) { + $xml .= ""; + foreach ($authors as $auth) { + $xml .= '"; + } + $xml .= ""; + } + $authors = biblio_get_contributor_category($node->biblio_contributors, 3); + if (!empty($authors)) { + $xml .= ""; + foreach ($authors as $auth) { + $xml .= '"; + } + $xml .= ""; + } + $authors = biblio_get_contributor_category($node->biblio_contributors, 4); + if (!empty($authors)) { + $xml .= ""; + foreach ($authors as $auth) { + $xml .= '"; + } + $xml .= ""; + } + $authors = biblio_get_contributor_category($node->biblio_contributors, 5); + if (!empty($authors)) { + $xml .= ""; + foreach ($authors as $auth) { + $xml .= '"; + } + $xml .= ""; + } + $xml .= ''; + unset($node->biblio_contributors); + return $xml; +} + +function en8_field_map($biblio_field) { + static $fmap = array(); + if (empty($fmap)) { + $fmap = biblio_get_map('field_map', 'endnote8'); + } + return ($en8_field = array_search($biblio_field, $fmap)) ? $en8_field : ''; +} + +function _endnote8_type_map($bibliotype) { + static $map = array(); + if (empty($map)) { + $map = biblio_get_map('type_map', 'endnote8'); + } + return ($en8_type = array_search($bibliotype, $map)) ? $en8_type : 13; //return the biblio type or 129 (Misc) if type not found +} +