本文整理汇总了PHP中serendipity_request_end函数的典型用法代码示例。如果您正苦于以下问题:PHP serendipity_request_end函数的具体用法?PHP serendipity_request_end怎么用?PHP serendipity_request_end使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serendipity_request_end函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetXMLTree
function GetXMLTree($file)
{
require_once S9Y_PEAR_PATH . 'HTTP/Request2.php';
serendipity_request_start();
$options = array();
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
// On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1
$options['ssl_verify_peer'] = false;
}
$req = new HTTP_Request2($file, HTTP_Request2::METHOD_GET, $options);
try {
$response = $req->send();
if ($response->getStatus() != '200') {
throw new HTTP_Request2_Exception('Status code not 200, xml file not fetched');
}
$data = $response->getBody();
} catch (HTTP_Request2_Exception $e) {
$data = file_get_contents($file);
}
serendipity_request_end();
// Global replacements
// by: waldo@wh-e.com - trim space around tags not within
$data = preg_replace('@>[[:space:]]+<@', '><', $data);
// Flatten the input opml file to not have nested categories
$data = preg_replace('@<outline[^>]+[^/]>@imsU', '', $data);
$data = str_replace('</outline>', '', $data);
// XML functions
$xml_string = '<?xml version="1.0" encoding="UTF-8" ?>';
if (preg_match('@(<\\?xml.+\\?>)@imsU', $data, $xml_head)) {
$xml_string = $xml_head[1];
}
$encoding = 'UTF-8';
if (preg_match('@encoding="([^"]+)"@', $xml_string, $xml_encoding)) {
$encoding = $xml_encoding[1];
}
$p = xml_parser_create($encoding);
// by: anony@mous.com - meets XML 1.0 specification
@xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($p, XML_OPTION_TARGET_ENCODING, LANG_CHARSET);
xml_parse_into_struct($p, $data, $vals, $index);
xml_parser_free($p);
$i = 0;
$tree = array();
$tree[] = array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'value' => $vals[$i]['value'], 'children' => $this->GetChildren($vals, $i));
return $tree;
}
示例2: fetchPingbackData
/**
* Fetches additional comment data from the page that sent the pingback
* @access private
* @param array comment array to be filled
*/
function fetchPingbackData(&$comment)
{
global $serendipity;
// Don't fetch remote page, if not explicitly allowed in serendipity_config_local.php:
if (empty($serendipity['pingbackFetchPage'])) {
return;
}
// If we don't have a comment or a commentors url, stop it.
if (!isset($comment) || !is_array($comment) || !isset($comment['url'])) {
return;
}
// Max amount of characters fetched from the page doing a pingback:
$fetchPageMaxLength = 200;
if (isset($serendipity['pingbackFetchPageMaxLength'])) {
$fetchPageMaxLength = $serendipity['pingbackFetchPageMaxLength'];
}
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
$url = $comment['url'];
if (function_exists('serendipity_request_start')) {
serendipity_request_start();
}
// Request the page
$req = new HTTP_Request($url, array('allowRedirects' => true, 'maxRedirects' => 5, 'timeout' => 20, 'readTimeout' => array(5, 0)));
// code 200: OK, code 30x: REDIRECTION
$responses = "/(200 OK)|(30[0-9] Found)/";
// |(30[0-9] Moved)
if (PEAR::isError($req->sendRequest()) || preg_match($responses, $req->getResponseCode())) {
// nothing to do,
} else {
$fContent = $req->getResponseBody();
// Get a title
if (preg_match('@<head[^>]*>.*?<title[^>]*>(.*?)</title>.*?</head>@is', $fContent, $matches)) {
$comment['title'] = serendipity_entity_decode(strip_tags($matches[1]), ENT_COMPAT, LANG_CHARSET);
}
// Try to get content from first <p> tag on:
if (preg_match('@<p[^>]*>(.*?)</body>@is', $fContent, $matches)) {
$body = $matches[1];
}
if (empty($body) && preg_match('@<body[^>]*>(.*?)</body>@is', $fContent, $matches)) {
$body = $matches[1];
}
// Get a part of the article
if (!empty($body)) {
$body = trackback_body_strip($body);
// truncate the text to 200 chars
$arr = str_split($body, $fetchPageMaxLength);
$body = $arr[0];
$comment['comment'] = $body . '[..]';
}
}
if (function_exists('serendipity_request_end')) {
serendipity_request_end();
}
}
示例3: mod_time
function mod_time($uri)
{
if (function_exists('version_compare') && version_compare(phpversion(), '4.3.0') >= 0) {
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
serendipity_request_start();
$req = new HTTP_Request($uri);
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
serendipity_request_end();
return false;
}
$fHeader = $req->getResponseHeader();
if (isset($fHeader['last-modified'])) {
$modtime = $fHeader['last-modified'];
}
serendipity_request_end();
} else {
$parts = parse_url($uri);
$host = $parts['host'];
$path = $parts['path'];
if (!($fp = @fsockopen($host, 80))) {
return false;
}
$req = "HEAD {$path} HTTP/1.1\r\nUser-Agent: PHP/" . phpversion();
$req .= "\r\nHost: {$host}\r\nAccept: */*\r\n\r\n";
fputs($fp, $req);
while (!feof($fp)) {
$str = fgets($fp, 4096);
if (strpos(strtolower($str), 'last-modified') !== false) {
$modtime = substr($str, 15);
break;
}
}
fclose($fp);
}
return isset($modtime) ? $modtime : 0;
}
示例4: require_once
function &importFeeds()
{
// Used by ImportOPML routine
global $serendipity;
$file = $serendipity['POST']['aggregatorOPML'];
require_once (defined('S9Y_PEAR_PATH') ? S9Y_PEAR_PATH : S9Y_INCLUDE_PATH . 'bundled-libs/') . 'HTTP/Request.php';
if (function_exists('serendipity_request_start')) {
serendipity_request_start();
}
$req = new HTTP_Request($file);
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
$data = file_get_contents($file);
if (empty($data)) {
return false;
}
} else {
// Fetch file
$data = $req->getResponseBody();
}
if (function_exists('serendipity_request_end')) {
serendipity_request_end();
}
// XML functions
$xml_string = '<?xml version="1.0" encoding="UTF-8" ?>';
if (preg_match('@(<\\?xml.+\\?>)@imsU', $data, $xml_head)) {
$xml_string = $xml_head[1];
}
$encoding = 'UTF-8';
if (preg_match('@encoding="([^"]+)"@', $xml_string, $xml_encoding)) {
$encoding = $xml_encoding[1];
}
// Global replacements
// by: waldo@wh-e.com - trim space around tags not within
$data = preg_replace('@>[[:space:]]+<@i', '><', $data);
switch (strtolower($encoding)) {
case 'iso-8859-1':
case 'utf-8':
$p = xml_parser_create($encoding);
break;
default:
$p = xml_parser_create('');
}
// by: anony@mous.com - meets XML 1.0 specification
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
@xml_parser_set_option($p, XML_OPTION_TARGET_ENCODING, LANG_CHARSET);
xml_parse_into_struct($p, $data, $vals, $index);
xml_parser_free($p);
$i = 0;
$tree = array();
$tree[] = array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'value' => $vals[$i]['value'], 'children' => $this->GetChildren($vals, $i));
return $tree;
}
示例5: serendipity_request_url
function serendipity_request_url($uri, $method = 'GET', $contenttype = null, $data = null, $extra_options = null, $addData = null, $auth = null)
{
global $serendipity;
require_once S9Y_PEAR_PATH . 'HTTP/Request2.php';
$options = array('follow_redirects' => true, 'max_redirects' => 5);
if (is_array($extra_options)) {
foreach ($extra_options as $okey => $oval) {
$options[$okey] = $oval;
}
}
serendipity_plugin_api::hook_event('backend_http_request', $options, $addData);
serendipity_request_start();
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
// On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1
$options['ssl_verify_peer'] = false;
}
switch (strtoupper($method)) {
case 'GET':
$http_method = HTTP_Request2::METHOD_GET;
break;
case 'PUT':
$http_method = HTTP_Request2::METHOD_PUT;
break;
case 'OPTIONS':
$http_method = HTTP_Request2::METHOD_OPTIONS;
break;
case 'HEAD':
$http_method = HTTP_Request2::METHOD_HEAD;
break;
case 'DELETE':
$http_method = HTTP_Request2::METHOD_DELETE;
break;
case 'TRACE':
$http_method = HTTP_Request2::METHOD_TRACE;
break;
case 'CONNECT':
$http_method = HTTP_Request2::METHOD_CONNECT;
break;
default:
case 'POST':
$http_method = HTTP_Request2::METHOD_POST;
break;
}
$req = new HTTP_Request2($uri, $http_method, $options);
if (isset($contenttype) && $contenttype !== null) {
$req->setHeader('Content-Type', $contenttype);
}
if (is_array($auth)) {
$req->setAuth($auth['user'], $auth['pass']);
}
if ($data != null) {
if (is_array($data)) {
$req->addPostParameter($data);
} else {
$req->setBody($data);
}
}
try {
$res = $req->send();
} catch (HTTP_Request2_Exception $e) {
serendipity_request_end();
return false;
}
$fContent = $res->getBody();
$serendipity['last_http_request'] = array('responseCode' => $res->getStatus(), 'effectiveUrl' => $res->getEffectiveUrl(), 'reasonPhrase' => $res->getReasonPhrase(), 'isRedirect' => $res->isRedirect(), 'cookies' => $res->getCookies(), 'version' => $res->getVersion(), 'header' => $res->getHeader(), 'object' => $res);
serendipity_request_end();
return $fContent;
}
示例6: get_gg_status
function get_gg_status($numer_gg, $haslo_gg, $szukany_numer, &$error, &$gg_status_widocznosc)
{
define("GG_WELCOME", 0x1);
define("GG_LOGIN", 0xc);
define("GG_LOGIN60", 0x15);
define("GG_LOGIN_OK", 0x3);
define("GG_LOGIN_FAILED", 0x9);
define("GG_NEW_STATUS", 0x2);
define("GG_STATUS", 0x2);
define("GG_STATUS_NOT_AVAIL", 0x1);
define("GG_STATUS_NOT_AVAIL_DESCR", 0x15);
define("GG_STATUS_AVAIL", 0x2);
define("GG_STATUS_AVAIL_DESCR", 0x4);
define("GG_STATUS_BUSY", 0x3);
define("GG_STATUS_BUSY_DESCR", 0x5);
define("GG_STATUS_INVISIBLE", 0x14);
define("GG_NOTIFY", 0x10);
define("GG_NOTIFY_REPLY", 0xc);
define("GG_NOTIFY_REPLY60", 0x11);
define("GG_USER_NORMAL", 0x3);
define("GG_USER_BLOCKED", 0x4);
define("GG_SEND_MSG", 0xb);
define("GG_CLASS_MSG", 0x4);
define("GG_CLASS_CHAT", 0x8);
define("GG_CLASS_ACK", 0x20);
define("GG_SEND_MSG_ACK", 0x5);
define("GG_ACK_DELIVERED", 0x2);
define("GG_ACK_QUEUED", 0x3);
define("GG_RECV_MSG", 0xa);
define("GG_LOGIN_FAILED2", 0xb);
define("GG_ACK_MBOXFULL", 0x4);
define("DISCONNECTED", 0x100);
define("GG_PUBDIR50_REQUEST", 0x14);
define("GG_PUBDIR50_REPLY", 0xe);
define("GG_PUBDIR50_SEARCH", 0x3);
//
// Getting a logon server
//
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
serendipity_request_start();
$req = new HTTP_Request('http://appmsg.gadu-gadu.pl:80/appsvc/appmsg.asp?fmnumber=<' . $numer_gg . '>');
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
$error = PLUGIN_GGOPIS_MSG_NOCONNTOAPPMSG . $errno . " - " . $errstr . "\n";
serendipity_request_end();
return false;
} else {
$buf = $req->getResponseBody();
preg_match("/\\s([\\d\\.]{8,16})\\:([\\d]{1,5})\\s/", $buf, $adres);
$host = $adres[1];
$port = $adres[2];
serendipity_request_end();
}
//
// Connecting to a server
//
require_once S9Y_PEAR_PATH . 'Net/Socket.php';
$conn = new Net_Socket();
if (!$conn->connect($host, $port, null, 10)) {
$error = PLUGIN_GGOPIS_MSG_CONNERROR . ": {$errno} - {$errstr}\n\n";
return false;
}
//
// Getting data from a server -
// receiving a key needed to calculate
// a hash from your password
//
if (!($data = $conn->read(12))) {
$error = PLUGIN_GGOPIS_MSG_CONNUNEXPCLOSED . "\n\n";
$conn->disconnect();
return false;
}
$tab = unpack("Vtyp/Vrozmiar/Vklucz", $data);
// Calculating a password hash
$hash = $this->calculate_hash($haslo_gg, $tab['klucz']);
$data = pack("VVVVVVvVvVvCCa" . strlen(""), GG_LOGIN60, 0x20 + strlen(""), $numer_gg, $hash, GG_STATUS_AVAIL, 0x20, 0, 0, 0, 0, 0, 0x14, 0xbe, "");
// Sending a password hash - logging to a GG server
$conn->write($data);
if (!($data1 = $conn->read(8))) {
$error = PLUGIN_GGOPIS_MSG_UNKNOWNERROR . "\n";
$conn->disconnect();
return false;
}
// Checking a login status
$tab = unpack("Vlogin_status/Vrozmiar", $data1);
if ($tab['login_status'] != GG_LOGIN_OK) {
$error = PLUGIN_GGOPIS_MSG_INCORRPASSWD . "\n\n";
$conn->disconnect();
return false;
}
// Sending a contact list with one contact
$data = pack("VVVC", GG_NOTIFY, 5, $szukany_numer, GG_USER_NORMAL);
if (!$conn->write($data)) {
$error = PLUGIN_GGOPIS_MSG_SENDCONTACTSERROR . "\n\n";
$conn->disconnect();
return false;
}
// Receiving a packet with the next packet specification
$gg_opis = '';
$data = $conn->read(8);
if (strlen($data) > 0) {
//.........这里部分代码省略.........
示例7: event_hook
//.........这里部分代码省略.........
$this->IsHardcoreSpammer();
if ($akismet == 'moderate') {
$this->log($logfile, $eventData['id'], 'MODERATE', PLUGIN_EVENT_SPAMBLOCK_REASON_AKISMET_SPAMLIST . ': ' . $spam['message'], $addData);
$eventData['moderate_comments'] = true;
$serendipity['csuccess'] = 'moderate';
$serendipity['moderate_reason'] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY . ' (Akismet)';
} else {
$this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_REASON_AKISMET_SPAMLIST . ': ' . $spam['message'], $addData);
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY;
return false;
}
}
}
// Check Trackback URLs?
if (($addData['type'] == 'TRACKBACK' || $addData['type'] == 'PINGBACK') && serendipity_db_bool($this->get_config('trackback_check_url'))) {
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
if (function_exists('serendipity_request_start')) {
serendipity_request_start();
}
$req = new HTTP_Request($addData['url'], array('allowRedirects' => true, 'maxRedirects' => 5, 'readTimeout' => array(5, 0)));
$is_valid = false;
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
$is_valid = false;
} else {
$fdata = $req->getResponseBody();
// Check if the target page contains a link to our blog
if (preg_match('@' . preg_quote($serendipity['baseURL'], '@') . '@i', $fdata)) {
$is_valid = true;
} else {
$is_valid = false;
}
}
if (function_exists('serendipity_request_end')) {
serendipity_request_end();
}
if ($is_valid === false) {
$this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_REASON_TRACKBACKURL, $addData);
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_REASON_TRACKBACKURL;
return false;
}
}
if (false === $this->wordfilter($logfile, $eventData, $wordmatch, $addData)) {
return false;
}
// Check for maximum number of links before rejecting
$link_count = substr_count(strtolower($addData['comment']), 'http://');
if ($links_reject > 0 && $link_count > $links_reject) {
$this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_REASON_LINKS_REJECT, $addData);
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_BODY;
return false;
}
// Captcha checking
if ($show_captcha && $addData['type'] == 'NORMAL') {
if (!isset($_SESSION['spamblock']['captcha']) || !isset($serendipity['POST']['captcha']) || strtolower($serendipity['POST']['captcha']) != strtolower($_SESSION['spamblock']['captcha'])) {
$this->log($logfile, $eventData['id'], 'REJECTED', sprintf(PLUGIN_EVENT_SPAMBLOCK_REASON_CAPTCHAS, $serendipity['POST']['captcha'], $_SESSION['spamblock']['captcha']), $addData);
$eventData = array('allow_comments' => false);
$serendipity['messagestack']['comments'][] = PLUGIN_EVENT_SPAMBLOCK_ERROR_CAPTCHAS;
return false;
} else {
// DEBUG
// $this->log($logfile, $eventData['id'], 'REJECTED', 'Captcha passed: ' . $serendipity['POST']['captcha'] . ' / ' . $_SESSION['spamblock']['captcha'] . ' // Source: ' . $_SERVER['REQUEST_URI'], $addData);
}
} else {
示例8: updateTwitterTimelineCache
function updateTwitterTimelineCache($cachefile)
{
global $serendipity;
$cachetime = (int) $this->get_config('cachetime', 300);
if (!file_exists($cachefile) || filemtime($cachefile) < time() - $cachetime) {
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
$service = $this->get_config('service');
$username = $this->get_config('username');
$number = $this->get_config('number');
if (serendipity_db_bool($this->get_config('toall_only', false))) {
$number = 50;
// Fetch many in the hope, that there are enough globals with it.
}
if ($service == 'identi.ca') {
$service_url = 'http://identi.ca/api';
$status_url = 'http://identi.ca/notice/';
$search_twitter_uri = $service_url . '/statuses/user_timeline/' . $username . '.json?count=' . $number;
} else {
$followme_url = 'https://twitter.com/' . $username;
$service_url = 'https://api.twitter.com';
$status_url = 'https://twitter.com/' . $username . '/statuses/';
$search_twitter_uri = 'https://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $username . '&count=' . $number;
}
serendipity_request_start();
$req = new HTTP_Request($search_twitter_uri);
$req->sendRequest();
$response = trim($req->getResponseBody());
$error = $req->getResponseCode();
serendipity_request_end();
if ($error == 200 && !empty($response)) {
$fp = fopen($cachefile, 'w');
fwrite($fp, serialize($response));
fflush($fp);
fclose($fp);
}
}
}
示例9: preg_replace
//.........这里部分代码省略.........
$options = array('allowRedirects' => true, 'maxRedirects' => 5);
serendipity_plugin_api::hook_event('backend_http_request', $options, 'spartacus');
serendipity_request_start();
$req = new HTTP_Request($url, $options);
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
$resolved_url = $url . ' (IP ' . $url_ip . ')';
$this->outputMSG('error', sprintf(PLUGIN_EVENT_SPARTACUS_FETCHERROR, $resolved_url));
//--JAM: START FIREWALL DETECTION
if ($req->getResponseCode()) {
$this->outputMSG('error', sprintf(PLUGIN_EVENT_SPARTACUS_REPOSITORY_ERROR, $req->getResponseCode()));
}
$check_health = true;
if (function_exists('curl_init')) {
$this->outputMSG('notice', PLUGIN_EVENT_SPARTACUS_TRYCURL);
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_HEADER, 0);
$curl_result = curl_exec($curl_handle);
curl_close($curl_handle);
if ($curl_result) {
$check_health = false;
} else {
$this->outputMSG('error', PLUGIN_EVENT_SPARTACUS_CURLFAIL . "\n");
}
}
}
if ($check_health) {
/*--JAM: Useful for later, when we have a health monitor for SPARTACUS
$propbag = new serendipity_property_bag;
$this->introspect($propbag);
$health_url = 'http://spartacus.s9y.org/spartacus_health.php?version=' . $propbag->get('version');
*/
// Garvin: Temporary health. Better than nothing, eh?
$health_url = $url;
$matches = array();
preg_match('#http://[^/]*/#', $url, $matches);
if ($matches[0]) {
$health_url = $matches[0];
}
$mirrors = $this->getMirrors('files_health', true);
$health_url = $mirrors[$health_url];
$this->outputMSG('notice', sprintf(PLUGIN_EVENT_SPARTACUS_HEALTHCHECK, $health_url));
$health_options = $options;
serendipity_plugin_api::hook_event('backend_http_request', $health_options, 'spartacus_health');
$health_req = new HTTP_Request($health_url, $health_options);
$health_result = $health_req->sendRequest();
if (PEAR::isError($health_result)) {
$fp = @fsockopen('www.google.com', 80, $errno, $errstr);
if (!$fp) {
$this->outputMSG('error', sprintf(PLUGIN_EVENT_SPARTACUS_HEALTHBLOCKED, $errno, $errstr));
} else {
$this->outputMSG('error', PLUGIN_EVENT_SPARTACUS_HEALTHDOWN);
$this->outputMSG('notice', sprintf(PLUGIN_EVENT_SPARTACUS_HEALTHLINK, $health_url));
fclose($fp);
}
} else {
if ($health_req->getResponseCode() != '200') {
$this->outputMSG('error', sprintf(PLUGIN_EVENT_SPARTACUS_HEALTHERROR, $health_req->getResponseCode()));
$this->outputMSG('notice', sprintf(PLUGIN_EVENT_SPARTACUS_HEALTHLINK, $health_url));
} else {
$this->outputMSG('error', PLUGIN_EVENT_SPARTACUS_HEALTFIREWALLED);
//--JAM: Parse response and display it.
}
}
//--JAM: END FIREWALL DETECTION
if (file_exists($target) && filesize($target) > 0) {
$data = file_get_contents($target);
$this->outputMSG('success', sprintf(PLUGIN_EVENT_SPARTACUS_FETCHED_BYTES_CACHE, strlen($data), $target));
}
} else {
// Fetch file
if (!$data) {
$data = $req->getResponseBody();
}
if (is_object($serendipity['logger'])) {
$serendipity['logger']->debug(sprintf(PLUGIN_EVENT_SPARTACUS_FETCHED_BYTES_URL, strlen($data), $target));
}
$tdir = dirname($target);
if (!is_dir($tdir) && !$this->rmkdir($tdir, $sub)) {
$this->outputMSG('error', sprintf(FILE_WRITE_ERROR, $tdir));
return $error;
}
$fp = @fopen($target, 'w');
if (!$fp) {
$this->outputMSG('error', sprintf(FILE_WRITE_ERROR, $target));
return $error;
}
if ($decode_utf8) {
$data = str_replace('<?xml version="1.0" encoding="UTF-8" ?>', '<?xml version="1.0" encoding="' . LANG_CHARSET . '" ?>', $data);
$this->decode($data, true);
}
fwrite($fp, $data);
fclose($fp);
$this->fileperm($target, false);
$this->purgeCache = true;
}
serendipity_request_end();
}
return $data;
}
示例10: saveAndResponseAvatar
/**
* Caches an avatar and streams it back to the browser.
*/
function saveAndResponseAvatar($eventData, $url, $allow_redirection = 3)
{
require_once S9Y_PEAR_PATH . 'HTTP/Request2.php';
global $serendipity;
$fContent = null;
if (function_exists('serendipity_request_start')) {
serendipity_request_start();
}
if ($allow_redirection) {
$request_pars['follow_redirects'] = true;
$request_pars['max_redirects'] = $allow_redirection;
} else {
$request_pars['follow_redirects'] = false;
}
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
// On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1
$request_pars['ssl_verify_peer'] = false;
}
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET, $request_pars);
try {
$response = $req->send();
if ($response->getStatus() != '200') {
throw new HTTP_Request2_Exception("Could not search on identica");
}
// Allow only images as Avatar!
$mime = $response->getHeader("content-type");
$this->avatarConfiguration['mime-type'] = $mime;
$this->log("Avatar fetch mimetype: {$mime}" . " for url=" . $url);
$mimeparts = explode('/', $mime);
if (count($mimeparts) == 2 && $mimeparts[0] == 'image') {
$fContent = $response->getBody();
}
} catch (HTTP_Request2_Exception $e) {
$fContent = null;
$this->log("Avatar fetch error: " . $e);
}
if (function_exists('serendipity_request_start')) {
serendipity_request_end();
}
// if no content was fetched, return false
if (!isset($fContent) || empty($fContent)) {
$this->log("Avatar fetch: no Content!");
return false;
}
$cache_file = $this->cacheAvatar($eventData, $fContent);
if ($cache_file) {
$this->show($cache_file);
} else {
if ($this->supportDefaultAvatar()) {
$this->fetchDefault();
}
}
return true;
}
示例11: updateTwitterTimelineCache
function updateTwitterTimelineCache($parts)
{
global $serendipity;
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
if (count($parts) < 5) {
return time() + 60 * 60;
}
// params corrupted next try allowed one minute later
// Do we need to do OAuth?
if (count($parts) > 6) {
$idx_twitter = $parts[5];
$idxmd5 = $parts[6];
$idxmd5_test = md5(serendipity_event_twitter::pluginSecret() . "_{$idx_twitter}");
if ($idxmd5_test != $idxmd5) {
// Seems to be a hack!
return time() + 60 * 60;
// params corrupted next try allowed one minute later
}
}
$show_rt = false;
if (count($parts) > 7) {
$features = $parts[7];
$show_rt = strpos($features, 'r') !== false;
}
$cachetime = (int) $parts[4];
$service = $parts[1];
$username = str_replace('!', '_', $parts[2]);
$cache_user = md5($service) . md5($username);
$cachefile = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE . "/twitterresult.{$cache_user}.json";
$nextcheck = time() + (int) $cachetime;
if (file_exists($cachefile)) {
$nextcheck = filemtime($cachefile) + $cachetime;
}
if (!file_exists($cachefile) || filemtime($cachefile) < time() - $cachetime) {
$number = str_replace("!", "_", $parts[3]);
$error = 200;
// Default is: All OK
if (!empty($idx_twitter)) {
$search_twitter_uri = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=' . $username . '&count=' . $number . '&trim_user=true';
if (!$show_rt) {
$search_twitter_uri .= '&include_rts=false';
}
if ($idx_twitter == '1') {
$idx_twitter = '';
}
// First cfg is saved with empty suffix!
$connection = $this->twitteroa_connect($idx_twitter);
$connection->decode_json = false;
$response = $connection->get($search_twitter_uri);
} else {
if ($service == 'identi.ca') {
$followme_url = 'http://identi.ca/' . $username;
$status_url = 'http://identi.ca/notice/';
$JSONcallback = 'identicaCallback2';
$service_url = 'http://identi.ca/api';
$search_twitter_uri = $service_url . '/statuses/user_timeline/' . $username . '.json?count=' . $number;
} else {
$followme_url = 'https://twitter.com/' . $username;
$service_url = 'https://twitter.com';
$status_url = 'https://twitter.com/' . $username . '/statuses/';
$JSONcallback = 'twitterCallback2';
$search_twitter_uri = 'https://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $username . '&count=' . $number;
}
serendipity_request_start();
$req = new HTTP_Request($search_twitter_uri);
$req->sendRequest();
$response = trim($req->getResponseBody());
$error = $req->getResponseCode();
serendipity_request_end();
}
$this->log("error: {$error}");
if ($error == 200 && !empty($response)) {
$this->log("Writing response into cache.");
$fp = fopen($cachefile, 'w');
fwrite($fp, serialize($response));
fflush($fp);
fclose($fp);
$nextcheck = time() + (int) $cachetime;
$this->log("Writing response into cache. DONE");
}
}
return $nextcheck;
}
示例12: userinfo
function userinfo($screenname)
{
if (empty($screenname)) {
echo "screenname empty";
return;
}
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
$requrl = $this->get_api_url() . 'users/show.json?screen_name=' . $screenname;
if (function_exists('serendipity_request_start')) {
serendipity_request_start();
}
$req = new HTTP_Request($requrl);
$req->sendRequest();
$response = trim($req->getResponseBody());
if (function_exists('serendipity_request_start')) {
serendipity_request_end();
}
return @json_decode($response);
}
示例13: fetchPingbackData
/**
* Fetches additional comment data from the page that sent the pingback
* @access private
* @param array comment array to be filled
*/
function fetchPingbackData(&$comment)
{
global $serendipity;
// Don't fetch remote page, if not explicitly allowed in serendipity_config_local.php:
if (empty($serendipity['pingbackFetchPage'])) {
return;
}
// If we don't have a comment or a commentors url, stop it.
if (!isset($comment) || !is_array($comment) || !isset($comment['url'])) {
return;
}
// Max amount of characters fetched from the page doing a pingback:
$fetchPageMaxLength = 200;
if (isset($serendipity['pingbackFetchPageMaxLength'])) {
$fetchPageMaxLength = $serendipity['pingbackFetchPageMaxLength'];
}
require_once S9Y_PEAR_PATH . 'HTTP/Request2.php';
$url = $comment['url'];
if (function_exists('serendipity_request_start')) {
serendipity_request_start();
}
// Request the page
$options = array('follow_redirects' => true, 'max_redirects' => 5, 'timeout' => 20);
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
// On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1
$options['ssl_verify_peer'] = false;
}
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET, $options);
// code 200: OK, code 30x: REDIRECTION
$responses = "/(200)|(30[0-9])/";
// |(30[0-9] Moved)
try {
$response = $req->send();
if (preg_match($responses, $response->getStatus())) {
}
$fContent = $response->getBody();
// Get a title
if (preg_match('@<head[^>]*>.*?<title[^>]*>(.*?)</title>.*?</head>@is', $fContent, $matches)) {
$comment['title'] = serendipity_entity_decode(strip_tags($matches[1]), ENT_COMPAT, LANG_CHARSET);
}
// Try to get content from first <p> tag on:
if (preg_match('@<p[^>]*>(.*?)</body>@is', $fContent, $matches)) {
$body = $matches[1];
}
if (empty($body) && preg_match('@<body[^>]*>(.*?)</body>@is', $fContent, $matches)) {
$body = $matches[1];
}
// Get a part of the article
if (!empty($body)) {
$body = trackback_body_strip($body);
// truncate the text to 200 chars
$arr = str_split($body, $fetchPageMaxLength);
$body = $arr[0];
$comment['comment'] = $body . '[..]';
}
} catch (HTTP_Request2_Exception $e) {
}
if (function_exists('serendipity_request_end')) {
serendipity_request_end();
}
}
示例14: http
/**
* Make an HTTP request
*
* @return API results
*/
function http($url, $method, $postfields = NULL)
{
$this->http_info = array();
if (function_exists('curl_init')) {
$ci = curl_init();
/* Curl settings */
curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
curl_setopt($ci, CURLOPT_HEADER, FALSE);
switch ($method) {
case 'POST':
curl_setopt($ci, CURLOPT_POST, TRUE);
if (!empty($postfields)) {
curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
}
break;
case 'DELETE':
curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
if (!empty($postfields)) {
$url = "{$url}?{$postfields}";
}
}
curl_setopt($ci, CURLOPT_URL, $url);
$response = curl_exec($ci);
$this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
$this->http_info = array_merge($this->http_info, curl_getinfo($ci));
$this->url = $url;
curl_close($ci);
} else {
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
serendipity_request_start();
$req = new HTTP_Request($url);
switch ($method) {
case 'POST':
$req->setMethod(HTTP_REQUEST_METHOD_POST);
if (!empty($postfields)) {
$fields = explode('&', $postfields);
foreach ($fields as $field) {
$data = explode('=', $field);
$req->addPostData($data[0], $data[1], true);
}
}
break;
case 'DELETE':
$req->setMethod(HTTP_REQUEST_METHOD_DELETE);
if (!empty($postfields)) {
$url = "{$url}?{$postfields}";
}
}
$req->sendRequest();
$response = trim($req->getResponseBody());
$this->url = $url;
$this->http_code = $req->getResponseCode();
serendipity_event_twitter::twitteroalog($url . " - " . $postfields . " (Code: " . $this->http_code . ")\n" . $response);
serendipity_request_end();
}
return $response;
}
示例15: urlcheck
function urlcheck($uri)
{
// These two substring comparisons are faster than one regexp.
if ('http://' != substr($uri, 0, 7) && 'https://' != substr($uri, 0, 8)) {
return false;
}
// Disabled by now. May get enabled in the future, but for now the extra HTTP call isn't worth trying.
return true;
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
serendipity_request_start();
$req = new HTTP_Request($uri);
if (PEAR::isError($req->sendRequest()) || !preg_match('@^[23]..@', $req->getResponseCode())) {
serendipity_request_end();
return false;
} else {
serendipity_request_end();
return true;
}
}