function insert_biblio(&$entry) { // Insert records entries for this entry and its containers, // and the associated recDetails and usrRecTagLinks entris. global $session_data; global $bib_type_names; if (!$bib_type_names) { load_bib_type_names(); } // resolve the container: we may have to insert records entries for the base entry's container, container-container etc if ($entry->_container && !$entry->_container->getBiblioID()) { if ($entry->_container && $entry->_container->isValid()) { // there's the possibility that the container is invalid, but not required (so don't hook it up) insert_biblio($entry->_container); } // check container->getBiblioID() } $bib = array('rec_RecTypeID' => $entry->getReferenceType(), 'rec_Added' => date('Y-m-d H:i:s'), 'rec_Modified' => date('Y-m-d H:i:s'), 'rec_AddedByImport' => 1, 'rec_AddedByUGrpID' => get_user_id(), 'rec_FlagTemporary' => 1); // always insert entries as temporary, we can perm them later $bib_details = array(); $rec_scratchpad = '[' . str_replace('parser', 'import', $session_data['parser']->parserDescription()) . ', ' . $session_data['import_time'] . ', from file: ' . $session_data['in_filename'] . ', by user: '******']'; $fields = $entry->getFields(); foreach (array_keys($fields) as $i) { if (!$fields[$i]->getValue()) { continue; } if (!$fields[$i]->getType()) { if ($rec_scratchpad) { $rec_scratchpad .= "\n"; } $val = $fields[$i]->getRawValue(); $rec_scratchpad .= is_array($val) ? join("\n", $val) : $val; } else { if ($fields[$i]->getType() === "url") { // set as the rec_URL $bib["rec_URL"] = $fields[$i]->getRawValue(); } else { if ($fields[$i]->getType() === 256 && !@$bib["rec_URL"]) { //256 - web links MAGIC NUMBER // use first web link as the rec_URL $bib["rec_URL"] = $fields[$i]->getRawValue(); } else { $bib_details[] =& $fields[$i]; } } } } if ($rec_scratchpad) { $bib['rec_ScratchPad'] = $rec_scratchpad; } $creatorDT = defined('DT_CREATOR') ? DT_CREATOR : 0; mysql__insert('Records', $bib); $rec_id = mysql_insert_id(); $entry->setBiblioID($rec_id); $bib_detail_insert = ''; foreach (array_keys($bib_details) as $i) { unset($field); $field =& $bib_details[$i]; if ($field->getType() == $creatorDT) { //MAGIC NUMBER - Author/Creator foreach ($field->getValue() as $person_bib_id) { if ($bib_detail_insert) { $bib_detail_insert .= ', '; } $bib_detail_insert .= '(' . $rec_id . ',' . $field->getType() . ', "' . mysql_real_escape_string($person_bib_id) . '", NULL, 1)'; } } else { if ($field->getGeographicValue()) { if ($bib_detail_insert) { $bib_detail_insert .= ', '; } $bib_detail_insert .= '(' . $rec_id . ',' . $field->getType() . ',"' . mysql_real_escape_string($field->getValue()) . '",geomfromtext("' . mysql_real_escape_string($field->getGeographicValue()) . '"),1)'; } else { if ($bib_detail_insert) { $bib_detail_insert .= ', '; } $bib_detail_insert .= '(' . $rec_id . ',' . $field->getType() . ', "' . mysql_real_escape_string($field->getValue()) . '", NULL, 1)'; } } } if ($entry->_container && $entry->_container->isValid()) { global $rectype_to_bdt_id_map; if ($bib_detail_insert) { $bib_detail_insert .= ', '; } $resource_pointer_type = @$rectype_to_bdt_id_map[$entry->_container->getReferenceType()]; if (!$resource_pointer_type) { $resource_pointer_type = 267; } //MAGIC bibliographic reference $bib_detail_insert .= '(' . $rec_id . ',' . $resource_pointer_type . ',' . $entry->_container->getBiblioID() . ', NULL, 1)'; } if ($bib_detail_insert) { $bib_detail_insert = 'insert into recDetails (dtl_RecID, dtl_DetailTypeID, dtl_Value, dtl_Geo, dtl_AddedByImport) values ' . $bib_detail_insert; mysql_query($bib_detail_insert); } $recTitle = $entry->getTitle(); mysql_query('set @suppress_update_trigger := 1'); //, rec_Hash = hhash(rec_ID) - this function has error mysql_query('update Records set rec_Title = "' . mysql_real_escape_string($recTitle) . '" where rec_ID=' . $rec_id); mysql_query('set @suppress_update_trigger := NULL'); }
function getTitle() { // Construct/retrieve the formatted title for this entry, // based on the reference type's title mask. global $heurist_rectypes; if (!$heurist_rectypes) { load_heurist_rectypes(); } if (!$this->getBiblioID()) { return ""; } if ($this->_title) { return $this->_title; } $mask = $heurist_rectypes[$this->_rectype]['rty_TitleMask']; $this->_title = fill_title_mask($mask, $this->getBiblioID(), $this->getReferenceType()); return $this->_title; // fin FIXME the code below never executes, looks old and refactored into TitleMask.php ?remove? global $heurist_rectypes, $bib_type_names; if (!$heurist_rectypes) { load_heurist_rectypes(); } if (!$bib_type_names) { load_bib_type_names(); } $mask = $heurist_rectypes[$this->_rectype]['rty_TitleMask']; if (!$mask) { return ''; } if (!preg_match_all('/\\[\\[|\\]\\]|(\\s*(\\[\\s*([^]]+)\\s*\\]))/s', $mask, $matches)) { return $this->_title = $mask; } // nothing to do -- no substitutions $replacements = array(); for ($i = 0; $i < count($matches[1]); ++$i) { /* * $matches[3][$i] contains the field name as supplied (the string that we look up), * $matches[2][$i] contains the field plus surrounding whitespace and containing brackets * (this is what we replace if there is a substitution) * $matches[1][$i] contains the field plus surrounding whitespace and containing brackets and LEADING WHITESPACE * (this is what we replace with an empty string if there is no substitution value available) */ $value = $this->get_field_value($matches[3][$i]); if ($value) { $replacements[$matches[2][$i]] = $value; } else { $replacements[$matches[1][$i]] = ''; } } $replacements['magic-open-bracket'] = '['; $replacements['magic-close-bracket'] = ']'; $title = array_str_replace(array_keys($replacements), array_values($replacements), $mask); $title = preg_replace('!^[-:;,./\\s]*(.*?)[-:;,/\\s]*$!s', '\\1', $title); $title = preg_replace('!\\([-:;,./\\s]+\\)!s', '', $title); $title = preg_replace('!\\([-:;,./\\s]*(.*?)[-:;,./\\s]*\\)!s', '(\\1)', $title); $title = preg_replace('!\\([-:;,./\\s]*\\)|\\[[-:;,./\\s]*\\]!s', '', $title); $title = preg_replace('!,,+!s', ',', $title); $title = preg_replace('!\\s+,!s', ',', $title); $title = preg_replace('! +!s', ' ', $title); /* Clean up miscellaneous stray punctuation &c. */ return $this->_title = trim($title); }