You are here

function _biblio_ris_import_string in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/RIS/biblio_ris.module \_biblio_ris_import_string()
  2. 7.2 modules/RIS/biblio_ris.module \_biblio_ris_import_string()
1 call to _biblio_ris_import_string()
biblio_ris_form_biblio_node_form_submit in modules/RIS/biblio_ris.module

File

modules/RIS/biblio_ris.module, line 230

Code

function _biblio_ris_import_string($string) {
  $tag = '';
  $node = new stdClass();
  $unmapped = array();
  $lines = preg_split('/[\\r\\n]/', $string, -1, PREG_SPLIT_NO_EMPTY);
  foreach ($lines as $line) {
    $line_len = strlen($line);
    if ($line_len > 3) {

      // There could be some unprintables at the beginning of the line so fine the location of the %.
      $start = strpos($line, '  -');
      if ($start !== FALSE) {
        $tag = drupal_substr($line, $start - 2, 2);
        $data = trim(drupal_substr($line, $start + 3));
      }
      else {
        $data = $line;
      }
    }

    // If this is not a blank line.
    if ($line_len > 3 && !empty($tag)) {
      if ($tag == 'ER') {
        if (!empty($node)) {
          $node->biblio_ris_md5 = md5(serialize($node));
          if (empty($node->title)) {
            $node->title = t("Untitled");
          }
          if (!($dup = biblio_ris_check_md5($node->biblio_ris_md5))) {
            return $node;
          }
          else {
            $message = t('The RIS node that you are trying to paste into the form already exists in the database, see !url', array(
              '!url' => l('node/' . $dup, 'node/' . $dup),
            ));
            form_set_error('paste_data_ris', $message);
            return;
          }
        }
      }
      else {
        _biblio_ris_parse_line($tag, $data, $node, $unmapped);
      }
    }
  }

  // end while
  if (!empty($unmapped)) {
    $ignored_tags = array_unique($unmapped);
    $message = t("The following elements were ignored because they do not map to any biblio fields:") . ' ';
    $message .= implode(', ', $ignored_tags);
    if (user_access('administer biblio')) {
      $message .= '. ' . t('Click !url if you wish to check the field mapping', array(
        '!url' => l(t('here'), 'admin/config/content/biblio/iomap/edit/ris'),
      ));
    }
    drupal_set_message($message, 'warning');
  }
}