function scanForItems($destroyed) { static $locations; $i = 0; $num = count($destroyed); if (is_null($locations)) { $qry = DBFactory::getDBQuery(); $qry->execute("SELECT itl_id, itl_location FROM kb3_item_locations"); while ($row = $qry->getRow()) { $locations[$row['itl_location']] = $row['itl_id']; } } while ($i < $num) { $container = false; $destroyed[$i] = trim($destroyed[$i]); // TODO: Find a nicer way to do this. Then rewrite the rest of the parser. $destroyed[$i] = preg_replace("/ \\(Copy\\)(.*)\\([\\w ]*\\)/", "\$1(Copy)", $destroyed[$i]); $itemname = substr($destroyed[$i], 0, strlen($destroyed[$i])); if ($destroyed[$i] == "") { $i++; continue; } if ($destroyed[$i] == "Empty.") { $container = false; $i++; continue; } $qtypos = 0; $locpos = 0; $itemname = ""; $quantity = ""; $location = ""; $qtypos = strpos($destroyed[$i], ", Qty: "); $locpos = strrpos($destroyed[$i], "("); if ($container && $locpos != false) { $container = false; } if (strpos($destroyed[$i], "Container")) { $container = true; } if ($qtypos <= 0 && !$locpos) { $itemlen = strlen($destroyed[$i]); if ($container) { $location = "Cargo"; } } if ($qtypos > 0 && !$locpos) { $itemlen = $qtypos; $qtylen = strlen($destroyed[$i]) - $qtypos; if ($container) { $location = "Cargo"; } } if ($locpos > 0 && $qtypos <= 0) { $itemlen = $locpos - 1; $qtylen = 0; $loclen = strlen($destroyed[$i]) - $locpos - 2; if (!$locpos) { $container = false; } } if ($locpos > 0 && $qtypos > 0) { $itemlen = $qtypos; $qtylen = $locpos - $qtypos - 7; $loclen = strlen($destroyed[$i]) - $locpos - 2; if (!$locpos) { $container = false; } } $itemname = substr($destroyed[$i], 0, $itemlen); if ($qtypos) { $quantity = substr($destroyed[$i], $qtypos + 6, $qtylen); } if ($locpos) { $location = substr($destroyed[$i], $locpos + 1, $loclen); } if ($quantity == "") { $quantity = 1; } $item = Item::lookup(trim($itemname)); if (!$item || !$item->getID()) { $this->error('Item not found.', trim($itemname)); } if ($location == 'In Container') { $location = 'Cargo'; } if ($location) { $locid = $locations[$location]; } else { $locid = 0; } $items[] = array('item' => $item, 'quantity' => $quantity, 'location' => $locid); $i++; } return $items; }