123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877 |
- <?php
- function tripal_pub_remote_alter_form_AGL($form, $form_state) {
- $num_criteria = $form['num_criteria']['#default_value'];
-
-
-
- $form['days']['#title'] = t('Year');
- $form['days']['#description'] = t('Please enter a year to limit records by the year they were published, created or modified in the database.');
-
- for($i = 1; $i <= $num_criteria; $i++) {
- unset($form['criteria'][$i]["scope-$i"]['#options']['journal']);
- }
- return $form;
- }
- function tripal_pub_remote_validate_form_AGL($form, $form_state) {
- $days = trim($form_state['values']["days"]);
- $num_criteria = $form['num_criteria']['#default_value'];
- if ($days and !preg_match('/^\d\d\d\d$/', $days)) {
- form_set_error("days", "Please enter a four digit year.");
- }
- $num_ids = 0;
- for ($i = 1; $i <= $num_criteria; $i++) {
- $search_terms = trim($form_state['values']["search_terms-$i"]);
- $scope = $form_state['values']["scope-$i"];
- if ($scope == 'id' and !preg_match('/^AGL:\d+$/', $search_terms)) {
- form_set_error("search_terms-$i", "The AGL accession be a numeric value, prefixed with 'AGL:' (e.g. AGL:3890740).");
- }
- if ($scope == 'id') {
- $num_ids++;
- }
- if($num_ids > 1) {
- form_set_error("search_terms-$i", "Unfortuantely, the AGL importer can only support a single accession at a time. Please remove the others.");
- }
- }
- return $form;
- }
- function tripal_pub_remote_search_AGL($search_array, $num_to_retrieve, $pager_id) {
-
- $num_criteria = $search_array['num_criteria'];
- $days = $search_array['days'];
-
- $search_array['limit'] = $num_to_retrieve;
-
-
-
-
-
-
-
-
- $ccl = '';
- $title = '';
- $author = '';
- $abstract = '';
- $id = '';
- $any = '';
- $negate_title = '';
- $negate_author = '';
- $negate_abstract = '';
- $negate_id = '';
- $negate_any = '';
- $order = array();
- $first_abstract = 1;
- $first_author = 1;
- $first_title = 1;
- $first_id = 1;
- $first_any = 1;
- $first_negate_abstract = 1;
- $first_negate_author = 1;
- $first_negate_title = 1;
- $first_negate_id = 1;
- $first_negate_any = 1;
- for ($i = 1; $i <= $num_criteria; $i++) {
- $search_terms = trim($search_array['criteria'][$i]['search_terms']);
- $scope = $search_array['criteria'][$i]['scope'];
- $is_phrase = $search_array['criteria'][$i]['is_phrase'];
- $op = $search_array['criteria'][$i]['operation'];
- if ($op) {
- $op = strtolower($op);
- }
- $search_terms = trim($search_terms);
-
- if (!$is_phrase) {
- $search_terms = preg_replace('/ OR /', ' or ', $search_terms);
- $search_terms = preg_replace('/ AND /', ' and ', $search_terms);
- }
-
- else {
- $search_terms = "\"$search_terms\"";
- }
-
-
- $negate = '';
- if ($op == 'not') {
- $scope = "negate_$scope";
- $op = 'or';
- }
- $order[] = array('scope' => $scope, 'op' => $op);
-
- if ($scope == 'title') {
- if ($first_title) {
- $title .= "($search_terms) ";
- $first_title = 0;
- }
- else {
- $title .= "$op ($search_terms) ";
- }
- }
- if ($scope == 'negate_title') {
- if ($first_negate_title) {
- $negate_title .= "($search_terms) ";
- $first_negate_title = 0;
- }
- else {
- $negate_title .= "$op ($search_terms) ";
- }
- }
- elseif ($scope == 'author') {
- if ($first_author) {
- $author .= "($search_terms) ";
- $first_author = 0;
- }
- else {
- $author .= "$op ($search_terms) ";
- }
- }
- elseif ($scope == 'negate_author') {
- if ($first_negate_author) {
- $negate_author .= "($search_terms) ";
- $first_negate_author = 0;
- }
- else {
- $negate_author .= "$op ($search_terms) ";
- }
- }
- elseif ($scope == 'abstract') {
- if ($first_abstract) {
- $abstract .= "($search_terms) ";
- $first_abstract = 0;
- }
- else {
- $abstract .= "$op ($search_terms) ";
- }
- }
- elseif ($scope == 'negate_abstract') {
- if ($first_negate_abstract) {
- $negate_abstract .= "($search_terms) ";
- $first_negate_abstract = 0;
- }
- else {
- $negate_abstract .= "$op ($search_terms) ";
- }
- }
- elseif ($scope == 'journal') {
- if ($first_journal) {
- $journal .= "($search_terms) ";
- $first_jounral = 0;
- }
- else {
- $journal .= "$op ($search_terms) ";
- }
- }
- elseif ($scope == 'negate_journal') {
- if ($first_negate_journal) {
- $negate_journal .= "($search_terms) ";
- $first_negate_journal = 0;
- }
- else {
- $negate_journal .= "$op ($search_terms) ";
- }
- }
- elseif ($scope == 'id') {
- if ($first_id) {
- $id .= "(" . preg_replace('/AGL:([^\s]*)/', '$1', $search_terms) . ") ";
- $first_id = 0;
- }
- else {
- $id .= "$op (" . preg_replace('/AGL:([^\s]*)/', '$1', $search_terms) . ") ";
- }
- }
- elseif ($scope == 'negate_id') {
- if ($first_negate_id) {
- $negate_id .= "(" . preg_replace('/AGL:([^\s]*)/', '$1', $search_terms) . ") ";
- $first_negate_id = 0;
- }
- else {
- $negate_id .= "$op (" . preg_replace('/AGL:([^\s]*)/', '$1', $search_terms) . ") ";
- }
- }
- elseif ($scope == 'any'){
- if ($first_any) {
- $any .= "($search_terms) ";
- $first_any = 0;
- }
- else {
- $any .= "$op ($search_terms) ";
- }
- }
- elseif ($scope == 'negate_any'){
- if ($first_negate_any) {
- $negate_any .= "($search_terms) ";
- $first_any = 0;
- }
- else {
- $negate_any .= "$op ($search_terms) ";
- }
- }
- }
-
- $abstract_done = 0;
- $author_done = 0;
- $journal_done = 0;
- $title_done = 0;
- $id_done = 0;
- $any_done = 0;
- $negate_abstract_done = 0;
- $negate_journal_done = 0;
- $negate_author_done = 0;
- $negate_title_done = 0;
- $negate_id_done = 0;
- $negate_any_done = 0;
- for ($i = 0; $i < count($order) ; $i++) {
- if ($order[$i]['scope'] == 'abstract' and !$abstract_done) {
- $op = $order[$i]['op'];
- $ccl .= "$op abstract=($abstract) ";
- $abstract_done = 1;
- }
- if ($order[$i]['scope'] == 'negate_abstract' and !$negate_abstract_done) {
- $ccl .= "not abstract=($negate_abstract) ";
- $negate_abstract_done = 1;
- }
- if ($order[$i]['scope'] == 'author' and !$author_done) {
- $op = $order[$i]['op'];
- $ccl .= "$op author=($author) ";
- $author_done = 1;
- }
- if ($order[$i]['scope'] == 'negate_author' and !$negate_author_done) {
- $ccl .= "not author=($negate_author) ";
- $negate_author_done = 1;
- }
- if ($order[$i]['scope'] == 'journal' and !$journal_done) {
- $op = $order[$i]['op'];
- $ccl .= "$op journal=($journal) ";
- $journal_done = 1;
- }
- if ($order[$i]['scope'] == 'negate_journal' and !$negate_journal_done) {
- $ccl .= "not author=($negate_journal) ";
- $negate_journal_done = 1;
- }
- if ($order[$i]['scope'] == 'id' and !$id_done) {
- $op = $order[$i]['op'];
- $ccl .= "$op id=($id) ";
- $id_done = 1;
- }
- if ($order[$i]['scope'] == 'negate_id' and !$negate_id_done) {
- $ccl .= "not id=($negate_id) ";
- $negate_id_done = 1;
- }
- if ($order[$i]['scope'] == 'title' and !$title_done) {
- $op = $order[$i]['op'];
- $ccl .= "$op title=($title) ";
- $title_done = 1;
- }
- if ($order[$i]['scope'] == 'negate_title' and !$negate_title_done) {
- $ccl .= "not title=($negate_title) ";
- $negate_title_done = 1;
- }
- if ($order[$i]['scope'] == 'any' and !$any_done) {
- $op = $order[$i]['op'];
- $ccl .= "$op ($any) ";
- $any_done = 1;
- }
- if ($order[$i]['scope'] == 'negate_any' and !$negate_any_done) {
- $ccl .= "not ($negate_any) ";
- $negate_any_done = 1;
- }
- }
-
- if ($days) {
- $ccl .= "and year=($days)";
- }
-
- $ccl = preg_replace('/^\s*(and|or)/', '', $ccl);
-
-
-
-
- $yazc = yaz_connect('agricola.nal.usda.gov:7190/voyager');
-
- yaz_syntax($yazc, "usmarc");
-
-
-
-
-
-
-
-
-
- $fields = array(
- "title" => "u=4",
- "author" => "u=1003",
- "abstract" => "u=62",
- "id" => "u=12",
- "year" => "u=30 r=o",
- "journal" => "u=1033"
- );
- yaz_ccl_conf($yazc, $fields);
- if (!yaz_ccl_parse($yazc, $ccl, $cclresult)) {
- drupal_set_message('Error parsing search string: ' . $cclresult["errorstring"], "error");
- watchdog('tripal_pub', 'Error: %errstr', array('%errstr' => $cclresult["errorstring"]), WATCHDOG_ERROR);
- return array();
- }
- $search_str = $cclresult["rpn"];
- $search_array['search_string'] = $search_str;
-
- $_SESSION['tripal_pub_AGL_query'][$search_str]['yaz_connection'] = $yazc;
-
-
- $pubs = tripal_pager_callback('tripal_pub_AGL_range', $num_to_retrieve, $pager_id,
- 'tripal_pub_AGL_count', $search_array);
-
- unset($_SESSION['tripal_pub_AGL_query'][$search_str]['yaz_connection']);
- yaz_close($yazc);
- return $pubs;
- }
- function tripal_pub_AGL_count($search_array) {
- $search_str = $search_array['search_string'];
- $days = $search_array['days'];
- $limit = $search_array['limit'];
- $yazc = $_SESSION['tripal_pub_AGL_query'][$search_str]['yaz_connection'];
-
- if (!yaz_search($yazc, "rpn", $search_str)){
- $error_no = yaz_errno($yazc);
- $error_msg = yaz_error($yazc);
- $additional = yaz_addinfo($yazc);
- if ($additional != $error_msg) {
- $error_msg .= " $additional";
- }
- drupal_set_message("ERROR preparing search at AGL: ($error_no) $error_msg", "error");
- return 0;
- }
- if (!yaz_wait()) {
- $error_no = yaz_errno($yazc);
- $error_msg = yaz_error($yazc);
- $additional = yaz_addinfo($yazc);
- if ($additional != $error_msg) {
- $error_msg .= " $additional";
- }
- drupal_set_message("ERROR waiting on search at AGL: ($error_no) $error_msg", "error");
- return 0;
- }
-
- $count = yaz_hits($yazc);
- $_SESSION['tripal_pub_AGL_query'][$search_str]['Count'] = $count;
- return $count;
- }
- function tripal_pub_AGL_range($search_array, $start = 0, $limit = 10) {
- $pubs = array();
- $search_str = $search_array['search_string'];
- $days = $search_array['days'];
- $limit = $search_array['limit'];
- $yazc = $_SESSION['tripal_pub_AGL_query'][$search_str]['yaz_connection'];
- $count = $_SESSION['tripal_pub_AGL_query'][$search_str]['Count'];
- yaz_range($yazc, 1, $num_pubs);
- if (!yaz_present($yazc)) {
- $error_no = yaz_errno($yazc);
- $error_msg = yaz_error($yazc);
- $additional = yaz_addinfo($yazc);
- if ($additional != $error_msg) {
- $error_msg .= " $additional";
- }
- drupal_set_message("ERROR waiting on search at AGL: ($error_no) $error_msg", "error");
- return $pubs;
- }
-
- if ($start + $limit > $count) {
- $limit = $count - $start;
- }
- for($i = $start; $i < $start + $limit; $i++) {
- $pub_xml = yaz_record($yazc, $i + 1, 'xml; charset=marc-8,utf-8');
- $pub = tripal_pub_AGL_parse_pubxml($pub_xml);
- $pubs[] = $pub;
- }
- return $pubs;
- }
- function tripal_pub_AGL_parse_pubxml($pub_xml) {
- $pub = array();
-
-
-
- $pub['Publication Type'][0] = 'Journal Article';
- if (!$pub_xml) {
- return $pub;
- }
-
- $xml = new XMLReader();
- $xml->xml(trim($pub_xml));
- while ($xml->read()) {
- $element = $xml->name;
- if ($xml->nodeType == XMLReader::ELEMENT and $element == 'controlfield') {
- $tag = $xml->getAttribute('tag');
- $xml->read();
- $value = $xml->value;
- switch ($tag) {
- case '001':
- $pub['Publication Accession'] = $value;
- break;
- case '003':
- break;
- case '005':
- break;
- case '006':
- break;
- case '007':
- break;
- case '008':
- $month = array(
- '01' => 'Jan', '02' => 'Feb', '03' => 'Mar',
- '04' => 'Apr', '05' => 'May', '06' => 'Jun',
- '07' => 'Jul', '08' => 'Aug', '09' => 'Sep',
- '10' => 'Oct', '11' => 'Nov', '12' => 'Dec'
- );
- $date0 = substr($value, 0, 6);
- $date1 = substr($value, 7, 4);
- $date2 = substr($value, 11, 4);
- $place = substr($value, 15, 3);
- $lang = substr($value, 35, 3);
- if (preg_match('/\d\d\d\d/', $date1)) {
- $pub['Year'] = $date1;
- $pub['Publication Date'] = $date1;
- }
- if (preg_match('/\d\d/', $date2)) {
- $pub['Publication Date'] = $date1 . " " . $month[substr($date2, 0, 2)] . " " . substr($date2, 3, 2);
- }
- if (!preg_match('/\s+/', $place)) {
- $pub['Published Location'] = $place;
- }
- if (!preg_match('/\s+/', $lang)) {
- $pub['Language Abbr'] = $lang;
- }
- break;
- default:
- break;
- }
- }
- elseif ($xml->nodeType == XMLReader::ELEMENT and $element == 'datafield') {
- $tag = $xml->getAttribute('tag');
- $ind1 = $xml->getAttribute('ind1');
- $ind2 = $xml->getAttribute('ind2');
- switch ($tag) {
- case '16':
- break;
- case '35':
- $author = array();
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- $pub['Publication Accession'] = $value;
- break;
- }
- }
- case '40':
- $author = array();
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- $pub['Publication Database'] = $value;
- break;
- }
- }
- break;
- case '72':
- break;
- case '100':
- $author = tripal_pub_remote_search_AGL_get_author($xml, $ind1);
- $pub['Author List'][] = $author;
- break;
- case '110':
- $author = array();
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- $author['Collective'] = $value;
- break;
- case 'b':
- $author['Collective'] .= ' ' . $value;
- break;
- }
- }
- $pub['Author List'][] = $author;
- break;
- case '111':
- break;
- case '130':
- break;
- case '210':
- break;
- case '222':
- break;
- case '240':
- break;
- case '242':
- break;
- case '243':
- break;
- case '245':
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- $pub['Title'] = trim(preg_replace('/\.$/', '', $value));
- break;
- case 'b':
- $pub['Title'] .= ' ' . $value;
- break;
- case 'h':
- $pub['Publication Model'] = $value;
- break;
- }
- }
- break;
- case '246':
- break;
- case '247':
- break;
- case '250':
- break;
- case '254':
- break;
- case '255':
- break;
- case '256':
- break;
- case '257':
- break;
- case '258':
- break;
- case '260':
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- $pub['Published Location'] = $value;
- break;
- case 'b':
- $pub['Publisher'] = $value;
- break;
- case 'c':
- $pub['Publication Date'] = $value;
- break;
- }
- }
- break;
- case '263':
- break;
- case '264':
- break;
- case '270':
- break;
- case '300':
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- $pages = $value;
- $pages = preg_replace('/^p\. /', '', $pages);
- $pages = preg_replace('/\.$/', '' , $pages);
- if(preg_match('/p$/', $pages)) {
-
- }
- else {
- $pub['Pages'] = $pages;
- }
- break;
- }
- }
- break;
- case '500':
- $pub['Notes'] = $value;
- break;
- case '504':
- break;
- case '520':
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- $pub['Abstract'] = $value;
- break;
- }
- }
- break;
- case '650':
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- $pub['Keywords'][] = $value;
- break;
- }
- }
- break;
- case '653':
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- $pub['Keywords'][] = $value;
- break;
- }
- }
- break;
- case '700':
- $author = tripal_pub_remote_search_AGL_get_author($xml, $ind1);
- $pub['Author List'][] = $author;
- break;
- case '710':
- $author = array();
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- $author['Collective'] = $value;
- break;
- case 'b':
- $author['Collective'] .= ' ' . $value;
- break;
- }
- }
- $pub['Author List'][] = $author;
- break;
- case '773':
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
- if (preg_match('/Proceedings/i', $value)) {
- $pub['Series Name'] = preg_replace('/\.$/', '', $value);
- $pub['Publication Type'][0] = 'Conference Proceedings';
- }
- else {
- $pub['Journal Name'] = preg_replace('/\.$/', '', $value);
- }
- break;
- case 't':
- if (preg_match('/Proceedings/i', $value)) {
- $pub['Series Name'] = preg_replace('/\.$/', '', $value);
- $pub['Publication Type'][0] = 'Conference Proceedings';
- }
- $pub['Journal Name'] = preg_replace('/\.$/', '', $value);
- break;
- case 'g':
- $matches = array();
- if (preg_match('/^(\d\d\d\d)/', $value, $matches)) {
- $pub['Publication Date'] = $matches[1];
- }
- elseif (preg_match('/(.*?)(\.|\s+)\s*(\d+),\s(\d\d\d\d)/', $value, $matches)) {
- $year = $matches[4];
- $month = $matches[1];
- $day = $matches[3];
- $pub['Publication Date'] = "$year $month $day";
- }
- elseif (preg_match('/\((.*?)(\.|\s+)(\d\d\d\d)\)/', $value, $matches)) {
- $year = $matches[3];
- $month = $matches[1];
- $pub['Publication Date'] = "$year $month";
- }
- elseif (preg_match('/^(.*?) (\d\d\d\d)/', $value, $matches)) {
- $year = $matches[2];
- $month = $matches[1];
- $pub['Publication Date'] = "$year $month";
- }
- if (preg_match('/v\. (.*?)(,|\s+)/', $value, $matches)) {
- $pub['Volume'] = $matches[1];
- }
- if (preg_match('/v\. (.*?)(,|\s+)\((.*?)\)/', $value, $matches)) {
- $pub['Volume'] = $matches[1];
- $pub['Issue'] = $matches[3];
- }
- if (preg_match('/no\. (.*?)(\s|$)/', $value, $matches)) {
- $pub['Issue'] = $matches[1];
- }
- break;
- case 'p':
- $pub['Journal Abbreviation'] = $value;
- break;
- case 'z':
- $pub['ISBN'] = $value;
- break;
- }
- }
- break;
- case '852':
- break;
- case '856':
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'u':
- $pub['URL'] = $value;
- break;
- }
- }
- break;
- default:
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- $unhandled[$tag][] = $codes;
- break;
- }
- }
- }
-
-
- if ($pub['Publication Database'] != 'AGL') {
- }
- if ($pub['Publication Accession'] and $pub['Publication Database']) {
- $pub['Publication Dbxref'] = $pub['Publication Database'] . ":" . $pub['Publication Accession'];
- unset($pub['Publication Accession']);
- unset($pub['Publication Database']);
- }
-
- if (is_array($pub['Author List'])) {
- foreach ($pub['Author List'] as $author) {
- if ($author['valid'] == 'N') {
-
-
- continue;
- }
- if ($author['Collective']) {
- $authors .= $author['Collective'] . ', ';
- }
- else {
- $authors .= $author['Surname'] . ' ' . $author['First Initials'] . ', ';
- }
- }
- $authors = substr($authors, 0, -2);
- $pub['Authors'] = $authors;
- }
- else {
- $pub['Authors'] = $pub['Author List'];
- }
-
- $pub['Citation'] = tripal_pub_create_citation($pub);
- $pub['raw'] = $pub_xml;
- return $pub;
- }
- function tripal_pub_remote_search_AGL_get_subfield($xml) {
- $codes = array();
- while ($xml->read()) {
- $sub_element = $xml->name;
-
- if ($xml->nodeType == XMLReader::END_ELEMENT and $sub_element == 'datafield') {
- return $codes;
- }
-
- if ($xml->nodeType == XMLReader::ELEMENT and $sub_element == 'subfield') {
- $code = $xml->getAttribute('code');
- $xml->read();
- $value = $xml->value;
- $codes[$code] = $value;
- }
- }
- return $codes;
- }
- function tripal_pub_remote_search_AGL_get_author($xml, $ind1) {
- $author = array();
- $codes = tripal_pub_remote_search_AGL_get_subfield($xml);
- foreach ($codes as $code => $value) {
- switch ($code) {
- case 'a':
-
- $value = preg_replace('/,$/', '', $value);
- if ($ind1 == 0) {
- $author['Given Name'] = $names[0];
- }
- if ($ind1 == 1) {
-
- $names = explode(',', $value);
- $author['Surname'] = $names[0];
- $author['Given Name'] = '';
- unset($names[0]);
- foreach($names as $index => $name) {
- $author['Given Name'] .= $name . ' ';
- }
- $first_names = explode(' ', $author['Given Name']);
- $author['First Initials'] = '';
- foreach ($first_names as $index => $name) {
- $author['First Initials'] .= substr($name, 0, 1);
- }
- }
- if ($ind1 == 3) {
- }
- break;
- }
- }
- return $author;
- }
|