code
stringlengths 17
296k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public static function _mime_types($ext = '') {
$mimes = array(
'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
'doc' => 'application/msword',
'bin' => 'application/macbinary',
'dms' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'exe' => 'application/octet-stream',
'class' => 'application/octet-stream',
'psd' => 'application/octet-stream',
'so' => 'application/octet-stream',
'sea' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'oda' => 'application/oda',
'pdf' => 'application/pdf',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'smi' => 'application/smil',
'smil' => 'application/smil',
'mif' => 'application/vnd.mif',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'wbxml' => 'application/vnd.wap.wbxml',
'wmlc' => 'application/vnd.wap.wmlc',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'gtar' => 'application/x-gtar',
'php' => 'application/x-httpd-php',
'php4' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'phtml' => 'application/x-httpd-php',
'phps' => 'application/x-httpd-php-source',
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'sit' => 'application/x-stuffit',
'tar' => 'application/x-tar',
'tgz' => 'application/x-tar',
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => 'application/zip',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'ra' => 'audio/x-realaudio',
'rv' => 'video/vnd.rn-realvideo',
'wav' => 'audio/x-wav',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'png' => 'image/png',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'shtml' => 'text/html',
'txt' => 'text/plain',
'text' => 'text/plain',
'log' => 'text/plain',
'rtx' => 'text/richtext',
'rtf' => 'text/rtf',
'xml' => 'text/xml',
'xsl' => 'text/xml',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie',
'doc' => 'application/msword',
'word' => 'application/msword',
'xl' => 'application/excel',
'eml' => 'message/rfc822',
);
return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
} | Gets the MIME type of the embedded or inline image
@param string File extension
@access public
@return string MIME type of ext
@static | _mime_types | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/phpmailer.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/phpmailer.php | MIT |
public function SecureHeader($str) {
$str = str_replace("\r", '', $str);
$str = str_replace("\n", '', $str);
return trim($str);
} | Strips newlines to prevent header injection.
@access public
@param string $str String
@return string | SecureHeader | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/phpmailer.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/phpmailer.php | MIT |
public function Sign($cert_filename, $key_filename, $key_pass) {
$this->sign_cert_file = $cert_filename;
$this->sign_key_file = $key_filename;
$this->sign_key_pass = $key_pass;
} | Set the private key file and password to sign the message.
@access public
@param string $key_filename Parameter File Name
@param string $key_pass Password for private key | Sign | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/phpmailer.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/phpmailer.php | MIT |
public function DKIM_QP($txt) {
$tmp = "";
$line = "";
for ($i = 0; $i < strlen($txt); $i++) {
$ord = ord($txt[$i]);
if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
$line .= $txt[$i];
} else {
$line .= "=" . sprintf("%02X", $ord);
}
}
return $line;
} | Set the private key file and password to sign the message.
@access public
@param string $key_filename Parameter File Name
@param string $key_pass Password for private key | DKIM_QP | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/phpmailer.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/phpmailer.php | MIT |
public function DKIM_BodyC($body) {
if ($body == '') {
return "\r\n";
}
// stabilize line endings
$body = str_replace("\r\n", "\n", $body);
$body = str_replace("\n", "\r\n", $body);
// END stabilize line endings
while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
$body = substr($body, 0, strlen($body) - 2);
}
return $body;
} | Generate DKIM Canonicalization Body
@access public
@param string $body Message Body | DKIM_BodyC | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/phpmailer.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/phpmailer.php | MIT |
public function __construct() {
$this->smtp_conn = 0;
$this->error = null;
$this->helo_rply = null;
$this->do_debug = 0;
} | Initialize the class so that the data is in a known state.
@access public
@return void | __construct | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Connect($host, $port = 0, $tval = 30) {
// set the error val to null so there is no confusion
$this->error = null;
// make sure we are __not__ connected
if ($this->connected()) {
// already connected, generate error
$this->error = array("error" => "Already connected to a server");
return false;
}
if (empty($port)) {
$port = $this->SMTP_PORT;
}
// connect to the smtp server
//try it nobird
$contextOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false
)
);
$context = stream_context_create($contextOptions);
$this->smtp_conn = stream_socket_client("{$host}:{$port}", $errno, $errstr, $tval, STREAM_CLIENT_CONNECT, $context);
/*
$this->smtp_conn = @fsockopen($host, // the host of the server
$port, // the port to use
$errno, // error number if any
$errstr, // error message if any
$tval); // give up after ? secs
*/
// verify we connected properly
if (empty($this->smtp_conn)) {
$this->error = array("error" => "Failed to connect to server",
"errno" => $errno,
"errstr" => $errstr);
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
}
return false;
}
// SMTP server can take longer to respond, give longer timeout for first read
// Windows does not have support for this timeout function
if (substr(PHP_OS, 0, 3) != "WIN") {
socket_set_timeout($this->smtp_conn, $tval, 0);
}
// get any announcement
$announce = $this->get_lines();
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
}
return true;
} | Connect to the server specified on the port specified.
If the port is not specified use the default SMTP_PORT.
If tval is specified then a connection will try and be
established with the server for that number of seconds.
If tval is not specified the default is 30 seconds to
try on the connection.
SMTP CODE SUCCESS: 220
SMTP CODE FAILURE: 421
@access public
@return bool | Connect | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function StartTLS() {
$this->error = null; # to avoid confusion
if (!$this->connected()) {
$this->error = array("error" => "Called StartTLS() without being connected");
return false;
}
fputs($this->smtp_conn, "STARTTLS" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply, 0, 3);
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if ($code != 220) {
$this->error =
array("error" => "STARTTLS not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
// Begin encrypted connection
if (!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
return false;
}
return true;
} | Initiate a TLS communication with the server.
SMTP CODE 220 Ready to start TLS
SMTP CODE 501 Syntax error (no parameters allowed)
SMTP CODE 454 TLS not available due to temporary reason
@access public
@return bool success | StartTLS | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Authenticate($username, $password) {
// Start authentication
fputs($this->smtp_conn, "AUTH LOGIN" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply, 0, 3);
if ($code != 334) {
$this->error =
array("error" => "AUTH not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
// Send encoded username
fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply, 0, 3);
if ($code != 334) {
$this->error =
array("error" => "Username not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
// Send encoded password
fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply, 0, 3);
if ($code != 235) {
$this->error =
array("error" => "Password not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
} | Performs SMTP authentication. Must be run after running the
Hello() method. Returns true if successfully authenticated.
@access public
@return bool | Authenticate | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Connected() {
if (!empty($this->smtp_conn)) {
$sock_status = socket_get_status($this->smtp_conn);
if ($sock_status["eof"]) {
// the socket is valid but we are not connected
if ($this->do_debug >= 1) {
echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
}
$this->Close();
return false;
}
return true; // everything looks good
}
return false;
} | Returns true if connected to a server otherwise false
@access public
@return bool | Connected | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Close() {
$this->error = null; // so there is no confusion
$this->helo_rply = null;
if (!empty($this->smtp_conn)) {
// close the connection and cleanup
fclose($this->smtp_conn);
$this->smtp_conn = 0;
}
} | Closes the socket and cleans up the state of the class.
It is not considered good to use this function without
first trying to use QUIT.
@access public
@return void | Close | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Data($msg_data) {
$this->error = null; // so no confusion is caused
if (!$this->connected()) {
$this->error = array(
"error" => "Called Data() without being connected");
return false;
}
fputs($this->smtp_conn, "DATA" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply, 0, 3);
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if ($code != 354) {
$this->error =
array("error" => "DATA command not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
/* the server is ready to accept data!
* according to rfc 821 we should not send more than 1000
* including the CRLF
* characters on a single line so we will break the data up
* into lines by \r and/or \n then if needed we will break
* each of those into smaller lines to fit within the limit.
* in addition we will be looking for lines that start with
* a period '.' and append and additional period '.' to that
* line. NOTE: this does not count towards limit.
*/
// normalize the line breaks so we know the explode works
$msg_data = str_replace("\r\n", "\n", $msg_data);
$msg_data = str_replace("\r", "\n", $msg_data);
$lines = explode("\n", $msg_data);
/* we need to find a good way to determine is headers are
* in the msg_data or if it is a straight msg body
* currently I am assuming rfc 822 definitions of msg headers
* and if the first field of the first line (':' sperated)
* does not contain a space then it _should_ be a header
* and we can process all lines before a blank "" line as
* headers.
*/
$field = substr($lines[0], 0, strpos($lines[0], ":"));
$in_headers = false;
if (!empty($field) && !strstr($field, " ")) {
$in_headers = true;
}
$max_line_length = 998; // used below; set here for ease in change
while (list(, $line) = @each($lines)) {
$lines_out = null;
if ($line == "" && $in_headers) {
$in_headers = false;
}
// ok we need to break this line up into several smaller lines
while (strlen($line) > $max_line_length) {
$pos = strrpos(substr($line, 0, $max_line_length), " ");
// Patch to fix DOS attack
if (!$pos) {
$pos = $max_line_length - 1;
$lines_out[] = substr($line, 0, $pos);
$line = substr($line, $pos);
} else {
$lines_out[] = substr($line, 0, $pos);
$line = substr($line, $pos + 1);
}
/* if processing headers add a LWSP-char to the front of new line
* rfc 822 on long msg headers
*/
if ($in_headers) {
$line = "\t" . $line;
}
}
$lines_out[] = $line;
// send the lines to the server
while (list(, $line_out) = @each($lines_out)) {
if (strlen($line_out) > 0) {
if (substr($line_out, 0, 1) == ".") {
$line_out = "." . $line_out;
}
}
fputs($this->smtp_conn, $line_out . $this->CRLF);
}
}
// message data has been sent
fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply, 0, 3);
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if ($code != 250) {
$this->error =
array("error" => "DATA not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
} | Issues a data command and sends the msg_data to the server
finializing the mail transaction. $msg_data is the message
that is to be send with the headers. Each header needs to be
on a single line followed by a <CRLF> with the message headers
and the message body being seperated by and additional <CRLF>.
Implements rfc 821: DATA <CRLF>
SMTP CODE INTERMEDIATE: 354
[data]
<CRLF>.<CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE FAILURE: 552,554,451,452
SMTP CODE FAILURE: 451,554
SMTP CODE ERROR : 500,501,503,421
@access public
@return bool | Data | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Hello($host = '') {
$this->error = null; // so no confusion is caused
if (!$this->connected()) {
$this->error = array(
"error" => "Called Hello() without being connected");
return false;
}
// if hostname for HELO was not specified send default
if (empty($host)) {
// determine appropriate default to send to server
$host = "localhost";
}
// Send extended hello first (RFC 2821)
if (!$this->SendHello("EHLO", $host)) {
if (!$this->SendHello("HELO", $host)) {
return false;
}
}
return true;
} | Sends the HELO command to the smtp server.
This makes sure that we and the server are in
the same known state.
Implements from rfc 821: HELO <SP> <domain> <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE ERROR : 500, 501, 504, 421
@access public
@return bool | Hello | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Mail($from) {
$this->error = null; // so no confusion is caused
if (!$this->connected()) {
$this->error = array(
"error" => "Called Mail() without being connected");
return false;
}
$useVerp = ($this->do_verp ? "XVERP" : "");
fputs($this->smtp_conn, "MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply, 0, 3);
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if ($code != 250) {
$this->error =
array("error" => "MAIL not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
} | Starts a mail transaction from the email address specified in
$from. Returns true if successful or false otherwise. If True
the mail transaction is started and then one or more Recipient
commands may be called followed by a Data command.
Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE SUCCESS: 552,451,452
SMTP CODE SUCCESS: 500,501,421
@access public
@return bool | Mail | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Quit($close_on_error = true) {
$this->error = null; // so there is no confusion
if (!$this->connected()) {
$this->error = array(
"error" => "Called Quit() without being connected");
return false;
}
// send the quit command to the server
fputs($this->smtp_conn, "quit" . $this->CRLF);
// get any good-bye messages
$byemsg = $this->get_lines();
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
}
$rval = true;
$e = null;
$code = substr($byemsg, 0, 3);
if ($code != 221) {
// use e as a tmp var cause Close will overwrite $this->error
$e = array("error" => "SMTP server rejected quit command",
"smtp_code" => $code,
"smtp_rply" => substr($byemsg, 4));
$rval = false;
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
}
}
if (empty($e) || $close_on_error) {
$this->Close();
}
return $rval;
} | Sends the quit command to the server and then closes the socket
if there is no error or the $close_on_error argument is true.
Implements from rfc 821: QUIT <CRLF>
SMTP CODE SUCCESS: 221
SMTP CODE ERROR : 500
@access public
@return bool | Quit | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Recipient($to) {
$this->error = null; // so no confusion is caused
if (!$this->connected()) {
$this->error = array(
"error" => "Called Recipient() without being connected");
return false;
}
fputs($this->smtp_conn, "RCPT TO:<" . $to . ">" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply, 0, 3);
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if ($code != 250 && $code != 251) {
$this->error =
array("error" => "RCPT not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
} | Sends the command RCPT to the SMTP server with the TO: argument of $to.
Returns true if the recipient was accepted false if it was rejected.
Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
SMTP CODE SUCCESS: 250,251
SMTP CODE FAILURE: 550,551,552,553,450,451,452
SMTP CODE ERROR : 500,501,503,421
@access public
@return bool | Recipient | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Reset() {
$this->error = null; // so no confusion is caused
if (!$this->connected()) {
$this->error = array(
"error" => "Called Reset() without being connected");
return false;
}
fputs($this->smtp_conn, "RSET" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply, 0, 3);
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if ($code != 250) {
$this->error =
array("error" => "RSET failed",
"smtp_code" => $code,
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
} | Sends the RSET command to abort and transaction that is
currently in progress. Returns true if successful false
otherwise.
Implements rfc 821: RSET <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE ERROR : 500,501,504,421
@access public
@return bool | Reset | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function SendAndMail($from) {
$this->error = null; // so no confusion is caused
if (!$this->connected()) {
$this->error = array(
"error" => "Called SendAndMail() without being connected");
return false;
}
fputs($this->smtp_conn, "SAML FROM:" . $from . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply, 0, 3);
if ($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if ($code != 250) {
$this->error =
array("error" => "SAML not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply, 4));
if ($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
} | Starts a mail transaction from the email address specified in
$from. Returns true if successful or false otherwise. If True
the mail transaction is started and then one or more Recipient
commands may be called followed by a Data command. This command
will send the message to the users terminal if they are logged
in and send them an email.
Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE SUCCESS: 552,451,452
SMTP CODE SUCCESS: 500,501,502,421
@access public
@return bool | SendAndMail | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public function Turn() {
$this->error = array("error" => "This method, TURN, of the SMTP " .
"is not implemented");
if ($this->do_debug >= 1) {
echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
}
return false;
} | This is an optional command for SMTP that this class does not
support. This method is here to make the RFC821 Definition
complete for this class and __may__ be implimented in the future
Implements from rfc 821: TURN <CRLF>
SMTP CODE SUCCESS: 250
SMTP CODE FAILURE: 502
SMTP CODE ERROR : 500, 503
@access public
@return bool | Turn | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
private function get_lines() {
$data = "";
while ($str = @fgets($this->smtp_conn, 515)) {
if ($this->do_debug >= 4) {
echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
}
$data .= $str;
if ($this->do_debug >= 4) {
echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
}
// if 4th character is a space, we are done reading, break the loop
if (substr($str, 3, 1) == " ") {break;}
}
return $data;
} | Read in as many lines as possible
either before eof or socket timeout occurs on the operation.
With SMTP we can tell if we have more lines to read if the
4th character is '-' symbol. If it is a space then we don't
need to read anything else.
@access private
@return string | get_lines | php | zblogcn/zblogphp | zb_users/theme/tpure/plugin/phpmailer/smtp.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/theme/tpure/plugin/phpmailer/smtp.php | MIT |
public static function factory($expression, Scheduler__Cron__FieldFactory $fieldFactory = null)
{
$mappings = array(
'@yearly' => '0 0 1 1 *',
'@annually' => '0 0 1 1 *',
'@monthly' => '0 0 1 * *',
'@weekly' => '0 0 * * 0',
'@daily' => '0 0 * * *',
'@hourly' => '0 * * * *'
);
if (isset($mappings[$expression])) {
$expression = $mappings[$expression];
}
return new static($expression, $fieldFactory ?: new Scheduler__Cron__FieldFactory());
} | Factory method to create a new CronExpression.
@param string $expression The CRON expression to create. There are
several special predefined values which can be used to substitute the
CRON expression:
`@yearly`, `@annually` - Run once a year, midnight, Jan. 1 - 0 0 1 1 *
`@monthly` - Run once a month, midnight, first of month - 0 0 1 * *
`@weekly` - Run once a week, midnight on Sun - 0 0 * * 0
`@daily` - Run once a day, midnight - 0 0 * * *
`@hourly` - Run once an hour, first minute - 0 * * * *
@param FieldFactory $fieldFactory Field factory to use
@return CronExpression | factory | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/CronExpression.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/CronExpression.php | MIT |
public function setPart($position, $value)
{
if (!$this->fieldFactory->getField($position)->validate($value)) {
throw new InvalidArgumentException(
'Invalid CRON field value ' . $value . ' at position ' . $position
);
}
$this->cronParts[$position] = $value;
return $this;
} | Set part of the CRON expression
@param int $position The position of the CRON expression to set
@param string $value The value to set
@return CronExpression
@throws \InvalidArgumentException if the value is not valid for the part | setPart | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/CronExpression.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/CronExpression.php | MIT |
public function setMaxIterationCount($maxIterationCount)
{
$this->maxIterationCount = $maxIterationCount;
return $this;
} | Set max iteration count for searching next run dates
@param int $maxIterationCount Max iteration count when searching for next run date
@return CronExpression | setMaxIterationCount | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/CronExpression.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/CronExpression.php | MIT |
public function getNextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false)
{
return $this->getRunDate($currentTime, $nth, false, $allowCurrentDate);
} | Get a next run date relative to the current date or a specific date
@param string|\DateTime $currentTime Relative calculation date
@param int $nth Number of matches to skip before returning a
matching next run date. 0, the default, will return the current
date and time if the next run date falls on the current date and
time. Setting this value to 1 will skip the first match and go to
the second match. Setting this value to 2 will skip the first 2
matches and so on.
@param bool $allowCurrentDate Set to TRUE to return the current date if
it matches the cron expression.
@return \DateTime
@throws \RuntimeException on too many iterations | getNextRunDate | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/CronExpression.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/CronExpression.php | MIT |
public function getPreviousRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false)
{
return $this->getRunDate($currentTime, $nth, true, $allowCurrentDate);
} | Get a previous run date relative to the current date or a specific date
@param string|\DateTime $currentTime Relative calculation date
@param int $nth Number of matches to skip before returning
@param bool $allowCurrentDate Set to TRUE to return the
current date if it matches the cron expression
@return \DateTime
@throws \RuntimeException on too many iterations
@see \Cron\CronExpression::getNextRunDate | getPreviousRunDate | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/CronExpression.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/CronExpression.php | MIT |
public function getMultipleRunDates($total, $currentTime = 'now', $invert = false, $allowCurrentDate = false)
{
$matches = array();
for ($i = 0; $i < max(0, $total); $i++) {
try {
$matches[] = $this->getRunDate($currentTime, $i, $invert, $allowCurrentDate);
} catch (RuntimeException $e) {
break;
}
}
return $matches;
} | Get multiple run dates starting at the current date or a specific date
@param int $total Set the total number of dates to calculate
@param string|\DateTime $currentTime Relative calculation date
@param bool $invert Set to TRUE to retrieve previous dates
@param bool $allowCurrentDate Set to TRUE to return the
current date if it matches the cron expression
@return array Returns an array of run dates | getMultipleRunDates | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/CronExpression.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/CronExpression.php | MIT |
public function getExpression($part = null)
{
if (null === $part) {
return implode(' ', $this->cronParts);
} elseif (array_key_exists($part, $this->cronParts)) {
return $this->cronParts[$part];
}
return null;
} | Get all or part of the CRON expression
@param string $part Specify the part to retrieve or NULL to get the full
cron schedule string.
@return string|null Returns the CRON expression, a part of the
CRON expression, or NULL if the part was specified but not found | getExpression | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/CronExpression.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/CronExpression.php | MIT |
public function __toString()
{
return $this->getExpression();
} | Helper method to output the full expression.
@return string Full CRON expression | __toString | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/CronExpression.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/CronExpression.php | MIT |
public function getField($position)
{
if (!isset($this->fields[$position])) {
switch ($position) {
case 0:
$this->fields[$position] = new Scheduler__Cron__MinutesField();
break;
case 1:
$this->fields[$position] = new Scheduler__Cron__HoursField();
break;
case 2:
$this->fields[$position] = new Scheduler__Cron__DayOfMonthField();
break;
case 3:
$this->fields[$position] = new Scheduler__Cron__MonthField();
break;
case 4:
$this->fields[$position] = new Scheduler__Cron__DayOfWeekField();
break;
case 5:
$this->fields[$position] = new Scheduler__Cron__YearField();
break;
default:
throw new InvalidArgumentException(
$position . ' is not a valid position'
);
}
}
return $this->fields[$position];
} | Get an instance of a field object for a cron expression position
@param int $position CRON expression position value to retrieve
@return FieldInterface
@throws InvalidArgumentException if a position is not valid | getField | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/FieldFactory.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/FieldFactory.php | MIT |
public function isIncrementsOfRanges($value)
{
return strpos($value, '/') !== false;
} | Check if a value is an increments of ranges
@param string $value Value to test
@return bool | isIncrementsOfRanges | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/AbstractField.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/AbstractField.php | MIT |
public function isInRange($dateValue, $value)
{
$parts = array_map('trim', explode('-', $value, 2));
return $dateValue >= $parts[0] && $dateValue <= $parts[1];
} | Test if a value is within a range
@param string $dateValue Set date value
@param string $value Value to test
@return bool | isInRange | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/AbstractField.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/AbstractField.php | MIT |
public function isInIncrementsOfRanges($dateValue, $value)
{
$parts = array_map('trim', explode('/', $value, 2));
$stepSize = isset($parts[1]) ? (int) $parts[1] : 0;
if ($stepSize === 0) {
return false;
}
if (($parts[0] == '*' || $parts[0] === '0')) {
return (int) $dateValue % $stepSize == 0;
}
$range = explode('-', $parts[0], 2);
$offset = $range[0];
$to = isset($range[1]) ? $range[1] : $dateValue;
// Ensure that the date value is within the range
if ($dateValue < $offset || $dateValue > $to) {
return false;
}
if ($dateValue > $offset && 0 === $stepSize) {
return false;
}
for ($i = $offset; $i <= $to; $i+= $stepSize) {
if ($i == $dateValue) {
return true;
}
}
return false;
} | Test if a value is within an increments of ranges (offset[-to]/step size)
@param string $dateValue Set date value
@param string $value Value to test
@return bool | isInIncrementsOfRanges | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/AbstractField.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/AbstractField.php | MIT |
public function getRangeForExpression($expression, $max)
{
$values = array();
if ($this->isRange($expression) || $this->isIncrementsOfRanges($expression)) {
if (!$this->isIncrementsOfRanges($expression)) {
list ($offset, $to) = explode('-', $expression);
$stepSize = 1;
}
else {
$range = array_map('trim', explode('/', $expression, 2));
$stepSize = isset($range[1]) ? $range[1] : 0;
$range = $range[0];
$range = explode('-', $range, 2);
$offset = $range[0];
$to = isset($range[1]) ? $range[1] : $max;
}
$offset = $offset == '*' ? 0 : $offset;
for ($i = $offset; $i <= $to; $i += $stepSize) {
$values[] = $i;
}
sort($values);
}
else {
$values = array($expression);
}
return $values;
} | Returns a range of values for the given cron expression
@param string $expression The expression to evaluate
@param int $max Maximum offset for range
@return array | getRangeForExpression | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/AbstractField.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/AbstractField.php | MIT |
private static function getNearestWeekday($currentYear, $currentMonth, $targetDay)
{
$tday = str_pad($targetDay, 2, '0', STR_PAD_LEFT);
$target = DateTime::createFromFormat('Y-m-d', "$currentYear-$currentMonth-$tday");
$currentWeekday = (int) $target->format('N');
if ($currentWeekday < 6) {
return $target;
}
$lastDayOfMonth = $target->format('t');
foreach (array(-1, 1, -2, 2) as $i) {
$adjusted = $targetDay + $i;
if ($adjusted > 0 && $adjusted <= $lastDayOfMonth) {
$target->setDate($currentYear, $currentMonth, $adjusted);
if ($target->format('N') < 6 && $target->format('m') == $currentMonth) {
return $target;
}
}
}
} | Get the nearest day of the week for a given day in a month
@param int $currentYear Current year
@param int $currentMonth Current month
@param int $targetDay Target day of the month
@return \DateTime Returns the nearest date | getNearestWeekday | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/DayOfMonthField.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/DayOfMonthField.php | MIT |
public function validate($value)
{
// Allow wildcards and a single L
if ($value === '?' || $value === '*' || $value === 'L') {
return true;
}
// If you only contain numbers and are within 1-31
if ((bool) preg_match('/^\d{1,2}$/', $value) && ($value >= 1 && $value <= 31)) {
return true;
}
// If you have a -, we will deal with each of your chunks
if ((bool) preg_match('/-/', $value)) {
// We cannot have a range within a list or vice versa
if ((bool) preg_match('/,/', $value)) {
return false;
}
$chunks = explode('-', $value);
foreach ($chunks as $chunk) {
if (!$this->validate($chunk)) {
return false;
}
}
return true;
}
// If you have a comma, we will deal with each value
if ((bool) preg_match('/,/', $value)) {
// We cannot have a range within a list or vice versa
if ((bool) preg_match('/-/', $value)) {
return false;
}
$chunks = explode(',', $value);
foreach ($chunks as $chunk) {
if (!$this->validate($chunk)) {
return false;
}
}
return true;
}
// If you contain a /, we'll deal with it
if ((bool) preg_match('/\//', $value)) {
$chunks = explode('/', $value);
foreach ($chunks as $chunk) {
if (!$this->validate($chunk)) {
return false;
}
}
return true;
}
// If you end in W, make sure that it has a numeric in front of it
if ((bool) preg_match('/^\d{1,2}W$/', $value)) {
return true;
}
return false;
} | Validates that the value is valid for the Day of the Month field
Days of the month can contain values of 1-31, *, L, or ? by default. This can be augmented with lists via a ',',
ranges via a '-', or with a '[0-9]W' to specify the closest weekday.
@param string $value
@return bool | validate | php | zblogcn/zblogphp | zb_users/plugin/Scheduler/lib/cron/DayOfMonthField.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/Scheduler/lib/cron/DayOfMonthField.php | MIT |
function createLinkstring($para)
{
$arg = '';
foreach ($para as $key => $val) {
$arg .= $key . '='. $val . '&';
}
//去掉最后一个&字符
$arg = substr($arg, 0, count($arg) - 2);
//如果存在转义字符,那么去掉转义
$arg = stripslashes($arg);
return $arg;
} | 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串.
@param $para 需要拼接的数组
return 拼接完成以后的字符串 | createLinkstring | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_core.function.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_core.function.php | MIT |
function paraFilter($para)
{
$para_filter = array();
foreach ($para as $key => $val) {
if ($key == 'sign' || $key == 'sign_type' || $val == '') {
continue;
} else {
$para_filter[$key] = $val;
}
}
return $para_filter;
} | 除去数组中的空值和签名参数.
@param $para 签名参数组
return 去掉空值与签名参数后的新签名参数组 | paraFilter | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_core.function.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_core.function.php | MIT |
function logResult($word = '')
{
global $zbp;
Logs($word);
// $fp = fopen('log.txt', 'a');
// flock($fp, LOCK_EX);
// fwrite($fp, '执行日期:'.strftime('%Y%m%d%H%M%S', time())."\n".$word."\n");
// flock($fp, LOCK_UN);
// fclose($fp);
} | 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
注意:服务器需要开通fopen配置.
@param $word 要写入日志里的文本内容 默认值:空值 | logResult | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_core.function.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_core.function.php | MIT |
function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '')
{
if (trim($input_charset) != '') {
$url = $url . '_input_charset=' . $input_charset;
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); //SSL证书认证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); //严格认证
curl_setopt($curl, CURLOPT_CAINFO, $cacert_url); //证书地址
curl_setopt($curl, CURLOPT_HEADER, 0); // 过滤HTTP头
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 显示输出结果
curl_setopt($curl, CURLOPT_POST, true); // post传输数据
curl_setopt($curl, CURLOPT_POSTFIELDS, $para); // post传输数据
$responseText = curl_exec($curl);
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容
curl_close($curl);
return $responseText;
} | 远程获取数据,POST模式
注意:
1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了
2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem'.
@param $url 指定URL完整路径地址
@param $cacert_url 指定当前工作目录绝对路径
@param $para 请求的数据
@param $input_charset 编码格式。默认值:空值
return 远程输出的数据 | getHttpResponsePOST | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_core.function.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_core.function.php | MIT |
function getHttpResponseGET($url, $cacert_url)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0); // 过滤HTTP头
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 显示输出结果
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); //SSL证书认证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); //严格认证
curl_setopt($curl, CURLOPT_CAINFO, $cacert_url); //证书地址
$responseText = curl_exec($curl);
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容
curl_close($curl);
return $responseText;
} | 远程获取数据,GET模式
注意:
1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了
2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem'.
@param $url 指定URL完整路径地址
@param $cacert_url 指定当前工作目录绝对路径
return 远程输出的数据 | getHttpResponseGET | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_core.function.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_core.function.php | MIT |
public function verifyNotify()
{
if (empty($_POST)) {
//判断POST来的数组是否为空
return false;
} else {
//生成签名结果
$isSign = $this->getSignVeryfy($_POST, $_POST['sign']);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt = 'false';
if (!empty($_POST['notify_id'])) {
$responseTxt = $this->getResponse($_POST['notify_id']);
}
global $zbp;
if ($zbp->Config('alipay')->savelogs) {
//写日志记录
if ($isSign) {
$isSignStr = 'true';
} else {
$isSignStr = 'false';
}
$log_text = 'responseTxt=' . $responseTxt . "\n notify_url_log:isSign=" . $isSignStr . ',';
$log_text = $log_text . createLinkString($_POST);
logResult($log_text);
}
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if (preg_match('/true$/i', $responseTxt) && $isSign) {
return true;
} else {
return false;
}
}
} | 针对notify_url验证消息是否是支付宝发出的合法消息.
@return 验证结果 | verifyNotify | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_notify.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_notify.class.php | MIT |
public function verifyReturn()
{
if (empty($_GET)) {
//判断POST来的数组是否为空
return false;
} else {
//生成签名结果
$isSign = $this->getSignVeryfy($_GET, $_GET['sign']);
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
$responseTxt = 'false';
if (!empty($_GET['notify_id'])) {
$responseTxt = $this->getResponse($_GET['notify_id']);
}
global $zbp;
if ($zbp->Config('alipay')->savelogs) {
//写日志记录
if ($isSign) {
$isSignStr = 'true';
} else {
$isSignStr = 'false';
}
$log_text = 'responseTxt=' . $responseTxt . "\n return_url_log:isSign=" . $isSignStr . ',';
$log_text = $log_text . createLinkString($_GET);
logResult($log_text);
}
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if (preg_match('/true$/i', $responseTxt) && $isSign) {
return true;
} else {
return false;
}
}
} | 针对return_url验证消息是否是支付宝发出的合法消息.
@return 验证结果 | verifyReturn | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_notify.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_notify.class.php | MIT |
public function getResponse($notify_id)
{
$transport = strtolower(trim($this->alipay_config['transport']));
$partner = trim($this->alipay_config['partner']);
$veryfy_url = '';
if ($transport == 'https') {
$veryfy_url = $this->https_verify_url;
} else {
$veryfy_url = $this->http_verify_url;
}
$veryfy_url = $veryfy_url . 'partner=' . $partner . '¬ify_id=' . $notify_id;
$responseTxt = getHttpResponseGET($veryfy_url, $this->alipay_config['cacert']);
return $responseTxt;
} | 获取远程服务器ATN结果,验证返回URL.
@param $notify_id 通知校验ID
@return 服务器ATN结果
验证结果集:
invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
true 返回正确信息
false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟 | getResponse | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_notify.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_notify.class.php | MIT |
public function buildRequestHttp($para_temp)
{
$sResult = '';
//待请求参数数组字符串
$request_data = $this->buildRequestPara($para_temp);
//远程获取数据
$sResult = getHttpResponsePOST($this->alipay_gateway_new, $this->alipay_config['cacert'], $request_data, trim(strtolower($this->alipay_config['input_charset'])));
return $sResult;
} | 建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果.
@param $para_temp 请求参数数组
@return 支付宝处理结果 | buildRequestHttp | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_submit.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_submit.class.php | MIT |
public function buildRequestHttpInFile($para_temp, $file_para_name, $file_name)
{
//待请求参数数组
$para = $this->buildRequestPara($para_temp);
$para[$file_para_name] = '@' . $file_name;
//远程获取数据
$sResult = getHttpResponsePOST($this->alipay_gateway_new, $this->alipay_config['cacert'], $para, trim(strtolower($this->alipay_config['input_charset'])));
return $sResult;
} | 建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果,带文件上传功能.
@param $para_temp 请求参数数组
@param $file_para_name 文件类型的参数名
@param $file_name 文件完整绝对路径
@return 支付宝返回处理结果 | buildRequestHttpInFile | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_submit.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_submit.class.php | MIT |
public function query_timestamp()
{
$url = $this->alipay_gateway_new . 'service=query_timestamp&partner=' . trim(strtolower($this->alipay_config['partner'])) . '&_input_charset=' . trim(strtolower($this->alipay_config['input_charset']));
$encrypt_key = '';
$doc = new DOMDocument();
$doc->load($url);
$itemEncrypt_key = $doc->getElementsByTagName('encrypt_key');
$encrypt_key = $itemEncrypt_key->item(0)->nodeValue;
return $encrypt_key;
} | 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件
return 时间戳字符串. | query_timestamp | php | zblogcn/zblogphp | zb_users/plugin/alipay/lib/alipay_submit.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/alipay/lib/alipay_submit.class.php | MIT |
public static function validate_bucket($bucket)
{
//bucket 正则
$pattern1 = '/^[a-z][-a-z0-9]{4,61}[a-z0-9]$/';
if (!preg_match($pattern1, $bucket)) {
return false;
}
return true;
} | 校验bucket是否合法,bucket规范
1. 由小写字母,数字和横线'-'组成,长度为6~63位
2. 不能以数字作为Bucket开头
3. 不能以'-'作为Bucket的开头或者结尾.
@param string $bucket
@return bool | validate_bucket | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/bcs.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/bcs.class.php | MIT |
public static function validate_object($object)
{
$pattern = '/^\//';
if (empty($object) || !preg_match($pattern, $object)) {
return false;
}
return true;
} | 校验object是否合法,object命名规范
1. object必须以'/'开头.
@param string $object
@return bool | validate_object | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/bcs.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/bcs.class.php | MIT |
private static function array_to_json($array)
{
if (!is_array($array)) {
throw new BCS_Exception("Param must be array in function array_to_json()", -1);
}
self::array_recursive($array, 'addslashes', false);
self::array_recursive($array, 'rawurlencode', false);
return rawurldecode(json_encode($array));
} | 由数组构造json字符串,增加了一些特殊处理以支持特殊字符和不同编码的中文.
@param array $array | array_to_json | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/bcs.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/bcs.class.php | MIT |
private function analyze_user_acl($acl)
{
$result = array();
if (is_array($acl)) {
//(1).a
$result['content'] = $this->check_user_acl($acl);
} elseif (is_string($acl)) {
if (in_array($acl, self::$ACL_TYPES)) {
//(2).a
$result["headers"] = array(
"x-bs-acl" => $acl, );
} else {
//(1).b
$result['content'] = $acl;
}
} else {
throw new BCS_Exception("Invalid acl.", -1);
}
return $result;
} | 根据用户传入的acl,进行相应的处理
(1).设置详细json格式的acl;
a. $acl 为json的array
b. $acl 为json的string
(2).通过acl_type字段进行设置.
@param string|array $acl
@throws BCS_Exception
@return array | analyze_user_acl | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/bcs.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/bcs.class.php | MIT |
public function log($log, $opt)
{
if (isset($opt[self::IMPORT_BCS_LOG_METHOD]) && function_exists($opt[self::IMPORT_BCS_LOG_METHOD])) {
$opt[self::IMPORT_BCS_LOG_METHOD]($log);
} else {
trigger_error($log);
}
} | 内置的日志函数,可以根据用户传入的log函数,进行日志输出.
@param string $log
@param array $opt | log | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/bcs.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/bcs.class.php | MIT |
public function __construct($url = null, $proxy = null, $helpers = null)
{
// Set some default values.
$this->request_url = $url;
$this->method = self::HTTP_GET;
$this->request_headers = array();
$this->request_body = '';
// Set a new Request class if one was set.
if (isset($helpers['request']) && !empty($helpers['request'])) {
$this->request_class = $helpers['request'];
}
// Set a new Request class if one was set.
if (isset($helpers['response']) && !empty($helpers['response'])) {
$this->response_class = $helpers['response'];
}
if ($proxy) {
$this->set_proxy($proxy);
}
return $this;
} | Constructs a new instance of this class.
@param string $url (Optional) The URL to request or service endpoint to query
@param string $proxy (Optional) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`
@param array $helpers (Optional) An associative array of classnames to use for request, and response functionality. Gets passed in automatically by the calling class.
@return $this a reference to the current instance | __construct | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function __destruct()
{
if (isset($this->read_file) && isset($this->read_stream)) {
fclose($this->read_stream);
}
if (isset($this->write_file) && isset($this->write_stream)) {
fclose($this->write_stream);
}
return $this;
} | Destructs the instance. Closes opened file handles.
@return $this a reference to the current instance | __destruct | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_credentials($user, $pass)
{
$this->username = $user;
$this->password = $pass;
return $this;
} | Sets the credentials to use for authentication.
@param string $user (Required) The username to authenticate with
@param string $pass (Required) The password to authenticate with
@return $this a reference to the current instance | set_credentials | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function add_header($key, $value)
{
$this->request_headers[$key] = $value;
return $this;
} | Adds a custom HTTP header to the cURL request.
@param string $key (Required) The custom HTTP header to set
@param mixed $value (Required) The value to assign to the custom HTTP header
@return $this a reference to the current instance | add_header | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function remove_header($key)
{
if (isset($this->request_headers[$key])) {
unset($this->request_headers[$key]);
}
return $this;
} | Removes an HTTP header from the cURL request.
@param string $key (Required) The custom HTTP header to set
@return $this a reference to the current instance | remove_header | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_method($method)
{
$this->method = strtoupper($method);
return $this;
} | Set the method type for the request.
@param string $method (Required) One of the following constants: <HTTP_GET>, <HTTP_POST>, <HTTP_PUT>, <HTTP_HEAD>, <HTTP_DELETE>
@return $this a reference to the current instance | set_method | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_useragent($ua)
{
$this->useragent = $ua;
return $this;
} | Sets a custom useragent string for the class.
@param string $ua (Required) The useragent string to use
@return $this a reference to the current instance | set_useragent | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_body($body)
{
$this->request_body = $body;
return $this;
} | Set the body to send in the request.
@param string $body (Required) The textual content to send along in the body of the request
@return $this a reference to the current instance | set_body | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_request_url($url)
{
$this->request_url = $url;
return $this;
} | Set the URL to make the request to.
@param string $url (Required) The URL to make the request to
@return $this a reference to the current instance | set_request_url | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_curlopts($curlopts)
{
$this->curlopts = $curlopts;
return $this;
} | Set additional CURLOPT settings. These will merge with the default settings, and override if
there is a duplicate.
@param array $curlopts (Optional) A set of key-value pairs that set `CURLOPT` options. These will merge with the existing CURLOPTs, and ones passed here will override the defaults. Keys should be the `CURLOPT_*` constants, not strings.
@return $this a reference to the current instance | set_curlopts | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_read_stream_size($size)
{
$this->read_stream_size = $size;
return $this;
} | Sets the length in bytes to read from the stream while streaming up.
@param int $size (Required) The length in bytes to read from the stream
@return $this a reference to the current instance | set_read_stream_size | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_read_stream($resource, $size = null)
{
if (!isset($size) || $size < 0) {
$stats = fstat($resource);
if ($stats && $stats['size'] >= 0) {
$position = ftell($resource);
if ($position !== false && $position >= 0) {
$size = $stats['size'] - $position;
}
}
}
$this->read_stream = $resource;
return $this->set_read_stream_size($size);
} | Sets the resource to read from while streaming up. Reads the stream from its current position until
EOF or `$size` bytes have been read. If `$size` is not given it will be determined by <php:fstat()> and
<php:ftell()>.
@param resource $resource (Required) The readable resource to read from
@param int $size (Optional) The size of the stream to read
@return $this a reference to the current instance | set_read_stream | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_read_file($location)
{
$this->read_file = $location;
$read_file_handle = fopen($location, 'r');
return $this->set_read_stream($read_file_handle);
} | Sets the file to read from while streaming up.
@param string $location (Required) The readable location to read from
@return $this a reference to the current instance | set_read_file | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_write_stream($resource)
{
$this->write_stream = $resource;
return $this;
} | Sets the resource to write to while streaming down.
@param resource $resource (Required) The writeable resource to write to
@return $this a reference to the current instance | set_write_stream | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_write_file($location)
{
$this->write_file = $location;
$write_file_handle = fopen($location, 'w');
return $this->set_write_stream($write_file_handle);
} | Sets the file to write to while streaming down.
@param string $location (Required) The writeable location to write to
@return $this a reference to the current instance | set_write_file | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_proxy($proxy)
{
$proxy = parse_url($proxy);
$proxy['user'] = isset($proxy['user']) ? $proxy['user'] : null;
$proxy['pass'] = isset($proxy['pass']) ? $proxy['pass'] : null;
$proxy['port'] = isset($proxy['port']) ? $proxy['port'] : null;
$this->proxy = $proxy;
return $this;
} | Set the proxy to use for making requests.
@param string $proxy (Required) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`
@return $this a reference to the current instance | set_proxy | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function set_seek_position($position)
{
$this->seek_position = isset($position) ? (int) $position : null;
return $this;
} | Set the intended starting seek position.
@param int $position (Required) The byte-position of the stream to begin reading from
@return $this a reference to the current instance | set_seek_position | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function register_streaming_read_callback($callback)
{
$this->registered_streaming_read_callback = $callback;
return $this;
} | Register a callback function to execute whenever a data stream is read from using
<CFRequest::streaming_read_callback()>.
The user-defined callback function should accept three arguments:
<ul>
<li><code>$curl_handle</code> - <code>resource</code> - Required - The cURL handle resource that represents the in-progress transfer.</li>
<li><code>$file_handle</code> - <code>resource</code> - Required - The file handle resource that represents the file on the local file system.</li>
<li><code>$length</code> - <code>integer</code> - Required - The length in kilobytes of the data chunk that was transferred.</li>
</ul>
@param string|array|function $callback (Required) The callback function is called by <php:call_user_func()>, so you can pass the following values: <ul>
<li>The name of a global function to execute, passed as a string.</li>
<li>A method to execute, passed as <code>array('ClassName', 'MethodName')</code>.</li>
<li>An anonymous function (PHP 5.3+).</li></ul>
@return $this a reference to the current instance | register_streaming_read_callback | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function register_streaming_write_callback($callback)
{
$this->registered_streaming_write_callback = $callback;
return $this;
} | Register a callback function to execute whenever a data stream is written to using
<CFRequest::streaming_write_callback()>.
The user-defined callback function should accept two arguments:
<ul>
<li><code>$curl_handle</code> - <code>resource</code> - Required - The cURL handle resource that represents the in-progress transfer.</li>
<li><code>$length</code> - <code>integer</code> - Required - The length in kilobytes of the data chunk that was transferred.</li>
</ul>
@param string|array|function $callback (Required) The callback function is called by <php:call_user_func()>, so you can pass the following values: <ul>
<li>The name of a global function to execute, passed as a string.</li>
<li>A method to execute, passed as <code>array('ClassName', 'MethodName')</code>.</li>
<li>An anonymous function (PHP 5.3+).</li></ul>
@return $this a reference to the current instance | register_streaming_write_callback | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function streaming_read_callback($curl_handle, $file_handle, $length)
{
// Once we've sent as much as we're supposed to send...
if ($this->read_stream_read >= $this->read_stream_size) {
// Send EOF
return '';
}
// If we're at the beginning of an upload and need to seek...
if ($this->read_stream_read == 0 && isset($this->seek_position) && $this->seek_position !== ftell($this->read_stream)) {
if (fseek($this->read_stream, $this->seek_position) !== 0) {
throw new BCS_RequestCore_Exception('The stream does not support seeking and is either not at the requested position or the position is unknown.');
}
}
$read = fread($this->read_stream, min($this->read_stream_size - $this->read_stream_read, $length)); // Remaining upload data or cURL's requested chunk size
$this->read_stream_read += strlen($read);
$out = $read === false ? '' : $read;
// Execute callback function
if ($this->registered_streaming_read_callback) {
call_user_func($this->registered_streaming_read_callback, $curl_handle, $file_handle, $out);
}
return $out;
} | A callback function that is invoked by cURL for streaming up.
@param resource $curl_handle (Required) The cURL handle for the request
@param resource $file_handle (Required) The open file handle resource
@param int $length (Required) The maximum number of bytes to read
@return binary binary data from a stream | streaming_read_callback | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function streaming_write_callback($curl_handle, $data)
{
$length = strlen($data);
$written_total = 0;
$written_last = 0;
while ($written_total < $length) {
$written_last = fwrite($this->write_stream, substr($data, $written_total));
if ($written_last === false) {
return $written_total;
}
$written_total += $written_last;
}
// Execute callback function
if ($this->registered_streaming_write_callback) {
call_user_func($this->registered_streaming_write_callback, $curl_handle, $written_total);
}
return $written_total;
} | A callback function that is invoked by cURL for streaming down.
@param resource $curl_handle (Required) The cURL handle for the request
@param binary $data (Required) The data to write
@return int the number of bytes written | streaming_write_callback | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function send_request($parse = false)
{
if (false === $this->isBaeEnv()) {
set_time_limit(0);
}
$curl_handle = $this->prep_request();
$this->response = curl_exec($curl_handle);
if ($this->response === false ||
($this->method === self::HTTP_GET &&
curl_errno($curl_handle) === CURLE_PARTIAL_FILE)) {
throw new BCS_RequestCore_Exception('cURL resource: ' . (string) $curl_handle . '; cURL error: ' . curl_error($curl_handle) . ' (' . curl_errno($curl_handle) . ')');
} | Sends the request, calling necessary utility functions to update built-in properties.
@param bool $parse (Optional) Whether to parse the response with BCS_ResponseCore or not
@return string the resulting unparsed data from the request | send_request | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function get_response_header($header = null)
{
if ($header) {
// return $this->response_headers [strtolower ( $header )];
return $this->response_headers[$header];
}
return $this->response_headers;
} | Get the HTTP response headers from the request.
@param string $header (Optional) A specific header value to return. Defaults to all headers.
@return string|array all or selected header values | get_response_header | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function get_response_body()
{
return $this->response_body;
} | Get the HTTP response body from the request.
@return string the response body | get_response_body | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function get_response_code()
{
return $this->response_code;
} | Get the HTTP response code from the request.
@return string the HTTP response code | get_response_code | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
public function __construct($header, $body, $status = null)
{
$this->header = $header;
$this->body = $body;
$this->status = $status;
return $this;
} | Constructs a new instance of this class.
@param array $header (Required) Associative array of HTTP headers (typically returned by <BCS_RequestCore::get_response_header()>)
@param string $body (Required) XML-formatted response from AWS
@param int $status (Optional) HTTP response status code from the request
@return object contains an <php:array> `header` property (HTTP headers as an associative array), a <php:SimpleXMLElement> or <php:string> `body` property, and an <php:integer> `status` code | __construct | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/bcs/libs/requestcore/requestcore.class.php | MIT |
function Qiniu_RSF_ListPrefix(
$self,
$bucket,
$prefix = '',
$marker = '',
$limit = 0
) // => ($items, $markerOut, $err)
{
global $QINIU_RSF_HOST;
$query = array('bucket' => $bucket);
if (!empty($prefix)) {
$query['prefix'] = $prefix;
}
if (!empty($marker)) {
$query['marker'] = $marker;
}
if (!empty($limit)) {
$query['limit'] = $limit;
}
$url = $QINIU_RSF_HOST . '/list?' . http_build_query($query);
list($ret, $err) = Qiniu_Client_Call($self, $url);
if ($err !== null) {
return array(null, '', $err);
}
$items = $ret['items'];
if (empty($ret['marker'])) {
$markerOut = '';
$err = Qiniu_RSF_EOF;
} else {
$markerOut = $ret['marker'];
}
return array($items, $markerOut, $err);
} | 1. 首次请求 marker = ""
2. 无论 err 值如何,均应该先看 items 是否有内容
3. 如果后续没有更多数据,err 返回 EOF,markerOut 返回 ""(但不通过该特征来判断是否结束). | Qiniu_RSF_ListPrefix | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/qiniu/rsf.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/qiniu/rsf.php | MIT |
public function set_enable_domain_style($enable_domain_style = true)
{
$this->enable_domain_style = $enable_domain_style;
} | 设置路径形式,如果为true,则启用三级域名,如bucket.oss.aliyuncs.com.
@author [email protected]
@param bool $enable_domain_style
@since 2012-06-11
@return void | set_enable_domain_style | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/sdk.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/sdk.class.php | MIT |
public function list_object($bucket, $options = null)
{
//options
$this->validate_options($options);
if (!$options) {
$options = array();
}
//bucket
$this->is_empty($bucket, OSS_BUCKET_IS_NOT_ALLOWED_EMPTY);
$options[self::OSS_BUCKET] = $bucket;
$options[self::OSS_METHOD] = 'GET';
$options[self::OSS_OBJECT] = '/';
$options[self::OSS_HEADERS] = array(
self::OSS_DELIMITER => isset($options[self::OSS_DELIMITER]) ? $options[self::OSS_DELIMITER] : '/',
self::OSS_PREFIX => isset($options[self::OSS_PREFIX]) ? $options[self::OSS_PREFIX] : '',
self::OSS_MAX_KEYS => isset($options[self::OSS_MAX_KEYS]) ? $options[self::OSS_MAX_KEYS] : self::OSS_MAX_KEYS_VALUE,
self::OSS_MARKER => isset($options[self::OSS_MARKER]) ? $options[self::OSS_MARKER] : '',
);
$response = $this->auth($options);
return $response;
} | List Object.
@param string $bucket (Required)
@param array $options (Optional)
其中options中的参数如下
$options = array(
'max-keys' => max-keys用于限定此次返回object的最大数,如果不设定,默认为100,max-keys取值不能大于100。
'prefix' => 限定返回的object key必须以prefix作为前缀。注意使用prefix查询时,返回的key中仍会包含prefix。
'delimiter' => 是一个用于对Object名字进行分组的字符。所有名字包含指定的前缀且第一次出现delimiter字符之间的object作为一组元素
'marker' => 用户设定结果从marker之后按字母排序的第一个开始返回。
)
其中 prefix,marker用来实现分页显示效果,参数的长度必须小于256字节。
@throws OSS_Exception
@author [email protected]
@since 2011-11-14
@return ResponseCore | list_object | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/sdk.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/sdk.class.php | MIT |
public function upload_file_by_content($bucket, $object, $options = null)
{
//options
$this->validate_options($options);
if (!$options) {
$options = array();
}
//bucket
$this->is_empty($bucket, OSS_BUCKET_IS_NOT_ALLOWED_EMPTY);
//object
$this->is_empty($object, OSS_OBJECT_IS_NOT_ALLOWED_EMPTY);
//内容校验
$this->validate_content($options);
$objArr = explode('/', $object);
$basename = array_pop($objArr);
$extension = explode('.', $basename);
$extension = array_pop($extension);
$content_type = MimeTypes::get_mimetype(strtolower($extension));
$options[self::OSS_BUCKET] = $bucket;
$options[self::OSS_METHOD] = 'PUT';
$options[self::OSS_OBJECT] = $object;
if (!isset($options[self::OSS_LENGTH])) {
$options[self::OSS_CONTENT_LENGTH] = strlen($options[self::OSS_CONTENT]);
} else {
$options[self::OSS_CONTENT_LENGTH] = $options[self::OSS_LENGTH];
}
if (!isset($options[self::OSS_CONTENT_TYPE]) && isset($content_type) && !empty($content_type)) {
$options[self::OSS_CONTENT_TYPE] = $content_type;
}
$response = $this->auth($options);
return $response;
} | 通过在http body中添加内容来上传文件,适合比较小的文件
根据api约定,需要在http header中增加content-length字段.
@param string $bucket (Required)
@param string $object (Required)
@param string $content (Required)
@param array $options (Optional)
@author [email protected]
@since 2011-11-14
@return ResponseCore | upload_file_by_content | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/sdk.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/sdk.class.php | MIT |
public function __construct($url = null, $proxy = null, $helpers = null)
{
// Set some default values.
$this->request_url = $url;
$this->method = self::HTTP_GET;
$this->request_headers = array();
$this->request_body = '';
// Set a new Request class if one was set.
if (isset($helpers['request']) && !empty($helpers['request'])) {
$this->request_class = $helpers['request'];
}
// Set a new Request class if one was set.
if (isset($helpers['response']) && !empty($helpers['response'])) {
$this->response_class = $helpers['response'];
}
if ($proxy) {
$this->set_proxy($proxy);
}
return $this;
} | Constructs a new instance of this class.
@param string $url (Optional) The URL to request or service endpoint to query
@param string $proxy (Optional) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`
@param array $helpers (Optional) An associative array of classnames to use for request, and response functionality. Gets passed in automatically by the calling class.
@return $this a reference to the current instance | __construct | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function __destruct()
{
if (isset($this->read_file) && isset($this->read_stream)) {
fclose($this->read_stream);
}
if (isset($this->write_file) && isset($this->write_stream)) {
fclose($this->write_stream);
}
return $this;
} | Destructs the instance. Closes opened file handles.
@return $this a reference to the current instance | __destruct | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_credentials($user, $pass)
{
$this->username = $user;
$this->password = $pass;
return $this;
} | Sets the credentials to use for authentication.
@param string $user (Required) The username to authenticate with
@param string $pass (Required) The password to authenticate with
@return $this a reference to the current instance | set_credentials | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function add_header($key, $value)
{
$this->request_headers[$key] = $value;
return $this;
} | Adds a custom HTTP header to the cURL request.
@param string $key (Required) The custom HTTP header to set
@param mixed $value (Required) The value to assign to the custom HTTP header
@return $this a reference to the current instance | add_header | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function remove_header($key)
{
if (isset($this->request_headers[$key])) {
unset($this->request_headers[$key]);
}
return $this;
} | Removes an HTTP header from the cURL request.
@param string $key (Required) The custom HTTP header to set
@return $this a reference to the current instance | remove_header | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_method($method)
{
$this->method = strtoupper($method);
return $this;
} | Set the method type for the request.
@param string $method (Required) One of the following constants: <HTTP_GET>, <HTTP_POST>, <HTTP_PUT>, <HTTP_HEAD>, <HTTP_DELETE>
@return $this a reference to the current instance | set_method | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_useragent($ua)
{
$this->useragent = $ua;
return $this;
} | Sets a custom useragent string for the class.
@param string $ua (Required) The useragent string to use
@return $this a reference to the current instance | set_useragent | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_body($body)
{
$this->request_body = $body;
return $this;
} | Set the body to send in the request.
@param string $body (Required) The textual content to send along in the body of the request
@return $this a reference to the current instance | set_body | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_request_url($url)
{
$this->request_url = $url;
return $this;
} | Set the URL to make the request to.
@param string $url (Required) The URL to make the request to
@return $this a reference to the current instance | set_request_url | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_curlopts($curlopts)
{
$this->curlopts = $curlopts;
return $this;
} | Set additional CURLOPT settings. These will merge with the default settings, and override if
there is a duplicate.
@param array $curlopts (Optional) A set of key-value pairs that set `CURLOPT` options. These will merge with the existing CURLOPTs, and ones passed here will override the defaults. Keys should be the `CURLOPT_*` constants, not strings.
@return $this a reference to the current instance | set_curlopts | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_read_stream_size($size)
{
$this->read_stream_size = $size;
return $this;
} | Sets the length in bytes to read from the stream while streaming up.
@param int $size (Required) The length in bytes to read from the stream
@return $this a reference to the current instance | set_read_stream_size | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_read_stream($resource, $size = null)
{
if (!isset($size) || $size < 0) {
$stats = fstat($resource);
if ($stats && $stats['size'] >= 0) {
$position = ftell($resource);
if ($position !== false && $position >= 0) {
$size = $stats['size'] - $position;
}
}
}
$this->read_stream = $resource;
return $this->set_read_stream_size($size);
} | Sets the resource to read from while streaming up. Reads the stream from its current position until
EOF or `$size` bytes have been read. If `$size` is not given it will be determined by <php:fstat()> and
<php:ftell()>.
@param resource $resource (Required) The readable resource to read from
@param int $size (Optional) The size of the stream to read
@return $this a reference to the current instance | set_read_stream | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_read_file($location)
{
$this->read_file = $location;
$read_file_handle = fopen($location, 'r');
return $this->set_read_stream($read_file_handle);
} | Sets the file to read from while streaming up.
@param string $location (Required) The readable location to read from
@return $this a reference to the current instance | set_read_file | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_write_stream($resource)
{
$this->write_stream = $resource;
return $this;
} | Sets the resource to write to while streaming down.
@param resource $resource (Required) The writeable resource to write to
@return $this a reference to the current instance | set_write_stream | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_write_file($location)
{
$this->write_file = $location;
$write_file_handle = fopen($location, 'w');
return $this->set_write_stream($write_file_handle);
} | Sets the file to write to while streaming down.
@param string $location (Required) The writeable location to write to
@return $this a reference to the current instance | set_write_file | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_proxy($proxy)
{
$proxy = parse_url($proxy);
$proxy['user'] = isset($proxy['user']) ? $proxy['user'] : null;
$proxy['pass'] = isset($proxy['pass']) ? $proxy['pass'] : null;
$proxy['port'] = isset($proxy['port']) ? $proxy['port'] : null;
$this->proxy = $proxy;
return $this;
} | Set the proxy to use for making requests.
@param string $proxy (Required) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port`
@return $this a reference to the current instance | set_proxy | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function set_seek_position($position)
{
$this->seek_position = isset($position) ? (int) $position : null;
return $this;
} | Set the intended starting seek position.
@param int $position (Required) The byte-position of the stream to begin reading from
@return $this a reference to the current instance | set_seek_position | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function register_streaming_read_callback($callback)
{
$this->registered_streaming_read_callback = $callback;
return $this;
} | Register a callback function to execute whenever a data stream is read from using
<CFRequest::streaming_read_callback()>.
The user-defined callback function should accept three arguments:
<ul>
<li><code>$curl_handle</code> - <code>resource</code> - Required - The cURL handle resource that represents the in-progress transfer.</li>
<li><code>$file_handle</code> - <code>resource</code> - Required - The file handle resource that represents the file on the local file system.</li>
<li><code>$length</code> - <code>integer</code> - Required - The length in kilobytes of the data chunk that was transferred.</li>
</ul>
@param string|array|function $callback (Required) The callback function is called by <php:call_user_func()>, so you can pass the following values: <ul>
<li>The name of a global function to execute, passed as a string.</li>
<li>A method to execute, passed as <code>array('ClassName', 'MethodName')</code>.</li>
<li>An anonymous function (PHP 5.3+).</li></ul>
@return $this a reference to the current instance | register_streaming_read_callback | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
public function register_streaming_write_callback($callback)
{
$this->registered_streaming_write_callback = $callback;
return $this;
} | Register a callback function to execute whenever a data stream is written to using
<CFRequest::streaming_write_callback()>.
The user-defined callback function should accept two arguments:
<ul>
<li><code>$curl_handle</code> - <code>resource</code> - Required - The cURL handle resource that represents the in-progress transfer.</li>
<li><code>$length</code> - <code>integer</code> - Required - The length in kilobytes of the data chunk that was transferred.</li>
</ul>
@param string|array|function $callback (Required) The callback function is called by <php:call_user_func()>, so you can pass the following values: <ul>
<li>The name of a global function to execute, passed as a string.</li>
<li>A method to execute, passed as <code>array('ClassName', 'MethodName')</code>.</li>
<li>An anonymous function (PHP 5.3+).</li></ul>
@return $this a reference to the current instance | register_streaming_write_callback | php | zblogcn/zblogphp | zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | https://github.com/zblogcn/zblogphp/blob/master/zb_users/plugin/CloudStorage/api/oss/lib/requestcore/requestcore.class.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.