eileensiow Posted March 10, 2010 Share Posted March 10, 2010 I've been searching for alternatives to allow_url for my currency real live update cause my host disabled the function. I found the following script but not sure how to apply it in prestashop. Some care to assist me? class XMLWrapper { public function loadXML($url) { if (ini_get('allow_url_fopen') == true) { return $this->load_fopen($url); } else if (function_exists('curl_init')) { return $this->load_curl($url); } else { // Enable 'allow_url_fopen' or install cURL. throw new Exception("Can't load data."); } } private function load_fopen($url) { return simplexml_load_file($url); } private function load_curl($url) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); curl_close($curl); return simplexml_load_string($result); }} Link to comment Share on other sites More sharing options...
twiggy182 Posted March 11, 2011 Share Posted March 11, 2011 Hi,here is how to use it (in classes/currency.php): static public function refreshCurrencies() { $curl = curl_init('http://www.prestashop.com/xml/currencies.xml'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); curl_close($curl); /*return simplexml_load_string($result); if (!$feed = @simplexml_load_file('http://www.prestashop.com/xml/currencies.xml')) */ if (!$feed = @simplexml_load_string($result)) return Tools::displayError('Cannot parse feed!'); With that change, you don't have to enable "allow_url_fopen" in your php.ini (which is a big security risk). However, curl need to be installed:)With the code you provided, PS developper could test if curl is installed and use that code instead of using simplexml_load_file. I may submit a patch if I get some time:)I hope it will help some persons.Regards Link to comment Share on other sites More sharing options...
twiggy182 Posted March 12, 2011 Share Posted March 12, 2011 Hi again,I just wanted to clarify that this fix is to solve the "Cannot parse feed!" when trying to sync conversion rate.Regards Link to comment Share on other sites More sharing options...
Recommended Posts