Esempio n. 1
0
 function Retrieve()
 {
     if ($this->id != 0) {
         $this->object = db_retrieve_reference($this->id);
     }
     return $this->object;
 }
Esempio n. 2
0
function find_reference($journal, $volume, $page, $year = '')
{
    global $db;
    $references = array();
    $hits = array();
    if ($journal == '' || $volume == '' || $page == '') {
        //echo "journal=$journal\n";
        return $hits;
    }
    $series = '';
    $issn = '';
    $oclc = 0;
    if (preg_match('/^(?<journal>.*),\\s+ser\\.\\s+(?<series>.*)$/', $journal, $m)) {
        $journal = $m['journal'];
        $series = $m['series'];
    }
    if (preg_match('/^(?<journal>.*),\\s+(ns|n.s.)$/', $journal, $m)) {
        $journal = $m['journal'];
        //$series = $m['series'];
    }
    if (preg_match('/^(?<page>\\d+),(.*)$/', $page, $m)) {
        $page = $m['page'];
    }
    $issn = issn_from_title($journal);
    if ($issn == '') {
        $oclc = oclc_for_title($journal);
    }
    //echo $issn;
    //echo $oclc;
    $sql = '';
    if ($issn != '') {
        $sql = 'SELECT * FROM rdmp_reference WHERE issn=' . $db->qstr($issn) . ' AND volume=' . $db->qstr($volume) . ' AND ' . $page . ' BETWEEN spage AND epage';
    }
    if ($oclc != '') {
        $sql = 'SELECT * FROM rdmp_reference WHERE oclc=' . $db->qstr($oclc) . ' AND volume=' . $db->qstr($volume) . ' AND ' . $page . ' BETWEEN spage AND epage';
    }
    if ($sql != '') {
        if ($series != '') {
            $sql .= ' AND series=' . $db->qstr($series);
        }
        if ($year != '') {
            $sql .= ' AND year=' . $db->qstr($year);
        }
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        while (!$result->EOF) {
            $references[] = $result->fields['reference_id'];
            $result->MoveNext();
        }
    }
    foreach ($references as $reference_id) {
        $hits[] = reference_to_bibjson(db_retrieve_reference($reference_id));
    }
    return $hits;
}
Esempio n. 3
0
function articles_for_item($ItemID)
{
    global $db;
    $obj = new stdclass();
    $sql = 'SELECT * FROM bhl_title INNER JOIN bhl_item USING(TitleID) WHERE ItemID=' . $ItemID . ' LIMIT 1';
    $result = $db->Execute($sql);
    if ($result == false) {
        die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
    }
    if ($result->NumRows() == 1) {
        $obj->ItemID = $result->fields['ItemID'];
        $obj->FullTitle = $result->fields['FullTitle'];
        $obj->VolumeInfo = $result->fields['VolumeInfo'];
    } else {
    }
    if (isset($obj->ItemID)) {
        $ids = array();
        $sql = 'SELECT DISTINCT rdmp_reference.reference_id, page.SequenceOrder 
		FROM rdmp_reference_page_joiner
		INNER JOIN page USING(PageID) 
		INNER JOIN rdmp_reference USING(PageID)
		WHERE ItemID=' . $obj->ItemID . '
		ORDER BY CAST(page.SequenceOrder AS SIGNED)';
        $result = $db->Execute($sql);
        if ($result == false) {
            die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
        }
        while (!$result->EOF) {
            $ids[] = $result->fields['reference_id'];
            $result->MoveNext();
        }
        $obj->articles = array();
        foreach ($ids as $reference_id) {
            $reference = db_retrieve_reference($reference_id);
            if (isset($reference->oclc)) {
                if ($reference->oclc == 0) {
                    unset($reference->oclc);
                }
            }
            if (isset($reference->sici)) {
                unset($reference->sici);
            }
            if (isset($reference->reference_cluster_id)) {
                unset($reference->reference_cluster_id);
            }
            // get pages
            $pages = bhl_retrieve_reference_pages($reference_id);
            foreach ($pages as $page) {
                $reference->bhl_pages[] = (int) $page->PageID;
            }
            $obj->articles[] = $reference;
        }
    }
    //print_r($obj);
    return $obj;
}
Esempio n. 4
0
$exhibit->items = array();
$id = 0;
if (isset($_GET['id'])) {
    $id = $_GET['id'];
}
if ($id != 0) {
    $refs = db_retrieve_authored_references($id);
    $coauthors = db_retrieve_coauthors($id);
    $c = array();
    foreach ($coauthors->coauthors as $co) {
        $c[] = $co->id;
    }
    $journal_names = array();
    foreach ($refs as $reference_id) {
        global $config;
        $reference = db_retrieve_reference($reference_id);
        $item = new stdclass();
        $item->uri = $config['web_root'] . 'reference/' . $reference_id;
        $item->type = $reference->genre;
        $item->label = $reference->title;
        // Group journals
        if (!isset($journal_names[$reference->issn])) {
            $journal_names[$reference->issn] = $reference->secondary_title;
        }
        $item->journal = $journal_names[$reference->issn];
        $item->citation = reference_authors_to_text_string($reference) . ' (' . $reference->year . ') ' . reference_to_citation_text_string($reference);
        $item->year = $reference->year;
        if ($reference->PageID != 0) {
            $image = bhl_fetch_page_image($reference->PageID);
            $item->imageURL = $image->thumbnail->url;
        } else {
Esempio n. 5
0
 function DisplayHtmlContent()
 {
     global $config;
     echo html_page_header(true, '', 'name');
     echo '<div style="float:right;background-color:rgb(230,242,250);padding:6px">' . "\n";
     if ($this->issn != '') {
         echo '<h2>Identifiers</h2>' . "\n";
         echo '<ul class="guid-list">' . "\n";
         echo '<li class="permalink"><a href="' . $config['web_root'] . 'issn/' . $this->issn . '" title="Permalink">' . $config['web_root'] . 'issn/' . $this->issn . '</a></li>' . "\n";
         echo '<li class="worldcat"><a href="http://www.worldcat.org/issn/' . $this->issn . '" title="ISSN">' . $this->issn . '</a></li>' . "\n";
         echo '<h2>Export</h2>' . "\n";
         echo '<ul class="export-list">' . "\n";
         echo '<li class="xml"><a href="' . $config['web_root'] . 'issn/' . $this->issn . '.xml" title="Endnote XML">Endnote XML</a></li>';
         echo '<li class="ris"><a href="' . $config['web_root'] . 'issn/' . $this->issn . '.ris" title="RIS">Reference manager</a></li>';
         echo '<li class="bibtex"><a href="' . $config['web_root'] . 'issn/' . $this->issn . '.bib" title="BibTex">BibTex</a></li>';
         echo '<li class="text"><a href="' . $config['web_root'] . 'issn/' . $this->issn . '.text" title="text">Text</a></li>';
         echo '</ul>' . "\n";
     }
     if ($this->oclc != '') {
         echo '<h2>Identifiers</h2>' . "\n";
         echo '<ul class="guid-list">' . "\n";
         echo '<li class="permalink"><a href="' . $config['web_root'] . 'oclc/' . $this->oclc . '" title="Permalink">' . $config['web_root'] . 'oclc/' . $this->oclc . '</a></li>' . "\n";
         echo '<li class="worldcat"><a href="http://www.worldcat.org/oclc/' . $this->oclc . '" title="OCLC">' . $this->oclc . '</a></li>' . "\n";
         echo '<h2>Export</h2>' . "\n";
         echo '<ul class="export-list">' . "\n";
         echo '<li class="xml"><a href="' . $config['web_root'] . 'oclc/' . $this->oclc . '.xml" title="Endnote XML">Endnote XML</a></li>';
         echo '<li class="ris"><a href="' . $config['web_root'] . 'oclc/' . $this->oclc . '.ris" title="RIS">Reference manager</a></li>';
         echo '<li class="bibtex"><a href="' . $config['web_root'] . 'oclc/' . $this->oclc . '.bib" title="BibTex">BibTex</a></li>';
         echo '<li class="text"><a href="' . $config['web_root'] . 'oclc/' . $this->oclc . '.text" title="text">Text</a></li>';
         echo '</ul>' . "\n";
     }
     echo '</div>' . "\n";
     echo '<h1>' . $this->GetTitle() . '</h1>';
     // Image
     if (isset($this->issn)) {
         echo '<div>';
         echo '<img src="http://bioguid.info/issn/image.php?issn=' . $this->issn . '" alt="cover" style="border:1px solid rgb(228,228,228);height:100px;" />';
         echo '</div>';
     }
     // Stats
     /*		echo '<div>';
     		echo '<img src="' . sparkline_articles_added_for_issn($this->issn) . '" alt="sparkline" />';
     		echo '</div>';*/
     echo '<a href="http://twitter.com/share" class="twitter-share-button" data-count="vertical" data-via="rdmpage" data-related="biostor_org">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>';
     echo '<h2>Coverage</h2>' . "\n";
     echo '<p>';
     if ($this->issn != '') {
         echo bhl_articles_for_issn($this->issn);
     }
     if ($this->oclc != '') {
         echo bhl_articles_for_oclc($this->oclc);
     }
     echo ' articles in database.</p>' . "\n";
     echo '<h3>Distribution of identified articles over time</h3>' . "\n";
     echo '<div>' . "\n";
     echo '   <img src="' . sparkline_references($this->issn, $this->oclc, 360, 100) . '" alt="sparkline" />' . "\n";
     echo '</div>' . "\n";
     $titles = array();
     if ($this->issn != '') {
         $titles = bhl_titles_for_issn($this->issn);
     }
     if ($this->oclc != '') {
         $titles = bhl_titles_for_oclc($this->oclc);
     }
     if (count($titles) > 0) {
         echo '<h3>Distribution of identified articles across BHL items</h3>' . "\n";
         echo '<div>';
         echo '<div style="display:inline;background-color:rgb(230,242,250);width:20px;height:20px;">&nbsp;&nbsp;&nbsp;&nbsp;</div>';
         echo '&nbsp;Scanned pages&nbsp;';
         echo '<div style="display:inline;background-color:rgb(0,119,204);width:10px;height:10px;">&nbsp;&nbsp;&nbsp;&nbsp;</div>';
         echo '&nbsp;Articles&nbsp;';
         echo '</div>';
         echo '<p></p>';
         $items = array();
         $volumes = array();
         items_from_titles($titles, $items, $volumes);
         $html = '<div style="height:400px;border:1px solid rgb(192,192,192);overflow:auto;">' . "\n";
         $html .= '<table>' . "\n";
         $html .= '<tbody style="font-size:10px;">' . "\n";
         foreach ($volumes as $volume) {
             $item = $items[$volume];
             // How many pages in this item?
             $num_pages = bhl_num_pages_in_item($item->ItemID);
             // Coverage
             $coverage = bhl_item_page_coverage($item->ItemID);
             $row_height = 10;
             // Draw as DIV
             $html .= '<tr>' . "\n";
             $html .= '<td>';
             $html .= '<a href="http://www.biodiversitylibrary.org/item/' . $item->ItemID . '" target="_new">';
             $html .= $item->VolumeInfo;
             $html .= '</a>';
             $html .= '</td>' . "\n";
             $html .= '<td>' . "\n";
             $html .= '<div style="position:relative">' . "\n";
             $html .= '   <div style="background-color:rgb(230,242,250);border-bottom:1px solid rgb(192,192,192);border-right:1px solid rgb(192,192,192);position:absolute;left:0px;top:0px;width:' . $num_pages . 'px;height:' . $row_height . 'px;">' . "\n";
             foreach ($coverage as $c) {
                 $html .= '      <div style="background-color:rgb(0,119,204);position:absolute;left:' . $c->start . 'px;top:0px;width:' . ($c->end - $c->start) . 'px;height:' . $row_height . 'px;">' . "\n";
                 $html .= '      </div>' . "\n";
             }
             $html .= '   </div>' . "\n";
             $html .= '</div>' . "\n";
             $html .= '</td>' . "\n";
             $html .= '</tr>' . "\n";
         }
         $html .= '</tbody>' . "\n";
         $html .= '</table>' . "\n";
         $html .= '</div>' . "\n";
         echo $html;
     }
     $institutions = institutions_from_titles($titles);
     if (count($institutions) != 0) {
         echo '<h3>BHL source(s)</h3>' . "\n";
         echo '<table>' . "\n";
         foreach ($institutions as $k => $v) {
             echo '<tr>' . "\n";
             echo '<td>' . "\n";
             switch ($k) {
                 case 'American Museum of Natural History Library':
                     echo '<img src="' . $config['web_root'] . 'images/institutions/' . 'AMNH_logo_--_blue_rectangle.jpg' . '" width="48" />';
                     break;
                 case 'Harvard University, MCZ, Ernst Mayr Library':
                     echo '<br /><img src="' . $config['web_root'] . 'images/institutions/' . 'Mod_Color_Harvard_Shield_small_bigger.jpg' . '" width="48" />';
                     break;
                 case 'Missouri Botanical Garden':
                     echo '<br /><img src="' . $config['web_root'] . 'images/institutions/' . 'twitter_icon_MBG.jpg' . '" width="48" />';
                     break;
                 case 'New York Botanical Garden':
                     echo '<br /><img src="' . $config['web_root'] . 'images/institutions/' . 'NYBGDOMEHEADERWEB.jpg' . '" />';
                     break;
                 case 'Smithsonian Institution Libraries':
                     echo '<br /><img src="' . $config['web_root'] . 'images/institutions/' . 'SILCatesbyMagnolia.jpg' . '"  width="48" />';
                     break;
                 case 'The Field Museum':
                     echo '<br /><img src="' . $config['web_root'] . 'images/institutions/' . 'field.jpg' . '" width="48" />';
                     break;
                 case 'BHL-Europe':
                     echo '<br /><div style="background-color:green;width:120px;text-align:center"><img src="' . $config['web_root'] . 'images/institutions/' . 'BHL_logo_wg.png' . '" height="48" /></div>';
                     break;
                 case 'Boston Public Library':
                     echo '<br /><img src="' . $config['web_root'] . 'images/institutions/' . 'BPLcards.jpg' . '" width="48" />';
                     break;
                 case 'Harvard University Herbarium':
                     echo '<br /><img src="' . $config['web_root'] . 'images/institutions/' . 'huh_logo_bw_100.png' . '" width="48" />';
                     break;
                 case 'MBLWHOI Library':
                     echo '<br /><img src="' . $config['web_root'] . 'images/institutions/' . 'library_logo2_bigger.jpg' . '" width="48" />';
                     break;
                 case 'Natural History Museum, London':
                     echo '<br /><img src="' . $config['web_root'] . 'images/institutions/' . 'natural_history_museum-01.jpg' . '" width="48" />';
                     break;
                 case 'University of Illinois Urbana Champaign':
                     echo '<br /><img src="' . $config['web_root'] . 'images/institutions/' . 'ilogo_horz_bold.gif' . '" height="48" />';
                     break;
                 default:
                     break;
             }
             echo '</td>' . "\n";
             echo '<td>' . "\n";
             echo $k . '<br />' . $v . ' items';
             echo '</td>' . "\n";
             echo '</tr>' . "\n";
         }
         echo '</table>' . "\n";
     }
     // How does journal relate to BHL Titles and Items?
     $titles = array();
     if ($this->issn != '') {
         $titles = db_retrieve_journal_names_from_issn($this->issn);
     }
     if ($this->oclc != '') {
         $titles = db_retrieve_journal_names_from_oclc($this->oclc);
     }
     if (count($titles) > 1) {
         echo '<h2>Alternative titles</h2>';
         echo '<ul>';
         foreach ($titles as $title) {
             echo '<li>' . $title . '</li>';
         }
         echo '</ul>';
     }
     echo '<h2>Articles</h2>';
     if ($this->issn == '0374-5481') {
         // Special treatment for Ann mag Nat Hist
         echo '<ul>';
         for ($series = 1; $series <= 9; $series++) {
             echo '<li><a href="' . $config['web_root'] . 'issn/' . $this->issn . '#series' . $series . '">Series ' . $series . '</a></li>';
         }
         echo '</ul>';
         for ($series = 1; $series <= 9; $series++) {
             echo '<h3><a name="series' . $series . '"></a>Series ' . $series . '</h3>' . "\n";
             $articles = db_retrieve_articles_from_journal_series($this->issn, $series == 1 ? '' : $series);
             echo '<ul>';
             foreach ($articles as $k => $v) {
                 echo '<li style="display:block;border-top:1px solid #EEE; ">' . $k;
                 echo '<ul>';
                 if (is_array($v)) {
                     foreach ($v as $ref) {
                         echo '<li><a href="' . $config['web_root'] . 'reference/' . $ref->id . '">' . $ref->title . '</a></li>';
                     }
                 }
                 echo '</ul>';
                 echo '</li>';
             }
             echo '</ul>';
         }
     } else {
         $articles = db_retrieve_articles_from_journal($this->issn, $this->oclc);
         //print_r($articles);
         echo '<ul>';
         foreach ($articles as $k => $v) {
             echo '<li style="display:block;border-top:1px solid #EEE; ">' . $k;
             echo '<ul>';
             if (is_array($v)) {
                 foreach ($v as $ref) {
                     if (0) {
                         // fast
                         echo '<li><a href="' . $config['web_root'] . 'reference/' . $ref->id . '">' . $ref->title . '</a></li>';
                     } else {
                         // slower, but useful for debugging
                         $reference = db_retrieve_reference($ref->id);
                         echo '<li style="border-bottom:1px dotted rgb(128,128,128);padding:4px;">';
                         echo '<a href="' . $config['web_root'] . 'reference/' . $ref->id . '">' . $reference->title . '</a><br/>';
                         echo '<span style="color:green;">' . reference_authors_to_text_string($reference);
                         if (isset($reference->year)) {
                             echo ' (' . $reference->year . ')';
                         }
                         echo ' ' . reference_to_citation_text_string($reference) . '</span>';
                         echo ' ' . reference_to_coins($reference);
                         // Thumbail, useful for debugging
                         if (0) {
                             echo '<div>';
                             $pages = bhl_retrieve_reference_pages($ref->id);
                             $image = bhl_fetch_page_image($pages[0]->PageID);
                             echo '<a href="' . $config['web_root'] . 'reference/' . $ref->id . '">';
                             echo '<img style="padding:2px;border:1px solid blue;margin:2px;" id="thumbnail_image_' . $page->PageID . '" src="' . $image->thumbnail->url . '" width="' . $image->thumbnail->width . '" height="' . $image->thumbnail->height . '" alt="thumbnail"/>';
                             echo '</a>';
                             echo '</div>';
                         }
                         echo '</li>';
                     }
                 }
             } else {
                 // Article lacks volume
                 if (isset($v->id)) {
                     $reference = db_retrieve_reference($v->id);
                     echo '<li style="border-bottom:1px dotted rgb(128,128,128);padding:4px;">';
                     echo '<a href="' . $config['web_root'] . 'reference/' . $v->id . '">' . $reference->title . '</a><br/>';
                     echo '<span style="color:green;">' . reference_authors_to_text_string($reference);
                     if (isset($reference->year)) {
                         echo ' (' . $reference->year . ')';
                     }
                     echo ' ' . reference_to_citation_text_string($reference) . '</span>';
                     echo ' ' . reference_to_coins($reference);
                 }
             }
             echo '</ul>';
             echo '</li>';
         }
         echo '</ul>';
     }
 }
Esempio n. 6
0
function db_find_article($article, $allow_non_bhl = false)
{
    global $db;
    $id = 0;
    // Ensure we have enough info
    // Otherwise tools like the Google Bot may cause spurious records to be added
    if (!isset($article->volume) || !isset($article->spage) || !(isset($article->secondary_title) || isset($article->issn))) {
        // handle case where OpenURL has DOI but not enough other details
        if (!isset($article->doi)) {
            return $id;
        }
    }
    // Does a reference exist?
    $sql = '';
    $hits = array();
    // Unset things we don't have
    foreach ($article as $k => $v) {
        if ($v == '') {
            unset($article->{${k}});
        }
    }
    // Check first for identifiers
    if (isset($article->doi) && $article->doi != '') {
        $id = db_retrieve_reference_from_doi($article->doi);
        if ($id != 0) {
            return $id;
        }
    }
    if (isset($article->hdl) && $article->hdl != '') {
        $id = db_retrieve_reference_from_handle($article->hdl);
        if ($id != 0) {
            return $id;
        }
    }
    // Metadata lookup
    if (isset($article->issn) && $article->issn != '' && isset($article->volume) && isset($article->spage)) {
        $sql = 'SELECT * FROM rdmp_reference
			WHERE (issn = ' . $db->Quote($article->issn) . ')
			AND (volume = ' . $db->Quote($article->volume) . ')
			AND (spage = ' . $db->Quote($article->spage) . ')';
    } elseif (isset($article->oclc) && $article->oclc != '' && isset($article->volume) && isset($article->spage)) {
        // OCLC
        $sql = 'SELECT * FROM rdmp_reference
			WHERE (oclc = ' . $db->Quote($article->oclc) . ')
			AND (volume = ' . $db->Quote($article->volume) . ')
			AND (spage = ' . $db->Quote($article->spage) . ')';
    } else {
        // No ISSN so try and match on journal title
        $sql = 'SELECT * FROM rdmp_reference
			WHERE (secondary_title = ' . $db->Quote($article->secondary_title) . ')
			AND (volume = ' . $db->Quote($article->volume) . ')
			AND (spage = ' . $db->Quote($article->spage) . ')';
    }
    if ($allow_non_bhl) {
    } else {
        $sql .= ' AND (PageID <> 0)';
    }
    //echo $sql;
    // 	Do we have this?
    $result = $db->Execute($sql);
    if ($result == false) {
        die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
    }
    while (!$result->EOF) {
        $hits[] = $result->fields['reference_id'];
        $result->MoveNext();
    }
    //print_r($hits);
    //print_r($article);
    $matches = array();
    if (count($hits) > 0) {
        // We have a potential match, but if journal pagination is with respect to issue,
        // not journal, then we may have a problem as different articles may start with the
        // same page number
        foreach ($hits as $hit) {
            $ref = db_retrieve_reference($hit);
            //print_r($ref);
            $matched = 0;
            // Does ending page match?
            if (isset($article->epage) && isset($ref->epage)) {
                if ($article->epage == $ref->epage) {
                    $matched++;
                }
            } else {
                // no epage, accept hit by default
                $matched++;
            }
            // Do issue numbers match?
            if (isset($article->issue) && isset($ref->issue)) {
                if ($article->issue != '' && $article->issue == $ref->issue) {
                    $matched++;
                }
            }
            switch ($matched) {
                case 0:
                    // Unlikely to be same thing, unless mistake in pagination, but allow for missing epage
                    break;
                case 1:
                case 2:
                default:
                    // gotta be this one
                    $matches[] = $hit;
                    break;
            }
        }
    }
    if (count($matches) == 1) {
        $id = $matches[0];
    }
    /*	// Basic triple
    	if (
    		(isset($article->issn) && ($article->issn != ''))
    		&& isset($article->volume)
    		&& isset($article->spage)
    		)
    	{
    		$sql = 'SELECT * FROM rdmp_reference
    			WHERE (issn = ' .  $db->Quote($article->issn) . ')
    			AND (volume = ' .  $db->Quote($article->volume) . ')
    			AND (spage = ' .  $db->Quote($article->spage) . ')
    			LIMIT 1';
    	}
    	else
    	{
    		// No ISSN so try and match on journal title
    		$sql = 'SELECT * FROM rdmp_reference
    			WHERE (secondary_title = ' .  $db->Quote($article->secondary_title) . ')
    			AND (volume = ' .  $db->Quote($article->volume) . ')
    			AND (spage = ' .  $db->Quote($article->spage) . ')
    			LIMIT 1';
    	}
    				
    	$result = $db->Execute($sql);
    	if ($result == false) die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
    
    	
    	if ($result->NumRows() == 1)
    	{
    		$id = $result->fields['reference_id'];
    	}
    */
    return $id;
}
<?php

require_once '../config.inc.php';
require_once '../db.php';
$ids = array(113472);
//foreach ($ids as $reference_id)
for ($reference_id = 113472; $reference_id <= 113472; $reference_id++) {
    echo "-- {$reference_id}\n";
    $article = db_retrieve_reference($reference_id);
    $pages = bhl_retrieve_reference_pages($reference_id);
    //print_r($pages);
    foreach ($pages as $page) {
        $url = 'http://www.biodiversitylibrary.org/api2/httpquery.ashx?op=GetPageNames&pageid=' . $page->PageID . '&apikey=' . '0d4f0303-712e-49e0-92c5-2113a5959159' . '&format=json';
        $json = get($url);
        $obj = json_decode($json);
        //print_r($obj);
        if ($obj->Status == 'ok') {
            foreach ($obj->Result as $name) {
                $sql = "DELETE FROM bhl_page_name WHERE NameConfirmed='" . addslashes($name->NameFound) . "' AND PageID=" . $page->PageID . ";";
                echo $sql . "\n";
                $sql = "INSERT INTO bhl_page_name(NameBankID,PageID,NameConfirmed) VALUES (";
                if ($name->NameBankID != null) {
                    $sql .= $name->NameBankID;
                } else {
                    $sql .= '0';
                }
                $sql .= ',' . $page->PageID;
                $sql .= ",'" . addslashes($name->NameFound) . "'";
                $sql .= ');';
                echo $sql . "\n";
            }
Esempio n. 8
0
/**
 * @brief Handle OpenURL request
 *
 * We may have more than one parameter with same name, so need to access QUERY_STRING, not _GET
 * http://stackoverflow.com/questions/353379/how-to-get-multiple-parameters-with-same-name-from-a-url-in-php
 *
 */
function main()
{
    global $config;
    global $debug;
    global $format;
    $id = 0;
    $callback = '';
    // If no query parameters
    if (count($_GET) == 0) {
        display_form();
        exit(0);
    }
    if (isset($_GET['format'])) {
        switch ($_GET['format']) {
            case 'html':
                $format = 'html';
                break;
            case 'json':
                $format = 'json';
                break;
            default:
                $format = 'html';
                break;
        }
    }
    if (isset($_GET['callback'])) {
        $callback = $_GET['callback'];
    }
    $debug = false;
    if (isset($_GET['debug'])) {
        $debug = true;
    }
    // Handle query and display results.
    $query = explode('&', html_entity_decode($_SERVER['QUERY_STRING']));
    $params = array();
    foreach ($query as $param) {
        list($key, $value) = explode('=', $param);
        $key = preg_replace('/^\\?/', '', urldecode($key));
        $params[$key][] = trim(urldecode($value));
    }
    if ($debug) {
        echo '<h1>Params</h1>';
        echo '<pre>';
        print_r($params);
        echo '</pre>';
    }
    // This is what we got from user
    $referent = new stdclass();
    parse_openurl($params, $referent);
    // Flesh it out
    // If we are looking for an article we need an ISSN, or at least an OCLC
    // Ask whether have this in our database (assumes we have ISSN)
    if (!isset($referent->issn)) {
        // Try and get ISSN from bioGUID
        $issn = issn_from_title($referent->secondary_title);
        if ($issn != '') {
            $referent->issn = $issn;
        } else {
            // No luck with ISSN, look for OCLC
            if (!isset($referent->oclc)) {
                $oclc = oclc_for_title($referent->secondary_title);
                if ($oclc != 0) {
                    $referent->oclc = $oclc;
                }
            }
        }
    }
    if ($debug) {
        echo '<h1>Referent</h1>';
        echo '<pre>';
        print_r($referent);
        echo '</pre>';
    }
    // Handle identifiers
    if (isset($referent->url)) {
        // BHL URL, for example if we have already mapped article to BHL
        // in Zotero,
        if (preg_match('/^http:\\/\\/(www\\.)?biodiversitylibrary.org\\/page\\/(?<pageid>[0-9]+)/', $referent->url, $matches)) {
            //print_r($matches);
            $PageID = $matches['pageid'];
            $references = bhl_reference_from_pageid($PageID);
            //print_r($references);
            if (count($references) == 0) {
                // We don't have an article for this PageID
                $search_hit = bhl_score_page($PageID, $referent->title);
                // Store
                $id = db_store_article($referent, $PageID);
            } else {
                // Have a reference with this PageID already
                // Will need to handle case where > 1 article on same page, e.g.
                // http://www.biodiversitylibrary.org/page/3336598
                $id = $references[0];
            }
            // Did we get a hit?
            if ($id != 0) {
                // We have this reference in our database
                switch ($format) {
                    case 'json':
                        // Display object
                        $reference = db_retrieve_reference($id);
                        header("Content-type: text/plain; charset=utf-8\n\n");
                        if ($callback != '') {
                            echo $callback . '(';
                        }
                        echo json_format(json_encode($reference));
                        if ($callback != '') {
                            echo ')';
                        }
                        break;
                    case 'html':
                    default:
                        // Redirect to reference display
                        header('Location: ' . $config['web_root'] . 'reference/' . $id . "\n\n");
                        break;
                }
                exit;
            }
        }
    }
    // OK, we're not forcing a match to BHL, so do we have this article?
    $id = db_find_article($referent);
    //echo "<b>id=$id</b><br/>";
    if ($id != 0) {
        // We have this reference in our database
        switch ($format) {
            case 'json':
                // Display object
                $reference = db_retrieve_reference($id);
                header("Content-type: text/plain; charset=utf-8\n\n");
                if ($callback != '') {
                    echo $callback . '(';
                }
                echo json_format(json_encode($reference));
                if ($callback != '') {
                    echo ')';
                }
                break;
            case 'html':
            default:
                // Twitter as log
                if ($config['twitter']) {
                    $tweet_this = false;
                    $tweet_this = isset($_GET['rfr_id']);
                    if ($tweet_this) {
                        $url = $config['web_root'] . 'reference/' . $id . ' ';
                        //  . '#openurl'; // url + hashtag
                        $url = $id;
                        $url_len = strlen($url);
                        $status = '';
                        //$text = $_GET['rfr_id'];
                        $text = '#openurl ' . $_SERVER["HTTP_REFERER"];
                        //$text .= ' @rdmpage';
                        if (isset($article->title)) {
                        }
                        $status = $text;
                        $status_len = strlen($status);
                        $extra = 140 - $status_len - $url_len - 1;
                        if ($extra < 0) {
                            $status_len += $extra;
                            $status_len -= 1;
                            $status = substr($status, 0, $status_len);
                            $status .= '…';
                        }
                        $status .= ' ' . $url;
                        tweet($status);
                    }
                }
                // Redirect to reference display
                header('Location: reference/' . $id . "\n\n");
                break;
        }
        exit;
    }
    // OK, not found, so let's go look for it...
    // Search BHL
    $atitle = '';
    if (isset($referent->title)) {
        $atitle = $referent->title;
    }
    $search_hits = bhl_find_article($atitle, $referent->secondary_title, $referent->volume, isset($referent->spage) ? $referent->spage : $referent->pages, isset($referent->series) ? $referent->series : '', isset($referent->date) ? $referent->date : '', isset($referent->issn) ? $referent->issn : '');
    if (count($search_hits) == 0) {
        // try alternative way of searching using article title
        $search_hits = bhl_find_article_from_article_title($referent->title, $referent->secondary_title, $referent->volume, isset($referent->spage) ? $referent->spage : $referent->pages, isset($referent->series) ? $referent->series : '', isset($referent->issn) ? $referent->issn : '');
    }
    // At this point if we haven't found it in BHL we could go elsewhere, e.g. bioGUID,
    // in which case we'd need to take this into account when displaying HTML and JSON
    if ($debug) {
        echo '<h3>Search hits</h3>';
        echo '<pre>';
        print_r($search_hits);
        echo '</pre>';
    }
    if (1) {
        // Check whether we already have an article that starts on this
        foreach ($search_hits as $hit) {
            $references = bhl_reference_from_pageid($hit->PageID);
            //print_r($references);
            if (count($references) != 0) {
                // We have this reference in our database
                switch ($format) {
                    case 'json':
                        // Display object
                        $reference = db_retrieve_reference($references[0]);
                        header("Content-type: text/plain; charset=utf-8\n\n");
                        if ($callback != '') {
                            echo $callback . '(';
                        }
                        echo json_format(json_encode($reference));
                        if ($callback != '') {
                            echo ')';
                        }
                        break;
                    case 'html':
                    default:
                        // Redirect to reference display
                        header('Location: reference/' . $references[0] . "\n\n");
                        break;
                }
                exit;
            }
        }
    }
    // Output search results in various formats...
    switch ($format) {
        case 'json':
            display_bhl_result_json($referent, $search_hits, $callback);
            break;
        case 'html':
        default:
            display_bhl_result_html($referent, $search_hits);
            break;
    }
}
Esempio n. 9
0
 function DisplayHtmlContent()
 {
     global $config;
     echo html_page_header(true, '', 'name');
     echo '<h1>' . $this->GetTitle() . '</h1>';
     if (count($this->object->specimens) == 0) {
         echo '<p>No specimens with this code</p>';
     } else {
         // What articles have this specimen?
         echo '<h2>References in BioStor with this specimen</h2>';
         $refs = specimens_references_with_code($this->code);
         //print_r($refs);
         foreach ($refs as $occurrenceID => $ref_list) {
             if ($occurrenceID != 0) {
                 echo '<p>GBIF occurrence <a class="gbif" href="http://data.gbif.org/occurrences/' . $occurrenceID . '/" target="_new">' . $occurrenceID . '</a>';
                 $datasetID = specimens_dataset_from_occurrence($occurrenceID);
                 $dataset = specimens_dataset($datasetID);
                 echo ' from dataset <a href="gbif_dataset.php?datasetID=' . $dataset->datasetID . '">' . $dataset->dataResourceName . ' (' . $dataset->providerName . ')' . '</a>';
                 echo '</p>';
                 $occurrence = specimens_from_occurrenceID($occurrenceID);
                 echo '<p>' . $occurrence->scientificName . ' (' . join(':', $occurrence->lineage) . ')' . '</p>';
             } else {
                 echo '<p>(specimen not known in GBIF)</p>';
             }
             echo '<table cellspacing="0" cellpadding="2" width="100%">';
             foreach ($ref_list as $reference_id) {
                 $reference = db_retrieve_reference($reference_id);
                 echo '<tr';
                 if (in_array($reference_id, $act_refs)) {
                     echo ' style="background-color:#D8F3C9;"';
                 }
                 echo '>';
                 if ($reference->PageID != 0) {
                     $image = bhl_fetch_page_image($reference->PageID);
                     $imageURL = $image->thumbnail->url;
                 } else {
                     // if it's an article we could use journal image
                     $imageURL = 'http://bioguid.info/issn/image.php?issn=' . $reference->issn;
                 }
                 echo '<td valign="top"><img style="border:1px solid rgb(192,192,192);" src="' . $imageURL . '" width="40" />';
                 echo '</td>';
                 echo '<td valign="top">';
                 echo '<a href="' . $config['web_root'] . 'reference/' . $reference_id . '">' . $reference->title . '</a><br/>';
                 echo '<span>' . reference_authors_to_text_string($reference);
                 if (isset($reference->year)) {
                     echo ' (' . $reference->year . ')';
                 }
                 echo ' ' . reference_to_citation_text_string($reference) . '</span>';
                 echo ' ' . reference_to_coins($reference);
                 if (0) {
                     echo '<div>';
                     echo bhl_pages_with_name_thumbnails($reference_id, $this->object->NameBankID);
                     echo '</div>';
                 }
                 echo '</td>';
                 echo '</tr>';
             }
             echo '</table>';
         }
     }
 }
Esempio n. 10
0
// fetch names if we haven't got them...
require_once dirname(__FILE__) . '/db.php';
require_once dirname(__FILE__) . '/lib.php';
require_once dirname(__FILE__) . '/bhl_names.php';
$ids = array(126311);
$ids = array(105416, 105402, 125890, 59343, 107177);
$ids = array(110878);
$ids = array(99906, 108144, 100200, 100656, 107955, 107963, 107976, 83078, 66142, 87244, 87255, 105412, 87185, 87103, 65960, 66503, 87120, 105406, 86522, 105403, 126315, 107177, 95592, 97207, 105415, 87635, 97899, 65958, 48993, 59343, 14562, 125890, 103534, 109586, 891, 97484, 889, 105414, 1312, 104732, 84533, 113895, 105402, 85290, 114597, 126311, 102399);
$ids = array(54668, 14790, 54677, 99677, 127560, 60044, 127575, 127574, 99512, 107049, 106157, 105730, 125900, 127561, 105962, 61688, 58301, 105714, 58630, 14789, 98326, 14787, 106156, 97776, 99962, 98307, 14781, 97871, 4435, 844, 97482, 832, 97490, 101826, 106132);
$ids = array(127609);
$ids = array(120824);
$ids = array(116847);
$ids = array(127997);
foreach ($ids as $reference_id) {
    echo $reference_id . "\n";
    if (db_retrieve_reference($reference_id) != null) {
        $nm = bhl_names_in_reference_by_page($reference_id);
        if (isset($nm->names) && count($nm->names) == 0) {
            // fetch names
            $pages = bhl_retrieve_reference_pages($reference_id);
            $page_ids = array();
            foreach ($pages as $p) {
                echo $p->PageID;
                $parameters = array('op' => 'GetPageMetadata', 'pageid' => $p->PageID, 'ocr' => 'f', 'names' => 't', 'apikey' => '0d4f0303-712e-49e0-92c5-2113a5959159', 'format' => 'json');
                $url = 'http://www.biodiversitylibrary.org/api2/httpquery.ashx?' . http_build_query($parameters);
                $json = get($url);
                //echo $json;
                if ($json != '') {
                    $response = json_decode($json);
                    foreach ($response->Result->Names as $Name) {
                        echo '.';
Esempio n. 11
0
 }
 /*
 echo '<pre>';
 
 print_r($page2biostor);
 echo '</pre>';
 */
 $count = 0;
 foreach ($r as $row) {
     if (is_array($row)) {
         if (isset($row['Url'])) {
             $PageID = str_replace('http://www.biodiversitylibrary.org/page/', '', $row['Url']);
             //echo $PageID . '<br/>';
             if (isset($page2biostor[$PageID])) {
                 if (!isset($hits[$page2biostor[$PageID]])) {
                     $reference = db_retrieve_reference($page2biostor[$PageID]);
                     $hit = reference_to_bibjson($reference);
                     $hit->PageID = $reference->PageID;
                     $hit->biostor = $page2biostor[$PageID];
                     $hits[$page2biostor[$PageID]] = $hit;
                 }
             } else {
                 /*			$ItemID = bhl_retrieve_ItemID_from_PageID($PageID);
                 					
                 					if ($ItemID == 0)
                 					{
                 						$id = $count;
                 						$count++;
                 					}
                 					else
                 					{
Esempio n. 12
0
 function DisplayJson()
 {
     $act_refs = array();
     $refs = bhl_references_with_namestring($this->GetTitle());
     // Merge with references from nomenclators
     $refs = array_merge($refs, $act_refs);
     $refs = array_unique($refs);
     $obj = new stdclass();
     $obj->references = array();
     foreach ($refs as $reference_id) {
         $obj->references[] = db_retrieve_reference($reference_id);
     }
     header("Content-type: text/plain; charset=utf-8\n\n");
     if ($this->callback != '') {
         echo $this->callback . '(';
     }
     echo json_format(json_encode($obj));
     if ($this->callback != '') {
         echo ')';
     }
 }
Esempio n. 13
0
 function Retrieve()
 {
     if ($this->id != 0) {
         $this->object = db_retrieve_reference($this->id);
         $this->in_bhl = db_reference_from_bhl($this->id);
     }
     // Geocoding?
     if ($this->in_bhl) {
         if (!bhl_has_been_geocoded($this->id)) {
             bhl_geocode_reference($this->id);
         }
         $this->localities = bhl_localities_for_reference($this->id);
     }
     // Specimens?
     if ($this->in_bhl) {
         if (!specimens_has_been_parsed($this->id)) {
             specimens_from_reference($this->id);
         }
         $this->specimens = specimens_from_db($this->id);
     }
     return $this->object;
 }
Esempio n. 14
0
/**
 * @brief Create PDF for a reference
 *
 * We create a simple cover page for the PDF. This page contains basic bibliographic metadata
 * for the PDF, in order for Mendeley to process the PDF correctly. In response to my discovery
 * that Mendeley doesn't accept all XMP (Ticket#2010040110000015) support@mendeley.com replied that
 * they have some heuristic tests to see if the metadata is valid, such as whether the information 
 * about the title and authors occurs on the first of the PDF.
 *
 *
 * @param reference_id Reference id
 * @param pdf_filename Full path of PDF file to create
 *
 */
function pdf_create($reference_id, $pdf_filename)
{
    global $config;
    // Get reference
    $reference = db_retrieve_reference($reference_id);
    // Get tags
    $tags = pdf_tags($reference->reference_id, 10);
    // Paper size
    // A4 = 210 x 297
    $paper_width = 210;
    // mm
    $paper_height = 297;
    // mm
    $margin = 10;
    //----------------------------------------------------------------------------------------------
    // PDF
    $pdf = new FPDF('P', 'mm', 'A4');
    //$pdf = PDF_Rotate('P', 'mm', 'A4');
    //----------------------------------------------------------------------------------------------
    // Basic metadata (e.g., that displayed by Mac OS X Preview)
    $pdf->SetTitle($reference->title, true);
    // true means use UTF-8
    $pdf->SetAuthor(reference_authors_to_text_string($reference), true);
    // true means use UTF-8
    if (count($tags) > 0) {
        $pdf->SetKeywords(join(", ", $tags), true);
    }
    //----------------------------------------------------------------------------------------------
    // Cover page (partly to ensure Mendeley accepts XMP metadata)
    $pdf->AddPage();
    // Title
    $pdf->SetFont('Arial', '', 24);
    $pdf->SetXY($margin, $margin);
    $pdf->Write(10, utf8_decode($reference->title));
    // Authors
    $y = $pdf->GetY();
    $pdf->SetXY($margin, $y + 16);
    $pdf->SetFont('Arial', 'B', 16);
    $pdf->Write(6, utf8_decode(reference_authors_to_text_string($reference)));
    // Citation
    $y = $pdf->GetY();
    $pdf->SetXY($margin, $y + 10);
    $pdf->SetFont('Arial', 'I', 12);
    $pdf->Write(6, utf8_decode($reference->secondary_title));
    $pdf->SetFont('Arial', '', 12);
    $pdf->Write(6, ' ' . $reference->volume);
    if (isset($reference->issue)) {
        $pdf->Write(6, '(' . $reference->issue . ')');
    }
    $pdf->Write(6, ':' . $reference->spage);
    if (isset($reference->epage)) {
        $pdf->Write(6, '-' . $reference->epage);
    }
    $pdf->Write(6, ' (' . $reference->year . ')');
    // URL
    $url = $config['web_root'] . 'reference/' . $reference->reference_id;
    $pdf->Write(6, ' ');
    $pdf->SetTextColor(0, 0, 255);
    $pdf->SetFont('', 'U');
    $pdf->Write(6, $url, $url);
    $pdf->SetFont('', '');
    $pdf->SetTextColor(0, 0, 0);
    //----------------------------------------------------------------------------------------------
    // If we add taxon names as keywords
    if (count($tags) > 0) {
        $keywords = "Keywords: " . join("; ", $tags);
        $y = $pdf->GetY();
        $pdf->SetXY($margin, $y + 10);
        $pdf->Write(6, $keywords);
    }
    //----------------------------------------------------------------------------------------------
    // Footer giving credit to BHL
    $y = $paper_height;
    $y -= $margin;
    $y -= 40;
    $pdf->Image($config['web_dir'] . '/images/cc/cc.png', 10, $y, 10);
    $pdf->Image($config['web_dir'] . '/images/cc/by.png', 20, $y, 10);
    $pdf->Image($config['web_dir'] . '/images/cc/nc.png', 30, $y, 10);
    $pdf->SetXY(10, $y + 10);
    $pdf->SetFont('Arial', '', 10);
    $pdf->SetTextColor(0, 0, 0);
    $pdf->Write(6, 'Page images from the Biodiversity Heritage Library, ');
    //Then put a blue underlined link
    $pdf->SetTextColor(0, 0, 255);
    $pdf->SetFont('', 'U');
    $pdf->Write(6, 'http://www.biodiversitylibrary.org/', 'http://www.biodiversitylibrary.org/');
    $pdf->SetFont('', '');
    $pdf->SetTextColor(0, 0, 0);
    $pdf->Write(6, ', made available under a Creative Commons Attribution-Noncommercial License ');
    $pdf->SetTextColor(0, 0, 255);
    $pdf->SetFont('', 'U');
    $pdf->Write(6, 'http://creativecommons.org/licenses/by-nc/2.5/', 'http://creativecommons.org/licenses/by-nc/2.5/');
    //----------------------------------------------------------------------------------------------
    // Add BHL page scans
    $pages = bhl_retrieve_reference_pages($reference_id);
    foreach ($pages as $page) {
        $image = bhl_fetch_page_image($page->PageID);
        $page_width = $paper_width;
        $page_height = $paper_height;
        $page_width -= 2 * $margin;
        $page_height -= 2 * $margin;
        // Fit to page
        $img_height = $image->height;
        $img_width = $image->width;
        $w_scale = $page_width / $img_width;
        $h_scale = $page_height / $img_height;
        $scale = min($w_scale, $h_scale);
        $img_height *= $scale;
        $img_width *= $scale;
        $pdf->AddPage();
        $x_offset = ($paper_width - $img_width) / 2.0;
        $y_offset = ($paper_height - $img_height) / 2.0;
        $pdf->Image($image->file_name, $x_offset, $y_offset, $img_width);
    }
    $pdf->Output($pdf_filename, 'F');
    pdf_add_xmp($reference, $pdf_filename, $tags);
}