本文整理汇总了PHP中drupal_http_request函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_http_request函数的具体用法?PHP drupal_http_request怎么用?PHP drupal_http_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_http_request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: request
/**
* Perform request to the Alma server.
*
* @param string $method
* The REST method to call e.g. 'patron/status'. borrCard and pinCode
* are required for all request related to library patrons.
* @param array $params
* Query string parameters in the form of key => value.
* @return DOMDocument
* A DOMDocument object with the response.
*/
public function request($method, $params = array())
{
// For use with a non-Drupal-system, we should have a way to swap
// the HTTP client out.
$request = drupal_http_request(url($this->base_url . $method, array('query' => $params)));
if ($request->code == 200) {
// Since we currently have no neat for the more advanced stuff
// SimpleXML provides, we'll just use DOM, since that is a lot
// faster in most cases.
$doc = new DOMDocument();
$doc->loadXML($request->data);
if ($doc->getElementsByTagName('status')->item(0)->getAttribute('value') == 'ok') {
return $doc;
} else {
$message = $doc->getElementsByTagName('status')->item(0)->getAttribute('key');
switch ($message) {
case '':
case 'borrCardNotFound':
throw new AlmaClientBorrCardNotFound('Invalid borrower credentials');
break;
default:
throw new AlmaClientCommunicationError('Status is not okay: ' . $message);
}
}
} else {
throw new AlmaClientHTTPError('Request error: ' . $request->code . $request->error);
}
}
示例2: sendRequest
private function sendRequest($action, $query = NULL, $type = 'GET')
{
$headers_string = $_COOKIE['vmapi_session_headers'];
if (!empty($headers_string)) {
self::$lastHeaders = json_decode($headers_string);
}
if (empty(self::$lastHeaders)) {
// need to recreate our headers
$timestamp = time();
$nonce = hash('sha1', openssl_random_pseudo_bytes(20));
$date = date('Y-m-d\\TH:i:sO', $timestamp);
$digest = base64_encode(hash('sha256', $nonce . $date . self::$key, TRUE));
$header_array = array('Content-Type' => 'application/json', 'Authorization' => 'WSSE profile="UsernameToken"', 'X-WSSE' => 'UsernameToken Username="' . self::$username . '", PasswordDigest="' . $digest . '", Nonce="' . $nonce . '", Created="' . $date . '"');
self::$lastHeaders = $header_array;
// by default, expire headers in 10 minutes
setcookie('vmapi_session_headers', json_encode(self::$lastHeaders), $timestamp + 600, '/');
}
$json_query = json_encode($query);
//print_r($json_query);
$url = self::$path;
$url .= '?action=' . $action;
if ($query != NULL) {
$url .= '&query=' . urlencode($json_query);
}
// upon reviewing the code for this class, drupal_http_request() is the only method
// dependant upon drupal. in order to make the entire class drupal-independant
// we would have to use a native PHP method for sending HTTP requests.
self::$lastResponse = drupal_http_request($url, self::$lastHeaders, $type);
if (self::$lastResponse->code > 200) {
print_r(self::$lastResponse);
}
}
示例3: takeshi_get_favicon
function takeshi_get_favicon($url)
{
$request = drupal_http_request($url, 'r');
if ($request) {
if (preg_match('/<link[^>]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $request->data, $matches)) {
$linkUrl = html_entity_decode($matches[1]);
if (substr($linkUrl, 0, 1) == '/') {
$urlParts = parse_url($url);
$faviconURL = $urlParts['scheme'] . '://' . $urlParts['host'] . $linkUrl;
} elseif (substr($linkUrl, 0, 7) == 'http://') {
$faviconURL = $linkUrl;
} elseif (substr($url, -1, 1) == '/') {
$faviconURL = $url . $linkUrl;
} else {
$faviconURL = $url . '/' . $linkUrl;
}
} else {
$urlParts = parse_url($url);
$faviconURL = $urlParts['scheme'] . '://' . $urlParts['host'] . '/favicon.ico';
}
$HTTPRequest = @fopen($faviconURL, 'r');
if ($HTTPRequest) {
stream_set_timeout($HTTPRequest, 0.1);
$favicon = fread($HTTPRequest, 8192);
$HTTPRequestData = stream_get_meta_data($HTTPRequest);
fclose($HTTPRequest);
if (!$HTTPRequestData['timed_out'] && strlen($favicon) < 8192) {
return $faviconURL;
}
}
}
return "false";
}
示例4: send_with_drupal
private static function send_with_drupal($url, $options, $ignore_error)
{
ShareaholicUtilities::log($url);
ShareaholicUtilities::log($options);
ShareaholicUtilities::log('-----------------');
$request = array();
$result = array();
$request['method'] = isset($options['method']) ? $options['method'] : 'GET';
$request['headers'] = isset($options['headers']) ? $options['headers'] : array();
$request['max_redirects'] = isset($options['redirection']) ? $options['redirection'] : 5;
$request['timeout'] = isset($options['timeout']) ? $options['timeout'] : 15;
$request['headers']['User-Agent'] = isset($options['user-agent']) ? $options['user-agent'] : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0';
if (isset($options['body'])) {
if (isset($request['headers']['Content-Type']) && $request['headers']['Content-Type'] === 'application/json') {
$request['data'] = json_encode($options['body']);
} else {
$request['data'] = http_build_query($options['body']);
}
} else {
$request['body'] = NULL;
}
$response = drupal_http_request($url, $request);
if (isset($response->error)) {
ShareaholicUtilities::log($response->error);
if (!$ignore_error) {
ShareaholicUtilities::log_event('CurlRequestFailure', array('error_message' => $response->error, 'url' => $url));
}
return false;
}
$result['headers'] = $response->headers;
$result['body'] = $response->data;
$result['response'] = array('code' => $response->code, 'message' => $response->status_message);
return $result;
}
示例5: ninesixtyrobots_preprocess_page
/**
* Add custom PHPTemplate variable into the page template
*/
function ninesixtyrobots_preprocess_page(&$vars)
{
// Check if the theme is using Twitter.
$use_twitter = theme_get_setting('use_twitter');
if (is_null($use_twitter)) {
$use_twitter = 1;
}
// If the theme uses Twitter pull it in and display it in the slogan.
if ($use_twitter) {
if ($cache = cache_get('ninesixtyrobots_tweets')) {
$data = $cache->data;
} else {
$query = theme_get_setting('twitter_search_term');
if (is_null($query)) {
$query = 'lullabot';
}
$query = drupal_urlencode($query);
$response = drupal_http_request('http://search.twitter.com/search.json?q=' . $query);
if ($response->code == 200) {
$data = json_decode($response->data);
// Set a 5 minute cache on retrieving tweets.
// Note if this isn't updating on your site *run cron*.
cache_set('ninesixtyrobots_tweets', $data, 'cache', 300);
}
}
$tweet = $data->results[array_rand($data->results)];
// Create the actual variable finally.
$vars['site_slogan'] = check_plain(html_entity_decode($tweet->text));
}
}
示例6: verify
function verify()
{
$vars = $this->ipn_vars;
$this->ipn = $this->ipn_vars;
$vars['cmd'] = '_notify-validate';
$options = array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded'), 'method' => 'POST', 'data' => drupal_http_build_query($vars));
$result = drupal_http_request($this->ipnLink, $options);
$this->ipnResult = $result->data;
if (!empty($result->error)) {
$this->lastError = t('IPN Validation Error: @error', array('@error' => $result->error));
return FALSE;
} else {
if ($result->code == 200) {
if ($result->data == 'VERIFIED') {
return TRUE;
} else {
$this->lastError = t('IPN Validation Failed: @error', array('@error' => $result->data));
return FALSE;
}
} else {
// The server might be down, let's log an error but still pass the
// validation.
ms_core_log_error('ms_paypal_wps', 'The Validation Server had an error processing a request. Request: !request Response: !response', array('!request' => ms_core_print_r($options), '!response' => ms_core_print_r($result)), WATCHDOG_CRITICAL);
return TRUE;
}
}
}
示例7: cachedRequest
public static function cachedRequest($url, array $options = array(), $cache_errors = FALSE)
{
$cid = static::cachedRequestGetCid($url, $options);
$bin = isset($options['cache']['bin']) ? $options['cache']['bin'] : 'cache';
if ($cid && ($cache = CacheHelper::get($cid, $bin))) {
return $cache->data;
} else {
$response = drupal_http_request($url, $options);
$response->request_url = $url;
$response->request_options = $options;
if (!empty($response->error)) {
trigger_error("Error on request to {$url}: {$response->code} {$response->error}.", E_USER_WARNING);
}
if (!$cache_errors && !empty($response->error)) {
$cid = FALSE;
}
if ($cid) {
$expire = static::cachedRequestGetExpire($response, $options);
if ($expire !== FALSE) {
cache_set($cid, $response, $bin, $expire);
}
}
return $response;
}
}
示例8: fetch
public function fetch()
{
$this->query = $this->url . '?pid=' . $this->pid . '&noredirect=true&format=unixref&id=doi%3A' . $this->doi;
$request_options = array('method' => 'POST');
$result = drupal_http_request($this->query, $request_options);
if ($result->code != 200) {
drupal_set_message(t('HTTP error: !error when trying to contact crossref.org for XML input', array('!error' => $result->code)), 'error');
return;
}
if (empty($result->data)) {
drupal_set_message(t('Did not get any data from crossref.org'), 'error');
return;
}
$sxml = @simplexml_load_string($result->data);
if ($error = (string) $sxml->doi_record->crossref->error) {
drupal_set_message($error, 'error');
return;
}
$this->nodes = array();
$this->parser = drupal_xml_parser_create($result->data);
// use case-folding so we are sure to find the tag in
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, FALSE);
xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, TRUE);
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'unixref_startElement', 'unixref_endElement');
xml_set_character_data_handler($this->parser, 'unixref_characterData');
if (!xml_parse($this->parser, $result->data)) {
drupal_set_message(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser)), 'error');
}
xml_parser_free($this->parser);
return $this->node;
}
示例9: executeRequest
public function executeRequest(TingClientHttpRequest $request)
{
$result = drupal_http_request($request->getUrl(), array(), $request->getMethod(), NULL, $this->numRetries);
if (isset($result->error)) {
throw new TingClientException('Unable to excecute Drupal HTTP request: ' . $result->error, $result->code);
}
return $result->data;
}
示例10: authenticateInstagramCredentials
public static function authenticateInstagramCredentials($instagramBookModel, $code)
{
global $base_url;
$url = "https://api.instagram.com/oauth/access_token";
$data = array('client_id' => $instagramBookModel->instagram_client_id, 'client_secret' => $instagramBookModel->instagram_client_secret, 'grant_type' => 'authorization_code', 'redirect_uri' => $base_url . "/" . ADMIN_URL, 'code' => $code);
$options = array('method' => 'POST', 'data' => drupal_http_build_query($data), 'timeout' => 15, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'));
$response = drupal_http_request($url, $options);
return json_decode($response->data);
}
示例11: single_page_worker
/**
* Wrapper for the Shareaholic Content Manager Single Page worker API
*
* @param Object $node The content that was created/updated/deleted
*/
public static function single_page_worker($node)
{
$page_link = url('node/' . $node->nid, array('absolute' => TRUE));
if (isset($page_link)) {
$single_page_job_url = ShareaholicUtilities::CM_API_URL . '/jobs/uber_single_page';
$data = '{"args":["' . $page_link . '", {"force": true}]}';
$options = array('method' => 'POST', 'data' => $data, 'headers' => array('Content-Type' => 'application/json'));
$response = drupal_http_request($single_page_job_url, $options);
}
}
示例12: validate
/**
* Validate the input URI.
* @param string $uri
* the URL to validate.
*/
public function validate($uri)
{
// build the callUrl to call W3C validator
$callUrl = $this->makeCallUrl($uri);
// call the W3Cvalidator WS
$result = drupal_http_request($callUrl);
if (!isset($result->error)) {
return $this->parseSOAP12Response($result->data);
} else {
return null;
}
}
示例13: request
/**
* Perform request to the Alma server.
*
* @param string $method
* The REST method to call e.g. 'patron/status'. borrCard and pinCode
* are required for all request related to library patrons.
* @param array $params
* Query string parameters in the form of key => value.
* @param bool $check_status
* Check the status element, and throw an exception if it is not ok.
*
* @return DOMDocument
* A DOMDocument object with the response.
*/
public function request($method, $params = array(), $check_status = TRUE)
{
$start_time = explode(' ', microtime());
// For use with a non-Drupal-system, we should have a way to swap
// the HTTP client out.
$request = drupal_http_request(url($this->base_url . $method, array('query' => $params)), array('secure_socket_transport' => 'sslv3'));
$stop_time = explode(' ', microtime());
// For use with a non-Drupal-system, we should have a way to swap
// logging and logging preferences out.
if (variable_get('alma_enable_logging', FALSE)) {
$seconds = floatval($stop_time[1] + $stop_time[0] - ($start_time[1] + $start_time[0]));
// Filter params to avoid logging sensitive data.
// This can be disabled by setting alma_logging_filter_params = 0. There
// is no UI for setting this variable
// It is intended for settings.php in development environments only.
$params = variable_get('alma_logging_filter_params', 1) ? self::filter_request_params($params) : $params;
// Log the request.
watchdog('alma', 'Sent request: @url (@seconds s)', array('@url' => url($this->base_url . $method, array('query' => $params)), '@seconds' => $seconds), WATCHDOG_DEBUG);
}
if ($request->code == 200) {
// Since we currently have no need for the more advanced stuff
// SimpleXML provides, we'll just use DOM, since that is a lot
// faster in most cases.
$doc = new DOMDocument();
$doc->loadXML($request->data);
if (!$check_status || $doc->getElementsByTagName('status')->item(0)->getAttribute('value') == 'ok') {
return $doc;
} else {
$message = $doc->getElementsByTagName('status')->item(0)->getAttribute('key');
switch ($message) {
case '':
case 'borrCardNotFound':
throw new AlmaClientBorrCardNotFound('Invalid borrower credentials');
case 'reservationNotFound':
throw new AlmaClientReservationNotFound('Reservation not found');
case 'invalidPatron':
if ($method == 'patron/selfReg') {
throw new AlmaClientUserAlreadyExistsError();
} else {
throw new AlmaClientInvalidPatronError();
}
default:
throw new AlmaClientCommunicationError('Status is not okay: ' . $message);
}
}
} else {
throw new AlmaClientHTTPError('Request error: ' . $request->code . $request->error);
}
}
示例14: gatherHookDocumentationFiles
/**
* Gather hook documentation files.
*
* This retrieves a list of api hook documentation files from drupal.org's
* version control server.
*/
protected function gatherHookDocumentationFiles()
{
$directory = \ModuleBuilder\Factory::getEnvironment()->getHooksDirectory();
// Fetch data about the files we need to download.
$hook_files = $this->getHookFileUrls($directory);
//print_r($hook_files);
// Retrieve each file and store it in the hooks directory, overwriting what's currently there
foreach ($hook_files as $file_name => $data) {
$file_contents = drupal_http_request($data['url']);
// TODO: replace with call to environment output.
//_module_builder_drush_print("writing $directory/$file_name", 2);
file_put_contents("{$directory}/{$file_name}", $destination . $file_contents->data);
}
return $hook_files;
}
示例15: callback
/**
* The callback for running checks and returning responses.
*
* Required for each status handler unless 'use_callback' is set to FALSE in
* the info declaration.
*
* @return array
* - 'success' (bool, required)
* Whether or not the status check was a success or failure.
* - 'messages' (array, required)
* A list of string messages to be added to the response information
* for the test.
*/
public function callback()
{
// Perform a request on an example url.
$url = 'http://exampleurl.com';
$response = drupal_http_request($url);
// Check for a 200 response and the word 'text' in the response.
if ($response->code == '200' && strpos($response->data, 'text') !== FALSE) {
$success = TRUE;
$messages[] = t('@url retrieved successfully.', ['@url' => $url]);
} else {
$success = FALSE;
$messages[] = t('@url not retrieved successfully.', ['@url' => $url]);
}
return ['success' => $success, 'messages' => $messages];
}