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         $doc = new DOMDocument();
33         $doc->loadHTML($response);
34         
35         $xpath = new DOMXpath($doc);
36         
37 //        $params = array(
38 //            'lang' => 'en',
39 //            'result' => 1,
40 //            'date1' => '10/14/14',
41 //            'date'=> '10/20/14',
42 //            'date_fmt' => 'us',
43 //            'exch' => 'CNY',
44 //            'expr' => 'USD',
45 //            'margin_fixed' => 0,
46 //            'format'=> 'HTML'
47 //        );
48 //        
49 //        $response = $this->curl($this->actionUrl, $params, 'POST');
50 //        
51 //        file_put_contents('/tmp/test.html', $response);
52         
53     }
54     
55     function curl($url, $request = array(), $method = 'GET') 
56     {
57          
58         if(is_array($request)){
59             $request = http_build_query($request);
60         }
61         
62         $url = $url . ($method == 'GET' ? "?" . $request : '');  
63         $ch = curl_init($url);
64         
65         if ($method == 'POST') {
66             curl_setopt($ch, CURLOPT_POST, 1);
67             curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
68             curl_setopt($ch, CURLOPT_HTTPHEADER,
69                     array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($request)));
70         }
71         
72         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
73         
74         curl_setopt($ch, CURLOPT_HEADER, false);
75         curl_setopt($ch, CURLOPT_VERBOSE, 1);
76         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
77         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
78
79         $response = curl_exec($ch);
80
81         curl_close($ch);
82         
83         return $response;
84     }
85     
86     /*
87     lang:en
88     result:1
89     date1:10/14/14
90     date:10/20/14
91     date_fmt:us
92     exch:USD
93     exch2:
94     expr:EUR
95     expr2:
96     margin_fixed:0
97     format:HTML
98     SUBMIT:Get Table
99     */
100 }