GoogleTranslate.php
[Pman.Core] / GoogleTranslate.php
1 <?php
2
3 /**
4  * Description of GoogleTranslate
5  *
6  * @author chris
7  */
8
9 require_once 'Pman.php';
10 class Pman_Core_GoogleTranslate extends Pman
11 {
12     //put your code here
13     function getAuth()
14     {
15         
16         $au = $this->getAuthUser();
17         if (!$au) {
18             $this->jerrAuth("only authenticated users");
19         }
20         
21         $this->authUser = $au;
22     }
23     function get() {
24         // for testing..
25         return $this->post();
26     }
27     
28     function post()
29     {
30         $pc = HTML_FlexyFramework::get()->Pman_Core;
31         if (empty($pc['googlekey'])) {
32             $this->jerr("Google API Key not configured");
33         }
34         
35         $param = array(
36             'key' => $pc['googlekey'],
37             'q' => rawurlencode($_REQUEST['text']),
38             'source' => $_REQUEST['src'],
39             'target' => $_REQUEST['dest']
40         );
41         
42         $url = 'https://www.googleapis.com/language/translate/v2';
43
44         $handle = curl_init();
45         curl_setopt($handle,CURLOPT_URL, $url);
46         curl_setopt($handle, CURLOPT_POST, count($param));
47         curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($param));
48         curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
49         
50         $response = curl_exec($handle);
51         
52         print_r($response);
53         
54         $responseDecoded = json_decode($response, true);
55         curl_close($handle);
56     
57         $this->jdata($responseDecoded);
58         
59     }
60     
61     
62 }