Permalink
Browse files

merge in changes from SVN, should be everything up to r616

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_AJAX/trunk@259271 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent b446984 commit ad5d83fce061f0e482e4d8ab0e22bbe466f2a0a2 Joshua Eichorn committed May 7, 2008
View
Oops, something went wrong.
View
@@ -1,5 +1,5 @@
<?php
-define ("NEWLINE", "\n");
+define ("HTML_AJAX_NEWLINE", "\n");
// {{{ class HTML_AJAX_Debug
/**
* AJAX Debugging implementation
@@ -101,11 +101,11 @@ function HTML_AJAX_Debug($errMsg, $errLine, $errCode, $errFile)
*/
function xmlError()
{
- $error = " <when>{$this->_timeOccured}</when>" . NEWLINE;
- $error .= " <msg>{$this->errorMsg}</msg>" . NEWLINE;
- $error .= " <code>{$this->errorCode}</code>" . NEWLINE;
- $error .= " <line>{$this->errorLine}</line>" . NEWLINE;
- $error .= " <file>{$this->errorFile}</file>" . NEWLINE . NEWLINE;
+ $error = " <when>{$this->_timeOccured}</when>" . HTML_AJAX_NEWLINE;
+ $error .= " <msg>{$this->errorMsg}</msg>" . HTML_AJAX_NEWLINE;
+ $error .= " <code>{$this->errorCode}</code>" . HTML_AJAX_NEWLINE;
+ $error .= " <line>{$this->errorLine}</line>" . HTML_AJAX_NEWLINE;
+ $error .= " <file>{$this->errorFile}</file>" . HTML_AJAX_NEWLINE . HTML_AJAX_NEWLINE;
return $this->error = $error;
}
// }}}
View
@@ -40,6 +40,11 @@ class HTML_AJAX_Helper
*/
var $stubs = array();
+ /**
+ * Combine jsLibraries into a single require and remove duplicates
+ */
+ var $combineJsIncludes = false;
+
/**
* Include all needed libraries, stubs, and set defaultServer
*
@@ -48,24 +53,41 @@ class HTML_AJAX_Helper
function setupAJAX()
{
$libs = array(0=>array());
+ $combinedLibs = array();
+
+ $this->jsLibraries = array_unique($this->jsLibraries);
foreach($this->jsLibraries as $library) {
if (is_array($library)) {
+ $library = array_unique($library);
+ $combinedLibs = array_merge($combinedLibs,$library);
$libs[] = implode(',',$library);
}
else {
$libs[0][] = $library;
+ $combinedLibs[] = $library;
}
}
$libs[0] = implode(',',$libs[0]);
+ $sep = '?';
+ if (strstr($this->serverUrl,'?')) {
+ $sep = '&';
+ }
+
$ret = '';
- foreach($libs as $list) {
- $ret .= "<script type='text/javascript' src='{$this->serverUrl}?client={$list}'></script>\n";
- }
+ if ($this->combineJsIncludes == true) {
+ $list = implode(',',$combinedLibs);
+ $ret .= "<script type='text/javascript' src='{$this->serverUrl}{$sep}client={$list}'></script>\n";
+ }
+ else {
+ foreach($libs as $list) {
+ $ret .= "<script type='text/javascript' src='{$this->serverUrl}{$sep}client={$list}'></script>\n";
+ }
+ }
if (count($this->stubs) > 0) {
$stubs = implode(',',$this->stubs);
- $ret .= "<script type='text/javascript' src='{$this->serverUrl}?stub={$stubs}'></script>\n";
+ $ret .= "<script type='text/javascript' src='{$this->serverUrl}{$sep}stub={$stubs}'></script>\n";
}
$ret .= $this->encloseInScript('HTML_AJAX.defaultServerUrl = '.$this->escape($this->serverUrl));
return $ret;
@@ -145,5 +167,18 @@ function jsonEncode($input) {
$s = new HTML_AJAX_Serializer_JSON();
return $s->serialize($input);
}
+
+ /**
+ * Check the request headers to see if this is an AJAX request
+ *
+ * @return boolean
+ */
+ function isAJAX() {
+ if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
+ return true;
+ }
+ return false;
+ }
}
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
?>
View
@@ -6,6 +6,11 @@
* Feel free to report bugs against it to HTML_AJAX
*/
+/**
+ * Needed for compat functions
+ */
+require_once 'HTML/AJAX.php';
+
/**
* Converts to and from JSON format.
*
@@ -755,7 +760,7 @@ function decode($str)
*/
function isError($data, $code = null)
{
- if (class_exists('pear')) {
+ if (HTML_AJAX_class_exists('pear', false)) {
return PEAR::isError($data, $code);
} elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
is_subclass_of($data, 'services_json_error'))) {
@@ -766,7 +771,7 @@ function isError($data, $code = null)
}
}
-if (class_exists('pear_error')) {
+if (HTML_AJAX_class_exists('pear_error', false)) {
class HTML_AJAX_JSON_Error extends PEAR_Error
{
@@ -43,7 +43,7 @@ function HTML_AJAX_Serializer_JSON($use_loose_type = true)
$this->_jsonext = $this->_detect();
if(!$this->_jsonext) {
$use_loose_type = ($this->loose_type) ? SERVICES_JSON_LOOSE_TYPE : 0;
- $this->_json =& new HTML_AJAX_JSON($use_loose_type);
+ $this->_json = new HTML_AJAX_JSON($use_loose_type);
}
}
// }}}
View
@@ -93,6 +93,24 @@ class HTML_AJAX_Server
);
/**
+ * Compression Options
+ *
+ * <code>
+ * array(
+ * 'enabled' => false, // enable compression
+ * 'type' => 'gzip' // the type of compression to do, options: gzip
+ * )
+ * </code>
+ *
+ * @var array
+ * @access public
+ */
+ var $compression = array(
+ 'enabled' => false,
+ 'type' => 'gzip'
+ );
+
+ /**
* Javascript library names and there path
*
* the return of $this->clientJsLocation(), is prepended before running readfile on them
@@ -121,10 +139,10 @@ class HTML_AJAX_Server
'behavior' => array('behavior/behavior.js','behavior/cssQuery-p.js'),
// rules to help you use a minimal library set
- 'standard' => array('Compat.js','clientPool.js','util.js','main.js','HttpClient.js','Request.js','serializer/JSON.js',
- 'loading.js','serializer/UrlSerializer.js','Alias.js','behavior/behavior.js','behavior/cssQuery-p.js'),
- 'jsonrpc' => array('Compat.js','util.js','main.js','clientPool.js','HttpClient.js','Request.js','serializer/JSON.js'),
- 'proxyobjects' => array('Compat.js','util.js','main.js','clientPool.js','Request.js','serializer/JSON.js','Dispatcher.js'),
+ 'standard' => array('Compat.js','clientPool.js','util.js','Main.js','HttpClient.js','Request.js','serializer/JSON.js',
+ 'Loading.js','serializer/UrlSerializer.js','Alias.js','behavior/behavior.js','behavior/cssQuery-p.js'),
+ 'jsonrpc' => array('Compat.js','util.js','Main.js','clientPool.js','HttpClient.js','Request.js','serializer/JSON.js'),
+ 'proxyobjects' => array('Compat.js','util.js','Main.js','clientPool.js','Request.js','serializer/JSON.js','Dispatcher.js'),
// BC rules
'priorityqueue' => 'Queue.js',
@@ -155,7 +173,7 @@ class HTML_AJAX_Server
*/
function HTML_AJAX_Server($serverUrl = false)
{
- $this->ajax =& new HTML_AJAX();
+ $this->ajax = new HTML_AJAX();
// parameters for HTML::AJAX
$parameters = array('stub', 'client');
@@ -434,8 +452,15 @@ function generateClient()
$output = $this->ajax->packJavaScript($output);
$length = strlen($output);
}
+
+ if ($this->compression['enabled'] && $this->compression['type'] == 'gzip' && strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false) {
+ $output = gzencode($output,9);
+ $length = strlen($output);
+ $headers['Content-Encoding'] = 'gzip';
+ }
+
if ($length > 0 && $this->ajax->_sendContentLength()) {
- //$headers['Content-Length'] = $length;
+ $headers['Content-Length'] = $length;
}
$headers['Content-Type'] = 'text/javascript; charset=utf-8';
$this->ajax->_sendHeaders($headers);
@@ -480,6 +505,45 @@ function clientJsLocation()
}
/**
+ * Set the location of the client js
+ *
+ * @access public
+ * @param string $location Location
+ * @return void
+ */
+ function setClientJsLocation($location)
+ {
+ $this->clientJsLocation = $location;
+ }
+
+ /**
+ * Set the path to a Javascript libraries
+ *
+ * @access public
+ * @param string $library Library name
+ * @param string $path Path
+ * @return void
+ */
+ function setJavascriptLibraryPath($library, $path)
+ {
+ $this->javascriptLibraryPaths[$library] = $path;
+ }
+
+ /**
+ * Set the path to more than one Javascript libraries at once
+ *
+ * @access public
+ * @param array $paths Paths
+ * @return void
+ */
+ function setJavascriptLibraryPaths($paths)
+ {
+ if (is_array($paths)) {
+ $this->javascriptLibraryPaths = array_merge($this->javascriptLibraryPaths, $paths);
+ }
+ }
+
+ /**
* Load options from _GET
*
* @access private
View
@@ -76,5 +76,16 @@
</table>
<input type="submit" name="submit" value="Submit form" />
</form>
+
+ <h3>JavaScript callback function target test</h3>
+ <form action="server.php" method="post" onsubmit="return !HTML_AJAX.formSubmit(this, function(result) { document.getElementById('target').innerHTML = result; }, {className: 'test', methodName:'multiarg'});">
+
+ <table>
+ <tr>
+ <td>Text</td>
+ <td><input type="text" name="test_text" value="example" /></td>
+ </tr>
+ </table>
+ </form>
</body>
</html>
@@ -21,7 +21,7 @@ class GuestbookServer extends HTML_AJAX_Server {
// init method for the test class, includes needed files an registers it for ajax
function initGuestbook() {
include 'guestbook.class.php';
- $this->registerClass(new Guestbook(),'guestbook',array('newEntry', 'clearGuestbook', 'deleteEntry', 'editEntry')); // specify methods so that we get case in php4
+ $this->registerClass(new Guestbook(),'guestbook',array('newEntry', 'clearGuestbook', 'deleteEntry', 'editEntry', 'updateSelect')); // specify methods so that we get case in php4
}
}
@@ -137,6 +137,19 @@ function editEntry($id) {
return $response;
}
+ function updateSelect($id)
+ {
+ $response = new HTML_AJAX_Action();
+ $attr = array('id' => $id, 'name' => $id);
+ $response->replaceNode($id, 'select', $attr);
+ for ($i=1;$i<=10;$i++)
+ {
+ $attr = array('value' => $i, 'innerHTML' => 'Option ' . $i);
+ $response->createNode($id, 'option', $attr, 'append');
+ }
+ return $response;
+ }
+
function _makeDiv($key, $data, $replace = FALSE) {
$div = '';
if($replace == FALSE)
@@ -148,6 +148,10 @@ function editentry(id) {
var remoteguestbook = new guestbook();
remoteguestbook.editEntry(id);
}
+function updateselect(id) {
+ var remoteguestbook = new guestbook();
+ remoteguestbook.updateSelect(id);
+}
</script>
<h2>Welcome to the Guestbook</h2>
<div id="guestbookList">
@@ -184,15 +188,15 @@ function editentry(id) {
</fieldset>
</form>
-<h4>Current Guestbook Testing Status</h4>
-<h5>Win32 - XP</h5>
-<ol>
-<li>Firefox 1.5b - all passed</li>
-<li>IE 6 - all passed</li>
-<li>Netscape 8 - IE mode passed, Gecko mode failed (some kind of browser bug I suspect)</li>
-<li>Opera 8.5 - all passed</li>
-<li>IE 5.5 - sessions were messed up but what worked was fine</li>
-<li>IE 5.01 - same as 5.5, messed up sessions but partially worked</li>
-</ol>
+<p>Fill a select item with a list of options - tests the HTML_AJAX_Action::replaceNode and HTML_AJAX_Action::createNode methods</p>
+ <form id="testing" action="index.php" method="post" onsubmit="return false;">
+ <div>
+ <a href="#" onclick="updateselect('replaceme');">Gimme some options</a>
+ <select id="replaceme">
+ <option name="dog" id="dog">Dog</option>
+ </select>
+ </div>
+ </form>
+
</body>
</html>
@@ -18,7 +18,7 @@
// create an instance and set the server url
$ajaxHelper = new HTML_AJAX_Helper();
-$ajaxHelper->serverUrl = 'auto_server.php';
+$ajaxHelper->serverUrl = 'server.php?gzip=true';
$ajaxHelper->jsLibraries[] = 'customLib';
?>
<html>
@@ -42,6 +42,16 @@
// update the element using ajax
echo $ajaxHelper->updateElement('updateTarget',array('test','echo_string','Some text to echo'),'replace',true);
?>
+
+
+<p>Was this page loaded using AJAX: <?php var_dump($ajaxHelper->isAJAX()); ?></p>
+
+Below is the output of HTML_AJAX_Helper::isAJAX() on content loaded from AJAX
+<div id="updateTarget2"></div>
+<?php
+ echo $ajaxHelper->updateElement('updateTarget2','support/isajax.php','replace',true);
+?>
+
</body>
</html>
<?php
View
@@ -1,9 +1,9 @@
<html>
<head>
-<title>HTML_AJAX 0.5.0 Examples</title>
+<title>HTML_AJAX 0.5.3 Examples</title>
</head>
<body>
-<h1>HTML_AJAX 0.5.0 Examples</h1>
+<h1>HTML_AJAX 0.5.3 Examples</h1>
<p>
These are examples showing the basics of using HTML_AJAX
</p>
@@ -58,6 +58,8 @@
<li><a href='server.php?client=util,main'>server.php?client=util,main</a> - server.php generating a javascript file with the main and util libs in it</li>
<li><a href='auto_server.php?stub=test2'>server.php?stub=test2</a> - auto_server.php generating a javascript file a which contains a generated proxy class for the test2 php class</li>
<li><a href='auto_server.php?stub=all'>server.php?stub=all</a> - auto_server.php generating a javascript file which contains proxies for all the php classes registered with it</li>
+<li><a href='server.php?stub=all&gzip=true'>server.php?stub=all&gzip=true</a> - an example with gzip compression enabled (note gzip=true isn't built in, see server.php)<li>
+<li><a href='server.php?stub=all&gzip=true'>server.php?stub=all&gzip=true</a> - another example with gzip compression enabled (note gzip=true isn't built in, see server.php)<li>
</ul>
<p>
@@ -79,6 +81,8 @@
<li><a href='tests/setInnerHTML.php'>setInnerHTML.php</a> - Tests used to verify the operation of HTML_AJAX_Util.setInnerHTML</li>
<li><a href='tests/duplicateJSLib.php'>duplicateJSLib.php</a> - Tests used to verify that HTML_AJAX_Server is removing duplicate JS libraries from client generation correctly</li>
<li><a href='tests/behaviorSpeed.php'>behaviorSpeed.php</a> - Tests used to see how fast the JavaScript behavior code runs.</li>
+<li><a href='tests/helper_combine.php'>helper_combine.php</a> - Tests used to verify helper url javascript include generation.</li>
+<li><a href='interceptors.php'>interceptors.php</a> - Interceptors test</a></li>
</ul>
<p>
Oops, something went wrong.

0 comments on commit ad5d83f

Please sign in to comment.