本文整理汇总了PHP中Idno\Core\Webservice类的典型用法代码示例。如果您正苦于以下问题:PHP Webservice类的具体用法?PHP Webservice怎么用?PHP Webservice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Webservice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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/');
}
示例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;
}
示例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/');
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
}
}
}
});
}
示例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']);
}
示例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());
}
}
}
示例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 '';
}
示例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);
}
示例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 '';
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}