Initial commit: Kimai TMS
Kimai time management system (PHP 5.6 / MySQL) with custom extensions: - Budget tracking (ki_budget) - Change request form (ki_changerequest) - Invoice generation (ki_invoice) - Expense tracking (ki_expenses) - Flexi time (ki_flexitime) - Export, admin panel, timesheets, tasks, summary Database: ~900K time entries, 2,000+ users, 439 projects. Config: includes/autoconf.php — localhost/kimai/kimai
This commit is contained in:
312
libraries/xajax/xajax_plugins/response/comet/comet.inc.php
Normal file
312
libraries/xajax/xajax_plugins/response/comet/comet.inc.php
Normal file
@@ -0,0 +1,312 @@
|
||||
<?php
|
||||
define('FILE_APPEND', 1);
|
||||
|
||||
/*
|
||||
File: tableUpdater.inc.php
|
||||
|
||||
Contains a class that can be used to invoke DOM calls on the browser which
|
||||
will create or update an HTML table.
|
||||
|
||||
Title: clsTableUpdater class
|
||||
|
||||
Please see <copyright.inc.php> for a detailed description, copyright
|
||||
and license information.
|
||||
*/
|
||||
|
||||
if (false == class_exists('xajaxPlugin') || false == class_exists('xajaxPluginManager'))
|
||||
{
|
||||
$sBaseFolder = dirname(dirname(dirname(__FILE__)));
|
||||
$sXajaxCore = $sBaseFolder . '/xajax_core';
|
||||
|
||||
if (false == class_exists('xajaxPlugin'))
|
||||
require $sXajaxCore . '/xajaxPlugin.inc.php';
|
||||
if (false == class_exists('xajaxPluginManager'))
|
||||
require $sXajaxCore . '/xajaxPluginManager.inc.php';
|
||||
}
|
||||
|
||||
//require_once dirname(__FILE__) . '/xajaxCometPlugin.inc.php';
|
||||
|
||||
/*
|
||||
Class: clsTableUpdater
|
||||
*/
|
||||
class clsCometStreaming extends xajaxResponsePlugin
|
||||
{
|
||||
/*
|
||||
String: sDefer
|
||||
|
||||
Used to store the state of the scriptDeferral configuration setting. When
|
||||
script deferral is desired, this member contains 'defer' which will request
|
||||
that the browser defer loading of the javascript until the rest of the page
|
||||
has been loaded.
|
||||
*/
|
||||
var $sDefer;
|
||||
|
||||
/*
|
||||
String: sJavascriptURI
|
||||
|
||||
Used to store the base URI for where the javascript files are located. This
|
||||
enables the plugin to generate a script reference to it's javascript file
|
||||
if the javascript code is NOT inlined.
|
||||
*/
|
||||
var $sJavascriptURI;
|
||||
|
||||
/*
|
||||
Boolean: bInlineScript
|
||||
|
||||
Used to store the value of the inlineScript configuration option. When true,
|
||||
the plugin will return it's javascript code as part of the javascript header
|
||||
for the page, else, it will generate a script tag referencing the file by
|
||||
using the <clsTableUpdater->sJavascriptURI>.
|
||||
*/
|
||||
var $bInlineScript;
|
||||
|
||||
/*
|
||||
Function: clsTableUpdater
|
||||
|
||||
Constructs and initializes an instance of the table updater class.
|
||||
*/
|
||||
function clsCometStreaming()
|
||||
{
|
||||
$this->sDefer = '';
|
||||
$this->sJavascriptURI = '';
|
||||
$this->bInlineScript = false;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: configure
|
||||
|
||||
Receives configuration settings set by <xajax> or user script calls to
|
||||
<xajax->configure>.
|
||||
|
||||
sName - (string): The name of the configuration option being set.
|
||||
mValue - (mixed): The value being associated with the configuration option.
|
||||
*/
|
||||
function configure($sName, $mValue)
|
||||
{
|
||||
if ('scriptDeferral' == $sName) {
|
||||
if (true === $mValue || false === $mValue) {
|
||||
if ($mValue) $this->sDefer = 'defer ';
|
||||
else $this->sDefer = '';
|
||||
}
|
||||
} else if ('javascript URI' == $sName) {
|
||||
$this->sJavascriptURI = $mValue;
|
||||
} else if ('inlineScript' == $sName) {
|
||||
if (true === $mValue || false === $mValue)
|
||||
$this->bInlineScript = $mValue;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: generateClientScript
|
||||
|
||||
Called by the <xajaxPluginManager> during the script generation phase. This
|
||||
will either inline the script or insert a script tag which references the
|
||||
<tableUpdater.js> file based on the value of the <clsTableUpdater->bInlineScript>
|
||||
configuration option.
|
||||
*/
|
||||
function generateClientScript()
|
||||
{
|
||||
if ($this->bInlineScript)
|
||||
{
|
||||
echo "\n<script type='text/javascript' " . $this->sDefer . "charset='UTF-8'>\n";
|
||||
echo "/* <![CDATA[ */\n";
|
||||
|
||||
include(dirname(__FILE__) . 'xajax_plugins/response/comet/comet.js');
|
||||
|
||||
echo "/* ]]> */\n";
|
||||
echo "</script>\n";
|
||||
} else {
|
||||
echo "\n<script type='text/javascript' src='" . $this->sJavascriptURI . "xajax_plugins/response/comet/comet.js' " . $this->sDefer . "charset='UTF-8'></script>\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class xajaxCometResponse extends xajaxResponse
|
||||
{
|
||||
var $bHeaderSent = false;
|
||||
|
||||
|
||||
/*
|
||||
Function: xajaxCometResponse
|
||||
|
||||
calls parent function xajaxResponse();
|
||||
*/
|
||||
|
||||
|
||||
function xajaxCometResponse()
|
||||
{
|
||||
parent::xajaxResponse();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: printOutput
|
||||
|
||||
override the original printOutput function. It's no longer needed since the output is already sent.
|
||||
*/
|
||||
|
||||
function printOutput()
|
||||
{
|
||||
if ( "HTML5DRAFT" == $_GET['xjxstreaming']) {
|
||||
|
||||
$response = "";
|
||||
$response .= "Event: xjxendstream\n";
|
||||
$response .= "data: done\n";
|
||||
$response .= "\n";
|
||||
print $response;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Function: flush_XHR
|
||||
|
||||
Flushes the command queue for comet browsers.
|
||||
*/
|
||||
|
||||
function flush_XHR()
|
||||
{
|
||||
|
||||
if (!$this->bHeaderSent)
|
||||
{
|
||||
$this->_sendHeaders();
|
||||
$this->bHeaderSent=true;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$this->_printResponse_XML();
|
||||
$c = ob_get_contents();
|
||||
ob_get_clean();
|
||||
$c = str_replace(chr(1)," ",$c);
|
||||
$c = str_replace(chr(2)," ",$c);
|
||||
$c = str_replace(chr(31)," ",$c);
|
||||
$c = str_replace(""," ",$c);
|
||||
if ($c == "<xjx></xjx>") return false;
|
||||
print $c;
|
||||
ob_flush();
|
||||
flush();
|
||||
$this->sleep(1.1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: flush_activeX
|
||||
|
||||
Flushes the command queue for ActiveX browsers.
|
||||
*/
|
||||
|
||||
function flush_activeX()
|
||||
{
|
||||
ob_start();
|
||||
$this->_printResponse_XML();
|
||||
$c = ob_get_contents();
|
||||
ob_get_clean();
|
||||
|
||||
$c = '<?xml version="1.0" ?>'.$c;
|
||||
$c = str_replace('"','\"',$c);
|
||||
$c = str_replace("\n",'\n',$c);
|
||||
$c = str_replace("\r",'\r',$c);
|
||||
|
||||
$response = "";
|
||||
$response .= "<script>top.document.callback(\"";
|
||||
$response .= $c;
|
||||
$response .= "\");</script>";
|
||||
|
||||
print $response;
|
||||
ob_flush();
|
||||
flush();
|
||||
$this->sleep(0.99);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: flush_HTML5DRAFT
|
||||
|
||||
Flushes the command queue for HTML5DRAFT browsers.
|
||||
*/
|
||||
|
||||
function flush_HTML5DRAFT()
|
||||
{
|
||||
|
||||
|
||||
if (!$this->bHeaderSent)
|
||||
{
|
||||
header("Content-Type: application/x-dom-event-stream");
|
||||
$this->bHeaderSent=1;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$this->_printResponse_XML();
|
||||
$c = ob_get_contents();
|
||||
ob_get_clean();
|
||||
$c = str_replace("\n",'\n',$c);
|
||||
$c = str_replace("\r",'\r',$c);
|
||||
$response = "";
|
||||
$response .= "Event: xjxstream\n";
|
||||
$response .= "data: $c\n";
|
||||
$response .= "\n";
|
||||
print $response;
|
||||
ob_flush();
|
||||
flush();
|
||||
$this->sleep(1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: flush
|
||||
|
||||
Determines which browser is wating for a response and calls the according flush function.
|
||||
*/
|
||||
function flush()
|
||||
{
|
||||
if (0 == count($this->aCommands)) return false;
|
||||
if ("xhr" == $_SERVER['HTTP_STREAMING'])
|
||||
{
|
||||
$this->flush_XHR();
|
||||
}
|
||||
elseif ( "HTML5DRAFT" == $_GET['xjxstreaming'])
|
||||
{
|
||||
$this->flush_HTML5DRAFT();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->flush_activeX();
|
||||
}
|
||||
$this->aCommands=array();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: sleep
|
||||
|
||||
Very accurate sleep function.
|
||||
*/
|
||||
function sleep($seconds)
|
||||
{
|
||||
usleep(floor($seconds*1000000));
|
||||
}
|
||||
|
||||
|
||||
function file_put_contents($n, $d, $flag = false)
|
||||
{
|
||||
$mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
|
||||
$f = @fopen($n, $mode);
|
||||
if ($f === false)
|
||||
{
|
||||
return 0;
|
||||
} else
|
||||
{
|
||||
if (is_array($d)) $d = implode($d);
|
||||
$bytes_written = fwrite($f, $d);
|
||||
fclose($f);
|
||||
return $bytes_written;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$objPluginManager =& xajaxPluginManager::getInstance();
|
||||
$objPluginManager->registerPlugin(new clsCometStreaming());
|
||||
516
libraries/xajax/xajax_plugins/response/comet/comet.js
Normal file
516
libraries/xajax/xajax_plugins/response/comet/comet.js
Normal file
@@ -0,0 +1,516 @@
|
||||
/*
|
||||
File: comet.js
|
||||
|
||||
Title: Comet plugin for xajax
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
@package comet plugin
|
||||
@version $Id:
|
||||
@copyright Copyright (c) 2007 by Steffen Konerow (IE)
|
||||
@license http://www.xajaxproject.org/bsd_license.txt BSD License
|
||||
*/
|
||||
|
||||
/*
|
||||
Class: xajax.ext.comet
|
||||
|
||||
This class contains all functions for using comet streaming with xajax.
|
||||
|
||||
*/
|
||||
|
||||
try {
|
||||
if (undefined == xajax.ext)
|
||||
xajax.ext = {};
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (undefined == xajax.ext.comet)
|
||||
xajax.ext.comet = {};
|
||||
} catch (e) {
|
||||
alert("Could not create xajax.ext.comet namespace");
|
||||
}
|
||||
|
||||
// create Shorthand for xajax.ext.comet
|
||||
xjxEc = xajax.ext.comet;
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: detectSupport
|
||||
|
||||
Detects browser for using fallback methods instead of multipart XHR responses.
|
||||
*/
|
||||
xjxEc.detectSupport = function()
|
||||
{
|
||||
|
||||
|
||||
var agt=navigator.userAgent.toLowerCase();
|
||||
if (agt.indexOf("opera") != -1) return 'Opera';
|
||||
if (agt.indexOf("staroffice") != -1) return 'Star Office';
|
||||
if (agt.indexOf("webtv") != -1) return 'WebTV';
|
||||
if (agt.indexOf("beonex") != -1) return 'Beonex';
|
||||
if (agt.indexOf("chimera") != -1) return 'Chimera';
|
||||
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
|
||||
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
|
||||
if (agt.indexOf("firefox") != -1) return 'Firefox';
|
||||
if (agt.indexOf("safari") != -1) return 'Safari';
|
||||
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
|
||||
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
|
||||
if (agt.indexOf("netscape") != -1) return 'Netscape';
|
||||
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
|
||||
if (agt.indexOf('\/') != -1)
|
||||
{
|
||||
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla')
|
||||
{
|
||||
return navigator.userAgent.substr(0,agt.indexOf('\/'));
|
||||
}
|
||||
else return 'Netscape';
|
||||
}
|
||||
else if (agt.indexOf(' ') != -1) return navigator.userAgent.substr(0,agt.indexOf(' '));
|
||||
else return navigator.userAgent;
|
||||
|
||||
// if (navigator.appVersion.indexOf("MSIE")!=-1)
|
||||
// {
|
||||
// var version,temp;
|
||||
// temp=navigator.appVersion.split("MSIE")
|
||||
// version=parseFloat(temp[1])
|
||||
// if (version>=5.5) return "MSIE";
|
||||
// }
|
||||
// if ( "undefined" != typeof window.opera )
|
||||
// {
|
||||
// return "OPERA";
|
||||
// }
|
||||
// if ( "undefined" != typeof window.Iterator )
|
||||
// {
|
||||
// return "FF2";
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Function: prepareRequestXHR
|
||||
|
||||
Prepares the XMLHttpRequest object for this xajax request in FF/Safari browsers.
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequestXHR = function (oRequest)
|
||||
{
|
||||
if (true == oRequest.comet)
|
||||
{
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
oRequest.request = xt.getRequestObject();
|
||||
|
||||
oRequest.setRequestHeaders = function(headers) {
|
||||
if ('object' == typeof headers) {
|
||||
for (var optionName in headers)
|
||||
this.request.setRequestHeader(optionName, headers[optionName]);
|
||||
}
|
||||
}
|
||||
oRequest.setCommonRequestHeaders = function() {
|
||||
this.setRequestHeaders(this.commonHeaders);
|
||||
}
|
||||
oRequest.setPostRequestHeaders = function() {
|
||||
this.setRequestHeaders(this.postHeaders);
|
||||
}
|
||||
oRequest.setGetRequestHeaders = function() {
|
||||
this.setRequestHeaders(this.getHeaders);
|
||||
}
|
||||
|
||||
|
||||
oRequest.applyRequestHeaders = function() {
|
||||
}
|
||||
|
||||
oRequest.setCommonRequestHeaders = function() {
|
||||
this.request.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
|
||||
this.request.setRequestHeader('streaming', 'xhr');
|
||||
|
||||
if (typeof(oRequest.header) == "object")
|
||||
{
|
||||
for (a in oRequest.header)
|
||||
this.request.setRequestHeader(a, oRequest.header[a]);
|
||||
}
|
||||
}
|
||||
oRequest.comet = {};
|
||||
oRequest.comet.LastPosition = 0;
|
||||
|
||||
var pollLatestResponse = function() {
|
||||
xjxEc.responseProcessor.XHR(oRequest);
|
||||
}
|
||||
oRequest.pollTimer = setInterval(pollLatestResponse, 80);
|
||||
oRequest.request.onreadystatechange = function()
|
||||
{
|
||||
if (oRequest.request.readyState < 3)
|
||||
return;
|
||||
|
||||
if (oRequest.request.readyState == 4)
|
||||
{
|
||||
clearInterval(oRequest.pollTimer);
|
||||
xjxEc.responseProcessor.XHR(oRequest);
|
||||
|
||||
//xajax.responseReceived(oRequest);
|
||||
xajax.completeResponse(oRequest);
|
||||
return;
|
||||
}
|
||||
}
|
||||
oRequest.finishRequest = function()
|
||||
{
|
||||
return this.returnValue;
|
||||
}
|
||||
|
||||
if ('undefined' != typeof oRequest.userName && 'undefined' != typeof oRequest.password)
|
||||
{
|
||||
oRequest.open = function()
|
||||
{
|
||||
this.request.open(
|
||||
this.method,
|
||||
this.requestURI,
|
||||
true,
|
||||
oRequest.userName,
|
||||
oRequest.password);
|
||||
}
|
||||
} else
|
||||
{
|
||||
oRequest.open = function()
|
||||
{
|
||||
this.request.open(
|
||||
this.method,
|
||||
this.requestURI,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
if ('POST' == oRequest.method) { // W3C: Method is case sensitive
|
||||
oRequest.applyRequestHeaders = function() {
|
||||
this.setCommonRequestHeaders();
|
||||
try {
|
||||
this.setPostRequestHeaders();
|
||||
} catch (e) {
|
||||
this.method = 'GET';
|
||||
this.requestURI += this.requestURI.indexOf('?')== -1 ? '?' : '&';
|
||||
this.requestURI += this.requestData;
|
||||
this.requestData = '';
|
||||
if (0 == this.requestRetry) this.requestRetry = 1;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
oRequest.applyRequestHeaders = function() {
|
||||
this.setCommonRequestHeaders();
|
||||
this.setGetRequestHeaders();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
return xjxEc.prepareRequest(oRequest);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: connect_htmlfile
|
||||
|
||||
Create a hidden iframe for IE
|
||||
|
||||
*/
|
||||
xjxEc.connect_htmlfile = function (url, callback,oRequest)
|
||||
{
|
||||
|
||||
try {
|
||||
xjxEc.transferDoc = new ActiveXObject("htmlfile");
|
||||
xjxEc.transferDoc.open();
|
||||
xjxEc.transferDoc.write("<html>");
|
||||
xjxEc.transferDoc.write("<script>document.domain='http://192.168.1.21/';</script>");
|
||||
xjxEc.transferDoc.write("</html>");
|
||||
xjxEc.transferDoc.close();
|
||||
xjxEc.ifrDiv = xjxEc.transferDoc.createElement("div");
|
||||
xjxEc.transferDoc.body.appendChild(xjxEc.ifrDiv);
|
||||
xjxEc.ifrDiv.innerHTML = "<iframe src='" + url + "'></iframe>";
|
||||
xjxEc.transferDoc.callback = function (response) {
|
||||
callback(response,oRequest);
|
||||
};
|
||||
} catch (ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Function: prepareRequestActiveX
|
||||
|
||||
Prepares the Iframe for streaming with active X
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequestActiveX = function(oRequest) {
|
||||
if (true == oRequest.comet) {
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
oRequest.requestURI += oRequest.requestURI.indexOf('?')== -1 ? '?' : '&';
|
||||
oRequest.requestURI += oRequest.requestData;
|
||||
oRequest.requestData = '';
|
||||
try {
|
||||
xjxEc.connect_htmlfile(oRequest.requestURI,xjxEc.responseProcessor.ActiveX,oRequest);
|
||||
if (0 < oRequest.requestRetry) oRequest.requestRetry = 0;
|
||||
} catch (ex) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
return xjxEc.prepareRequest(oRequest);
|
||||
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Function: prepareRequestHTMLDRAFT
|
||||
|
||||
Prepares streaming with HTML 5 Draft
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.prepareRequestHTMLDRAFT = function(oRequest) {
|
||||
if (true == oRequest.comet) {
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
oRequest.requestURI += oRequest.requestURI.indexOf('?')== -1 ? '?' : '&';
|
||||
oRequest.requestURI += oRequest.requestData;
|
||||
oRequest.requestURI += "&xjxstreaming=HTML5DRAFT";
|
||||
try {
|
||||
var uri = oRequest.requestURI;
|
||||
var es = document.createElement("event-source");
|
||||
es.setAttribute("src", uri);
|
||||
es.setAttribute("width", 200);
|
||||
es.setAttribute("height", 200);
|
||||
es.style.display="block";
|
||||
callback = function(event)
|
||||
{
|
||||
xjxEc.responseProcessor.HTMLDRAFT(event.data,oRequest);
|
||||
};
|
||||
remove = function() {
|
||||
es.removeEventListener("xjxstream",callback,false);
|
||||
es.removeEventListener("xjxendstream",remove,false);
|
||||
//document.body.removeChild(es);
|
||||
}
|
||||
|
||||
es.addEventListener("xjxstream",callback,false);
|
||||
es.addEventListener("xjxendstream",remove,false);
|
||||
document.body.appendChild(es);
|
||||
if (0 < oRequest.requestRetry) oRequest.requestRetry = 0;
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
}
|
||||
return;
|
||||
}
|
||||
return xjxEc.prepareRequest(oRequest);
|
||||
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: responseProcessor.XHR
|
||||
|
||||
Processes the streaming response for FF/Safari
|
||||
|
||||
*/
|
||||
xajax.debug={};
|
||||
xajax.debug.prepareDebugText = function(text) {
|
||||
try {
|
||||
text = text.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/\n/g, '<br />');
|
||||
return text;
|
||||
} catch (e) {
|
||||
xajax.debug.stringReplace = function(haystack, needle, newNeedle) {
|
||||
var segments = haystack.split(needle);
|
||||
haystack = '';
|
||||
for (var i = 0; i < segments.length; ++i) {
|
||||
if (0 != i)
|
||||
haystack += newNeedle;
|
||||
haystack += segments[i];
|
||||
}
|
||||
return haystack;
|
||||
}
|
||||
xajax.debug.prepareDebugText = function(text) {
|
||||
text = xajax.debug.stringReplace(text, '&', '&');
|
||||
text = xajax.debug.stringReplace(text, '<', '<');
|
||||
text = xajax.debug.stringReplace(text, '>', '>');
|
||||
text = xajax.debug.stringReplace(text, '\n', '<br />');
|
||||
return text;
|
||||
}
|
||||
xajax.debug.prepareDebugText(text);
|
||||
}
|
||||
}
|
||||
xjxEc.responseProcessor={}
|
||||
|
||||
|
||||
xjxEc.responseProcessor.XHR = function(oRequest) {
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
var oRet = oRequest.returnValue;
|
||||
if ("" == oRequest.request.responseText) return;
|
||||
var allMessages = oRequest.request.responseText;
|
||||
do {
|
||||
var unprocessed = allMessages.substring(oRequest.comet.LastPosition);
|
||||
var messageXMLEndIndex = unprocessed.indexOf("</xjx>");
|
||||
if (messageXMLEndIndex!=-1) {
|
||||
var endOfFirstMessageIndex = messageXMLEndIndex + "</xjx>".length;
|
||||
var anUpdate = unprocessed.substring(0, endOfFirstMessageIndex);
|
||||
|
||||
var cmd = (new DOMParser()).parseFromString(anUpdate, "text/xml");
|
||||
try {
|
||||
var seq = 0;
|
||||
var child = cmd.documentElement.firstChild;
|
||||
xt.xml.processFragment(child, seq, oRequest);
|
||||
} catch (ex) {
|
||||
}
|
||||
xt.queue.process(xx.response);
|
||||
oRequest.comet.LastPosition += endOfFirstMessageIndex;
|
||||
}
|
||||
} while (messageXMLEndIndex != -1);
|
||||
|
||||
return oRet;
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: responseProcessor.ActiveX
|
||||
|
||||
Processes the streaming response for IE
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.responseProcessor.ActiveX = function(response,oRequest) {
|
||||
|
||||
response.replace('\"','"');
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
var oRet = oRequest.returnValue;
|
||||
if (response) {
|
||||
var cmd = (new DOMParser()).parseFromString(response, "text/xml");
|
||||
var seq=0;
|
||||
var child = cmd.documentElement.firstChild;
|
||||
xt.xml.processFragment(child, seq, oRequest);
|
||||
|
||||
if (null == xx.response.timeout)
|
||||
xt.queue.process(xx.response);
|
||||
}
|
||||
return oRet;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
Function: responseProcessor.HTMLDRAFT
|
||||
|
||||
Processes the streaming response for HTML 5 Draft Browsers (Opera 9+)
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.responseProcessor.HTMLDRAFT = function(response,oRequest) {
|
||||
var xx = xajax;
|
||||
var xt = xx.tools;
|
||||
var xcb = xx.callback;
|
||||
var gcb = xcb.global;
|
||||
var lcb = oRequest.callback;
|
||||
var oRet = oRequest.returnValue;
|
||||
if (response) {
|
||||
var cmd = (new DOMParser()).parseFromString(response, "text/xml");
|
||||
var seq=0;
|
||||
var child = cmd.documentElement.firstChild;
|
||||
xt.xml.processFragment(child, seq, oRequest);
|
||||
|
||||
if (null == xx.response.timeout)
|
||||
xt.queue.process(xx.response);
|
||||
|
||||
}
|
||||
return oRet;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
Function: submitRequestActiveX
|
||||
|
||||
Supresses the xajax.submitRequest() function call for IE in streaming calls.
|
||||
|
||||
*/
|
||||
|
||||
xjxEc.submitRequestActiveX = function(oRequest) {
|
||||
if (true == oRequest.comet) return;
|
||||
xjxEc.submitRequest(oRequest);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
variable setup. Detects IE and replaces the according functions
|
||||
|
||||
*/
|
||||
|
||||
|
||||
xjxEc.prepareRequest = xajax.prepareRequest;
|
||||
|
||||
xjxEc.stream_support = xjxEc.detectSupport();
|
||||
switch (xjxEc.stream_support)
|
||||
{
|
||||
case "Internet Explorer" :
|
||||
xajax.prepareRequest = xjxEc.prepareRequestActiveX;
|
||||
xjxEc.submitRequest=xajax.submitRequest;
|
||||
xajax.submitRequest=xjxEc.submitRequestActiveX;
|
||||
break;
|
||||
case "Firefox" :
|
||||
case "Safari" :
|
||||
xajax.prepareRequest = xjxEc.prepareRequestXHR;
|
||||
break;
|
||||
|
||||
|
||||
case "Opera" :
|
||||
xajax.prepareRequest = xjxEc.prepareRequestHTMLDRAFT;
|
||||
xjxEc.submitRequest=xajax.submitRequest;
|
||||
xajax.submitRequest=xjxEc.submitRequestActiveX;
|
||||
break;
|
||||
default : alert("Xajax.Ext.Comet: Your browser does not support comet streaming or is not yet supported by this plugin!");
|
||||
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
Function: DOMParser
|
||||
|
||||
Prototype DomParser for IE/Opera
|
||||
|
||||
*/
|
||||
if (typeof DOMParser == "undefined") {
|
||||
DOMParser = function () {}
|
||||
|
||||
DOMParser.prototype.parseFromString = function (str, contentType) {
|
||||
if (typeof ActiveXObject != "undefined") {
|
||||
var d = new ActiveXObject("Microsoft.XMLDOM");
|
||||
d.loadXML(str);
|
||||
return d;
|
||||
} else if (typeof XMLHttpRequest != "undefined") {
|
||||
var req = new XMLHttpRequest;
|
||||
req.open("GET", "data:" + (contentType || "application/xml") +
|
||||
";charset=utf-8," + encodeURIComponent(str), false);
|
||||
if (req.overrideMimeType) {
|
||||
req.overrideMimeType(contentType);
|
||||
}
|
||||
req.send(null);
|
||||
return req.responseXML;
|
||||
}
|
||||
}
|
||||
}
|
||||
// -------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
/*
|
||||
File: xajaxCometFunction.inc.php
|
||||
|
||||
Contains the xajaxCometFunction class
|
||||
|
||||
Title: xajaxCometFunction class
|
||||
|
||||
Please see <copyright.inc.php> for a detailed description, copyright
|
||||
and license information.
|
||||
*/
|
||||
|
||||
/*
|
||||
@package xajax
|
||||
@version $Id: xajaxCometFunction.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $
|
||||
@copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson
|
||||
@license http://www.xajaxproject.org/bsd_license.txt BSD License
|
||||
*/
|
||||
|
||||
/*
|
||||
Class: xajaxCometFunction
|
||||
|
||||
Construct instances of this class to define functions that will be registered
|
||||
with the <xajax> request processor. This class defines the parameters that
|
||||
are needed for the definition of a xajax enabled function. While you can
|
||||
still specify functions by name during registration, it is advised that you
|
||||
convert to using this class when you wish to register external functions or
|
||||
to specify call options as well.
|
||||
*/
|
||||
class xajaxCometFunction
|
||||
{
|
||||
/*
|
||||
String: sAlias
|
||||
|
||||
An alias to use for this function. This is useful when you want
|
||||
to call the same xajax enabled function with a different set of
|
||||
call options from what was already registered.
|
||||
*/
|
||||
var $sAlias;
|
||||
|
||||
/*
|
||||
Object: uf
|
||||
|
||||
A string or array which defines the function to be registered.
|
||||
*/
|
||||
var $uf;
|
||||
|
||||
/*
|
||||
String: sInclude
|
||||
|
||||
The path and file name of the include file that contains the function.
|
||||
*/
|
||||
var $sInclude;
|
||||
|
||||
/*
|
||||
Array: aConfiguration
|
||||
|
||||
An associative array containing call options that will be sent to the
|
||||
browser curing client script generation.
|
||||
*/
|
||||
var $aConfiguration;
|
||||
|
||||
/*
|
||||
Function: xajaxCometFunction
|
||||
|
||||
Constructs and initializes the <xajaxCometFunction> object.
|
||||
|
||||
$uf - (mixed): A function specification in one of the following formats:
|
||||
|
||||
- a three element array:
|
||||
(string) Alternate function name: when a method of a class has the same
|
||||
name as another function in the system, you can provide an alias to
|
||||
help avoid collisions.
|
||||
(object or class name) Class: the name of the class or an instance of
|
||||
the object which contains the function to be called.
|
||||
(string) Method: the name of the method that will be called.
|
||||
- a two element array:
|
||||
(object or class name) Class: the name of the class or an instance of
|
||||
the object which contains the function to be called.
|
||||
(string) Method: the name of the method that will be called.
|
||||
- a string:
|
||||
the name of the function that is available at global scope (not in a
|
||||
class.
|
||||
$sInclude - (string, optional): The path and file name of the include file
|
||||
that contains the class or function to be called.
|
||||
|
||||
$aConfiguration - (array, optional): An associative array of call options
|
||||
that will be used when sending the request from the client.
|
||||
|
||||
Examples:
|
||||
|
||||
$myFunction = array('alias', 'myClass', 'myMethod');
|
||||
$myFunction = array('alias', &$myObject, 'myMethod');
|
||||
$myFunction = array('myClass', 'myMethod');
|
||||
$myFunction = array(&$myObject, 'myMethod');
|
||||
$myFunction = 'myFunction';
|
||||
|
||||
$myUserFunction = new xajaxCometFunction($myFunction, 'myFile.inc.php', array(
|
||||
'method' => 'get',
|
||||
'mode' => 'synchronous'
|
||||
));
|
||||
|
||||
$xajax->register(XAJAX_FUNCTION, $myUserFunction);
|
||||
*/
|
||||
function xajaxCometFunction($uf, $sInclude=NULL, $aConfiguration=array())
|
||||
{
|
||||
$this->sAlias = '';
|
||||
$this->uf =& $uf;
|
||||
$this->sInclude = $sInclude;
|
||||
$this->aConfiguration = array();
|
||||
foreach ($aConfiguration as $sKey => $sValue)
|
||||
$this->configure($sKey, $sValue);
|
||||
|
||||
if (is_array($this->uf) && 2 < count($this->uf))
|
||||
{
|
||||
$this->sAlias = $this->uf[0];
|
||||
$this->uf = array_slice($this->uf, 1);
|
||||
}
|
||||
|
||||
//SkipDebug
|
||||
if (is_array($this->uf) && 2 != count($this->uf))
|
||||
trigger_error(
|
||||
'Invalid function declaration for xajaxCometFunction.',
|
||||
E_USER_ERROR
|
||||
);
|
||||
//EndSkipDebug
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getName
|
||||
|
||||
Get the name of the function being referenced.
|
||||
|
||||
Returns:
|
||||
|
||||
string - the name of the function contained within this object.
|
||||
*/
|
||||
function getName()
|
||||
{
|
||||
// Do not use sAlias here!
|
||||
if (is_array($this->uf))
|
||||
return $this->uf[1];
|
||||
return $this->uf;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: configure
|
||||
|
||||
Call this to set call options for this instance.
|
||||
*/
|
||||
function configure($sName, $sValue)
|
||||
{
|
||||
if ('alias' == $sName)
|
||||
$this->sAlias = $sValue;
|
||||
else
|
||||
$this->aConfiguration[$sName] = $sValue;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: generateRequest
|
||||
|
||||
Constructs and returns a <xajaxRequest> object which is capable
|
||||
of generating the javascript call to invoke this xajax enabled
|
||||
function.
|
||||
*/
|
||||
function generateRequest($sXajaxPrefix)
|
||||
{
|
||||
$sAlias = $this->getName();
|
||||
if (0 < strlen($this->sAlias))
|
||||
$sAlias = $this->sAlias;
|
||||
return new xajaxRequest("{$sXajaxPrefix}{$sAlias}");
|
||||
}
|
||||
|
||||
/*
|
||||
Function: generateClientScript
|
||||
|
||||
Called by the <xajaxPlugin> that is referencing this function
|
||||
reference during the client script generation phase. This function
|
||||
will generate the javascript function stub that is sent to the
|
||||
browser on initial page load.
|
||||
*/
|
||||
function generateClientScript($sXajaxPrefix)
|
||||
{
|
||||
$sFunction = $this->getName();
|
||||
$sAlias = $sFunction;
|
||||
if (0 < strlen($this->sAlias))
|
||||
$sAlias = $this->sAlias;
|
||||
echo "{$sXajaxPrefix}{$sAlias} = function() { ";
|
||||
echo "return xajax.request( ";
|
||||
echo "{ xjxcomet: '{$sFunction}' }, ";
|
||||
echo "{ parameters: arguments, mode:'comet'";
|
||||
|
||||
$sSeparator = ", ";
|
||||
foreach ($this->aConfiguration as $sKey => $sValue)
|
||||
echo "{$sSeparator}{$sKey}: {$sValue}";
|
||||
|
||||
echo " } ); ";
|
||||
echo "};\n";
|
||||
}
|
||||
|
||||
/*
|
||||
Function: call
|
||||
|
||||
Called by the <xajaxPlugin> that references this function during the
|
||||
request processing phase. This function will call the specified
|
||||
function, including an external file if needed and passing along
|
||||
the specified arguments.
|
||||
*/
|
||||
function call($aArgs=array())
|
||||
{
|
||||
$objResponseManager =& xajaxResponseManager::getInstance();
|
||||
|
||||
if (NULL != $this->sInclude)
|
||||
{
|
||||
ob_start();
|
||||
require_once $this->sInclude;
|
||||
$sOutput = ob_get_clean();
|
||||
|
||||
//SkipDebug
|
||||
if (0 < strlen($sOutput))
|
||||
{
|
||||
$sOutput = 'From include file: ' . $this->sInclude . ' => ' . $sOutput;
|
||||
$objResponseManager->debug($sOutput);
|
||||
}
|
||||
//EndSkipDebug
|
||||
}
|
||||
|
||||
$mFunction = $this->uf;
|
||||
$objResponseManager->append(call_user_func_array($mFunction, $aArgs));
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user