当前位置: 首页>>代码示例>>PHP>>正文


PHP Webservice::get方法代码示例

本文整理汇总了PHP中Idno\Core\Webservice::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Webservice::get方法的具体用法?PHP Webservice::get怎么用?PHP Webservice::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Idno\Core\Webservice的用法示例。


在下文中一共展示了Webservice::get方法的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/');
 }
开发者ID:sintoris,项目名称:Known,代码行数:26,代码来源:Admin.php

示例2: 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
  * @param array $response (optional) response from fetching $url
  * @return array
  */
 static function addSyndicatedReplyTargets($url, $inreplyto = array(), $response = false)
 {
     $inreplyto = (array) $inreplyto;
     if (!$response) {
         $response = \Idno\Core\Webservice::get($url);
     }
     if ($response && $response['response'] >= 200 && $response['response'] < 300) {
         if ($mf2 = self::parseContent($response['content'], $url)) {
             // first check rel-syndication
             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;
                         }
                     }
                 }
             }
             // then look for u-syndication
             if ($entry = self::findRepresentativeHEntry($mf2, $url, ['h-entry', 'h-event'])) {
                 if (!empty($entry['properties']['syndication'])) {
                     foreach ($entry['properties']['syndication'] as $syndication) {
                         if (!in_array($syndication, $inreplyto) && is_string($syndication)) {
                             $inreplyto[] = $syndication;
                         }
                     }
                 }
             }
         }
     }
     return $inreplyto;
 }
开发者ID:smartboyathome,项目名称:Known,代码行数:40,代码来源:Webmention.php

示例3: 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

示例4: 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

示例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: 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

示例7: 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

示例8: testConnection

 public function testConnection()
 {
     $user = \Tests\KnownTestCase::user();
     $result = \Idno\Core\Webservice::get(\Idno\Core\Idno::site()->config()->url . '', [], ['Accept: application/json']);
     $content = json_decode($result['content']);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue(!empty($content));
     $this->assertTrue($response == 200);
 }
开发者ID:smartboyathome,项目名称:Known,代码行数:10,代码来源:BasicAPITest.php

示例9: 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

示例10: 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 = array())
 {
     if (!is_array($inreplyto)) {
         $inreplyto = array($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:d6-9b,项目名称:Known,代码行数:29,代码来源:Webmention.php

示例11: 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

示例12: testAdminGatekeeper

 public function testAdminGatekeeper()
 {
     $result = \Idno\Core\Webservice::get(\Idno\Core\Idno::site()->config()->url . 'admin/', [], []);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue($response == 403);
     $user = \Tests\KnownTestCase::user();
     $this->assertTrue(is_object(\Idno\Core\Idno::site()->session()->logUserOn($user)));
     // Try normal user
     \Idno\Core\Idno::site()->session()->logUserOff();
     $result = \Idno\Core\Webservice::get(\Idno\Core\Idno::site()->config()->url . 'admin/', [], ['X-KNOWN-USERNAME: ' . $user->handle, 'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/admin/', $user->getAPIkey(), true))]);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue($response == 403);
     // Try admin
     $user = \Tests\KnownTestCase::admin();
     $this->assertTrue(is_object(\Idno\Core\Idno::site()->session()->logUserOn($user)));
     $result = \Idno\Core\Webservice::get(\Idno\Core\Idno::site()->config()->url . 'admin/', [], ['X-KNOWN-USERNAME: ' . $user->handle, 'X-KNOWN-SIGNATURE: ' . base64_encode(hash_hmac('sha256', '/admin/', $user->getAPIkey(), true))]);
     $response = $result['response'];
     $this->assertTrue(empty($result['error']));
     $this->assertTrue($response == 200);
     \Idno\Core\Idno::site()->session()->logUserOff();
 }
开发者ID:beck24,项目名称:Known,代码行数:23,代码来源:GatekeeperTest.php

示例13: checkService

 /**
  * Fetch and parse the Bridgy user page for this service,
  * update its status and return true if it has changed.
  */
 function checkService($user, $service)
 {
     if (!isset($user->bridgy) || !isset($user->bridgy[$service])) {
         return false;
     }
     $bridgy_url = $user->bridgy[$service]['user'];
     if (!empty($bridgy_url) and $resp = \Idno\Core\Webservice::get($bridgy_url)) {
         $parsed = (new \Mf2\Parser($resp['content'], $bridgy_url))->parse();
         $status = 'disabled';
         if (!empty($parsed['items'])) {
             $hcard = $parsed['items'][0];
             if (!empty($hcard['properties']['bridgy-account-status']) && $hcard['properties']['bridgy-account-status'][0] == 'enabled' && !empty($hcard['properties']['bridgy-listen-status']) && $hcard['properties']['bridgy-listen-status'][0] == 'enabled') {
                 $status = 'enabled';
             }
         }
         if ($user->bridgy[$service]['status'] != $status) {
             $user->bridgy[$service]['status'] = $status;
             $user->save();
             return true;
         }
         return false;
     }
 }
开发者ID:hank,项目名称:Known,代码行数:27,代码来源:Check.php

示例14: getFeedDetails

 /**
  * Given the URL of a website, returns a single linked array containing the URL and title of a feed
  * (whether Microformats or RSS / Atom). The function will attempt to discover RSS and Atom feeds in
  * the page if this is an HTML site. Returns false if there is no feed.
  * @param $url
  * @return array|false
  */
 function getFeedDetails($url)
 {
     if (!filter_var($url, FILTER_VALIDATE_URL)) {
         return false;
     }
     $client = new Webservice();
     if ($result = $client->get($url)) {
         $feed = array();
         if (!empty($result['content'])) {
             $feed['webmention'] = Webmention::supportsMentions($url, $result['content']);
             if ($html = @\DOMDocument::loadHTML($result['content'])) {
                 $xpath = new \DOMXpath($html);
                 $title = $xpath->query('//title')->item(0)->nodeValue;
                 if ($xpath->query("//*[contains(concat(' ', @class, ' '), ' h-entry ')]")->length > 0) {
                     $feed['type'] = 'mf2';
                     $feed['url'] = $url;
                     if (!empty($title)) {
                         $feed['title'] = $title;
                     }
                     return $feed;
                 }
                 if ($rss_url = $this->findXMLFeedURL($html)) {
                     $feed['type'] = 'xml';
                     $feed['url'] = $rss_url;
                     if (!empty($title)) {
                         $feed['title'] = $title;
                     }
                     return $feed;
                 }
             }
             if ($xml = @simplexml_load_string($result['content'])) {
                 if (!empty($xml->rss->channel->item) || !empty($xml->feed) || !empty($xml->channel->item)) {
                     $feed['type'] = 'xml';
                     $feed['url'] = $url;
                     if (!empty($xml->rss->channel->title)) {
                         $feed['title'] = $xml->rss->channel->title;
                     } else {
                         if (!empty($xml->channel->title)) {
                             $feed['title'] = $xml->channel->title;
                         } else {
                             if (!empty($xml->title)) {
                                 $feed['title'] = $xml->title;
                             }
                         }
                     }
                     return $feed;
                 }
             }
         }
     }
     return false;
 }
开发者ID:sintoris,项目名称:Known,代码行数:59,代码来源:Reader.php

示例15: post

 function post()
 {
     parse_str(trim(file_get_contents("php://input")), $vars);
     // Check that both source and target are non-empty
     if (!empty($vars['source']) && !empty($vars['target']) && $vars['source'] != $vars['target']) {
         $source = $vars['source'];
         $target = $vars['target'];
         // Remove anchors from target URL, but save them to '#' input so we can still reference them later
         if (strpos($target, '#')) {
             list($target, $fragment) = explode('#', $target, 2);
             if (!empty($fragment)) {
                 $this->setInput('#', $fragment);
             }
         }
         // Get the page handler for target
         if ($page = \Idno\Core\Idno::site()->getPageHandler($target)) {
             // First of all, make sure the target page isn't the source page. Let's not webmention ourselves!
             $webmention_ok = true;
             if (\Idno\Common\Entity::isLocalUUID($source)) {
                 if ($source_page = \Idno\Core\Idno::site()->getPageHandler($source)) {
                     if ($source_page == $page) {
                         $webmention_ok = false;
                     }
                 }
             }
             // Check that source exists, parse it for mf2 content,
             // and ensure that it genuinely mentions this page
             if ($webmention_ok) {
                 if ($source_content = \Idno\Core\Webservice::get($source)) {
                     if (substr_count($source_content['content'], $target) || $source_content['response'] == 410) {
                         $source_mf2 = \Idno\Core\Webmention::parseContent($source_content['content'], $source);
                         // Set source and target information as input variables
                         $page->setPermalink();
                         if ($page->webmentionContent($source, $target, $source_content, $source_mf2)) {
                             $this->setResponse(202);
                             // Webmention received a-ok.
                             exit;
                         } else {
                             $error = 'target_not_supported';
                             $error_text = 'This is not webmentionable.';
                         }
                     } else {
                         $error = 'no_link_found';
                         $error_text = 'The source URI does not contain a link to the target URI.';
                         \Idno\Core\Idno::site()->logging->warning('No link from ' . $source . ' to ' . $target);
                     }
                 } else {
                     $error = 'source_not_found';
                     $error_text = 'The source content for ' . $source . ' could not be obtained.';
                     \Idno\Core\Idno::site()->logging->warning('No content from ' . $source);
                 }
             } else {
                 $error = 'target_not_supported';
                 $error_text = 'A page can\'t webmention itself.';
             }
         } else {
             $error = 'target_not_found';
             $error_text = 'The target page ' . $target . ' does not exist.';
             \Idno\Core\Idno::site()->logging()->error('Could not find handler for ' . $target);
         }
     }
     $this->setResponse(400);
     // Webmention failed.
     if (empty($error)) {
         $error = 'unknown_error';
         $error_text = 'Not all the required webmention variables were set.';
     }
     echo json_encode(array('error' => $error, 'error_text' => $error_text));
 }
开发者ID:knownunknowns,项目名称:Known,代码行数:69,代码来源:Endpoint.php


注:本文中的Idno\Core\Webservice::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。