<?php
########################################################################
#
# Project: Grocery List
# URL: http://sourceforge.net/projects/grocery-list/
# E-mail: hide@address.com
#
# Copyright: (C) 2010, Neil McNab
# License: GNU General Public License Version 3
#
# 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, version 3 of the License.
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Filename: $URL: https://grocery-list.svn.sourceforge.net/svnroot/grocery-list/releases/1.0/include/upcdata.php $
# Last Updated: $Date: 2010-03-07 15:23:54 -0800 (Sun, 07 Mar 2010) $
# Author(s): Neil McNab
#
# Description:
# Interface to upcdata.info web service.
#
########################################################################
if (!defined('UPCDATAKEY')) {
// set your key here
//define('UPCDATAKEY', '');
}
function upcdata_lookup($upc) {
$result = array();
if (!defined('UPCDATAKEY')) {
return FALSE;
}
$url = sprintf("http://upcdata.info/?code=%013d&Key=%s&ProductOnly=1&action=get", $upc, UPCDATAKEY);
$xml = simplexml_load_string(upcdata_http_get($url));
$result['upc'] = strval($xml->EAN13);
$result['description'] = strval($xml->Product->Name);
$result['size'] = strval($xml->Product->Description);
return $result;
}
function upcdata_http_get($request) {
$file = FALSE;
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$file = curl_exec($ch);
if ( curl_getinfo($ch,CURLINFO_HTTP_CODE) !== 200 ) {
return FALSE;
//print 'Bad Data File '. RPC_URL . " " . curl_getinfo($ch,CURLINFO_HTTP_CODE); # . " " . $file);
}
} else {
// PHP built-in method, not secure, using as failback only
$file = file_get_contents($request);
}
return $file;
}
?>