private function proxy_http_request($data = array()) { $method = strtolower($_POST['method']); $url = $_POST['url']; if (isset($_POST['cookie_name'])) { $data['cookies'] = array(new WP_Http_Cookie(array('name' => $_POST['cookie_name'], 'value' => $_POST['cookie_value']))); } switch ($method) { case 'put': $response = ThePlatform_API_HTTP::put($url, $data); break; case 'get': $response = ThePlatform_API_HTTP::get($url); break; case 'post': $response = ThePlatform_API_HTTP::post($url, $data); break; default: $response = array(); break; } return $response; }
/** * Creates a placeholder Media object in MPX. * * @param array $args URL arguments to pass to the Media data service * @param string $token The token for this upload session * @return string JSON response from the Media data service */ function create_media_placeholder($args, $token) { $fields = json_decode(stripslashes($args['fields']), TRUE); $custom_fields = json_decode(stripslashes($args['custom_fields']), TRUE); if (empty($fields)) { wp_die('No fields are set, unable to upload Media'); } // Create the Custom Fields namespace and values arrays $custom_field_ns = array(); $custom_field_values = array(); if (!empty($custom_fields)) { $fieldKeys = implode('|', array_keys($custom_fields)); $customfield_info = $this->get_customfield_info($fieldKeys); foreach ($customfield_info['entries'] as $value) { if ($value['namespacePrefix'] !== '') { $custom_field_ns[$value['namespacePrefix']] = $value['namespace']; $custom_field_values[$value['namespacePrefix'] . '$' . $value['fieldName']] = $custom_fields[$value['fieldName']]; } } } $payload = array_merge(array('$xmlns' => array_merge(array(), $custom_field_ns)), array_merge($fields, $custom_field_values)); $url = TP_API_MEDIA_ENDPOINT; $url .= '&account=' . $this->get_mpx_account_id(); $url .= '&token=' . $token; $data = array('body' => json_encode($payload, JSON_UNESCAPED_SLASHES)); $response = ThePlatform_API_HTTP::post($url, $data, true); return theplatform_decode_json_from_server($response, TRUE); }