protected static function _send_request($url, $params = array(), $method = 'GET', $multi_part, $gzencoded = false, $has_return_value = true, $json_response = true, $has_api_response = true) { $response = null; $method = strtoupper($method); if ($params) { $url = self::add_parameters_to_url($url, $params); if ($method == 'GET') { $url .= '?' . http_build_query($params); } } if (!isset($params['api_version']) || !$params['api_version']) { $params['api_version'] = self::API_VERSION; } TranslationProxy_Com_Log::log_call($url, $params, $method, $multi_part); $api_response = self::_call_remote_api($url, $params, $method, $multi_part, $has_return_value); if ($gzencoded) { try { // set_error_handler('icl_handleError'); $gzdecoded_response = @gzdecode($api_response); // restore_error_handler(); if (!$gzdecoded_response) { throw new TranslationProxy_Api_Error('gzdecode() returned an empty value. api_response: ' . print_r($api_response, true), 0); } else { $api_response = $gzdecoded_response; } } catch (Exception $e) { throw new TranslationProxy_Api_Error('gzdecode() failed. api_response: ' . print_r($api_response, true), 0); } } if ($json_response) { TranslationProxy_Com_Log::log_response($api_response); } else { TranslationProxy_Com_Log::log_response('XLIFF received'); } if ($has_return_value) { if ($json_response) { $response = json_decode($api_response); if ($has_api_response) { $response = self::_get_api_response($response); } } else { $response = $api_response; } } return $response; }
/** * @param string $url * @param array $params * @param string $method * @param bool|true $has_return_value * @param bool|true $json_response * @param bool|true $has_api_response * * @return array|mixed|null|object|string * @throws TranslationProxy_Api_Error */ public function send_request($url, $params = array(), $method = 'GET', $has_return_value = true, $json_response = true, $has_api_response = true) { if (!$url) { throw new InvalidArgumentException('Empty target URL given!'); } $response = null; $method = strtoupper($method); if ($params) { $url = TranslationProxy_Api::add_parameters_to_url($url, $params); if ($method === 'GET') { $url .= '?' . http_build_query($params); } } if (!isset($params['api_version']) || !$params['api_version']) { $params['api_version'] = self::API_VERSION; } TranslationProxy_Com_Log::log_call($url, $params); $api_response = $this->call_remote_api($url, $params, $method, $has_return_value); if ($has_return_value) { if (!isset($api_response['headers']['content-type'])) { throw new RuntimeException('Invalid HTTP response, no content type in header given!'); } $content_type = $api_response['headers']['content-type']; $api_response = $api_response['body']; $api_response = strpos($content_type, 'zip') !== false ? gzdecode($api_response) : $api_response; TranslationProxy_Com_Log::log_response($json_response ? $api_response : 'XLIFF received'); if ($json_response) { $response = json_decode($api_response); if ($has_api_response) { if (!$response || !isset($response->status->code) || $response->status->code != 0) { throw new RuntimeException("Cannot communicate with the remote service response on url:" . $url . ' params: ' . serialize($params) . 'response: ' . serialize($response)); } $response = $response->response; } } else { $response = $api_response; } } return $response; }
public function __construct($message) { TranslationProxy_Com_Log::log_error($message); parent::__construct($message); }
private function build_tp_com_log() { require_once WPML_TM_PATH . '/inc/translation-proxy/translationproxy-com-log.class.php'; if (isset($_POST['tp-com-clear-log'])) { TranslationProxy_Com_Log::clear_log(); } if (isset($_POST['tp-com-disable-log'])) { TranslationProxy_Com_Log::set_logging_state(false); } if (isset($_POST['tp-com-enable-log'])) { TranslationProxy_Com_Log::set_logging_state(true); } $action_url = esc_attr('admin.php?page=' . WPML_TM_FOLDER . '/menu/main.php&sm=' . $_GET['sm']); $com_log = TranslationProxy_Com_Log::get_log(); ?> <form method="post" id="tp-com-log-form" name="tp-com-log-form" action="<?php echo $action_url; ?> "> <?php if (TranslationProxy_Com_Log::is_logging_enabled()) { ?> <?php _e("This is a log of the communication between your site and the translation system. It doesn't include any private information and allows WPML support to help with problems related to sending content to translation.", 'wpml-translation-management'); ?> <br /> <br /> <?php if ($com_log != '') { ?> <textarea wrap="off" readonly="readonly" rows="16" style="font-size:10px; width:100%"><?php echo $com_log; ?> </textarea> <br /> <br /> <input class="button-secondary" type="submit" name="tp-com-clear-log" value="<?php _e('Clear log', 'wpml-translation-management'); ?> "> <?php } else { ?> <strong><?php _e('The communication log is empty.', 'wpml-translation-management'); ?> </strong> <br /> <br /> <?php } ?> <input class="button-secondary" type="submit" name="tp-com-disable-log" value="<?php _e('Disable logging', 'wpml-translation-management'); ?> "> <?php } else { ?> <?php _e("Communication logging is currently disabled. To allow WPML support to help you with issues related to sending content to translation, you need to enable the communication logging.", 'wpml-translation-management'); ?> <br /> <br /> <input class="button-secondary" type="submit" name="tp-com-enable-log" value="<?php _e('Enable logging', 'wpml-translation-management'); ?> "> <?php } ?> </form> <?php }
public function add_com_log_link() { require_once WPML_TM_PATH . '/inc/translation-proxy/translationproxy-com-log.class.php'; TranslationProxy_Com_Log::add_com_log_link(); }
function xmlrpc_updated_job_status_with_log($args) { require_once WPML_TM_PATH . '/inc/translation-proxy/translationproxy-com-log.class.php'; TranslationProxy_Com_Log::log_xml_rpc(array('tp_job_id' => $args[0], 'cms_id' => $args[1], 'status' => $args[2], 'signature' => 'UNDISCLOSED')); $ret = $this->xmlrpc_updated_job_status($args); TranslationProxy_Com_Log::log_xml_rpc(array('result' => $ret)); return $ret; }
/** * @param array $args * * @param bool $bypass_auth * * @return int|string */ function xmlrpc_updated_job_status_with_log($args, $bypass_auth = false) { require_once WPML_TM_PATH . '/inc/translation-proxy/translationproxy-com-log.class.php'; TranslationProxy_Com_Log::log_xml_rpc(array('tp_job_id' => $args[0], 'cms_id' => $args[1], 'status' => $args[2], 'signature' => 'UNDISCLOSED')); $args[3] = $bypass_auth ? true : $args[3]; $project = TranslationProxy::get_current_project(); if ($project) { $update = new WPML_TM_XmlRpc_Job_Update($project, $this); $ret = $update->update_status($args, $bypass_auth); } else { $ret = "Project does not exist"; } TranslationProxy_Com_Log::log_xml_rpc(array('result' => $ret)); return $ret; }