/** * Generate client js * * @todo this is going to need tests to cover all the options */ function generateClient() { $headers = array(); ob_start(); // create a list list of js files were going to need to output // index is the full file and so is the value, this keeps duplicates out of $fileList $fileList = array(); if (!is_array($this->options['client'])) { $this->options['client'] = array(); } foreach ($this->options['client'] as $library) { if (isset($this->javascriptLibraries[$library])) { $lib = (array) $this->javascriptLibraries[$library]; foreach ($lib as $file) { if (isset($this->javascriptLibraryPaths[$library])) { $fileList[$this->javascriptLibraryPaths[$library] . $file] = $this->javascriptLibraryPaths[$library] . $file; } else { $fileList[$this->clientJsLocation() . $file] = $this->clientJsLocation() . $file; } } } } // do needed class init if were running an init server if (!is_array($this->options['stub'])) { $this->options['stub'] = array(); } $classList = $this->options['stub']; if ($this->initMethods) { if (isset($this->options['stub'][0]) && $this->options['stub'][0] === 'all') { $this->_initAll(); } else { foreach ($this->options['stub'] as $stub) { $this->_init($stub); } } } if (isset($this->options['stub'][0]) && $this->options['stub'][0] === 'all') { $classList = array_keys($this->ajax->_exportedInstances); } // if were doing stub and client we have to wait for both ETags before we can compare with the client $combinedOutput = false; if ($classList != false && count($classList) > 0 && count($fileList) > 0) { $combinedOutput = true; } if ($classList != false && count($classList) > 0) { // were setup enough to make a stubETag if the input it wants is a class list if ($this->cacheOptions['httpCacheStub'] && $this->cacheOptions['StubCacheExpects'] == 'classes') { $stubETag = $this->_callCacheRule('Stub', $classList); } // if were not in combined output compare etags, if method returns true were done if (!$combinedOutput && isset($stubETag)) { if ($this->_compareEtags($stubETag)) { ob_end_clean(); return; } } // output the stubs for all the classes in our list foreach ($classList as $class) { echo $this->ajax->generateClassStub($class); } // if were cacheing and the rule expects content make a tag and check it, if the check is true were done if ($this->cacheOptions['httpCacheStub'] && $this->cacheOptions['StubCacheExpects'] == 'content') { $stubETag = $this->_callCacheRule('Stub', ob_get_contents()); } // if were not in combined output compare etags, if method returns true were done if (!$combinedOutput && isset($stubETag)) { if ($this->_compareEtags($stubETag)) { ob_end_clean(); return; } } } if (count($fileList) > 0) { // if were caching and need a file list build our jsETag if ($this->cacheOptions['httpCacheClient'] && $this->cacheOptions['ClientCacheExpects'] === 'files') { $jsETag = $this->_callCacheRule('Client', $fileList); } // if were not in combined output compare etags, if method returns true were done if (!$combinedOutput && isset($jsETag)) { if ($this->_compareEtags($jsETag)) { ob_end_clean(); return; } } // output the needed client js files foreach ($fileList as $file) { $this->_readFile($file); } // if were caching and need content build the etag if ($this->cacheOptions['httpCacheClient'] && $this->cacheOptions['ClientCacheExpects'] === 'content') { $jsETag = $this->_callCacheRule('Client', ob_get_contents()); } // if were not in combined output compare etags, if method returns true were done if (!$combinedOutput && isset($jsETag)) { if ($this->_compareEtags($jsETag)) { ob_end_clean(); return; } } else { if (isset($jsETag) && isset($stubETag)) { if ($this->_compareEtags(md5($stubETag . $jsETag))) { ob_end_clean(); return; } } } } // were outputting content, add our length header and send the output $length = ob_get_length(); $output = ob_get_contents(); ob_end_clean(); if ($this->ajax->packJavaScript) { $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-Type'] = 'text/javascript; charset=utf-8'; $this->ajax->_sendHeaders($headers); echo $output; }
/** * A simple script to build a single js file from the multiple sources * @license http://www.opensource.org/licenses/lgpl-license.php LGPL */ // simple script contains a merged js file from multiple source files // can optionaly strip whitespace require_once 'HTML/AJAX.php'; $dest = "HTML_AJAX.js"; if (isset($argv[1])) { $dest = $argv[1]; } $strip = false; if (isset($argv[2]) && $argv[2] == 'strip') { $strip = true; } $source = array('Compat.js', 'Main.js', 'Queue.js', 'clientPool.js', 'IframeXHR.js', 'serializer/UrlSerializer.js', 'serializer/phpSerializer.js', 'Dispatcher.js', 'HttpClient.js', 'Request.js', 'serializer/JSON.js', 'serializer/haSerializer.js', 'Loading.js', 'util.js', 'behavior/behavior.js', 'behavior/cssQuery-p.js'); $out = ''; $ajax = new HTML_AJAX(); foreach ($source as $file) { if ($strip) { $s = $ajax->packJavaScript(file_get_contents($file)); } else { $s = file_get_contents($file); } $out .= "// {$file}\n"; $out .= $s; } $fp = fopen($dest, 'w'); fwrite($fp, $out); fclose($fp);