function bhl_retrieve_title($id) { global $db; global $ADODB_FETCH_MODE; $title = NULL; $sql = 'SELECT * FROM bhl_title WHERE (TitleID=' . $id . ') LIMIT 1'; $result = $db->Execute($sql); if ($result == false) { die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql); } if ($result->NumRows() == 1) { $title = new stdclass(); $title->id = $result->fields['TitleID']; $title->FullTitle = $result->fields['FullTitle']; $title->ShortTitle = $result->fields['ShortTitle']; $title->PublicationDetails = $result->fields['PublicationDetails']; $title->StartYear = $result->fields['StartYear']; $title->EndYear = $result->fields['EndYear']; $title->LanguageCode = $result->fields['LanguageCode']; $title->TL2Author = $result->fields['TL2Author']; // Identifiers $sql = 'SELECT * FROM bhl_title INNER JOIN bhl_title_identifier USING(TitleID) WHERE (TitleID=' . $id . ')'; $result = $db->Execute($sql); if ($result == false) { die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql); } $title->identifiers = array(); while (!$result->EOF) { $title->identifiers[] = array('namespace' => $result->fields['IdentifierName'], 'identifier' => $result->fields['IdentifierValue']); $result->MoveNext(); } // Institution // Date range $sql = 'SELECT VolumeInfo, Year FROM bhl_item WHERE (TitleID=' . $id . ')'; $result = $db->Execute($sql); if ($result == false) { die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql); } $title->years = array(); while (!$result->EOF) { $info = new stdclass(); $parsed = bhl_date_from_details($result->fields['Year'], $info); if (!$parsed) { $parsed = parse_bhl_date($result->fields['VolumeInfo'], $info); } if ($parsed) { //print_r($info); if (isset($info->start)) { if (!isset($title->years[$info->start])) { $title->years[$info->start] = 0; } $title->years[$info->start]++; if (isset($info->end)) { for ($i = $info->start; $i <= $info->end; $i++) { if (!isset($title->years[$i])) { $title->years[$i] = 0; } $title->years[$i]++; } } } } $result->MoveNext(); } $years = array_keys($title->years); sort($years); $from = $years[0]; $to = $years[count($years) - 1]; for ($i = $from; $i < $to; $i++) { if (!in_array($i, $years)) { $title->years[$i] = 0; } } // sort ksort($title->years); } return $title; }
function sparkline($id) { //$id = 2475959; //$id = 530114; //$id = 4799126; //$id=4799142; //$id=2707985; //$id=31333; //$id=3851985; //$id = 27222; //$id=2478573; $url = 'http://www.biodiversitylibrary.org/services/name/NameService.ashx?op=NameGetDetail&nameBankID=' . $id . '&format=json'; $url = 'http://www.biodiversitylibrary.org/api/httpquery.ashx?op=NameGetDetail&nameBankID=' . $id . '&format=json'; //echo $url; //exit(); $json = get($url); $obj = json_decode($json); //print_r($obj); $years = array(); $decades = array(); foreach ($obj->Result->Titles as $title) { // Try and get date for title $title_info = new stdclass(); if (bhl_date_from_details($title->PublicationDetails, $title_info)) { //print_r($title_info); } foreach ($title->Items as $item) { $info = new stdclass(); if (parse_bhl_date($item->VolumeInfo, $info)) { } if (isset($title_info->start) || isset($info->start)) { $event = new stdclass(); if (isset($info->start)) { $event->start = $info->start; if (isset($info->end)) { $event->end = $info->end; } } else { $event->start = $title_info->start; if (isset($title_info->end)) { $event->end = $title_info->end; } } // Years echo $event->start . ' ' . $event->end . ' '; if (isset($event->end)) { $weight = 1 / ($event->end - $event->start + 1); echo $weight . '<br />'; for ($i = $event->start; $i <= $event->end; $i++) { if (!isset($years[$i])) { $years[$i] = 0; } $years[$i] += $weight; } } else { echo '1<br />'; if (!isset($years[$event->start])) { $years[$event->start] = 0; } $years[$event->start]++; } /* // Decades if (isset($event->end)) { for ($i = $event->start; $i <= $event->end; $i++) { $weight = 1/($event->end - $event->start); $d = floor($i / 10) * 10; if (!isset($decades[$d])) { $decades[$d] = 0; } $decades[$d]++; } } else { $d = floor($event->start/ 10) * 10; if (!isset($decades[$d])) { $decades[$d] = 0; } $decades[$d]++; } */ } else { // Didn't get dates } } } print_r($years); /* $url = 'http://chart.apis.google.com/chart?chs=400x100&cht=ls&chco=0077CC&chm=B,e6f2fa,0,0.0,0.0&chd=t:'; //$chxl = '&chtx=x&chxl=0:'; $max_items = 0; foreach ($years as $k => $v) { $max_items = max($max_items, $v); } $count = 0; for ($i = 1700; $i < 2000; $i++) { if ($count > 0) { $url .= ','; } if (isset($years[$i])) { $url .= round(($years[$i] * 100.0)/$max_items); } else { $url .= '0'; } $count++; } echo $url; */ //print_r($decades); $url = 'http://chart.apis.google.com/chart?chs=400x100&cht=ls&chco=0077CC&chm=B,e6f2fa,0,0.0,0.0&chd=t:'; //$chxl = '&chtx=x&chxl=0:'; // Aggregate into decades $decades = array(); foreach ($years as $k => $v) { $d = floor($k / 10) * 10; if (!isset($decades[$d])) { $decades[$d] = 0; } $decades[$d] += $v; } $max_items = 0; foreach ($decades as $k => $v) { $max_items = max($max_items, $v); } $count = 0; for ($i = 1750; $i < 2010; $i += 10) { if ($count > 0) { $url .= ','; } if (isset($decades[$i])) { $url .= round($decades[$i] * 100.0 / $max_items); } else { $url .= '0'; } $count++; } $url .= '&chxt=x,y&chxl=0:|1750|1800|1850|1900|1950|2000|1:||' . $max_items; for ($i = 1750; $i < 2010; $i += 10) { echo "{$i}|"; if (isset($decades[$i])) { echo $decades[$i]; } else { } echo "<br/>"; } return $url; }
'description':'pages <a href="http://www.biodiversitylibrary.org/page/3332443" target="_new">161</a>, 195', 'image': 'http://images.allposters.com/images/AWI/NR096_b.jpg', 'link': 'http://www.biodiversitylibrary.org/item/22866' }, ] } */ $timeline = new stdclass(); $timeline->dateTimeFormat = "iso8601"; $timeline->events = array(); foreach ($obj->NameResult->Titles as $title) { //echo $title->TitleID . ' ' . $title->PublicationTitle . ' ' . count($title->Items) . "\n"; // Try and get date for title $title_info = new stdclass(); if (bhl_date_from_details($title->PublicationDetails, $title_info)) { //print_r($title_info); } foreach ($title->Items as $item) { //echo ' ' . $item->VolumeInfo . "\n"; $info = new stdclass(); if (parse_bhl_date($item->VolumeInfo, $info)) { //print_r($info); } if (isset($title_info->start) || isset($info->start)) { $event = new stdclass(); if (isset($info->start)) { $event->start = $info->start; if (isset($info->end)) { $event->end = $info->end; }
} } return $matched; } if (0) { $dates = array(); $failed = array(); array_push($dates, '[Monaco]Impr. de Monaco,1889-19<14>'); array_push($dates, 'Lille :Le Bigot,1888-[1895]'); array_push($dates, 'London,Longmans, Green and Co.,1922.'); array_push($dates, 'Copenhagen,[G. & C. Gads Forlag],1910.'); array_push($dates, 'Boston,S.E. Cassino and company,1884-85.'); $ok = 0; foreach ($dates as $str) { $info = new stdclass(); $matched = bhl_date_from_details($str, $info); if ($matched) { $ok++; print_r($info); } else { array_push($failed, $str); } } // report echo "--------------------------\n"; echo count($refs) . ' dates, ' . (count($dates) - $ok) . ' failed' . "\n"; print_r($failed); } if (0) { $dates = array(); $failed = array();
function bhl_name_search($NameBankID) { global $db; $hits = array(); if ($NameBankID == 0) { return $hits; } $sql = 'SELECT DISTINCT bhl_item.TitleID, bhl_item.ItemID, bhl_item.VolumeInfo, bhl_page.PageID, bhl_page.Year as y1, bhl_item.Year as y2, bhl_title.ShortTitle FROM bhl_page_name INNER JOIN bhl_page USING(PageID) INNER JOIN bhl_item USING(ItemID) INNER JOIN bhl_title USING(TitleID) WHERE (NameBankID=' . $NameBankID . ')'; $result = $db->Execute($sql); if ($result == false) { die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql); } while (!$result->EOF) { $ItemID = $result->fields['ItemID']; if (!isset($hits[$ItemID])) { $item = new stdclass(); $item->ItemID = $ItemID; $item->type = 0; $item->pages = array(); $item->TitleID = $result->fields['TitleID']; $item->title = $result->fields['ShortTitle']; $hits[$ItemID] = $item; } $hits[$ItemID]->pages[] = $result->fields['PageID']; $hits[$ItemID]->VolumeInfo = $result->fields['VolumeInfo']; if ($result->fields['y1'] != '') { $hits[$ItemID]->Year = $result->fields['y1']; } elseif ($result->fields['y2'] != '') { $hits[$ItemID]->Year = $result->fields['y2']; } $result->MoveNext(); } // Try and date each item... foreach ($hits as $k => $v) { $hits[$k]->info = new stdclass(); $have_year = false; if (parse_bhl_date($hits[$k]->VolumeInfo, $hits[$k]->info)) { $have_year = isset($hits[$k]->info->start); } if (!$have_year && isset($hits[$k]->Year)) { if (bhl_date_from_details($hits[$k]->Year, $hits[$k]->info)) { $have_year = isset($hits[$k]->info->start); } } } return $hits; }