From c8d0eeb8ff54c0b47b5572b1fbb2155708198db7 Mon Sep 17 00:00:00 2001 From: samerton Date: Sun, 10 Jan 2016 14:56:52 +0000 Subject: [PATCH] Query Buycraft API with cURL Change Buycraft API query so it uses cURL instead of file_get_contents. Closes #58 --- addons/Donate/integration/buycraft.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/addons/Donate/integration/buycraft.php b/addons/Donate/integration/buycraft.php index a76ce9580c..49573cc4cf 100644 --- a/addons/Donate/integration/buycraft.php +++ b/addons/Donate/integration/buycraft.php @@ -8,14 +8,25 @@ $API = $queries->getWhere('donation_settings', array("name", "=", "api_key")); $API = $API[0]->value; - -$bc_payments = file_get_contents('https://api.buycraft.net/v4?action=payments&secret=' . $API); -$bc_payments = json_decode($bc_payments, true); -$bc_packages = file_get_contents('https://api.buycraft.net/v4?action=packages&secret=' . $API); +$ch = curl_init(); +curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'); + +// Payments +curl_setopt($ch, CURLOPT_URL, 'https://api.buycraft.net/v4?action=payments&secret=' . $API); +$bc_payments = curl_exec($ch); +$bc_payments = json_decode($bc_payments, true); + +// Packages +curl_setopt($ch, CURLOPT_URL, 'https://api.buycraft.net/v4?action=packages&secret=' . $API); +$bc_packages = curl_exec($ch); $bc_packages = json_decode($bc_packages, true); -$bc_categories = file_get_contents('https://api.buycraft.net/v4?action=categories&secret=' . $API); +// Categories +curl_setopt($ch, CURLOPT_URL, 'https://api.buycraft.net/v4?action=categories&secret=' . $API); +$bc_categories = curl_exec($ch); $bc_categories = json_decode($bc_categories, true); -?> \ No newline at end of file +curl_close($ch); \ No newline at end of file