From: Chris Date: Wed, 2 Apr 2014 10:09:29 +0000 (+0800) Subject: GoogleTranslate.php X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=commitdiff_plain;h=99f086c24379d18e9c725beb1cfc6f34471c402a GoogleTranslate.php --- diff --git a/GoogleTranslate.php b/GoogleTranslate.php index a9e22bcc..8b4585e0 100644 --- a/GoogleTranslate.php +++ b/GoogleTranslate.php @@ -10,6 +10,54 @@ require_once 'Pman.php'; class Pman_Core_GoogleTranslate extends Pman { //put your code here + function getAuth() + { + + $au = $this->getAuthUser(); + if (!$au) { + $this->jerrAuth("only authenticated users"); + } + + $this->authUser = $au; + } + function get() { + // for testing.. + return $this->post(); + } + + function post() + { + $pc = HTML_FlexyFramework::get()->Pman_Core; + if (empty($pc['googlekey'])) { + $this->jerr("Google API Key not configured"); + } + + $apiKey = $pc['googlekey']; + + $text = 'Hello world!'; + $param = array( + 'key' => $pc['googlekey'], + 'q' => rawurlencode($_REQUEST['text']), + 'source' => $_REQUEST['src'], + 'target' => $_REQUEST['dest'] + ); + + $url = 'https://www.googleapis.com/language/translate/v2?key='. + $apiKey. + '&q='. + rawurlencode($text). + '&source=en&target=fr'; + + $handle = curl_init($url); + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec($handle); + $responseDecoded = json_decode($response, true); + curl_close($handle); + + + $this->jdata($key); + + } }