function _dsq_fopen_urlopen in Drupal Most Popular 7
File
- modules/
mostpopular_disqus/ disqusapi/ url.php, line 177
Code
function _dsq_fopen_urlopen($url, $postdata, &$response, $file_name, $file_field) {
$params = array();
if ($file_name && $file_field) {
$boundary = '----------' . md5(time());
$content = dsq_get_post_content($boundary, $postdata, $file_name, $file_field);
$header = dsq_get_http_headers_for_request($boundary, $content, $file_name, $file_field);
$params = array(
'http' => array(
'method' => 'POST',
'header' => $header,
'content' => $content,
'timeout' => SOCKET_TIMEOUT,
),
);
}
else {
if ($postdata) {
$params = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => dsq_get_query_string($postdata),
'timeout' => SOCKET_TIMEOUT,
),
);
}
}
ini_set('user_agent', USER_AGENT);
$ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp) {
return false;
}
// Get status code from headers.
list($unused, $response['code'], $unused) = explode(' ', $http_response_header[0], 3);
$headers = array_slice($http_response_header, 1);
// Convert headers into associative array.
foreach ($headers as $unused => $header) {
$header = explode(':', $header);
$header[0] = trim($header[0]);
$header[1] = trim($header[1]);
$headers[strtolower($header[0])] = strtolower($header[1]);
}
$response['data'] = stream_get_contents($fp);
}