@ -99,7 +99,7 @@ class xajaxResponse
* converted to HTML entities
*
*/
public function __construct($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities= false)
public function __construct($sEncoding = XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities = false)
{
$this->setCharEncoding($sEncoding);
$this->bOutputEntities = $bOutputEntities;
@ -114,7 +114,7 @@ class xajaxResponse
*
* @param string
*/
function setCharEncoding($sEncoding)
public function setCharEncoding($sEncoding)
{
$this->sEncoding = $sEncoding;
}
@ -132,7 +132,7 @@ class xajaxResponse
* Tells the response object to output special characters intact. (default
* behavior)
*/
function outputEntitiesOff()
public function outputEntitiesOff()
{
$this->bOutputEntities = false;
}
@ -146,9 +146,9 @@ class xajaxResponse
* Cancel in the browsers's confirm dialog
* @param string the message to show in the browser's confirm dialog
*/
function addConfirmCommands($iCmdNumber, $sMessage)
public function addConfirmCommands($iCmdNumber, $sMessage)
{
$this->xml .= $this->_cmdXML(array("n"=>"cc","t"=>$iCmdNumber),$sMessage);
$this->xml .= $this->_cmdXML(array("n" => "cc", "t" => $iCmdNumber), $sMessage);
}
/**
@ -161,9 +161,9 @@ class xajaxResponse
* "value", etc.)
* @param string the data you want to set the attribute to
*/
function addAssign($sTarget,$sAttribute, $sData)
public function addAssign($sTarget, $sAttribute, $sData)
{
$this->xml .= $this->_cmdXML(array("n"=>"as","t"=>$sTarget,"p"=>$sAttribute),$sData);
$this->xml .= $this->_cmdXML(array("n" => "as", "t" => $sTarget, "p" => $sAttribute), $sData);
}
/**
@ -176,9 +176,9 @@ class xajaxResponse
* "value", etc.)
* @param string the data you want to append to the end of the attribute
*/
function addAppend($sTarget,$sAttribute, $sData)
public function addAppend($sTarget, $sAttribute, $sData)
{
$this->xml .= $this->_cmdXML(array("n"=>"ap","t"=>$sTarget,"p"=>$sAttribute),$sData);
$this->xml .= $this->_cmdXML(array("n" => "ap", "t" => $sTarget, "p" => $sAttribute), $sData);
}
/**
@ -192,9 +192,9 @@ class xajaxResponse
* @param string the data you want to prepend to the beginning of the
* attribute
*/
function addPrepend($sTarget,$sAttribute, $sData)
public function addPrepend($sTarget, $sAttribute, $sData)
{
$this->xml .= $this->_cmdXML(array("n"=>"pp","t"=>$sTarget,"p"=>$sAttribute),$sData);
$this->xml .= $this->_cmdXML(array("n" => "pp", "t" => $sTarget, "p" => $sAttribute), $sData);
}
/**
@ -209,10 +209,10 @@ class xajaxResponse
* @param string the string to replace the search string when found in the
* attribute
*/
function addReplace($sTarget,$sAttribute,$sSearch, $sData)
public function addReplace($sTarget, $sAttribute, $sSearch, $sData)
{
$sDta = "< s > <![CDATA[$sSearch]]> < / s > < r > <![CDATA[$sData]]> < / r > ";
$this->xml .= $this->_cmdXML(array("n"=>"rp","t"=>$sTarget,"p"=>$sAttribute),$sDta);
$this->xml .= $this->_cmdXML(array("n" => "rp", "t" => $sTarget, "p" => $sAttribute), $sDta);
}
/**
@ -224,9 +224,9 @@ class xajaxResponse
* @param string the part of the element you wish to clear ("innerHTML",
* "value", etc.)
*/
function addClear($sTarget, $sAttribute)
public function addClear($sTarget, $sAttribute)
{
$this->addAssign($sTarget,$sAttribute, '');
$this->addAssign($sTarget, $sAttribute, '');
}
/**
@ -236,9 +236,9 @@ class xajaxResponse
*
* @param string the text to be displayed in the Javascript alert box
*/
function addAlert($sMsg)
public function addAlert($sMsg)
{
$this->xml .= $this->_cmdXML(array("n"=>"al"),$sMsg);
$this->xml .= $this->_cmdXML(array("n" => "al"), $sMsg);
}
/**
@ -248,24 +248,23 @@ class xajaxResponse
*
* @param string the URL to redirect the client browser to
*/
function addRedirect($sURL)
public function addRedirect($sURL)
{
//we need to parse the query part so that the values are rawurlencode()'ed
//can't just use parse_url() cos we could be dealing with a relative URL which
// parse_url() can't deal with.
$queryStart = strpos($sURL, '?', strrpos($sURL, '/'));
if ($queryStart !== FALSE)
{
if ($queryStart !== false) {
$queryStart++;
$queryEnd = strpos($sURL, '#', $queryStart);
if ($queryEnd === FALSE)
if ($queryEnd === false) {
$queryEnd = strlen($sURL);
$queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart);
}
$queryPart = substr($sURL, $queryStart, $queryEnd - $queryStart);
$queryParts = array();
parse_str($queryPart, $queryParts);
$newQueryPart = "";
foreach($queryParts as $key => $value)
{
foreach ($queryParts as $key => $value) {
$newQueryPart .= rawurlencode($key).'='.rawurlencode($value).ini_get('arg_separator.output');
}
$sURL = str_replace($queryPart, $newQueryPart, $sURL);
@ -280,9 +279,9 @@ class xajaxResponse
*
* @param string contains Javascript code to be executed
*/
function addScript($sJS)
public function addScript($sJS)
{
$this->xml .= $this->_cmdXML(array("n"=>"js"),$sJS);
$this->xml .= $this->_cmdXML(array("n" => "js"), $sJS);
}
/**
@ -293,11 +292,12 @@ class xajaxResponse
* @param string $sFunc the name of a Javascript function
* @param mixed $args,... optional arguments to pass to the Javascript function
*/
function addScriptCall() {
public function addScriptCall()
{
$arguments = func_get_args();
$sFunc = array_shift($arguments);
$sData = $this->_buildObjXml($arguments);
$this->xml .= $this->_cmdXML(array("n"=>"jc","t"=>$sFunc),$sData);
$this->xml .= $this->_cmdXML(array("n" => "jc", "t" => $sFunc), $sData);
}
/**
@ -307,9 +307,9 @@ class xajaxResponse
*
* @param string contains the id of an HTML element to be removed
*/
function addRemove($sTarget)
public function addRemove($sTarget)
{
$this->xml .= $this->_cmdXML(array("n"=>"rm","t"=>$sTarget),'');
$this->xml .= $this->_cmdXML(array("n" => "rm", "t" => $sTarget), '');
}
/**
@ -323,14 +323,16 @@ class xajaxResponse
* @param string the id to be assigned to the new element
* @param string deprecated, use the addCreateInput() method instead
*/
function addCreate($sParent, $sTag, $sId, $sType= "")
public function addCreate($sParent, $sTag, $sId, $sType = "")
{
if ($sType)
{
trigger_error("The \$sType parameter of addCreate has been deprecated. Use the addCreateInput() method instead.", E_USER_WARNING);
if ($sType) {
trigger_error(
"The \$sType parameter of addCreate has been deprecated. Use the addCreateInput() method instead.",
E_USER_WARNING
);
return;
}
$this->xml .= $this->_cmdXML(array("n"=>"ce","t"=>$sParent,"p"=>$sId),$sTag);
$this->xml .= $this->_cmdXML(array("n" => "ce", "t" => $sParent, "p" => $sId), $sTag);
}
/**
@ -343,9 +345,9 @@ class xajaxResponse
* @param string the tag to be added
* @param string the id to be assigned to the new element
*/
function addInsert($sBefore, $sTag, $sId)
public function addInsert($sBefore, $sTag, $sId)
{
$this->xml .= $this->_cmdXML(array("n"=>"ie","t"=>$sBefore,"p"=>$sId),$sTag);
$this->xml .= $this->_cmdXML(array("n" => "ie", "t" => $sBefore, "p" => $sId), $sTag);
}
/**
@ -358,9 +360,9 @@ class xajaxResponse
* @param string the tag to be added
* @param string the id to be assigned to the new element
*/
function addInsertAfter($sAfter, $sTag, $sId)
public function addInsertAfter($sAfter, $sTag, $sId)
{
$this->xml .= $this->_cmdXML(array("n"=>"ia","t"=>$sAfter,"p"=>$sId),$sTag);
$this->xml .= $this->_cmdXML(array("n" => "ia", "t" => $sAfter, "p" => $sId), $sTag);
}
/**
@ -376,9 +378,9 @@ class xajaxResponse
* name when it is submitted
* @param string the id to be assigned to the new input
*/
function addCreateInput($sParent, $sType, $sName, $sId)
public function addCreateInput($sParent, $sType, $sName, $sId)
{
$this->xml .= $this->_cmdXML(array("n"=>"ci","t"=>$sParent,"p"=>$sId,"c"=>$sType),$sName);
$this->xml .= $this->_cmdXML(array("n" => "ci", "t" => $sParent, "p" => $sId, "c" => $sType), $sName);
}
/**
@ -394,9 +396,9 @@ class xajaxResponse
* name when it is submitted
* @param string the id to be assigned to the new input
*/
function addInsertInput($sBefore, $sType, $sName, $sId)
public function addInsertInput($sBefore, $sType, $sName, $sId)
{
$this->xml .= $this->_cmdXML(array("n"=>"ii","t"=>$sBefore,"p"=>$sId,"c"=>$sType),$sName);
$this->xml .= $this->_cmdXML(array("n" => "ii", "t" => $sBefore, "p" => $sId, "c" => $sType), $sName);
}
/**
@ -412,9 +414,9 @@ class xajaxResponse
* name when it is submitted
* @param string the id to be assigned to the new input
*/
function addInsertInputAfter($sAfter, $sType, $sName, $sId)
public function addInsertInputAfter($sAfter, $sType, $sName, $sId)
{
$this->xml .= $this->_cmdXML(array("n"=>"iia","t"=>$sAfter,"p"=>$sId,"c"=>$sType),$sName);
$this->xml .= $this->_cmdXML(array("n" => "iia", "t" => $sAfter, "p" => $sId, "c" => $sType), $sName);
}
/**
@ -426,9 +428,9 @@ class xajaxResponse
* @param string the event you wish to set ("onclick", "onmouseover", etc.)
* @param string the Javascript string you want the event to invoke
*/
function addEvent($sTarget,$sEvent, $sScript)
public function addEvent($sTarget, $sEvent, $sScript)
{
$this->xml .= $this->_cmdXML(array("n"=>"ev","t"=>$sTarget,"p"=>$sEvent),$sScript);
$this->xml .= $this->_cmdXML(array("n" => "ev", "t" => $sTarget, "p" => $sEvent), $sScript);
}
/**
@ -441,9 +443,9 @@ class xajaxResponse
* @param string the name of a Javascript function that will handle the
* event. Multiple handlers can be added for the same event
*/
function addHandler($sTarget,$sEvent, $sHandler)
public function addHandler($sTarget, $sEvent, $sHandler)
{
$this->xml .= $this->_cmdXML(array("n"=>"ah","t"=>$sTarget,"p"=>$sEvent),$sHandler);
$this->xml .= $this->_cmdXML(array("n" => "ah", "t" => $sTarget, "p" => $sEvent), $sHandler);
}
/**
@ -457,9 +459,9 @@ class xajaxResponse
* @param string the name of a Javascript handler function that you want to
* remove
*/
function addRemoveHandler($sTarget,$sEvent, $sHandler)
public function addRemoveHandler($sTarget, $sEvent, $sHandler)
{
$this->xml .= $this->_cmdXML(array("n"=>"rh","t"=>$sTarget,"p"=>$sEvent),$sHandler);
$this->xml .= $this->_cmdXML(array("n" => "rh", "t" => $sTarget, "p" => $sEvent), $sHandler);
}
/**
@ -469,9 +471,9 @@ class xajaxResponse
*
* @param string URL of the Javascript file to include
*/
function addIncludeScript($sFileName)
public function addIncludeScript($sFileName)
{
$this->xml .= $this->_cmdXML(array("n"=>"in"),$sFileName);
$this->xml .= $this->_cmdXML(array("n" => "in"), $sFileName);
}
/**
@ -484,12 +486,13 @@ class xajaxResponse
*
* @return string response XML data
*/
function getXML()
public function getXML()
{
$sXML = "<? xml version = \ "1.0 \" " ;
if ($this->sEncoding & & strlen(trim($this->sEncoding)) > 0)
if ($this->sEncoding & & strlen(trim($this->sEncoding)) > 0) {
$sXML .= " encoding=\"".$this->sEncoding."\"";
$sXML .= " ?".">< xjx > " . $this->xml . "< / xjx > ";
}
$sXML .= " ?".">< xjx > ".$this->xml."< / xjx > ";
return $sXML;
}
@ -506,7 +509,7 @@ class xajaxResponse
* @param string the response XML (returned from a getXML() method) to add
* to the end of this response object
*/
function loadXML($mXML)
public function loadXML($mXML)
{
if (is_a($mXML, "xajaxResponse")) {
$mXML = $mXML->getXML();
@ -527,31 +530,39 @@ class xajaxResponse
* @param string data
* @return string XML command
*/
function _cmdXML($aAttributes, $sData)
public function _cmdXML($aAttributes, $sData)
{
if ($this->bOutputEntities) {
// An adaptation for the Dokeos LMS, 22-AUG-2009.
if (function_exists('api_convert_encoding')) {
$sData = call_user_func_array('api_convert_encoding', array(& $sData, 'HTML-ENTITIES', $this->sEncoding));
}
//if (function_exists('mb_convert_encoding')) {
$sData = call_user_func_array(
'api_convert_encoding',
array(& $sData, 'HTML-ENTITIES', $this->sEncoding)
);
} //if (function_exists('mb_convert_encoding')) {
elseif (function_exists('mb_convert_encoding')) {
//
$sData = call_user_func_array('mb_convert_encoding', array(& $sData, 'HTML-ENTITIES', $this->sEncoding));
}
else {
trigger_error("The xajax XML response output could not be converted to HTML entities because the mb_convert_encoding function is not available", E_USER_NOTICE);
} else {
trigger_error(
"The xajax XML response output could not be converted to HTML entities because the mb_convert_encoding function is not available",
E_USER_NOTICE
);
}
}
$xml = "< cmd " ;
foreach($aAttributes as $sAttribute => $sValue)
foreach ($aAttributes as $sAttribute => $sValue) {
$xml .= " $sAttribute=\"$sValue\"";
if ($sData !== null & & !stristr($sData,'< ![CDATA['))
}
if ($sData !== null & & !stristr($sData, '< ![CDATA[')) {
$xml .= "><![CDATA[$sData]]> < / cmd > ";
else if ($sData !== null)
} else {
if ($sData !== null) {
$xml .= ">$sData< / cmd > ";
else
} else {
$xml .= ">< / cmd > ";
}
}
return $xml;
}
@ -565,23 +576,23 @@ class xajaxResponse
* @param mixed data structure to serialize to XML
* @return string serialized XML
*/
function _buildObjXml($var) {
if (gettype($var) == "object") $var = get_object_vars($var);
public function _buildObjXml($var)
{
if (gettype($var) == "object") {
$var = get_object_vars($var);
}
if (!is_array($var)) {
return "<![CDATA[$var]]> ";
}
else {
} else {
$data = "< xjxobj > ";
foreach ($var as $key => $value) {
$data .= "< e > ";
$data .= "< k > " . htmlspecialchars($key) . "< / k > ";
$data .= "< v > " . $this->_buildObjXml($value) . "< / v > ";
$data .= "< k > ".htmlspecialchars($key)."< / k > ";
$data .= "< v > ".$this->_buildObjXml($value)."< / v > ";
$data .= "< / e > ";
}
$data .= "< / xjxobj > ";
return $data;
}
}
}// end class xajaxResponse
?>
}