本文整理汇总了PHP中DokuHTTPClient类的典型用法代码示例。如果您正苦于以下问题:PHP DokuHTTPClient类的具体用法?PHP DokuHTTPClient怎么用?PHP DokuHTTPClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DokuHTTPClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkUpdateMessages
/**
* Check for new messages from upstream
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function checkUpdateMessages()
{
global $conf;
global $INFO;
if (!$conf['updatecheck']) {
return;
}
if ($conf['useacl'] && $INFO['perm'] < AUTH_ADMIN) {
return;
}
$cf = $conf['cachedir'] . '/messages.txt';
$lm = @filemtime($cf);
// check if new messages needs to be fetched
if ($lm < time() - 60 * 60 * 24 || $lm < @filemtime(DOKU_CONF . 'msg')) {
$num = @file(DOKU_CONF . 'msg');
$num = is_array($num) ? (int) $num[0] : 0;
$http = new DokuHTTPClient();
$http->timeout = 8;
$data = $http->get(DOKU_MESSAGEURL . $num);
io_saveFile($cf, $data);
} else {
$data = io_readFile($cf);
}
// show messages through the usual message mechanism
$msgs = explode("\n%\n", $data);
foreach ($msgs as $msg) {
if ($msg) {
msg($msg, 2);
}
}
}
示例2: ping
/**
* @param $sourceUri
* @param $targetUri
* @return IXR_Error
*/
function ping($sourceUri, $targetUri)
{
global $ID;
$ID = substr($_SERVER['PATH_INFO'], 1);
if (is_null($this->tools) || !$this->tools->linkbackAllowed()) {
return new IXR_Error(PINGBACK_ERROR_TARGETURI_CANNOT_BE_USED, '');
}
// Given URLs are no urls? Quit
if (!preg_match("#^([a-z0-9\\-\\.+]+?)://.*#i", $sourceUri)) {
return new IXR_Error(PINGBACK_ERROR_GENERIC, '');
}
if (!preg_match("#^([a-z0-9\\-\\.+]+?)://.*#i", $targetUri)) {
return new IXR_Error(PINGBACK_ERROR_GENERIC, '');
}
// Source URL does not exist? Quit
$http = new DokuHTTPClient();
$page = $http->get($sourceUri);
if ($page === false) {
return new IXR_Error(PINGBACK_ERROR_SOURCEURI_DOES_NOT_EXIST, '');
}
// Target URL does not match with request? Quit
if ($targetUri != wl($ID, '', true)) {
return new IXR_Error(PINGBACK_ERROR_GENERIC, '');
}
// Retrieve data from source
$linkback = $this->_getTrackbackData($sourceUri, $targetUri, $page);
// Source URL does not contain link to target? Quit
if (!$linkback) {
return new IXR_Error(PINGBACK_ERROR_SOURCEURI_DOES_NOT_CONTAIN_LINK, '');
}
if (!$this->tools->saveLinkback('pingback', $linkback['title'], $sourceUri, $linkback['excerpt'], $ID)) {
return new IXR_Error(PINGBACK_ERROR_PINGBACK_ALREADY_MADE, '');
}
}
示例3: _process
/**
* Process trackback request.
*/
function _process()
{
// get ID
global $ID;
$ID = substr($_SERVER['PATH_INFO'], 1);
$sourceUri = $_REQUEST['url'];
if (is_null($this->tools) || !$this->tools->linkbackAllowed()) {
$this->_printTrackbackError('Trackbacks disabled.');
return;
}
// No POST request? Quit
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->_printTrackbackError('Trackback was not received via HTTP POST.');
return;
}
// Given URL is not an url? Quit
if (!preg_match("#^([a-z0-9\\-\\.+]+?)://.*#i", $sourceUri)) {
$this->_printTrackbackError('Given trackback URL is not an URL.');
return;
}
// Source does not exist? Quit
$http = new DokuHTTPClient();
$page = $http->get($sourceUri);
if ($page === false) {
$this->_printTrackbackError('Linked page cannot be reached');
return;
}
if (!$this->tools->saveLinkback('trackback', strip_tags($_REQUEST['title']), $sourceUri, strip_tags($_REQUEST['excerpt']), $ID)) {
$this->_printTrackbackError('Trackback already received.');
return;
}
$this->_printTrackbackSuccess();
}
示例4: checkUpdateMessages
/**
* Check for new messages from upstream
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function checkUpdateMessages()
{
global $conf;
global $INFO;
global $updateVersion;
if (!$conf['updatecheck']) {
return;
}
if ($conf['useacl'] && !$INFO['ismanager']) {
return;
}
$cf = $conf['cachedir'] . '/messages.txt';
$lm = @filemtime($cf);
// check if new messages needs to be fetched
if ($lm < time() - 60 * 60 * 24 || $lm < @filemtime(DOKU_INC . DOKU_SCRIPT)) {
@touch($cf);
dbglog("checkUpdatesMessages(): downloading messages.txt");
$http = new DokuHTTPClient();
$http->timeout = 12;
$data = $http->get(DOKU_MESSAGEURL . $updateVersion);
io_saveFile($cf, $data);
} else {
dbglog("checkUpdatesMessages(): messages.txt up to date");
$data = io_readFile($cf);
}
// show messages through the usual message mechanism
$msgs = explode("\n%\n", $data);
foreach ($msgs as $msg) {
if ($msg) {
msg($msg, 2);
}
}
}
示例5: get_language_data
private function get_language_data()
{
/* @var $cache door43Cache */
$cache = $this->getCache();
$cacheFile = 'langnames.json';
$langs = $cache->getObject($cacheFile, true);
// download from api.unfoldingWord.org if needed
if (empty($langs)) {
$http = new DokuHTTPClient();
$raw = $http->get('https://td.unfoldingword.org/exports/langnames.json');
$langs = json_decode($raw, true);
$cache->saveString($cacheFile, $raw);
}
// if still empty, use the backup copy
if (empty($langs)) {
$langs = json_decode(file_get_contents(dirname(__FILE__) . '/lang/langnames.json'), true);
}
// $this->LN
// $this->translations
$ln = array();
$translations = '';
$langDir = array();
foreach ($langs as $lang) {
$ln[$lang['lc']] = $lang['ln'];
$translations .= ' ' . $lang['lc'];
$langDir[$lang['lc']] = $lang['ld'];
}
$cache->saveObject('helperLN.json', $ln);
$cache->saveObject('languageDirection.json', $langDir);
$sorted = array_unique(array_filter(explode(' ', $translations)));
sort($sorted);
$cache->saveObject('translations.json', $sorted);
}
示例6: _getRemoteData
/**
* Use DokuWiki's HTTP Clients for downloading
*
* @param string $url
* @throws Exception
* @return string
*/
protected function _getRemoteData($url)
{
$http = new DokuHTTPClient($url);
$file = $http->get($url);
if (!$file) {
throw new Exception('Your server can\'t connect to external resources. Please update the file manually.');
}
return $file;
}
示例7: getInfoByHash
public function getInfoByHash($repository_id, $commit_id)
{
$gitlabServer = $this->getConf('server');
$apiToken = $this->getConf('api_token');
$http = new DokuHTTPClient();
$reqUrl = $gitlabServer . '/api/v3/projects/' . $repository_id . '/repository/commits/' . $commit_id . '/?private_token=' . $apiToken;
$data = json_decode($http->get($reqUrl), true);
return array($data['message'], $data['id']);
}
示例8: retrieveResponse
/**
* Any implementing HTTP providers should send a request to the provided endpoint with the parameters.
* They should return, in string form, the response body and throw an exception on error.
*
* @param UriInterface $endpoint
* @param mixed $requestBody
* @param array $extraHeaders
* @param string $method
*
* @return string
*
* @throws TokenResponseException
*/
public function retrieveResponse(UriInterface $endpoint, $requestBody, array $extraHeaders = array(), $method = 'POST')
{
$http = new \DokuHTTPClient();
$http->headers = array_merge($http->headers, $extraHeaders);
$ok = $http->sendRequest($endpoint->getAbsoluteUri(), $requestBody, $method);
if (!$ok) {
throw new TokenResponseException($http->error);
}
return $http->resp_body;
}
示例9: sendData
/**
* Send the data, to the submit url
*
* @param string $data The popularity data
* @return string An empty string if everything worked fine, a string describing the error otherwise
*/
function sendData($data)
{
$error = '';
$httpClient = new DokuHTTPClient();
$status = $httpClient->sendRequest($this->submitUrl, array('data' => $data), 'POST');
if (!$status) {
$error = $httpClient->error;
}
return $error;
}
示例10: execute_request
public function execute_request()
{
global $INPUT;
// if no contentType was passed, use application/json as the default
$contentType = $INPUT->str('contentType');
if (empty($contentType)) {
$contentType = 'application/json';
}
header('Content-Type: ' . $contentType);
$http = new DokuHTTPClient();
// Get the list of source languages that are level 3.
$url = $INPUT->str('requestUrl');
echo $http->get($url);
}
示例11: _listhd
private function _listhd()
{
require_once DOKU_INC . 'inc/HTTPClient.php';
$url = 'https://xkcd.com/rss.xml';
$ch = new DokuHTTPClient();
$piece = $ch->get($url);
$xml = simplexml_load_string($piece);
$comicURL = $xml->channel->item->link;
$description = (string) $xml->channel->item->description;
$description = html_entity_decode($description, ENT_NOQUOTES);
$feed_contents = $description;
// Not used anymore because of new xml format
//$dom = new DOMDocument();
//$dom->loadXML($description);
//$imgSrc = $dom->childNodes->item(0)->attributes->getNamedItem('src' )->value;
//$imgTitle = $dom->childNodes->item(0)->attributes->getNamedItem('title' )->value;
//$feed_contents = "<a href=\"$comicURL\"><img src=\"$imgSrc\" title=\"$imgTitle\" /></a>\n";
return $feed_contents;
}
示例12: checkUpdateMessages
/**
* Check for new messages from upstream
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function checkUpdateMessages()
{
global $conf;
global $INFO;
global $updateVersion;
if (!$conf['updatecheck']) {
return;
}
if ($conf['useacl'] && !$INFO['ismanager']) {
return;
}
$cf = getCacheName($updateVersion, '.updmsg');
$lm = @filemtime($cf);
// check if new messages needs to be fetched
if ($lm < time() - 60 * 60 * 24 || $lm < @filemtime(DOKU_INC . DOKU_SCRIPT)) {
@touch($cf);
dbglog("checkUpdateMessages(): downloading messages to " . $cf);
$http = new DokuHTTPClient();
$http->timeout = 12;
$resp = $http->get(DOKU_MESSAGEURL . $updateVersion);
if (is_string($resp) && ($resp == "" || substr(trim($resp), -1) == '%')) {
// basic sanity check that this is either an empty string response (ie "no messages")
// or it looks like one of our messages, not WiFi login or other interposed response
io_saveFile($cf, $resp);
} else {
dbglog("checkUpdateMessages(): unexpected HTTP response received");
}
} else {
dbglog("checkUpdateMessages(): messages up to date");
}
$data = io_readFile($cf);
// show messages through the usual message mechanism
$msgs = explode("\n%\n", $data);
foreach ($msgs as $msg) {
if ($msg) {
msg($msg, 2);
}
}
}
示例13: pingSearchEngines
/**
* Pings search engines with the sitemap url. Plugins can add or remove
* urls to ping using the SITEMAP_PING event.
*
* @author Michael Hamann
*/
public function pingSearchEngines()
{
//ping search engines...
$http = new DokuHTTPClient();
$http->timeout = 8;
$encoded_sitemap_url = urlencode(wl('', array('do' => 'sitemap'), true, '&'));
$ping_urls = array('google' => 'http://www.google.com/webmasters/sitemaps/ping?sitemap=' . $encoded_sitemap_url, 'yahoo' => 'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=dokuwiki&url=' . $encoded_sitemap_url, 'microsoft' => 'http://www.bing.com/webmaster/ping.aspx?siteMap=' . $encoded_sitemap_url);
$data = array('ping_urls' => $ping_urls, 'encoded_sitemap_url' => $encoded_sitemap_url);
$event = new Doku_Event('SITEMAP_PING', $data);
if ($event->advise_before(true)) {
foreach ($data['ping_urls'] as $name => $url) {
dbglog("Sitemapper::PingSearchEngines(): pinging {$name}");
$resp = $http->get($url);
if ($http->error) {
dbglog("Sitemapper:pingSearchengines(): {$http->error}");
}
dbglog('Sitemapper:pingSearchengines(): ' . preg_replace('/[\\n\\r]/', ' ', strip_tags($resp)));
}
}
$event->advise_after();
return true;
}
示例14: runSitemapper
/**
* Builds a Google Sitemap of all public pages known to the indexer
*
* The map is placed in the root directory named sitemap.xml.gz - This
* file needs to be writable!
*
* @author Andreas Gohr
* @link https://www.google.com/webmasters/sitemaps/docs/en/about.html
*/
function runSitemapper()
{
global $conf;
print "runSitemapper(): started" . NL;
if (!$conf['sitemap']) {
return false;
}
if ($conf['compression'] == 'bz2' || $conf['compression'] == 'gz') {
$sitemap = 'sitemap.xml.gz';
} else {
$sitemap = 'sitemap.xml';
}
print "runSitemapper(): using {$sitemap}" . NL;
if (@file_exists(DOKU_INC . $sitemap)) {
if (!is_writable(DOKU_INC . $sitemap)) {
return false;
}
} else {
if (!is_writable(DOKU_INC)) {
return false;
}
}
if (@filesize(DOKU_INC . $sitemap) && @filemtime(DOKU_INC . $sitemap) > time() - $conf['sitemap'] * 60 * 60 * 24) {
print 'runSitemapper(): Sitemap up to date' . NL;
return false;
}
$pages = file($conf['indexdir'] . '/page.idx');
print 'runSitemapper(): creating sitemap using ' . count($pages) . ' pages' . NL;
// build the sitemap
ob_start();
print '<?xml version="1.0" encoding="UTF-8"?>' . NL;
print '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . NL;
foreach ($pages as $id) {
$id = trim($id);
$file = wikiFN($id);
//skip hidden, non existing and restricted files
if (isHiddenPage($id)) {
continue;
}
$date = @filemtime($file);
if (!$date) {
continue;
}
if (auth_aclcheck($id, '', '') < AUTH_READ) {
continue;
}
print ' <url>' . NL;
print ' <loc>' . wl($id, '', true) . '</loc>' . NL;
print ' <lastmod>' . date_iso8601($date) . '</lastmod>' . NL;
print ' </url>' . NL;
}
print '</urlset>' . NL;
$data = ob_get_contents();
ob_end_clean();
//save the new sitemap
io_saveFile(DOKU_INC . $sitemap, $data);
//ping search engines...
$http = new DokuHTTPClient();
$http->timeout = 8;
//ping google
print 'runSitemapper(): pinging google' . NL;
$url = 'http://www.google.com/webmasters/sitemaps/ping?sitemap=';
$url .= urlencode(DOKU_URL . $sitemap);
$resp = $http->get($url);
if ($http->error) {
print 'runSitemapper(): ' . $http->error . NL;
}
print 'runSitemapper(): ' . preg_replace('/[\\n\\r]/', ' ', strip_tags($resp)) . NL;
//ping yahoo
print 'runSitemapper(): pinging yahoo' . NL;
$url = 'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=dokuwiki&url=';
$url .= urlencode(DOKU_URL . $sitemap);
$resp = $http->get($url);
if ($http->error) {
print 'runSitemapper(): ' . $http->error . NL;
}
print 'runSitemapper(): ' . preg_replace('/[\\n\\r]/', ' ', strip_tags($resp)) . NL;
//ping microsoft
print 'runSitemapper(): pinging microsoft' . NL;
$url = 'http://www.bing.com/webmaster/ping.aspx?siteMap=';
$url .= urlencode(DOKU_URL . $sitemap);
$resp = $http->get($url);
if ($http->error) {
print 'runSitemapper(): ' . $http->error . NL;
}
print 'runSitemapper(): ' . preg_replace('/[\\n\\r]/', ' ', strip_tags($resp)) . NL;
print 'runSitemapper(): finished' . NL;
return true;
}
示例15: handle
//.........这里部分代码省略.........
if (preg_match('/sortprice/i', $more, $match)) {
$params['sort'] = 'Price';
} elseif (preg_match('/sortpriority/i', $more, $match)) {
$params['sort'] = 'Priority';
} elseif (preg_match('/sortadded/i', $more, $match)) {
$params['sort'] = 'DateAdded';
}
// no country given?
if (empty($asin)) {
$asin = $ctry;
$ctry = 'us';
}
// correct country given?
if (!preg_match('/^(us|uk|jp|de|fr|ca)$/', $ctry)) {
$ctry = 'us';
}
// get partner id
$partner = $this->getConf('partner_' . $ctry);
// correct domains
if ($ctry == 'us') {
$ctry = 'com';
}
if ($ctry == 'uk') {
$ctry = 'co.uk';
}
// basic API parameters
$opts = array();
$opts['Service'] = 'AWSECommerceService';
$opts['AWSAccessKeyId'] = AMAZON_APIKEY;
$opts['AssociateTag'] = $partner;
if ($type == 'product') {
// parameters for querying a single product
$opts['Operation'] = 'ItemLookup';
$opts['ResponseGroup'] = 'Medium,OfferSummary';
if (strlen($asin) < 13) {
$opts['IdType'] = 'ASIN';
$opts['ItemId'] = $asin;
} else {
$opts['SearchIndex'] = 'Books';
$opts['IdType'] = 'ISBN';
$opts['ItemId'] = $asin;
}
} else {
// parameters to query a wishlist
$opts['Operation'] = 'ListLookup';
$opts['ResponseGroup'] = 'ListItems,Medium,OfferSummary';
$opts['ListId'] = $asin;
$opts['Sort'] = $params['sort'];
$opts['IsIncludeUniversal'] = 'True';
$opts['IsOmitPurchasedItems'] = $params['purchased'] ? 'False' : 'True';
if ($type == 'wishlist') {
$opts['ListType'] = 'WishList';
} else {
$opts['ListType'] = 'Listmania';
}
}
// support paged results
$result = array();
$pages = 1;
for ($page = 1; $page <= $pages; $page++) {
$opts['ProductPage'] = $page;
// fetch it
$http = new DokuHTTPClient();
$url = $this->_signedRequestURI($ctry, $opts, $this->getConf('publickey'), $this->getConf('privatekey'));
$xml = $http->get($url);
if (empty($xml)) {
if ($http->error) {
return $http->error;
}
if ($http->status == 403) {
return 'Signature check failed, did you set your Access Keys in config?';
}
return 'unkown error';
}
// parse it
require_once dirname(__FILE__) . '/XMLParser.php';
$xmlp = new XMLParser($xml);
$data = $xmlp->getTree();
//dbg($data);
// check for errors and return the item(s)
if ($type == 'product') {
// error?
if ($data['ITEMLOOKUPRESPONSE'][0]['ITEMS'][0]['REQUEST'][0]['ERRORS']) {
return $data['ITEMLOOKUPRESPONSE'][0]['ITEMS'][0]['REQUEST'][0]['ERRORS'][0]['ERROR'][0]['MESSAGE'][0]['VALUE'];
}
// return item
$result = array_merge($result, (array) $data['ITEMLOOKUPRESPONSE'][0]['ITEMS'][0]['ITEM']);
} else {
// error?
if ($data['LISTLOOKUPRESPONSE'][0]['LISTS'][0]['REQUEST'][0]['ERRORS']) {
return $data['LISTLOOKUPRESPONSE'][0]['LISTS'][0]['REQUEST'][0]['ERRORS'][0]['ERROR'][0]['MESSAGE'][0]['VALUE'];
}
// multiple pages?
$pages = (int) $data['LISTLOOKUPRESPONSE'][0]['LISTS'][0]['LIST'][0]['TOTALPAGES'][0]['VALUE'];
// return items
$result = array_merge($result, (array) $data['LISTLOOKUPRESPONSE'][0]['LISTS'][0]['LIST'][0]['LISTITEM']);
}
}
return array($result, $params);
}