isbndb.inc.php 2.11 KB
Newer Older
Ayolo's avatar
Ayolo committed
1 2 3
<?php

/**
4
 * @file Base de donnés externe : ISBNDB.COM.
Ayolo's avatar
Ayolo committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 * Base de donnés de livres.
 */

/* Copyright 2006
 * - Julien Etelain <julien CHEZ pmad POINT net>
 *
 * Ce fichier fait partie du site de l'Association des étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
29

Ayolo's avatar
Ayolo committed
30 31 32 33 34 35 36 37 38 39 40 41
require_once("xml.inc.php");

function isbn_get_infos( $isbn )
{

	$cts = file_get_contents("http://isbndb.com/api/books.xml?access_key=28SNOW6C&index1=isbn&value1=$isbn");

	if ( $cts )
	{
		$xml = new u007xml($cts);
		if ( $xml->arrOutput[0]["childrens"][0]["attributes"]["TOTAL_RESULTS"] != 1 )
			return -2;
42

Ayolo's avatar
Ayolo committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
		$res["isbn"]=$xml->arrOutput[0]["childrens"][0]["childrens"][0]["attributes"]["ISBN"];
		$res["title"]=$xml->arrOutput[0]["childrens"][0]["childrens"][0]["childrens"][0]["nodevalue"];
		$res["longtitle"]=$xml->arrOutput[0]["childrens"][0]["childrens"][0]["childrens"][1]["nodevalue"];
		$res["author"]=$xml->arrOutput[0]["childrens"][0]["childrens"][0]["childrens"][2]["nodevalue"];
		$res["editor"]=$xml->arrOutput[0]["childrens"][0]["childrens"][0]["childrens"][3]["nodevalue"];
		return $res;
	}
	return -3;
}

function isbn_get_infos_from_ean13 ( $cbar )
{
	$cap=NULL;
	if ( ereg("978([0-9]{9})([0-9])",$cbar,$cap) )
	{
		$poids = array(10,9,8,7,6,5,4,3,2);
		for($i=0;$i<9;$i++)
			$t += $cap[1]{$i} * $poids[$i];
61 62
		$l = ($t%11);

Ayolo's avatar
Ayolo committed
63 64 65 66 67 68 69 70
		if ( $l == 1 )
			$l = "X";
		elseif ( $l !=0 )
			$l = 11-$l;
		return isbn_get_infos($cap[1].$l);
	}
	return -1;
}
71 72


Ayolo's avatar
Ayolo committed
73
?>