0
+ * xajax.inc.php :: Main xajax class and setup file
0
+ * copyright (c) 2005 by Jared White & J. Max Wilson
0
+ * http://www.xajaxproject.org
0
+ * xajax is an open source PHP class library for easily creating powerful
0
+ * PHP-driven, web-based Ajax Applications. Using xajax, you can asynchronously
0
+ * call PHP functions and update the content of your your webpage without
0
+ * xajax is released under the terms of the LGPL license
0
+ * http://www.gnu.org/copyleft/lesser.html#SEC3
0
+ * This library is free software; you can redistribute it and/or
0
+ * modify it under the terms of the GNU Lesser General Public
0
+ * License as published by the Free Software Foundation; either
0
+ * version 2.1 of the License, or (at your option) any later version.
0
+ * This library is distributed in the hope that it will be useful,
0
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
0
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0
+ * Lesser General Public License for more details.
0
+ * You should have received a copy of the GNU Lesser General Public
0
+ * License along with this library; if not, write to the Free Software
0
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0
+ * @copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson
0
+ * @license http://www.gnu.org/copyleft/lesser.html#SEC3 LGPL License
0
+ ----------------------------------------------------------------------------
0
+ | Online documentation for this class is available on the xajax wiki at: |
0
+ | http://wiki.xajaxproject.org/Documentation:xajax.inc.php |
0
+ ----------------------------------------------------------------------------
0
+ * Define XAJAX_DEFAULT_CHAR_ENCODING that is used by both
0
+ * the xajax and xajaxResponse classes
0
+if (!defined ('XAJAX_DEFAULT_CHAR_ENCODING'))
0
+ define ('XAJAX_DEFAULT_CHAR_ENCODING', 'utf-8' );
0
+require_once(dirname(__FILE__)."/xajaxResponse.inc.php");
0
+ * Communication Method Defines
0
+if (!defined ('XAJAX_GET'))
0
+ define ('XAJAX_GET', 0);
0
+if (!defined ('XAJAX_POST'))
0
+ define ('XAJAX_POST', 1);
0
+ * The xajax class generates the xajax javascript for your page including the
0
+ * Javascript wrappers for the PHP functions that you want to call from your page.
0
+ * It also handles processing and executing the command messages in the XML responses
0
+ * sent back to your page from your PHP functions.
0
+ * @var array Array of PHP functions that will be callable through javascript wrappers
0
+ * @var array Array of object callbacks that will allow Javascript to call PHP methods (key=function name)
0
+ * @var array Array of RequestTypes to be used with each function (key=function name)
0
+ var $aFunctionRequestTypes;
0
+ * @var array Array of Include Files for any external functions (key=function name)
0
+ var $aFunctionIncludeFiles;
0
+ * @var string Name of the PHP function to call if no callable function was found
0
+ var $sCatchAllFunction;
0
+ * @var string Name of the PHP function to call before any other function
0
+ * @var string The URI for making requests to the xajax object
0
+ * @var string The prefix to prepend to the javascript wraper function name
0
+ * @var boolean Show debug messages (default false)
0
+ * @var boolean Show messages in the client browser's status bar (default false)
0
+ * @var boolean Allow xajax to exit after processing a request (default true)
0
+ * @var boolean Use wait cursor in browser (default true)
0
+ * @var boolean Use an special xajax error handler so the errors are sent to the browser properly (default false)
0
+ * @var string Specify what, if any, file xajax should log errors to (and more information in a future release)
0
+ * @var boolean Clean all output buffers before outputting response (default false)
0
+ * @var string String containing the character encoding used
0
+ * @var boolean Decode input request args from UTF-8 (default false)
0
+ var $bDecodeUTF8Input;
0
+ * @var boolean Convert special characters to HTML entities (default false)
0
+ * @var array Array for parsing complex objects
0
+ * @var integer Position in $aObjArray
0
+ * Constructor. You can set some extra xajax options right away or use
0
+ * individual methods later to set options.
0
+ * @param string defaults to the current browser URI
0
+ * @param string defaults to "xajax_";
0
+ * @param string defaults to XAJAX_DEFAULT_CHAR_ENCODING defined above
0
+ * @param boolean defaults to false
0
+ function xajax($sRequestURI="",$sWrapperPrefix="xajax_",$sEncoding=XAJAX_DEFAULT_CHAR_ENCODING,$bDebug=false)
0
+ $this->aFunctions = array();
0
+ $this->aObjects = array();
0
+ $this->aFunctionIncludeFiles = array();
0
+ $this->sRequestURI = $sRequestURI;
0
+ if ($this->sRequestURI == "")
0
+ $this->sRequestURI = $this->_detectURI();
0
+ $this->sWrapperPrefix = $sWrapperPrefix;
0
+ $this->bDebug = $bDebug;
0
+ $this->bStatusMessages = false;
0
+ $this->bWaitCursor = true;
0
+ $this->bExitAllowed = true;
0
+ $this->bErrorHandler = false;
0
+ $this->bCleanBuffer = false;
0
+ $this->setCharEncoding($sEncoding);
0
+ $this->bDecodeUTF8Input = false;
0
+ $this->bOutputEntities = false;
0
+ * Sets the URI to which requests will be made.
0
+ * <i>Usage:</i> <kbd>$xajax->setRequestURI("http://www.xajaxproject.org");</kbd>
0
+ * @param string the URI (can be absolute or relative) of the PHP script
0
+ * that will be accessed when an xajax request occurs
0
+ function setRequestURI($sRequestURI)
0
+ $this->sRequestURI = $sRequestURI;
0
+ * Sets the prefix that will be appended to the Javascript wrapper
0
+ * functions (default is "xajax_").
0
+ function setWrapperPrefix($sPrefix)
0
+ $this->sWrapperPrefix = $sPrefix;
0
+ * Enables debug messages for xajax.
0
+ * Disables debug messages for xajax (default behavior).
0
+ $this->bDebug = false;
0
+ * Enables messages in the browser's status bar for xajax.
0
+ function statusMessagesOn()
0
+ $this->bStatusMessages = true;
0
+ * Disables messages in the browser's status bar for xajax (default behavior).
0
+ function statusMessagesOff()
0
+ $this->bStatusMessages = false;
0
+ * Enables the wait cursor to be displayed in the browser (default behavior).
0
+ function waitCursorOn()
0
+ $this->bWaitCursor = true;
0
+ * Disables the wait cursor to be displayed in the browser.
0
+ function waitCursorOff()
0
+ $this->bWaitCursor = false;
0
+ * Enables xajax to exit immediately after processing a request and
0
+ * sending the response back to the browser (default behavior).
0
+ function exitAllowedOn()
0
+ $this->bExitAllowed = true;
0
+ * Disables xajax's default behavior of exiting immediately after
0
+ * processing a request and sending the response back to the browser.
0
+ function exitAllowedOff()
0
+ $this->bExitAllowed = false;
0
+ * Turns on xajax's error handling system so that PHP errors that occur
0
+ * during a request are trapped and pushed to the browser in the form of
0
+ function errorHandlerOn()
0
+ $this->bErrorHandler = true;
0
+ * Turns off xajax's error handling system (default behavior).
0
+ function errorHandlerOff()
0
+ $this->bErrorHandler = false;
0
+ * Specifies a log file that will be written to by xajax during a request
0
+ * (used only by the error handling system at present). If you don't invoke
0
+ * this method, or you pass in "", then no log file will be written to.
0
+ * <i>Usage:</i> <kbd>$xajax->setLogFile("/xajax_logs/errors.log");</kbd>
0
+ function setLogFile($sFilename)
0
+ $this->sLogFile = $sFilename;
0
+ * Causes xajax to clean out all output buffers before outputting a
0
+ * response (default behavior).
0
+ function cleanBufferOn()
0
+ $this->bCleanBuffer = true;
0
+ * Turns off xajax's output buffer cleaning.
0
+ function cleanBufferOff()
0
+ $this->bCleanBuffer = false;
0
+ * Sets the character encoding for the HTTP output based on
0
+ * <kbd>$sEncoding</kbd>, which is a string containing the character
0
+ * encoding to use. You don't need to use this method normally, since the
0
+ * character encoding for the response gets set automatically based on the
0
+ * <kbd>XAJAX_DEFAULT_CHAR_ENCODING</kbd> constant.
0
+ * <i>Usage:</i> <kbd>$xajax->setCharEncoding("utf-8");</kbd>
0
+ * @param string the encoding type to use (utf-8, iso-8859-1, etc.)
0
+ function setCharEncoding($sEncoding)
0
+ $this->sEncoding = $sEncoding;
0
+ * Causes xajax to decode the input request args from UTF-8 to the current
0
+ * encoding if possible. Either the iconv or mb_string extension must be
0
+ * present for optimal functionality.
0
+ function decodeUTF8InputOn()
0
+ $this->bDecodeUTF8Input = true;
0
+ * Turns off decoding the input request args from UTF-8 (default behavior).
0
+ function decodeUTF8InputOff()
0
+ $this->bDecodeUTF8Input = false;
0
+ * Tells the response object to convert special characters to HTML entities
0
+ * automatically (only works if the mb_string extension is available).
0
+ function outputEntitiesOn()
0
+ $this->bOutputEntities = true;
0
+ * Tells the response object to output special characters intact. (default
0
+ function outputEntitiesOff()
0
+ $this->bOutputEntities = false;
0
+ * Registers a PHP function or method to be callable through xajax in your
0
+ * Javascript. If you want to register a function, pass in the name of that
0
+ * function. If you want to register a static class method, pass in an
0
+ * <kbd>array("myFunctionName", "myClass", "myMethod")</kbd>
0
+ * For an object instance method, use an object variable for the second
0
+ * array element (and in PHP 4 make sure you put an & before the variable
0
+ * to pass the object by reference). Note: the function name is what you
0
+ * call via Javascript, so it can be anything as long as it doesn't
0
+ * conflict with any other registered function name.
0
+ * <i>Usage:</i> <kbd>$xajax->registerFunction("myFunction");</kbd>
0
+ * or: <kbd>$xajax->registerFunction(array("myFunctionName", &$myObject, "myMethod"));</kbd>
0
+ * @param mixed contains the function name or an object callback array
0
+ * @param mixed request type (XAJAX_GET/XAJAX_POST) that should be used
0
+ * for this function. Defaults to XAJAX_POST.
0
+ function registerFunction($mFunction,$sRequestType=XAJAX_POST)
0
+ if (is_array($mFunction)) {
0
+ $this->aFunctions[$mFunction[0]] = 1;
0
+ $this->aFunctionRequestTypes[$mFunction[0]] = $sRequestType;
0
+ $this->aObjects[$mFunction[0]] = array_slice($mFunction, 1);
0
+ $this->aFunctions[$mFunction] = 1;
0
+ $this->aFunctionRequestTypes[$mFunction] = $sRequestType;
0
+ * Registers a PHP function to be callable through xajax which is located
0
+ * in some other file. If the function is requested the external file will
0
+ * be included to define the function before the function is called.
0
+ * <i>Usage:</i> <kbd>$xajax->registerExternalFunction("myFunction","myFunction.inc.php",XAJAX_POST);</kbd>
0
+ * @param string contains the function name or an object callback array
0
+ * ({@link xajax::registerFunction() see registerFunction} for
0
+ * more info on object callback arrays)
0
+ * @param string contains the path and filename of the include file
0
+ * @param mixed the RequestType (XAJAX_GET/XAJAX_POST) that should be used
0
+ * for this function. Defaults to XAJAX_POST.
0
+ function registerExternalFunction($mFunction,$sIncludeFile,$sRequestType=XAJAX_POST)