本文整理汇总了PHP中Idno\Core\Webservice类的典型用法代码示例。如果您正苦于以下问题:PHP Webservice类的具体用法?PHP Webservice怎么用?PHP Webservice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Webservice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: postContent
function postContent()
{
$this->adminGatekeeper();
$request = $this->getInput('request');
$key = $this->getInput('key');
$username = $this->getInput('username');
$json = $this->getInput('json');
$follow_redirects = $this->getInput('follow_redirects');
$method = $this->getInput('method', 'GET');
$url = \Idno\Core\Idno::site()->config()->getURL();
if (strripos($url, '/') == strlen($url) - 1) {
$url = substr($url, 0, strlen($url) - 1);
}
$url .= $request;
$client = new Webservice();
if ($method == 'POST') {
$result = $client->post($url, $json, array('X-KNOWN-USERNAME: ' . $username, 'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', $request, $key, true))));
} else {
$result = $client->get($url, null, array('X-KNOWN-USERNAME: ' . $username, 'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', $request, $key, true))));
}
$response = Webservice::getLastResponse();
$sent_request = Webservice::getLastRequest() . $json;
$api_request = array('request' => $request, 'key' => $key, 'username' => $username, 'json' => $json, 'sent_request' => $sent_request, 'response' => gzencode($response, 9), 'method' => $method);
\Idno\Core\Idno::site()->session()->set('api_request', $api_request);
$this->forward(\Idno\Core\Idno::site()->config()->getURL() . 'admin/apitester/');
}
开发者ID:sintoris,项目名称:Known,代码行数:26,代码来源:Admin.php
示例2: retrieveItems
/**
* Get parsed items from this feed
* @return array|bool
*/
function retrieveItems()
{
$ws = new Webservice();
if ($content = $ws->get($this->getFeedURL())) {
return \Idno\Core\site()->reader()->parseFeed($content['content'], $this->getFeedURL());
}
return false;
}
开发者ID:hank,项目名称:Known,代码行数:12,代码来源:Feed.php
示例3: postContent
function postContent()
{
$this->createGatekeeper();
// Logged-in only please
$email = $this->getInput('email');
$message = $this->getInput('message');
if (!empty($email) && !empty($message)) {
$web_client = new Webservice();
$results = $web_client->post('http://withknown.com/vendor-services/feedback/', ['url' => \Idno\Core\site()->config()->getURL(), 'title' => \Idno\Core\site()->config()->getTitle(), 'version' => \Idno\Core\site()->getVersion(), 'public' => \Idno\Core\site()->config()->isPublicSite(), 'hub' => \Idno\Core\site()->config()->known_hub, 'email' => $email, 'message' => $message]);
\Idno\Core\site()->session()->addMessage("Thanks! We received your feedback.");
}
$this->forward(\Idno\Core\site()->config()->getURL() . 'account/settings/feedback/confirm/');
}
开发者ID:avewrigley,项目名称:idno,代码行数:13,代码来源:Feedback.php
示例4: publish
/**
* If this idno installation has a PubSubHubbub hub, send a publish notification to the hub
* @param string $url
* @return array
*/
static function publish($url)
{
if ($hub = \Idno\Core\site()->config()->hub) {
return \Idno\Core\Webservice::post($hub, ['hub.mode' => 'publish', 'hub.url' => $url]);
}
return false;
}
开发者ID:phpsource,项目名称:idno,代码行数:12,代码来源:PubSubHubbub.php
示例5: retrieveItems
/**
* Get parsed items from this feed
* @return array|bool
*/
function retrieveItems()
{
if ($content = Webservice::get($this->getFeedURL())) {
return \Idno\Core\Idno::site()->reader()->parseFeed($content['content'], $this->getFeedURL());
}
return false;
}
开发者ID:smartboyathome,项目名称:Known,代码行数:11,代码来源:Feed.php
示例6: registerEventHooks
function registerEventHooks()
{
\Idno\Core\site()->events()->addListener('syndicate', function (\Idno\Core\Event $event) {
$eventdata = $event->data();
if (!empty($eventdata['object'])) {
if (!empty(site()->config()->wayback_machine)) {
if ($eventdata['object'] instanceof Entity) {
if ($eventdata['object']->isPublic()) {
Webservice::get('https://web.archive.org/save/' . $eventdata['object']->getDisplayURL());
}
}
}
$content_type = $eventdata['object']->getActivityStreamsObjectType();
if ($services = \Idno\Core\site()->syndication()->getServices($content_type)) {
if ($selected_services = \Idno\Core\site()->currentPage()->getInput('syndication')) {
if (!empty($selected_services) && is_array($selected_services)) {
foreach ($selected_services as $selected_service) {
$event->data()['syndication_account'] = false;
if (in_array($selected_service, $services)) {
site()->triggerEvent('post/' . $content_type . '/' . $selected_service, $eventdata);
} else {
if ($implied_service = $this->getServiceByAccountString($selected_service)) {
$eventdata['syndication_account'] = $this->getAccountFromAccountString($selected_service);
site()->triggerEvent('post/' . $content_type . '/' . $implied_service, $eventdata);
}
}
}
}
}
}
}
});
}
开发者ID:johnellison,项目名称:90days,代码行数:33,代码来源:Syndication.php
示例7: getContent
function getContent()
{
$this->createGatekeeper();
$user = \Idno\Core\site()->session()->currentUser();
$u = $this->getInput('u');
if ($content = \Idno\Core\Webservice::get($u)['content']) {
$parser = new \Mf2\Parser($content, $u);
if ($return = $parser->parse()) {
if (isset($return['items'])) {
$t = \Idno\Core\site()->template();
$body = '';
$hcard = [];
$this->findHcard($return['items'], $hcard);
$hcard = $this->removeDuplicateProfiles($hcard);
if (!count($hcard)) {
throw new \Exception("Sorry, could not find any users on that page, perhaps they need to mark up their profile in <a href=\"http://microformats.org/wiki/microformats-2\">Microformats</a>?");
}
// TODO: Add a manual way to add the user
foreach ($hcard as $card) {
$body .= $t->__(['mf2' => $card])->draw('account/settings/following/mf2user');
}
// List user
$t->body = $body;
$t->title = 'Found users';
$t->drawPage();
}
} else {
throw new \Exception("Sorry, there was a problem parsing the page!");
}
} else {
throw new \Exception("Sorry, {$u} could not be retrieved!");
}
// forward back
$this->forward($_SERVER['HTTP_REFERER']);
}
开发者ID:avewrigley,项目名称:idno,代码行数:35,代码来源:Bookmarklet.php
示例8: postContent
function postContent()
{
$body = strip_tags($this->getInput('body'));
$name = strip_tags($this->getInput('name'));
$url = trim($this->getInput('url'));
$url2 = trim($this->getInput('url-2'));
$validator = $this->getInput('validator');
if (!empty($url2)) {
$this->deniedContent();
}
$this->referrerGatekeeper();
if (!empty($body) && !empty($name) && !empty($validator)) {
if ($object = Entity::getByUUID($validator)) {
if ($url = Webservice::sanitizeURL($url)) {
if ($content = Webservice::get($url)) {
if ($content['response'] == '200') {
$icon = Webmention::getIconFromWebsiteContent($content['content'], $url);
}
}
}
if (empty($icon)) {
$bn = hexdec(substr(md5($url), 0, 15));
$number = 1 + $bn % 5;
$icon = \Idno\Core\site()->config()->url . 'gfx/users/default-' . str_pad($number, 2, '0', STR_PAD_LEFT) . '.png';
}
$object->addAnnotation('reply', $name, $url, $icon, $body);
$this->forward($object->getDisplayURL());
}
}
}
开发者ID:emory,项目名称:Known,代码行数:30,代码来源:Post.php
示例9: getTitleFromURL
/**
* Given a URL, returns the page title.
* @param $Url
* @return mixed
*/
function getTitleFromURL($Url)
{
$str = \Idno\Core\Webservice::file_get_contents($Url);
if (strlen($str) > 0) {
preg_match("/\\<title\\>(.*)\\<\\/title\\>/siu", $str, $title);
return htmlspecialchars_decode($title[1]);
}
return '';
}
开发者ID:johnellison,项目名称:90days,代码行数:14,代码来源:Like.php
示例10: registerEventHooks
function registerEventHooks()
{
\Idno\Core\site()->syndication()->registerService('webhooks', function () {
return $this->hasWebhooks();
}, array('note', 'bookmark', 'event', 'article'));
if ($this->hasWebhooks()) {
if (!empty(\Idno\Core\site()->config()->webhook_syndication)) {
foreach (\Idno\Core\site()->config()->webhook_syndication as $hook) {
\Idno\Core\site()->syndication()->registerServiceAccount('webhooks', $hook['url'], $hook['title']);
}
}
if (\Idno\Core\site()->session()->isLoggedIn()) {
if (!empty(\Idno\Core\site()->session()->currentUser()->webhook_syndication)) {
foreach (\Idno\Core\site()->session()->currentUser()->webhook_syndication as $hook) {
\Idno\Core\site()->syndication()->registerServiceAccount('webhooks', $hook['url'], $hook['title']);
}
}
}
}
$hook_function = function (\Idno\Core\Event $event) {
$eventdata = $event->data();
if ($this->hasWebhooks()) {
$object = $eventdata['object'];
if (!empty($object) && $object instanceof Entity && !empty($eventdata['syndication_account'])) {
$payload = array();
$hook_url = $eventdata['syndication_account'];
if ($owner = $object->getOwner()) {
$payload['icon_url'] = $owner->getIcon();
$payload['username'] = $owner->getHandle();
}
$payload['content_type'] = $object->getActivityStreamsObjectType();
$payload['text'] = $object->getTitle() . ' <' . $object->getURL() . '>';
$payload['title'] = $object->getTitle();
$client = new Webservice();
$client->post($hook_url, json_encode($payload));
}
}
};
\Idno\Core\site()->addEventHook('post/note/webhooks', $hook_function);
\Idno\Core\site()->addEventHook('post/article/webhooks', $hook_function);
\Idno\Core\site()->addEventHook('post/bookmark/webhooks', $hook_function);
\Idno\Core\site()->addEventHook('post/event/webhooks', $hook_function);
}
开发者ID:hank,项目名称:Known,代码行数:43,代码来源:Main.php
示例11: getTitleFromURL
/**
* Given a URL, returns the page title.
* @param $Url
* @return mixed
*/
function getTitleFromURL($Url)
{
$str = \Idno\Core\Webservice::file_get_contents($Url);
//@file_get_contents($Url);
if (strlen($str) > 0) {
preg_match("/\\<title\\>(.*)\\<\\/title\\>/i", $str, $title);
return $title[1];
}
return '';
}
开发者ID:avewrigley,项目名称:idno,代码行数:15,代码来源:Like.php
示例12: parseTitle
function parseTitle($url)
{
$response = Webservice::get($url);
if ($response['response'] == 200) {
$doc = \DOMDocument::loadHTML($response['content']);
foreach ($doc->getElementsByTagName('title') as $title) {
return trim($title->textContent);
}
}
return false;
}
开发者ID:kylewm,项目名称:KnownIndieSyndicate,代码行数:11,代码来源:Add.php
示例13: getAccessToken
public function getAccessToken($endpointUrl, $grant_type = 'authorization_code', array $parameters)
{
if ($parameters['state'] != \Idno\Core\site()->plugins()->get('AppNet')->getState()) {
throw new \Exception('State value not correct, possible CSRF attempt.');
}
unset($parameters['state']);
$parameters['client_id'] = $this->key;
$parameters['client_secret'] = $this->secret;
$parameters['grant_type'] = $grant_type;
return \Idno\Core\Webservice::post(\IdnoPlugins\AppNet\Main::$TOKEN_ENDPOINT, $parameters);
}
开发者ID:pierreozoux,项目名称:KnownAppNet,代码行数:11,代码来源:Client.php
示例14: testAuthenticated
public function testAuthenticated()
{
$user = \Tests\KnownTestCase::user();
$result = \Idno\Core\Webservice::post(\Idno\Core\Idno::site()->config()->url . 'status/edit', ['body' => "Making a nice test post via the api"], ['Accept: application/json', 'X-KNOWN-USERNAME: ' . $user->handle, 'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/status/edit', $user->getAPIkey(), true))]);
print_r($result);
$content = json_decode($result['content']);
$response = $result['response'];
$this->assertTrue(empty($result['error']));
$this->assertTrue(!empty($content));
$this->assertTrue(!empty($content->location));
$this->assertTrue($response == 200);
}
开发者ID:smartboyathome,项目名称:Known,代码行数:12,代码来源:BasicAPITest.php
示例15: testUpload
public function testUpload()
{
$user = \Tests\KnownTestCase::user();
$result = \Idno\Core\Webservice::post(\Idno\Core\Idno::site()->config()->url . 'photo/edit', ['title' => 'A Photo upload', 'body' => "Uploading a pretty picture via the api", 'photo' => \Idno\Core\WebserviceFile::createFromCurlString("@" . dirname(__FILE__) . "/" . self::$file . ";filename=Photo.jpg;type=image/jpeg")], ['Accept: application/json', 'X-KNOWN-USERNAME: ' . $user->handle, 'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/photo/edit', $user->getAPIkey(), true))]);
print_r($result);
$content = json_decode($result['content']);
$response = $result['response'];
$this->assertTrue(empty($result['error']));
$this->assertTrue(!empty($content));
$this->assertTrue(!empty($content->location));
$this->assertTrue($response == 200);
}
开发者ID:smartboyathome,项目名称:Known,代码行数:12,代码来源:UploadTest.php
示例16: getAccessToken
public function getAccessToken($endpointUrl, $grant_type = 'authorization_code', array $parameters)
{
if ($parameters['state'] != \Idno\Core\site()->plugins()->get('LinkedIn')->getState()) {
throw new \Exception('State value not correct, possible CSRF attempt.');
}
unset($parameters['state']);
$parameters['client_id'] = $this->key;
$parameters['client_secret'] = $this->secret;
$parameters['grant_type'] = $grant_type;
/**
* Note from the original OAuth 2 library:
*
* Passing an array to CURLOPT_POSTFIELDS will encode the data as multipart/form-data,
* while passing a URL-encoded string will encode the data as application/x-www-form-urlencoded.
* http://php.net/manual/en/function.curl-setopt.php
*
* ... Linked in API will only accept the latter at this stage.
*/
$result = \Idno\Core\Webservice::post(\IdnoPlugins\LinkedIn\Main::$TOKEN_ENDPOINT, http_build_query($parameters, null, '&'));
return json_decode($result['content']);
}
开发者ID:kylewm,项目名称:KnownLinkedin,代码行数:21,代码来源:Client.php
示例17: addSyndicatedReplyTargets
/**
* Given an array of URLs (or an empty array) and a target URL to check,
* adds and rel="syndication" URLs in the target to the array
* @param $url
* @param array $inreplyto
* @return array
*/
static function addSyndicatedReplyTargets($url, $inreplyto = [])
{
if (!is_array($inreplyto)) {
$inreplyto = [$inreplyto];
}
if ($content = \Idno\Core\Webservice::get($url)) {
if ($mf2 = self::parseContent($content['content'], $url)) {
$mf2 = (array) $mf2;
$mf2['rels'] = (array) $mf2['rels'];
if (!empty($mf2['rels']['syndication'])) {
if (is_array($mf2['rels']['syndication'])) {
foreach ($mf2['rels']['syndication'] as $syndication) {
if (!in_array($syndication, $inreplyto) && !empty($syndication)) {
$inreplyto[] = $syndication;
}
}
}
}
}
}
return $inreplyto;
}
开发者ID:avewrigley,项目名称:idno,代码行数:29,代码来源:Webmention.php
示例18: post
function post()
{
// Get parameters
$code = $this->getInput('code');
$me = $this->getInput('me');
$redirect_uri = $this->getInput('redirect_uri');
$state = $this->getInput('state');
$client_id = $this->getInput('client_id');
// Verify code
$response = Webservice::post('https://indieauth.com/auth', array('me' => $me, 'code' => $code, 'redirect_uri' => $redirect_uri, 'state' => $state, 'client_id' => $client_id));
if ($response['response'] == 200) {
parse_str($response['content'], $content);
if (!empty($content['me']) && (parse_url($content['me'], PHP_URL_HOST) == parse_url(\Idno\Core\site()->config()->getURL(), PHP_URL_HOST) || 'www.' . parse_url($content['me'], PHP_URL_HOST) == parse_url(\Idno\Core\site()->config()->getURL(), PHP_URL_HOST))) {
// Get user & existing tokens
$user = \Idno\Entities\User::getOne(array('admin' => true));
$indieauth_tokens = $user->indieauth_tokens;
if (empty($indieauth_tokens)) {
$indieauth_tokens = array();
}
// Generate access token and save it to the user
$token = md5(rand(0, 99999) . time() . $user->getUUID() . $client_id . $state . rand(0, 999999));
$indieauth_tokens[$token] = array('me' => $me, 'redirect_uri' => $redirect_uri, 'scope' => 'post', 'client_id' => $client_id, 'issued_at' => time(), 'nonce' => mt_rand(1000000, pow(2, 30)));
$user->indieauth_tokens = $indieauth_tokens;
$user->save();
if (\Idno\Core\site()->session()->isLoggedOn() && $user->getUUID() == \Idno\Core\site()->session()->currentUser()->getUUID()) {
\Idno\Core\site()->session()->refreshSessionUser($user);
}
// Output to the browser
$this->setResponse(200);
header('Content-Type: application/x-www-form-urlencoded');
echo http_build_query(array('access_token' => $token, 'scope' => 'post', 'me' => $me));
exit;
} else {
$this->setResponse(404);
echo "Client mismatch.";
}
}
}
开发者ID:hank,项目名称:Known,代码行数:38,代码来源:Token.php
示例19: getContent
function getContent()
{
$this->createGatekeeper();
$user = \Idno\Core\site()->session()->currentUser();
$u = $this->getInput('u');
if ($content = \Idno\Core\Webservice::get($u)['content']) {
$parser = new \Mf2\Parser($content, $u);
if ($return = $parser->parse()) {
if (isset($return['items'])) {
$t = \Idno\Core\site()->template();
$body = '';
$hcard = array();
$this->findHcard($return['items'], $hcard);
$hcard = $this->removeDuplicateProfiles($hcard);
if (!count($hcard)) {
//throw new \Exception("Sorry, could not find any users on that page, perhaps they need to mark up their profile in <a href=\"http://microformats.org/wiki/microformats-2\">Microformats</a>?"); // TODO: Add a manual way to add the user
// No entry could be found, so lets fake one and allow manual entry
$hcard[] = ['properties' => ['name' => [$this->findPageTitle($content)], 'photo' => [], 'email' => [], 'nickname' => [], 'url' => [$u]]];
// Display a warning
\Idno\Core\site()->session()->addErrorMessage('Page did not contain any <a href=\\"http://microformats.org/wiki/microformats-2\\">Microformats</a> markup... doing my best with what I have!');
}
foreach ($hcard as $card) {
$body .= $t->__(array('mf2' => $card))->draw('account/settings/following/mf2user');
}
// List user
$t->body = $body;
$t->title = 'Found users';
$t->drawPage();
}
} else {
throw new \Exception("Sorry, there was a problem parsing the page!");
}
} else {
throw new \Exception("Sorry, {$u} could not be retrieved!");
}
// forward back
$this->forward($_SERVER['HTTP_REFERER']);
}
开发者ID:hank,项目名称:Known,代码行数:38,代码来源:Bookmarklet.php
示例20: getContent
function getContent()
{
$user = \Idno\Entities\User::getOne(array('admin' => true));
// This is for single user sites; will retrieve the main user
$code = $this->getInput('code');
if (!empty($code)) {
$client = new Webservice();
$response = Webservice::post('http://indieauth.com/auth', array('code' => $code, 'redirect_uri' => \Idno\Core\Idno::site()->config()->getURL(), 'client_id' => \Idno\Core\Idno::site()->config()->getURL()));
if ($response['response'] == 200) {
parse_str($response['content'], $content);
if (!empty($content['me']) && parse_url($content['me'], PHP_URL_HOST) == parse_url(\Idno\Core\Idno::site()->config()->getURL, PHP_URL_HOST)) {
$user = \Idno\Core\Idno::site()->session()->currentUser();
$user->indieauth_code = $code;
$user->save();
\Idno\Core\Idno::site()->session()->logUserOn($user);
} else {
\Idno\Core\Idno::site()->session()->addMessage("Couldn't log you in: the token hostname didn't match.");
}
} else {
\Idno\Core\Idno::site()->session()->addMessage("Uh oh! We got a " . $response['response'] . " response.");
}
}
}
开发者ID:sintoris,项目名称:Known,代码行数:23,代码来源:Callback.php
注:本文中的Idno\Core\Webservice类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论