Skip to content

Commit

Permalink
new files up to svn rev r616
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/HTML_AJAX/trunk@259272 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Joshua Eichorn committed May 7, 2008
1 parent ad5d83f commit 204206a
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 0 deletions.
88 changes: 88 additions & 0 deletions AJAX/Serializer/XML.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
// $Id$
/**
* XML Serializer - does NOT need a js serializer, use responseXML property in XmlHttpRequest
*
* @category HTML
* @package AJAX
* @author Elizabeth Smith <auroraeosrose@gmail.com>
* @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;
}
}
}
?>
5 changes: 5 additions & 0 deletions docs/authors
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Joshua Eichorn <josh@bluga.net> - Project Lead
David Coallier <davidc@php.net> - Project Lead
Laurent Yaish <laurenty@gmail.com> - Developer
Elizabeth Smith <auroraeosrose@gmail.com> - Developer
Arpad Ray <arpad@php.net> - Developer
7 changes: 7 additions & 0 deletions docs/todo
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions examples/bugfixes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Simple grab example
*
* @category HTML
* @package AJAX
* @author Arpad Ray <arpad@php.net>
* @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>
40 changes: 40 additions & 0 deletions examples/interceptorServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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 <josh@bluga.net>
* @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();
?>
67 changes: 67 additions & 0 deletions examples/interceptors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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 <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="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>
35 changes: 35 additions & 0 deletions examples/support/interceptor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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;
}
}
7 changes: 7 additions & 0 deletions examples/support/isajax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
require_once 'HTML/AJAX/Helper.php';

$helper = new HTML_AJAX_Helper();

var_dump($helper->isAJAX());
?>
66 changes: 66 additions & 0 deletions examples/tests/helper_combine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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();

$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: */
?>

0 comments on commit 204206a

Please sign in to comment.