$response->setContent($result->content); $response->setResponseCode(200, false); Hook::trigger('onAfterTranslation'); } public function _translate(&$ch, &$boundary) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http' . ((int)Configuration::getInstance()->get('port')===443?'s':''). '://'.Configuration::getInstance()->get('host').':'.Configuration::getInstance()->get('port')); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($ch, CURLOPT_TIMEOUT, 300); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $boundary->getContent()); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Cache-Control: no-cache', 'Content-Type: multipart/form-data; boundary=' . $boundary->getBoundary() )); if ((int)Configuration::getInstance()->get('port') === 443) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); if (Configuration::getInstance()->get('dl_certificates') === true) { curl_setopt($ch, CURLOPT_CAINFO, Certificates::getInstance()->getPath()); } } $time_start = microtime(true); $translated_content = curl_exec($ch); Debug::timing('Curl translation request took %s', $time_start); $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); Debug::log('Response code: ' . $response_code); Debug::log('Translated content: ' . PHP_EOL . '######################' . PHP_EOL . $translated_content . PHP_EOL . '######################', 5); return [$translated_content, $response_code]; } public function translateJson($content, $url, $language) { Hook::trigger('onBeforeJsonTranslation'); $boundary = Boundary::getInstance(); $content = json_encode($content); $boundary->addPostFields('version', Processor::$version); $boundary->addPostFields('url', $url); $boundary->addPostFields('language', $language); $boundary->addPostFields('is_search', true); $boundary->addPostFields('content', $content); $boundary->addPostFields('token',Configuration::getInstance()->get('token')); $boundary->addPostFields('ip', Helper::getIpAddress()); $boundary->addPostFields('user_agent', !empty($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:''); Hook::trigger('onBeforeJsonTranslationRequest'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http' . ((int)Configuration::getInstance()->get('port')===443?'s':''). '://'.Configuration::getInstance()->get('host').':'.Configuration::getInstance()->get('port')); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($ch, CURLOPT_TIMEOUT, 300); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $boundary->getContent()); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Cache-Control: no-cache', 'Content-Type: multipart/form-data; boundary=' . $boundary->getBoundary() )); if ((int)Configuration::getInstance()->get('port') === 443) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); if (Configuration::getInstance()->get('dl_certificates') === true) { curl_setopt($ch, CURLOPT_CAINFO, Certificates::getInstance()->getPath()); } } $time_start = microtime(true); $translated_content = curl_exec($ch); Debug::timing('Curl translation request took %s', $time_start); $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); Debug::log('Response code: ' . $response_code); Debug::log('Translated content: ' . PHP_EOL . '######################' . PHP_EOL . $translated_content . PHP_EOL . '######################', 5); curl_close($ch); if (!$translated_content || $response_code !== 200) { return false; } $result = json_decode($translated_content); if (!$result) { return false; } Debug::log('Translation decoded ' . print_r($result, true), 5); Hook::trigger('onAfterJsonTranslation'); return json_decode($result->content); } }