Location: PHPKode > projects > PHP OpenTailorShop > phpopentailorshop/xajax/tests/suite/pluginTest.php

$sBaseFolder = dirname(dirname(dirname(__FILE__)));


$requestURI = $xajax->_detectURI();

$requestURI = str_replace('methodOne=1', '', $requestURI);
$requestURI = str_replace('methodTwo=1', '', $requestURI);
$requestURI = str_replace('methodThree=1', '', $requestURI);

$reqShowOutput =& $xajax->register(XAJAX_FUNCTION, "showOutput");

class testPlugin extends xajaxResponsePlugin
	function getName()
		return "testPlugin";
	function generateClientScript()
		echo "\n<script type='text/javascript' charset='UTF-8'>\n"; // " . $this->sDefer . "
		echo "/* <![CDATA[ */\n";

		echo "xajax.command.handler.register('testPlg', function(args) { \n";
		echo "\talert('Test plugin command received: ' + args.data);\n";
		echo "});\n";

		echo "/* ]]> */\n";
		echo "</script>\n";
	function testMethod()
		$this->addCommand(array('n'=>'testPlg'), 'abcde]]>fg');	

$objPluginManager =& xajaxPluginManager::getInstance();
$objPluginManager->registerPlugin(new testPlugin());


$sRoot = dirname(dirname(dirname(__FILE__)));

if (false == class_exists('xajaxControl')) {
	$sCore = '/xajax_core';
	include_once($sRoot . $sCore . '/xajaxControl.inc.php');

$sControls = '/xajax_controls';
foreach (array(
	'/misc.inc.php') as $sFile)
	include_once($sRoot . $sControls . $sFile);

$buttonShowOutput = new clsButton(array(
	'attributes' => array('id' => 'btnShowOutput'),
	'child' => new clsLiteral('Show Response XML'),
	'event' => array('onclick', $reqShowOutput)

	$objTestScriptPlugin->printHeader($xajax, "Basic Plugin Test");
	if (isset($_GET['methodOne']))
		echo 'Using plugin access method One.';
	else if (isset($_GET['methodTwo']))
		echo 'Using plugin access method Two.';
	else if (isset($_GET['methodThree']))
		echo 'Using plugin access method Three.';
		$buttonShowOutput->setAttribute('disabled', 'disabled');

<form id="testForm1" onsubmit="return false;">
<p><?php $buttonShowOutput->printHTML(); ?></p>

		Please select a method appropriate to the version of php running on your host:
	$sSeparator = '?';
	if (false !== strstr($requestURI, '?'))
		$sSeparator = '&';

	$newRequestURI = $requestURI . $sSeparator . 'methodOne=1';
	$newRequestURI = str_replace('?&', '?', str_replace('&&', '&', $newRequestURI));
	echo "<a href='" . $newRequestURI . "'>PHP4 & PHP5</a> ";

	$newRequestURI = $requestURI . $sSeparator . 'methodTwo=1';
	$newRequestURI = str_replace('?&', '?', str_replace('&&', '&', $newRequestURI));
	echo "<a href='" . $newRequestURI . "'>PHP5</a> ";

	$newRequestURI = $requestURI . $sSeparator . 'methodThree=1';
	$newRequestURI = str_replace('?&', '?', str_replace('&&', '&', $newRequestURI));
	echo "<a href='" . $newRequestURI . "'>PHP5 (type 2)</a>";
<p>This test script demonstrates the ability to declare and register response plugins then use
the registered plugin to send back new response commands to the client.
<p>To use this script, select an option (above) that matches your server configuration; all methods
can be used on a PHP5 based server.
<p>The plugin will register a javascript command handler, then, upon request, it will add
a response command that will be sent back to the client, invoking the command on the browser.
<p>In this case, the plugin simply shows an alert dialog beginning with the text 'Test plugin 
command received:' then some data sent from the server.
<p>The test script also outputs a preformatted string that represents a response object 
that includes the plugin response command.  NOTE:  This is not a copy of the response that IS sent
to the browser, just an example of one.

function showOutput()
	$testResponse = new xajaxResponse();
	$testResponse->alert("This is the text that would be displayed in an alert box.");
	// PHP4 & PHP5
	if (isset($_GET['methodOne']))
		eval('$testResponse->plugin("testPlugin", "testMethod");');
	// PHP5 ONLY - Uncomment to test
	if (isset($_GET['methodTwo']))
	// PHP5 ONLY - Uncomment to test
	if (isset($_GET['methodThree']))
	$testResponseOutput = '<pre>' 
		. htmlspecialchars(str_replace("><", ">\n<", $testResponse->getOutput())) 
		. '</pre>';
	$objResponse = new xajaxResponse();
	$objResponse->assign("status", "innerHTML", $testResponseOutput);
	if (isset($_GET['methodOne']))
		eval('$objResponse->plugin("testPlugin", "testMethod");');
	if (isset($_GET['methodTwo']))
	if (isset($_GET['methodThree']))
	return $objResponse;

Return current item: PHP OpenTailorShop