$specimens = specimens_from_db($reference_id); if (count($specimens) == 0) { $specimens = specimens_from_reference($reference_id); } echo "Specimens:\n"; print_r($specimens); $nm = bhl_names_in_reference_by_page($reference_id); $nm->names; // Get majority rule taxon (what paper is about) $tags = array(); foreach ($nm->names as $name) { $tags[] = $name->namestring; } $paths = get_paths($tags); $majority_rule = majority_rule_path($paths); $expanded = expand_path($majority_rule); print_r($expanded); // OK, now match... foreach ($specimens as $specimen) { //$go = false; $go = true; $code = $specimen->code; if (preg_match('/^AMNH /', $code)) { if (in_array('Amphibia', $expanded)) { $code = str_replace('AMNH ', 'AMNH A-', $code); } if (in_array('Reptilia', $expanded)) { $code = str_replace('AMNH ', 'AMNH R-', $code); } if (in_array('Aves', $expanded)) { $code = str_replace('AMNH ', 'AMNH Skin-', $code);
function DisplayJson() { $j = reference_to_mendeley($this->object); // Array of BHL pages $j->bhl_pages = array(); $j->thumbnails = array(); $count = 0; $pages = bhl_retrieve_reference_pages($this->id); foreach ($pages as $page) { $j->bhl_pages[] = (int) $page->PageID; // Store thumbnails of pages (just page 1 for now) if ($count == 0) { $image = bhl_fetch_page_image($page->PageID); $file = @fopen($image->thumbnail->file_name, "r") or die("could't open file --\"{$image->thumbnail}->file_name\""); $img = fread($file, filesize($image->thumbnail->file_name)); fclose($file); // to do: test for MIME type, don't assume it $base64 = chunk_split(base64_encode($img)); $thumbnail = 'data:image/gif;base64,' . $base64; $j->thumbnails[] = $thumbnail; } $count++; } // don't do names.. if (1) { // Names $nm = bhl_names_in_reference_by_page($this->id); $j->names = $nm->names; // Get majority rule taxon (what paper is about) $tags = array(); foreach ($nm->names as $name) { $tags[] = $name->namestring; } $paths = get_paths($tags); $majority_rule = majority_rule_path($paths); $j->expanded = expand_path($majority_rule); /* // Nomenclatural acts $acts = acts_in_publication($this->id); if (count($acts) > 0) { $count = count($nm->names); foreach ($acts as $tn) { $name = $tn->nameComplete; // Zoobank crap $name = preg_replace('/ subsp\. /', ' ', $name); $name = preg_replace('/ var\. /', ' ', $name); // BHL might have missed this name if (!isset($nm->found[$name])) { $n = new stdclass; $n->namestring = $name; $n->identifiers = new stdclass; $n->pages = array(); $j->names[] = $n; $nm->found[$name] = $count++; } $index = $nm->found[$name]; // ION if (preg_match('/urn:lsid:organismnames.com:name:(?<id>\d+)/', $tn->global_id, $m)) { $j->names[$index]->identifiers->ion = (Integer)$m['id']; } // Zoobank if (preg_match('/urn:lsid:zoobank.org:act:(?<id>.*)/', $tn->global_id, $m)) { $j->names[$index]->identifiers->zoobank = $m['id']; } // IPNI if (preg_match('/urn:lsid:ipni.org:names:(?<id>.*)/', $tn->global_id, $m)) { $j->names[$index]->identifiers->ipni = $m['id']; } // Index Fungorum if (preg_match('/urn:lsid:indexfungorum.org:names(?<id>.*)/', $tn->global_id, $m)) { $j->names[$index]->identifiers->indexfungorum = (Integer)$m['id']; } } //ksort($j->names); } */ } // Output localities in text as array of features in GeoJSON format /* $j->featurecollection = new stdclass; $j->featurecollection->type = "FeatureCollection"; $j->featurecollection->features = array(); foreach ($this->localities as $loc) { $feature = new stdclass; $feature->type = "Feature"; $feature->geometry = new stdclass; $feature->geometry->type = "Point"; $feature->geometry->coordinates = array(); $feature->geometry->coordinates[] = (Double)$loc->longitude; $feature->geometry->coordinates[] = (Double)$loc->latitude; $j->featurecollection->features[] = $feature; } */ if (count($this->localities) > 0) { $j->geometry = new stdclass(); $j->geometry->type = "MultiPoint"; $j->geometry->coordinates = array(); foreach ($this->localities as $loc) { $j->geometry->coordinates[] = array((double) $loc->longitude, (double) $loc->latitude); } } // ? header("Content-type: text/plain; charset=utf-8\n\n"); if ($this->callback != '') { echo $this->callback . '('; } echo json_format(json_encode($j)); if ($this->callback != '') { echo ')'; } }