Changes up to 2.3.7 merged into unstable branch.
[fa-stable.git] / gl / includes / db / gl_db_rates.inc
index 5db9ba2443568970e8dd473c7a37321bd14d3431..5d98dcb7afd166084b4214e1901d771d1a1078a9 100644 (file)
@@ -9,6 +9,7 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
+include_once($path_to_root . "/includes/remote_url.inc");
 //---------------------------------------------------------------------------------------------
 function get_exchange_rate($rate_id)
 {
@@ -75,12 +76,10 @@ function delete_exchange_rate($rate_id)
 //
 function retrieve_exrate($curr_b, $date)
 {
-       global $Hooks;
-
-       if (method_exists($Hooks, 'retrieve_exrate'))
-               return $Hooks->retrieve_exrate($curr_b, $date);
-       else
-               return get_extern_rate($curr_b, 'ECB', $date);
+       $rate = hook_retrieve_exrate($curr_b, $date);
+       if (is_numeric($rate))
+               return $rate;
+       return get_extern_rate($curr_b, 'ECB', $date);
 }
 //-----------------------------------------------------------------------------
 
@@ -113,7 +112,9 @@ function get_extern_rate($curr_b, $provider = 'ECB', $date)
               curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie.txt");
           curl_setopt ($ch, CURLOPT_HEADER, 0);
               curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
-          curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
+              // prevent warning while save_mode/open_basedir on (redireciton doesn't occur at least on ECB page)
+                  if (!ini_get('save_mode') && !ini_get('open_basedir'))
+               curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
               curl_setopt ($ch, CURLOPT_TIMEOUT, 3);
           $contents = curl_exec ($ch);
               curl_close($ch);
@@ -123,21 +124,10 @@ function get_extern_rate($curr_b, $provider = 'ECB', $date)
           } while( ($contents == '') && $retry--);
           
        } else {
-               $handle = @fopen("http://".$site.$filename, 'rb');
-               if ($handle) {
-                       do 
-                       {
-                               $data = @fread( $handle, 4096 );
-                               if ( strlen ( $data ) == 0 ) 
-                                       break;
-                               $contents .= $data; // with this syntax only text will be translated, whole text with htmlspecialchars($data)
-                       } 
-                       while (true);
-                       @fclose( $handle );
-               } // end handle
+               $contents = url_get_contents("http://".$site.$filename);
        }
        if (!$contents) {
-               display_warning(_("Cannot retrieve currency rate from $provider page. Please set the rate manually."));
+               display_warning(sprintf(_("Cannot retrieve currency rate from %s page. Please set the rate manually."), $provider));
        }
        if ($provider == 'ECB')
        {