Esempio n. 1
0
/**
 *	Query EVE Central's XML feed.
 */
function ask_eve_central($item_id)
{
    file_put_contents(KB_CACHEDIR . '/evecentral/activity.log', "Handling from live.\n", FILE_APPEND);
    $query = DBFactory::getDBQuery();
    if (function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://api.eve-central.com/api/marketstat?regionlimit=10000002&typeid=" . $item_id . "");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $content = curl_exec($ch);
        curl_close($ch);
    } else {
        $file = fopen("http://api.eve-central.com/api/marketstat?regionlimit=10000002&typeid=" . $item_id . "", "r");
        if (!$file) {
            return -99;
        }
        $content = stream_get_contents($file);
        fclose($file);
    }
    if (strpos($content, '</evec_api>') == false) {
        return -99;
    } else {
        $parse = new XMLParser();
        $parse->preparseXML();
        $parse->parseXML($content);
        $values = $parse->get_data();
        if (0 == $values['WEIGHTED']) {
            return -99;
        }
        $weighted_average = $values['WEIGHTED'];
    }
    file_put_contents(KB_CACHEDIR . '/evecentral/activity.log', "{$content}\n", FILE_APPEND);
    $query->execute("REPLACE INTO kb3_eve_central (item_id, item_price) VALUES ({$item_id}, '{$weighted_average}')");
    return $weighted_average;
}