Example #1
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;
}
Example #2
0
<?php

/**
 * @file display_doi.php
 *
 * Handle DOIs. If reference with DOI exists in database, redirect to web page displaying
 * reference, otherwise 404.
 *
 */
require_once '../db.php';
$id = 0;
$doi = '';
if (isset($_GET['doi'])) {
    $doi = $_GET['doi'];
}
if ($doi != '') {
    $id = db_retrieve_reference_from_doi($doi);
}
if ($id == 0) {
    header('HTTP/1.1 404 Not Found');
    header('Status: 404 Not Found');
    $_SERVER['REDIRECT_STATUS'] = 404;
    echo 'DOI "' . $doi . '" not found';
} else {
    header('Location: ' . $config['web_root'] . 'reference/' . $id . "\n\n");
    $_SERVER['REDIRECT_STATUS'] = 200;
}