/** * Print the IMAP response to options.php * * @param array $response results of imap command * @access private */ function print_response($response) { foreach ($response as $value) { if (is_array($value)) { print_response($value); } else { print sm_encode_html_special_chars($value) . "<br />\n"; } } }
function print_response($response) { foreach ($response as $index => $value) { if (is_array($value)) { print_response($value); } else { print htmlspecialchars($value) . "<br>\n"; } } }
function post() { global $__password__; $request = @gzuncompress(@file_get_contents('php://input')); if ($request === False) { return print_notify($method, $url, 500, 'OOPS! gzuncompress php://input error!'); } $request = decode_data($request); $method = $request['method']; $url = $request['url']; $payload = $request['payload']; $dns = $request['dns']; if ($__password__ && $__password__ != $request['password']) { return print_notify($method, $url, 403, 'Wrong password.'); } if (substr($url, 0, 4) != 'http') { return print_notify($method, $url, 501, 'Unsupported Scheme'); } $FetchMax = 3; $FetchMaxSize = 1024 * 1024; $Deadline = array(0 => 16, 1 => 32); $deadline = $Deadline[0]; $headers = array(); foreach (explode("\r\n", $request['headers']) as $line) { $pair = explode(':', $line, 2); $headers[trim($pair[0])] = trim($pair[1]); } $headers['connection'] = 'close'; $fetchrange = 'bytes=0-' . strval($FetchMaxSize - 1); if (array_key_exists('range', $headers)) { preg_match('/(\\d+)?-(\\d+)?/', $headers['range'], $matches, PREG_OFFSET_CAPTURE); $start = $matches[1][0]; $end = $matches[2][0]; if ($start || $end) { if (!$start and intval($end) > $FetchMaxSize) { $end = '1023'; } else { if (!$end || intval($end) - intval($start) + 1 > $FetchMaxSize) { $end = strval($FetchMaxSize - 1 + intval($start)); } } $fetchrange = 'bytes=' . $start . '-' . $end; } } if ($dns) { preg_match('@://(.+?)[:/]@', $url, $matches, PREG_OFFSET_CAPTURE); if ($matches[1][0]) { $headers['host'] = $matches[1][0]; $url = preg_replace('@://.+?([:/])@', "://{$dns}\\1", $url); } //error_exit('matches', $matches); } //error_exit('url', $url, 'headers:', $headers); $errors = array(); for ($i = 0; $i < $FetchMax; $i++) { $response = urlfetch($url, $payload, $method, $headers, False, $deadline, False); $status_code = $response['status_code']; if (200 <= $status_code && $status_code < 400) { return print_response($status_code, $response['headers'], $response['content']); } else { if ($response['error']) { $errors[] = $response['error']; } else { $errors[] = 'URLError: ' . $status_code; } } } print_notify($request['method'], $request['url'], 502, 'PHP Fetch Server Failed: ' . var_export($errors, true)); }
if (isset(${$check}) && $submit != 'clear' && $submit != 'default') { print " checked"; } print "></td><td width=\"30%\">{$index}</td><td width=\"60%\">\n"; print addInput($index, $value, 60); } print "</td></tr></table></center><br>\n"; print "<center>" . addSubmit('submit', 'submit') . addSubmit('clear', 'submit') . addSubmit('default', 'submit') . "</center><br>\n"; $tests = array(); if ($submit == 'submit') { foreach ($type as $index => $value) { $check = "CHECK_" . $index; if (isset(${$check})) { $type[$index] = ${$index}; array_push($tests, $index); } } for ($i = 0; $i < count($tests); $i++) { print "<center><table width=\"95%\" border=\"0\" bgcolor=\"" . $color[4] . "\">\n"; print "<tr><td><b>" . $tests[$i] . "</b></td></tr>"; print "<tr><td><font color=\"" . $color[7] . "\"><small><b>" . "Request:</b></small></font></td></tr>\n"; $response = imap_test($imap_stream, $type[$tests[$i]]); print "<tr><td><font color=\"" . $color[7] . "\"><small><b>" . "Response:</b></small></font></td></tr>\n"; print "<tr><td>"; print_response($response); print "</td></tr></table></center><br>\n"; } } print "</form></td></tr></table></center></body></html>"; sqimap_logout($imap_stream); do_hook('info_bottom');
print_line("\n********A basic user profile call with field selectors********"); $api_url = "http://api.linkedin.com/v1/people/~:(first-name,last-name,positions)"; $oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET); print_response($oauth); print_line("\n********A basic user profile call with field selectors going into a subresource********"); $api_url = "http://api.linkedin.com/v1/people/~:(first-name,last-name,positions:(company:(name)))"; $oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET); print_response($oauth); print_line("\n********A basic user profile call into a subresource return data in JSON********"); $api_url = "https://api.linkedin.com/v1/people/~/connections:(first-name,last-name,headline)?format=json"; $oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET); print_response($oauth); print_line("\n********A more complicated example using postings into groups********"); $api_url = "http://api.linkedin.com/v1/groups/3297124/posts:(id,category,creator:(id,first-name,last-name),title,summary,creation-timestamp,site-group-post-url,comments,likes)"; $oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET); print_response($oauth); /******************************************************************************** * * Understanding the response, creating logging, request and response headers * ********************************************************************************/ print_line("\n********A basic user profile call and response dissected********"); $api_url = "https://api.linkedin.com/v1/people/~"; $oauth->fetch($api_url, null, OAUTH_HTTP_METHOD_GET); // show the headers print_line("\n** Request Headers:\n%s", $oauth->debugInfo["headers_sent"]); print_line("\n** Response Headers:\n%s\n", $oauth->debugInfo["headers_recv"]); // show the URL requested print_line("\n** Requested URL:\n\thttp://api.linkedin.com%s", substr(array_shift(explode("\n", $oauth->debugInfo["headers_sent"])), strpos($oauth->debugInfo["headers_sent"], " ") + 1, -9)); // for the response date and format, we need to parse the headers received $headers = http_parse_headers($oauth->debugInfo["headers_recv"]);