添加到 trunk
+YUCHENG HU+ git-svn-id: https://svn.code.sf.net/p/hawebs/svn@219 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
if (!defined('PHP_TEXT_CACHE_INCLUDE_PATH')) {
|
||||
define('PHP_TEXT_CACHE_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
}
|
||||
|
||||
class php_file_utilities {
|
||||
/**
|
||||
* Retrieves binary or text data from the specified file
|
||||
* @param string The file path
|
||||
* @param string The attributes for the read operation ('r' or 'rb' or 'rt')
|
||||
* @return mixed he text or binary data contained in the file
|
||||
*/
|
||||
function &getDataFromFile($filename, $readAttributes, $readSize = 8192) {
|
||||
$fileContents = null;
|
||||
$fileHandle = @fopen($filename, $readAttributes);
|
||||
|
||||
if($fileHandle){
|
||||
do {
|
||||
$data = fread($fileHandle, $readSize);
|
||||
|
||||
if (strlen($data) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
$fileContents .= $data;
|
||||
} while (true);
|
||||
|
||||
fclose($fileHandle);
|
||||
}
|
||||
|
||||
return $fileContents;
|
||||
} //getDataFromFile
|
||||
|
||||
/**
|
||||
* Writes the specified binary or text data to a file
|
||||
* @param string The file path
|
||||
* @param mixed The data to be written
|
||||
* @param string The attributes for the write operation ('w' or 'wb')
|
||||
*/
|
||||
function putDataToFile($fileName, &$data, $writeAttributes) {
|
||||
$fileHandle = @fopen($fileName, $writeAttributes);
|
||||
|
||||
if ($fileHandle) {
|
||||
fwrite($fileHandle, $data);
|
||||
fclose($fileHandle);
|
||||
}
|
||||
} //putDataToFile
|
||||
} //php_file_utilities
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
define('PHP_HTTP_TOOLS_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
require_once(PHP_HTTP_TOOLS_INCLUDE_PATH . 'php_http_client_generic.php');
|
||||
?>
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP HTTP Tools is a library for working with the http protocol
|
||||
* php_http_connector establishes http connections
|
||||
* @package php-http-tools
|
||||
* @version 0.3
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/php_http_tools/ PHP HTTP Tools Home Page
|
||||
* PHP HTTP Tools are Free Software
|
||||
**/
|
||||
|
||||
if (!defined('PHP_HTTP_TOOLS_INCLUDE_PATH')) {
|
||||
define('PHP_HTTP_TOOLS_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper class for establishing HTTP connections
|
||||
*
|
||||
* @package php-http-tools
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class php_http_connector {
|
||||
/** @var object A reference to a http connection or proxy, if one is required */
|
||||
var $httpConnection = null;
|
||||
|
||||
/**
|
||||
* Specifies the parameters of the http conection used to obtain the xml data
|
||||
* @param string The ip address or domain name of the connection
|
||||
* @param string The path of the connection
|
||||
* @param int The port that the connection is listening on
|
||||
* @param int The timeout value for the connection
|
||||
* @param string The user name, if authentication is required
|
||||
* @param string The password, if authentication is required
|
||||
*/
|
||||
function setConnection($host, $path = '/', $port = 80, $timeout = 0, $user = null, $password = null) {
|
||||
require_once(PHP_HTTP_TOOLS_INCLUDE_PATH . 'php_http_client_generic.php');
|
||||
|
||||
$this->httpConnection = new php_http_client_generic($host, $path, $port, $timeout, $user, $password);
|
||||
} //setConnection
|
||||
|
||||
/**
|
||||
* Specifies basic authentication for an http connection
|
||||
* @param string The user name
|
||||
* @param string The password
|
||||
*/
|
||||
function setAuthorization($user, $password) {
|
||||
$this->httpConnection->setAuthorization($user, $password);
|
||||
} //setAuthorization
|
||||
|
||||
/**
|
||||
* Specifies that a proxy is to be used to obtain the data
|
||||
* @param string The ip address or domain name of the proxy
|
||||
* @param string The path to the proxy
|
||||
* @param int The port that the proxy is listening on
|
||||
* @param int The timeout value for the connection
|
||||
* @param string The user name, if authentication is required
|
||||
* @param string The password, if authentication is required
|
||||
*/
|
||||
function setProxyConnection($host, $path = '/', $port = 80, $timeout = 0, $user = null, $password = null) {
|
||||
require_once(PHP_HTTP_TOOLS_INCLUDE_PATH . 'php_http_proxy.php');
|
||||
|
||||
$this->httpConnection = new php_http_proxy($host, $path, $port, $timeout, $user, $password);
|
||||
} //setProxyConnection
|
||||
|
||||
/**
|
||||
* Specifies basic authentication for the proxy
|
||||
* @param string The user name
|
||||
* @param string The password
|
||||
*/
|
||||
function setProxyAuthorization($user, $password) {
|
||||
$this->httpConnection->setProxyAuthorization($user, $password);
|
||||
} //setProxyAuthorization
|
||||
} //php_http_connector
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP HTTP Tools is a library for working with the http protocol
|
||||
* HTTPExceptions is an HTTP Exceptions class
|
||||
* @package php-http-tools
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/php_http_tools/ PHP HTTP Tools Home Page
|
||||
* PHP HTTP Tools are Free Software
|
||||
**/
|
||||
|
||||
/** socket connection error */
|
||||
define('HTTP_SOCKET_CONNECTION_ERR', 1);
|
||||
/** http transport error */
|
||||
define('HTTP_TRANSPORT_ERR', 2);
|
||||
|
||||
//HTTPExceptions Error Modes
|
||||
/** continue on error */
|
||||
define('HTTP_ONERROR_CONTINUE', 1);
|
||||
/** die on error */
|
||||
define('HTTP_ONERROR_DIE', 2);
|
||||
|
||||
/**
|
||||
* @global object Reference to custom error handler for HTTP Exception class
|
||||
*/
|
||||
$GLOBALS['HTTP_Exception_errorHandler'] = null;
|
||||
/**
|
||||
* @global int Error mode; specifies whether to die on error or simply return
|
||||
*/
|
||||
//$GLOBALS['HTTP_Exception_mode'] = HTTP_ONERROR_RETURN;
|
||||
// fixes bug identified here: sarahk.pcpropertymanager.com/blog/using-domit-rss/225/
|
||||
$GLOBALS['HTTP_Exception_mode'] = 1;
|
||||
/**
|
||||
* @global string Log file for errors
|
||||
*/
|
||||
$GLOBALS['HTTP_Exception_log'] = null;
|
||||
|
||||
/**
|
||||
* An HTTP Exceptions class (not yet implemented)
|
||||
*
|
||||
* @package php-http-tools
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class HTTPExceptions {
|
||||
function raiseException($errorNum, $errorString) {
|
||||
//die('HTTP Exception: ' . $errorNum . "\n " . $errorString);
|
||||
|
||||
if ($GLOBALS['HTTP_Exception_errorHandler'] != null) {
|
||||
call_user_func($GLOBALS['HTTP_Exception_errorHandler'], $errorNum, $errorString);
|
||||
}
|
||||
else {
|
||||
$errorMessageText = $errorNum . ' ' . $errorString;
|
||||
$errorMessage = 'Error: ' . $errorMessageText;
|
||||
|
||||
if ((!isset($GLOBALS['HTTP_ERROR_FORMATTING_HTML'])) ||
|
||||
($GLOBALS['HTTP_ERROR_FORMATTING_HTML'] == true)) {
|
||||
$errorMessage = "<p><pre>" . $errorMessage . "</pre></p>";
|
||||
}
|
||||
|
||||
//log error to file
|
||||
if ((isset($GLOBALS['HTTP_Exception_log'])) &&
|
||||
($GLOBALS['HTTP_Exception_log'] != null)) {
|
||||
require_once(PHP_HTTP_TOOLS_INCLUDE_PATH . 'php_file_utilities.php');
|
||||
$logItem = "\n" . date('Y-m-d H:i:s') . ' HTTP Error ' . $errorMessageText;
|
||||
php_file_utilities::putDataToFile($GLOBALS['HTTP_Exception_log'],
|
||||
$logItem, 'a');
|
||||
}
|
||||
|
||||
switch ($GLOBALS['HTTP_Exception_mode']) {
|
||||
case HTTP_ONERROR_CONTINUE:
|
||||
return;
|
||||
break;
|
||||
|
||||
case HTTP_ONERROR_DIE:
|
||||
die($errorMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} //raiseException
|
||||
|
||||
/**
|
||||
* custom handler for HTTP errors
|
||||
* @param object A reference to the custom error handler
|
||||
*/
|
||||
function setErrorHandler($method) {
|
||||
$GLOBALS['HTTP_Exception_errorHandler'] =& $method;
|
||||
} //setErrorHandler
|
||||
|
||||
/**
|
||||
* Set error mode
|
||||
* @param int The HTTP error mode
|
||||
*/
|
||||
function setErrorMode($mode) {
|
||||
$GLOBALS['HTTP_Exception_mode'] = $mode;
|
||||
} //setErrorMode
|
||||
|
||||
/**
|
||||
* Set error mode
|
||||
* @param boolean True if errors should be logged
|
||||
* @param string Absolute or relative path to log file
|
||||
*/
|
||||
function setErrorLog($doLogErrors, $logfile) {
|
||||
if ($doLogErrors) {
|
||||
$GLOBALS['HTTP_Exception_log'] = $logfile;
|
||||
}
|
||||
else {
|
||||
$GLOBALS['HTTP_Exception_log'] = null;
|
||||
}
|
||||
} //setErrorLog
|
||||
} //HTTPExceptions
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP HTTP Tools is a library for working with the http protocol
|
||||
* php_http_proxy represents a basic http proxy
|
||||
* @package php-http-tools
|
||||
* @version 0.3
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/php_http_tools/ PHP HTTP Tools Home Page
|
||||
* PHP HTTP Tools are Free Software
|
||||
**/
|
||||
if (!defined('PHP_HTTP_TOOLS_INCLUDE_PATH')) {
|
||||
define('PHP_HTTP_TOOLS_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
}
|
||||
|
||||
require_once(PHP_HTTP_TOOLS_INCLUDE_PATH . 'php_http_client_generic.php');
|
||||
|
||||
/**
|
||||
* An HTTP Proxy class
|
||||
*
|
||||
* @package php-http-tools
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class php_http_proxy extends php_http_client_generic {
|
||||
|
||||
/**
|
||||
* HTTP Proxy constructor
|
||||
* @param string The client connection host name, with or without its protocol prefix
|
||||
* @param string The client connection path, not including the host name
|
||||
* @param int The port to establish the client connection on
|
||||
* @param int The timeout value for the client connection
|
||||
*/
|
||||
function php_http_proxy($host, $path = '/', $port = 80, $timeout = 0) {
|
||||
$this->php_http_client_generic($host, $path, $port, $timeout);
|
||||
$this->setHeaders();
|
||||
} //php_http_proxy
|
||||
|
||||
/**
|
||||
* Sets the proxy timeout to the specified value
|
||||
* @param int The timeout value for the client connection
|
||||
*/
|
||||
function setTimeout($timeout) {
|
||||
$this->timeout = $timeout;
|
||||
} //setTimeout
|
||||
|
||||
/**
|
||||
* Sets the proxy headers
|
||||
*/
|
||||
function setHeaders() {
|
||||
$this->setHeader('User-Agent', 'PHP-HTTP-Proxy-Client/0.1');
|
||||
$this->setHeader('Connection', 'Close');
|
||||
} //setHeaders
|
||||
|
||||
/**
|
||||
* Specifies a user name and password for basic proxy authentication
|
||||
* @param string The user name for proxy authentication
|
||||
* @param string The password for proxy authentication
|
||||
*/
|
||||
function setProxyAuthorization($user, $password) {
|
||||
$encodedChallengeResponse = 'Basic ' . base64_encode($this->user . ':' . $this->password);
|
||||
$this->setHeader('Proxy-Authorization', $encodedChallengeResponse);
|
||||
} //setProxyAuthorization
|
||||
|
||||
/**
|
||||
* Handler for customizing the HTTP GET call
|
||||
* @param string The target url
|
||||
*/
|
||||
function get_custom($filename) {
|
||||
$url = $this->connection->formatHost($filename);
|
||||
$sep = strpos($url, '/');
|
||||
$targetHost = substr($url, 0, $sep);
|
||||
|
||||
$this->setHeader('Host', $targetHost);
|
||||
} //get_custom
|
||||
} //php_http_proxy
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
//*******************************************************************
|
||||
//php_http_server_generic represents a basic http server
|
||||
//*******************************************************************
|
||||
//by John Heinstein
|
||||
//[email protected]
|
||||
//*******************************************************************
|
||||
//Version 0.1
|
||||
//copyright 2004 Engage Interactive
|
||||
//http://www.engageinteractive.com/dom_xmlrpc/
|
||||
//All rights reserved
|
||||
//*******************************************************************
|
||||
//Licensed under the GNU General Public License (GPL)
|
||||
//http://www.gnu.org/copyleft/gpl.html
|
||||
//*******************************************************************
|
||||
|
||||
if (!defined('PHP_HTTP_TOOLS_INCLUDE_PATH')) {
|
||||
define('PHP_HTTP_TOOLS_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
}
|
||||
|
||||
define ('CRLF', "\r\n"); //end-of-line char as defined in HTTP spec
|
||||
define ('CR', "\r");
|
||||
define ('LF', "\n");
|
||||
|
||||
class php_http_server_generic {
|
||||
var $httpStatusCodes;
|
||||
|
||||
var $protocol = 'HTTP';
|
||||
var $protocolVersion = '1.0';
|
||||
var $statusCode = 200;
|
||||
|
||||
var $events = array('onRequest' => null, 'onResponse' => null,
|
||||
'onGet' => null, 'onHead' => null,
|
||||
'onPost' => null, 'onPut' => null);
|
||||
|
||||
function php_http_server_generic() {
|
||||
//require_once(PHP_HTTP_TOOLS_INCLUDE_PATH . 'php_http_status_codes.php');
|
||||
//$this->httpStatusCodes =&new php_http_status_codes();
|
||||
} //php_http_server_generic
|
||||
|
||||
function &getHeaders() {
|
||||
$headers = headers_list();
|
||||
$response = '';
|
||||
|
||||
if (count($headers) > 0) {
|
||||
foreach ($headers as $key => $value) {
|
||||
$response .= $value . CRLF;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
} //getHeaders
|
||||
|
||||
function setProtocolVersion($version) {
|
||||
if (($version == '1.0') || ($version == '1.1')) {
|
||||
$$this->protocolVersion = $version;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} //setProtocolVersion
|
||||
|
||||
function setHeader($name, $value) {
|
||||
header($name . ': ' . $value);
|
||||
} //setHeader
|
||||
|
||||
function setHeaders() {
|
||||
//you will want to override this method
|
||||
$this->setHeader('Content-Type', 'text/html');
|
||||
$this->setHeader('Server', 'PHP HTTP Server (Generic)/0.1');
|
||||
} //setHeaders
|
||||
|
||||
function fireEvent($target, $data) {
|
||||
if ($this->events[$target] != null) {
|
||||
call_user_func($this->events[$target], $data);
|
||||
}
|
||||
} //fireEvent
|
||||
|
||||
function fireHTTPEvent($target, $data = null) {
|
||||
if ($this->events[$target] == null) {
|
||||
//if no handler is assigned,
|
||||
//delegate the event to the default handler
|
||||
$this->setHTTPEvent($target);
|
||||
}
|
||||
|
||||
call_user_func($this->events[$target], $data);
|
||||
} //fireHTTPEvent
|
||||
|
||||
function setHTTPEvent($option, $customHandler = null) {
|
||||
if ($customHandler != null) {
|
||||
$handler =& $customHandler;
|
||||
}
|
||||
else {
|
||||
$handler = array(&$this, 'defaultHTTPEventHandler');
|
||||
}
|
||||
|
||||
switch($option) {
|
||||
case 'onGet':
|
||||
case 'onHead':
|
||||
case 'onPost':
|
||||
case 'onPut':
|
||||
$this->events[$option] =& $handler;
|
||||
break;
|
||||
}
|
||||
} //setHTTPServerEvent
|
||||
|
||||
function defaultHTTPHandler() {
|
||||
//will add functionality for this later
|
||||
//work with subclasses for the time being
|
||||
} //defaultHTTPHandler
|
||||
|
||||
function setDebug($option, $truthVal, $customHandler = null) {
|
||||
if ($customHandler != null) {
|
||||
$handler =& $customHandler;
|
||||
}
|
||||
else {
|
||||
$handler = array(&$this, 'defaultDebugHandler');
|
||||
}
|
||||
|
||||
switch($option) {
|
||||
case 'onRequest':
|
||||
case 'onResponse':
|
||||
$truthVal ? ($this->events[$option] =& $handler) :
|
||||
($this->events[$option] = null);
|
||||
break;
|
||||
}
|
||||
} //setDebug
|
||||
|
||||
function getDebug($option) {
|
||||
switch($option) {
|
||||
case 'onRequest':
|
||||
case 'onResponse':
|
||||
return ($this->events[$option] != null);
|
||||
break;
|
||||
}
|
||||
} //getDebug
|
||||
|
||||
function defaultDebugHandler($data) {
|
||||
//just write to a log file, since can't display in a browser
|
||||
$this->writeDebug($data);
|
||||
} //defaultDebugHandler
|
||||
|
||||
function writeDebug($data) {
|
||||
$filename = 'debug_' . time() . '.txt';
|
||||
$fileHandle = fopen($fileName, 'a');
|
||||
fwrite($fileHandle, $data);
|
||||
fclose($fileHandle);
|
||||
} //writeDebug
|
||||
|
||||
function receive() {
|
||||
global $HTTP_SERVER_VARS;
|
||||
$requestMethod = strToUpper($HTTP_SERVER_VARS['REQUEST_METHOD']);
|
||||
|
||||
switch ($requestMethod) {
|
||||
case 'GET':
|
||||
$this->fireHTTPEvent('onGet');
|
||||
break;
|
||||
|
||||
case 'HEAD':
|
||||
$this->fireHTTPEvent('onHead');
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$this->fireHTTPEvent('onPost');
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
$this->fireHTTPEvent('onPut');
|
||||
break;
|
||||
}
|
||||
} //receive
|
||||
|
||||
function respond($response) {
|
||||
//build header info
|
||||
//$response = $this->protocol . '/' . $this->protocolVersion . ' ' .
|
||||
//$this->statusCode . ' ' . $this->httpStatusCodes->getCodeString($this->statusCode) . CRLF;
|
||||
|
||||
if (!headers_sent()) { //avoid generating an error when in debug mode
|
||||
$this->setHeader('Date', "date('r')");
|
||||
$this->setHeader('Content-Length', strlen($response));
|
||||
$this->setHeader('Connection', 'Close');
|
||||
}
|
||||
|
||||
echo $response;
|
||||
} //respond
|
||||
} //php_http_server_generic
|
||||
|
||||
|
||||
//To invoke the server, do:
|
||||
//$httpServer = new php_http_server_generic(); //or instance of a subclass
|
||||
//$httpServer->receive();
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
define('PHP_HTTP_TOOLS_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
require_once(PHP_HTTP_TOOLS_INCLUDE_PATH . 'php_http_server_generic.php');
|
||||
?>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
//*******************************************************************
|
||||
//php_http_status_codes list the http static codes as constants
|
||||
//*******************************************************************
|
||||
//by John Heinstein
|
||||
//[email protected]
|
||||
//*******************************************************************
|
||||
//Version 0.1
|
||||
//copyright 2004 Engage Interactive
|
||||
//http://www.engageinteractive.com/dom_xmlrpc/
|
||||
//All rights reserved
|
||||
//*******************************************************************
|
||||
//Licensed under the GNU General Public License (GPL)
|
||||
//http://www.gnu.org/copyleft/gpl.html
|
||||
//*******************************************************************
|
||||
class php_http_status_codes {
|
||||
var $codes;
|
||||
|
||||
function php_http_status_codes() {
|
||||
$this->codes = array(
|
||||
200 => 'OK',
|
||||
201 => 'CREATED',
|
||||
202 => 'Accepted',
|
||||
203 => 'Partial Information',
|
||||
204 => 'No Response',
|
||||
301 => 'Moved',
|
||||
302 => 'Found',
|
||||
303 => 'Method',
|
||||
304 => 'Not Modified',
|
||||
400 => 'Bad Request',
|
||||
401 => 'Unauthorized',
|
||||
402 => 'PaymentRequired',
|
||||
403 => 'Forbidden',
|
||||
404 => 'Not found',
|
||||
500 => 'Internal Error',
|
||||
501 => 'Not implemented',
|
||||
502 => 'Service temporarily overloaded',
|
||||
503 => 'Gateway timeout');
|
||||
} //php_http_status_codes
|
||||
|
||||
function getCodes() {
|
||||
return $this->codes;
|
||||
} //getCodes
|
||||
|
||||
function getCodeString($code) {
|
||||
return $this->codes[$code];
|
||||
} //getCodeString
|
||||
} //class php_http_status_codes
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
/**
|
||||
* PHP Text Cache is a simple caching class for for saving/retrieving local copies of url data
|
||||
* @package php_text_cache
|
||||
* @version 0.3-pre
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/php_text_cache/ PHP Text Cache Home Page
|
||||
* PHP Text Cache is Free Software
|
||||
**/
|
||||
|
||||
if (!defined('PHP_TEXT_CACHE_INCLUDE_PATH')) {
|
||||
define('PHP_TEXT_CACHE_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
}
|
||||
|
||||
require_once(PHP_TEXT_CACHE_INCLUDE_PATH . 'php_http_connector.php');
|
||||
|
||||
/**
|
||||
* A simple caching class for saving/retrieving local copies of url data
|
||||
*
|
||||
* @package php_text_cache
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class php_text_cache extends php_http_connector {
|
||||
/** @var string The directory in which cached files are stored */
|
||||
var $cacheDir;
|
||||
/** @var int The amount time of time to wait before a cached file should be updated */
|
||||
var $cacheTime;
|
||||
/** @var boolean True if an HTTP client should be used to establish the connection */
|
||||
var $doUseHTTPClient;
|
||||
/** @var int Time in seconds to disconnect after attempting an http connection */
|
||||
var $httpTimeout;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param string Directory in which to store the cache files
|
||||
* @param int Expiry time for cache file (-1 signifies no expiry limit)
|
||||
* @param int Time in seconds to disconnect after attempting an http connection
|
||||
*/
|
||||
function php_text_cache($cacheDir = './', $cacheTime = -1, $timeout = 0) {
|
||||
$this->cacheDir = $cacheDir;
|
||||
$this->cacheTime = $cacheTime;
|
||||
$this->timeout = $timeout;
|
||||
} //php_text_cache
|
||||
|
||||
/**
|
||||
* Specifies the default timeout value for connecting to a host
|
||||
* @param int The number of seconds to timeout when attempting to connect to a server
|
||||
*/
|
||||
function setTimeout($timeout) {
|
||||
$this->timeout = $timeout;
|
||||
} //setTimeout
|
||||
|
||||
/**
|
||||
* Gets data from an url, or its cache file
|
||||
*
|
||||
* @param string The url of the data
|
||||
* @return string The data at the specified url
|
||||
*/
|
||||
function getData($url) {
|
||||
$cacheFile = $this->getCacheFileName($url);
|
||||
|
||||
if (is_file($cacheFile)) {
|
||||
$fileStats = stat($cacheFile);
|
||||
$lastChangeTime = $fileStats[9]; //mtime
|
||||
$currTime = time();
|
||||
|
||||
if (($this->cacheTime != -1) && ($currTime - $lastChangeTime) > $this->cacheTime) { //get data from url
|
||||
return $this->fromURL($url, $cacheFile);
|
||||
}
|
||||
else { //get data from file
|
||||
return $this->fromCache($cacheFile);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return $this->fromURL($url, $cacheFile);
|
||||
}
|
||||
} //getData
|
||||
|
||||
/**
|
||||
* Given an url, returns the path to the cache file
|
||||
*
|
||||
* Uses an md5 hash of the url. This can be
|
||||
* overridden if a different approach is required
|
||||
*
|
||||
* @param string The url of the data
|
||||
* @return string The cache file name
|
||||
*/
|
||||
function getCacheFileName($url) {
|
||||
return ($this->cacheDir . md5($url));
|
||||
} //getCacheFileName
|
||||
|
||||
/**
|
||||
* Establishes a connection, given an url
|
||||
* @param string The url of the data
|
||||
*/
|
||||
function establishConnection($url) {
|
||||
require_once(PHP_TEXT_CACHE_INCLUDE_PATH . 'php_http_client_generic.php');
|
||||
|
||||
$host = php_http_connection::formatHost($url);
|
||||
$host = substr($host, 0, strpos($host, '/'));
|
||||
|
||||
$this->setConnection($host, '/', 80, $this->timeout);
|
||||
} //establishConnection
|
||||
|
||||
/**
|
||||
* Specifies whether an HTTP client should be used to establish a connection
|
||||
* @param boolean True if an HTTP client is to be used to establish the connection
|
||||
*/
|
||||
function useHTTPClient($truthVal) {
|
||||
// fixes bug identified here: sarahk.pcpropertymanager.com/blog/using-domit-rss/225/
|
||||
//$this->doUseHTTPClient = truthVal;
|
||||
$this->doUseHTTPClient = $truthVal;
|
||||
} //useHTTPClient
|
||||
|
||||
/**
|
||||
* Gets data from an url and caches a copy of the data
|
||||
* @param string The url for the data
|
||||
* @param string The cache file path
|
||||
* @return string The contents of the url
|
||||
*/
|
||||
function fromURL($url, $cacheFile) {
|
||||
$fileContents = '';
|
||||
|
||||
if ($this->httpConnection != null) {
|
||||
$response =& $this->httpConnection->get($url);
|
||||
|
||||
if ($response != null) {
|
||||
$fileContents = $response->getResponse();
|
||||
}
|
||||
}
|
||||
else if ($this->doUseHTTPClient) {
|
||||
$this->establishConnection($url);
|
||||
$response =& $this->httpConnection->get($url);
|
||||
|
||||
if ($response != null) {
|
||||
$fileContents = $response->getResponse();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$fileContents = $this->fromFile($url);
|
||||
}
|
||||
|
||||
//if file is empty, might need to establish an
|
||||
//http connection to get the data
|
||||
if (($fileContents == '') && !$this->doUseHTTPClient) {
|
||||
$this->establishConnection($url);
|
||||
$response =& $this->httpConnection->get($url);
|
||||
|
||||
if ($response != null) {
|
||||
$fileContents = $response->getResponse();
|
||||
}
|
||||
}
|
||||
|
||||
if ($fileContents != '') {
|
||||
require_once(PHP_TEXT_CACHE_INCLUDE_PATH . 'php_file_utilities.php');
|
||||
php_file_utilities::putDataToFile($cacheFile, $fileContents, 'w');
|
||||
}
|
||||
|
||||
return $fileContents;
|
||||
} //fromURL
|
||||
|
||||
/**
|
||||
* Get text from cache file
|
||||
* @param string The file path
|
||||
* @return string The text contained in the file, or an empty string
|
||||
*/
|
||||
function fromCache($cacheFile) {
|
||||
return $this->fromFile($cacheFile);
|
||||
} //fromCache
|
||||
|
||||
/**
|
||||
* Get text from an url or file
|
||||
* @param string The url or file path
|
||||
* @return string The text contained in the url or file, or an empty string
|
||||
*/
|
||||
function fromFile($filename) {
|
||||
if (function_exists('file_get_contents')) {
|
||||
return @file_get_contents($filename);
|
||||
}
|
||||
else {
|
||||
require_once(PHP_TEXT_CACHE_INCLUDE_PATH . 'php_file_utilities.php');
|
||||
$fileContents =& php_file_utilities::getDataFromFile($filename, 'r');
|
||||
return $fileContents;
|
||||
}
|
||||
|
||||
return '';
|
||||
} //fromFile
|
||||
} //php_text_cache
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class Timer {
|
||||
var $startTime;
|
||||
var $stopTime;
|
||||
|
||||
function start() {
|
||||
$this->startTime = microtime();
|
||||
} //start
|
||||
|
||||
function stop() {
|
||||
$this->stopTime = microtime();
|
||||
} //stop
|
||||
|
||||
function getTime() {
|
||||
return $this->elapsed($this->startTime, $this->stopTime);
|
||||
} //getTime
|
||||
|
||||
function elapsed($a, $b) {
|
||||
list($a_micro, $a_int) = explode(' ',$a);
|
||||
list($b_micro, $b_int) = explode(' ',$b);
|
||||
|
||||
if ($a_int > $b_int) {
|
||||
return ($a_int - $b_int) + ($a_micro - $b_micro);
|
||||
}
|
||||
else if ($a_int == $b_int) {
|
||||
if ($a_micro > $b_micro) {
|
||||
return ($a_int - $b_int) + ($a_micro - $b_micro);
|
||||
}
|
||||
else if ($a_micro<$b_micro) {
|
||||
return ($b_int - $a_int) + ($b_micro - $a_micro);
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else { // $a_int < $b_int
|
||||
return ($b_int - $a_int) + ($b_micro - $a_micro);
|
||||
}
|
||||
} //elapsed
|
||||
} //Timer
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* @package domit-xmlparser
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
|
||||
* DOMIT! is Free Software
|
||||
**/
|
||||
|
||||
/** Extension for cache files */
|
||||
define ('DOMIT_FILE_EXTENSION_CACHE', 'dch');
|
||||
|
||||
/**
|
||||
* A simple caching mechanism for a DOMIT_Document
|
||||
*/
|
||||
class DOMIT_cache {
|
||||
/**
|
||||
* Serializes and caches the specified DOMIT! document
|
||||
* @param string The name of the xml file to be saved
|
||||
* @param Object A reference to the document to be saved
|
||||
* @param string The write attributes for the saved document ('w' or 'wb')
|
||||
*/
|
||||
function toCache($xmlFileName, &$doc, $writeAttributes = 'w') {
|
||||
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
|
||||
require_once(DOMIT_INCLUDE_PATH . 'php_file_utilities.php');
|
||||
|
||||
$name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
|
||||
php_file_utilities::putDataToFile($name, serialize($doc), $writeAttributes);
|
||||
|
||||
return (file_exists($name) && is_writable($name));
|
||||
} //toCache
|
||||
|
||||
/**
|
||||
* Unserializes a cached DOMIT! document
|
||||
* @param string The name of the xml file to be retrieved
|
||||
* @return Object The retrieved document
|
||||
*/
|
||||
function &fromCache($xmlFileName) {
|
||||
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
|
||||
require_once(DOMIT_INCLUDE_PATH . 'php_file_utilities.php');
|
||||
|
||||
$name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
|
||||
$fileContents =& php_file_utilities::getDataFromFile($name, 'r');
|
||||
$newxmldoc =& unserialize($fileContents);
|
||||
|
||||
return $newxmldoc;
|
||||
} //fromCache
|
||||
|
||||
/**
|
||||
* Determines whether a cached version of the specified document exists
|
||||
* @param string The name of the xml file to be retrieved
|
||||
* @return boolean True if a cache of the specified document exists
|
||||
*/
|
||||
function cacheExists($xmlFileName) {
|
||||
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
|
||||
|
||||
$name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
|
||||
return file_exists($name);
|
||||
} //xmlFileName
|
||||
|
||||
/**
|
||||
* Removes a cache of the specified document
|
||||
* @param string The name of the xml file to be retrieved
|
||||
* @return boolean True if a cache has been removed
|
||||
*/
|
||||
function removeFromCache($xmlFileName) {
|
||||
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_utilities.php');
|
||||
|
||||
$name = DOMIT_Utilities::removeExtension($xmlFileName) . '.' . DOMIT_FILE_EXTENSION_CACHE;
|
||||
return unlink($name);
|
||||
} //removeFromCache
|
||||
} //DOMIT_cache
|
||||
?>
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* DOMIT! Doctor is a set of utilities for repairing malformed XML
|
||||
* @package domit-xmlparser
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
|
||||
* DOMIT! is Free Software
|
||||
**/
|
||||
|
||||
/**
|
||||
* A (static) class containing utilities for repairing malformed XML
|
||||
*
|
||||
* @package domit-xmlparser
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class domit_doctor {
|
||||
|
||||
/**
|
||||
* Looks for illegal ampersands and converts them to entities
|
||||
* @param string The xml text to be repaired
|
||||
* @return string The repaired xml text
|
||||
*/
|
||||
function fixAmpersands($xmlText) {
|
||||
$xmlText = trim($xmlText);
|
||||
$startIndex = -1;
|
||||
$processing = true;
|
||||
$illegalChar = '&';
|
||||
|
||||
while ($processing) {
|
||||
$startIndex = strpos($xmlText, $illegalChar, ($startIndex + 1));
|
||||
|
||||
if ($startIndex !== false) {
|
||||
$xmlText = domit_doctor::evaluateCharacter($xmlText,
|
||||
$illegalChar, ($startIndex + 1));
|
||||
}
|
||||
else {
|
||||
$processing = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $xmlText;
|
||||
} //fixAmpersands
|
||||
|
||||
/**
|
||||
* Evaluates whether an ampersand should be converted to an entity, and performs the conversion
|
||||
* @param string The xml text
|
||||
* @param string The (ampersand) character
|
||||
* @param int The character index immediately following the ampersand in question
|
||||
* @return string The repaired xml text
|
||||
*/
|
||||
function evaluateCharacter($xmlText, $illegalChar, $startIndex) {
|
||||
$total = strlen($xmlText);
|
||||
$searchingForCDATASection = false;
|
||||
|
||||
for ($i = $startIndex; $i < $total; $i++) {
|
||||
$currChar = substr($xmlText, $i, 1);
|
||||
|
||||
if (!$searchingForCDATASection) {
|
||||
switch ($currChar) {
|
||||
case ' ':
|
||||
case "'":
|
||||
case '"':
|
||||
case "\n":
|
||||
case "\r":
|
||||
case "\t":
|
||||
case '&':
|
||||
case "]":
|
||||
$searchingForCDATASection = true;
|
||||
break;
|
||||
case ";":
|
||||
return $xmlText;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch ($currChar) {
|
||||
case '<':
|
||||
case '>':
|
||||
return (substr_replace($xmlText, '&',
|
||||
($startIndex - 1) , 1));
|
||||
break;
|
||||
case "]":
|
||||
return $xmlText;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $xmlText;
|
||||
} //evaluateCharacter
|
||||
} //domit_doctor
|
||||
?>
|
||||
@@ -0,0 +1,278 @@
|
||||
<?php
|
||||
/**
|
||||
* @package domit-xmlparser
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
|
||||
* DOMIT! is Free Software
|
||||
**/
|
||||
|
||||
if (!defined('DOMIT_INCLUDE_PATH')) {
|
||||
define('DOMIT_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
}
|
||||
|
||||
/** Separator for elements path */
|
||||
define('GET_ELEMENTS_BY_PATH_SEPARATOR', '/');
|
||||
/** Constant for an absolute path search (starting at the document root) */
|
||||
define('GET_ELEMENTS_BY_PATH_SEARCH_ABSOLUTE', 0);
|
||||
/** Constant for a relative path search (starting at the level of the calling node) */
|
||||
define('GET_ELEMENTS_BY_PATH_SEARCH_RELATIVE', 1);
|
||||
/** Constant for a variable path search (finds all matches, regardless of place in the hierarchy) */
|
||||
define('GET_ELEMENTS_BY_PATH_SEARCH_VARIABLE', 2);
|
||||
|
||||
/**
|
||||
* getElementsByPath is a simple utility for path-based access to nodes in a DOMIT! document.
|
||||
*/
|
||||
class DOMIT_GetElementsByPath {
|
||||
/** @var Object The node from which the search is called */
|
||||
var $callingNode;
|
||||
/** @var int The type of search to be performed, i.e., relative, absolute, or variable */
|
||||
var $searchType;
|
||||
/** @var Object The node that is the current parent of the search */
|
||||
var $contextNode;
|
||||
/** @var array An array containing a series of path segments for which to search */
|
||||
var $arPathSegments = array();
|
||||
/** @var Object A DOMIT_NodeList of matching nodes */
|
||||
var $nodeList;
|
||||
/** @var Object The index of the current node of the search */
|
||||
var $targetIndex;
|
||||
/** @var Object if true, the search will be aborted once the first match is found */
|
||||
var $abortSearch = false;
|
||||
|
||||
/**
|
||||
* Constructor - creates an empty DOMIT_NodeList to store matching nodes
|
||||
*/
|
||||
function DOMIT_GetElementsByPath() {
|
||||
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_nodemaps.php');
|
||||
$this->nodeList = new DOMIT_NodeList();
|
||||
} //DOMIT_GetElementsByPath
|
||||
|
||||
/**
|
||||
* Parses the supplied "path"-based pattern
|
||||
* @param Object The node from which the search is called
|
||||
* @param string The pattern
|
||||
* @param int The node level of the current search
|
||||
* @return Object The NodeList containing matching nodes
|
||||
*/
|
||||
function &parsePattern(&$node, $pattern, $nodeIndex = 0) {
|
||||
$this->callingNode =& $node;
|
||||
$pattern = trim($pattern);
|
||||
|
||||
$this->determineSearchType($pattern);
|
||||
$this->setContextNode();
|
||||
$this->splitPattern($pattern);
|
||||
|
||||
$this->targetIndex = $nodeIndex;
|
||||
$totalSegments = count($this->arPathSegments);
|
||||
|
||||
if ($totalSegments > 0) {
|
||||
if ($this->searchType == GET_ELEMENTS_BY_PATH_SEARCH_VARIABLE) {
|
||||
$arContextNodes =& $this->contextNode->ownerDocument->getElementsByTagName($this->arPathSegments[0]);
|
||||
$totalContextNodes = $arContextNodes->getLength();
|
||||
|
||||
for ($i = 0; $i < $totalContextNodes; $i++) {
|
||||
$this->selectNamedChild($arContextNodes->item($i), 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($this->searchType == GET_ELEMENTS_BY_PATH_SEARCH_ABSOLUTE) {
|
||||
if ($this->contextNode->nodeName == $this->arPathSegments[0]) {
|
||||
if (count($this->arPathSegments) == 1) {
|
||||
$this->nodeList->appendNode($this->contextNode);
|
||||
}
|
||||
else {
|
||||
$this->selectNamedChild($this->contextNode, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($this->searchType == GET_ELEMENTS_BY_PATH_SEARCH_RELATIVE) {
|
||||
$this->selectNamedChild($this->contextNode, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($nodeIndex > 0) {
|
||||
if ($nodeIndex <= $this->nodeList->getLength()) {
|
||||
return $this->nodeList->item(($nodeIndex - 1));
|
||||
}
|
||||
else {
|
||||
$null = null;
|
||||
return $null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->nodeList;
|
||||
} //parsePattern
|
||||
|
||||
/**
|
||||
* Determines the type of search to be performed: absolute, relative, or variable
|
||||
* @param string The pattern
|
||||
*/
|
||||
function determineSearchType($pattern) {
|
||||
$firstChar = $pattern{0};
|
||||
|
||||
if ($firstChar != GET_ELEMENTS_BY_PATH_SEPARATOR) {
|
||||
//relative path
|
||||
$this->searchType = GET_ELEMENTS_BY_PATH_SEARCH_RELATIVE;
|
||||
}
|
||||
else {
|
||||
$secondChar = $pattern{1};
|
||||
|
||||
if ($secondChar != GET_ELEMENTS_BY_PATH_SEPARATOR) {
|
||||
//absolute path
|
||||
$this->searchType = GET_ELEMENTS_BY_PATH_SEARCH_ABSOLUTE;
|
||||
}
|
||||
else {
|
||||
//variable path
|
||||
$this->searchType = GET_ELEMENTS_BY_PATH_SEARCH_VARIABLE;
|
||||
}
|
||||
}
|
||||
} //determineSearchType
|
||||
|
||||
|
||||
/**
|
||||
* Sets the context node, i.e., the node from which the search begins
|
||||
*/
|
||||
function setContextNode() {
|
||||
switch($this->searchType) {
|
||||
case GET_ELEMENTS_BY_PATH_SEARCH_ABSOLUTE:
|
||||
$this->contextNode =& $this->callingNode->ownerDocument->documentElement;
|
||||
break;
|
||||
|
||||
case GET_ELEMENTS_BY_PATH_SEARCH_RELATIVE:
|
||||
if ($this->callingNode->uid != $this->callingNode->ownerDocument->uid) {
|
||||
$this->contextNode =& $this->callingNode;
|
||||
}
|
||||
else {
|
||||
$this->contextNode =& $this->callingNode->ownerDocument->documentElement;
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_ELEMENTS_BY_PATH_SEARCH_VARIABLE:
|
||||
$this->contextNode =& $this->callingNode->ownerDocument->documentElement;
|
||||
break;
|
||||
}
|
||||
} //setContextNode
|
||||
|
||||
/**
|
||||
* Splits the supplied pattern into searchable segments
|
||||
* @param string The pattern
|
||||
*/
|
||||
function splitPattern($pattern) {
|
||||
switch($this->searchType) {
|
||||
case GET_ELEMENTS_BY_PATH_SEARCH_ABSOLUTE:
|
||||
$lastIndex = 1;
|
||||
break;
|
||||
|
||||
case GET_ELEMENTS_BY_PATH_SEARCH_RELATIVE:
|
||||
$lastIndex = 0;
|
||||
break;
|
||||
|
||||
case GET_ELEMENTS_BY_PATH_SEARCH_VARIABLE:
|
||||
$lastIndex = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->arPathSegments = explode(GET_ELEMENTS_BY_PATH_SEPARATOR, substr($pattern, $lastIndex));
|
||||
} //splitPattern
|
||||
|
||||
/**
|
||||
* Matches the current path segment against the child nodes of the current context node
|
||||
* @param Object The context node
|
||||
* @param int The index in the arPathSegments array of the current path segment
|
||||
*/
|
||||
function selectNamedChild(&$node, $pIndex) {
|
||||
if (!$this->abortSearch) {
|
||||
if ($pIndex < count($this->arPathSegments)) { //not at last path segment
|
||||
$name = $this->arPathSegments[$pIndex];
|
||||
$numChildren = $node->childCount;
|
||||
|
||||
for ($i = 0; $i < $numChildren; $i++) {
|
||||
$currentChild =& $node->childNodes[$i];
|
||||
|
||||
if ($currentChild->nodeName == $name) {
|
||||
$this->selectNamedChild($currentChild, ($pIndex + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->nodeList->appendNode($node);
|
||||
|
||||
if ($this->targetIndex == $this->nodeList->getLength()) {
|
||||
$this->abortSearch = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} //selectNamedChild
|
||||
} //DOMIT_GetElementsByPath
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* getElementsByAttributePath is a temporary utility requested by a DOMIT! user for path-based access to attributes in a DOMIT! document.
|
||||
* This class may be absent from future versions of DOMIT!
|
||||
*/
|
||||
class DOMIT_GetElementsByAttributePath {
|
||||
/** @var Object A DOMIT_NodeList of matching attribute nodes */
|
||||
var $nodeList;
|
||||
|
||||
/**
|
||||
* Constructor - creates an empty DOMIT_NodeList to store matching nodes
|
||||
*/
|
||||
function DOMIT_GetElementsByAttributePath() {
|
||||
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_nodemaps.php');
|
||||
$this->nodeList = new DOMIT_NodeList();
|
||||
} //DOMIT_GetElementsByAttributePath
|
||||
|
||||
/**
|
||||
* Matches the current path segment against the child nodes of the current context node
|
||||
* @param Object The context node
|
||||
* @param string The pattern
|
||||
* @param int The index of the current path segment
|
||||
*/
|
||||
function &parsePattern(&$node, $pattern, $nodeIndex = 0) {
|
||||
$beginSquareBrackets = strpos($pattern, '[');
|
||||
|
||||
if ($beginSquareBrackets != 0) {
|
||||
$path = substr($pattern, 0, $beginSquareBrackets);
|
||||
|
||||
$attrPattern = substr($pattern, (strpos($pattern, '@') + 1));
|
||||
$attrPattern = substr($attrPattern, 0, strpos($attrPattern, ')'));
|
||||
|
||||
$commaIndex = strpos($attrPattern, ',');
|
||||
$key = trim(substr($attrPattern, 0, $commaIndex));
|
||||
$value = trim(substr($attrPattern, ($commaIndex + 1)));
|
||||
$value = substr($value, 1, (strlen($value) - 2));
|
||||
|
||||
$gebp = new DOMIT_GetElementsByPath();
|
||||
$myResponse =& $gebp->parsePattern($node, $path);
|
||||
|
||||
$total = $myResponse->getLength();
|
||||
|
||||
for ($i = 0; $i < $total; $i++) {
|
||||
$currNode =& $myResponse->item($i);
|
||||
|
||||
if ($currNode->hasAttribute($key)) {
|
||||
if ($currNode->getAttribute($key) == $value) {
|
||||
$this->nodeList->appendNode($currNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($nodeIndex == 0) {
|
||||
return $this->nodeList;
|
||||
}
|
||||
else {
|
||||
if ($nodeIndex <= $this->nodeList->getLength()) {
|
||||
return $this->nodeList->item(($nodeIndex - 1));
|
||||
}
|
||||
else {
|
||||
$this->nodeList = new DOMIT_NodeList();
|
||||
return $this->nodeList;
|
||||
}
|
||||
}
|
||||
} //parsePattern
|
||||
} //DOMIT_GetElementsByAttributePath
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* @package domit-xmlparser
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
|
||||
* DOMIT! is Free Software
|
||||
**/
|
||||
|
||||
/** The file system path to the domit library */
|
||||
|
||||
if (!defined( 'DOMIT_INCLUDE_PATH' )) {
|
||||
define('DOMIT_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
}
|
||||
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_parser.php');
|
||||
?>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @package domit-xmlparser
|
||||
* @subpackage domit-xmlparser-lite
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
|
||||
* DOMIT! is Free Software
|
||||
**/
|
||||
|
||||
/** The file system path to the domit library */
|
||||
define('DOMIT_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_lite_parser.php');
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
/**
|
||||
* nodetools is a class of miscellaneous XML helper methods
|
||||
* @package domit-xmlparser
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
|
||||
* DOMIT! is Free Software
|
||||
**/
|
||||
|
||||
/** attribute parse state, just before parsing an attribute */
|
||||
define('DOMIT_ATTRIBUTEPARSER_STATE_ATTR_NONE', 0);
|
||||
/** attribute parse state, parsing an attribute key */
|
||||
define('DOMIT_ATTRIBUTEPARSER_STATE_ATTR_KEY', 1);
|
||||
/** attribute parse state, parsing an attribute value */
|
||||
define('DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE', 2);
|
||||
|
||||
/**
|
||||
*@global Array Translation table for predefined XML entities
|
||||
*/
|
||||
$GLOBALS['DOMIT_PREDEFINED_ENTITIES'] = array('&' => '&', '<' => '<', '>' => '>',
|
||||
'"' => '"', "'" => ''');
|
||||
|
||||
/**
|
||||
* A class of miscellaneous XML helper methods
|
||||
*
|
||||
* @package domit-xmlparser
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class nodetools {
|
||||
/**
|
||||
* Parses the attributes string into an array of key / value pairs
|
||||
* @param string The attribute text
|
||||
* @return Array An array of key / value pairs
|
||||
*/
|
||||
function parseAttributes($attrText, $convertEntities = true, $definedEntities = null) {
|
||||
$attrText = trim($attrText);
|
||||
$attrArray = array();
|
||||
$maybeEntity = false;
|
||||
|
||||
$total = strlen($attrText);
|
||||
$keyDump = '';
|
||||
$valueDump = '';
|
||||
$currentState = DOMIT_ATTRIBUTEPARSER_STATE_ATTR_NONE;
|
||||
$quoteType = '';
|
||||
|
||||
if ($definedEntities == null) $defineEntities = array();
|
||||
|
||||
for ($i = 0; $i < $total; $i++) {
|
||||
// $currentChar = $attrText{$i};
|
||||
$currentChar = substr($attrText, $i, 1);
|
||||
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_NONE) {
|
||||
if (trim($currentChar != '')) {
|
||||
$currentState = DOMIT_ATTRIBUTEPARSER_STATE_ATTR_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($currentChar) {
|
||||
case "\t":
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE) {
|
||||
$valueDump .= $currentChar;
|
||||
}
|
||||
else {
|
||||
$currentChar = '';
|
||||
}
|
||||
break;
|
||||
|
||||
case "\x0B": //vertical tab
|
||||
case "\n":
|
||||
case "\r":
|
||||
$currentChar = '';
|
||||
break;
|
||||
|
||||
case '=':
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE) {
|
||||
$valueDump .= $currentChar;
|
||||
}
|
||||
else {
|
||||
$currentState = DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE;
|
||||
$quoteType = '';
|
||||
$maybeEntity = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case '"':
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE) {
|
||||
if ($quoteType == '') {
|
||||
$quoteType = '"';
|
||||
}
|
||||
else {
|
||||
if ($quoteType == $currentChar) {
|
||||
if ($convertEntities && $maybeEntity) {
|
||||
$valueDump = strtr($valueDump, DOMIT_PREDEFINED_ENTITIES);
|
||||
$valueDump = strtr($valueDump, $definedEntities);
|
||||
}
|
||||
|
||||
$attrArray[trim($keyDump)] = $valueDump;
|
||||
$keyDump = $valueDump = $quoteType = '';
|
||||
$currentState = DOMIT_ATTRIBUTEPARSER_STATE_ATTR_NONE;
|
||||
}
|
||||
else {
|
||||
$valueDump .= $currentChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "'":
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE) {
|
||||
if ($quoteType == '') {
|
||||
$quoteType = "'";
|
||||
}
|
||||
else {
|
||||
if ($quoteType == $currentChar) {
|
||||
if ($convertEntities && $maybeEntity) {
|
||||
$valueDump = strtr($valueDump, $predefinedEntities);
|
||||
$valueDump = strtr($valueDump, $definedEntities);
|
||||
}
|
||||
|
||||
$attrArray[trim($keyDump)] = $valueDump;
|
||||
$keyDump = $valueDump = $quoteType = '';
|
||||
$currentState = DOMIT_ATTRIBUTEPARSER_STATE_ATTR_NONE;
|
||||
}
|
||||
else {
|
||||
$valueDump .= $currentChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case '&':
|
||||
//might be an entity
|
||||
$maybeEntity = true;
|
||||
$valueDump .= $currentChar;
|
||||
break;
|
||||
|
||||
default:
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_KEY) {
|
||||
$keyDump .= $currentChar;
|
||||
}
|
||||
else {
|
||||
$valueDump .= $currentChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $attrArray;
|
||||
} //parseAttributes
|
||||
|
||||
/**
|
||||
* Move a node to the previous index in the childNodes array
|
||||
* @param Object The node to be moved
|
||||
*/
|
||||
function moveUp(&$node) {
|
||||
if (($node->previousSibling != null) && ($node->parentNode != null)) {
|
||||
$parent =& $node->parentNode;
|
||||
$previous =& $node->previousSibling;
|
||||
|
||||
$node =& $parent->removeChild($node);
|
||||
$parent->insertBefore($node, $previous);
|
||||
}
|
||||
} //moveUp
|
||||
|
||||
/**
|
||||
* Move a node to the next index in the childNodes array
|
||||
* @param Object The node to be moved
|
||||
*/
|
||||
function moveDown(&$node) {
|
||||
if (($node->nextSibling != null) && ($node->parentNode != null)) {
|
||||
$parent =& $node->parentNode;
|
||||
|
||||
if ($node->nextSibling->nextSibling == null) {
|
||||
$node =& $parent->removeChild($node);
|
||||
$parent->appendChild($node);
|
||||
}
|
||||
else {
|
||||
$insertionPoint =& $node->nextSibling->nextSibling;
|
||||
$node =& $parent->removeChild($node);
|
||||
$parent->insertBefore($node, $insertionPoint);
|
||||
}
|
||||
}
|
||||
} //moveDown
|
||||
|
||||
/**
|
||||
* Checks if a node exists on the given path; if so, returns the node, otherwise false
|
||||
* @param Object The calling node
|
||||
* @param string The path
|
||||
* @return mixed The found node, or false
|
||||
*/
|
||||
function &nodeExists(&$callingNode, $path) {
|
||||
$foundNode =& $callingNode->getElementsByPath($path, 1);
|
||||
|
||||
if ($foundNode == null) return false;
|
||||
return $foundNode;
|
||||
} //nodeExists
|
||||
|
||||
/**
|
||||
* Generates a heirarchy of nodes based on a path expression
|
||||
* @param string The path expression
|
||||
* @param string The value of a text node to be appended to the last element
|
||||
* @return object The generated nodes
|
||||
*/
|
||||
function &fromPath(&$xmldoc, $path, $text = null) {
|
||||
$pathSegments = explode('/', $path);
|
||||
$parent = null;
|
||||
$lastNode = null;
|
||||
$total = count($pathSegments);
|
||||
|
||||
for ($i = 0; $i < $total; $i++) {
|
||||
if ($pathSegments[$i] != '') {
|
||||
$currNode =& $xmldoc->createElement($pathSegments[$i]);
|
||||
|
||||
if ($parent == null) {
|
||||
$parent =& $currNode;
|
||||
}
|
||||
else {
|
||||
$lastNode->appendChild($currNode);
|
||||
}
|
||||
|
||||
$lastNode =& $currNode;
|
||||
}
|
||||
}
|
||||
|
||||
if ($text != null) {
|
||||
$currNode =& $xmldoc->createTextNode($text);
|
||||
$lastNode->appendChild($currNode);
|
||||
}
|
||||
|
||||
return $parent;
|
||||
} //nodeExists
|
||||
} //nodetools
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* parseAttributes is a function for parsing attribute and attribute-like strings
|
||||
* @package domit-xmlparser
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
|
||||
* DOMIT! is Free Software
|
||||
**/
|
||||
|
||||
/** attribute parse state, just before parsing an attribute */
|
||||
define('DOMIT_ATTRIBUTEPARSER_STATE_ATTR_NONE', 0);
|
||||
/** attribute parse state, parsing an attribute key */
|
||||
define('DOMIT_ATTRIBUTEPARSER_STATE_ATTR_KEY', 1);
|
||||
/** attribute parse state, parsing an attribute value */
|
||||
define('DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE', 2);
|
||||
|
||||
/**
|
||||
*@global Array Translation table for predefined XML entities
|
||||
*/
|
||||
$GLOBALS['DOMIT_PREDEFINED_ENTITIES'] = array('&' => '&', '<' => '<', '>' => '>',
|
||||
'"' => '"', "'" => ''');
|
||||
|
||||
/**
|
||||
* Parses the attributes string into an array of key / value pairs
|
||||
* @param string The attribute text
|
||||
* @return Array An array of key / value pairs
|
||||
*/
|
||||
function parseAttributes($attrText, $convertEntities = true, $definedEntities = null) {
|
||||
$attrText = trim($attrText);
|
||||
$attrArray = array();
|
||||
$maybeEntity = false;
|
||||
|
||||
$total = strlen($attrText);
|
||||
$keyDump = '';
|
||||
$valueDump = '';
|
||||
$currentState = DOMIT_ATTRIBUTEPARSER_STATE_ATTR_NONE;
|
||||
$quoteType = '';
|
||||
|
||||
if ($definedEntities == null) $defineEntities = array();
|
||||
|
||||
for ($i = 0; $i < $total; $i++) {
|
||||
// $currentChar = $attrText{$i};
|
||||
$currentChar = substr($attrText, $i, 1);
|
||||
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_NONE) {
|
||||
if (trim($currentChar != '')) {
|
||||
$currentState = DOMIT_ATTRIBUTEPARSER_STATE_ATTR_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($currentChar) {
|
||||
case "\t":
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE) {
|
||||
$valueDump .= $currentChar;
|
||||
}
|
||||
else {
|
||||
$currentChar = '';
|
||||
}
|
||||
break;
|
||||
|
||||
case "\x0B": //vertical tab
|
||||
case "\n":
|
||||
case "\r":
|
||||
$currentChar = '';
|
||||
break;
|
||||
|
||||
case '=':
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE) {
|
||||
$valueDump .= $currentChar;
|
||||
}
|
||||
else {
|
||||
$currentState = DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE;
|
||||
$quoteType = '';
|
||||
$maybeEntity = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case '"':
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE) {
|
||||
if ($quoteType == '') {
|
||||
$quoteType = '"';
|
||||
}
|
||||
else {
|
||||
if ($quoteType == $currentChar) {
|
||||
if ($convertEntities && $maybeEntity) {
|
||||
$valueDump = strtr($valueDump, DOMIT_PREDEFINED_ENTITIES);
|
||||
$valueDump = strtr($valueDump, $definedEntities);
|
||||
}
|
||||
|
||||
$attrArray[trim($keyDump)] = $valueDump;
|
||||
$keyDump = $valueDump = $quoteType = '';
|
||||
$currentState = DOMIT_ATTRIBUTEPARSER_STATE_ATTR_NONE;
|
||||
}
|
||||
else {
|
||||
$valueDump .= $currentChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "'":
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_VALUE) {
|
||||
if ($quoteType == '') {
|
||||
$quoteType = "'";
|
||||
}
|
||||
else {
|
||||
if ($quoteType == $currentChar) {
|
||||
if ($convertEntities && $maybeEntity) {
|
||||
$valueDump = strtr($valueDump, $predefinedEntities);
|
||||
$valueDump = strtr($valueDump, $definedEntities);
|
||||
}
|
||||
|
||||
$attrArray[trim($keyDump)] = $valueDump;
|
||||
$keyDump = $valueDump = $quoteType = '';
|
||||
$currentState = DOMIT_ATTRIBUTEPARSER_STATE_ATTR_NONE;
|
||||
}
|
||||
else {
|
||||
$valueDump .= $currentChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case '&':
|
||||
//might be an entity
|
||||
$maybeEntity = true;
|
||||
$valueDump .= $currentChar;
|
||||
break;
|
||||
|
||||
default:
|
||||
if ($currentState == DOMIT_ATTRIBUTEPARSER_STATE_ATTR_KEY) {
|
||||
$keyDump .= $currentChar;
|
||||
}
|
||||
else {
|
||||
$valueDump .= $currentChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $attrArray;
|
||||
} //parseAttributes
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
/**
|
||||
* DOMIT! RSS Lite is a lightweight version of the DOMIT! Lite RSS parser
|
||||
* @package domit-rss
|
||||
* @subpackage domit-rss-lite
|
||||
* @version 0.51
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/domitrss/ DOMIT! RSS Home Page
|
||||
* DOMIT! RSS is Free Software
|
||||
**/
|
||||
|
||||
if (!defined('DOMIT_RSS_INCLUDE_PATH')) {
|
||||
define('DOMIT_RSS_INCLUDE_PATH', (dirname(__FILE__) . DIRECTORY_SEPARATOR));
|
||||
}
|
||||
|
||||
/** current version of DOMIT! RSS Lite */
|
||||
define ('DOMIT_RSS_LITE_VERSION', '0.51');
|
||||
|
||||
require_once(DOMIT_RSS_INCLUDE_PATH . 'xml_domit_rss_shared.php');
|
||||
|
||||
/**
|
||||
* The base DOMIT! RSS Lite document class
|
||||
*
|
||||
* @package domit-rss
|
||||
* @subpackage domit-rss-lite
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class xml_domit_rss_document_lite extends xml_domit_rss_base_document {
|
||||
/**
|
||||
* Constructor
|
||||
* @param string Path to the rss file
|
||||
* @param string Directory for cache files
|
||||
* @param int Expiration time for a cache file
|
||||
*/
|
||||
function xml_domit_rss_document_lite($url = '', $cacheDir = './', $cacheTime = 3600) {
|
||||
$this->parser = 'DOMIT_RSS_LITE';
|
||||
$this->xml_domit_rss_base_document($url, $cacheDir, $cacheTime);
|
||||
} //xml_domit_rss_document_lite
|
||||
|
||||
/**
|
||||
* Performs initialization of the RSS document
|
||||
*/
|
||||
function _init() {
|
||||
$total = $this->node->documentElement->childCount;
|
||||
$itemCounter = 0;
|
||||
$channelCounter = 0;
|
||||
|
||||
for ($i = 0; $i < $total; $i++) {
|
||||
$currNode =& $this->node->documentElement->childNodes[$i];
|
||||
$tagName = strtolower($currNode->nodeName);
|
||||
|
||||
switch ($tagName) {
|
||||
case DOMIT_RSS_ELEMENT_ITEM:
|
||||
$this->domit_rss_items[$itemCounter] = new xml_domit_rss_item_lite($currNode);
|
||||
$itemCounter++;
|
||||
break;
|
||||
case DOMIT_RSS_ELEMENT_CHANNEL:
|
||||
$this->domit_rss_channels[$channelCounter] = new xml_domit_rss_channel_lite($currNode);
|
||||
$channelCounter++;
|
||||
break;
|
||||
case DOMIT_RSS_ELEMENT_TITLE:
|
||||
case DOMIT_RSS_ELEMENT_LINK:
|
||||
case DOMIT_RSS_ELEMENT_DESCRIPTION:
|
||||
$this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($itemCounter != 0) {
|
||||
$this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_ITEMS] =& $this->domit_rss_items;
|
||||
}
|
||||
|
||||
if ($channelCounter != 0) {
|
||||
$this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_CHANNELS] =& $this->domit_rss_channels;
|
||||
}
|
||||
|
||||
$this->handleChannelElementsEmbedded();
|
||||
} //_init
|
||||
|
||||
/**
|
||||
* Returns the current version of DOMIT! RSS
|
||||
* @return Object The current version of DOMIT! RSS
|
||||
*/
|
||||
function getVersion() {
|
||||
return DOMIT_RSS_LITE_VERSION;
|
||||
} //getVersion
|
||||
} //xml_domit_rss_document_lite
|
||||
|
||||
/**
|
||||
* Represents an RSS channel
|
||||
*
|
||||
* @package domit-rss
|
||||
* @subpackage domit-rss-lite
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class xml_domit_rss_channel_lite extends xml_domit_rss_elementindexer {
|
||||
/** @var array A list of references to channel items */
|
||||
var $domit_rss_items = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param Object A DOM node containing channel data
|
||||
*/
|
||||
function xml_domit_rss_channel_lite(&$channel) {
|
||||
$this->node =& $channel;
|
||||
$this->_init();
|
||||
} //xml_domit_rss_channel_lite
|
||||
|
||||
/**
|
||||
* Performs initialization of the RSS channel element
|
||||
*/
|
||||
function _init() {
|
||||
$total = $this->node->childCount;
|
||||
$itemCounter = 0;
|
||||
|
||||
for ($i = 0; $i < $total; $i++) {
|
||||
$currNode =& $this->node->childNodes[$i];
|
||||
$tagName = strtolower($currNode->nodeName);
|
||||
|
||||
switch ($tagName) {
|
||||
case DOMIT_RSS_ELEMENT_ITEM:
|
||||
$this->domit_rss_items[$itemCounter] = new xml_domit_rss_item_lite($currNode);
|
||||
$itemCounter++;
|
||||
break;
|
||||
case DOMIT_RSS_ELEMENT_TITLE:
|
||||
case DOMIT_RSS_ELEMENT_LINK:
|
||||
case DOMIT_RSS_ELEMENT_DESCRIPTION:
|
||||
$this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($itemCounter != 0) {
|
||||
$this->DOMIT_RSS_indexer[DOMIT_RSS_ARRAY_ITEMS] =& $this->domit_rss_items;
|
||||
}
|
||||
} //_init
|
||||
|
||||
/**
|
||||
* Returns the title of the channel
|
||||
* @return string The title of the channel, or an empty string
|
||||
*/
|
||||
function getTitle() {
|
||||
return $this->getElementText(DOMIT_RSS_ELEMENT_TITLE);
|
||||
} //getTitle
|
||||
|
||||
/**
|
||||
* Returns the url of the channel
|
||||
* @return string The url of the channel, or an empty string
|
||||
*/
|
||||
function getLink() {
|
||||
return $this->getElementText(DOMIT_RSS_ELEMENT_LINK);
|
||||
} //getLink
|
||||
|
||||
/**
|
||||
* Returns a description of the channel
|
||||
* @return string A description of the channel, or an empty string
|
||||
*/
|
||||
function getDescription() {
|
||||
return $this->getElementText(DOMIT_RSS_ELEMENT_DESCRIPTION);
|
||||
} //getDescription
|
||||
|
||||
/**
|
||||
* Returns the number of items in the channel
|
||||
* @return int The number of items in the channel
|
||||
*/
|
||||
function getItemCount() {
|
||||
return count($this->domit_rss_items);
|
||||
} //getItemCount
|
||||
|
||||
/**
|
||||
* Returns a reference to the item at the specified index
|
||||
* @param int The index of the requested item
|
||||
* @return Object A reference to the item at the specified index
|
||||
*/
|
||||
function &getItem($index) {
|
||||
return $this->domit_rss_items[$index];
|
||||
} //getItem
|
||||
} //xml_domit_rss_channel_lite
|
||||
|
||||
/**
|
||||
* Represents an RSS item
|
||||
*
|
||||
* @package domit-rss
|
||||
* @subpackage domit-rss-lite
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class xml_domit_rss_item_lite extends xml_domit_rss_elementindexer {
|
||||
/**
|
||||
* Constructor
|
||||
* @param Object A DOM node containing item data
|
||||
*/
|
||||
function xml_domit_rss_item_lite(&$item) {
|
||||
$this->node =& $item;
|
||||
$this->_init();
|
||||
} //xml_domit_rss_item_lite
|
||||
|
||||
/**
|
||||
* Performs initialization of the item element
|
||||
*/
|
||||
function _init(){
|
||||
$total = $this->node->childCount;
|
||||
|
||||
for($i = 0; $i < $total; $i++) {
|
||||
$currNode =& $this->node->childNodes[$i];
|
||||
$tagName = strtolower($currNode->nodeName);
|
||||
|
||||
switch ($tagName) {
|
||||
case DOMIT_RSS_ELEMENT_TITLE:
|
||||
case DOMIT_RSS_ELEMENT_LINK:
|
||||
case DOMIT_RSS_ELEMENT_DESCRIPTION:
|
||||
$this->DOMIT_RSS_indexer[$tagName] = new xml_domit_rss_simpleelement($currNode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} //init
|
||||
|
||||
/**
|
||||
* Returns the title of the item
|
||||
* @return string The title of the item, or an empty string
|
||||
*/
|
||||
function getTitle() {
|
||||
return $this->getElementText(DOMIT_RSS_ELEMENT_TITLE);
|
||||
} //getTitle
|
||||
|
||||
/**
|
||||
* Returns the url of the item
|
||||
* @return string The url of the item, or an empty string
|
||||
*/
|
||||
function getLink() {
|
||||
return $this->getElementText(DOMIT_RSS_ELEMENT_LINK);
|
||||
} //getLink
|
||||
|
||||
/**
|
||||
* Returns a description of the item
|
||||
* @return string A description of the item, or an empty string
|
||||
*/
|
||||
function getDescription() {
|
||||
return $this->getElementText(DOMIT_RSS_ELEMENT_DESCRIPTION);
|
||||
} //getDescription
|
||||
} //xml_domit_rss_item_lite
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
/**
|
||||
* @package domit-xmlparser
|
||||
* @version 1.01
|
||||
* @copyright (C) 2004 John Heinstein. All rights reserved
|
||||
* @author John Heinstein <[email protected]>
|
||||
* @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
|
||||
* DOMIT! is Free Software
|
||||
**/
|
||||
|
||||
if (!defined('DOMIT_INCLUDE_PATH')) {
|
||||
/* Path to DOMIT! files */
|
||||
define('DOMIT_INCLUDE_PATH', (dirname(__FILE__) . "/"));
|
||||
}
|
||||
|
||||
//Nodes
|
||||
/** DOM Element nodeType */
|
||||
define('DOMIT_ELEMENT_NODE', 1);
|
||||
/** DOM Attr nodeType */
|
||||
define('DOMIT_ATTRIBUTE_NODE', 2);
|
||||
/** DOM Text nodeType */
|
||||
define('DOMIT_TEXT_NODE', 3);
|
||||
/** DOM CDATA Section nodeType */
|
||||
define('DOMIT_CDATA_SECTION_NODE', 4);
|
||||
/** DOM Entity Reference nodeType */
|
||||
define('DOMIT_ENTITY_REFERENCE_NODE', 5);
|
||||
/** DOM Entity nodeType */
|
||||
define('DOMIT_ENTITY_NODE', 6);
|
||||
/** DOM Processing Instruction nodeType */
|
||||
define('DOMIT_PROCESSING_INSTRUCTION_NODE', 7);
|
||||
/** DOM Comment nodeType */
|
||||
define('DOMIT_COMMENT_NODE', 8);
|
||||
/** DOM Document nodeType */
|
||||
define('DOMIT_DOCUMENT_NODE', 9);
|
||||
/** DOM DocType nodeType */
|
||||
define('DOMIT_DOCUMENT_TYPE_NODE', 10);
|
||||
/** DOM Document Fragment nodeType */
|
||||
define('DOMIT_DOCUMENT_FRAGMENT_NODE', 11);
|
||||
/** DOM Notation nodeType */
|
||||
define('DOMIT_NOTATION_NODE', 12);
|
||||
|
||||
//DOM Level 1 Exceptions
|
||||
/** DOM error: array index out of bounds */
|
||||
define('DOMIT_INDEX_SIZE_ERR', 1);
|
||||
/** DOM error: text doesn't fit into a DOMString */
|
||||
define('DOMIT_DOMSTRING_SIZE_ERR', 2);
|
||||
/** DOM error: node can't be inserted at this location */
|
||||
define('DOMIT_HIERARCHY_REQUEST_ERR', 3);
|
||||
/** DOM error: node not a child of target document */
|
||||
define('DOMIT_WRONG_DOCUMENT_ERR', 4);
|
||||
/** DOM error: invalid character specified */
|
||||
define('DOMIT_INVALID_CHARACTER_ERR', 5);
|
||||
/** DOM error: data can't be added to current node */
|
||||
define('DOMIT_NO_DATA_ALLOWED_ERR', 6);
|
||||
/** DOM error: node is read-only */
|
||||
define('DOMIT_NO_MODIFICATION_ALLOWED_ERR', 7);
|
||||
/** DOM error: node can't be found in specified context */
|
||||
define('DOMIT_NOT_FOUND_ERR', 8);
|
||||
/** DOM error: operation not supported by current implementation */
|
||||
define('DOMIT_NOT_SUPPORTED_ERR', 9);
|
||||
/** DOM error: attribute currently in use elsewhere */
|
||||
define('DOMIT_INUSE_ATTRIBUTE_ERR', 10);
|
||||
|
||||
//DOM Level 2 Exceptions
|
||||
/** DOM error: attempt made to use an object that is no longer usable */
|
||||
define('DOMIT_INVALID_STATE_ERR', 11);
|
||||
/** DOM error: invalid or illegal string specified */
|
||||
define('DOMIT_SYNTAX_ERR', 12);
|
||||
/** DOM error: can't modify underlying type of node */
|
||||
define('DOMIT_INVALID_MODIFICATION_ERR', 13);
|
||||
/** DOM error: attempt to change node in a way incompatible with namespaces */
|
||||
define('DOMIT_NAMESPACE_ERR', 14);
|
||||
/** DOM error: operation unsupported by underlying object */
|
||||
define('DOMIT_INVALID_ACCESS_ERR', 15);
|
||||
|
||||
//DOMIT! Exceptions
|
||||
/** DOM error: attempt to instantiate abstract class */
|
||||
define('DOMIT_ABSTRACT_CLASS_INSTANTIATION_ERR', 100);
|
||||
/** DOM error: attempt to call abstract method */
|
||||
define('DOMIT_ABSTRACT_METHOD_INVOCATION_ERR', 101);
|
||||
/** DOM error: can't perform this action on or with Document Fragment */
|
||||
define('DOMIT_DOCUMENT_FRAGMENT_ERR', 102);
|
||||
|
||||
//DOMIT! Error Modes
|
||||
/** continue on error */
|
||||
define('DOMIT_ONERROR_CONTINUE', 1);
|
||||
/** die on error */
|
||||
define('DOMIT_ONERROR_DIE', 2);
|
||||
|
||||
|
||||
/**
|
||||
*@global Object Instance of the UIDGenerator class
|
||||
*/
|
||||
$GLOBALS['uidFactory'] = new UIDGenerator();
|
||||
|
||||
require_once(DOMIT_INCLUDE_PATH . 'xml_domit_nodemaps.php');
|
||||
|
||||
/**
|
||||
* Generates unique ids for each node
|
||||
*
|
||||
* @package domit-xmlparser
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class UIDGenerator {
|
||||
/** @var int A seed value for generating uids */
|
||||
var $seed;
|
||||
/** @var int A tally of the number of uids generated */
|
||||
var $counter = 0;
|
||||
|
||||
/**
|
||||
* UIDGenerator constructor
|
||||
*/
|
||||
function UIDGenerator() {
|
||||
$this->seed = 'node' . time();
|
||||
} //UIDGenerator
|
||||
|
||||
/**
|
||||
* Generates a unique id
|
||||
* @return uid
|
||||
*/
|
||||
function generateUID() {
|
||||
return ($this->seed . $this->counter++);
|
||||
} //generateUID
|
||||
} //UIDGenerator
|
||||
|
||||
/**
|
||||
* @global object Reference to custom error handler for DOMException class
|
||||
*/
|
||||
$GLOBALS['DOMIT_DOMException_errorHandler'] = null;
|
||||
/**
|
||||
* @global int Error mode; specifies whether to die on error or simply return
|
||||
*/
|
||||
$GLOBALS['DOMIT_DOMException_mode'] = DOMIT_ONERROR_CONTINUE;
|
||||
/**
|
||||
* @global string Log file for errors
|
||||
*/
|
||||
$GLOBALS['DOMIT_DOMException_log'] = null;
|
||||
|
||||
/**
|
||||
* A DOMIT! exception handling class
|
||||
*
|
||||
* @package domit-xmlparser
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class DOMIT_DOMException {
|
||||
/**
|
||||
* Raises the specified exception
|
||||
* @param int The error number
|
||||
* @param string A string explanation of the error
|
||||
*/
|
||||
function raiseException($errorNum, $errorString) {
|
||||
if ($GLOBALS['DOMIT_DOMException_errorHandler'] != null) {
|
||||
call_user_func($GLOBALS['DOMIT_DOMException_errorHandler'], $errorNum, $errorString);
|
||||
}
|
||||
else {
|
||||
$errorMessageText = $errorNum . ' ' . $errorString;
|
||||
$errorMessage = 'Error: ' . $errorMessageText;
|
||||
|
||||
if ((!isset($GLOBALS['DOMIT_ERROR_FORMATTING_HTML'])) ||
|
||||
($GLOBALS['DOMIT_ERROR_FORMATTING_HTML'] == true)) {
|
||||
$errorMessage = "<p><pre>" . $errorMessage . "</pre></p>";
|
||||
}
|
||||
|
||||
//log error to file
|
||||
if ((isset($GLOBALS['DOMIT_DOMException_log'])) &&
|
||||
($GLOBALS['DOMIT_DOMException_log'] != null)) {
|
||||
require_once(DOMIT_INCLUDE_PATH . 'php_file_utilities.php');
|
||||
$logItem = "\n" . date('Y-m-d H:i:s') . 'DOMIT! Error ' . $errorMessageText;
|
||||
php_file_utilities::putDataToFile($GLOBALS['DOMIT_DOMException_log'],
|
||||
$logItem, 'a');
|
||||
}
|
||||
|
||||
switch ($GLOBALS['DOMIT_DOMException_mode']) {
|
||||
case DOMIT_ONERROR_CONTINUE:
|
||||
return;
|
||||
break;
|
||||
|
||||
case DOMIT_ONERROR_DIE:
|
||||
die($errorMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} //raiseException
|
||||
|
||||
/**
|
||||
* custom handler for DOM errors
|
||||
* @param object A reference to the custom error handler
|
||||
*/
|
||||
function setErrorHandler($method) {
|
||||
$GLOBALS['DOMIT_DOMException_errorHandler'] =& $method;
|
||||
} //setErrorHandler
|
||||
|
||||
/**
|
||||
* Set error mode
|
||||
* @param int The DOM error mode
|
||||
*/
|
||||
function setErrorMode($mode) {
|
||||
$GLOBALS['DOMIT_DOMException_mode'] = $mode;
|
||||
} //setErrorMode
|
||||
|
||||
/**
|
||||
* Set error mode
|
||||
* @param boolean True if errors should be logged
|
||||
* @param string Absolute or relative path to log file
|
||||
*/
|
||||
function setErrorLog($doLogErrors, $logfile) {
|
||||
if ($doLogErrors) {
|
||||
$GLOBALS['DOMIT_DOMException_log'] = $logfile;
|
||||
}
|
||||
else {
|
||||
$GLOBALS['DOMIT_DOMException_log'] = null;
|
||||
}
|
||||
} //setErrorLog
|
||||
} //DOMIT_DOMException
|
||||
|
||||
/**
|
||||
* A class representing the DOM Implementation node
|
||||
*
|
||||
* @package domit-xmlparser
|
||||
* @author John Heinstein <[email protected]>
|
||||
*/
|
||||
class DOMIT_DOMImplementation {
|
||||
function hasFeature($feature, $version = null) {
|
||||
if (strtoupper($feature) == 'XML') {
|
||||
if (($version == '1.0') || ($version == '2.0') || ($version == null)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} //hasFeature
|
||||
|
||||
/**
|
||||
* Creates a new DOMIT_Document node and appends a documentElement with the specified info
|
||||
* @param string The namespaceURI of the documentElement
|
||||
* @param string The $qualifiedName of the documentElement
|
||||
* @param Object A document type node
|
||||
* @return Object The new document fragment node
|
||||
*/
|
||||
function &createDocument($namespaceURI, $qualifiedName, &$docType) {
|
||||
$xmldoc = new DOMIT_Document();
|
||||
$documentElement =& $xmldoc->createElementNS($namespaceURI, $qualifiedName);
|
||||
|
||||
$xmldoc->setDocumentElement($documentElement);
|
||||
|
||||
if ($docType != null) {
|
||||
$xmldoc->doctype =& $docType;
|
||||
}
|
||||
|
||||
return $xmldoc;
|
||||
} //createDocument
|
||||
|
||||
/**
|
||||
* Creates a new DOMIT_DocumentType node (not yet implemented!)
|
||||
* @param string The $qualifiedName
|
||||
* @param string The $publicID
|
||||
* @param string The $systemID
|
||||
* @return Object The new document type node
|
||||
*/
|
||||
function &createDocumentType($qualifiedName, $publicID, $systemID) {
|
||||
//not yet implemented
|
||||
DOMIT_DOMException::raiseException(DOMIT_NOT_SUPPORTED_ERROR,
|
||||
('Method createDocumentType is not yet implemented.'));
|
||||
} //createDocumentType
|
||||
} //DOMIT_DOMImplementation
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user