本文整理汇总了PHP中curl::get方法的典型用法代码示例。如果您正苦于以下问题:PHP curl::get方法的具体用法?PHP curl::get怎么用?PHP curl::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curl
的用法示例。
在下文中一共展示了curl::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPublicKeyFromServer
function getPublicKeyFromServer($server, $email)
{
/* refactor to
$command = "gpg --keyserver ".escapeshellarg($server)." --search-keys ".escapeshellarg($email)."";
echo "$command\n\n";
//execute the gnupg command
exec($command, $result);
*/
$curl = new curl();
// get Fingerprint
$data = $curl->get("http://" . $server . ":11371/pks/lookup?search=" . urlencode($email) . "&op=index&fingerprint=on&exact=on");
$data = $data['FILE'];
preg_match_all("/<pre>([\\s\\S]*?)<\\/pre>/", $data, $matches);
//$pub = $matches[1][1];
preg_match_all("/<a href=\"(.*?)\">(\\w*)<\\/a>/", $matches[1][1], $matches);
$url = $matches[1][0];
$keyID = $matches[2][0];
// get Public Key
$data = $curl->get("http://" . $server . ":11371" . $url);
$data = $data['FILE'];
preg_match_all("/<pre>([\\s\\S]*?)<\\/pre>/", $data, $matches);
$pub_key = trim($matches[1][0]);
return array("keyID" => $keyID, "public_key" => $pub_key);
}
示例2: definition
function definition()
{
global $DB, $CFG, $COURSE;
$mform =& $this->_form;
$mform->addElement('textarea', 'querysql', get_string('querysql', 'block_configurable_reports'), 'rows="35" cols="80"');
$mform->addRule('querysql', get_string('required'), 'required', null, 'client');
$mform->setType('querysql', PARAM_RAW);
$mform->addElement('hidden', 'courseid', $COURSE->id);
$mform->setType('courseid', PARAM_INT);
$this->add_action_buttons();
$mform->addElement('static', 'note', '', get_string('listofsqlreports', 'block_configurable_reports'));
if ($userandrepo = get_config('block_configurable_reports', 'sharedsqlrepository')) {
$c = new curl();
$res = $c->get("https://api.github.com/repos/{$userandrepo}/contents/");
$res = json_decode($res);
if (is_array($res)) {
$reportcategories = array(get_string('choose'));
foreach ($res as $item) {
if ($item->type == 'dir') {
$reportcategories[$item->path] = $item->path;
}
}
$mform->addElement('select', 'reportcategories', get_string('reportcategories', 'block_configurable_reports'), $reportcategories, array('onchange' => 'M.block_configurable_reports.onchange_reportcategories(this,"' . sesskey() . '")'));
$mform->addElement('select', 'reportsincategory', get_string('reportsincategory', 'block_configurable_reports'), $reportcategories, array('onchange' => 'M.block_configurable_reports.onchange_reportsincategory(this,"' . sesskey() . '")'));
$mform->addElement('textarea', 'remotequerysql', get_string('remotequerysql', 'block_configurable_reports'), 'rows="15" cols="90"');
}
}
//$this->add_action_buttons();
}
示例3: get
/**
* Makes a GET petition using the curl instance
*
* @param string $uri
* @return array
*/
private function get($uri)
{
$response = $this->client->get(self::APIBASE . $uri);
if ($response) {
return json_decode($response);
}
}
示例4: curl
/**
* The contructor is a copy of the stock simplepie File class which has
* been modifed to add in use the Moodle curl class rather than php curl
* functions.
*/
function moodle_simplepie_file($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
{
$this->url = $url;
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
$curl = new curl();
$curl->setopt(array('CURLOPT_HEADER' => true));
try {
$this->headers = $curl->get($url);
} catch (moodle_exception $e) {
$this->error = 'cURL Error: ' . $curl->error;
$this->success = false;
return false;
}
$parser =& new SimplePie_HTTP_Parser($this->headers);
if ($parser->parse()) {
$this->headers = $parser->headers;
$this->body = $parser->body;
$this->status_code = $parser->status_code;
if (($this->status_code == 300 || $this->status_code == 301 || $this->status_code == 302 || $this->status_code == 303 || $this->status_code == 307 || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects) {
$this->redirects++;
$location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
return $this->SimplePie_File($location, $timeout, $redirects, $headers);
}
}
}
示例5: ip
/**
* ip地址查询
*/
public function ip()
{
$ip = $this->post('ip');
if (!$ip) {
return;
}
$result = $ip_address = array();
// tool.lu
$toollu = curl::post('http://tool.lu/netcard/ajax.html', array('ip' => $ip));
$toollu = json_decode($toollu, true);
$result['tool.lu'] = trim($toollu['text'][2]);
$result['纯真数据库'] = trim($toollu['text'][1]);
// 站长工具
$chinaz = curl::post('http://ip.chinaz.com', array('ip' => $ip));
$chinaz = trim(preg_replace('/<.+?>/', '', $chinaz));
$chinaz = explode('查询结果', $chinaz);
if ($chinaz) {
unset($chinaz[0]);
$size = intval(count($chinaz));
$chinaz[$size] = trim(substr($chinaz[$size], 0, strpos($chinaz[$size], 'document')));
$address = '';
foreach ($chinaz as $c) {
$c = explode('==>>', $c);
$ip_address_ = explode(':', trim($c[0]));
$ip_address[] = trim($ip_address_[1]);
$tmp_arr = explode("\r\n", trim($c[2]));
$address .= trim($tmp_arr[0]) . ' ';
}
$result['站长工具'] = trim($address);
}
// 淘宝
if ($ip_address) {
$taobao = curl::get('http://ip.taobao.com/service/getIpInfo.php', array('ip' => $ip_address[0]));
$taobao = json_decode($taobao, true);
if (intval($taobao['code']) === 0) {
$taobao = $taobao['data'];
$result['淘宝'] = $taobao['country'] . '|' . $taobao['area'] . '|' . $taobao['region'] . '|' . $taobao['city'] . '|' . $taobao['isp'];
}
}
// ipip.net
if ($ip_address) {
$ipip = curl::get('http://freeapi.ipip.net/' . $ip_address[0]);
$ipip = json_decode($ipip, true);
if (is_array($ipip)) {
$ipipstr = '';
foreach ($ipip as $str) {
$str = trim($str);
if (empty($str)) {
continue;
}
$ipipstr .= $str . ' ';
}
$result['ipip.net'] = $ipipstr;
}
}
view::assign('input', $ip);
view::assign('ip', $ip_address);
view::assign('result', $result);
}
示例6: _get_collection
private function _get_collection($keyword)
{
global $OUTPUT;
$list = array();
$this->api = 'http://www.merlot.org/merlot/materials.rest?keywords=' . urlencode($keyword) . '&licenseKey=' . $this->licensekey;
$c = new curl(array('cache' => true, 'module_cache' => 'repository'));
$content = $c->get($this->api);
$xml = simplexml_load_string($content);
foreach ($xml->results->material as $entry) {
$list[] = array('title' => (string) $entry->title, 'thumbnail' => $OUTPUT->pix_url('f/unknown-32')->out(false), 'date' => userdate((int) $entry->creationDate), 'size' => '', 'source' => (string) $entry->URL);
}
return $list;
}
示例7: call_service
/**
* Calls the pluginfo.php service and returns the raw response
*
* @param string $component
* @param string $version
* @return string
*/
protected function call_service($component, $version)
{
global $CFG;
require_once $CFG->libdir . '/filelib.php';
$curl = new curl(array('proxy' => true));
$response = $curl->get($this->service_request_url(), $this->service_request_params($component, $version), $this->service_request_options());
$curlerrno = $curl->get_errno();
$curlinfo = $curl->get_info();
if (!empty($curlerrno)) {
throw new tool_installaddon_pluginfo_exception('err_curl_exec', array('url' => $curlinfo['url'], 'errno' => $curlerrno, 'error' => $curl->error));
} else {
if ($curlinfo['http_code'] != 200) {
throw new tool_installaddon_pluginfo_exception('err_curl_http_code', array('url' => $curlinfo['url'], 'http_code' => $curlinfo['http_code']));
} else {
if (isset($curlinfo['ssl_verify_result']) and $curlinfo['ssl_verify_result'] != 0) {
throw new tool_installaddon_pluginfo_exception('err_curl_ssl_verify', array('url' => $curlinfo['url'], 'ssl_verify_result' => $curlinfo['ssl_verify_result']));
}
}
}
return $response;
}
示例8: _get_collection
/**
* Private method to get youtube search results
* @param string $keyword
* @param int $start
* @param int $max max results
* @param string $sort
* @return array
*/
private function _get_collection($keyword, $start, $max, $sort)
{
$list = array();
$this->feed_url = 'http://gdata.youtube.com/feeds/api/videos?q=' . urlencode($keyword) . '&format=5&start-index=' . $start . '&max-results=' . $max . '&orderby=' . $sort;
$c = new curl(array('cache' => true, 'module_cache' => 'repository'));
$content = $c->get($this->feed_url);
$xml = simplexml_load_string($content);
$media = $xml->entry->children('http://search.yahoo.com/mrss/');
$links = $xml->children('http://www.w3.org/2005/Atom');
foreach ($xml->entry as $entry) {
$media = $entry->children('http://search.yahoo.com/mrss/');
$title = $media->group->title;
$attrs = $media->group->thumbnail[2]->attributes();
$thumbnail = $attrs['url'];
$arr = explode('/', $entry->id);
$id = $arr[count($arr) - 1];
$source = 'http://www.youtube.com/v/' . $id . '#' . $title;
$list[] = array('title' => (string) $title, 'thumbnail' => (string) $attrs['url'], 'thumbnail_width' => 150, 'thumbnail_height' => 120, 'size' => '', 'date' => '', 'source' => $source);
}
return $list;
}
示例9: validate_fields
/**
* Checks if the schema existing fields are properly set, triggers an exception otherwise.
*
* @throws \moodle_exception
* @param array $fields
* @param bool $requireexisting Require the fields to exist, otherwise exception.
* @return void
*/
protected function validate_fields(&$fields, $requireexisting = false)
{
global $CFG;
foreach ($fields as $fieldname => $data) {
$url = $this->engine->get_connection_url('/schema/fields/' . $fieldname);
$results = $this->curl->get($url);
if ($this->curl->error) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $this->curl->error);
}
if (!$results) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', get_string('nodatafromserver', 'search_solr'));
}
$results = json_decode($results);
if ($requireexisting && !empty($results->error) && $results->error->code === 404) {
$a = new \stdClass();
$a->fieldname = $fieldname;
$a->setupurl = $CFG->wwwroot . '/search/engine/solr/setup_schema.php';
throw new \moodle_exception('errorvalidatingschema', 'search_solr', '', $a);
}
// The field should not exist so we only accept 404 errors.
if (empty($results->error) || !empty($results->error) && $results->error->code !== 404) {
if (!empty($results->error)) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $results->error->msg);
} else {
// All these field attributes are set when fields are added through this script and should
// be returned and match the defined field's values.
if (empty($results->field) || !isset($results->field->type) || !isset($results->field->multiValued) || !isset($results->field->indexed) || !isset($results->field->stored)) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', get_string('schemafieldautocreated', 'search_solr', $fieldname));
} else {
if ($results->field->type !== $data['type'] && ($data['type'] !== 'text' || $results->field->type !== 'text_general') || $results->field->multiValued !== false || $results->field->indexed !== $data['indexed'] || $results->field->stored !== $data['stored']) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', get_string('schemafieldautocreated', 'search_solr', $fieldname));
} else {
// The field already exists and it is properly defined, no need to create it.
unset($fields[$fieldname]);
}
}
}
}
}
}
示例10: request_token
/**
* Request token for authentication
* This is the first step to use OAuth, it will return oauth_token and oauth_token_secret
* @return array
*/
public function request_token()
{
$this->sign_secret = $this->consumer_secret . '&';
$params = $this->prepare_oauth_parameters($this->request_token_api, array(), 'GET');
$content = $this->http->get($this->request_token_api, $params, $this->http_options);
// Including:
// oauth_token
// oauth_token_secret
$result = $this->parse_result($content);
if (empty($result['oauth_token'])) {
throw new moodle_exception('Error while requesting an oauth token');
}
// build oauth authrize url
if (!empty($this->oauth_callback)) {
// url must be rawurlencode
$result['authorize_url'] = $this->authorize_url . '?oauth_token=' . $result['oauth_token'] . '&oauth_callback=' . rawurlencode($this->oauth_callback->out(false));
} else {
// no callback
$result['authorize_url'] = $this->authorize_url . '?oauth_token=' . $result['oauth_token'];
}
return $result;
}
示例11: curl_request
public function curl_request($action, $collection = null)
{
$curl = new curl();
switch ($action) {
case 'user':
$url = $this->backpack . "/displayer/convert/email";
$param = array('email' => $this->email);
break;
case 'groups':
$url = $this->backpack . '/displayer/' . $this->backpackuid . '/groups.json';
break;
case 'badges':
$url = $this->backpack . '/displayer/' . $this->backpackuid . '/group/' . $collection . '.json';
break;
}
$options = array('FRESH_CONNECT' => true, 'RETURNTRANSFER' => true, 'FORBID_REUSE' => true, 'HEADER' => 0, 'HTTPHEADER' => array('Expect:'), 'CONNECTTIMEOUT' => 3);
if ($action == 'user') {
$out = $curl->post($url, $param, $options);
} else {
$out = $curl->get($url, array(), $options);
}
return json_decode($out);
}
示例12: do_request
/**
* Send the request via our curl object.
*
* @param curl $curl prepared curl object.
* @param Google_HttpRequest $request The request.
* @return string result of the request.
*/
private function do_request($curl, $request)
{
$url = $request->getUrl();
$method = $request->getRequestMethod();
switch (strtoupper($method)) {
case 'POST':
$ret = $curl->post($url, $request->getPostBody());
break;
case 'GET':
$ret = $curl->get($url);
break;
case 'HEAD':
$ret = $curl->head($url);
break;
case 'PUT':
$ret = $curl->put($url);
break;
default:
throw new coding_exception('Unknown request type: ' . $method);
break;
}
return $ret;
}
示例13: loginpage_hook
/**
* Authentication hook - is called every time user hit the login page
* The code is run only if the param code is mentionned.
*/
public function loginpage_hook()
{
global $USER, $SESSION, $CFG, $DB;
// Check the Google authorization code.
$authorizationcode = optional_param('code', '', PARAM_TEXT);
if (!empty($authorizationcode)) {
$authprovider = required_param('authprovider', PARAM_ALPHANUMEXT);
require_once $CFG->dirroot . '/auth/googleoauth2/classes/provider/' . $authprovider . '.php';
$providerclassname = 'provideroauth2' . $authprovider;
$provider = new $providerclassname();
// Try to get an access token (using the authorization code grant).
$token = $provider->getAccessToken('authorization_code', ['code' => $authorizationcode]);
$accesstoken = $token->accessToken;
$refreshtoken = $token->refreshToken;
$tokenexpires = $token->expires;
// With access token request by curl the email address.
if (!empty($accesstoken)) {
try {
// We got an access token, let's now get the user's details.
$userdetails = $provider->getUserDetails($token);
// Use these details to create a new profile.
switch ($authprovider) {
case 'battlenet':
// Battlenet as no email notion.
// TODO: need to check the idp table for matching user and request user to add his email.
// TODO: It will be similar logic for twitter.
$useremail = $userdetails->id . '@fakebattle.net';
break;
case 'github':
$useremails = $provider->getUserEmails($token);
// Going to try to find someone with a similar email using googleoauth2 auth.
$fallbackuseremail = '';
foreach ($useremails as $githubuseremail) {
if ($githubuseremail->verified) {
if ($DB->record_exists('user', array('auth' => 'googleoauth2', 'email' => $githubuseremail->email))) {
$useremail = $githubuseremail->email;
}
$fallbackuseremail = $githubuseremail->email;
}
}
// If we didn't find anyone then we take a verified email address.
if (empty($useremail)) {
$useremail = $fallbackuseremail;
}
break;
case 'vk':
// VK doesn't return the email address?
if ($userdetails->uid) {
$useremail = 'id' . $userdetails->uid . '@vkmessenger.com';
}
break;
default:
$useremail = $userdetails->email;
break;
}
$verified = 1;
} catch (Exception $e) {
// Failed to get user details.
throw new moodle_exception('faileduserdetails', 'auth_googleoauth2');
}
// Throw an error if the email address is not verified.
if (!$verified) {
throw new moodle_exception('emailaddressmustbeverified', 'auth_googleoauth2');
}
// Prohibit login if email belongs to the prohibited domain.
if ($err = email_is_not_allowed($useremail)) {
throw new moodle_exception($err, 'auth_googleoauth2');
}
// If email not existing in user database then create a new username (userX).
if (empty($useremail) or $useremail != clean_param($useremail, PARAM_EMAIL)) {
throw new moodle_exception('couldnotgetuseremail', 'auth_googleoauth2');
// TODO: display a link for people to retry.
}
// Get the user.
// Don't bother with auth = googleoauth2 because authenticate_user_login() will fail it if it's not 'googleoauth2'.
$user = $DB->get_record('user', array('email' => $useremail, 'deleted' => 0, 'mnethostid' => $CFG->mnet_localhost_id));
// Create the user if it doesn't exist.
if (empty($user)) {
// Deny login if setting "Prevent account creation when authenticating" is on.
if ($CFG->authpreventaccountcreation) {
throw new moodle_exception("noaccountyet", "auth_googleoauth2");
}
// Get following incremented username.
$googleuserprefix = core_text::strtolower(get_config('auth/googleoauth2', 'googleuserprefix'));
$lastusernumber = get_config('auth/googleoauth2', 'lastusernumber');
$lastusernumber = empty($lastusernumber) ? 1 : $lastusernumber + 1;
// Check the user doesn't exist.
$nextuser = $DB->record_exists('user', array('username' => $googleuserprefix . $lastusernumber));
while ($nextuser) {
$lastusernumber++;
$nextuser = $DB->record_exists('user', array('username' => $googleuserprefix . $lastusernumber));
}
set_config('lastusernumber', $lastusernumber, 'auth/googleoauth2');
$username = $googleuserprefix . $lastusernumber;
// Retrieve more information from the provider.
$newuser = new stdClass();
//.........这里部分代码省略.........
示例14: dirname
* A Moodle block for creating Configurable Reports
* @package blocks
* @author: Juan leyva <http://www.twitter.com/jleyvadelgado>
* @date: 2009
*/
define('AJAX_SCRIPT', true);
require dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once $CFG->libdir . '/filelib.php';
$action = required_param('action', PARAM_ALPHA);
if (!($userandrepo = get_config('block_configurable_reports', 'crrepository'))) {
echo json_encode(array());
die;
}
$c = new curl();
if ($action == 'listreports') {
if ($res = $c->get("https://api.github.com/repos/{$userandrepo}/contents/")) {
$data = json_decode($res);
if (!is_array($data)) {
echo json_encode(array());
die;
}
foreach ($data as $key => $d) {
if ($d->type != 'dir') {
unset($data[$key]);
}
}
echo json_encode($data);
die;
}
} else {
if ($action == 'listcategory') {
示例15: bigbluebuttonbn_wrap_simplexml_load_file
function bigbluebuttonbn_wrap_simplexml_load_file($url)
{
if (extension_loaded('curl')) {
$c = new curl();
$c->setopt(array("SSL_VERIFYPEER" => true));
$response = $c->get($url);
if ($response) {
$previous = libxml_use_internal_errors(true);
try {
$xml = new SimpleXMLElement($response, LIBXML_NOCDATA);
return $xml;
} catch (Exception $e) {
libxml_use_internal_errors($previous);
error_log("The XML response is not correct on wrap_simplexml_load_file: " . $e->getMessage());
return NULL;
}
} else {
error_log("No response on wrap_simplexml_load_file");
return NULL;
}
} else {
$previous = libxml_use_internal_errors(true);
try {
$xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
return $xml;
} catch (Exception $e) {
libxml_use_internal_errors($previous);
return NULL;
}
}
}