cvs: pear /HTML_AJAX/examples README auto_server.php customLib.js error_usage.php helper_usage.php index.php livesearch.class.php
proxy_usage_inline_javascript.php proxy_usage_server.php proxyless_usage.php queue_usage.php serialize.examples.htm serialize.examples.php server.php
test.class.php test.html test2.class.php test_speed.php
| From: | David Coallier | Date: | Mon, 07 Nov 2005 18:43:53 +0000 |
| Subject: | cvs: pear /HTML_AJAX/examples README auto_server.php customLib.js error_usage.php helper_usage.php index.php livesearch.class.php proxy_usage_inline_javascript.php proxy_usage_server.php proxyless_usage.php queue_usage.php serialize.examples.htm serialize.examples.php server.php test.class.php test.html test2.class.php test_speed.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-36134@lists.php.net to get a copy of this message | ||
davidc Mon Nov 7 13:43:53 2005 EDT
Modified files:
/pear/HTML_AJAX/examples README auto_server.php customLib.js
error_usage.php helper_usage.php index.php
livesearch.class.php
proxy_usage_inline_javascript.php
proxy_usage_server.php proxyless_usage.php
queue_usage.php serialize.examples.htm
serialize.examples.php server.php
test.class.php test.html test2.class.php
test_speed.php
Log:
Latest examples from local dev.
http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/README?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/README diff -u pear/HTML_AJAX/examples/README:1.3 pear/HTML_AJAX/examples/README:1.4 --- pear/HTML_AJAX/examples/README:1.3 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/README Mon Nov 7 13:43:49 2005 @@ -1 +1 @@ -See Index.php for details +See Index.php for details http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/auto_server.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/auto_server.php diff -u pear/HTML_AJAX/examples/auto_server.php:1.3 pear/HTML_AJAX/examples/auto_server.php:1.4 --- pear/HTML_AJAX/examples/auto_server.php:1.3 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/auto_server.php Mon Nov 7 13:43:49 2005 @@ -1,65 +1,65 @@ -<?php -/** - * Advanced usage of HTML_AJAX_Server - * Allows for a single server to manage exporting a large number of classes without high overhead per call - * Also gives a single place to handle setup tasks especially useful if session setup is required - * - * The server responds to ajax calls and also serves the js client libraries, so they can be used directly from the PEAR data dir - * 304 not modified headers are used when server client libraries so they will be cached on the browser reducing overhead - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - - // include the server class -include 'HTML/AJAX/Server.php'; - - -// extend HTML_AJAX_Server creating our own custom one with init{ClassName} methods for each class it supports calls on -class TestServer extends HTML_AJAX_Server { - // this flag must be set to on init methods - var $initMethods = true; - - // init method for the test class, includes needed files an registers it for ajax - function initTest() { - include 'test.class.php'; - $this->registerClass(new test()); - } - - // init method for the livesearch class, includes needed files an registers it for ajax - function initLivesearch() { - include 'livesearch.class.php'; - $this->registerClass(new livesearch()); - } - - -} - -// create an instance of our test server -$server = new TestServer(); - -// init methods can also be added to the server by registering init objects, this is useful in cases where you want to dynamically add init methods -class initObject { - // init method for the test class, includes needed files an registers it for ajax - function initTest2() { - include 'test2.class.php'; - $this->server->registerClass(new test2()); - } -} -$init = new initObject(); -$init->server =& $server; -$server->registerInitObject($init); - -// you can use HTML_AJAX_Server to deliver your own custom javascript libs, when used with comma seperated client lists you can -// use just one javascript include for all your library files -// example url: auto_server.php?client=auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,customLib -$server->registerJSLibrary('customLib','customLib.js','./'); - -// handle requests as needed -$server->handleRequest(); -?> +<?php +/** + * Advanced usage of HTML_AJAX_Server + * Allows for a single server to manage exporting a large number of classes without high overhead per call + * Also gives a single place to handle setup tasks especially useful if session setup is required + * + * The server responds to ajax calls and also serves the js client libraries, so they can be used directly from the PEAR data dir + * 304 not modified headers are used when server client libraries so they will be cached on the browser reducing overhead + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + + // include the server class +include 'HTML/AJAX/Server.php'; + + +// extend HTML_AJAX_Server creating our own custom one with init{ClassName} methods for each class it supports calls on +class TestServer extends HTML_AJAX_Server { + // this flag must be set to on init methods + var $initMethods = true; + + // init method for the test class, includes needed files an registers it for ajax + function initTest() { + include 'test.class.php'; + $this->registerClass(new test()); + } + + // init method for the livesearch class, includes needed files an registers it for ajax + function initLivesearch() { + include 'livesearch.class.php'; + $this->registerClass(new livesearch()); + } + + +} + +// create an instance of our test server +$server = new TestServer(); + +// init methods can also be added to the server by registering init objects, this is useful in cases where you want to dynamically add init methods +class initObject { + // init method for the test class, includes needed files an registers it for ajax + function initTest2() { + include 'test2.class.php'; + $this->server->registerClass(new test2()); + } +} +$init = new initObject(); +$init->server =& $server; +$server->registerInitObject($init); + +// you can use HTML_AJAX_Server to deliver your own custom javascript libs, when used with comma seperated client lists you can +// use just one javascript include for all your library files +// example url: auto_server.php?client=auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,customLib +$server->registerJSLibrary('customLib','customLib.js','./'); + +// handle requests as needed +$server->handleRequest(); +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/customLib.js?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/customLib.js diff -u pear/HTML_AJAX/examples/customLib.js:1.1 pear/HTML_AJAX/examples/customLib.js:1.2 --- pear/HTML_AJAX/examples/customLib.js:1.1 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/customLib.js Mon Nov 7 13:43:49 2005 @@ -1,5 +1,5 @@ -// An example custom javascript library served up by the auto_server - -function customLibAlert(msg) { - alert(msg); -} +// An example custom javascript library served up by the auto_server + +function customLibAlert(msg) { + alert(msg); +} http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/error_usage.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/error_usage.php diff -u pear/HTML_AJAX/examples/error_usage.php:1.1 pear/HTML_AJAX/examples/error_usage.php:1.2 --- pear/HTML_AJAX/examples/error_usage.php:1.1 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/error_usage.php Mon Nov 7 13:43:49 2005 @@ -1,31 +1,31 @@ -<?php -/** - * Test class used in other examples - * Constructors and private methods marked with _ are never exported in proxies to JavaScript - * - * @category HTML - * @package AJAX - * @author David Coallier <davidc@agoraproduction.com> - * @copyright 2005 David Coallier - * @license LGPL http://www.gnu.org/copyleft/lesser.txt - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -require_once 'HTML/AJAX.php'; - -class error_test -{ - function error_test() - { - $ajax =& new HTML_AJAX; - $ajax->debugEnabled = true; - $ajax->debugSession = true; - set_error_handler(array(&$ajax, '_errorHandler')); - trigger_error("I don't know"); - } -} - -$t =& new error_test; -print_r($t); - -?> +<?php +/** + * Test class used in other examples + * Constructors and private methods marked with _ are never exported in proxies to JavaScript + * + * @category HTML + * @package AJAX + * @author David Coallier <davidc@agoraproduction.com> + * @copyright 2005 David Coallier + * @license LGPL http://www.gnu.org/copyleft/lesser.txt + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +require_once 'HTML/AJAX.php'; + +class error_test +{ + function error_test() + { + $ajax =& new HTML_AJAX; + $ajax->debugEnabled = true; + $ajax->debugSession = true; + set_error_handler(array(&$ajax, '_errorHandler')); + trigger_error("I don't know"); + } +} + +$t =& new error_test; +print_r($t); + +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/helper_usage.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/helper_usage.php diff -u pear/HTML_AJAX/examples/helper_usage.php:1.1 pear/HTML_AJAX/examples/helper_usage.php:1.2 --- pear/HTML_AJAX/examples/helper_usage.php:1.1 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/helper_usage.php Mon Nov 7 13:43:49 2005 @@ -1,49 +1,49 @@ -<?php -/** - * Example of Using HTML_AJAX_Helper - * - * HTML_AJAX_Helper takes care of basic JavaScript and HTML generation that is needed in many AJAX requests - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - -// include the helper class -require_once 'HTML/AJAX/Helper.php'; - -// create an instance and set the server url -$ajaxHelper = new HTML_AJAX_Helper(); -$ajaxHelper->serverUrl = 'auto_server.php'; -$ajaxHelper->jsLibraries[] = 'customLib'; -?> -<html> -<head> - -<?php - // output a javascript neded to setup HTML_AJAX - // by default this is all the libraries shipped with HTML_AJAX, take a look at $ajaxHelper->jsLibraries to edit the list - echo $ajaxHelper->setupAJAX(); -?> - -</head> -<body> -<?php - // output a custom loading message - echo $ajaxHelper->loadingMessage("Waiting on the Server ..."); -?> - -<div id="updateTarget">I'm an update Target</div> -<?php - // update the element using ajax - echo $ajaxHelper->updateElement('updateTarget',array('test','echo_string','Some text to echo'),'replace',true); -?> -</body> -</html> -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ -?> +<?php +/** + * Example of Using HTML_AJAX_Helper + * + * HTML_AJAX_Helper takes care of basic JavaScript and HTML generation that is needed in many AJAX requests + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + +// include the helper class +require_once 'HTML/AJAX/Helper.php'; + +// create an instance and set the server url +$ajaxHelper = new HTML_AJAX_Helper(); +$ajaxHelper->serverUrl = 'auto_server.php'; +$ajaxHelper->jsLibraries[] = 'customLib'; +?> +<html> +<head> + +<?php + // output a javascript neded to setup HTML_AJAX + // by default this is all the libraries shipped with HTML_AJAX, take a look at $ajaxHelper->jsLibraries to edit the list + echo $ajaxHelper->setupAJAX(); +?> + +</head> +<body> +<?php + // output a custom loading message + echo $ajaxHelper->loadingMessage("Waiting on the Server ..."); +?> + +<div id="updateTarget">I'm an update Target</div> +<?php + // update the element using ajax + echo $ajaxHelper->updateElement('updateTarget',array('test','echo_string','Some text to echo'),'replace',true); +?> +</body> +</html> +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/index.php?r1=1.2&r2=1.3&ty=u Index: pear/HTML_AJAX/examples/index.php diff -u pear/HTML_AJAX/examples/index.php:1.2 pear/HTML_AJAX/examples/index.php:1.3 --- pear/HTML_AJAX/examples/index.php:1.2 Wed Oct 26 12:45:30 2005 +++ pear/HTML_AJAX/examples/index.php Mon Nov 7 13:43:49 2005 @@ -1,50 +1,51 @@ -<html> -<head> -<title>HTML_AJAX Examples</title> -</head> -<body> -<p> -These examples cover basic AJAX usage -</p> - -<p> -All example files are fully commented, reading through them will give you a good overview on how things work. -</p> - -<p>The term proxy in these examples refers to a javascript class that is generated and has functions that map to the eqivalent php class. -These proxy classes work much in the same way as a SOAP proxy class that is generated from wsdl. -</p> - -<p> -Front end files for examples, you can actually run these and see some example output -</p> -<ul> -<li><a href='proxyless_usage.php'>proxyless_usage.php</a> - Using HTML_AJAX in standalone mode, possible doesn't require PHP or any backend HTML_AJAX classes</li> -<li><a href='proxy_usage_inline_javascript.php'>proxy_usage_inline_javascript.php</a> - Single file proxy style usage</li> -<li><a href='proxy_usage_server.php'>proxy_usage_server.php</a> - Multi-file proxy usage, either server file could be used with this example</li> -<li><a href='queue_usage.php'>queue_usage.php</a> - An example of using a queue to manage ajax calls, a simple live search example</li> -<li><a href='helper_usage.php'>helper_usage.php</a> - An example showing the basics of the helper api</li> -</ul> - -<p>Real Life Examples</p> -<ul> -<li><a href='login/index.php'>login/index.php</a> - An example creating an AJAX driven login</a></li> -</ul> - -<p> -2 server examples are provided -</p> -<ul> -<li>server.php - Basic server operation, serving ajax calls and client lib requests</li> -<li>auto_server.php - Advanced server operation, only create php classes as needed</li> -</ul> - -<p> -Other Example files: -</p> -<ul> -<li><a href='test_speed.php'>test_speed.php</p> - A basic setup for measuring the speed of calls</li> -</ul> - -</body> -</html> +<html> +<head> +<title>HTML_AJAX Examples</title> +</head> +<body> +<p> +These examples cover basic AJAX usage +</p> + +<p> +All example files are fully commented, reading through them will give you a good overview on how things work. +</p> + +<p>The term proxy in these examples refers to a javascript class that is generated and has functions that map to the eqivalent php class. +These proxy classes work much in the same way as a SOAP proxy class that is generated from wsdl. +</p> + +<p> +Front end files for examples, you can actually run these and see some example output +</p> +<ul> +<li><a href='proxyless_usage.php'>proxyless_usage.php</a> - Using HTML_AJAX in standalone mode, possible doesn't require PHP or any backend HTML_AJAX classes</li> +<li><a href='proxy_usage_inline_javascript.php'>proxy_usage_inline_javascript.php</a> - Single file proxy style usage</li> +<li><a href='proxy_usage_server.php'>proxy_usage_server.php</a> - Multi-file proxy usage, either server file could be used with this example</li> +<li><a href='queue_usage.php'>queue_usage.php</a> - An example of using a queue to manage ajax calls, a simple live search example</li> +<li><a href='helper_usage.php'>helper_usage.php</a> - An example showing the basics of the helper api</li> +</ul> + +<p>Real Life Examples</p> +<ul> +<li><a href='login/index.php'>login/index.php</a> - An example creating an AJAX driven login</a></li> +</ul> + +<p> +2 server examples are provided +</p> +<ul> +<li>server.php - Basic server operation, serving ajax calls and client lib requests</li> +<li>auto_server.php - Advanced server operation, only create php classes as needed</li> +</ul> + +<p> +Other Example files: +</p> +<ul> +<li><a href='test_speed.php'>test_speed.php</a> - A basic setup for measuring the speed of calls</li> +<li><a href='serialize.examples.htm'>serialize.examples.htm/a> - Internal tests for the php serialize format serializer</li> +</ul> + +</body> +</html> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/livesearch.class.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/livesearch.class.php diff -u pear/HTML_AJAX/examples/livesearch.class.php:1.1 pear/HTML_AJAX/examples/livesearch.class.php:1.2 --- pear/HTML_AJAX/examples/livesearch.class.php:1.1 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/livesearch.class.php Mon Nov 7 13:43:49 2005 @@ -1,40 +1,40 @@ -<?php -/** - * Simple test class for doing fake livesearch - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -class livesearch { - /** - * Items to search against - */ - var $livesearch = array( - 'Orange', - 'Apple', - 'Pear', - 'Banana', - 'Blueberry', - ); - - /** - * Perform a search - * - * @return array - */ - function search($input) { - $ret = array(); - foreach($this->livesearch as $key => $value) { - if (stristr($value,$input)) { - $ret[$key] = $value; - } - } - return $ret; - } -} -?> +<?php +/** + * Simple test class for doing fake livesearch + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +class livesearch { + /** + * Items to search against + */ + var $livesearch = array( + 'Orange', + 'Apple', + 'Pear', + 'Banana', + 'Blueberry', + ); + + /** + * Perform a search + * + * @return array + */ + function search($input) { + $ret = array(); + foreach($this->livesearch as $key => $value) { + if (stristr($value,$input)) { + $ret[$key] = $value; + } + } + return $ret; + } +} +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php diff -u pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php:1.3 pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php:1.4 --- pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php:1.3 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php Mon Nov 7 13:43:49 2005 @@ -1,155 +1,155 @@ -<?php -/** - * Example of Using HTML_AJAX in proxy operation - * - * All AJAX calls are handled by this same file and the proxy js is outputed in a js block directly in this script - * This is a use case very similar to Sajax (Sajax registers functions not objects) - * - * The only needed interaction is creation of a new object from the proxy defintion, all AJAX calls happen transparently from - * - * If you want to perform async calls a callback object must be passed to the constructor of the object - * - * The client JavaScript library is provided by server.php, you could also copy HTML_AJAX.js (all js files combined) or the seperate js files into your webroot - * from the PEAR data dir and src them directly - * - * This example also registers a custom error handler, without this handler errors float out of the app as an Exception - * - * An example debugging event listener is also shown - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - -// include the main HTML_AJAX class -include 'HTML/AJAX.php'; - -// our simple test class -include 'test.class.php'; - - - -// create an instance of HTML_AJAX -$ajax = new HTML_AJAX(); -// register an instance of the test class -$ajax->registerClass(new test()); - -// handle and ajax call, if one is made die, else continue processing -if ($ajax->handleRequest()) { - die(); -} -?><html> -<head> - -<!-- the entire client library can be retreived in one call using the all keyword, or each piece can be requested like below --> -<script type='text/javascript' src="server.php?client=Main"></script> -<script type='text/javascript' src="server.php?client=Dispatcher"></script> -<script type='text/javascript' src="server.php?client=HttpClient"></script> -<script type='text/javascript' src="server.php?client=Request"></script> -<script type='text/javascript' src="server.php?client=JSON"></script> -<script type='text/javascript' src="server.php?client=loading"></script> - -<script type='text/javascript'> -<?php - // generate proxy definition javascript for all registered class - echo $ajax->generateJavascriptClient(); -?> - -// definition of the callback javascript class, used to handle async requests -function callback() {} -callback.prototype = { - echo_string: function(result) { - document.getElementById('target').innerHTML = result; - }, - slow_echo_string: function(result) { - document.getElementById('target').innerHTML = result; - }, - error_test: function(result) { - document.getElementById('target').innerHTML = result; - } -} - -// function used to clear out the target div -function clearTarget() { - document.getElementById('target').innerHTML = 'clear'; - document.getElementById('eventLog').innerHTML = 'clear'; - document.getElementById('error').innerHTML = 'clear'; -} - -// register a custom error handler -HTML_AJAX.onError = function(e) { - msg = "\n\n"; - for(var i in e) { - msg += i + ':' + e[i] +"\n"; - } - document.getElementById('error').innerHTML += msg; -} - -// register custom event handlers, but lets keep the old ones so we still have that automatic loading message -var onOpen = HTML_AJAX.onOpen; -var onLoad = HTML_AJAX.onLoad; - -HTML_AJAX.onOpen = function(request) { - onOpen(); - document.getElementById('eventLog').innerHTML += "Open: "+request.className+'::'+request.methodName+"\n"; -} -HTML_AJAX.onSend = function(request) { - document.getElementById('eventLog').innerHTML += "Send: "+request.className+'::'+request.methodName+"\n"; -} -HTML_AJAX.onProgress = function(request) { - document.getElementById('eventLog').innerHTML += "Progress: "+request.className+'::'+request.methodName+"\n"; -} -HTML_AJAX.onLoad = function(request) { - onLoad(); - document.getElementById('eventLog').innerHTML += "Load: "+request.className+'::'+request.methodName+"\n"; -} - -</script> -</head> -<body> -<script type="text/javascript"> -// create a proxy in sync mode -var syncProxy = new test(); -// create a proxy in async mode -var asyncProxy = new test(new callback()); - -// run a sync call and set its results to the target div -function syncCall() { - document.getElementById('target').innerHTML = syncProxy.echo_string("I'm a sync call"); -} - -// run a sync call, callback class will handle its results -function asyncCall() { - asyncProxy.echo_string("I'm a async call"); -} - -// run a sync call, callback class will handle its results -// the purpose of this slow call is to show off the built in loading messaging -function slowAsyncCall() { - asyncProxy.slow_echo_string("I'm a slow async call"); -} - -// run a sync call, callback class will handle its results -function serverErrorExample() { - asyncProxy.error_test("I'm an error generated by trigger error in test.class.php"); -} -</script> -<ul> - <li><a href="javascript:clearTarget()">Clear Target</a></li> - <li><a href="javascript:syncCall()">Run Sync Echo call</a></li> - <li><a href="javascript:asyncCall();">Run Async Echo call</a></li> - <li><a href="javascript:slowAsyncCall();">Run Slow Async Echo call (sleep on server to emulate slow processing)</a></li> - <li><a href="javascript:serverErrorExample();">Run a call where an error is generated on the server</a></li> -</ul> -<div style="white-space: pre; padding: 1em; margin: 1em; width: 300px; height: 400px; border: solid 2px black; overflow: auto; float: right;" id="error">Error Target</div> - -<div style="white-space: pre; padding: 1em; margin: 1em; width: 500px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> - -<div style="white-space: pre; padding: 1em; margin: 1em; width: 500px; height: 400px; border: solid 2px black; overflow: auto;" id="eventLog">Event Log -</div> -</body> -</html> +<?php +/** + * Example of Using HTML_AJAX in proxy operation + * + * All AJAX calls are handled by this same file and the proxy js is outputed in a js block directly in this script + * This is a use case very similar to Sajax (Sajax registers functions not objects) + * + * The only needed interaction is creation of a new object from the proxy defintion, all AJAX calls happen transparently from + * + * If you want to perform async calls a callback object must be passed to the constructor of the object + * + * The client JavaScript library is provided by server.php, you could also copy HTML_AJAX.js (all js files combined) or the seperate js files into your webroot + * from the PEAR data dir and src them directly + * + * This example also registers a custom error handler, without this handler errors float out of the app as an Exception + * + * An example debugging event listener is also shown + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + +// include the main HTML_AJAX class +include 'HTML/AJAX.php'; + +// our simple test class +include 'test.class.php'; + + + +// create an instance of HTML_AJAX +$ajax = new HTML_AJAX(); +// register an instance of the test class +$ajax->registerClass(new test()); + +// handle and ajax call, if one is made die, else continue processing +if ($ajax->handleRequest()) { + die(); +} +?><html> +<head> + +<!-- the entire client library can be retreived in one call using the all keyword, or each piece can be requested like below --> +<script type='text/javascript' src="server.php?client=Main"></script> +<script type='text/javascript' src="server.php?client=Dispatcher"></script> +<script type='text/javascript' src="server.php?client=HttpClient"></script> +<script type='text/javascript' src="server.php?client=Request"></script> +<script type='text/javascript' src="server.php?client=JSON"></script> +<script type='text/javascript' src="server.php?client=loading"></script> + +<script type='text/javascript'> +<?php + // generate proxy definition javascript for all registered class + echo $ajax->generateJavascriptClient(); +?> + +// definition of the callback javascript class, used to handle async requests +function callback() {} +callback.prototype = { + echo_string: function(result) { + document.getElementById('target').innerHTML = result; + }, + slow_echo_string: function(result) { + document.getElementById('target').innerHTML = result; + }, + error_test: function(result) { + document.getElementById('target').innerHTML = result; + } +} + +// function used to clear out the target div +function clearTarget() { + document.getElementById('target').innerHTML = 'clear'; + document.getElementById('eventLog').innerHTML = 'clear'; + document.getElementById('error').innerHTML = 'clear'; +} + +// register a custom error handler +HTML_AJAX.onError = function(e) { + msg = "\n\n"; + for(var i in e) { + msg += i + ':' + e[i] +"\n"; + } + document.getElementById('error').innerHTML += msg; +} + +// register custom event handlers, but lets keep the old ones so we still have that automatic loading message +var onOpen = HTML_AJAX.onOpen; +var onLoad = HTML_AJAX.onLoad; + +HTML_AJAX.onOpen = function(request) { + onOpen(); + document.getElementById('eventLog').innerHTML += "Open: "+request.className+'::'+request.methodName+"\n"; +} +HTML_AJAX.onSend = function(request) { + document.getElementById('eventLog').innerHTML += "Send: "+request.className+'::'+request.methodName+"\n"; +} +HTML_AJAX.onProgress = function(request) { + document.getElementById('eventLog').innerHTML += "Progress: "+request.className+'::'+request.methodName+"\n"; +} +HTML_AJAX.onLoad = function(request) { + onLoad(); + document.getElementById('eventLog').innerHTML += "Load: "+request.className+'::'+request.methodName+"\n"; +} + +</script> +</head> +<body> +<script type="text/javascript"> +// create a proxy in sync mode +var syncProxy = new test(); +// create a proxy in async mode +var asyncProxy = new test(new callback()); + +// run a sync call and set its results to the target div +function syncCall() { + document.getElementById('target').innerHTML = syncProxy.echo_string("I'm a sync call"); +} + +// run a sync call, callback class will handle its results +function asyncCall() { + asyncProxy.echo_string("I'm a async call"); +} + +// run a sync call, callback class will handle its results +// the purpose of this slow call is to show off the built in loading messaging +function slowAsyncCall() { + asyncProxy.slow_echo_string("I'm a slow async call"); +} + +// run a sync call, callback class will handle its results +function serverErrorExample() { + asyncProxy.error_test("I'm an error generated by trigger error in test.class.php"); +} +</script> +<ul> + <li><a href="javascript:clearTarget()">Clear Target</a></li> + <li><a href="javascript:syncCall()">Run Sync Echo call</a></li> + <li><a href="javascript:asyncCall();">Run Async Echo call</a></li> + <li><a href="javascript:slowAsyncCall();">Run Slow Async Echo call (sleep on server to emulate slow processing)</a></li> + <li><a href="javascript:serverErrorExample();">Run a call where an error is generated on the server</a></li> +</ul> +<div style="white-space: pre; padding: 1em; margin: 1em; width: 300px; height: 400px; border: solid 2px black; overflow: auto; float: right;" id="error">Error Target</div> + +<div style="white-space: pre; padding: 1em; margin: 1em; width: 500px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> + +<div style="white-space: pre; padding: 1em; margin: 1em; width: 500px; height: 400px; border: solid 2px black; overflow: auto;" id="eventLog">Event Log +</div> +</body> +</html> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/proxy_usage_server.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/proxy_usage_server.php diff -u pear/HTML_AJAX/examples/proxy_usage_server.php:1.3 pear/HTML_AJAX/examples/proxy_usage_server.php:1.4 --- pear/HTML_AJAX/examples/proxy_usage_server.php:1.3 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/proxy_usage_server.php Mon Nov 7 13:43:49 2005 @@ -1,95 +1,95 @@ -<?php -/** - * Example of Using HTML_AJAX in proxy operation - * - * All AJAX calls are handled by the auto_server.php file, server.php could also be used, the differences between the two are covered in those files - * This is a use case very similar to JPSpan (JPSpan only has a server.php equivalent) - * - * The only needed interaction is creation of a new object from the proxy defintion, all AJAX calls happen transparently from there - * - * If you want to perform async calls a callback object must be passed to the constructor of the object - * - * The client JavaScript library is provided by auto_server.php, you could also copy HTML_AJAX.js (all js files combined) or the seperate js files into your webroot - * from the PEAR data dir and src them directly. You can use multiple includes of the component files or use the all flag to get them all at once. - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - -?><html> -<head> - -<!-- These two calls can be combined into one call if wanted, but its not recomended since it will hurt caching as you might want stubs of multiple classes --> -<script type='text/javascript' src="auto_server.php?client=all"></script> -<!-- Stub is passed the class you want the proxy definition for, you can also use all to get every registered class but that create those auto server - has to instanciate every class where here only the class used on this page has to be instanciated --> -<script type='text/javascript' src="auto_server.php?stub=test"></script> - -<script type='text/javascript'> -// definition of the callback javascript class, used to handle async requests -function callback() {} -callback.prototype = { - echo_string: function(result) { - document.getElementById('target').innerHTML = result; - }, - cookies: function(result) { - var ret = ""; - for(var i in result) { - ret += i+':'+result[i]+"\n"; - } - document.getElementById('target').innerHTML = ret; - } -} - -// function used to clear out the target div -function clearTarget() { - document.getElementById('target').innerHTML = 'clear'; -} -</script> -</head> -<body> -<script type="text/javascript"> -// create a proxy in sync mode -var syncProxy = new test(); -// create a proxy in async mode -var asyncProxy = new test(new callback()); - -// run a sync call and set its results to the target div -function syncCall() { - document.getElementById('target').innerHTML = syncProxy.echo_string("I'm a sync call"); -} - -// run a sync call, callback class will handle its results -function asyncCall() { - asyncProxy.echo_string("I'm a async call"); -} - -function cookieTest() { - asyncProxy.cookies(); -} -</script> -<ul> - <li><a href="javascript:clearTarget()">Clear Target</a></li> - <li><a href="javascript:syncCall()">Run Sync Echo call</a></li> - <li><a href="javascript:asyncCall();">Run Async Echo call</a></li> - <li><a href="javascript:cookieTest();">View Cookies</a></li> -</ul> - -<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> - -<div> -Runing view Cookies should show you these same cookies being returned by the AJAX call -<pre> -<?php - var_dump($_COOKIE); -?> -</pre> -</div> - -</body> -</html> +<?php +/** + * Example of Using HTML_AJAX in proxy operation + * + * All AJAX calls are handled by the auto_server.php file, server.php could also be used, the differences between the two are covered in those files + * This is a use case very similar to JPSpan (JPSpan only has a server.php equivalent) + * + * The only needed interaction is creation of a new object from the proxy defintion, all AJAX calls happen transparently from there + * + * If you want to perform async calls a callback object must be passed to the constructor of the object + * + * The client JavaScript library is provided by auto_server.php, you could also copy HTML_AJAX.js (all js files combined) or the seperate js files into your webroot + * from the PEAR data dir and src them directly. You can use multiple includes of the component files or use the all flag to get them all at once. + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + +?><html> +<head> + +<!-- These two calls can be combined into one call if wanted, but its not recomended since it will hurt caching as you might want stubs of multiple classes --> +<script type='text/javascript' src="auto_server.php?client=all"></script> +<!-- Stub is passed the class you want the proxy definition for, you can also use all to get every registered class but that create those auto server + has to instanciate every class where here only the class used on this page has to be instanciated --> +<script type='text/javascript' src="auto_server.php?stub=test"></script> + +<script type='text/javascript'> +// definition of the callback javascript class, used to handle async requests +function callback() {} +callback.prototype = { + echo_string: function(result) { + document.getElementById('target').innerHTML = result; + }, + cookies: function(result) { + var ret = ""; + for(var i in result) { + ret += i+':'+result[i]+"\n"; + } + document.getElementById('target').innerHTML = ret; + } +} + +// function used to clear out the target div +function clearTarget() { + document.getElementById('target').innerHTML = 'clear'; +} +</script> +</head> +<body> +<script type="text/javascript"> +// create a proxy in sync mode +var syncProxy = new test(); +// create a proxy in async mode +var asyncProxy = new test(new callback()); + +// run a sync call and set its results to the target div +function syncCall() { + document.getElementById('target').innerHTML = syncProxy.echo_string("I'm a sync call"); +} + +// run a sync call, callback class will handle its results +function asyncCall() { + asyncProxy.echo_string("I'm a async call"); +} + +function cookieTest() { + asyncProxy.cookies(); +} +</script> +<ul> + <li><a href="javascript:clearTarget()">Clear Target</a></li> + <li><a href="javascript:syncCall()">Run Sync Echo call</a></li> + <li><a href="javascript:asyncCall();">Run Async Echo call</a></li> + <li><a href="javascript:cookieTest();">View Cookies</a></li> +</ul> + +<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> + +<div> +Runing view Cookies should show you these same cookies being returned by the AJAX call +<pre> +<?php + var_dump($_COOKIE); +?> +</pre> +</div> + +</body> +</html> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/proxyless_usage.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/proxyless_usage.php diff -u pear/HTML_AJAX/examples/proxyless_usage.php:1.3 pear/HTML_AJAX/examples/proxyless_usage.php:1.4 --- pear/HTML_AJAX/examples/proxyless_usage.php:1.3 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/proxyless_usage.php Mon Nov 7 13:43:49 2005 @@ -1,128 +1,128 @@ -<?php -/** - * Example of Using HTML_AJAX in proxyless operation - * - * This is the simplest way to use HTML_AJAX if your just using grab and replace functions you don't even need a server - * You need every javascript file except JSON which is optional and is only needed if your using that encoding - * - * The proxyless api is provided by Main.js - * - * There are 3 main methods and 2 properties to the proxyless api, they all exist as static methods on HTML_AJAX - * HTML_AJAX.grab(url) - * HTML_AJAX.replace(id,url) or HTML_AJAX.replace(id,class,method,arg1,arg2,etc) - * HTML_AJAX.call(class,method,callback,arg1,arg2,etc) - * - * HTML_AJAX.defaultServerUrl = 'serverurl'; - * HTML_AJAX.defaultEncoding = 'Null'; - * - * The api is demonstrated below, server.php is used for call examples and to load the needed js files - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -?> -<html> -<head> - -<script type='text/javascript' src="server.php?client=Util"></script> -<script type='text/javascript' src="server.php?client=main"></script> -<script type='text/javascript' src="server.php?client=dispatcher"></script> -<script type='text/javascript' src="server.php?client=HttpClient"></script> -<script type='text/javascript' src="server.php?client=Request"></script> -<script type='text/javascript' src="server.php?client=json"></script> -<script type='text/javascript' src="server.php?client=loading"></script> - -</head> -<body> -<script type="text/javascript"> -function clearTarget() { - document.getElementById('target').innerHTML = 'clear'; -} - -// Add an error handler so we get an alert if any errors happen while making an AJAX call -HTML_AJAX.onError = function(e) -{ - alert(HTML_AJAX_Util.varDump(e)); -} - - -// Grab is the simplest usage of HTML_AJAX you use it to perform a request to a page and get its results back -// It can be used in either Sync mode where it returns directory or with a call back, both methods are shown below -var url = 'README'; -function grabSync() { - document.getElementById('target').innerHTML = HTML_AJAX.grab(url); -} - -function grabAsync() { - HTML_AJAX.grab(url,grabCallback); -} - -function grabCallback(result) { - document.getElementById('target').innerHTML = result; -} - - -// replace can operate either against a url like grab or against a remote method -// if its going to be used against a remote method defaultServerUrl needs to be set to a url that is exporting the class its trying to call -// note that replace replace always works async - -HTML_AJAX.defaultServerUrl = 'server.php'; - -function replaceUrl() { - HTML_AJAX.replace('target',url); -} - -function replaceFromMethod() { - HTML_AJAX.replace('target','test','echo_string','Im a method call replacement'); -} -function replaceFromMethodMulti() { - // Null encoding does not support multiple arguments, you have to use JSON for that - HTML_AJAX.defaultEncoding = 'JSON'; // set encoding to JSON encoding method - HTML_AJAX.replace('target','test','multiarg','argument1','argument2','argument3'); - HTML_AJAX.defaultEncoding = 'Null'; // return it to default which is Null -} - - -// call is used to call a method on a remote server -// you need to set HTML_AJAX.defaultServerUrl to use it -// you might also want to set HTML_AJAX.defaultEncoding, options are Null and JSON, the server will autodetect this encoding from your content type -// but the return content type will be based on whatever the servers settings are -// You can use call in either Sync or Async mode depending on if you pass it a callback function - -function callSync() { - HTML_AJAX.defaultEncoding = 'JSON'; // set encoding to JSON encoding method - document.getElementById('target').innerHTML = HTML_AJAX.call('test','echo_string',false,'Im text that was echoed'); - HTML_AJAX.defaultEncoding = 'Null'; // return it to default which is Null -} - -function callAsync() { - HTML_AJAX.call('test','echo_string',callCallback,'Im text that was echoed Async'); -} - -function callCallback(result) { - document.getElementById('target').innerHTML = result; -} - -</script> -<ul> - <li><a href="javascript:clearTarget()">Clear Target</a></li> - <li><a href="javascript:grabSync()">Run Sync Grab Example</a></li> - <li><a href="javascript:grabAsync()">Run Async Grab Example</a></li> - <li><a href="javascript:replaceUrl()">Replace with content from a url</a></li> - <li><a href="javascript:replaceFromMethod()">Replace with content from a method call</a></li> - <li><a href="javascript:replaceFromMethodMulti()">Replace with content from a method call (multiple method arguments)</a></li> - <li><a href="javascript:callSync()">Sync Call</a></li> - <li><a href="javascript:callAsync()">ASync Call</a></li> -</ul> - -<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> -</body> -</html> -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ -?> +<?php +/** + * Example of Using HTML_AJAX in proxyless operation + * + * This is the simplest way to use HTML_AJAX if your just using grab and replace functions you don't even need a server + * You need every javascript file except JSON which is optional and is only needed if your using that encoding + * + * The proxyless api is provided by Main.js + * + * There are 3 main methods and 2 properties to the proxyless api, they all exist as static methods on HTML_AJAX + * HTML_AJAX.grab(url) + * HTML_AJAX.replace(id,url) or HTML_AJAX.replace(id,class,method,arg1,arg2,etc) + * HTML_AJAX.call(class,method,callback,arg1,arg2,etc) + * + * HTML_AJAX.defaultServerUrl = 'serverurl'; + * HTML_AJAX.defaultEncoding = 'Null'; + * + * The api is demonstrated below, server.php is used for call examples and to load the needed js files + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +?> +<html> +<head> + +<script type='text/javascript' src="server.php?client=Util"></script> +<script type='text/javascript' src="server.php?client=main"></script> +<script type='text/javascript' src="server.php?client=dispatcher"></script> +<script type='text/javascript' src="server.php?client=HttpClient"></script> +<script type='text/javascript' src="server.php?client=Request"></script> +<script type='text/javascript' src="server.php?client=json"></script> +<script type='text/javascript' src="server.php?client=loading"></script> + +</head> +<body> +<script type="text/javascript"> +function clearTarget() { + document.getElementById('target').innerHTML = 'clear'; +} + +// Add an error handler so we get an alert if any errors happen while making an AJAX call +HTML_AJAX.onError = function(e) +{ + alert(HTML_AJAX_Util.varDump(e)); +} + + +// Grab is the simplest usage of HTML_AJAX you use it to perform a request to a page and get its results back +// It can be used in either Sync mode where it returns directory or with a call back, both methods are shown below +var url = 'README'; +function grabSync() { + document.getElementById('target').innerHTML = HTML_AJAX.grab(url); +} + +function grabAsync() { + HTML_AJAX.grab(url,grabCallback); +} + +function grabCallback(result) { + document.getElementById('target').innerHTML = result; +} + + +// replace can operate either against a url like grab or against a remote method +// if its going to be used against a remote method defaultServerUrl needs to be set to a url that is exporting the class its trying to call +// note that replace replace always works async + +HTML_AJAX.defaultServerUrl = 'server.php'; + +function replaceUrl() { + HTML_AJAX.replace('target',url); +} + +function replaceFromMethod() { + HTML_AJAX.replace('target','test','echo_string','Im a method call replacement'); +} +function replaceFromMethodMulti() { + // Null encoding does not support multiple arguments, you have to use JSON for that + HTML_AJAX.defaultEncoding = 'JSON'; // set encoding to JSON encoding method + HTML_AJAX.replace('target','test','multiarg','argument1','argument2','argument3'); + HTML_AJAX.defaultEncoding = 'Null'; // return it to default which is Null +} + + +// call is used to call a method on a remote server +// you need to set HTML_AJAX.defaultServerUrl to use it +// you might also want to set HTML_AJAX.defaultEncoding, options are Null and JSON, the server will autodetect this encoding from your content type +// but the return content type will be based on whatever the servers settings are +// You can use call in either Sync or Async mode depending on if you pass it a callback function + +function callSync() { + HTML_AJAX.defaultEncoding = 'JSON'; // set encoding to JSON encoding method + document.getElementById('target').innerHTML = HTML_AJAX.call('test','echo_string',false,'Im text that was echoed'); + HTML_AJAX.defaultEncoding = 'Null'; // return it to default which is Null +} + +function callAsync() { + HTML_AJAX.call('test','echo_string',callCallback,'Im text that was echoed Async'); +} + +function callCallback(result) { + document.getElementById('target').innerHTML = result; +} + +</script> +<ul> + <li><a href="javascript:clearTarget()">Clear Target</a></li> + <li><a href="javascript:grabSync()">Run Sync Grab Example</a></li> + <li><a href="javascript:grabAsync()">Run Async Grab Example</a></li> + <li><a href="javascript:replaceUrl()">Replace with content from a url</a></li> + <li><a href="javascript:replaceFromMethod()">Replace with content from a method call</a></li> + <li><a href="javascript:replaceFromMethodMulti()">Replace with content from a method call (multiple method arguments)</a></li> + <li><a href="javascript:callSync()">Sync Call</a></li> + <li><a href="javascript:callAsync()">ASync Call</a></li> +</ul> + +<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> +</body> +</html> +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/queue_usage.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/queue_usage.php diff -u pear/HTML_AJAX/examples/queue_usage.php:1.1 pear/HTML_AJAX/examples/queue_usage.php:1.2 --- pear/HTML_AJAX/examples/queue_usage.php:1.1 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/queue_usage.php Mon Nov 7 13:43:49 2005 @@ -1,76 +1,76 @@ -<?php -/** - * Example of Using HTML_AJAX with a queue - * - * When using HTML_AJAX your actually always using a queue, its just its a simple one that always performs whatever actions its given immediately - * HTML_AJAX however provides other queues offering different modes of operation - * - * Currently the Queues are (class names are prefixed with: HTML_AJAX_Queue_): - * Immediate - Default make the request immediately - * Interval_SingleBuffer - Make request on an interval with holding just the last request between calls - * - * Interval_SingleBuffer is generally used for Live Search/Google Suggest type operations - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -?> -<html> -<head> - -<script type='text/javascript' src="server.php?client=Util,main,dispatcher,httpclient,request,json,loading"></script> -<script type='text/javascript' src="auto_server.php?stub=livesearch"></script> - -</head> -<body> -<script type="text/javascript"> - -// callback hash, outputs the results of the search method -callback = { - search: function(result) { - var out = "<ul>"; - - // if we have object this works right, if we have an array we get a problem - // if we have sparse keys will get an array back otherwise will get an array - for(var i in result) { - if (i != '______array') { - out += "<li>"+i+" = "+result[i]+"</li>"; - } - } - out += "</ul>"; - document.getElementById('target').innerHTML = out; - } -} - -// setup our remote object from the generated proxy stub -var remoteLiveSearch = new livesearch(callback); - -// we could change the queue by overriding the default one, but generally you want to create a new one -// set our remote object to use the rls queue -remoteLiveSearch.dispatcher.queue = 'rls'; - -// create the rls queue, with a 350ms buffer, a larger interval such as 2000 is useful to see what is happening but not so useful in real life -HTML_AJAX.queues['rls'] = new HTML_AJAX_Queue_Interval_SingleBuffer(350); - - -// what to call on onkeyup, you might want some logic here to not search on empty strings or to do something else in those cases -function searchRequest(searchBox) { - remoteLiveSearch.search(searchBox.value); -} -</script> - -<p>This is a really basic LiveSearch example, type in the box below to find a fruit</p> - -Search <input id="search" autocomplete="off" onkeyup="searchRequest(this)"> - -<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> -</body> -</html> -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ -?> +<?php +/** + * Example of Using HTML_AJAX with a queue + * + * When using HTML_AJAX your actually always using a queue, its just its a simple one that always performs whatever actions its given immediately + * HTML_AJAX however provides other queues offering different modes of operation + * + * Currently the Queues are (class names are prefixed with: HTML_AJAX_Queue_): + * Immediate - Default make the request immediately + * Interval_SingleBuffer - Make request on an interval with holding just the last request between calls + * + * Interval_SingleBuffer is generally used for Live Search/Google Suggest type operations + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +?> +<html> +<head> + +<script type='text/javascript' src="server.php?client=Util,main,dispatcher,httpclient,request,json,loading"></script> +<script type='text/javascript' src="auto_server.php?stub=livesearch"></script> + +</head> +<body> +<script type="text/javascript"> + +// callback hash, outputs the results of the search method +callback = { + search: function(result) { + var out = "<ul>"; + + // if we have object this works right, if we have an array we get a problem + // if we have sparse keys will get an array back otherwise will get an array + for(var i in result) { + if (i != '______array') { + out += "<li>"+i+" = "+result[i]+"</li>"; + } + } + out += "</ul>"; + document.getElementById('target').innerHTML = out; + } +} + +// setup our remote object from the generated proxy stub +var remoteLiveSearch = new livesearch(callback); + +// we could change the queue by overriding the default one, but generally you want to create a new one +// set our remote object to use the rls queue +remoteLiveSearch.dispatcher.queue = 'rls'; + +// create the rls queue, with a 350ms buffer, a larger interval such as 2000 is useful to see what is happening but not so useful in real life +HTML_AJAX.queues['rls'] = new HTML_AJAX_Queue_Interval_SingleBuffer(350); + + +// what to call on onkeyup, you might want some logic here to not search on empty strings or to do something else in those cases +function searchRequest(searchBox) { + remoteLiveSearch.search(searchBox.value); +} +</script> + +<p>This is a really basic LiveSearch example, type in the box below to find a fruit</p> + +Search <input id="search" autocomplete="off" onkeyup="searchRequest(this)"> + +<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> +</body> +</html> +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/serialize.examples.htm?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/serialize.examples.htm diff -u pear/HTML_AJAX/examples/serialize.examples.htm:1.1 pear/HTML_AJAX/examples/serialize.examples.htm:1.2 --- pear/HTML_AJAX/examples/serialize.examples.htm:1.1 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/serialize.examples.htm Mon Nov 7 13:43:49 2005 @@ -1,381 +1,381 @@ -<script type="text/javascript" src="serialize.js"></script> -<script type="text/javascript"> - -function describe(inp) -{ - var type = gettype(inp); - var ctype; - var out = "Type: " + type + "\nContents: "; - switch (type) { - case "string": - case "number": - out += inp; - break; - case "boolean": - out += (inp ? 'true' : 'false'); - break; - case "array": - case "object": - for (k in inp) { - out += k + " => "; - ctype = gettype(inp[k]); - out += (ctype == "array" || ctype == "object" ? describe(inp[k]) : inp[k]) + "\n"; - } - } - return out; -} - -unserializer = new Unserializer; - -</script> -<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1><strong>PHP Code:</strong> -<pre>$foo = null;</pre> -<strong>PHP value:</strong><pre> -NULL -</pre> -<strong>Serialized in PHP:</strong> -<pre>N;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("N%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = true;</pre> -<strong>PHP value:</strong><pre> -bool(true) -</pre> -<strong>Serialized in PHP:</strong> -<pre>b:1;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("b%3A1%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = "foobar";</pre> -<strong>PHP value:</strong><pre> -string(6) "foobar" -</pre> -<strong>Serialized in PHP:</strong> -<pre>s:6:"foobar";</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foobar%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = 337;</pre> -<strong>PHP value:</strong><pre> -int(337) -</pre> -<strong>Serialized in PHP:</strong> -<pre>i:337;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("i%3A337%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = 99.99;</pre> -<strong>PHP value:</strong><pre> -float(99.99) -</pre> -<strong>Serialized in PHP:</strong> -<pre>d:99.9899999999999948840923025272786617279052734375;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("d%3A99.9899999999999948840923025272786617279052734375%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = array("a" => 1, "b" => 2, 3);</pre> -<strong>PHP value:</strong><pre> -array(3) { - ["a"]=> - int(1) - ["b"]=> - int(2) - [0]=> - int(3) -} -</pre> -<strong>Serialized in PHP:</strong> -<pre>a:3:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bs%3A1%3A%22a%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = array(1,2,array(1,2,3));</pre> -<strong>PHP value:</strong><pre> -array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} -</pre> -<strong>Serialized in PHP:</strong> -<pre>a:3:{i:0;i:1;i:1;i:2;i:2;a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bi%3A0%3Bi%3A1%3Bi%3A1%3Bi%3A2%3Bi%3A2%3Ba%3A3%3A%7Bi%3A0%3Bi%3A1%3Bi%3A1%3Bi%3A2%3Bi%3A2%3Bi%3A3%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>class Foo { var $foo; var $bar; }$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");</pre> -<strong>PHP value:</strong><pre> -object(Foo)#1 (2) { - ["foo"]=> - string(5) "hello" - ["bar"]=> - array(2) { - [0]=> - string(5) "world" - [1]=> - string(8) "universe" - } -} -</pre> -<strong>Serialized in PHP:</strong> -<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1></pre> -<strong>Invalidly serialized:</strong> -<pre>x</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("x"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>x:1</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("x%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>N</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("N"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>Nx</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("Nx"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>b:f;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("b%3Af%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>b:1</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("b%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>i:foo;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("i%3Afoo%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>i:1</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("i%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>d:foo;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("d%3Afoo%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>d:1.1.1;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("d%3A1.1.1%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>d:1.1</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("d%3A1.1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>s:6:"foo";</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foo%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>s:6:"foofoo"</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foofoo%22"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>s:1:"foo";</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("s%3A1%3A%22foo%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>s:0:""</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("s%3A0%3A%22%22"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>a:3:{s:1:"aa";i:1;s:1:"b";i:2;i:0;i:3;}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bs%3A1%3A%22aa%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>a:4:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A4%3A%7Bs%3A1%3A%22a%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>a:3:{i:1;s:1:"b";i:2;i:0;i:3;}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>a:3:{}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>O:3:"Fooo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Fooo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>O:3:"Foo":3:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A3%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>O:3:"Foo":2:{s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe"}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - +<script type="text/javascript" src="server.php?client=phpserializer"></script> +<script type="text/javascript"> + +function describe(inp) +{ + var type = gettype(inp); + var ctype; + var out = "Type: " + type + "\nContents: "; + switch (type) { + case "string": + case "number": + out += inp; + break; + case "boolean": + out += (inp ? 'true' : 'false'); + break; + case "array": + case "object": + for (k in inp) { + out += k + " => "; + ctype = gettype(inp[k]); + out += (ctype == "array" || ctype == "object" ? describe(inp[k]) : inp[k]) + "\n"; + } + } + return out; +} + +unserializer = new Unserializer; + +</script> +<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1><strong>PHP Code:</strong> +<pre>$foo = null;</pre> +<strong>PHP value:</strong><pre> +NULL +</pre> +<strong>Serialized in PHP:</strong> +<pre>N;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("N%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = true;</pre> +<strong>PHP value:</strong><pre> +bool(true) +</pre> +<strong>Serialized in PHP:</strong> +<pre>b:1;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("b%3A1%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = "foobar";</pre> +<strong>PHP value:</strong><pre> +string(6) "foobar" +</pre> +<strong>Serialized in PHP:</strong> +<pre>s:6:"foobar";</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foobar%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = 337;</pre> +<strong>PHP value:</strong><pre> +int(337) +</pre> +<strong>Serialized in PHP:</strong> +<pre>i:337;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("i%3A337%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = 99.99;</pre> +<strong>PHP value:</strong><pre> +float(99.99) +</pre> +<strong>Serialized in PHP:</strong> +<pre>d:99.9899999999999948840923025272786617279052734375;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("d%3A99.9899999999999948840923025272786617279052734375%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = array("a" => 1, "b" => 2, 3);</pre> +<strong>PHP value:</strong><pre> +array(3) { + ["a"]=> + int(1) + ["b"]=> + int(2) + [0]=> + int(3) +} +</pre> +<strong>Serialized in PHP:</strong> +<pre>a:3:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bs%3A1%3A%22a%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = array(1,2,array(1,2,3));</pre> +<strong>PHP value:</strong><pre> +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +</pre> +<strong>Serialized in PHP:</strong> +<pre>a:3:{i:0;i:1;i:1;i:2;i:2;a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bi%3A0%3Bi%3A1%3Bi%3A1%3Bi%3A2%3Bi%3A2%3Ba%3A3%3A%7Bi%3A0%3Bi%3A1%3Bi%3A1%3Bi%3A2%3Bi%3A2%3Bi%3A3%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>class Foo { var $foo; var $bar; }$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");</pre> +<strong>PHP value:</strong><pre> +object(Foo)#1 (2) { + ["foo"]=> + string(5) "hello" + ["bar"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(8) "universe" + } +} +</pre> +<strong>Serialized in PHP:</strong> +<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1></pre> +<strong>Invalidly serialized:</strong> +<pre>x</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("x"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>x:1</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("x%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>N</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("N"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>Nx</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("Nx"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>b:f;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("b%3Af%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>b:1</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("b%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>i:foo;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("i%3Afoo%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>i:1</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("i%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>d:foo;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("d%3Afoo%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>d:1.1.1;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("d%3A1.1.1%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>d:1.1</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("d%3A1.1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>s:6:"foo";</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foo%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>s:6:"foofoo"</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foofoo%22"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>s:1:"foo";</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("s%3A1%3A%22foo%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>s:0:""</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("s%3A0%3A%22%22"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>a:3:{s:1:"aa";i:1;s:1:"b";i:2;i:0;i:3;}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bs%3A1%3A%22aa%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>a:4:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A4%3A%7Bs%3A1%3A%22a%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>a:3:{i:1;s:1:"b";i:2;i:0;i:3;}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>a:3:{}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>O:3:"Fooo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Fooo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>O:3:"Foo":3:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A3%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>O:3:"Foo":2:{s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe"}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/serialize.examples.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/serialize.examples.php diff -u pear/HTML_AJAX/examples/serialize.examples.php:1.1 pear/HTML_AJAX/examples/serialize.examples.php:1.2 --- pear/HTML_AJAX/examples/serialize.examples.php:1.1 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/serialize.examples.php Mon Nov 7 13:43:49 2005 @@ -1,98 +1,98 @@ -<script type="text/javascript" src="serialize.js"></script> -<script type="text/javascript"> - -function describe(inp) -{ - var type = gettype(inp); - var ctype; - var out = "Type: " + type + "\nContents: "; - switch (type) { - case "string": - case "number": - out += inp; - break; - case "boolean": - out += (inp ? 'true' : 'false'); - break; - case "array": - case "object": - for (k in inp) { - out += k + " => "; - ctype = gettype(inp[k]); - out += (ctype == "array" || ctype == "object" ? describe(inp[k]) : inp[k]) + "\n"; - } - } - return out; -} - -unserializer = new Unserializer; - -</script> -<?php - -$examples = array( - '$foo = null;', - '$foo = true;', - '$foo = "foobar";', - '$foo = 337;', - '$foo = 99.99;', - '$foo = array("a" => 1, "b" => 2, 3);', - '$foo = array(1,2,array(1,2,3));', - 'class Foo { var $foo; var $bar; }' - . '$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");' -); - -echo '<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1>'; -$c = count($examples); -for ($i = 0; $i < $c; $i++) { - echo "<strong>PHP Code:</strong>\n<pre>$examples[$i]</pre>\n<strong>PHP value:</strong><pre>\n"; - eval($examples[$i]); - var_dump($foo); - $sfoo = serialize($foo); - echo "</pre>\n<strong>Serialized in PHP:</strong>\n<pre>", $sfoo, "</pre>\n", - "<strong>Unserialized in JS:</strong>\n<pre>\n", - '<script type="text/javascript">', - 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {', - 'document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + ', - '"</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));', "</script>\n</pre>\n<hr />\n\n"; -} - -$bad_examples = array( - 'x', - 'x:1', - 'N', - 'Nx', - 'b:f;', - 'b:1', - 'i:foo;', - 'i:1', - 'd:foo;', - 'd:1.1.1;', - 'd:1.1', - 's:6:"foo";', - 's:6:"foofoo"', - 's:1:"foo";', - 's:0:""', - 'a:3:{s:1:"aa";i:1;s:1:"b";i:2;i:0;i:3;}', - 'a:4:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;', - 'a:3:{i:1;s:1:"b";i:2;i:0;i:3;}', - 'a:3:{}', - 'O:3:"Fooo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', - 'O:3:"Foo":3:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', - 'O:3:"Foo":2:{s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', - 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}', - 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe"}}' -); - -echo '<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1>'; -foreach ($bad_examples as $sfoo) { - echo "</pre>\n<strong>Invalidly serialized:</strong>\n<pre>", $sfoo, "</pre>\n", - "<strong>Unserialized in JS:</strong>\n<pre>\n", - '<script type="text/javascript">', - 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {', - 'document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));', - "</script>\n</pre>\n<hr />\n\n"; -} - - -?> +<script type="text/javascript" src="serialize.js"></script> +<script type="text/javascript"> + +function describe(inp) +{ + var type = gettype(inp); + var ctype; + var out = "Type: " + type + "\nContents: "; + switch (type) { + case "string": + case "number": + out += inp; + break; + case "boolean": + out += (inp ? 'true' : 'false'); + break; + case "array": + case "object": + for (k in inp) { + out += k + " => "; + ctype = gettype(inp[k]); + out += (ctype == "array" || ctype == "object" ? describe(inp[k]) : inp[k]) + "\n"; + } + } + return out; +} + +unserializer = new Unserializer; + +</script> +<?php + +$examples = array( + '$foo = null;', + '$foo = true;', + '$foo = "foobar";', + '$foo = 337;', + '$foo = 99.99;', + '$foo = array("a" => 1, "b" => 2, 3);', + '$foo = array(1,2,array(1,2,3));', + 'class Foo { var $foo; var $bar; }' + . '$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");' +); + +echo '<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1>'; +$c = count($examples); +for ($i = 0; $i < $c; $i++) { + echo "<strong>PHP Code:</strong>\n<pre>$examples[$i]</pre>\n<strong>PHP value:</strong><pre>\n"; + eval($examples[$i]); + var_dump($foo); + $sfoo = serialize($foo); + echo "</pre>\n<strong>Serialized in PHP:</strong>\n<pre>", $sfoo, "</pre>\n", + "<strong>Unserialized in JS:</strong>\n<pre>\n", + '<script type="text/javascript">', + 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {', + 'document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + ', + '"</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));', "</script>\n</pre>\n<hr />\n\n"; +} + +$bad_examples = array( + 'x', + 'x:1', + 'N', + 'Nx', + 'b:f;', + 'b:1', + 'i:foo;', + 'i:1', + 'd:foo;', + 'd:1.1.1;', + 'd:1.1', + 's:6:"foo";', + 's:6:"foofoo"', + 's:1:"foo";', + 's:0:""', + 'a:3:{s:1:"aa";i:1;s:1:"b";i:2;i:0;i:3;}', + 'a:4:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;', + 'a:3:{i:1;s:1:"b";i:2;i:0;i:3;}', + 'a:3:{}', + 'O:3:"Fooo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', + 'O:3:"Foo":3:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', + 'O:3:"Foo":2:{s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', + 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}', + 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe"}}' +); + +echo '<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1>'; +foreach ($bad_examples as $sfoo) { + echo "</pre>\n<strong>Invalidly serialized:</strong>\n<pre>", $sfoo, "</pre>\n", + "<strong>Unserialized in JS:</strong>\n<pre>\n", + '<script type="text/javascript">', + 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {', + 'document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));', + "</script>\n</pre>\n<hr />\n\n"; +} + + +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/server.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/server.php diff -u pear/HTML_AJAX/examples/server.php:1.3 pear/HTML_AJAX/examples/server.php:1.4 --- pear/HTML_AJAX/examples/server.php:1.3 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/server.php Mon Nov 7 13:43:49 2005 @@ -1,35 +1,35 @@ -<?php -/** - * Simplest possible usage of HTML_AJAX_Server - * - * The server responds to ajax calls and also serves the js client libraries, so they can be used directly from the PEAR data dir - * 304 not modified headers are used when server client libraries so they will be cached on the browser reducing overhead - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - - // include the server class -include 'HTML/AJAX/Server.php'; - -// include the test class will be registering - include 'test.class.php'; - -// create our new server -$server = new HTML_AJAX_Server(); - -// register an instance of the class were registering -$test =& new test(); -$server->registerClass($test); - -// handle different types of requests possiblities are -// ?client=all - request for all javascript client files -// ?stub=classname - request for proxy stub for given class, can be combined with client but this may hurt caching unless stub=all is used -// ?c=classname&m=method - an ajax call, server handles serialization and handing things off to the proper method then returning the results -$server->handleRequest(); -?> +<?php +/** + * Simplest possible usage of HTML_AJAX_Server + * + * The server responds to ajax calls and also serves the js client libraries, so they can be used directly from the PEAR data dir + * 304 not modified headers are used when server client libraries so they will be cached on the browser reducing overhead + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + + // include the server class +include 'HTML/AJAX/Server.php'; + +// include the test class will be registering + include 'test.class.php'; + +// create our new server +$server = new HTML_AJAX_Server(); + +// register an instance of the class were registering +$test =& new test(); +$server->registerClass($test); + +// handle different types of requests possiblities are +// ?client=all - request for all javascript client files +// ?stub=classname - request for proxy stub for given class, can be combined with client but this may hurt caching unless stub=all is used +// ?c=classname&m=method - an ajax call, server handles serialization and handing things off to the proper method then returning the results +$server->handleRequest(); +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/test.class.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/test.class.php diff -u pear/HTML_AJAX/examples/test.class.php:1.3 pear/HTML_AJAX/examples/test.class.php:1.4 --- pear/HTML_AJAX/examples/test.class.php:1.3 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/test.class.php Mon Nov 7 13:43:49 2005 @@ -1,45 +1,45 @@ -<?php -/** - * Test class used in other examples - * Constructors and private methods marked with _ are never exported in proxies to JavaScript - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -class test { - function test() { - } - function _private() { - } - function echo_string($string) { - return "From PHP: ".$string; - } - function slow_echo_string($string) { - sleep(2); - return "From PHP: ".$string; - } - function error_test($string) { - trigger_error($string); - } - function multiarg() { - $args = func_get_args(); - return "passed in ".count($args)." args ".implode('|',$args); - } - function cookies() { - return $_COOKIE; - } -} - -if (isset($_GET['TEST_CLASS'])) { - $t = new test(); - var_dump($t->echo_string('test string')); - var_dump($t->slow_echo_string('test string')); - var_dump($t->error_test('test string')); - var_dump($t->multiarg('arg1','arg2','arg3')); -} -?> +<?php +/** + * Test class used in other examples + * Constructors and private methods marked with _ are never exported in proxies to JavaScript + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +class test { + function test() { + } + function _private() { + } + function echo_string($string) { + return "From PHP: ".$string; + } + function slow_echo_string($string) { + sleep(2); + return "From PHP: ".$string; + } + function error_test($string) { + trigger_error($string); + } + function multiarg() { + $args = func_get_args(); + return "passed in ".count($args)." args ".implode('|',$args); + } + function cookies() { + return $_COOKIE; + } +} + +if (isset($_GET['TEST_CLASS'])) { + $t = new test(); + var_dump($t->echo_string('test string')); + var_dump($t->slow_echo_string('test string')); + var_dump($t->error_test('test string')); + var_dump($t->multiarg('arg1','arg2','arg3')); +} +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/test.html?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/test.html diff -u pear/HTML_AJAX/examples/test.html:1.1 pear/HTML_AJAX/examples/test.html:1.2 --- pear/HTML_AJAX/examples/test.html:1.1 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/test.html Mon Nov 7 13:43:49 2005 @@ -1,55 +1,55 @@ -<!DOCTYPE html -PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" -"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> - <title> - How to use behavior.js - </title> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> - <script src="cssQuery-p.js" type="text/javascript"></script> - <script src="behavior.js" type="text/javascript"></script> -<script type="text/javascript"> -Behavior.register( - ".alert", - function(element) { - element.onclick = function(){ - alert('I alert on click'); - } - } - ); - - Behavior.register( - ".annoy", - function(element) { - element.onmouseout = function(){ - alert('I alert on mouseout, very annoying'); - } - } - ); - - Behavior.register( - ".red", - function(element) { - element.onmouseover = function(){ - element.style.backgroundColor = 'red'; - } - } - ); -</script> -</head> - -<body> - <div style="border: 1px solid black; width: 50%; margin: 5em"> - <div class="alert"> - I am a div that alerts when you click on me - notice I just have class="alert" to make it work :) - </div> - <div class="annoy"> - I am a div that alerts when you mouseover me - class="annoy" makes it work - </div> - <div class=" alert red"> - I am a div that alerts when you click on me and the background turns red on mouseover - class="alert red" - </div> - </div> -</body> -</html> +<!DOCTYPE html +PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <title> + How to use behavior.js + </title> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <script src="cssQuery-p.js" type="text/javascript"></script> + <script src="behavior.js" type="text/javascript"></script> +<script type="text/javascript"> +Behavior.register( + ".alert", + function(element) { + element.onclick = function(){ + alert('I alert on click'); + } + } + ); + + Behavior.register( + ".annoy", + function(element) { + element.onmouseout = function(){ + alert('I alert on mouseout, very annoying'); + } + } + ); + + Behavior.register( + ".red", + function(element) { + element.onmouseover = function(){ + element.style.backgroundColor = 'red'; + } + } + ); +</script> +</head> + +<body> + <div style="border: 1px solid black; width: 50%; margin: 5em"> + <div class="alert"> + I am a div that alerts when you click on me - notice I just have class="alert" to make it work :) + </div> + <div class="annoy"> + I am a div that alerts when you mouseover me - class="annoy" makes it work + </div> + <div class=" alert red"> + I am a div that alerts when you click on me and the background turns red on mouseover - class="alert red" + </div> + </div> +</body> +</html> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/test2.class.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/test2.class.php diff -u pear/HTML_AJAX/examples/test2.class.php:1.1 pear/HTML_AJAX/examples/test2.class.php:1.2 --- pear/HTML_AJAX/examples/test2.class.php:1.1 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/test2.class.php Mon Nov 7 13:43:49 2005 @@ -1,25 +1,25 @@ -<?php -/** - * Test class used in other examples - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -class test2 { - function echo_string($string) { - return $string; - } - function slow_echo_string($string) { - sleep(2); - return $string; - } - function error_test($string) { - trigger_error($string); - } -} -?> +<?php +/** + * Test class used in other examples + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +class test2 { + function echo_string($string) { + return $string; + } + function slow_echo_string($string) { + sleep(2); + return $string; + } + function error_test($string) { + trigger_error($string); + } +} +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/test_speed.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/test_speed.php diff -u pear/HTML_AJAX/examples/test_speed.php:1.3 pear/HTML_AJAX/examples/test_speed.php:1.4 --- pear/HTML_AJAX/examples/test_speed.php:1.3 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/test_speed.php Mon Nov 7 13:43:49 2005 @@ -1,91 +1,91 @@ -<?php -/** - * Simple speed test using the null serializer, possibly useful in comparing overhead when tested on local host - * - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - include 'HTML/AJAX.php'; - - include 'test.class.php'; - - - - $ajax = new HTML_AJAX(); - $ajax->serializer = "Null"; - $ajax->unserializer = "Null"; - $ajax->registerClass(new test()); - - if ($ajax->handleRequest()) { - die(); - } -?><html> -<head> - -<script type='text/javascript' src="server.php?client=all&stub=all"></script> -</head> -<body> -<script type="text/javascript"> -var t = new test(); -var t2 = new test({echo_string: function(){ endCall('Async Echo'); totalA(); }}); - -var time1; -var total = 0; -var count = 0; - -function speedTest() { - - document.getElementById('target').innerHTML += "10 Sync Calls\n"; - for(var i = 0; i < 10; i++) { - startCall(); - t.echo_string('Test'); - endCall('Sync Echo'); - } - document.getElementById('target').innerHTML += "Total: "+total+"\n\n\n"; - total = 0; - - document.getElementById('target').innerHTML += "10 Async Calls\n"; - count = 0; - for(var i = 0; i < 10; i++) { - setTimeout("runAsync();",500*i); - } - total = 0; - -} -function totalA() { - count++; - if (count == 10) { - document.getElementById('target').innerHTML += "Total: "+total+"\n"; - } -} -function runAsync() { - startCall(); - t2.echo_string('Test'); -} -function startCall() { - time1 = new Date(); -} -function endCall(name) { - var time = 0; - - var time2 = new Date(); - - time = time2.getTime() - time1.getTime(); - total += time; - - document.getElementById('target').innerHTML += name+":"+time+"\n"; -} - - -</script> -<a href="javascript:speedTest()">Start Speed Test</a> -<pre id="target"> -</pre> -</body> -</html> +<?php +/** + * Simple speed test using the null serializer, possibly useful in comparing overhead when tested on local host + * + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + include 'HTML/AJAX.php'; + + include 'test.class.php'; + + + + $ajax = new HTML_AJAX(); + $ajax->serializer = "Null"; + $ajax->unserializer = "Null"; + $ajax->registerClass(new test()); + + if ($ajax->handleRequest()) { + die(); + } +?><html> +<head> + +<script type='text/javascript' src="server.php?client=all&stub=all"></script> +</head> +<body> +<script type="text/javascript"> +var t = new test(); +var t2 = new test({echo_string: function(){ endCall('Async Echo'); totalA(); }}); + +var time1; +var total = 0; +var count = 0; + +function speedTest() { + + document.getElementById('target').innerHTML += "10 Sync Calls\n"; + for(var i = 0; i < 10; i++) { + startCall(); + t.echo_string('Test'); + endCall('Sync Echo'); + } + document.getElementById('target').innerHTML += "Total: "+total+"\n\n\n"; + total = 0; + + document.getElementById('target').innerHTML += "10 Async Calls\n"; + count = 0; + for(var i = 0; i < 10; i++) { + setTimeout("runAsync();",500*i); + } + total = 0; + +} +function totalA() { + count++; + if (count == 10) { + document.getElementById('target').innerHTML += "Total: "+total+"\n"; + } +} +function runAsync() { + startCall(); + t2.echo_string('Test'); +} +function startCall() { + time1 = new Date(); +} +function endCall(name) { + var time = 0; + + var time2 = new Date(); + + time = time2.getTime() - time1.getTime(); + total += time; + + document.getElementById('target').innerHTML += name+":"+time+"\n"; +} + + +</script> +<a href="javascript:speedTest()">Start Speed Test</a> +<pre id="target"> +</pre> +</body> +</html>
http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/README?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/README diff -u pear/HTML_AJAX/examples/README:1.3 pear/HTML_AJAX/examples/README:1.4 --- pear/HTML_AJAX/examples/README:1.3 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/README Mon Nov 7 13:43:49 2005 @@ -1 +1 @@ -See Index.php for details +See Index.php for details http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/auto_server.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/auto_server.php diff -u pear/HTML_AJAX/examples/auto_server.php:1.3 pear/HTML_AJAX/examples/auto_server.php:1.4 --- pear/HTML_AJAX/examples/auto_server.php:1.3 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/auto_server.php Mon Nov 7 13:43:49 2005 @@ -1,65 +1,65 @@ -<?php -/** - * Advanced usage of HTML_AJAX_Server - * Allows for a single server to manage exporting a large number of classes without high overhead per call - * Also gives a single place to handle setup tasks especially useful if session setup is required - * - * The server responds to ajax calls and also serves the js client libraries, so they can be used directly from the PEAR data dir - * 304 not modified headers are used when server client libraries so they will be cached on the browser reducing overhead - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - - // include the server class -include 'HTML/AJAX/Server.php'; - - -// extend HTML_AJAX_Server creating our own custom one with init{ClassName} methods for each class it supports calls on -class TestServer extends HTML_AJAX_Server { - // this flag must be set to on init methods - var $initMethods = true; - - // init method for the test class, includes needed files an registers it for ajax - function initTest() { - include 'test.class.php'; - $this->registerClass(new test()); - } - - // init method for the livesearch class, includes needed files an registers it for ajax - function initLivesearch() { - include 'livesearch.class.php'; - $this->registerClass(new livesearch()); - } - - -} - -// create an instance of our test server -$server = new TestServer(); - -// init methods can also be added to the server by registering init objects, this is useful in cases where you want to dynamically add init methods -class initObject { - // init method for the test class, includes needed files an registers it for ajax - function initTest2() { - include 'test2.class.php'; - $this->server->registerClass(new test2()); - } -} -$init = new initObject(); -$init->server =& $server; -$server->registerInitObject($init); - -// you can use HTML_AJAX_Server to deliver your own custom javascript libs, when used with comma seperated client lists you can -// use just one javascript include for all your library files -// example url: auto_server.php?client=auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,customLib -$server->registerJSLibrary('customLib','customLib.js','./'); - -// handle requests as needed -$server->handleRequest(); -?> +<?php +/** + * Advanced usage of HTML_AJAX_Server + * Allows for a single server to manage exporting a large number of classes without high overhead per call + * Also gives a single place to handle setup tasks especially useful if session setup is required + * + * The server responds to ajax calls and also serves the js client libraries, so they can be used directly from the PEAR data dir + * 304 not modified headers are used when server client libraries so they will be cached on the browser reducing overhead + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + + // include the server class +include 'HTML/AJAX/Server.php'; + + +// extend HTML_AJAX_Server creating our own custom one with init{ClassName} methods for each class it supports calls on +class TestServer extends HTML_AJAX_Server { + // this flag must be set to on init methods + var $initMethods = true; + + // init method for the test class, includes needed files an registers it for ajax + function initTest() { + include 'test.class.php'; + $this->registerClass(new test()); + } + + // init method for the livesearch class, includes needed files an registers it for ajax + function initLivesearch() { + include 'livesearch.class.php'; + $this->registerClass(new livesearch()); + } + + +} + +// create an instance of our test server +$server = new TestServer(); + +// init methods can also be added to the server by registering init objects, this is useful in cases where you want to dynamically add init methods +class initObject { + // init method for the test class, includes needed files an registers it for ajax + function initTest2() { + include 'test2.class.php'; + $this->server->registerClass(new test2()); + } +} +$init = new initObject(); +$init->server =& $server; +$server->registerInitObject($init); + +// you can use HTML_AJAX_Server to deliver your own custom javascript libs, when used with comma seperated client lists you can +// use just one javascript include for all your library files +// example url: auto_server.php?client=auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,customLib +$server->registerJSLibrary('customLib','customLib.js','./'); + +// handle requests as needed +$server->handleRequest(); +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/customLib.js?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/customLib.js diff -u pear/HTML_AJAX/examples/customLib.js:1.1 pear/HTML_AJAX/examples/customLib.js:1.2 --- pear/HTML_AJAX/examples/customLib.js:1.1 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/customLib.js Mon Nov 7 13:43:49 2005 @@ -1,5 +1,5 @@ -// An example custom javascript library served up by the auto_server - -function customLibAlert(msg) { - alert(msg); -} +// An example custom javascript library served up by the auto_server + +function customLibAlert(msg) { + alert(msg); +} http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/error_usage.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/error_usage.php diff -u pear/HTML_AJAX/examples/error_usage.php:1.1 pear/HTML_AJAX/examples/error_usage.php:1.2 --- pear/HTML_AJAX/examples/error_usage.php:1.1 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/error_usage.php Mon Nov 7 13:43:49 2005 @@ -1,31 +1,31 @@ -<?php -/** - * Test class used in other examples - * Constructors and private methods marked with _ are never exported in proxies to JavaScript - * - * @category HTML - * @package AJAX - * @author David Coallier <davidc@agoraproduction.com> - * @copyright 2005 David Coallier - * @license LGPL http://www.gnu.org/copyleft/lesser.txt - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -require_once 'HTML/AJAX.php'; - -class error_test -{ - function error_test() - { - $ajax =& new HTML_AJAX; - $ajax->debugEnabled = true; - $ajax->debugSession = true; - set_error_handler(array(&$ajax, '_errorHandler')); - trigger_error("I don't know"); - } -} - -$t =& new error_test; -print_r($t); - -?> +<?php +/** + * Test class used in other examples + * Constructors and private methods marked with _ are never exported in proxies to JavaScript + * + * @category HTML + * @package AJAX + * @author David Coallier <davidc@agoraproduction.com> + * @copyright 2005 David Coallier + * @license LGPL http://www.gnu.org/copyleft/lesser.txt + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +require_once 'HTML/AJAX.php'; + +class error_test +{ + function error_test() + { + $ajax =& new HTML_AJAX; + $ajax->debugEnabled = true; + $ajax->debugSession = true; + set_error_handler(array(&$ajax, '_errorHandler')); + trigger_error("I don't know"); + } +} + +$t =& new error_test; +print_r($t); + +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/helper_usage.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/helper_usage.php diff -u pear/HTML_AJAX/examples/helper_usage.php:1.1 pear/HTML_AJAX/examples/helper_usage.php:1.2 --- pear/HTML_AJAX/examples/helper_usage.php:1.1 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/helper_usage.php Mon Nov 7 13:43:49 2005 @@ -1,49 +1,49 @@ -<?php -/** - * Example of Using HTML_AJAX_Helper - * - * HTML_AJAX_Helper takes care of basic JavaScript and HTML generation that is needed in many AJAX requests - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - -// include the helper class -require_once 'HTML/AJAX/Helper.php'; - -// create an instance and set the server url -$ajaxHelper = new HTML_AJAX_Helper(); -$ajaxHelper->serverUrl = 'auto_server.php'; -$ajaxHelper->jsLibraries[] = 'customLib'; -?> -<html> -<head> - -<?php - // output a javascript neded to setup HTML_AJAX - // by default this is all the libraries shipped with HTML_AJAX, take a look at $ajaxHelper->jsLibraries to edit the list - echo $ajaxHelper->setupAJAX(); -?> - -</head> -<body> -<?php - // output a custom loading message - echo $ajaxHelper->loadingMessage("Waiting on the Server ..."); -?> - -<div id="updateTarget">I'm an update Target</div> -<?php - // update the element using ajax - echo $ajaxHelper->updateElement('updateTarget',array('test','echo_string','Some text to echo'),'replace',true); -?> -</body> -</html> -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ -?> +<?php +/** + * Example of Using HTML_AJAX_Helper + * + * HTML_AJAX_Helper takes care of basic JavaScript and HTML generation that is needed in many AJAX requests + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + +// include the helper class +require_once 'HTML/AJAX/Helper.php'; + +// create an instance and set the server url +$ajaxHelper = new HTML_AJAX_Helper(); +$ajaxHelper->serverUrl = 'auto_server.php'; +$ajaxHelper->jsLibraries[] = 'customLib'; +?> +<html> +<head> + +<?php + // output a javascript neded to setup HTML_AJAX + // by default this is all the libraries shipped with HTML_AJAX, take a look at $ajaxHelper->jsLibraries to edit the list + echo $ajaxHelper->setupAJAX(); +?> + +</head> +<body> +<?php + // output a custom loading message + echo $ajaxHelper->loadingMessage("Waiting on the Server ..."); +?> + +<div id="updateTarget">I'm an update Target</div> +<?php + // update the element using ajax + echo $ajaxHelper->updateElement('updateTarget',array('test','echo_string','Some text to echo'),'replace',true); +?> +</body> +</html> +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/index.php?r1=1.2&r2=1.3&ty=u Index: pear/HTML_AJAX/examples/index.php diff -u pear/HTML_AJAX/examples/index.php:1.2 pear/HTML_AJAX/examples/index.php:1.3 --- pear/HTML_AJAX/examples/index.php:1.2 Wed Oct 26 12:45:30 2005 +++ pear/HTML_AJAX/examples/index.php Mon Nov 7 13:43:49 2005 @@ -1,50 +1,51 @@ -<html> -<head> -<title>HTML_AJAX Examples</title> -</head> -<body> -<p> -These examples cover basic AJAX usage -</p> - -<p> -All example files are fully commented, reading through them will give you a good overview on how things work. -</p> - -<p>The term proxy in these examples refers to a javascript class that is generated and has functions that map to the eqivalent php class. -These proxy classes work much in the same way as a SOAP proxy class that is generated from wsdl. -</p> - -<p> -Front end files for examples, you can actually run these and see some example output -</p> -<ul> -<li><a href='proxyless_usage.php'>proxyless_usage.php</a> - Using HTML_AJAX in standalone mode, possible doesn't require PHP or any backend HTML_AJAX classes</li> -<li><a href='proxy_usage_inline_javascript.php'>proxy_usage_inline_javascript.php</a> - Single file proxy style usage</li> -<li><a href='proxy_usage_server.php'>proxy_usage_server.php</a> - Multi-file proxy usage, either server file could be used with this example</li> -<li><a href='queue_usage.php'>queue_usage.php</a> - An example of using a queue to manage ajax calls, a simple live search example</li> -<li><a href='helper_usage.php'>helper_usage.php</a> - An example showing the basics of the helper api</li> -</ul> - -<p>Real Life Examples</p> -<ul> -<li><a href='login/index.php'>login/index.php</a> - An example creating an AJAX driven login</a></li> -</ul> - -<p> -2 server examples are provided -</p> -<ul> -<li>server.php - Basic server operation, serving ajax calls and client lib requests</li> -<li>auto_server.php - Advanced server operation, only create php classes as needed</li> -</ul> - -<p> -Other Example files: -</p> -<ul> -<li><a href='test_speed.php'>test_speed.php</p> - A basic setup for measuring the speed of calls</li> -</ul> - -</body> -</html> +<html> +<head> +<title>HTML_AJAX Examples</title> +</head> +<body> +<p> +These examples cover basic AJAX usage +</p> + +<p> +All example files are fully commented, reading through them will give you a good overview on how things work. +</p> + +<p>The term proxy in these examples refers to a javascript class that is generated and has functions that map to the eqivalent php class. +These proxy classes work much in the same way as a SOAP proxy class that is generated from wsdl. +</p> + +<p> +Front end files for examples, you can actually run these and see some example output +</p> +<ul> +<li><a href='proxyless_usage.php'>proxyless_usage.php</a> - Using HTML_AJAX in standalone mode, possible doesn't require PHP or any backend HTML_AJAX classes</li> +<li><a href='proxy_usage_inline_javascript.php'>proxy_usage_inline_javascript.php</a> - Single file proxy style usage</li> +<li><a href='proxy_usage_server.php'>proxy_usage_server.php</a> - Multi-file proxy usage, either server file could be used with this example</li> +<li><a href='queue_usage.php'>queue_usage.php</a> - An example of using a queue to manage ajax calls, a simple live search example</li> +<li><a href='helper_usage.php'>helper_usage.php</a> - An example showing the basics of the helper api</li> +</ul> + +<p>Real Life Examples</p> +<ul> +<li><a href='login/index.php'>login/index.php</a> - An example creating an AJAX driven login</a></li> +</ul> + +<p> +2 server examples are provided +</p> +<ul> +<li>server.php - Basic server operation, serving ajax calls and client lib requests</li> +<li>auto_server.php - Advanced server operation, only create php classes as needed</li> +</ul> + +<p> +Other Example files: +</p> +<ul> +<li><a href='test_speed.php'>test_speed.php</a> - A basic setup for measuring the speed of calls</li> +<li><a href='serialize.examples.htm'>serialize.examples.htm/a> - Internal tests for the php serialize format serializer</li> +</ul> + +</body> +</html> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/livesearch.class.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/livesearch.class.php diff -u pear/HTML_AJAX/examples/livesearch.class.php:1.1 pear/HTML_AJAX/examples/livesearch.class.php:1.2 --- pear/HTML_AJAX/examples/livesearch.class.php:1.1 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/livesearch.class.php Mon Nov 7 13:43:49 2005 @@ -1,40 +1,40 @@ -<?php -/** - * Simple test class for doing fake livesearch - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -class livesearch { - /** - * Items to search against - */ - var $livesearch = array( - 'Orange', - 'Apple', - 'Pear', - 'Banana', - 'Blueberry', - ); - - /** - * Perform a search - * - * @return array - */ - function search($input) { - $ret = array(); - foreach($this->livesearch as $key => $value) { - if (stristr($value,$input)) { - $ret[$key] = $value; - } - } - return $ret; - } -} -?> +<?php +/** + * Simple test class for doing fake livesearch + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +class livesearch { + /** + * Items to search against + */ + var $livesearch = array( + 'Orange', + 'Apple', + 'Pear', + 'Banana', + 'Blueberry', + ); + + /** + * Perform a search + * + * @return array + */ + function search($input) { + $ret = array(); + foreach($this->livesearch as $key => $value) { + if (stristr($value,$input)) { + $ret[$key] = $value; + } + } + return $ret; + } +} +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php diff -u pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php:1.3 pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php:1.4 --- pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php:1.3 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/proxy_usage_inline_javascript.php Mon Nov 7 13:43:49 2005 @@ -1,155 +1,155 @@ -<?php -/** - * Example of Using HTML_AJAX in proxy operation - * - * All AJAX calls are handled by this same file and the proxy js is outputed in a js block directly in this script - * This is a use case very similar to Sajax (Sajax registers functions not objects) - * - * The only needed interaction is creation of a new object from the proxy defintion, all AJAX calls happen transparently from - * - * If you want to perform async calls a callback object must be passed to the constructor of the object - * - * The client JavaScript library is provided by server.php, you could also copy HTML_AJAX.js (all js files combined) or the seperate js files into your webroot - * from the PEAR data dir and src them directly - * - * This example also registers a custom error handler, without this handler errors float out of the app as an Exception - * - * An example debugging event listener is also shown - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - -// include the main HTML_AJAX class -include 'HTML/AJAX.php'; - -// our simple test class -include 'test.class.php'; - - - -// create an instance of HTML_AJAX -$ajax = new HTML_AJAX(); -// register an instance of the test class -$ajax->registerClass(new test()); - -// handle and ajax call, if one is made die, else continue processing -if ($ajax->handleRequest()) { - die(); -} -?><html> -<head> - -<!-- the entire client library can be retreived in one call using the all keyword, or each piece can be requested like below --> -<script type='text/javascript' src="server.php?client=Main"></script> -<script type='text/javascript' src="server.php?client=Dispatcher"></script> -<script type='text/javascript' src="server.php?client=HttpClient"></script> -<script type='text/javascript' src="server.php?client=Request"></script> -<script type='text/javascript' src="server.php?client=JSON"></script> -<script type='text/javascript' src="server.php?client=loading"></script> - -<script type='text/javascript'> -<?php - // generate proxy definition javascript for all registered class - echo $ajax->generateJavascriptClient(); -?> - -// definition of the callback javascript class, used to handle async requests -function callback() {} -callback.prototype = { - echo_string: function(result) { - document.getElementById('target').innerHTML = result; - }, - slow_echo_string: function(result) { - document.getElementById('target').innerHTML = result; - }, - error_test: function(result) { - document.getElementById('target').innerHTML = result; - } -} - -// function used to clear out the target div -function clearTarget() { - document.getElementById('target').innerHTML = 'clear'; - document.getElementById('eventLog').innerHTML = 'clear'; - document.getElementById('error').innerHTML = 'clear'; -} - -// register a custom error handler -HTML_AJAX.onError = function(e) { - msg = "\n\n"; - for(var i in e) { - msg += i + ':' + e[i] +"\n"; - } - document.getElementById('error').innerHTML += msg; -} - -// register custom event handlers, but lets keep the old ones so we still have that automatic loading message -var onOpen = HTML_AJAX.onOpen; -var onLoad = HTML_AJAX.onLoad; - -HTML_AJAX.onOpen = function(request) { - onOpen(); - document.getElementById('eventLog').innerHTML += "Open: "+request.className+'::'+request.methodName+"\n"; -} -HTML_AJAX.onSend = function(request) { - document.getElementById('eventLog').innerHTML += "Send: "+request.className+'::'+request.methodName+"\n"; -} -HTML_AJAX.onProgress = function(request) { - document.getElementById('eventLog').innerHTML += "Progress: "+request.className+'::'+request.methodName+"\n"; -} -HTML_AJAX.onLoad = function(request) { - onLoad(); - document.getElementById('eventLog').innerHTML += "Load: "+request.className+'::'+request.methodName+"\n"; -} - -</script> -</head> -<body> -<script type="text/javascript"> -// create a proxy in sync mode -var syncProxy = new test(); -// create a proxy in async mode -var asyncProxy = new test(new callback()); - -// run a sync call and set its results to the target div -function syncCall() { - document.getElementById('target').innerHTML = syncProxy.echo_string("I'm a sync call"); -} - -// run a sync call, callback class will handle its results -function asyncCall() { - asyncProxy.echo_string("I'm a async call"); -} - -// run a sync call, callback class will handle its results -// the purpose of this slow call is to show off the built in loading messaging -function slowAsyncCall() { - asyncProxy.slow_echo_string("I'm a slow async call"); -} - -// run a sync call, callback class will handle its results -function serverErrorExample() { - asyncProxy.error_test("I'm an error generated by trigger error in test.class.php"); -} -</script> -<ul> - <li><a href="javascript:clearTarget()">Clear Target</a></li> - <li><a href="javascript:syncCall()">Run Sync Echo call</a></li> - <li><a href="javascript:asyncCall();">Run Async Echo call</a></li> - <li><a href="javascript:slowAsyncCall();">Run Slow Async Echo call (sleep on server to emulate slow processing)</a></li> - <li><a href="javascript:serverErrorExample();">Run a call where an error is generated on the server</a></li> -</ul> -<div style="white-space: pre; padding: 1em; margin: 1em; width: 300px; height: 400px; border: solid 2px black; overflow: auto; float: right;" id="error">Error Target</div> - -<div style="white-space: pre; padding: 1em; margin: 1em; width: 500px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> - -<div style="white-space: pre; padding: 1em; margin: 1em; width: 500px; height: 400px; border: solid 2px black; overflow: auto;" id="eventLog">Event Log -</div> -</body> -</html> +<?php +/** + * Example of Using HTML_AJAX in proxy operation + * + * All AJAX calls are handled by this same file and the proxy js is outputed in a js block directly in this script + * This is a use case very similar to Sajax (Sajax registers functions not objects) + * + * The only needed interaction is creation of a new object from the proxy defintion, all AJAX calls happen transparently from + * + * If you want to perform async calls a callback object must be passed to the constructor of the object + * + * The client JavaScript library is provided by server.php, you could also copy HTML_AJAX.js (all js files combined) or the seperate js files into your webroot + * from the PEAR data dir and src them directly + * + * This example also registers a custom error handler, without this handler errors float out of the app as an Exception + * + * An example debugging event listener is also shown + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + +// include the main HTML_AJAX class +include 'HTML/AJAX.php'; + +// our simple test class +include 'test.class.php'; + + + +// create an instance of HTML_AJAX +$ajax = new HTML_AJAX(); +// register an instance of the test class +$ajax->registerClass(new test()); + +// handle and ajax call, if one is made die, else continue processing +if ($ajax->handleRequest()) { + die(); +} +?><html> +<head> + +<!-- the entire client library can be retreived in one call using the all keyword, or each piece can be requested like below --> +<script type='text/javascript' src="server.php?client=Main"></script> +<script type='text/javascript' src="server.php?client=Dispatcher"></script> +<script type='text/javascript' src="server.php?client=HttpClient"></script> +<script type='text/javascript' src="server.php?client=Request"></script> +<script type='text/javascript' src="server.php?client=JSON"></script> +<script type='text/javascript' src="server.php?client=loading"></script> + +<script type='text/javascript'> +<?php + // generate proxy definition javascript for all registered class + echo $ajax->generateJavascriptClient(); +?> + +// definition of the callback javascript class, used to handle async requests +function callback() {} +callback.prototype = { + echo_string: function(result) { + document.getElementById('target').innerHTML = result; + }, + slow_echo_string: function(result) { + document.getElementById('target').innerHTML = result; + }, + error_test: function(result) { + document.getElementById('target').innerHTML = result; + } +} + +// function used to clear out the target div +function clearTarget() { + document.getElementById('target').innerHTML = 'clear'; + document.getElementById('eventLog').innerHTML = 'clear'; + document.getElementById('error').innerHTML = 'clear'; +} + +// register a custom error handler +HTML_AJAX.onError = function(e) { + msg = "\n\n"; + for(var i in e) { + msg += i + ':' + e[i] +"\n"; + } + document.getElementById('error').innerHTML += msg; +} + +// register custom event handlers, but lets keep the old ones so we still have that automatic loading message +var onOpen = HTML_AJAX.onOpen; +var onLoad = HTML_AJAX.onLoad; + +HTML_AJAX.onOpen = function(request) { + onOpen(); + document.getElementById('eventLog').innerHTML += "Open: "+request.className+'::'+request.methodName+"\n"; +} +HTML_AJAX.onSend = function(request) { + document.getElementById('eventLog').innerHTML += "Send: "+request.className+'::'+request.methodName+"\n"; +} +HTML_AJAX.onProgress = function(request) { + document.getElementById('eventLog').innerHTML += "Progress: "+request.className+'::'+request.methodName+"\n"; +} +HTML_AJAX.onLoad = function(request) { + onLoad(); + document.getElementById('eventLog').innerHTML += "Load: "+request.className+'::'+request.methodName+"\n"; +} + +</script> +</head> +<body> +<script type="text/javascript"> +// create a proxy in sync mode +var syncProxy = new test(); +// create a proxy in async mode +var asyncProxy = new test(new callback()); + +// run a sync call and set its results to the target div +function syncCall() { + document.getElementById('target').innerHTML = syncProxy.echo_string("I'm a sync call"); +} + +// run a sync call, callback class will handle its results +function asyncCall() { + asyncProxy.echo_string("I'm a async call"); +} + +// run a sync call, callback class will handle its results +// the purpose of this slow call is to show off the built in loading messaging +function slowAsyncCall() { + asyncProxy.slow_echo_string("I'm a slow async call"); +} + +// run a sync call, callback class will handle its results +function serverErrorExample() { + asyncProxy.error_test("I'm an error generated by trigger error in test.class.php"); +} +</script> +<ul> + <li><a href="javascript:clearTarget()">Clear Target</a></li> + <li><a href="javascript:syncCall()">Run Sync Echo call</a></li> + <li><a href="javascript:asyncCall();">Run Async Echo call</a></li> + <li><a href="javascript:slowAsyncCall();">Run Slow Async Echo call (sleep on server to emulate slow processing)</a></li> + <li><a href="javascript:serverErrorExample();">Run a call where an error is generated on the server</a></li> +</ul> +<div style="white-space: pre; padding: 1em; margin: 1em; width: 300px; height: 400px; border: solid 2px black; overflow: auto; float: right;" id="error">Error Target</div> + +<div style="white-space: pre; padding: 1em; margin: 1em; width: 500px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> + +<div style="white-space: pre; padding: 1em; margin: 1em; width: 500px; height: 400px; border: solid 2px black; overflow: auto;" id="eventLog">Event Log +</div> +</body> +</html> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/proxy_usage_server.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/proxy_usage_server.php diff -u pear/HTML_AJAX/examples/proxy_usage_server.php:1.3 pear/HTML_AJAX/examples/proxy_usage_server.php:1.4 --- pear/HTML_AJAX/examples/proxy_usage_server.php:1.3 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/proxy_usage_server.php Mon Nov 7 13:43:49 2005 @@ -1,95 +1,95 @@ -<?php -/** - * Example of Using HTML_AJAX in proxy operation - * - * All AJAX calls are handled by the auto_server.php file, server.php could also be used, the differences between the two are covered in those files - * This is a use case very similar to JPSpan (JPSpan only has a server.php equivalent) - * - * The only needed interaction is creation of a new object from the proxy defintion, all AJAX calls happen transparently from there - * - * If you want to perform async calls a callback object must be passed to the constructor of the object - * - * The client JavaScript library is provided by auto_server.php, you could also copy HTML_AJAX.js (all js files combined) or the seperate js files into your webroot - * from the PEAR data dir and src them directly. You can use multiple includes of the component files or use the all flag to get them all at once. - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - -?><html> -<head> - -<!-- These two calls can be combined into one call if wanted, but its not recomended since it will hurt caching as you might want stubs of multiple classes --> -<script type='text/javascript' src="auto_server.php?client=all"></script> -<!-- Stub is passed the class you want the proxy definition for, you can also use all to get every registered class but that create those auto server - has to instanciate every class where here only the class used on this page has to be instanciated --> -<script type='text/javascript' src="auto_server.php?stub=test"></script> - -<script type='text/javascript'> -// definition of the callback javascript class, used to handle async requests -function callback() {} -callback.prototype = { - echo_string: function(result) { - document.getElementById('target').innerHTML = result; - }, - cookies: function(result) { - var ret = ""; - for(var i in result) { - ret += i+':'+result[i]+"\n"; - } - document.getElementById('target').innerHTML = ret; - } -} - -// function used to clear out the target div -function clearTarget() { - document.getElementById('target').innerHTML = 'clear'; -} -</script> -</head> -<body> -<script type="text/javascript"> -// create a proxy in sync mode -var syncProxy = new test(); -// create a proxy in async mode -var asyncProxy = new test(new callback()); - -// run a sync call and set its results to the target div -function syncCall() { - document.getElementById('target').innerHTML = syncProxy.echo_string("I'm a sync call"); -} - -// run a sync call, callback class will handle its results -function asyncCall() { - asyncProxy.echo_string("I'm a async call"); -} - -function cookieTest() { - asyncProxy.cookies(); -} -</script> -<ul> - <li><a href="javascript:clearTarget()">Clear Target</a></li> - <li><a href="javascript:syncCall()">Run Sync Echo call</a></li> - <li><a href="javascript:asyncCall();">Run Async Echo call</a></li> - <li><a href="javascript:cookieTest();">View Cookies</a></li> -</ul> - -<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> - -<div> -Runing view Cookies should show you these same cookies being returned by the AJAX call -<pre> -<?php - var_dump($_COOKIE); -?> -</pre> -</div> - -</body> -</html> +<?php +/** + * Example of Using HTML_AJAX in proxy operation + * + * All AJAX calls are handled by the auto_server.php file, server.php could also be used, the differences between the two are covered in those files + * This is a use case very similar to JPSpan (JPSpan only has a server.php equivalent) + * + * The only needed interaction is creation of a new object from the proxy defintion, all AJAX calls happen transparently from there + * + * If you want to perform async calls a callback object must be passed to the constructor of the object + * + * The client JavaScript library is provided by auto_server.php, you could also copy HTML_AJAX.js (all js files combined) or the seperate js files into your webroot + * from the PEAR data dir and src them directly. You can use multiple includes of the component files or use the all flag to get them all at once. + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + +?><html> +<head> + +<!-- These two calls can be combined into one call if wanted, but its not recomended since it will hurt caching as you might want stubs of multiple classes --> +<script type='text/javascript' src="auto_server.php?client=all"></script> +<!-- Stub is passed the class you want the proxy definition for, you can also use all to get every registered class but that create those auto server + has to instanciate every class where here only the class used on this page has to be instanciated --> +<script type='text/javascript' src="auto_server.php?stub=test"></script> + +<script type='text/javascript'> +// definition of the callback javascript class, used to handle async requests +function callback() {} +callback.prototype = { + echo_string: function(result) { + document.getElementById('target').innerHTML = result; + }, + cookies: function(result) { + var ret = ""; + for(var i in result) { + ret += i+':'+result[i]+"\n"; + } + document.getElementById('target').innerHTML = ret; + } +} + +// function used to clear out the target div +function clearTarget() { + document.getElementById('target').innerHTML = 'clear'; +} +</script> +</head> +<body> +<script type="text/javascript"> +// create a proxy in sync mode +var syncProxy = new test(); +// create a proxy in async mode +var asyncProxy = new test(new callback()); + +// run a sync call and set its results to the target div +function syncCall() { + document.getElementById('target').innerHTML = syncProxy.echo_string("I'm a sync call"); +} + +// run a sync call, callback class will handle its results +function asyncCall() { + asyncProxy.echo_string("I'm a async call"); +} + +function cookieTest() { + asyncProxy.cookies(); +} +</script> +<ul> + <li><a href="javascript:clearTarget()">Clear Target</a></li> + <li><a href="javascript:syncCall()">Run Sync Echo call</a></li> + <li><a href="javascript:asyncCall();">Run Async Echo call</a></li> + <li><a href="javascript:cookieTest();">View Cookies</a></li> +</ul> + +<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> + +<div> +Runing view Cookies should show you these same cookies being returned by the AJAX call +<pre> +<?php + var_dump($_COOKIE); +?> +</pre> +</div> + +</body> +</html> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/proxyless_usage.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/proxyless_usage.php diff -u pear/HTML_AJAX/examples/proxyless_usage.php:1.3 pear/HTML_AJAX/examples/proxyless_usage.php:1.4 --- pear/HTML_AJAX/examples/proxyless_usage.php:1.3 Mon Oct 24 23:27:41 2005 +++ pear/HTML_AJAX/examples/proxyless_usage.php Mon Nov 7 13:43:49 2005 @@ -1,128 +1,128 @@ -<?php -/** - * Example of Using HTML_AJAX in proxyless operation - * - * This is the simplest way to use HTML_AJAX if your just using grab and replace functions you don't even need a server - * You need every javascript file except JSON which is optional and is only needed if your using that encoding - * - * The proxyless api is provided by Main.js - * - * There are 3 main methods and 2 properties to the proxyless api, they all exist as static methods on HTML_AJAX - * HTML_AJAX.grab(url) - * HTML_AJAX.replace(id,url) or HTML_AJAX.replace(id,class,method,arg1,arg2,etc) - * HTML_AJAX.call(class,method,callback,arg1,arg2,etc) - * - * HTML_AJAX.defaultServerUrl = 'serverurl'; - * HTML_AJAX.defaultEncoding = 'Null'; - * - * The api is demonstrated below, server.php is used for call examples and to load the needed js files - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -?> -<html> -<head> - -<script type='text/javascript' src="server.php?client=Util"></script> -<script type='text/javascript' src="server.php?client=main"></script> -<script type='text/javascript' src="server.php?client=dispatcher"></script> -<script type='text/javascript' src="server.php?client=HttpClient"></script> -<script type='text/javascript' src="server.php?client=Request"></script> -<script type='text/javascript' src="server.php?client=json"></script> -<script type='text/javascript' src="server.php?client=loading"></script> - -</head> -<body> -<script type="text/javascript"> -function clearTarget() { - document.getElementById('target').innerHTML = 'clear'; -} - -// Add an error handler so we get an alert if any errors happen while making an AJAX call -HTML_AJAX.onError = function(e) -{ - alert(HTML_AJAX_Util.varDump(e)); -} - - -// Grab is the simplest usage of HTML_AJAX you use it to perform a request to a page and get its results back -// It can be used in either Sync mode where it returns directory or with a call back, both methods are shown below -var url = 'README'; -function grabSync() { - document.getElementById('target').innerHTML = HTML_AJAX.grab(url); -} - -function grabAsync() { - HTML_AJAX.grab(url,grabCallback); -} - -function grabCallback(result) { - document.getElementById('target').innerHTML = result; -} - - -// replace can operate either against a url like grab or against a remote method -// if its going to be used against a remote method defaultServerUrl needs to be set to a url that is exporting the class its trying to call -// note that replace replace always works async - -HTML_AJAX.defaultServerUrl = 'server.php'; - -function replaceUrl() { - HTML_AJAX.replace('target',url); -} - -function replaceFromMethod() { - HTML_AJAX.replace('target','test','echo_string','Im a method call replacement'); -} -function replaceFromMethodMulti() { - // Null encoding does not support multiple arguments, you have to use JSON for that - HTML_AJAX.defaultEncoding = 'JSON'; // set encoding to JSON encoding method - HTML_AJAX.replace('target','test','multiarg','argument1','argument2','argument3'); - HTML_AJAX.defaultEncoding = 'Null'; // return it to default which is Null -} - - -// call is used to call a method on a remote server -// you need to set HTML_AJAX.defaultServerUrl to use it -// you might also want to set HTML_AJAX.defaultEncoding, options are Null and JSON, the server will autodetect this encoding from your content type -// but the return content type will be based on whatever the servers settings are -// You can use call in either Sync or Async mode depending on if you pass it a callback function - -function callSync() { - HTML_AJAX.defaultEncoding = 'JSON'; // set encoding to JSON encoding method - document.getElementById('target').innerHTML = HTML_AJAX.call('test','echo_string',false,'Im text that was echoed'); - HTML_AJAX.defaultEncoding = 'Null'; // return it to default which is Null -} - -function callAsync() { - HTML_AJAX.call('test','echo_string',callCallback,'Im text that was echoed Async'); -} - -function callCallback(result) { - document.getElementById('target').innerHTML = result; -} - -</script> -<ul> - <li><a href="javascript:clearTarget()">Clear Target</a></li> - <li><a href="javascript:grabSync()">Run Sync Grab Example</a></li> - <li><a href="javascript:grabAsync()">Run Async Grab Example</a></li> - <li><a href="javascript:replaceUrl()">Replace with content from a url</a></li> - <li><a href="javascript:replaceFromMethod()">Replace with content from a method call</a></li> - <li><a href="javascript:replaceFromMethodMulti()">Replace with content from a method call (multiple method arguments)</a></li> - <li><a href="javascript:callSync()">Sync Call</a></li> - <li><a href="javascript:callAsync()">ASync Call</a></li> -</ul> - -<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> -</body> -</html> -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ -?> +<?php +/** + * Example of Using HTML_AJAX in proxyless operation + * + * This is the simplest way to use HTML_AJAX if your just using grab and replace functions you don't even need a server + * You need every javascript file except JSON which is optional and is only needed if your using that encoding + * + * The proxyless api is provided by Main.js + * + * There are 3 main methods and 2 properties to the proxyless api, they all exist as static methods on HTML_AJAX + * HTML_AJAX.grab(url) + * HTML_AJAX.replace(id,url) or HTML_AJAX.replace(id,class,method,arg1,arg2,etc) + * HTML_AJAX.call(class,method,callback,arg1,arg2,etc) + * + * HTML_AJAX.defaultServerUrl = 'serverurl'; + * HTML_AJAX.defaultEncoding = 'Null'; + * + * The api is demonstrated below, server.php is used for call examples and to load the needed js files + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +?> +<html> +<head> + +<script type='text/javascript' src="server.php?client=Util"></script> +<script type='text/javascript' src="server.php?client=main"></script> +<script type='text/javascript' src="server.php?client=dispatcher"></script> +<script type='text/javascript' src="server.php?client=HttpClient"></script> +<script type='text/javascript' src="server.php?client=Request"></script> +<script type='text/javascript' src="server.php?client=json"></script> +<script type='text/javascript' src="server.php?client=loading"></script> + +</head> +<body> +<script type="text/javascript"> +function clearTarget() { + document.getElementById('target').innerHTML = 'clear'; +} + +// Add an error handler so we get an alert if any errors happen while making an AJAX call +HTML_AJAX.onError = function(e) +{ + alert(HTML_AJAX_Util.varDump(e)); +} + + +// Grab is the simplest usage of HTML_AJAX you use it to perform a request to a page and get its results back +// It can be used in either Sync mode where it returns directory or with a call back, both methods are shown below +var url = 'README'; +function grabSync() { + document.getElementById('target').innerHTML = HTML_AJAX.grab(url); +} + +function grabAsync() { + HTML_AJAX.grab(url,grabCallback); +} + +function grabCallback(result) { + document.getElementById('target').innerHTML = result; +} + + +// replace can operate either against a url like grab or against a remote method +// if its going to be used against a remote method defaultServerUrl needs to be set to a url that is exporting the class its trying to call +// note that replace replace always works async + +HTML_AJAX.defaultServerUrl = 'server.php'; + +function replaceUrl() { + HTML_AJAX.replace('target',url); +} + +function replaceFromMethod() { + HTML_AJAX.replace('target','test','echo_string','Im a method call replacement'); +} +function replaceFromMethodMulti() { + // Null encoding does not support multiple arguments, you have to use JSON for that + HTML_AJAX.defaultEncoding = 'JSON'; // set encoding to JSON encoding method + HTML_AJAX.replace('target','test','multiarg','argument1','argument2','argument3'); + HTML_AJAX.defaultEncoding = 'Null'; // return it to default which is Null +} + + +// call is used to call a method on a remote server +// you need to set HTML_AJAX.defaultServerUrl to use it +// you might also want to set HTML_AJAX.defaultEncoding, options are Null and JSON, the server will autodetect this encoding from your content type +// but the return content type will be based on whatever the servers settings are +// You can use call in either Sync or Async mode depending on if you pass it a callback function + +function callSync() { + HTML_AJAX.defaultEncoding = 'JSON'; // set encoding to JSON encoding method + document.getElementById('target').innerHTML = HTML_AJAX.call('test','echo_string',false,'Im text that was echoed'); + HTML_AJAX.defaultEncoding = 'Null'; // return it to default which is Null +} + +function callAsync() { + HTML_AJAX.call('test','echo_string',callCallback,'Im text that was echoed Async'); +} + +function callCallback(result) { + document.getElementById('target').innerHTML = result; +} + +</script> +<ul> + <li><a href="javascript:clearTarget()">Clear Target</a></li> + <li><a href="javascript:grabSync()">Run Sync Grab Example</a></li> + <li><a href="javascript:grabAsync()">Run Async Grab Example</a></li> + <li><a href="javascript:replaceUrl()">Replace with content from a url</a></li> + <li><a href="javascript:replaceFromMethod()">Replace with content from a method call</a></li> + <li><a href="javascript:replaceFromMethodMulti()">Replace with content from a method call (multiple method arguments)</a></li> + <li><a href="javascript:callSync()">Sync Call</a></li> + <li><a href="javascript:callAsync()">ASync Call</a></li> +</ul> + +<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> +</body> +</html> +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/queue_usage.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/queue_usage.php diff -u pear/HTML_AJAX/examples/queue_usage.php:1.1 pear/HTML_AJAX/examples/queue_usage.php:1.2 --- pear/HTML_AJAX/examples/queue_usage.php:1.1 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/queue_usage.php Mon Nov 7 13:43:49 2005 @@ -1,76 +1,76 @@ -<?php -/** - * Example of Using HTML_AJAX with a queue - * - * When using HTML_AJAX your actually always using a queue, its just its a simple one that always performs whatever actions its given immediately - * HTML_AJAX however provides other queues offering different modes of operation - * - * Currently the Queues are (class names are prefixed with: HTML_AJAX_Queue_): - * Immediate - Default make the request immediately - * Interval_SingleBuffer - Make request on an interval with holding just the last request between calls - * - * Interval_SingleBuffer is generally used for Live Search/Google Suggest type operations - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -?> -<html> -<head> - -<script type='text/javascript' src="server.php?client=Util,main,dispatcher,httpclient,request,json,loading"></script> -<script type='text/javascript' src="auto_server.php?stub=livesearch"></script> - -</head> -<body> -<script type="text/javascript"> - -// callback hash, outputs the results of the search method -callback = { - search: function(result) { - var out = "<ul>"; - - // if we have object this works right, if we have an array we get a problem - // if we have sparse keys will get an array back otherwise will get an array - for(var i in result) { - if (i != '______array') { - out += "<li>"+i+" = "+result[i]+"</li>"; - } - } - out += "</ul>"; - document.getElementById('target').innerHTML = out; - } -} - -// setup our remote object from the generated proxy stub -var remoteLiveSearch = new livesearch(callback); - -// we could change the queue by overriding the default one, but generally you want to create a new one -// set our remote object to use the rls queue -remoteLiveSearch.dispatcher.queue = 'rls'; - -// create the rls queue, with a 350ms buffer, a larger interval such as 2000 is useful to see what is happening but not so useful in real life -HTML_AJAX.queues['rls'] = new HTML_AJAX_Queue_Interval_SingleBuffer(350); - - -// what to call on onkeyup, you might want some logic here to not search on empty strings or to do something else in those cases -function searchRequest(searchBox) { - remoteLiveSearch.search(searchBox.value); -} -</script> - -<p>This is a really basic LiveSearch example, type in the box below to find a fruit</p> - -Search <input id="search" autocomplete="off" onkeyup="searchRequest(this)"> - -<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> -</body> -</html> -<?php -/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ -?> +<?php +/** + * Example of Using HTML_AJAX with a queue + * + * When using HTML_AJAX your actually always using a queue, its just its a simple one that always performs whatever actions its given immediately + * HTML_AJAX however provides other queues offering different modes of operation + * + * Currently the Queues are (class names are prefixed with: HTML_AJAX_Queue_): + * Immediate - Default make the request immediately + * Interval_SingleBuffer - Make request on an interval with holding just the last request between calls + * + * Interval_SingleBuffer is generally used for Live Search/Google Suggest type operations + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +?> +<html> +<head> + +<script type='text/javascript' src="server.php?client=Util,main,dispatcher,httpclient,request,json,loading"></script> +<script type='text/javascript' src="auto_server.php?stub=livesearch"></script> + +</head> +<body> +<script type="text/javascript"> + +// callback hash, outputs the results of the search method +callback = { + search: function(result) { + var out = "<ul>"; + + // if we have object this works right, if we have an array we get a problem + // if we have sparse keys will get an array back otherwise will get an array + for(var i in result) { + if (i != '______array') { + out += "<li>"+i+" = "+result[i]+"</li>"; + } + } + out += "</ul>"; + document.getElementById('target').innerHTML = out; + } +} + +// setup our remote object from the generated proxy stub +var remoteLiveSearch = new livesearch(callback); + +// we could change the queue by overriding the default one, but generally you want to create a new one +// set our remote object to use the rls queue +remoteLiveSearch.dispatcher.queue = 'rls'; + +// create the rls queue, with a 350ms buffer, a larger interval such as 2000 is useful to see what is happening but not so useful in real life +HTML_AJAX.queues['rls'] = new HTML_AJAX_Queue_Interval_SingleBuffer(350); + + +// what to call on onkeyup, you might want some logic here to not search on empty strings or to do something else in those cases +function searchRequest(searchBox) { + remoteLiveSearch.search(searchBox.value); +} +</script> + +<p>This is a really basic LiveSearch example, type in the box below to find a fruit</p> + +Search <input id="search" autocomplete="off" onkeyup="searchRequest(this)"> + +<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div> +</body> +</html> +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/serialize.examples.htm?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/serialize.examples.htm diff -u pear/HTML_AJAX/examples/serialize.examples.htm:1.1 pear/HTML_AJAX/examples/serialize.examples.htm:1.2 --- pear/HTML_AJAX/examples/serialize.examples.htm:1.1 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/serialize.examples.htm Mon Nov 7 13:43:49 2005 @@ -1,381 +1,381 @@ -<script type="text/javascript" src="serialize.js"></script> -<script type="text/javascript"> - -function describe(inp) -{ - var type = gettype(inp); - var ctype; - var out = "Type: " + type + "\nContents: "; - switch (type) { - case "string": - case "number": - out += inp; - break; - case "boolean": - out += (inp ? 'true' : 'false'); - break; - case "array": - case "object": - for (k in inp) { - out += k + " => "; - ctype = gettype(inp[k]); - out += (ctype == "array" || ctype == "object" ? describe(inp[k]) : inp[k]) + "\n"; - } - } - return out; -} - -unserializer = new Unserializer; - -</script> -<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1><strong>PHP Code:</strong> -<pre>$foo = null;</pre> -<strong>PHP value:</strong><pre> -NULL -</pre> -<strong>Serialized in PHP:</strong> -<pre>N;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("N%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = true;</pre> -<strong>PHP value:</strong><pre> -bool(true) -</pre> -<strong>Serialized in PHP:</strong> -<pre>b:1;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("b%3A1%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = "foobar";</pre> -<strong>PHP value:</strong><pre> -string(6) "foobar" -</pre> -<strong>Serialized in PHP:</strong> -<pre>s:6:"foobar";</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foobar%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = 337;</pre> -<strong>PHP value:</strong><pre> -int(337) -</pre> -<strong>Serialized in PHP:</strong> -<pre>i:337;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("i%3A337%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = 99.99;</pre> -<strong>PHP value:</strong><pre> -float(99.99) -</pre> -<strong>Serialized in PHP:</strong> -<pre>d:99.9899999999999948840923025272786617279052734375;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("d%3A99.9899999999999948840923025272786617279052734375%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = array("a" => 1, "b" => 2, 3);</pre> -<strong>PHP value:</strong><pre> -array(3) { - ["a"]=> - int(1) - ["b"]=> - int(2) - [0]=> - int(3) -} -</pre> -<strong>Serialized in PHP:</strong> -<pre>a:3:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bs%3A1%3A%22a%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>$foo = array(1,2,array(1,2,3));</pre> -<strong>PHP value:</strong><pre> -array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} -</pre> -<strong>Serialized in PHP:</strong> -<pre>a:3:{i:0;i:1;i:1;i:2;i:2;a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bi%3A0%3Bi%3A1%3Bi%3A1%3Bi%3A2%3Bi%3A2%3Ba%3A3%3A%7Bi%3A0%3Bi%3A1%3Bi%3A1%3Bi%3A2%3Bi%3A2%3Bi%3A3%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<strong>PHP Code:</strong> -<pre>class Foo { var $foo; var $bar; }$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");</pre> -<strong>PHP value:</strong><pre> -object(Foo)#1 (2) { - ["foo"]=> - string(5) "hello" - ["bar"]=> - array(2) { - [0]=> - string(5) "world" - [1]=> - string(8) "universe" - } -} -</pre> -<strong>Serialized in PHP:</strong> -<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> -</pre> -<hr /> - -<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1></pre> -<strong>Invalidly serialized:</strong> -<pre>x</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("x"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>x:1</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("x%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>N</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("N"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>Nx</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("Nx"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>b:f;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("b%3Af%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>b:1</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("b%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>i:foo;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("i%3Afoo%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>i:1</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("i%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>d:foo;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("d%3Afoo%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>d:1.1.1;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("d%3A1.1.1%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>d:1.1</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("d%3A1.1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>s:6:"foo";</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foo%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>s:6:"foofoo"</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foofoo%22"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>s:1:"foo";</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("s%3A1%3A%22foo%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>s:0:""</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("s%3A0%3A%22%22"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>a:3:{s:1:"aa";i:1;s:1:"b";i:2;i:0;i:3;}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bs%3A1%3A%22aa%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>a:4:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A4%3A%7Bs%3A1%3A%22a%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>a:3:{i:1;s:1:"b";i:2;i:0;i:3;}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>a:3:{}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>O:3:"Fooo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Fooo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>O:3:"Foo":3:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A3%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>O:3:"Foo":2:{s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - -</pre> -<strong>Invalidly serialized:</strong> -<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe"}}</pre> -<strong>Unserialized in JS:</strong> -<pre> -<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> -</pre> -<hr /> - +<script type="text/javascript" src="server.php?client=phpserializer"></script> +<script type="text/javascript"> + +function describe(inp) +{ + var type = gettype(inp); + var ctype; + var out = "Type: " + type + "\nContents: "; + switch (type) { + case "string": + case "number": + out += inp; + break; + case "boolean": + out += (inp ? 'true' : 'false'); + break; + case "array": + case "object": + for (k in inp) { + out += k + " => "; + ctype = gettype(inp[k]); + out += (ctype == "array" || ctype == "object" ? describe(inp[k]) : inp[k]) + "\n"; + } + } + return out; +} + +unserializer = new Unserializer; + +</script> +<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1><strong>PHP Code:</strong> +<pre>$foo = null;</pre> +<strong>PHP value:</strong><pre> +NULL +</pre> +<strong>Serialized in PHP:</strong> +<pre>N;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("N%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = true;</pre> +<strong>PHP value:</strong><pre> +bool(true) +</pre> +<strong>Serialized in PHP:</strong> +<pre>b:1;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("b%3A1%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = "foobar";</pre> +<strong>PHP value:</strong><pre> +string(6) "foobar" +</pre> +<strong>Serialized in PHP:</strong> +<pre>s:6:"foobar";</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foobar%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = 337;</pre> +<strong>PHP value:</strong><pre> +int(337) +</pre> +<strong>Serialized in PHP:</strong> +<pre>i:337;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("i%3A337%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = 99.99;</pre> +<strong>PHP value:</strong><pre> +float(99.99) +</pre> +<strong>Serialized in PHP:</strong> +<pre>d:99.9899999999999948840923025272786617279052734375;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("d%3A99.9899999999999948840923025272786617279052734375%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = array("a" => 1, "b" => 2, 3);</pre> +<strong>PHP value:</strong><pre> +array(3) { + ["a"]=> + int(1) + ["b"]=> + int(2) + [0]=> + int(3) +} +</pre> +<strong>Serialized in PHP:</strong> +<pre>a:3:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bs%3A1%3A%22a%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>$foo = array(1,2,array(1,2,3));</pre> +<strong>PHP value:</strong><pre> +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +</pre> +<strong>Serialized in PHP:</strong> +<pre>a:3:{i:0;i:1;i:1;i:2;i:2;a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bi%3A0%3Bi%3A1%3Bi%3A1%3Bi%3A2%3Bi%3A2%3Ba%3A3%3A%7Bi%3A0%3Bi%3A1%3Bi%3A1%3Bi%3A2%3Bi%3A2%3Bi%3A3%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<strong>PHP Code:</strong> +<pre>class Foo { var $foo; var $bar; }$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");</pre> +<strong>PHP value:</strong><pre> +object(Foo)#1 (2) { + ["foo"]=> + string(5) "hello" + ["bar"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(8) "universe" + } +} +</pre> +<strong>Serialized in PHP:</strong> +<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + "</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));</script> +</pre> +<hr /> + +<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1></pre> +<strong>Invalidly serialized:</strong> +<pre>x</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("x"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>x:1</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("x%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>N</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("N"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>Nx</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("Nx"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>b:f;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("b%3Af%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>b:1</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("b%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>i:foo;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("i%3Afoo%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>i:1</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("i%3A1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>d:foo;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("d%3Afoo%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>d:1.1.1;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("d%3A1.1.1%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>d:1.1</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("d%3A1.1"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>s:6:"foo";</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foo%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>s:6:"foofoo"</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("s%3A6%3A%22foofoo%22"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>s:1:"foo";</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("s%3A1%3A%22foo%22%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>s:0:""</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("s%3A0%3A%22%22"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>a:3:{s:1:"aa";i:1;s:1:"b";i:2;i:0;i:3;}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bs%3A1%3A%22aa%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>a:4:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A4%3A%7Bs%3A1%3A%22a%22%3Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>a:3:{i:1;s:1:"b";i:2;i:0;i:3;}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7Bi%3A1%3Bs%3A1%3A%22b%22%3Bi%3A2%3Bi%3A0%3Bi%3A3%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>a:3:{}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("a%3A3%3A%7B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>O:3:"Fooo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Fooo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>O:3:"Foo":3:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A3%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>O:3:"Foo":2:{s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%3B%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + +</pre> +<strong>Invalidly serialized:</strong> +<pre>O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe"}}</pre> +<strong>Unserialized in JS:</strong> +<pre> +<script type="text/javascript">var sfoo = unescape("O%3A3%3A%22Foo%22%3A2%3A%7Bs%3A3%3A%22foo%22%3Bs%3A5%3A%22hello%22%3Bs%3A3%3A%22bar%22%3Ba%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22world%22%3Bi%3A1%3Bs%3A8%3A%22universe%22%7D%7D"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));</script> +</pre> +<hr /> + http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/serialize.examples.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/serialize.examples.php diff -u pear/HTML_AJAX/examples/serialize.examples.php:1.1 pear/HTML_AJAX/examples/serialize.examples.php:1.2 --- pear/HTML_AJAX/examples/serialize.examples.php:1.1 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/serialize.examples.php Mon Nov 7 13:43:49 2005 @@ -1,98 +1,98 @@ -<script type="text/javascript" src="serialize.js"></script> -<script type="text/javascript"> - -function describe(inp) -{ - var type = gettype(inp); - var ctype; - var out = "Type: " + type + "\nContents: "; - switch (type) { - case "string": - case "number": - out += inp; - break; - case "boolean": - out += (inp ? 'true' : 'false'); - break; - case "array": - case "object": - for (k in inp) { - out += k + " => "; - ctype = gettype(inp[k]); - out += (ctype == "array" || ctype == "object" ? describe(inp[k]) : inp[k]) + "\n"; - } - } - return out; -} - -unserializer = new Unserializer; - -</script> -<?php - -$examples = array( - '$foo = null;', - '$foo = true;', - '$foo = "foobar";', - '$foo = 337;', - '$foo = 99.99;', - '$foo = array("a" => 1, "b" => 2, 3);', - '$foo = array(1,2,array(1,2,3));', - 'class Foo { var $foo; var $bar; }' - . '$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");' -); - -echo '<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1>'; -$c = count($examples); -for ($i = 0; $i < $c; $i++) { - echo "<strong>PHP Code:</strong>\n<pre>$examples[$i]</pre>\n<strong>PHP value:</strong><pre>\n"; - eval($examples[$i]); - var_dump($foo); - $sfoo = serialize($foo); - echo "</pre>\n<strong>Serialized in PHP:</strong>\n<pre>", $sfoo, "</pre>\n", - "<strong>Unserialized in JS:</strong>\n<pre>\n", - '<script type="text/javascript">', - 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {', - 'document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + ', - '"</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));', "</script>\n</pre>\n<hr />\n\n"; -} - -$bad_examples = array( - 'x', - 'x:1', - 'N', - 'Nx', - 'b:f;', - 'b:1', - 'i:foo;', - 'i:1', - 'd:foo;', - 'd:1.1.1;', - 'd:1.1', - 's:6:"foo";', - 's:6:"foofoo"', - 's:1:"foo";', - 's:0:""', - 'a:3:{s:1:"aa";i:1;s:1:"b";i:2;i:0;i:3;}', - 'a:4:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;', - 'a:3:{i:1;s:1:"b";i:2;i:0;i:3;}', - 'a:3:{}', - 'O:3:"Fooo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', - 'O:3:"Foo":3:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', - 'O:3:"Foo":2:{s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', - 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}', - 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe"}}' -); - -echo '<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1>'; -foreach ($bad_examples as $sfoo) { - echo "</pre>\n<strong>Invalidly serialized:</strong>\n<pre>", $sfoo, "</pre>\n", - "<strong>Unserialized in JS:</strong>\n<pre>\n", - '<script type="text/javascript">', - 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {', - 'document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));', - "</script>\n</pre>\n<hr />\n\n"; -} - - -?> +<script type="text/javascript" src="serialize.js"></script> +<script type="text/javascript"> + +function describe(inp) +{ + var type = gettype(inp); + var ctype; + var out = "Type: " + type + "\nContents: "; + switch (type) { + case "string": + case "number": + out += inp; + break; + case "boolean": + out += (inp ? 'true' : 'false'); + break; + case "array": + case "object": + for (k in inp) { + out += k + " => "; + ctype = gettype(inp[k]); + out += (ctype == "array" || ctype == "object" ? describe(inp[k]) : inp[k]) + "\n"; + } + } + return out; +} + +unserializer = new Unserializer; + +</script> +<?php + +$examples = array( + '$foo = null;', + '$foo = true;', + '$foo = "foobar";', + '$foo = 337;', + '$foo = 99.99;', + '$foo = array("a" => 1, "b" => 2, 3);', + '$foo = array(1,2,array(1,2,3));', + 'class Foo { var $foo; var $bar; }' + . '$foo = new Foo; $foo->foo = "hello"; $foo->bar = array("world","universe");' +); + +echo '<h1><a name="pos">Positives</a> | <a href="#neg">Negatives</a></h1>'; +$c = count($examples); +for ($i = 0; $i < $c; $i++) { + echo "<strong>PHP Code:</strong>\n<pre>$examples[$i]</pre>\n<strong>PHP value:</strong><pre>\n"; + eval($examples[$i]); + var_dump($foo); + $sfoo = serialize($foo); + echo "</pre>\n<strong>Serialized in PHP:</strong>\n<pre>", $sfoo, "</pre>\n", + "<strong>Unserialized in JS:</strong>\n<pre>\n", + '<script type="text/javascript">', + 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {', + 'document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo) + ', + '"</pre>\n<strong>Serialized in JS:</strong>\n<pre>" + serialize(usfoo));', "</script>\n</pre>\n<hr />\n\n"; +} + +$bad_examples = array( + 'x', + 'x:1', + 'N', + 'Nx', + 'b:f;', + 'b:1', + 'i:foo;', + 'i:1', + 'd:foo;', + 'd:1.1.1;', + 'd:1.1', + 's:6:"foo";', + 's:6:"foofoo"', + 's:1:"foo";', + 's:0:""', + 'a:3:{s:1:"aa";i:1;s:1:"b";i:2;i:0;i:3;}', + 'a:4:{s:1:"a";i:1;s:1:"b";i:2;i:0;i:3;', + 'a:3:{i:1;s:1:"b";i:2;i:0;i:3;}', + 'a:3:{}', + 'O:3:"Fooo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', + 'O:3:"Foo":3:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', + 'O:3:"Foo":2:{s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}}', + 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe";}', + 'O:3:"Foo":2:{s:3:"foo";s:5:"hello";s:3:"bar";a:2:{i:0;s:5:"world";i:1;s:8:"universe"}}' +); + +echo '<h1><a href="#pos">Positives</a> | <a name="neg">Negatives</a></h1>'; +foreach ($bad_examples as $sfoo) { + echo "</pre>\n<strong>Invalidly serialized:</strong>\n<pre>", $sfoo, "</pre>\n", + "<strong>Unserialized in JS:</strong>\n<pre>\n", + '<script type="text/javascript">', + 'var sfoo = unescape("', urlencode($sfoo), '"); var usfoo = unserializer.unserialize(sfoo); if (unserializer.error) {', + 'document.write("Error: " + unserializer.getError() + "\n"); } document.write(describe(usfoo));', + "</script>\n</pre>\n<hr />\n\n"; +} + + +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/server.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/server.php diff -u pear/HTML_AJAX/examples/server.php:1.3 pear/HTML_AJAX/examples/server.php:1.4 --- pear/HTML_AJAX/examples/server.php:1.3 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/server.php Mon Nov 7 13:43:49 2005 @@ -1,35 +1,35 @@ -<?php -/** - * Simplest possible usage of HTML_AJAX_Server - * - * The server responds to ajax calls and also serves the js client libraries, so they can be used directly from the PEAR data dir - * 304 not modified headers are used when server client libraries so they will be cached on the browser reducing overhead - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - - // include the server class -include 'HTML/AJAX/Server.php'; - -// include the test class will be registering - include 'test.class.php'; - -// create our new server -$server = new HTML_AJAX_Server(); - -// register an instance of the class were registering -$test =& new test(); -$server->registerClass($test); - -// handle different types of requests possiblities are -// ?client=all - request for all javascript client files -// ?stub=classname - request for proxy stub for given class, can be combined with client but this may hurt caching unless stub=all is used -// ?c=classname&m=method - an ajax call, server handles serialization and handing things off to the proper method then returning the results -$server->handleRequest(); -?> +<?php +/** + * Simplest possible usage of HTML_AJAX_Server + * + * The server responds to ajax calls and also serves the js client libraries, so they can be used directly from the PEAR data dir + * 304 not modified headers are used when server client libraries so they will be cached on the browser reducing overhead + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + + // include the server class +include 'HTML/AJAX/Server.php'; + +// include the test class will be registering + include 'test.class.php'; + +// create our new server +$server = new HTML_AJAX_Server(); + +// register an instance of the class were registering +$test =& new test(); +$server->registerClass($test); + +// handle different types of requests possiblities are +// ?client=all - request for all javascript client files +// ?stub=classname - request for proxy stub for given class, can be combined with client but this may hurt caching unless stub=all is used +// ?c=classname&m=method - an ajax call, server handles serialization and handing things off to the proper method then returning the results +$server->handleRequest(); +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/test.class.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/test.class.php diff -u pear/HTML_AJAX/examples/test.class.php:1.3 pear/HTML_AJAX/examples/test.class.php:1.4 --- pear/HTML_AJAX/examples/test.class.php:1.3 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/test.class.php Mon Nov 7 13:43:49 2005 @@ -1,45 +1,45 @@ -<?php -/** - * Test class used in other examples - * Constructors and private methods marked with _ are never exported in proxies to JavaScript - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -class test { - function test() { - } - function _private() { - } - function echo_string($string) { - return "From PHP: ".$string; - } - function slow_echo_string($string) { - sleep(2); - return "From PHP: ".$string; - } - function error_test($string) { - trigger_error($string); - } - function multiarg() { - $args = func_get_args(); - return "passed in ".count($args)." args ".implode('|',$args); - } - function cookies() { - return $_COOKIE; - } -} - -if (isset($_GET['TEST_CLASS'])) { - $t = new test(); - var_dump($t->echo_string('test string')); - var_dump($t->slow_echo_string('test string')); - var_dump($t->error_test('test string')); - var_dump($t->multiarg('arg1','arg2','arg3')); -} -?> +<?php +/** + * Test class used in other examples + * Constructors and private methods marked with _ are never exported in proxies to JavaScript + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +class test { + function test() { + } + function _private() { + } + function echo_string($string) { + return "From PHP: ".$string; + } + function slow_echo_string($string) { + sleep(2); + return "From PHP: ".$string; + } + function error_test($string) { + trigger_error($string); + } + function multiarg() { + $args = func_get_args(); + return "passed in ".count($args)." args ".implode('|',$args); + } + function cookies() { + return $_COOKIE; + } +} + +if (isset($_GET['TEST_CLASS'])) { + $t = new test(); + var_dump($t->echo_string('test string')); + var_dump($t->slow_echo_string('test string')); + var_dump($t->error_test('test string')); + var_dump($t->multiarg('arg1','arg2','arg3')); +} +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/test.html?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/test.html diff -u pear/HTML_AJAX/examples/test.html:1.1 pear/HTML_AJAX/examples/test.html:1.2 --- pear/HTML_AJAX/examples/test.html:1.1 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/test.html Mon Nov 7 13:43:49 2005 @@ -1,55 +1,55 @@ -<!DOCTYPE html -PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" -"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> - <title> - How to use behavior.js - </title> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> - <script src="cssQuery-p.js" type="text/javascript"></script> - <script src="behavior.js" type="text/javascript"></script> -<script type="text/javascript"> -Behavior.register( - ".alert", - function(element) { - element.onclick = function(){ - alert('I alert on click'); - } - } - ); - - Behavior.register( - ".annoy", - function(element) { - element.onmouseout = function(){ - alert('I alert on mouseout, very annoying'); - } - } - ); - - Behavior.register( - ".red", - function(element) { - element.onmouseover = function(){ - element.style.backgroundColor = 'red'; - } - } - ); -</script> -</head> - -<body> - <div style="border: 1px solid black; width: 50%; margin: 5em"> - <div class="alert"> - I am a div that alerts when you click on me - notice I just have class="alert" to make it work :) - </div> - <div class="annoy"> - I am a div that alerts when you mouseover me - class="annoy" makes it work - </div> - <div class=" alert red"> - I am a div that alerts when you click on me and the background turns red on mouseover - class="alert red" - </div> - </div> -</body> -</html> +<!DOCTYPE html +PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <title> + How to use behavior.js + </title> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <script src="cssQuery-p.js" type="text/javascript"></script> + <script src="behavior.js" type="text/javascript"></script> +<script type="text/javascript"> +Behavior.register( + ".alert", + function(element) { + element.onclick = function(){ + alert('I alert on click'); + } + } + ); + + Behavior.register( + ".annoy", + function(element) { + element.onmouseout = function(){ + alert('I alert on mouseout, very annoying'); + } + } + ); + + Behavior.register( + ".red", + function(element) { + element.onmouseover = function(){ + element.style.backgroundColor = 'red'; + } + } + ); +</script> +</head> + +<body> + <div style="border: 1px solid black; width: 50%; margin: 5em"> + <div class="alert"> + I am a div that alerts when you click on me - notice I just have class="alert" to make it work :) + </div> + <div class="annoy"> + I am a div that alerts when you mouseover me - class="annoy" makes it work + </div> + <div class=" alert red"> + I am a div that alerts when you click on me and the background turns red on mouseover - class="alert red" + </div> + </div> +</body> +</html> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/test2.class.php?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/examples/test2.class.php diff -u pear/HTML_AJAX/examples/test2.class.php:1.1 pear/HTML_AJAX/examples/test2.class.php:1.2 --- pear/HTML_AJAX/examples/test2.class.php:1.1 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/test2.class.php Mon Nov 7 13:43:49 2005 @@ -1,25 +1,25 @@ -<?php -/** - * Test class used in other examples - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ -class test2 { - function echo_string($string) { - return $string; - } - function slow_echo_string($string) { - sleep(2); - return $string; - } - function error_test($string) { - trigger_error($string); - } -} -?> +<?php +/** + * Test class used in other examples + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ +class test2 { + function echo_string($string) { + return $string; + } + function slow_echo_string($string) { + sleep(2); + return $string; + } + function error_test($string) { + trigger_error($string); + } +} +?> http://cvs.php.net/diff.php/pear/HTML_AJAX/examples/test_speed.php?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/examples/test_speed.php diff -u pear/HTML_AJAX/examples/test_speed.php:1.3 pear/HTML_AJAX/examples/test_speed.php:1.4 --- pear/HTML_AJAX/examples/test_speed.php:1.3 Mon Oct 24 23:27:42 2005 +++ pear/HTML_AJAX/examples/test_speed.php Mon Nov 7 13:43:49 2005 @@ -1,91 +1,91 @@ -<?php -/** - * Simple speed test using the null serializer, possibly useful in comparing overhead when tested on local host - * - * - * @category HTML - * @package AJAX - * @author Joshua Eichorn <josh@bluga.net> - * @copyright 2005 Joshua Eichorn - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @version Release: @package_version@ - * @link http://pear.php.net/package/HTML_AJAX - */ - include 'HTML/AJAX.php'; - - include 'test.class.php'; - - - - $ajax = new HTML_AJAX(); - $ajax->serializer = "Null"; - $ajax->unserializer = "Null"; - $ajax->registerClass(new test()); - - if ($ajax->handleRequest()) { - die(); - } -?><html> -<head> - -<script type='text/javascript' src="server.php?client=all&stub=all"></script> -</head> -<body> -<script type="text/javascript"> -var t = new test(); -var t2 = new test({echo_string: function(){ endCall('Async Echo'); totalA(); }}); - -var time1; -var total = 0; -var count = 0; - -function speedTest() { - - document.getElementById('target').innerHTML += "10 Sync Calls\n"; - for(var i = 0; i < 10; i++) { - startCall(); - t.echo_string('Test'); - endCall('Sync Echo'); - } - document.getElementById('target').innerHTML += "Total: "+total+"\n\n\n"; - total = 0; - - document.getElementById('target').innerHTML += "10 Async Calls\n"; - count = 0; - for(var i = 0; i < 10; i++) { - setTimeout("runAsync();",500*i); - } - total = 0; - -} -function totalA() { - count++; - if (count == 10) { - document.getElementById('target').innerHTML += "Total: "+total+"\n"; - } -} -function runAsync() { - startCall(); - t2.echo_string('Test'); -} -function startCall() { - time1 = new Date(); -} -function endCall(name) { - var time = 0; - - var time2 = new Date(); - - time = time2.getTime() - time1.getTime(); - total += time; - - document.getElementById('target').innerHTML += name+":"+time+"\n"; -} - - -</script> -<a href="javascript:speedTest()">Start Speed Test</a> -<pre id="target"> -</pre> -</body> -</html> +<?php +/** + * Simple speed test using the null serializer, possibly useful in comparing overhead when tested on local host + * + * + * @category HTML + * @package AJAX + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version Release: @package_version@ + * @link http://pear.php.net/package/HTML_AJAX + */ + include 'HTML/AJAX.php'; + + include 'test.class.php'; + + + + $ajax = new HTML_AJAX(); + $ajax->serializer = "Null"; + $ajax->unserializer = "Null"; + $ajax->registerClass(new test()); + + if ($ajax->handleRequest()) { + die(); + } +?><html> +<head> + +<script type='text/javascript' src="server.php?client=all&stub=all"></script> +</head> +<body> +<script type="text/javascript"> +var t = new test(); +var t2 = new test({echo_string: function(){ endCall('Async Echo'); totalA(); }}); + +var time1; +var total = 0; +var count = 0; + +function speedTest() { + + document.getElementById('target').innerHTML += "10 Sync Calls\n"; + for(var i = 0; i < 10; i++) { + startCall(); + t.echo_string('Test'); + endCall('Sync Echo'); + } + document.getElementById('target').innerHTML += "Total: "+total+"\n\n\n"; + total = 0; + + document.getElementById('target').innerHTML += "10 Async Calls\n"; + count = 0; + for(var i = 0; i < 10; i++) { + setTimeout("runAsync();",500*i); + } + total = 0; + +} +function totalA() { + count++; + if (count == 10) { + document.getElementById('target').innerHTML += "Total: "+total+"\n"; + } +} +function runAsync() { + startCall(); + t2.echo_string('Test'); +} +function startCall() { + time1 = new Date(); +} +function endCall(name) { + var time = 0; + + var time2 = new Date(); + + time = time2.getTime() - time1.getTime(); + total += time; + + document.getElementById('target').innerHTML += name+":"+time+"\n"; +} + + +</script> +<a href="javascript:speedTest()">Start Speed Test</a> +<pre id="target"> +</pre> +</body> +</html>