You are here

function _biblio_ris_import_string in Bibliography Module 6.2

Same name and namespace in other branches
  1. 7 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_validate in modules/RIS/biblio_ris.module

File

modules/RIS/biblio_ris.module, line 200

Code

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

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

      // if this is not a blank line
      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 ');
            $message .= l('node/' . $dup, 'node/' . $dup);
            form_set_error('paste_data', $message);
            return;
          }
        }
      }
      else {
        _biblio_ris_parse_line($tag, $data, $node);
      }
    }
  }

  // end while
}