PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-e-commerce/wpsc-includes/currency_converter.inc.php

https://github.com/AaronFernandes/aquestionof
PHP | 101 lines | 85 code | 6 blank | 10 comment | 7 complexity | 631f5cc7c4d3f05efa33cf6c8b73f02b MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /*
  3. CURRENCYCONVERTER
  4. Date - Feb 23,2005
  5. Author - Harish Chauhan
  6. Email - harishc@ultraglobal.biz
  7. ABOUT
  8. This PHP script will use for conversion of currency.
  9. you can find it is tricky but it is usefull.
  10. */
  11. Class CURRENCYCONVERTER
  12. {
  13. var $_amt=1;
  14. var $_to="";
  15. var $_from="";
  16. var $_error="";
  17. function CURRENCYCONVERTER($amt=1,$to="",$from="")
  18. {
  19. $this->_amt=$amt;
  20. $this->_to=$to;
  21. $this->_from=$from;
  22. }
  23. function error()
  24. {
  25. return $this->_error;
  26. }
  27. function convert($amt=NULL,$to="",$from="")
  28. {
  29. if ($amt == 0) {
  30. return 0;
  31. }
  32. if($amt>1)
  33. $this->_amt=$amt;
  34. if(!empty($to))
  35. $this->_to=$to;
  36. if(!empty($from))
  37. $this->_from=$from;
  38. $host="www.xe.com";
  39. $fp = @fsockopen($host, 80, $errno, $errstr, 30);
  40. if (!$fp)
  41. {
  42. $this->_error="$errstr ($errno)<br />\n";
  43. return false;
  44. }
  45. else
  46. {
  47. $file="/ucc/convert.cgi";
  48. $str = "?language=xe&Amount=".$this->_amt."&From=".$this->_from."&To=".$this->_to;
  49. $out = "GET ".$file.$str." HTTP/1.0\r\n";
  50. $out .= "Host: $host\r\n";
  51. $out .= "Connection: Close\r\n\r\n";
  52. @fputs($fp, $out);
  53. while (!@feof($fp))
  54. {
  55. $data.= @fgets($fp, 128);
  56. }
  57. @fclose($fp);
  58. @preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $data, $match);
  59. $data =$match[2];
  60. $search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
  61. "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
  62. "'([\r\n])[\s]+'", // Strip out white space
  63. "'&(quot|#34);'i", // Replace HTML entities
  64. "'&(amp|#38);'i",
  65. "'&(lt|#60);'i",
  66. "'&(gt|#62);'i",
  67. "'&(nbsp|#160);'i",
  68. "'&(iexcl|#161);'i",
  69. "'&(cent|#162);'i",
  70. "'&(pound|#163);'i",
  71. "'&(copy|#169);'i",
  72. "'&#(\d+);'e"); // evaluate as php
  73. $replace = array ("",
  74. "",
  75. "\\1",
  76. "\"",
  77. "&",
  78. "<",
  79. ">",
  80. " ",
  81. chr(161),
  82. chr(162),
  83. chr(163),
  84. chr(169),
  85. "chr(\\1)");
  86. $data = @preg_replace($search, $replace, $data);
  87. @preg_match_all("/(\d[^\.]*(\.\d+)?)/",$data,$mathces);
  88. $return=preg_replace("/[^\d\.]*/","",$mathces[0][1]);
  89. return (double)$return;
  90. }
  91. }
  92. }
  93. ?>