UpdateCurrencyRate.php
[Pman.Core] / UpdateCurrencyRate.php
1 <?php
2
3 require_once 'Pman.php';
4
5 class Pman_Core_UpdateCurrencyRate extends Pman
6 {
7     
8     static $cli_desc = "Update Currency Exchange Rate";
9     
10     static $cli_opts = array();
11     
12     var $cli = false; 
13     
14     var $actionUrl = 'http://www.oanda.com/currency/historical-rates-classic';
15     
16     
17     function getAuth() 
18     {
19         $ff = HTML_FlexyFramework::get();
20         if (!empty($ff->cli)) {
21             $this->cli = true;
22             return true;
23         }
24         
25         die("NOT ALLOWED");
26     }
27     
28     function get()
29     {
30         echo"'update currency exchange rate \n";
31         
32         $response = $this->curl($this->actionUrl, array(), 'GET');
33         file_put_contents('/tmp/test.html', $response);exit;
34         
35         
36         $doc = new DOMDocument();
37         $doc->loadHTML($response);
38         
39         $xpath = new DOMXpath($doc);
40         
41 //        $params = array(
42 //            'lang' => 'en',
43 //            'result' => 1,
44 //            'date1' => '10/14/14',
45 //            'date'=> '10/20/14',
46 //            'date_fmt' => 'us',
47 //            'exch' => 'CNY',
48 //            'expr' => 'USD',
49 //            'margin_fixed' => 0,
50 //            'format'=> 'HTML'
51 //        );
52 //        
53 //        $response = $this->curl($this->actionUrl, $params, 'POST');
54 //        
55 //        file_put_contents('/tmp/test.html', $response);
56         
57     }
58     
59     function curl($url, $request = array(), $method = 'GET') 
60     {
61          
62         if(is_array($request)){
63             $request = http_build_query($request);
64         }
65         
66         $url = $url . ($method == 'GET' ? "?" . $request : '');  
67         $ch = curl_init($url);
68         
69         if ($method == 'POST') {
70             curl_setopt($ch, CURLOPT_POST, 1);
71             curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
72             curl_setopt($ch, CURLOPT_HTTPHEADER,
73                     array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
74         }
75         
76         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
77         
78         curl_setopt($ch, CURLOPT_HEADER, false);
79         curl_setopt($ch, CURLOPT_VERBOSE, 1);
80         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
81         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
82
83         $response = curl_exec($ch);
84
85         curl_close($ch);
86         
87         return $response;
88     }
89     
90     /*
91     lang:en
92     result:1
93     date1:10/14/14
94     date:10/20/14
95     date_fmt:us
96     exch:USD
97     exch2:
98     expr:EUR
99     expr2:
100     margin_fixed:0
101     format:HTML
102     SUBMIT:Get Table
103     */
104 }