Index: millennium.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/millennium/millennium.module,v
retrieving revision 1.13.2.33.2.2.2.45
diff -u -r1.13.2.33.2.2.2.45 millennium.module
--- millennium.module	4 Dec 2009 18:04:22 -0000	1.13.2.33.2.2.2.45
+++ millennium.module	4 Dec 2009 23:51:34 -0000
@@ -1491,7 +1491,7 @@
   $log = 'Imported automatically by Millennium module on date '. date('g:i:s a');
 
   // LCC
-  $lcc = trim(millennium_getFieldPlain($marc, "05..."));
+  $lcc = trim(millennium_getFieldPlain($marc, "05"));
   // If no LCC, try to get from items
   /*
   if ($lcc == "" && $recnum) {
@@ -1511,7 +1511,7 @@
 
   // Notes
   $notes="";
-  $tmpfields = millennium_getFields($marc, "50...");
+  $tmpfields = millennium_getFields_fixed($marc, "50");
   if (is_array($tmpfields)) {
     foreach ($tmpfields as $field) {
       if (trim($field["plaintext"])) {
@@ -1524,7 +1524,7 @@
   // Links
   $links = array();
   $item_description = "";
-  $tmpfields = millennium_getFields($marc, "856..");
+  $tmpfields = millennium_getFields_fixed($marc, "856");
   if (is_array($tmpfields)) {
     foreach ($tmpfields as $field) {
       #print_r($field);
@@ -1550,7 +1550,7 @@
   $biblio["type"] = millennium_marcleader_to_mattype($marc);
 
   // Title
-  $data = millennium_getFields($marc, "245..");
+  $data = millennium_getFields_fixed($marc, "245");
   list($subfield_a) = millennium_getSubfields($data[0], "a");
   list($subfield_b) = millennium_getSubfields($data[0], "b");
   list($subfield_p) = millennium_getSubfields($data[0], "p");
@@ -1586,7 +1586,7 @@
 
   foreach ($tags as $fieldname => $tag) {
     $result = "";
-    $found_data = millennium_getFields($marc, "$tag..");
+    $found_data = millennium_getFields($marc, "$tag");
     if (is_array($found_data)) {
       foreach ($found_data as $data) {
         $subfield_re = isset($biblio_subfields[$fieldname]) ? $biblio_subfields[$fieldname] : "a";
@@ -1624,7 +1624,7 @@
   }
 
   // Imprint -> Editor, place, date edited
-  $found_data = millennium_getFields($marc, "260..");
+  $found_data = millennium_getFields_fixed($marc, "260");
   if (is_array($found_data)) {
     $data = $found_data[0];
     list($place_publication) = millennium_getSubfields($data, "a");
@@ -1648,7 +1648,7 @@
   }
 
   // Language
-  $tmpfields = millennium_getFields($marc, "008..");  #get all 008s
+  $tmpfields = millennium_getFields_fixed($marc, "008");  #get all 008s
   if (is_array($tmpfields)) {
     $lang_code = drupal_substr($tmpfields[0]["rawdata"], 35, 3);
     $biblio['lang'] = $lang_code;
@@ -1891,7 +1891,7 @@
     millennium_add_node_taxonomy_terms($nodeobject, variable_get('millennium_marc_vid_year', -1), array($year));
   }
 
-  $tmpfields = millennium_getFields($record, "008..");  #get all 008s
+  $tmpfields = millennium_getFields_fixed($record, "008");  #get all 008s
   if (is_array($tmpfields)) {
 
     // Language
@@ -1949,7 +1949,7 @@
     */
 
   // Get all 65x's
-  $tmpfields = millennium_getFields($record, "65...");
+  $tmpfields = millennium_getFields_fixed($record, "65");
   if (is_array($tmpfields)) {
     foreach ($tmpfields as $field) {
       foreach ($field["subfields"] as $subfield) {
@@ -1991,7 +1991,7 @@
 
   // Series
   #$tmpfields = millennium_getFields($record, "4901.");  // Only "traced" series; tag 490, indicators "1 "
-  $tmpfields = millennium_getFields($record, "830..");  // 830 - Series Added Entry-Uniform Title
+  $tmpfields = millennium_getFields_fixed($record, "830");  // 830 - Series Added Entry-Uniform Title
   if (is_array($tmpfields)) {
     foreach ($tmpfields as $field) {
       list($tmpsub) = millennium_getSubfields($field, "a");
@@ -2066,11 +2066,7 @@
   035    (DLC)13358247
   ...
   */
-  $ok = preg_match('/LEADER (.*)/', $marc_txt, $matches);
-  if (!$ok) {
-    return false;
-  }
-  $record["LEADER"] = $matches[1];
+  $marc["LEADER"] = substr($marc_txt, 7, strpos($marc_txt, "\n")-7);
   $ok = preg_match_all('/([\d ][\d ][\d ]) ([ \d])([ \d]) (.*)/i', $marc_txt, $matches, PREG_SET_ORDER);
   $record_index = 0;
   foreach ($matches as $match) {
@@ -2079,7 +2075,7 @@
 
     if ( $tag . $ind1 . $ind2 == "     ") {
       // Concatenate this data to the previous index
-      $record[$record_index-1]["rawdata"].=(preg_match('/[a-z0-9]$/i', $record[$record_index-1]["rawdata"]) ===false ? "" : " ") . $data;
+      $record[$record_index-1]["rawdata"] .= (preg_match('/[a-z0-9]$/i', $record[$record_index-1]["rawdata"]) === false ? "" : " ") . $data;
     }
     else {
       $record[$record_index]["tags"] = $tag.$ind1.$ind2;
@@ -2143,6 +2139,13 @@
   if (!is_array($record)) {
     return false;
   }
+  // If no regexp in $tag_regexp, then call faster function
+  if (strpos($tag_regexp, '|') === false 
+    && strpos($tag_regexp, '.') === false
+    && strpos($tag_regexp, '[') === false
+    && strpos($tag_regexp, '(') === false) {
+    return millennium_getFields_fixed($record, $tag_regexp);
+  }
   foreach ($record as $element) {
     if (preg_match("/^$tag_regexp/", $element["tags"])) {
       $results[] = $element;
@@ -2152,6 +2155,23 @@
 }
 
 /**
+ * Return array of field contents
+ * @param tag_start is a substring for the starting characters in tags; tags are formatted TTTXY where TTT is a zerofilled 3-digit marc tag, X is subfield 1 (either . or a number), and Y is subfield 2
+ * @param record array containing a parsed marc record
+ */
+function millennium_getFields_fixed($record, $tag_start) {
+  if (!is_array($record)) {
+    return false;
+  }
+  foreach ($record as $element) {
+    if (strpos($tag_start, $element["tags"]) === 0) {
+      $results[] = $element;
+    }
+  }
+  return $results;
+}
+
+/**
  * Returns the plaintext version of a parsed marc record
  * @param record array containing a parsed marc record
  */
@@ -2889,7 +2909,7 @@
  * @param array $marc A parsed marc record
  */
 function millennium_marcleader_to_mattype($marc) {
-  $marc007 = millennium_getFields($marc, "007..");
+  $marc007 = millennium_getFields_fixed($marc, "007");
   $record_type = substr($marc['LEADER'], 6, 1);
   $bibliographic_level = substr($marc['LEADER'], 7, 1);
   $material_category = substr($marc007[0], 0, 1);

