cvs: pear /HTML_AJAX/AJAX/Serializer XML.php /HTML_AJAX/docs authors todo /HTML_AJAX/examples bugfixes.php interceptorServer.php interceptors.php /HTML_AJAX/examples/support interceptor.php isajax.php /HTML_AJAX/examples/tests helper_combine.php

[email protected] ("Joshua Eichorn") Wed, 07 May 2008 21:28:11 -0000
Newsgroups php.pear.cvs
Message-ID <cvsjeichorn1210195691@cvsserver>
jeichorn		Wed May  7 21:28:11 2008 UTC

  Added files:                 
    /pear/HTML_AJAX/AJAX/Serializer	XML.php 
    /pear/HTML_AJAX/docs	authors 
    /pear/HTML_AJAX/examples	bugfixes.php interceptorServer.php 
                            	interceptors.php 
    /pear/HTML_AJAX/examples/support	interceptor.php isajax.php 
    /pear/HTML_AJAX/examples/tests	helper_combine.php 

  Modified files:              
    /pear/HTML_AJAX/docs	todo 
  Log:
  new files up to svn rev r616
jeichorn-20080507212811.txt (text/plain, 11.8 KB)
http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/docs/todo?r1=1.2&r2=1.3&diff_format=u
Index: pear/HTML_AJAX/docs/todo
diff -u /dev/null pear/HTML_AJAX/docs/todo:1.3
--- /dev/null	Wed May  7 21:28:11 2008
+++ pear/HTML_AJAX/docs/todo	Wed May  7 21:28:11 2008
@@ -0,0 +1,7 @@
+JPSpan serializer for compatibility
+Additional functionality to helper class
+Inline frame ajax fallback and file upload support
+Something for Polling
+Basic debugging tools (XMLHttpRequest tester, serialized items viewer, debug console)
+Complete Documentation including basic tutorials and step by step for advanced uses
+Framework integration - either documentation or some kind of API
\ No newline at end of file

http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/AJAX/Serializer/XML.php?view=markup&rev=1.1
Index: pear/HTML_AJAX/AJAX/Serializer/XML.php
+++ pear/HTML_AJAX/AJAX/Serializer/XML.php
<?php
// $Id: XML.php,v 1.1 2008/05/07 21:28:11 jeichorn Exp $
/**
 * XML Serializer - does NOT need a js serializer, use responseXML property in XmlHttpRequest
 *
 * @category   HTML
 * @package    AJAX
 * @author     Elizabeth Smith <[email protected]>
 * @copyright  2005-2006 Elizabeth Smith
 * @license    http://www.opensource.org/licenses/lgpl-license.php  LGPL
 * @version    Release: @package_version@
 * @link       http://pear.php.net/package/PackageName
 */
class HTML_AJAX_Serializer_XML
{

    /**
     * Serializes a domdocument into an xml string
     *
     * Uses dom or domxml to dump a string from a DomDocument instance
     * remember dom is always the default and this will die horribly without
     * a domdocument instance
     *
     * @access public
     * @param  object $input instanceof DomDocument
     * @return string xml string of DomDocument
     */
    function serialize($input) 
    {
        if(empty($input))
        {
            return $input;
        }
        // we check for the dom extension
        elseif (extension_loaded('Dom'))
        {
            return $input->saveXml();
        }
        // then will check for domxml
        elseif (extension_loaded('Domxml')) 
	{
            return $input->dump_mem();
        }
	// will throw an error
	else {
		$error = new HTML_AJAX_Serializer_Error();	
		$this->serializerNewType = 'Error';
		return $error->serialize(array('errStr'=>"Missing PHP Dom extension direct XML won't work"));
	}
    }

    /**
     * Unserializes the xml string sent from the document
     *
     * Uses dom or domxml to pump a string into a DomDocument instance
     * remember dom is always the default and this will die horribly without
     * one or the other, and will throw warnings if you have bad xml
     *
     * @access public
     * @param  string $input   The input to serialize.
     * @return object instanceofDomDocument
     */
    function unserialize($input) 
    {
        if(empty($input))
        {
            return $input;
        }
        // we check for the dom extension
        elseif (extension_loaded('Dom'))
        {
            $doc = new DOMDocument();
            $doc->loadXML($input);
            return $doc;
        }
        // then we check for the domxml extensions
        elseif (extension_loaded('Domxml'))
	{
            return domxml_open_mem($input);
	}
	// we give up and just return the xml directly
        else
        {
		return $input;
        }
    }
}
?>

http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/bugfixes.php?view=markup&rev=1.1
Index: pear/HTML_AJAX/examples/bugfixes.php
+++ pear/HTML_AJAX/examples/bugfixes.php
<?php
/**
 * Simple grab example
 *
 * @category   HTML
 * @package    AJAX
 * @author     Arpad Ray <[email protected]>
 * @copyright  2005 Arpad Ray
 * @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';

if (isset($_GET['grab'])) {
    die('Grabbed from php!');
}

$ajax = new HTML_AJAX();
if ($ajax->handleRequest()) {
    exit;
}

?><html>
<head>
<script type='text/javascript' src="../js/HTML_AJAX.js"></script>
<script type="text/javascript">
var BugFixes = {
    /**
     * @link http://pear.php.net/bugs/11542
     */
    bug11542: function()
    {
        var i = 0;
        result = HTML_AJAX.grab('grab.php?grab=1');
        alert(i);
    }
}
</script>
</head>
<body>
<a href="#" onclick="BugFixes.bug11542();">Test bugfix 11542 (Should alert 0)</a>
</body>
</html>

http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/interceptorServer.php?view=markup&rev=1.1
Index: pear/HTML_AJAX/examples/interceptorServer.php
+++ pear/HTML_AJAX/examples/interceptorServer.php
<?php
/**
 * HTML_AJAX_Server with a register itnerceptor class
 *
 * 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 <[email protected]>
 * @copyright  2007 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 'support/test.class.php';
	include 'support/test2.class.php';
	include 'support/interceptor.php';

// create our new server
$server = new HTML_AJAX_Server();

// register an instance of the class were registering
$test = new test();
$server->registerClass($test,'test');

$test2 = new test2();
$server->registerClass($test2,'test2');

$server->ajax->packJavaScript = true;

$server->ajax->setInterceptor(new Interceptor());

$server->handleRequest();
?>

http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/interceptors.php?view=markup&rev=1.1
Index: pear/HTML_AJAX/examples/interceptors.php
+++ pear/HTML_AJAX/examples/interceptors.php
<?php
/**
 * Front end for interceptor examples, see support/interceptor.php for the interceptor class that is being used, and interceptorServer.php for how to register one
 *
 * @category   HTML
 * @package    AJAX
 * @author     Joshua Eichorn <[email protected]>
 * @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="interceptorServer.php?client=all"></script>
<script type='text/javascript' src="interceptorServer.php?stub=all"></script>

<script type='text/javascript'>
// definition of the callback javascript class, used to handle async requests
var callback = {
	test1: function(result) {
		document.getElementById('target').innerHTML = HTML_AJAX_Util.varDump(result);
	},
	test2: function(result) {
		document.getElementById('target').innerHTML = HTML_AJAX_Util.varDump(result);
	},
	test3: function(result) {
		document.getElementById('target').innerHTML = HTML_AJAX_Util.varDump(result);
	}
}

// function used to clear out the target div
function clearTarget() {
	document.getElementById('target').innerHTML = 'clear';
}

HTML_AJAX.onError = function(e) {
	document.getElementById('errors').innerHTML = HTML_AJAX_Util.varDump(e);
}
</script>
</head>
<body>
<script type="text/javascript">
// create a proxy in async mode
var testProxy = new test(callback);
var test2Proxy = new test2({test: function(result) { document.getElementById('target').innerHTML = HTML_AJAX_Util.varDump(result); }});

// run a sync call and set its results to the target div
</script>
<ul>
	<li><a href="javascript:clearTarget()">Clear Target</a></li>
	<li><a href="javascript:testProxy.test1('One')">Run test::test1, matches interceptor for specific method</a></li>
	<li><a href="javascript:testProxy.test2('Two')">Run test::test2, matches interceptor for class</a></li>
	<li><a href="javascript:testProxy.test3('Three')">Run test::test3, matches interceptor for class</a></li>
	<li><a href="javascript:test2Proxy.test('Four')">Run test2::test, matches global interceptor</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 style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="errors">Errors</div>

</div>

</body>
</html>

http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/support/interceptor.php?view=markup&rev=1.1
Index: pear/HTML_AJAX/examples/support/interceptor.php
+++ pear/HTML_AJAX/examples/support/interceptor.php
<?php
class Interceptor {

	/**
	 * A global interceptor runs all calls not matched by a more specific rule
	 * This example creates a not logged in error
	 */
	function intercept($className,$methodName,$params) {

		// if you were using php5 you could throw an exception instead of using trigger_error
		trigger_error("Not logged in: $className::$methodName");

		return $params;
	}

	/**
	 * A class level interceptor for the test class
	 * This examples sets the first parameter to the method name
	 */
	function test($methodName,$params) {
		$params[0] = 'Intercepted: '.$methodName.' - Original: '.$params[0];

		return $params;
	}

	/**
	 * A method level interceptor for the test::test1 method
	 * This examples sets the first parameter to boink
	 */
	function test_test1($params) {
		$params[0] = 'Intercepted: boink - Original: '.$params[0];

		return $params;
	}
}

http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/support/isajax.php?view=markup&rev=1.1
Index: pear/HTML_AJAX/examples/support/isajax.php
+++ pear/HTML_AJAX/examples/support/isajax.php
<?php
require_once 'HTML/AJAX/Helper.php';

$helper = new HTML_AJAX_Helper();

var_dump($helper->isAJAX());
?>

http://cvs.php.net/viewvc.cgi/pear/HTML_AJAX/examples/tests/helper_combine.php?view=markup&rev=1.1
Index: pear/HTML_AJAX/examples/tests/helper_combine.php
+++ pear/HTML_AJAX/examples/tests/helper_combine.php
<?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 <[email protected]>
 * @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();

$combine = false;
if (isset($_GET['mode']) && $_GET['mode']  == 'combined') {
    $combine = true;
}
$ajaxHelper->combineJsIncludes = $combine;

$ajaxHelper->serverUrl = '../server.php';

// reset array so were only dealing with our custom lib not the default set
$ajaxHelper->jsLibraries = array();
$ajaxHelper->jsLibraries[] = 'customLib';
$ajaxHelper->jsLibraries[] = 'customLib';
$ajaxHelper->jsLibraries[] = 'customLib';
$ajaxHelper->jsLibraries[] = 'customLib';
$ajaxHelper->jsLibraries[] = 'customLib';
$ajaxHelper->jsLibraries[] = 'customLib';

// in default operation a sub-array in jsLibraries will make a second include
// with combineJsIncludes as true subarray's are merged into a single include
$ajaxHelper->jsLibraries['test'][] = 'customLib';
$ajaxHelper->jsLibraries['test'][] = 'customLib';
$ajaxHelper->jsLibraries['test'][] = 'customLib';

?>
<html>
<head>

<?php
    echo $ajaxHelper->setupAJAX();
?>

</head>
<body>

<p>This is a test that we can combine js client library includes, the loaded libraries should only include customLib once</p>

<ul>
    <li><a href="?mode=combined">Combined Includes</a></li>
    <li><a href="?mode=default">Default includes, 1 include per sub-array</a></li>

</body>
</html>
<?php 
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
?>