TimeTrex Community Edition v16.2.0
This commit is contained in:
1243
classes/pear/HTTP/Download.php
Normal file
1243
classes/pear/HTTP/Download.php
Normal file
File diff suppressed because it is too large
Load Diff
122
classes/pear/HTTP/Download/Archive.php
Normal file
122
classes/pear/HTTP/Download/Archive.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTTP::Download::Archive
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Download
|
||||
* @author Michael Wallner <mike@php.net>
|
||||
* @copyright 2003-2005 Michael Wallner
|
||||
* @license BSD, revisewd
|
||||
* @version CVS: $Id: Archive.php 304423 2010-10-15 13:36:46Z clockwerx $
|
||||
* @link http://pear.php.net/package/HTTP_Download
|
||||
*/
|
||||
|
||||
/**
|
||||
* Requires HTTP_Download
|
||||
*/
|
||||
require_once 'HTTP/Download.php';
|
||||
|
||||
/**
|
||||
* Requires System
|
||||
*/
|
||||
require_once 'System.php';
|
||||
|
||||
/**
|
||||
* HTTP_Download_Archive
|
||||
*
|
||||
* Helper class for sending Archives.
|
||||
*
|
||||
* @access public
|
||||
* @version $Revision: 304423 $
|
||||
*/
|
||||
class HTTP_Download_Archive
|
||||
{
|
||||
/**
|
||||
* Send a bunch of files or directories as an archive
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* require_once 'HTTP/Download/Archive.php';
|
||||
* HTTP_Download_Archive::send(
|
||||
* 'myArchive.tgz',
|
||||
* '/var/ftp/pub/mike',
|
||||
* HTTP_DOWNLOAD_BZ2,
|
||||
* '',
|
||||
* '/var/ftp/pub'
|
||||
* );
|
||||
* </code>
|
||||
*
|
||||
* @see Archive_Tar::createModify()
|
||||
* @static
|
||||
* @access public
|
||||
* @return mixed Returns true on success or PEAR_Error on failure.
|
||||
* @param string $name name the sent archive should have
|
||||
* @param mixed $files files/directories
|
||||
* @param string $type archive type
|
||||
* @param string $add_path path that should be prepended to the files
|
||||
* @param string $strip_path path that should be stripped from the files
|
||||
*/
|
||||
function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_path = '')
|
||||
{
|
||||
$tmp = System::mktemp();
|
||||
|
||||
switch ($type = strToUpper($type))
|
||||
{
|
||||
case HTTP_DOWNLOAD_TAR:
|
||||
include_once 'Archive/Tar.php';
|
||||
$arc = new Archive_Tar($tmp);
|
||||
$content_type = 'x-tar';
|
||||
break;
|
||||
|
||||
case HTTP_DOWNLOAD_TGZ:
|
||||
include_once 'Archive/Tar.php';
|
||||
$arc = new Archive_Tar($tmp, 'gz');
|
||||
$content_type = 'x-gzip';
|
||||
break;
|
||||
|
||||
case HTTP_DOWNLOAD_BZ2:
|
||||
include_once 'Archive/Tar.php';
|
||||
$arc = new Archive_Tar($tmp, 'bz2');
|
||||
$content_type = 'x-bzip2';
|
||||
break;
|
||||
|
||||
case HTTP_DOWNLOAD_ZIP:
|
||||
include_once 'Archive/Zip.php';
|
||||
$arc = new Archive_Zip($tmp);
|
||||
$content_type = 'x-zip';
|
||||
break;
|
||||
|
||||
default:
|
||||
return PEAR::raiseError(
|
||||
'Archive type not supported: ' . $type,
|
||||
HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE
|
||||
);
|
||||
}
|
||||
|
||||
if ($type == HTTP_DOWNLOAD_ZIP) {
|
||||
$options = array( 'add_path' => $add_path,
|
||||
'remove_path' => $strip_path);
|
||||
if (!$arc->create($files, $options)) {
|
||||
return PEAR::raiseError('Archive creation failed.');
|
||||
}
|
||||
} else {
|
||||
if (!$e = $arc->createModify($files, $add_path, $strip_path)) {
|
||||
return PEAR::raiseError('Archive creation failed.');
|
||||
}
|
||||
if (PEAR::isError($e)) {
|
||||
return $e;
|
||||
}
|
||||
}
|
||||
unset($arc);
|
||||
|
||||
$dl = new HTTP_Download(array('file' => $tmp));
|
||||
$dl->setContentType('application/' . $content_type);
|
||||
$dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $name);
|
||||
return $dl->send();
|
||||
}
|
||||
}
|
||||
?>
|
177
classes/pear/HTTP/Download/PgLOB.php
Normal file
177
classes/pear/HTTP/Download/PgLOB.php
Normal file
@ -0,0 +1,177 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTTP::Download::PgLOB
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Download
|
||||
* @author Michael Wallner <mike@php.net>
|
||||
* @copyright 2003-2005 Michael Wallner
|
||||
* @license BSD, revised
|
||||
* @version CVS: $Id: PgLOB.php 304423 2010-10-15 13:36:46Z clockwerx $
|
||||
* @link http://pear.php.net/package/HTTP_Download
|
||||
*/
|
||||
|
||||
$GLOBALS['_HTTP_Download_PgLOB_Connection'] = null;
|
||||
stream_register_wrapper('pglob', 'HTTP_Download_PgLOB');
|
||||
|
||||
/**
|
||||
* PgSQL large object stream interface for HTTP_Download
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* require_once 'HTTP/Download.php';
|
||||
* require_once 'HTTP/Download/PgLOB.php';
|
||||
* $db = &DB::connect('pgsql://user:pass@host/db');
|
||||
* // or $db = pg_connect(...);
|
||||
* $lo = HTTP_Download_PgLOB::open($db, 12345);
|
||||
* $dl = &new HTTP_Download;
|
||||
* $dl->setResource($lo);
|
||||
* $dl->send()
|
||||
* </code>
|
||||
*
|
||||
* @access public
|
||||
* @version $Revision: 304423 $
|
||||
*/
|
||||
class HTTP_Download_PgLOB
|
||||
{
|
||||
/**
|
||||
* Set Connection
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return bool
|
||||
* @param mixed $conn
|
||||
*/
|
||||
function setConnection($conn)
|
||||
{
|
||||
if (is_a($conn, 'DB_Common')) {
|
||||
$conn = $conn->dbh;
|
||||
} elseif ( is_a($conn, 'MDB_Common') ||
|
||||
is_a($conn, 'MDB2_Driver_Common')) {
|
||||
$conn = $conn->connection;
|
||||
}
|
||||
if ($isResource = is_resource($conn)) {
|
||||
$GLOBALS['_HTTP_Download_PgLOB_Connection'] = $conn;
|
||||
}
|
||||
return $isResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Connection
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return resource
|
||||
*/
|
||||
function getConnection()
|
||||
{
|
||||
if (is_resource($GLOBALS['_HTTP_Download_PgLOB_Connection'])) {
|
||||
return $GLOBALS['_HTTP_Download_PgLOB_Connection'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return resource
|
||||
* @param mixed $conn
|
||||
* @param int $loid
|
||||
* @param string $mode
|
||||
*/
|
||||
function open($conn, $loid, $mode = 'rb')
|
||||
{
|
||||
HTTP_Download_PgLOB::setConnection($conn);
|
||||
return fopen('pglob:///'. $loid, $mode);
|
||||
}
|
||||
|
||||
/**#@+
|
||||
* Stream Interface Implementation
|
||||
* @internal
|
||||
*/
|
||||
var $ID = 0;
|
||||
var $size = 0;
|
||||
var $conn = null;
|
||||
var $handle = null;
|
||||
|
||||
function stream_open($path, $mode)
|
||||
{
|
||||
if (!$this->conn = HTTP_Download_PgLOB::getConnection()) {
|
||||
return false;
|
||||
}
|
||||
if (!preg_match('/(\d+)/', $path, $matches)) {
|
||||
return false;
|
||||
}
|
||||
$this->ID = $matches[1];
|
||||
|
||||
if (!pg_query($this->conn, 'BEGIN')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->handle = pg_lo_open($this->conn, $this->ID, $mode);
|
||||
if (!is_resource($this->handle)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// fetch size of lob
|
||||
pg_lo_seek($this->handle, 0, PGSQL_SEEK_END);
|
||||
$this->size = (int) pg_lo_tell($this->handle);
|
||||
pg_lo_seek($this->handle, 0, PGSQL_SEEK_SET);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function stream_read($length)
|
||||
{
|
||||
return pg_lo_read($this->handle, $length);
|
||||
}
|
||||
|
||||
function stream_seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
return pg_lo_seek($this->handle, $offset, $whence);
|
||||
}
|
||||
|
||||
function stream_tell()
|
||||
{
|
||||
return pg_lo_tell($this->handle);
|
||||
}
|
||||
|
||||
function stream_eof()
|
||||
{
|
||||
return pg_lo_tell($this->handle) >= $this->size;
|
||||
}
|
||||
|
||||
function stream_flush()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
function stream_stat()
|
||||
{
|
||||
return array('size' => $this->size, 'ino' => $this->ID);
|
||||
}
|
||||
|
||||
function stream_write($data)
|
||||
{
|
||||
return pg_lo_write($this->handle, $data);
|
||||
}
|
||||
|
||||
function stream_close()
|
||||
{
|
||||
if (pg_lo_close($this->handle)) {
|
||||
return pg_query($this->conn, 'COMMIT');
|
||||
} else {
|
||||
pg_query($this->conn ,'ROLLBACK');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**#@-*/
|
||||
}
|
||||
|
||||
?>
|
531
classes/pear/HTTP/Header.php
Normal file
531
classes/pear/HTTP/Header.php
Normal file
@ -0,0 +1,531 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTTP::Header
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Header
|
||||
* @author Wolfram Kriesing <wk@visionp.de>
|
||||
* @author Davey Shafik <davey@php.net>
|
||||
* @author Michael Wallner <mike@php.net>
|
||||
* @copyright 2003-2005 The Authors
|
||||
* @license BSD, revised
|
||||
* @version CVS: $Id: Header.php,v 1.32 2005/11/08 19:06:10 mike Exp $
|
||||
* @link http://pear.php.net/package/HTTP_Header
|
||||
*/
|
||||
|
||||
/**
|
||||
* Requires HTTP
|
||||
*/
|
||||
require_once 'HTTP.php';
|
||||
|
||||
/**#@+
|
||||
* Information Codes
|
||||
*/
|
||||
define('HTTP_HEADER_STATUS_100', '100 Continue');
|
||||
define('HTTP_HEADER_STATUS_101', '101 Switching Protocols');
|
||||
define('HTTP_HEADER_STATUS_102', '102 Processing');
|
||||
define('HTTP_HEADER_STATUS_INFORMATIONAL',1);
|
||||
/**#@-*/
|
||||
|
||||
/**#+
|
||||
* Success Codes
|
||||
*/
|
||||
define('HTTP_HEADER_STATUS_200', '200 OK');
|
||||
define('HTTP_HEADER_STATUS_201', '201 Created');
|
||||
define('HTTP_HEADER_STATUS_202', '202 Accepted');
|
||||
define('HTTP_HEADER_STATUS_203', '203 Non-Authoritative Information');
|
||||
define('HTTP_HEADER_STATUS_204', '204 No Content');
|
||||
define('HTTP_HEADER_STATUS_205', '205 Reset Content');
|
||||
define('HTTP_HEADER_STATUS_206', '206 Partial Content');
|
||||
define('HTTP_HEADER_STATUS_207', '207 Multi-Status');
|
||||
define('HTTP_HEADER_STATUS_SUCCESSFUL',2);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Redirection Codes
|
||||
*/
|
||||
define('HTTP_HEADER_STATUS_300', '300 Multiple Choices');
|
||||
define('HTTP_HEADER_STATUS_301', '301 Moved Permanently');
|
||||
define('HTTP_HEADER_STATUS_302', '302 Found');
|
||||
define('HTTP_HEADER_STATUS_303', '303 See Other');
|
||||
define('HTTP_HEADER_STATUS_304', '304 Not Modified');
|
||||
define('HTTP_HEADER_STATUS_305', '305 Use Proxy');
|
||||
define('HTTP_HEADER_STATUS_306', '306 (Unused)');
|
||||
define('HTTP_HEADER_STATUS_307', '307 Temporary Redirect');
|
||||
define('HTTP_HEADER_STATUS_REDIRECT',3);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Error Codes
|
||||
*/
|
||||
define('HTTP_HEADER_STATUS_400', '400 Bad Request');
|
||||
define('HTTP_HEADER_STATUS_401', '401 Unauthorized');
|
||||
define('HTTP_HEADER_STATUS_402', '402 Payment Granted');
|
||||
define('HTTP_HEADER_STATUS_403', '403 Forbidden');
|
||||
define('HTTP_HEADER_STATUS_404', '404 File Not Found');
|
||||
define('HTTP_HEADER_STATUS_405', '405 Method Not Allowed');
|
||||
define('HTTP_HEADER_STATUS_406', '406 Not Acceptable');
|
||||
define('HTTP_HEADER_STATUS_407', '407 Proxy Authentication Required');
|
||||
define('HTTP_HEADER_STATUS_408', '408 Request Time-out');
|
||||
define('HTTP_HEADER_STATUS_409', '409 Conflict');
|
||||
define('HTTP_HEADER_STATUS_410', '410 Gone');
|
||||
define('HTTP_HEADER_STATUS_411', '411 Length Required');
|
||||
define('HTTP_HEADER_STATUS_412', '412 Precondition Failed');
|
||||
define('HTTP_HEADER_STATUS_413', '413 Request Entity Too Large');
|
||||
define('HTTP_HEADER_STATUS_414', '414 Request-URI Too Large');
|
||||
define('HTTP_HEADER_STATUS_415', '415 Unsupported Media Type');
|
||||
define('HTTP_HEADER_STATUS_416', '416 Requested range not satisfiable');
|
||||
define('HTTP_HEADER_STATUS_417', '417 Expectation Failed');
|
||||
define('HTTP_HEADER_STATUS_422', '422 Unprocessable Entity');
|
||||
define('HTTP_HEADER_STATUS_423', '423 Locked');
|
||||
define('HTTP_HEADER_STATUS_424', '424 Failed Dependency');
|
||||
define('HTTP_HEADER_STATUS_CLIENT_ERROR',4);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Server Errors
|
||||
*/
|
||||
define('HTTP_HEADER_STATUS_500', '500 Internal Server Error');
|
||||
define('HTTP_HEADER_STATUS_501', '501 Not Implemented');
|
||||
define('HTTP_HEADER_STATUS_502', '502 Bad Gateway');
|
||||
define('HTTP_HEADER_STATUS_503', '503 Service Unavailable');
|
||||
define('HTTP_HEADER_STATUS_504', '504 Gateway Time-out');
|
||||
define('HTTP_HEADER_STATUS_505', '505 HTTP Version not supported');
|
||||
define('HTTP_HEADER_STATUS_507', '507 Insufficient Storage');
|
||||
define('HTTP_HEADER_STATUS_SERVER_ERROR',5);
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* HTTP_Header
|
||||
*
|
||||
* @package HTTP_Header
|
||||
* @category HTTP
|
||||
* @access public
|
||||
* @version $Revision: 1.32 $
|
||||
*/
|
||||
class HTTP_Header extends HTTP
|
||||
{
|
||||
/**
|
||||
* Default Headers
|
||||
*
|
||||
* The values that are set as default, are the same as PHP sends by default.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_headers = array(
|
||||
'content-type' => 'text/html',
|
||||
'pragma' => 'no-cache',
|
||||
'cache-control' => 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
|
||||
);
|
||||
|
||||
/**
|
||||
* HTTP version
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_httpVersion = '1.0';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Sets HTTP version.
|
||||
*
|
||||
* @access public
|
||||
* @return object HTTP_Header
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
if (isset($_SERVER['SERVER_PROTOCOL'])) {
|
||||
$this->setHttpVersion(substr($_SERVER['SERVER_PROTOCOL'], -3));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set HTTP version
|
||||
*
|
||||
* @access public
|
||||
* @return bool Returns true on success or false if version doesn't
|
||||
* match 1.0 or 1.1 (note: 1 will result in 1.0)
|
||||
* @param mixed $version HTTP version, either 1.0 or 1.1
|
||||
*/
|
||||
function setHttpVersion($version)
|
||||
{
|
||||
$version = round((float) $version, 1);
|
||||
if ($version < 1.0 || $version > 1.1) {
|
||||
return false;
|
||||
}
|
||||
$this->_httpVersion = sprintf('%0.1f', $version);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTTP version
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getHttpVersion()
|
||||
{
|
||||
return $this->_httpVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Header
|
||||
*
|
||||
* The default value for the Last-Modified header will be current
|
||||
* date and atime if $value is omitted.
|
||||
*
|
||||
* @access public
|
||||
* @return bool Returns true on success or false if $key was empty or
|
||||
* $value was not of an scalar type.
|
||||
* @param string $key The name of the header.
|
||||
* @param string $value The value of the header. (NULL to unset header)
|
||||
*/
|
||||
function setHeader($key, $value = null)
|
||||
{
|
||||
if (empty($key) || (isset($value) && !is_scalar($value))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$key = strToLower($key);
|
||||
if ($key == 'last-modified') {
|
||||
if (!isset($value)) {
|
||||
$value = HTTP::Date(time());
|
||||
} elseif (is_numeric($value)) {
|
||||
$value = HTTP::Date($value);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($value)) {
|
||||
$this->_headers[$key] = $value;
|
||||
} else {
|
||||
unset($this->_headers[$key]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Header
|
||||
*
|
||||
* If $key is omitted, all stored headers will be returned.
|
||||
*
|
||||
* @access public
|
||||
* @return mixed Returns string value of the requested header,
|
||||
* array values of all headers or false if header $key
|
||||
* is not set.
|
||||
* @param string $key The name of the header to fetch.
|
||||
*/
|
||||
function getHeader($key = null)
|
||||
{
|
||||
if (!isset($key)) {
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
$key = strToLower($key);
|
||||
|
||||
if (!isset($this->_headers[$key])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->_headers[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Headers
|
||||
*
|
||||
* Send out the header that you set via setHeader().
|
||||
*
|
||||
* @access public
|
||||
* @return bool Returns true on success or false if headers are already
|
||||
* sent.
|
||||
* @param array $keys Headers to (not) send, see $include.
|
||||
* @param array $include If true only $keys matching headers will be
|
||||
* sent, if false only header not matching $keys will be
|
||||
* sent.
|
||||
*/
|
||||
function sendHeaders($keys = array(), $include = true)
|
||||
{
|
||||
if (headers_sent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($keys)) {
|
||||
array_change_key_case($keys, CASE_LOWER);
|
||||
foreach ($this->_headers as $key => $value) {
|
||||
if ($include ? in_array($key, $keys) : !in_array($key, $keys)) {
|
||||
header($key .': '. $value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($this->_headers as $header => $value) {
|
||||
header($header .': '. $value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Satus Code
|
||||
*
|
||||
* Send out the given HTTP-Status code. Use this for example when you
|
||||
* want to tell the client this page is cached, then you would call
|
||||
* sendStatusCode(304).
|
||||
*
|
||||
* @see HTTP_Header_Cache::exitIfCached()
|
||||
*
|
||||
* @access public
|
||||
* @return bool Returns true on success or false if headers are already
|
||||
* sent.
|
||||
* @param int $code The status code to send, i.e. 404, 304, 200, etc.
|
||||
*/
|
||||
function sendStatusCode($code)
|
||||
{
|
||||
if (headers_sent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($code == (int) $code && defined('HTTP_HEADER_STATUS_'. $code)) {
|
||||
$code = constant('HTTP_HEADER_STATUS_'. $code);
|
||||
}
|
||||
|
||||
if (strncasecmp(PHP_SAPI, 'cgi', 3)) {
|
||||
header('HTTP/'. $this->_httpVersion .' '. $code);
|
||||
} else {
|
||||
header('Status: '. $code);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Date to Timestamp
|
||||
*
|
||||
* Converts dates like
|
||||
* Mon, 31 Mar 2003 15:26:34 GMT
|
||||
* Tue, 15 Nov 1994 12:45:26 GMT
|
||||
* into a timestamp, strtotime() didn't do it in older versions.
|
||||
*
|
||||
* @deprecated Use PHPs strtotime() instead.
|
||||
* @access public
|
||||
* @return mixed Returns int unix timestamp or false if the date doesn't
|
||||
* seem to be a valid GMT date.
|
||||
* @param string $date The GMT date.
|
||||
*/
|
||||
function dateToTimestamp($date)
|
||||
{
|
||||
static $months = array(
|
||||
null => 0, 'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4,
|
||||
'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9,
|
||||
'Oct' => 10, 'Nov' => 11, 'Dec' => 12
|
||||
);
|
||||
|
||||
if (-1 < $timestamp = strToTime($date)) {
|
||||
return $timestamp;
|
||||
}
|
||||
|
||||
if (!preg_match('~[^,]*,\s(\d+)\s(\w+)\s(\d+)\s(\d+):(\d+):(\d+).*~',
|
||||
$date, $m)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// [0] => Mon, 31 Mar 2003 15:42:55 GMT
|
||||
// [1] => 31 [2] => Mar [3] => 2003 [4] => 15 [5] => 42 [6] => 55
|
||||
return mktime($m[4], $m[5], $m[6], $months[$m[2]], $m[1], $m[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* This function redirects the client. This is done by issuing a Location
|
||||
* header and exiting. Additionally to HTTP::redirect() you can also add
|
||||
* parameters to the url.
|
||||
*
|
||||
* If you dont need parameters to be added, simply use HTTP::redirect()
|
||||
* otherwise use HTTP_Header::redirect().
|
||||
*
|
||||
* @see HTTP::redirect()
|
||||
* @author Wolfram Kriesing <wk@visionp.de>
|
||||
* @access public
|
||||
* @return void
|
||||
* @param string $url The URL to redirect to, if none is given it
|
||||
* redirects to the current page.
|
||||
* @param array $param Array of query string parameters to add; usually
|
||||
* a set of key => value pairs; if an array entry consists
|
||||
* only of an value it is used as key and the respective
|
||||
* value is fetched from $GLOBALS[$value]
|
||||
* @param bool $session Whether the session name/id should be added
|
||||
*/
|
||||
function redirect($url = null, $param = array(), $session = false)
|
||||
{
|
||||
if (!isset($url)) {
|
||||
$url = $_SERVER['PHP_SELF'];
|
||||
}
|
||||
|
||||
$qs = array();
|
||||
|
||||
if ($session) {
|
||||
$qs[] = session_name() .'='. session_id();
|
||||
}
|
||||
|
||||
if (is_array($param) && count($param)) {
|
||||
if (count($param)) {
|
||||
foreach ($param as $key => $val) {
|
||||
if (is_string($key)) {
|
||||
$qs[] = urlencode($key) .'='. urlencode($val);
|
||||
} else {
|
||||
$qs[] = urlencode($val) .'='. urlencode(@$GLOBALS[$val]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($qstr = implode('&', $qs)) {
|
||||
$purl = parse_url($url);
|
||||
$url .= (isset($purl['query']) ? '&' : '?') . $qstr;
|
||||
}
|
||||
|
||||
parent::redirect($url);
|
||||
}
|
||||
|
||||
/**#@+
|
||||
* @author Davey Shafik <davey@php.net>
|
||||
* @param int $http_code HTTP Code to check
|
||||
* @access public
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return HTTP Status Code Type
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
function getStatusType($http_code)
|
||||
{
|
||||
if(is_int($http_code) && defined('HTTP_HEADER_STATUS_' .$http_code) || defined($http_code)) {
|
||||
$type = substr($http_code,0,1);
|
||||
switch ($type) {
|
||||
case HTTP_HEADER_STATUS_INFORMATIONAL:
|
||||
case HTTP_HEADER_STATUS_SUCCESSFUL:
|
||||
case HTTP_HEADER_STATUS_REDIRECT:
|
||||
case HTTP_HEADER_STATUS_CLIENT_ERROR:
|
||||
case HTTP_HEADER_STATUS_SERVER_ERROR:
|
||||
return $type;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Status Code Message
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
function getStatusText($http_code)
|
||||
{
|
||||
if ($this->getStatusType($http_code)) {
|
||||
if (is_int($http_code) && defined('HTTP_HEADER_STATUS_' .$http_code)) {
|
||||
return substr(constant('HTTP_HEADER_STATUS_' .$http_code),4);
|
||||
} else {
|
||||
return substr($http_code,4);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if HTTP Status code is Information (1xx)
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isInformational($http_code)
|
||||
{
|
||||
if ($status_type = $this->getStatusType($http_code)) {
|
||||
return $status_type[0] == HTTP_HEADER_STATUS_INFORMATIONAL;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if HTTP Status code is Successful (2xx)
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isSuccessful($http_code)
|
||||
{
|
||||
if ($status_type = $this->getStatusType($http_code)) {
|
||||
return $status_type[0] == HTTP_HEADER_STATUS_SUCCESSFUL;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if HTTP Status code is a Redirect (3xx)
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isRedirect($http_code)
|
||||
{
|
||||
if ($status_type = $this->getStatusType($http_code)) {
|
||||
return $status_type[0] == HTTP_HEADER_STATUS_REDIRECT;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if HTTP Status code is a Client Error (4xx)
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isClientError($http_code)
|
||||
{
|
||||
if ($status_type = $this->getStatusType($http_code)) {
|
||||
return $status_type[0] == HTTP_HEADER_STATUS_CLIENT_ERROR;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if HTTP Status code is Server Error (5xx)
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isServerError($http_code)
|
||||
{
|
||||
if ($status_type = $this->getStatusType($http_code)) {
|
||||
return $status_type[0] == HTTP_HEADER_STATUS_SERVER_ERROR;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if HTTP Status code is Server OR Client Error (4xx or 5xx)
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isError($http_code)
|
||||
{
|
||||
if ($status_type = $this->getStatusType($http_code)) {
|
||||
return (($status_type == HTTP_HEADER_STATUS_CLIENT_ERROR) || ($status_type == HTTP_HEADER_STATUS_SERVER_ERROR)) ? true : false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**#@-*/
|
||||
}
|
||||
?>
|
238
classes/pear/HTTP/Header/Cache.php
Normal file
238
classes/pear/HTTP/Header/Cache.php
Normal file
@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* HTTP::Header::Cache
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category HTTP
|
||||
* @package HTTP_Header
|
||||
* @author Wolfram Kriesing <wk@visionp.de>
|
||||
* @author Michael Wallner <mike@php.net>
|
||||
* @copyright 2003-2005 The Authors
|
||||
* @license BSD, revised
|
||||
* @version CVS: $Id: Cache.php,v 1.24 2005/11/08 19:06:14 mike Exp $
|
||||
* @link http://pear.php.net/package/HTTP_Header
|
||||
*/
|
||||
|
||||
/**
|
||||
* Requires HTTP_Header
|
||||
*/
|
||||
require_once 'HTTP/Header.php';
|
||||
|
||||
/**
|
||||
* HTTP_Header_Cache
|
||||
*
|
||||
* This package provides methods to easier handle caching of HTTP pages. That
|
||||
* means that the pages can be cached at the client (user agent or browser) and
|
||||
* your application only needs to send "hey client you already have the pages".
|
||||
*
|
||||
* Which is done by sending the HTTP-Status "304 Not Modified", so that your
|
||||
* application load and the network traffic can be reduced, since you only need
|
||||
* to send the complete page once. This is really an advantage e.g. for
|
||||
* generated style sheets, or simply pages that do only change rarely.
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* require_once 'HTTP/Header/Cache.php';
|
||||
* $httpCache = new HTTP_Header_Cache(4, 'weeks');
|
||||
* $httpCache->sendHeaders();
|
||||
* // your code goes here
|
||||
* </code>
|
||||
*
|
||||
* @package HTTP_Header
|
||||
* @category HTTP
|
||||
* @access public
|
||||
* @version $Revision: 1.24 $
|
||||
*/
|
||||
class HTTP_Header_Cache extends HTTP_Header
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Set the amount of time to cache.
|
||||
*
|
||||
* @access public
|
||||
* @return object HTTP_Header_Cache
|
||||
* @param int $expires
|
||||
* @param string $unit
|
||||
*/
|
||||
function __construct($expires = 0, $unit = 'seconds')
|
||||
{
|
||||
parent::HTTP_Header();
|
||||
$this->setHeader('Pragma', 'cache');
|
||||
$this->setHeader('Last-Modified', $this->getCacheStart());
|
||||
$this->setHeader('Cache-Control', 'private, must-revalidate, max-age=0');
|
||||
|
||||
if ($expires) {
|
||||
if (!$this->isOlderThan($expires, $unit)) {
|
||||
$this->exitCached();
|
||||
}
|
||||
$this->setHeader('Last-Modified', time());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Cache Start
|
||||
*
|
||||
* Returns the unix timestamp of the If-Modified-Since HTTP header or the
|
||||
* current time if the header was not sent by the client.
|
||||
*
|
||||
* @access public
|
||||
* @return int unix timestamp
|
||||
*/
|
||||
function getCacheStart()
|
||||
{
|
||||
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && !$this->isPost()) {
|
||||
return strtotime(current($array = explode(';',
|
||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'])));
|
||||
}
|
||||
return time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Older Than
|
||||
*
|
||||
* You can call it like this:
|
||||
* <code>
|
||||
* $httpCache->isOlderThan(1, 'day');
|
||||
* $httpCache->isOlderThan(47, 'days');
|
||||
*
|
||||
* $httpCache->isOlderThan(1, 'week');
|
||||
* $httpCache->isOlderThan(3, 'weeks');
|
||||
*
|
||||
* $httpCache->isOlderThan(1, 'hour');
|
||||
* $httpCache->isOlderThan(5, 'hours');
|
||||
*
|
||||
* $httpCache->isOlderThan(1, 'minute');
|
||||
* $httpCache->isOlderThan(15, 'minutes');
|
||||
*
|
||||
* $httpCache->isOlderThan(1, 'second');
|
||||
* $httpCache->isOlderThan(15);
|
||||
* </code>
|
||||
*
|
||||
* If you specify something greater than "weeks" as time untit, it just
|
||||
* works approximatly, because a month is taken to consist of 4.3 weeks.
|
||||
*
|
||||
* @access public
|
||||
* @return bool Returns true if requested page is older than specified.
|
||||
* @param int $time The amount of time.
|
||||
* @param string $unit The unit of the time amount - (year[s], month[s],
|
||||
* week[s], day[s], hour[s], minute[s], second[s]).
|
||||
*/
|
||||
function isOlderThan($time = 0, $unit = 'seconds')
|
||||
{
|
||||
if (!isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || $this->isPost()) {
|
||||
return true;
|
||||
}
|
||||
if (!$time) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (strtolower($unit))
|
||||
{
|
||||
case 'year':
|
||||
case 'years':
|
||||
$time *= 12;
|
||||
case 'month':
|
||||
case 'months':
|
||||
$time *= 4.3;
|
||||
case 'week':
|
||||
case 'weeks':
|
||||
$time *= 7;
|
||||
case 'day':
|
||||
case 'days':
|
||||
$time *= 24;
|
||||
case 'hour':
|
||||
case 'hours':
|
||||
$time *= 60;
|
||||
case 'minute':
|
||||
case 'minutes':
|
||||
$time *= 60;
|
||||
}
|
||||
|
||||
return (time() - $this->getCacheStart()) > $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Cached
|
||||
*
|
||||
* Check whether we can consider to be cached on the client side.
|
||||
*
|
||||
* @access public
|
||||
* @return bool Whether the page/resource is considered to be cached.
|
||||
* @param int $lastModified Unix timestamp of last modification.
|
||||
*/
|
||||
function isCached($lastModified = 0)
|
||||
{
|
||||
if ($this->isPost()) {
|
||||
return false;
|
||||
}
|
||||
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && !$lastModified) {
|
||||
return true;
|
||||
}
|
||||
if (!$seconds = time() - $lastModified) {
|
||||
return false;
|
||||
}
|
||||
return !$this->isOlderThan($seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Post
|
||||
*
|
||||
* Check if request method is "POST".
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function isPost()
|
||||
{
|
||||
return isset($_SERVER['REQUEST_METHOD']) and
|
||||
'POST' == $_SERVER['REQUEST_METHOD'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit If Cached
|
||||
*
|
||||
* Exit with "HTTP 304 Not Modified" if we consider to be cached.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @param int $lastModified Unix timestamp of last modification.
|
||||
*/
|
||||
function exitIfCached($lastModified = 0)
|
||||
{
|
||||
if ($this->isCached($lastModified)) {
|
||||
$this->exitCached();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit Cached
|
||||
*
|
||||
* Exit with "HTTP 304 Not Modified".
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function exitCached()
|
||||
{
|
||||
$this->sendHeaders();
|
||||
$this->sendStatusCode(304);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Last Modified
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @param int $lastModified The unix timestamp of last modification.
|
||||
*/
|
||||
function setLastModified($lastModified = null)
|
||||
{
|
||||
$this->setHeader('Last-Modified', $lastModified);
|
||||
}
|
||||
}
|
||||
?>
|
1191
classes/pear/HTTP/Request.php
Normal file
1191
classes/pear/HTTP/Request.php
Normal file
File diff suppressed because it is too large
Load Diff
96
classes/pear/HTTP/Request/Listener.php
Normal file
96
classes/pear/HTTP/Request/Listener.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Copyright (c) 2002-2003, Richard Heyes |
|
||||
// | All rights reserved. |
|
||||
// | |
|
||||
// | Redistribution and use in source and binary forms, with or without |
|
||||
// | modification, are permitted provided that the following conditions |
|
||||
// | are met: |
|
||||
// | |
|
||||
// | o Redistributions of source code must retain the above copyright |
|
||||
// | notice, this list of conditions and the following disclaimer. |
|
||||
// | o Redistributions in binary form must reproduce the above copyright |
|
||||
// | notice, this list of conditions and the following disclaimer in the |
|
||||
// | documentation and/or other materials provided with the distribution.|
|
||||
// | o The names of the authors may not be used to endorse or promote |
|
||||
// | products derived from this software without specific prior written |
|
||||
// | permission. |
|
||||
// | |
|
||||
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
||||
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
||||
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
||||
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
||||
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
||||
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
||||
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
||||
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
||||
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
||||
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
||||
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
||||
// | |
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | Author: Alexey Borzov <avb@php.net> |
|
||||
// +-----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Listener.php,v 1.2 2003/10/26 10:28:29 avb Exp $
|
||||
//
|
||||
|
||||
/**
|
||||
* This class implements the Observer part of a Subject-Observer
|
||||
* design pattern. It listens to the events sent by a
|
||||
* HTTP_Request or HTTP_Response instance.
|
||||
*
|
||||
* @package HTTP_Request
|
||||
* @author Alexey Borzov <avb@php.net>
|
||||
* @version $Revision: 1.2 $
|
||||
*/
|
||||
class HTTP_Request_Listener
|
||||
{
|
||||
/**
|
||||
* A listener's identifier
|
||||
* @var string
|
||||
*/
|
||||
var $_id;
|
||||
|
||||
/**
|
||||
* Constructor, sets the object's identifier
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$this->_id = md5(uniqid('http_request_', 1));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the listener's identifier
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function getId()
|
||||
{
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is called when Listener is notified of an event
|
||||
*
|
||||
* @access public
|
||||
* @param object an object the listener is attached to
|
||||
* @param string Event name
|
||||
* @param mixed Additional data
|
||||
* @abstract
|
||||
*/
|
||||
function update(&$subject, $event, $data = null)
|
||||
{
|
||||
echo "Notified of event: '$event'\n";
|
||||
if (null !== $data) {
|
||||
echo "Additional data: ";
|
||||
var_dump($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user