PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/endomorphosis/reservationtelco
PHP | 104 lines | 85 code | 6 blank | 13 comment | 7 complexity | 7cdf0494dfb1cf1b44c1be69ec9b1522 MD5 | raw file
  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.iraqidinar.org";
  39. $host="www.xe.com";
  40. $fp = @fsockopen($host, 80, $errno, $errstr, 30);
  41. if (!$fp)
  42. {
  43. $this->_error="$errstr ($errno)<br />\n";
  44. return false;
  45. }
  46. else
  47. {
  48. //$file="/conversiontool2.asp";
  49. $file="/ucc/convert.cgi";
  50. //$str = "?amount=".$this->_amt."&ConvertFrom=".$this->_from."&ConvertTo=".$this->_to;
  51. $str = "?language=xe&Amount=".$this->_amt."&From=".$this->_from."&To=".$this->_to;
  52. $out = "GET ".$file.$str." HTTP/1.0\r\n";
  53. $out .= "Host: $host\r\n";
  54. $out .= "Connection: Close\r\n\r\n";
  55. @fputs($fp, $out);
  56. while (!@feof($fp))
  57. {
  58. $data.= @fgets($fp, 128);
  59. }
  60. @fclose($fp);
  61. @preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $data, $match);
  62. $data =$match[2];
  63. $search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
  64. "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
  65. "'([\r\n])[\s]+'", // Strip out white space
  66. "'&(quot|#34);'i", // Replace HTML entities
  67. "'&(amp|#38);'i",
  68. "'&(lt|#60);'i",
  69. "'&(gt|#62);'i",
  70. "'&(nbsp|#160);'i",
  71. "'&(iexcl|#161);'i",
  72. "'&(cent|#162);'i",
  73. "'&(pound|#163);'i",
  74. "'&(copy|#169);'i",
  75. "'&#(\d+);'e"); // evaluate as php
  76. $replace = array ("",
  77. "",
  78. "\\1",
  79. "\"",
  80. "&",
  81. "<",
  82. ">",
  83. " ",
  84. chr(161),
  85. chr(162),
  86. chr(163),
  87. chr(169),
  88. "chr(\\1)");
  89. $data = @preg_replace($search, $replace, $data);
  90. @preg_match_all("/(\d[^\.]*(\.\d+)?)/",$data,$mathces);
  91. $return=preg_replace("/[^\d\.]*/","",$mathces[0][4]);
  92. return (double)$return;
  93. }
  94. }
  95. }
  96. ?>