@@ -45,21 +45,21 @@ discard block |
||
| 45 | 45 | * Define XAJAX_DEFAULT_CHAR_ENCODING that is used by both |
| 46 | 46 | * the xajax and xajaxResponse classes |
| 47 | 47 | */ |
| 48 | -if (!defined ('XAJAX_DEFAULT_CHAR_ENCODING')) |
|
| 48 | +if (!defined('XAJAX_DEFAULT_CHAR_ENCODING')) |
|
| 49 | 49 | { |
| 50 | - define ('XAJAX_DEFAULT_CHAR_ENCODING', 'utf-8' ); |
|
| 50 | + define('XAJAX_DEFAULT_CHAR_ENCODING', 'utf-8'); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * Communication Method Defines |
| 55 | 55 | */ |
| 56 | -if (!defined ('XAJAX_GET')) |
|
| 56 | +if (!defined('XAJAX_GET')) |
|
| 57 | 57 | { |
| 58 | - define ('XAJAX_GET', 0); |
|
| 58 | + define('XAJAX_GET', 0); |
|
| 59 | 59 | } |
| 60 | -if (!defined ('XAJAX_POST')) |
|
| 60 | +if (!defined('XAJAX_POST')) |
|
| 61 | 61 | { |
| 62 | - define ('XAJAX_POST', 1); |
|
| 62 | + define('XAJAX_POST', 1); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param string defaults to XAJAX_DEFAULT_CHAR_ENCODING defined above |
| 168 | 168 | * @param boolean defaults to false |
| 169 | 169 | */ |
| 170 | - public function __construct($sRequestURI="",$sWrapperPrefix="xajax_",$sEncoding=XAJAX_DEFAULT_CHAR_ENCODING,$bDebug=false) |
|
| 170 | + public function __construct($sRequestURI = "", $sWrapperPrefix = "xajax_", $sEncoding = XAJAX_DEFAULT_CHAR_ENCODING, $bDebug = false) |
|
| 171 | 171 | { |
| 172 | 172 | $this->aFunctions = array(); |
| 173 | 173 | $this->aObjects = array(); |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | * @param mixed request type (XAJAX_GET/XAJAX_POST) that should be used |
| 394 | 394 | * for this function. Defaults to XAJAX_POST. |
| 395 | 395 | */ |
| 396 | - function registerFunction($mFunction,$sRequestType=XAJAX_POST) |
|
| 396 | + function registerFunction($mFunction, $sRequestType = XAJAX_POST) |
|
| 397 | 397 | { |
| 398 | 398 | if (is_array($mFunction)) { |
| 399 | 399 | $this->aFunctions[$mFunction[0]] = 1; |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | * @param mixed the RequestType (XAJAX_GET/XAJAX_POST) that should be used |
| 421 | 421 | * for this function. Defaults to XAJAX_POST. |
| 422 | 422 | */ |
| 423 | - function registerExternalFunction($mFunction,$sIncludeFile,$sRequestType=XAJAX_POST) |
|
| 423 | + function registerExternalFunction($mFunction, $sIncludeFile, $sRequestType = XAJAX_POST) |
|
| 424 | 424 | { |
| 425 | 425 | $this->registerFunction($mFunction, $sRequestType); |
| 426 | 426 | |
@@ -545,10 +545,10 @@ discard block |
||
| 545 | 545 | } |
| 546 | 546 | else |
| 547 | 547 | { |
| 548 | - header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 549 | - header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
| 550 | - header ("Cache-Control: no-cache, must-revalidate"); |
|
| 551 | - header ("Pragma: no-cache"); |
|
| 548 | + header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 549 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); |
|
| 550 | + header("Cache-Control: no-cache, must-revalidate"); |
|
| 551 | + header("Pragma: no-cache"); |
|
| 552 | 552 | |
| 553 | 553 | $sFunctionName = $_GET["xajax"]; |
| 554 | 554 | |
@@ -566,12 +566,12 @@ discard block |
||
| 566 | 566 | if (!$this->_isFunctionCallable($this->sPreFunction)) { |
| 567 | 567 | $bFoundFunction = false; |
| 568 | 568 | $objResponse = new xajaxResponse(); |
| 569 | - $objResponse->addAlert("Unknown Pre-Function ". $this->sPreFunction); |
|
| 569 | + $objResponse->addAlert("Unknown Pre-Function ".$this->sPreFunction); |
|
| 570 | 570 | $sResponse = $objResponse->getXML(); |
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | //include any external dependencies associated with this function name |
| 574 | - if (array_key_exists($sFunctionName,$this->aFunctionIncludeFiles)) |
|
| 574 | + if (array_key_exists($sFunctionName, $this->aFunctionIncludeFiles)) |
|
| 575 | 575 | { |
| 576 | 576 | ob_start(); |
| 577 | 577 | include_once($this->aFunctionIncludeFiles[$sFunctionName]); |
@@ -611,13 +611,13 @@ discard block |
||
| 611 | 611 | |
| 612 | 612 | $aArgs[$i] = stripslashes($aArgs[$i]); |
| 613 | 613 | } |
| 614 | - if (stristr($aArgs[$i],"<xjxobj>") != false) |
|
| 614 | + if (stristr($aArgs[$i], "<xjxobj>") != false) |
|
| 615 | 615 | { |
| 616 | - $aArgs[$i] = $this->_xmlToArray("xjxobj",$aArgs[$i]); |
|
| 616 | + $aArgs[$i] = $this->_xmlToArray("xjxobj", $aArgs[$i]); |
|
| 617 | 617 | } |
| 618 | - else if (stristr($aArgs[$i],"<xjxquery>") != false) |
|
| 618 | + else if (stristr($aArgs[$i], "<xjxquery>") != false) |
|
| 619 | 619 | { |
| 620 | - $aArgs[$i] = $this->_xmlToArray("xjxquery",$aArgs[$i]); |
|
| 620 | + $aArgs[$i] = $this->_xmlToArray("xjxquery", $aArgs[$i]); |
|
| 621 | 621 | } |
| 622 | 622 | else if ($this->bDecodeUTF8Input) |
| 623 | 623 | { |
@@ -673,16 +673,16 @@ discard block |
||
| 673 | 673 | if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0) |
| 674 | 674 | $sContentHeader .= " charset=".$this->sEncoding; |
| 675 | 675 | header($sContentHeader); |
| 676 | - if ($this->bErrorHandler && !empty( $GLOBALS['xajaxErrorHandlerText'] )) { |
|
| 676 | + if ($this->bErrorHandler && !empty($GLOBALS['xajaxErrorHandlerText'])) { |
|
| 677 | 677 | $sErrorResponse = new xajaxResponse(); |
| 678 | - $sErrorResponse->addAlert("** PHP Error Messages: **" . $GLOBALS['xajaxErrorHandlerText']); |
|
| 678 | + $sErrorResponse->addAlert("** PHP Error Messages: **".$GLOBALS['xajaxErrorHandlerText']); |
|
| 679 | 679 | if ($this->sLogFile) { |
| 680 | 680 | $fH = @fopen($this->sLogFile, "a"); |
| 681 | 681 | if (!$fH) { |
| 682 | - $sErrorResponse->addAlert("** Logging Error **\n\nxajax was unable to write to the error log file:\n" . $this->sLogFile); |
|
| 682 | + $sErrorResponse->addAlert("** Logging Error **\n\nxajax was unable to write to the error log file:\n".$this->sLogFile); |
|
| 683 | 683 | } |
| 684 | 684 | else { |
| 685 | - fwrite($fH, "** xajax Error Log - " . strftime("%b %e %Y %I:%M:%S %p") . " **" . $GLOBALS['xajaxErrorHandlerText'] . "\n\n\n"); |
|
| 685 | + fwrite($fH, "** xajax Error Log - ".strftime("%b %e %Y %I:%M:%S %p")." **".$GLOBALS['xajaxErrorHandlerText']."\n\n\n"); |
|
| 686 | 686 | fclose($fH); |
| 687 | 687 | } |
| 688 | 688 | } |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * engine located within the xajax installation folder. |
| 725 | 725 | * Defaults to xajax_js/xajax.js. |
| 726 | 726 | */ |
| 727 | - function printJavascript($sJsURI="", $sJsFile=NULL) |
|
| 727 | + function printJavascript($sJsURI = "", $sJsFile = NULL) |
|
| 728 | 728 | { |
| 729 | 729 | print $this->getJavascript($sJsURI, $sJsFile); |
| 730 | 730 | } |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | * Defaults to xajax_js/xajax.js. |
| 754 | 754 | * @return string |
| 755 | 755 | */ |
| 756 | - function getJavascript($sJsURI="", $sJsFile=NULL) |
|
| 756 | + function getJavascript($sJsURI = "", $sJsFile = NULL) |
|
| 757 | 757 | { |
| 758 | 758 | $html = $this->getJavascriptConfig(); |
| 759 | 759 | $html .= $this->getJavascriptInclude($sJsURI, $sJsFile); |
@@ -771,15 +771,15 @@ discard block |
||
| 771 | 771 | { |
| 772 | 772 | $html = "\t<script type=\"text/javascript\">\n"; |
| 773 | 773 | $html .= "var xajaxRequestUri=\"".$this->sRequestURI."\";\n"; |
| 774 | - $html .= "var xajaxDebug=".($this->bDebug?"true":"false").";\n"; |
|
| 775 | - $html .= "var xajaxStatusMessages=".($this->bStatusMessages?"true":"false").";\n"; |
|
| 776 | - $html .= "var xajaxWaitCursor=".($this->bWaitCursor?"true":"false").";\n"; |
|
| 774 | + $html .= "var xajaxDebug=".($this->bDebug ? "true" : "false").";\n"; |
|
| 775 | + $html .= "var xajaxStatusMessages=".($this->bStatusMessages ? "true" : "false").";\n"; |
|
| 776 | + $html .= "var xajaxWaitCursor=".($this->bWaitCursor ? "true" : "false").";\n"; |
|
| 777 | 777 | $html .= "var xajaxDefinedGet=".XAJAX_GET.";\n"; |
| 778 | 778 | $html .= "var xajaxDefinedPost=".XAJAX_POST.";\n"; |
| 779 | 779 | $html .= "var xajaxLoaded=false;\n"; |
| 780 | 780 | |
| 781 | - foreach($this->aFunctions as $sFunction => $bExists) { |
|
| 782 | - $html .= $this->_wrap($sFunction,$this->aFunctionRequestTypes[$sFunction]); |
|
| 781 | + foreach ($this->aFunctions as $sFunction => $bExists) { |
|
| 782 | + $html .= $this->_wrap($sFunction, $this->aFunctionRequestTypes[$sFunction]); |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | $html .= "\t</script>\n"; |
@@ -803,7 +803,7 @@ discard block |
||
| 803 | 803 | * Defaults to xajax_js/xajax.js. |
| 804 | 804 | * @return string |
| 805 | 805 | */ |
| 806 | - function getJavascriptInclude($sJsURI="", $sJsFile=NULL) |
|
| 806 | + function getJavascriptInclude($sJsURI = "", $sJsFile = NULL) |
|
| 807 | 807 | { |
| 808 | 808 | //if ($sJsFile == NULL) $sJsFile = "xajax_js/xajax.js"; |
| 809 | 809 | $sJsFile = "xajax_js/xajax.js"; |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | //if ($sJsURI != "" && substr($sJsURI, -1) != "/") $sJsURI .= "/"; |
| 812 | 812 | $sJsURI = api_get_path(WEB_LIBRARY_JS_PATH); |
| 813 | 813 | |
| 814 | - $html = "\t<script type=\"text/javascript\" src=\"" . $sJsURI . $sJsFile . "\"></script>\n"; |
|
| 814 | + $html = "\t<script type=\"text/javascript\" src=\"".$sJsURI.$sJsFile."\"></script>\n"; |
|
| 815 | 815 | $html .= "\t<script type=\"text/javascript\">\n"; |
| 816 | 816 | $html .= "window.setTimeout(function () { if (!xajaxLoaded) { alert('Error: the xajax Javascript file could not be included. Perhaps the URL is incorrect?\\nURL: {$sJsURI}{$sJsFile}'); } }, 6000);\n"; |
| 817 | 817 | $html .= "\t</script>\n"; |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | * @param string an optional argument containing the full server file path |
| 827 | 827 | * of xajax.js. |
| 828 | 828 | */ |
| 829 | - function autoCompressJavascript($sJsFullFilename=NULL) |
|
| 829 | + function autoCompressJavascript($sJsFullFilename = NULL) |
|
| 830 | 830 | { |
| 831 | 831 | $sJsFile = "xajax_js/xajax.js"; |
| 832 | 832 | |
@@ -835,21 +835,21 @@ discard block |
||
| 835 | 835 | } |
| 836 | 836 | else { |
| 837 | 837 | $realPath = realpath(dirname(__FILE__)); |
| 838 | - $realJsFile = $realPath . "/". $sJsFile; |
|
| 838 | + $realJsFile = $realPath."/".$sJsFile; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | // Create a compressed file if necessary |
| 842 | 842 | if (!file_exists($realJsFile)) { |
| 843 | 843 | $srcFile = str_replace(".js", "_uncompressed.js", $realJsFile); |
| 844 | 844 | if (!file_exists($srcFile)) { |
| 845 | - trigger_error("The xajax uncompressed Javascript file could not be found in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR); |
|
| 845 | + trigger_error("The xajax uncompressed Javascript file could not be found in the <b>".dirname($realJsFile)."</b> folder. Error ", E_USER_ERROR); |
|
| 846 | 846 | } |
| 847 | 847 | require(dirname(__FILE__)."/xajaxCompress.php"); |
| 848 | 848 | $javaScript = implode('', file($srcFile)); |
| 849 | 849 | $compressedScript = xajaxCompressJavascript($javaScript); |
| 850 | 850 | $fH = @fopen($realJsFile, "w"); |
| 851 | 851 | if (!$fH) { |
| 852 | - trigger_error("The xajax compressed javascript file could not be written in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR); |
|
| 852 | + trigger_error("The xajax compressed javascript file could not be written in the <b>".dirname($realJsFile)."</b> folder. Error ", E_USER_ERROR); |
|
| 853 | 853 | } |
| 854 | 854 | else { |
| 855 | 855 | fwrite($fH, $compressedScript); |
@@ -918,23 +918,23 @@ discard block |
||
| 918 | 918 | // Build the URL: Start with scheme, user and pass |
| 919 | 919 | $sURL = $aURL['scheme'].'://'; |
| 920 | 920 | if (!empty($aURL['user'])) { |
| 921 | - $sURL.= $aURL['user']; |
|
| 921 | + $sURL .= $aURL['user']; |
|
| 922 | 922 | if (!empty($aURL['pass'])) { |
| 923 | - $sURL.= ':'.$aURL['pass']; |
|
| 923 | + $sURL .= ':'.$aURL['pass']; |
|
| 924 | 924 | } |
| 925 | - $sURL.= '@'; |
|
| 925 | + $sURL .= '@'; |
|
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | // Add the host |
| 929 | - $sURL.= $aURL['host']; |
|
| 929 | + $sURL .= $aURL['host']; |
|
| 930 | 930 | |
| 931 | 931 | // Add the port if needed |
| 932 | 932 | if (!empty($aURL['port']) && (($aURL['scheme'] == 'http' && $aURL['port'] != 80) || ($aURL['scheme'] == 'https' && $aURL['port'] != 443))) { |
| 933 | - $sURL.= ':'.$aURL['port']; |
|
| 933 | + $sURL .= ':'.$aURL['port']; |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | // Add the path and the query string |
| 937 | - $sURL.= $aURL['path'].@$aURL['query']; |
|
| 937 | + $sURL .= $aURL['path'].@$aURL['query']; |
|
| 938 | 938 | |
| 939 | 939 | // Clean up |
| 940 | 940 | unset($aURL); |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | * @access private |
| 1007 | 1007 | * @return string |
| 1008 | 1008 | */ |
| 1009 | - function _wrap($sFunction,$sRequestType=XAJAX_POST) |
|
| 1009 | + function _wrap($sFunction, $sRequestType = XAJAX_POST) |
|
| 1010 | 1010 | { |
| 1011 | 1011 | $js = "function ".$this->sWrapperPrefix."$sFunction(){return xajax.call(\"$sFunction\", arguments, ".$sRequestType.");}\n"; |
| 1012 | 1012 | return $js; |
@@ -1025,18 +1025,18 @@ discard block |
||
| 1025 | 1025 | function _xmlToArray($rootTag, $sXml) |
| 1026 | 1026 | { |
| 1027 | 1027 | $aArray = array(); |
| 1028 | - $sXml = str_replace("<$rootTag>","<$rootTag>|~|",$sXml); |
|
| 1029 | - $sXml = str_replace("</$rootTag>","</$rootTag>|~|",$sXml); |
|
| 1030 | - $sXml = str_replace("<e>","<e>|~|",$sXml); |
|
| 1031 | - $sXml = str_replace("</e>","</e>|~|",$sXml); |
|
| 1032 | - $sXml = str_replace("<k>","<k>|~|",$sXml); |
|
| 1033 | - $sXml = str_replace("</k>","|~|</k>|~|",$sXml); |
|
| 1034 | - $sXml = str_replace("<v>","<v>|~|",$sXml); |
|
| 1035 | - $sXml = str_replace("</v>","|~|</v>|~|",$sXml); |
|
| 1036 | - $sXml = str_replace("<q>","<q>|~|",$sXml); |
|
| 1037 | - $sXml = str_replace("</q>","|~|</q>|~|",$sXml); |
|
| 1038 | - |
|
| 1039 | - $this->aObjArray = explode("|~|",$sXml); |
|
| 1028 | + $sXml = str_replace("<$rootTag>", "<$rootTag>|~|", $sXml); |
|
| 1029 | + $sXml = str_replace("</$rootTag>", "</$rootTag>|~|", $sXml); |
|
| 1030 | + $sXml = str_replace("<e>", "<e>|~|", $sXml); |
|
| 1031 | + $sXml = str_replace("</e>", "</e>|~|", $sXml); |
|
| 1032 | + $sXml = str_replace("<k>", "<k>|~|", $sXml); |
|
| 1033 | + $sXml = str_replace("</k>", "|~|</k>|~|", $sXml); |
|
| 1034 | + $sXml = str_replace("<v>", "<v>|~|", $sXml); |
|
| 1035 | + $sXml = str_replace("</v>", "|~|</v>|~|", $sXml); |
|
| 1036 | + $sXml = str_replace("<q>", "<q>|~|", $sXml); |
|
| 1037 | + $sXml = str_replace("</q>", "|~|</q>|~|", $sXml); |
|
| 1038 | + |
|
| 1039 | + $this->aObjArray = explode("|~|", $sXml); |
|
| 1040 | 1040 | |
| 1041 | 1041 | $this->iPos = 0; |
| 1042 | 1042 | $aArray = $this->_parseObjXml($rootTag); |
@@ -1058,32 +1058,32 @@ discard block |
||
| 1058 | 1058 | |
| 1059 | 1059 | if ($rootTag == "xjxobj") |
| 1060 | 1060 | { |
| 1061 | - while(!stristr($this->aObjArray[$this->iPos],"</xjxobj>")) |
|
| 1061 | + while (!stristr($this->aObjArray[$this->iPos], "</xjxobj>")) |
|
| 1062 | 1062 | { |
| 1063 | 1063 | $this->iPos++; |
| 1064 | - if(stristr($this->aObjArray[$this->iPos],"<e>")) |
|
| 1064 | + if (stristr($this->aObjArray[$this->iPos], "<e>")) |
|
| 1065 | 1065 | { |
| 1066 | 1066 | $key = ""; |
| 1067 | 1067 | $value = null; |
| 1068 | 1068 | |
| 1069 | 1069 | $this->iPos++; |
| 1070 | - while(!stristr($this->aObjArray[$this->iPos],"</e>")) |
|
| 1070 | + while (!stristr($this->aObjArray[$this->iPos], "</e>")) |
|
| 1071 | 1071 | { |
| 1072 | - if(stristr($this->aObjArray[$this->iPos],"<k>")) |
|
| 1072 | + if (stristr($this->aObjArray[$this->iPos], "<k>")) |
|
| 1073 | 1073 | { |
| 1074 | 1074 | $this->iPos++; |
| 1075 | - while(!stristr($this->aObjArray[$this->iPos],"</k>")) |
|
| 1075 | + while (!stristr($this->aObjArray[$this->iPos], "</k>")) |
|
| 1076 | 1076 | { |
| 1077 | 1077 | $key .= $this->aObjArray[$this->iPos]; |
| 1078 | 1078 | $this->iPos++; |
| 1079 | 1079 | } |
| 1080 | 1080 | } |
| 1081 | - if(stristr($this->aObjArray[$this->iPos],"<v>")) |
|
| 1081 | + if (stristr($this->aObjArray[$this->iPos], "<v>")) |
|
| 1082 | 1082 | { |
| 1083 | 1083 | $this->iPos++; |
| 1084 | - while(!stristr($this->aObjArray[$this->iPos],"</v>")) |
|
| 1084 | + while (!stristr($this->aObjArray[$this->iPos], "</v>")) |
|
| 1085 | 1085 | { |
| 1086 | - if(stristr($this->aObjArray[$this->iPos],"<xjxobj>")) |
|
| 1086 | + if (stristr($this->aObjArray[$this->iPos], "<xjxobj>")) |
|
| 1087 | 1087 | { |
| 1088 | 1088 | $value = $this->_parseObjXml("xjxobj"); |
| 1089 | 1089 | $this->iPos++; |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | $this->iPos++; |
| 1103 | 1103 | } |
| 1104 | 1104 | |
| 1105 | - $aArray[$key]=$value; |
|
| 1105 | + $aArray[$key] = $value; |
|
| 1106 | 1106 | } |
| 1107 | 1107 | } |
| 1108 | 1108 | } |
@@ -1111,21 +1111,21 @@ discard block |
||
| 1111 | 1111 | { |
| 1112 | 1112 | $sQuery = ""; |
| 1113 | 1113 | $this->iPos++; |
| 1114 | - while(!stristr($this->aObjArray[$this->iPos],"</xjxquery>")) |
|
| 1114 | + while (!stristr($this->aObjArray[$this->iPos], "</xjxquery>")) |
|
| 1115 | 1115 | { |
| 1116 | - if (stristr($this->aObjArray[$this->iPos],"<q>") || stristr($this->aObjArray[$this->iPos],"</q>")) |
|
| 1116 | + if (stristr($this->aObjArray[$this->iPos], "<q>") || stristr($this->aObjArray[$this->iPos], "</q>")) |
|
| 1117 | 1117 | { |
| 1118 | 1118 | $this->iPos++; |
| 1119 | 1119 | continue; |
| 1120 | 1120 | } |
| 1121 | - $sQuery .= $this->aObjArray[$this->iPos]; |
|
| 1121 | + $sQuery .= $this->aObjArray[$this->iPos]; |
|
| 1122 | 1122 | $this->iPos++; |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | parse_str($sQuery, $aArray); |
| 1126 | 1126 | if ($this->bDecodeUTF8Input) |
| 1127 | 1127 | { |
| 1128 | - foreach($aArray as $key => $value) |
|
| 1128 | + foreach ($aArray as $key => $value) |
|
| 1129 | 1129 | { |
| 1130 | 1130 | $aArray[$key] = $this->_decodeUTF8Data($value); |
| 1131 | 1131 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | if (!defined ('XAJAX_DEFAULT_CHAR_ENCODING')) |
| 49 | 49 | { |
| 50 | - define ('XAJAX_DEFAULT_CHAR_ENCODING', 'utf-8' ); |
|
| 50 | + define ('XAJAX_DEFAULT_CHAR_ENCODING', 'utf-8' ); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | if (!defined ('XAJAX_GET')) |
| 57 | 57 | { |
| 58 | - define ('XAJAX_GET', 0); |
|
| 58 | + define ('XAJAX_GET', 0); |
|
| 59 | 59 | } |
| 60 | 60 | if (!defined ('XAJAX_POST')) |
| 61 | 61 | { |
| 62 | - define ('XAJAX_POST', 1); |
|
| 62 | + define ('XAJAX_POST', 1); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -72,1145 +72,1145 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | class xajax |
| 74 | 74 | { |
| 75 | - /**#@+ |
|
| 75 | + /**#@+ |
|
| 76 | 76 | * @access protected |
| 77 | 77 | */ |
| 78 | - /** |
|
| 79 | - * @var array Array of PHP functions that will be callable through javascript wrappers |
|
| 80 | - */ |
|
| 81 | - var $aFunctions; |
|
| 82 | - /** |
|
| 83 | - * @var array Array of object callbacks that will allow Javascript to call PHP methods (key=function name) |
|
| 84 | - */ |
|
| 85 | - var $aObjects; |
|
| 86 | - /** |
|
| 87 | - * @var array Array of RequestTypes to be used with each function (key=function name) |
|
| 88 | - */ |
|
| 89 | - var $aFunctionRequestTypes; |
|
| 90 | - /** |
|
| 91 | - * @var array Array of Include Files for any external functions (key=function name) |
|
| 92 | - */ |
|
| 93 | - var $aFunctionIncludeFiles; |
|
| 94 | - /** |
|
| 95 | - * @var string Name of the PHP function to call if no callable function was found |
|
| 96 | - */ |
|
| 97 | - var $sCatchAllFunction; |
|
| 98 | - /** |
|
| 99 | - * @var string Name of the PHP function to call before any other function |
|
| 100 | - */ |
|
| 101 | - var $sPreFunction; |
|
| 102 | - /** |
|
| 103 | - * @var string The URI for making requests to the xajax object |
|
| 104 | - */ |
|
| 105 | - var $sRequestURI; |
|
| 106 | - /** |
|
| 107 | - * @var string The prefix to prepend to the javascript wraper function name |
|
| 108 | - */ |
|
| 109 | - var $sWrapperPrefix; |
|
| 110 | - /** |
|
| 111 | - * @var boolean Show debug messages (default false) |
|
| 112 | - */ |
|
| 113 | - var $bDebug; |
|
| 114 | - /** |
|
| 115 | - * @var boolean Show messages in the client browser's status bar (default false) |
|
| 116 | - */ |
|
| 117 | - var $bStatusMessages; |
|
| 118 | - /** |
|
| 119 | - * @var boolean Allow xajax to exit after processing a request (default true) |
|
| 120 | - */ |
|
| 121 | - var $bExitAllowed; |
|
| 122 | - /** |
|
| 123 | - * @var boolean Use wait cursor in browser (default true) |
|
| 124 | - */ |
|
| 125 | - var $bWaitCursor; |
|
| 126 | - /** |
|
| 127 | - * @var boolean Use an special xajax error handler so the errors are sent to the browser properly (default false) |
|
| 128 | - */ |
|
| 129 | - var $bErrorHandler; |
|
| 130 | - /** |
|
| 131 | - * @var string Specify what, if any, file xajax should log errors to (and more information in a future release) |
|
| 132 | - */ |
|
| 133 | - var $sLogFile; |
|
| 134 | - /** |
|
| 135 | - * @var boolean Clean all output buffers before outputting response (default false) |
|
| 136 | - */ |
|
| 137 | - var $bCleanBuffer; |
|
| 138 | - /** |
|
| 139 | - * @var string String containing the character encoding used |
|
| 140 | - */ |
|
| 141 | - var $sEncoding; |
|
| 142 | - /** |
|
| 143 | - * @var boolean Decode input request args from UTF-8 (default false) |
|
| 144 | - */ |
|
| 145 | - var $bDecodeUTF8Input; |
|
| 146 | - /** |
|
| 147 | - * @var boolean Convert special characters to HTML entities (default false) |
|
| 148 | - */ |
|
| 149 | - var $bOutputEntities; |
|
| 150 | - /** |
|
| 151 | - * @var array Array for parsing complex objects |
|
| 152 | - */ |
|
| 153 | - var $aObjArray; |
|
| 154 | - /** |
|
| 155 | - * @var integer Position in $aObjArray |
|
| 156 | - */ |
|
| 157 | - var $iPos; |
|
| 158 | - |
|
| 159 | - /**#@-*/ |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Constructor. You can set some extra xajax options right away or use |
|
| 163 | - * individual methods later to set options. |
|
| 164 | - * |
|
| 165 | - * @param string defaults to the current browser URI |
|
| 166 | - * @param string defaults to "xajax_"; |
|
| 167 | - * @param string defaults to XAJAX_DEFAULT_CHAR_ENCODING defined above |
|
| 168 | - * @param boolean defaults to false |
|
| 169 | - */ |
|
| 170 | - public function __construct($sRequestURI="",$sWrapperPrefix="xajax_",$sEncoding=XAJAX_DEFAULT_CHAR_ENCODING,$bDebug=false) |
|
| 171 | - { |
|
| 172 | - $this->aFunctions = array(); |
|
| 173 | - $this->aObjects = array(); |
|
| 174 | - $this->aFunctionIncludeFiles = array(); |
|
| 175 | - $this->sRequestURI = $sRequestURI; |
|
| 176 | - if ($this->sRequestURI == "") |
|
| 177 | - $this->sRequestURI = $this->_detectURI(); |
|
| 178 | - $this->sWrapperPrefix = $sWrapperPrefix; |
|
| 179 | - $this->bDebug = $bDebug; |
|
| 180 | - $this->bStatusMessages = false; |
|
| 181 | - $this->bWaitCursor = true; |
|
| 182 | - $this->bExitAllowed = true; |
|
| 183 | - $this->bErrorHandler = false; |
|
| 184 | - $this->sLogFile = ""; |
|
| 185 | - $this->bCleanBuffer = false; |
|
| 186 | - $this->setCharEncoding($sEncoding); |
|
| 187 | - $this->bDecodeUTF8Input = false; |
|
| 188 | - $this->bOutputEntities = false; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Sets the URI to which requests will be made. |
|
| 193 | - * <i>Usage:</i> <kbd>$xajax->setRequestURI("http://www.xajaxproject.org");</kbd> |
|
| 194 | - * |
|
| 195 | - * @param string the URI (can be absolute or relative) of the PHP script |
|
| 196 | - * that will be accessed when an xajax request occurs |
|
| 197 | - */ |
|
| 198 | - function setRequestURI($sRequestURI) |
|
| 199 | - { |
|
| 200 | - $this->sRequestURI = $sRequestURI; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Sets the prefix that will be appended to the Javascript wrapper |
|
| 205 | - * functions (default is "xajax_"). |
|
| 206 | - * |
|
| 207 | - * @param string |
|
| 208 | - */ |
|
| 209 | - // |
|
| 210 | - function setWrapperPrefix($sPrefix) |
|
| 211 | - { |
|
| 212 | - $this->sWrapperPrefix = $sPrefix; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Enables debug messages for xajax. |
|
| 217 | - * */ |
|
| 218 | - function debugOn() |
|
| 219 | - { |
|
| 220 | - $this->bDebug = true; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Disables debug messages for xajax (default behavior). |
|
| 225 | - */ |
|
| 226 | - function debugOff() |
|
| 227 | - { |
|
| 228 | - $this->bDebug = false; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Enables messages in the browser's status bar for xajax. |
|
| 233 | - */ |
|
| 234 | - function statusMessagesOn() |
|
| 235 | - { |
|
| 236 | - $this->bStatusMessages = true; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Disables messages in the browser's status bar for xajax (default behavior). |
|
| 241 | - */ |
|
| 242 | - function statusMessagesOff() |
|
| 243 | - { |
|
| 244 | - $this->bStatusMessages = false; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Enables the wait cursor to be displayed in the browser (default behavior). |
|
| 249 | - */ |
|
| 250 | - function waitCursorOn() |
|
| 251 | - { |
|
| 252 | - $this->bWaitCursor = true; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Disables the wait cursor to be displayed in the browser. |
|
| 257 | - */ |
|
| 258 | - function waitCursorOff() |
|
| 259 | - { |
|
| 260 | - $this->bWaitCursor = false; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Enables xajax to exit immediately after processing a request and |
|
| 265 | - * sending the response back to the browser (default behavior). |
|
| 266 | - */ |
|
| 267 | - function exitAllowedOn() |
|
| 268 | - { |
|
| 269 | - $this->bExitAllowed = true; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Disables xajax's default behavior of exiting immediately after |
|
| 274 | - * processing a request and sending the response back to the browser. |
|
| 275 | - */ |
|
| 276 | - function exitAllowedOff() |
|
| 277 | - { |
|
| 278 | - $this->bExitAllowed = false; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Turns on xajax's error handling system so that PHP errors that occur |
|
| 283 | - * during a request are trapped and pushed to the browser in the form of |
|
| 284 | - * a Javascript alert. |
|
| 285 | - */ |
|
| 286 | - function errorHandlerOn() |
|
| 287 | - { |
|
| 288 | - $this->bErrorHandler = true; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Turns off xajax's error handling system (default behavior). |
|
| 293 | - */ |
|
| 294 | - function errorHandlerOff() |
|
| 295 | - { |
|
| 296 | - $this->bErrorHandler = false; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Specifies a log file that will be written to by xajax during a request |
|
| 301 | - * (used only by the error handling system at present). If you don't invoke |
|
| 302 | - * this method, or you pass in "", then no log file will be written to. |
|
| 303 | - * <i>Usage:</i> <kbd>$xajax->setLogFile("/xajax_logs/errors.log");</kbd> |
|
| 304 | - */ |
|
| 305 | - function setLogFile($sFilename) |
|
| 306 | - { |
|
| 307 | - $this->sLogFile = $sFilename; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Causes xajax to clean out all output buffers before outputting a |
|
| 312 | - * response (default behavior). |
|
| 313 | - */ |
|
| 314 | - function cleanBufferOn() |
|
| 315 | - { |
|
| 316 | - $this->bCleanBuffer = true; |
|
| 317 | - } |
|
| 318 | - /** |
|
| 319 | - * Turns off xajax's output buffer cleaning. |
|
| 320 | - */ |
|
| 321 | - function cleanBufferOff() |
|
| 322 | - { |
|
| 323 | - $this->bCleanBuffer = false; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Sets the character encoding for the HTTP output based on |
|
| 328 | - * <kbd>$sEncoding</kbd>, which is a string containing the character |
|
| 329 | - * encoding to use. You don't need to use this method normally, since the |
|
| 330 | - * character encoding for the response gets set automatically based on the |
|
| 331 | - * <kbd>XAJAX_DEFAULT_CHAR_ENCODING</kbd> constant. |
|
| 332 | - * <i>Usage:</i> <kbd>$xajax->setCharEncoding("utf-8");</kbd> |
|
| 333 | - * |
|
| 334 | - * @param string the encoding type to use (utf-8, iso-8859-1, etc.) |
|
| 335 | - */ |
|
| 336 | - function setCharEncoding($sEncoding) |
|
| 337 | - { |
|
| 338 | - $this->sEncoding = $sEncoding; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Causes xajax to decode the input request args from UTF-8 to the current |
|
| 343 | - * encoding if possible. Either the iconv or mb_string extension must be |
|
| 344 | - * present for optimal functionality. |
|
| 345 | - */ |
|
| 346 | - function decodeUTF8InputOn() |
|
| 347 | - { |
|
| 348 | - $this->bDecodeUTF8Input = true; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Turns off decoding the input request args from UTF-8 (default behavior). |
|
| 353 | - */ |
|
| 354 | - function decodeUTF8InputOff() |
|
| 355 | - { |
|
| 356 | - $this->bDecodeUTF8Input = false; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Tells the response object to convert special characters to HTML entities |
|
| 361 | - * automatically (only works if the mb_string extension is available). |
|
| 362 | - */ |
|
| 363 | - function outputEntitiesOn() |
|
| 364 | - { |
|
| 365 | - $this->bOutputEntities = true; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * Tells the response object to output special characters intact. (default |
|
| 370 | - * behavior). |
|
| 371 | - */ |
|
| 372 | - function outputEntitiesOff() |
|
| 373 | - { |
|
| 374 | - $this->bOutputEntities = false; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Registers a PHP function or method to be callable through xajax in your |
|
| 379 | - * Javascript. If you want to register a function, pass in the name of that |
|
| 380 | - * function. If you want to register a static class method, pass in an |
|
| 381 | - * array like so: |
|
| 382 | - * <kbd>array("myFunctionName", "myClass", "myMethod")</kbd> |
|
| 383 | - * For an object instance method, use an object variable for the second |
|
| 384 | - * array element (and in PHP 4 make sure you put an & before the variable |
|
| 385 | - * to pass the object by reference). Note: the function name is what you |
|
| 386 | - * call via Javascript, so it can be anything as long as it doesn't |
|
| 387 | - * conflict with any other registered function name. |
|
| 388 | - * |
|
| 389 | - * <i>Usage:</i> <kbd>$xajax->registerFunction("myFunction");</kbd> |
|
| 390 | - * or: <kbd>$xajax->registerFunction(array("myFunctionName", &$myObject, "myMethod"));</kbd> |
|
| 391 | - * |
|
| 392 | - * @param mixed contains the function name or an object callback array |
|
| 393 | - * @param mixed request type (XAJAX_GET/XAJAX_POST) that should be used |
|
| 394 | - * for this function. Defaults to XAJAX_POST. |
|
| 395 | - */ |
|
| 396 | - function registerFunction($mFunction,$sRequestType=XAJAX_POST) |
|
| 397 | - { |
|
| 398 | - if (is_array($mFunction)) { |
|
| 399 | - $this->aFunctions[$mFunction[0]] = 1; |
|
| 400 | - $this->aFunctionRequestTypes[$mFunction[0]] = $sRequestType; |
|
| 401 | - $this->aObjects[$mFunction[0]] = array_slice($mFunction, 1); |
|
| 402 | - } |
|
| 403 | - else { |
|
| 404 | - $this->aFunctions[$mFunction] = 1; |
|
| 405 | - $this->aFunctionRequestTypes[$mFunction] = $sRequestType; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Registers a PHP function to be callable through xajax which is located |
|
| 411 | - * in some other file. If the function is requested the external file will |
|
| 412 | - * be included to define the function before the function is called. |
|
| 413 | - * |
|
| 414 | - * <i>Usage:</i> <kbd>$xajax->registerExternalFunction("myFunction","myFunction.inc.php",XAJAX_POST);</kbd> |
|
| 415 | - * |
|
| 416 | - * @param string contains the function name or an object callback array |
|
| 417 | - * ({@link xajax::registerFunction() see registerFunction} for |
|
| 418 | - * more info on object callback arrays) |
|
| 419 | - * @param string contains the path and filename of the include file |
|
| 420 | - * @param mixed the RequestType (XAJAX_GET/XAJAX_POST) that should be used |
|
| 421 | - * for this function. Defaults to XAJAX_POST. |
|
| 422 | - */ |
|
| 423 | - function registerExternalFunction($mFunction,$sIncludeFile,$sRequestType=XAJAX_POST) |
|
| 424 | - { |
|
| 425 | - $this->registerFunction($mFunction, $sRequestType); |
|
| 426 | - |
|
| 427 | - if (is_array($mFunction)) { |
|
| 428 | - $this->aFunctionIncludeFiles[$mFunction[0]] = $sIncludeFile; |
|
| 429 | - } |
|
| 430 | - else { |
|
| 431 | - $this->aFunctionIncludeFiles[$mFunction] = $sIncludeFile; |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Registers a PHP function to be called when xajax cannot find the |
|
| 437 | - * function being called via Javascript. Because this is technically |
|
| 438 | - * impossible when using "wrapped" functions, the catch-all feature is |
|
| 439 | - * only useful when you're directly using the xajax.call() Javascript |
|
| 440 | - * method. Use the catch-all feature when you want more dynamic ability to |
|
| 441 | - * intercept unknown calls and handle them in a custom way. |
|
| 442 | - * |
|
| 443 | - * <i>Usage:</i> <kbd>$xajax->registerCatchAllFunction("myCatchAllFunction");</kbd> |
|
| 444 | - * |
|
| 445 | - * @param string contains the function name or an object callback array |
|
| 446 | - * ({@link xajax::registerFunction() see registerFunction} for |
|
| 447 | - * more info on object callback arrays) |
|
| 448 | - */ |
|
| 449 | - function registerCatchAllFunction($mFunction) |
|
| 450 | - { |
|
| 451 | - if (is_array($mFunction)) { |
|
| 452 | - $this->sCatchAllFunction = $mFunction[0]; |
|
| 453 | - $this->aObjects[$mFunction[0]] = array_slice($mFunction, 1); |
|
| 454 | - } |
|
| 455 | - else { |
|
| 456 | - $this->sCatchAllFunction = $mFunction; |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Registers a PHP function to be called before xajax calls the requested |
|
| 462 | - * function. xajax will automatically add the request function's response |
|
| 463 | - * to the pre-function's response to create a single response. Another |
|
| 464 | - * feature is the ability to return not just a response, but an array with |
|
| 465 | - * the first element being false (a boolean) and the second being the |
|
| 466 | - * response. In this case, the pre-function's response will be returned to |
|
| 467 | - * the browser without xajax calling the requested function. |
|
| 468 | - * |
|
| 469 | - * <i>Usage:</i> <kbd>$xajax->registerPreFunction("myPreFunction");</kbd> |
|
| 470 | - * |
|
| 471 | - * @param string contains the function name or an object callback array |
|
| 472 | - * ({@link xajax::registerFunction() see registerFunction} for |
|
| 473 | - * more info on object callback arrays) |
|
| 474 | - */ |
|
| 475 | - function registerPreFunction($mFunction) |
|
| 476 | - { |
|
| 477 | - if (is_array($mFunction)) { |
|
| 478 | - $this->sPreFunction = $mFunction[0]; |
|
| 479 | - $this->aObjects[$mFunction[0]] = array_slice($mFunction, 1); |
|
| 480 | - } |
|
| 481 | - else { |
|
| 482 | - $this->sPreFunction = $mFunction; |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Returns true if xajax can process the request, false if otherwise. |
|
| 488 | - * You can use this to determine if xajax needs to process the request or |
|
| 489 | - * not. |
|
| 490 | - * |
|
| 491 | - * @return boolean |
|
| 492 | - */ |
|
| 493 | - function canProcessRequests() |
|
| 494 | - { |
|
| 495 | - if ($this->getRequestMode() != -1) return true; |
|
| 496 | - return false; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * Returns the current request mode (XAJAX_GET or XAJAX_POST), or -1 if |
|
| 501 | - * there is none. |
|
| 502 | - * |
|
| 503 | - * @return mixed |
|
| 504 | - */ |
|
| 505 | - function getRequestMode() |
|
| 506 | - { |
|
| 507 | - if (!empty($_GET["xajax"])) |
|
| 508 | - return XAJAX_GET; |
|
| 509 | - |
|
| 510 | - if (!empty($_POST["xajax"])) |
|
| 511 | - return XAJAX_POST; |
|
| 512 | - |
|
| 513 | - return -1; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * This is the main communications engine of xajax. The engine handles all |
|
| 518 | - * incoming xajax requests, calls the apporiate PHP functions (or |
|
| 519 | - * class/object methods) and passes the XML responses back to the |
|
| 520 | - * Javascript response handler. If your RequestURI is the same as your Web |
|
| 521 | - * page then this function should be called before any headers or HTML has |
|
| 522 | - * been sent. |
|
| 523 | - */ |
|
| 524 | - function processRequests() |
|
| 525 | - { |
|
| 526 | - |
|
| 527 | - $requestMode = -1; |
|
| 528 | - $sFunctionName = ""; |
|
| 529 | - $bFoundFunction = true; |
|
| 530 | - $bFunctionIsCatchAll = false; |
|
| 531 | - $sFunctionNameForSpecial = ""; |
|
| 532 | - $aArgs = array(); |
|
| 533 | - $sPreResponse = ""; |
|
| 534 | - $bEndRequest = false; |
|
| 535 | - $sResponse = ""; |
|
| 536 | - |
|
| 537 | - $requestMode = $this->getRequestMode(); |
|
| 538 | - if ($requestMode == -1) return; |
|
| 539 | - |
|
| 540 | - if ($requestMode == XAJAX_POST) |
|
| 541 | - { |
|
| 542 | - $sFunctionName = $_POST["xajax"]; |
|
| 543 | - |
|
| 544 | - if (!empty($_POST["xajaxargs"])) |
|
| 545 | - $aArgs = $_POST["xajaxargs"]; |
|
| 546 | - } |
|
| 547 | - else |
|
| 548 | - { |
|
| 549 | - header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 550 | - header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
| 551 | - header ("Cache-Control: no-cache, must-revalidate"); |
|
| 552 | - header ("Pragma: no-cache"); |
|
| 553 | - |
|
| 554 | - $sFunctionName = $_GET["xajax"]; |
|
| 555 | - |
|
| 556 | - if (!empty($_GET["xajaxargs"])) |
|
| 557 | - $aArgs = $_GET["xajaxargs"]; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - // Use xajax error handler if necessary |
|
| 561 | - if ($this->bErrorHandler) { |
|
| 562 | - $GLOBALS['xajaxErrorHandlerText'] = ""; |
|
| 563 | - set_error_handler("xajaxErrorHandler"); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - if ($this->sPreFunction) { |
|
| 567 | - if (!$this->_isFunctionCallable($this->sPreFunction)) { |
|
| 568 | - $bFoundFunction = false; |
|
| 569 | - $objResponse = new xajaxResponse(); |
|
| 570 | - $objResponse->addAlert("Unknown Pre-Function ". $this->sPreFunction); |
|
| 571 | - $sResponse = $objResponse->getXML(); |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - //include any external dependencies associated with this function name |
|
| 575 | - if (array_key_exists($sFunctionName,$this->aFunctionIncludeFiles)) |
|
| 576 | - { |
|
| 577 | - ob_start(); |
|
| 578 | - include_once($this->aFunctionIncludeFiles[$sFunctionName]); |
|
| 579 | - ob_end_clean(); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - if ($bFoundFunction) { |
|
| 583 | - $sFunctionNameForSpecial = $sFunctionName; |
|
| 584 | - if (!array_key_exists($sFunctionName, $this->aFunctions)) |
|
| 585 | - { |
|
| 586 | - if ($this->sCatchAllFunction) { |
|
| 587 | - $sFunctionName = $this->sCatchAllFunction; |
|
| 588 | - $bFunctionIsCatchAll = true; |
|
| 589 | - } |
|
| 590 | - else { |
|
| 591 | - $bFoundFunction = false; |
|
| 592 | - $objResponse = new xajaxResponse(); |
|
| 593 | - $objResponse->addAlert("Unknown Function $sFunctionName."); |
|
| 594 | - $sResponse = $objResponse->getXML(); |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - else if ($this->aFunctionRequestTypes[$sFunctionName] != $requestMode) |
|
| 598 | - { |
|
| 599 | - $bFoundFunction = false; |
|
| 600 | - $objResponse = new xajaxResponse(); |
|
| 601 | - $objResponse->addAlert("Incorrect Request Type."); |
|
| 602 | - $sResponse = $objResponse->getXML(); |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - if ($bFoundFunction) |
|
| 607 | - { |
|
| 608 | - for ($i = 0; $i < sizeof($aArgs); $i++) |
|
| 609 | - { |
|
| 610 | - // If magic quotes is on, then we need to strip the slashes from the args |
|
| 611 | - if (get_magic_quotes_gpc() == 1 && is_string($aArgs[$i])) { |
|
| 612 | - |
|
| 613 | - $aArgs[$i] = stripslashes($aArgs[$i]); |
|
| 614 | - } |
|
| 615 | - if (stristr($aArgs[$i],"<xjxobj>") != false) |
|
| 616 | - { |
|
| 617 | - $aArgs[$i] = $this->_xmlToArray("xjxobj",$aArgs[$i]); |
|
| 618 | - } |
|
| 619 | - else if (stristr($aArgs[$i],"<xjxquery>") != false) |
|
| 620 | - { |
|
| 621 | - $aArgs[$i] = $this->_xmlToArray("xjxquery",$aArgs[$i]); |
|
| 622 | - } |
|
| 623 | - else if ($this->bDecodeUTF8Input) |
|
| 624 | - { |
|
| 625 | - $aArgs[$i] = $this->_decodeUTF8Data($aArgs[$i]); |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - if ($this->sPreFunction) { |
|
| 630 | - $mPreResponse = $this->_callFunction($this->sPreFunction, array($sFunctionNameForSpecial, $aArgs)); |
|
| 631 | - if (is_array($mPreResponse) && $mPreResponse[0] === false) { |
|
| 632 | - $bEndRequest = true; |
|
| 633 | - $sPreResponse = $mPreResponse[1]; |
|
| 634 | - } |
|
| 635 | - else { |
|
| 636 | - $sPreResponse = $mPreResponse; |
|
| 637 | - } |
|
| 638 | - if (is_a($sPreResponse, "xajaxResponse")) { |
|
| 639 | - $sPreResponse = $sPreResponse->getXML(); |
|
| 640 | - } |
|
| 641 | - if ($bEndRequest) $sResponse = $sPreResponse; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - if (!$bEndRequest) { |
|
| 645 | - if (!$this->_isFunctionCallable($sFunctionName)) { |
|
| 646 | - $objResponse = new xajaxResponse(); |
|
| 647 | - $objResponse->addAlert("The Registered Function $sFunctionName Could Not Be Found."); |
|
| 648 | - $sResponse = $objResponse->getXML(); |
|
| 649 | - } |
|
| 650 | - else { |
|
| 651 | - if ($bFunctionIsCatchAll) { |
|
| 652 | - $aArgs = array($sFunctionNameForSpecial, $aArgs); |
|
| 653 | - } |
|
| 654 | - $sResponse = $this->_callFunction($sFunctionName, $aArgs); |
|
| 655 | - } |
|
| 656 | - if (is_a($sResponse, "xajaxResponse")) { |
|
| 657 | - $sResponse = $sResponse->getXML(); |
|
| 658 | - } |
|
| 659 | - if (!is_string($sResponse) || strpos($sResponse, "<xjx>") === FALSE) { |
|
| 660 | - $objResponse = new xajaxResponse(); |
|
| 661 | - $objResponse->addAlert("No XML Response Was Returned By Function $sFunctionName."); |
|
| 662 | - $sResponse = $objResponse->getXML(); |
|
| 663 | - } |
|
| 664 | - else if ($sPreResponse != "") { |
|
| 665 | - $sNewResponse = new xajaxResponse($this->sEncoding, $this->bOutputEntities); |
|
| 666 | - $sNewResponse->loadXML($sPreResponse); |
|
| 667 | - $sNewResponse->loadXML($sResponse); |
|
| 668 | - $sResponse = $sNewResponse->getXML(); |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - $sContentHeader = "Content-type: text/xml;"; |
|
| 674 | - if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0) |
|
| 675 | - $sContentHeader .= " charset=".$this->sEncoding; |
|
| 676 | - header($sContentHeader); |
|
| 677 | - if ($this->bErrorHandler && !empty( $GLOBALS['xajaxErrorHandlerText'] )) { |
|
| 678 | - $sErrorResponse = new xajaxResponse(); |
|
| 679 | - $sErrorResponse->addAlert("** PHP Error Messages: **" . $GLOBALS['xajaxErrorHandlerText']); |
|
| 680 | - if ($this->sLogFile) { |
|
| 681 | - $fH = @fopen($this->sLogFile, "a"); |
|
| 682 | - if (!$fH) { |
|
| 683 | - $sErrorResponse->addAlert("** Logging Error **\n\nxajax was unable to write to the error log file:\n" . $this->sLogFile); |
|
| 684 | - } |
|
| 685 | - else { |
|
| 686 | - fwrite($fH, "** xajax Error Log - " . strftime("%b %e %Y %I:%M:%S %p") . " **" . $GLOBALS['xajaxErrorHandlerText'] . "\n\n\n"); |
|
| 687 | - fclose($fH); |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - $sErrorResponse->loadXML($sResponse); |
|
| 692 | - $sResponse = $sErrorResponse->getXML(); |
|
| 693 | - |
|
| 694 | - } |
|
| 695 | - if ($this->bCleanBuffer) while (@ob_end_clean()); |
|
| 696 | - print $sResponse; |
|
| 697 | - if ($this->bErrorHandler) restore_error_handler(); |
|
| 698 | - |
|
| 699 | - if ($this->bExitAllowed) |
|
| 700 | - exit(); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Prints the xajax Javascript header and wrapper code into your page by |
|
| 705 | - * printing the output of the getJavascript() method. It should only be |
|
| 706 | - * called between the <pre><head> </head></pre> tags in your HTML page. |
|
| 707 | - * Remember, if you only want to obtain the result of this function, use |
|
| 708 | - * {@link xajax::getJavascript()} instead. |
|
| 709 | - * |
|
| 710 | - * <i>Usage:</i> |
|
| 711 | - * <code> |
|
| 712 | - * <head> |
|
| 713 | - * ... |
|
| 714 | - * < ?php $xajax->printJavascript(); ? > |
|
| 715 | - * </code> |
|
| 716 | - * |
|
| 717 | - * @param string the relative address of the folder where xajax has been |
|
| 718 | - * installed. For instance, if your PHP file is |
|
| 719 | - * "http://www.myserver.com/myfolder/mypage.php" |
|
| 720 | - * and xajax was installed in |
|
| 721 | - * "http://www.myserver.com/anotherfolder", then $sJsURI |
|
| 722 | - * should be set to "../anotherfolder". Defaults to assuming |
|
| 723 | - * xajax is in the same folder as your PHP file. |
|
| 724 | - * @param string the relative folder/file pair of the xajax Javascript |
|
| 725 | - * engine located within the xajax installation folder. |
|
| 726 | - * Defaults to xajax_js/xajax.js. |
|
| 727 | - */ |
|
| 728 | - function printJavascript($sJsURI="", $sJsFile=NULL) |
|
| 729 | - { |
|
| 730 | - print $this->getJavascript($sJsURI, $sJsFile); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * Returns the xajax Javascript code that should be added to your HTML page |
|
| 735 | - * between the <kbd><head> </head></kbd> tags. |
|
| 736 | - * |
|
| 737 | - * <i>Usage:</i> |
|
| 738 | - * <code> |
|
| 739 | - * < ?php $xajaxJSHead = $xajax->getJavascript(); ? > |
|
| 740 | - * <head> |
|
| 741 | - * ... |
|
| 742 | - * < ?php echo $xajaxJSHead; ? > |
|
| 743 | - * </code> |
|
| 744 | - * |
|
| 745 | - * @param string the relative address of the folder where xajax has been |
|
| 746 | - * installed. For instance, if your PHP file is |
|
| 747 | - * "http://www.myserver.com/myfolder/mypage.php" |
|
| 748 | - * and xajax was installed in |
|
| 749 | - * "http://www.myserver.com/anotherfolder", then $sJsURI |
|
| 750 | - * should be set to "../anotherfolder". Defaults to assuming |
|
| 751 | - * xajax is in the same folder as your PHP file. |
|
| 752 | - * @param string the relative folder/file pair of the xajax Javascript |
|
| 753 | - * engine located within the xajax installation folder. |
|
| 754 | - * Defaults to xajax_js/xajax.js. |
|
| 755 | - * @return string |
|
| 756 | - */ |
|
| 757 | - function getJavascript($sJsURI="", $sJsFile=NULL) |
|
| 758 | - { |
|
| 759 | - $html = $this->getJavascriptConfig(); |
|
| 760 | - $html .= $this->getJavascriptInclude($sJsURI, $sJsFile); |
|
| 761 | - |
|
| 762 | - return $html; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Returns a string containing inline Javascript that sets up the xajax |
|
| 767 | - * runtime (typically called internally by xajax from get/printJavascript). |
|
| 768 | - * |
|
| 769 | - * @return string |
|
| 770 | - */ |
|
| 771 | - function getJavascriptConfig() |
|
| 772 | - { |
|
| 773 | - $html = "\t<script type=\"text/javascript\">\n"; |
|
| 774 | - $html .= "var xajaxRequestUri=\"".$this->sRequestURI."\";\n"; |
|
| 775 | - $html .= "var xajaxDebug=".($this->bDebug?"true":"false").";\n"; |
|
| 776 | - $html .= "var xajaxStatusMessages=".($this->bStatusMessages?"true":"false").";\n"; |
|
| 777 | - $html .= "var xajaxWaitCursor=".($this->bWaitCursor?"true":"false").";\n"; |
|
| 778 | - $html .= "var xajaxDefinedGet=".XAJAX_GET.";\n"; |
|
| 779 | - $html .= "var xajaxDefinedPost=".XAJAX_POST.";\n"; |
|
| 780 | - $html .= "var xajaxLoaded=false;\n"; |
|
| 781 | - |
|
| 782 | - foreach($this->aFunctions as $sFunction => $bExists) { |
|
| 783 | - $html .= $this->_wrap($sFunction,$this->aFunctionRequestTypes[$sFunction]); |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - $html .= "\t</script>\n"; |
|
| 787 | - return $html; |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * Returns a string containing a Javascript include of the xajax.js file |
|
| 792 | - * along with a check to see if the file loaded after six seconds |
|
| 793 | - * (typically called internally by xajax from get/printJavascript). |
|
| 794 | - * |
|
| 795 | - * @param string the relative address of the folder where xajax has been |
|
| 796 | - * installed. For instance, if your PHP file is |
|
| 797 | - * "http://www.myserver.com/myfolder/mypage.php" |
|
| 798 | - * and xajax was installed in |
|
| 799 | - * "http://www.myserver.com/anotherfolder", then $sJsURI |
|
| 800 | - * should be set to "../anotherfolder". Defaults to assuming |
|
| 801 | - * xajax is in the same folder as your PHP file. |
|
| 802 | - * @param string the relative folder/file pair of the xajax Javascript |
|
| 803 | - * engine located within the xajax installation folder. |
|
| 804 | - * Defaults to xajax_js/xajax.js. |
|
| 805 | - * @return string |
|
| 806 | - */ |
|
| 807 | - function getJavascriptInclude($sJsURI="", $sJsFile=NULL) |
|
| 808 | - { |
|
| 809 | - if ($sJsFile == NULL) $sJsFile = "xajax_js/xajax.js"; |
|
| 810 | - |
|
| 811 | - if ($sJsURI != "" && substr($sJsURI, -1) != "/") $sJsURI .= "/"; |
|
| 812 | - |
|
| 813 | - $html = "\t<script type=\"text/javascript\" src=\"" . $sJsURI . $sJsFile . "\"></script>\n"; |
|
| 814 | - $html .= "\t<script type=\"text/javascript\">\n"; |
|
| 815 | - $html .= "window.setTimeout(function () { if (!xajaxLoaded) { alert('Error: the xajax Javascript file could not be included. Perhaps the URL is incorrect?\\nURL: {$sJsURI}{$sJsFile}'); } }, 6000);\n"; |
|
| 816 | - $html .= "\t</script>\n"; |
|
| 817 | - return $html; |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * This method can be used to create a new xajax.js file out of the |
|
| 822 | - * xajax_uncompressed.js file (which will only happen if xajax.js doesn't |
|
| 823 | - * already exist on the filesystem). |
|
| 824 | - * |
|
| 825 | - * @param string an optional argument containing the full server file path |
|
| 826 | - * of xajax.js. |
|
| 827 | - */ |
|
| 828 | - function autoCompressJavascript($sJsFullFilename=NULL) |
|
| 829 | - { |
|
| 830 | - $sJsFile = "xajax_js/xajax.js"; |
|
| 831 | - |
|
| 832 | - if ($sJsFullFilename) { |
|
| 833 | - $realJsFile = $sJsFullFilename; |
|
| 834 | - } |
|
| 835 | - else { |
|
| 836 | - $realPath = realpath(dirname(__FILE__)); |
|
| 837 | - $realJsFile = $realPath . "/". $sJsFile; |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - // Create a compressed file if necessary |
|
| 841 | - if (!file_exists($realJsFile)) { |
|
| 842 | - $srcFile = str_replace(".js", "_uncompressed.js", $realJsFile); |
|
| 843 | - if (!file_exists($srcFile)) { |
|
| 844 | - trigger_error("The xajax uncompressed Javascript file could not be found in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR); |
|
| 845 | - } |
|
| 846 | - require(dirname(__FILE__)."/xajaxCompress.php"); |
|
| 847 | - $javaScript = implode('', file($srcFile)); |
|
| 848 | - $compressedScript = xajaxCompressJavascript($javaScript); |
|
| 849 | - $fH = @fopen($realJsFile, "w"); |
|
| 850 | - if (!$fH) { |
|
| 851 | - trigger_error("The xajax compressed javascript file could not be written in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR); |
|
| 852 | - } |
|
| 853 | - else { |
|
| 854 | - fwrite($fH, $compressedScript); |
|
| 855 | - fclose($fH); |
|
| 856 | - } |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * Returns the current URL based upon the SERVER vars. |
|
| 862 | - * |
|
| 863 | - * @access private |
|
| 864 | - * @return string |
|
| 865 | - */ |
|
| 866 | - function _detectURI() { |
|
| 867 | - $aURL = array(); |
|
| 868 | - |
|
| 869 | - // Try to get the request URL |
|
| 870 | - if (!empty($_SERVER['REQUEST_URI'])) { |
|
| 871 | - $aURL = parse_url($_SERVER['REQUEST_URI']); |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - // Fill in the empty values |
|
| 875 | - if (empty($aURL['scheme'])) { |
|
| 876 | - if (!empty($_SERVER['HTTP_SCHEME'])) { |
|
| 877 | - $aURL['scheme'] = $_SERVER['HTTP_SCHEME']; |
|
| 878 | - } else { |
|
| 879 | - $aURL['scheme'] = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ? 'https' : 'http'; |
|
| 880 | - } |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - if (empty($aURL['host'])) { |
|
| 884 | - if (!empty($_SERVER['HTTP_HOST'])) { |
|
| 885 | - if (strpos($_SERVER['HTTP_HOST'], ':') > 0) { |
|
| 886 | - list($aURL['host'], $aURL['port']) = explode(':', $_SERVER['HTTP_HOST']); |
|
| 887 | - } else { |
|
| 888 | - $aURL['host'] = $_SERVER['HTTP_HOST']; |
|
| 889 | - } |
|
| 890 | - } else if (!empty($_SERVER['SERVER_NAME'])) { |
|
| 891 | - $aURL['host'] = $_SERVER['SERVER_NAME']; |
|
| 892 | - } else { |
|
| 893 | - print "xajax Error: xajax failed to automatically identify your Request URI."; |
|
| 894 | - print "Please set the Request URI explicitly when you instantiate the xajax object."; |
|
| 895 | - exit(); |
|
| 896 | - } |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - if (empty($aURL['port']) && !empty($_SERVER['SERVER_PORT'])) { |
|
| 900 | - $aURL['port'] = $_SERVER['SERVER_PORT']; |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - if (empty($aURL['path'])) { |
|
| 904 | - if (!empty($_SERVER['PATH_INFO'])) { |
|
| 905 | - $sPath = parse_url($_SERVER['PATH_INFO']); |
|
| 906 | - } else { |
|
| 907 | - $sPath = parse_url(api_get_self()); |
|
| 908 | - } |
|
| 909 | - $aURL['path'] = $sPath['path']; |
|
| 910 | - unset($sPath); |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - if (!empty($aURL['query'])) { |
|
| 914 | - $aURL['query'] = '?'.$aURL['query']; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - // Build the URL: Start with scheme, user and pass |
|
| 918 | - $sURL = $aURL['scheme'].'://'; |
|
| 919 | - if (!empty($aURL['user'])) { |
|
| 920 | - $sURL.= $aURL['user']; |
|
| 921 | - if (!empty($aURL['pass'])) { |
|
| 922 | - $sURL.= ':'.$aURL['pass']; |
|
| 923 | - } |
|
| 924 | - $sURL.= '@'; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - // Add the host |
|
| 928 | - $sURL.= $aURL['host']; |
|
| 929 | - |
|
| 930 | - // Add the port if needed |
|
| 931 | - if (!empty($aURL['port']) && (($aURL['scheme'] == 'http' && $aURL['port'] != 80) || ($aURL['scheme'] == 'https' && $aURL['port'] != 443))) { |
|
| 932 | - $sURL.= ':'.$aURL['port']; |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - // Add the path and the query string |
|
| 936 | - $sURL.= $aURL['path'].@$aURL['query']; |
|
| 937 | - |
|
| 938 | - // Clean up |
|
| 939 | - unset($aURL); |
|
| 940 | - return $sURL; |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - /** |
|
| 944 | - * Returns true if the function name is associated with an object callback, |
|
| 945 | - * false if not. |
|
| 946 | - * |
|
| 947 | - * @param string the name of the function |
|
| 948 | - * @access private |
|
| 949 | - * @return boolean |
|
| 950 | - */ |
|
| 951 | - function _isObjectCallback($sFunction) |
|
| 952 | - { |
|
| 953 | - if (array_key_exists($sFunction, $this->aObjects)) return true; |
|
| 954 | - return false; |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * Returns true if the function or object callback can be called, false if |
|
| 959 | - * not. |
|
| 960 | - * |
|
| 961 | - * @param string the name of the function |
|
| 962 | - * @access private |
|
| 963 | - * @return boolean |
|
| 964 | - */ |
|
| 965 | - function _isFunctionCallable($sFunction) |
|
| 966 | - { |
|
| 967 | - if ($this->_isObjectCallback($sFunction)) { |
|
| 968 | - if (is_object($this->aObjects[$sFunction][0])) { |
|
| 969 | - return method_exists($this->aObjects[$sFunction][0], $this->aObjects[$sFunction][1]); |
|
| 970 | - } |
|
| 971 | - else { |
|
| 972 | - return is_callable($this->aObjects[$sFunction]); |
|
| 973 | - } |
|
| 974 | - } |
|
| 975 | - else { |
|
| 976 | - return function_exists($sFunction); |
|
| 977 | - } |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - /** |
|
| 981 | - * Calls the function, class method, or object method with the supplied |
|
| 982 | - * arguments. |
|
| 983 | - * |
|
| 984 | - * @param string the name of the function |
|
| 985 | - * @param array arguments to pass to the function |
|
| 986 | - * @access private |
|
| 987 | - * @return mixed the output of the called function or method |
|
| 988 | - */ |
|
| 989 | - function _callFunction($sFunction, $aArgs) |
|
| 990 | - { |
|
| 991 | - if ($this->_isObjectCallback($sFunction)) { |
|
| 992 | - $mReturn = call_user_func_array($this->aObjects[$sFunction], $aArgs); |
|
| 993 | - } |
|
| 994 | - else { |
|
| 995 | - $mReturn = call_user_func_array($sFunction, $aArgs); |
|
| 996 | - } |
|
| 997 | - return $mReturn; |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - /** |
|
| 1001 | - * Generates the Javascript wrapper for the specified PHP function. |
|
| 1002 | - * |
|
| 1003 | - * @param string the name of the function |
|
| 1004 | - * @param mixed the request type |
|
| 1005 | - * @access private |
|
| 1006 | - * @return string |
|
| 1007 | - */ |
|
| 1008 | - function _wrap($sFunction,$sRequestType=XAJAX_POST) |
|
| 1009 | - { |
|
| 1010 | - $js = "function ".$this->sWrapperPrefix."$sFunction(){return xajax.call(\"$sFunction\", arguments, ".$sRequestType.");}\n"; |
|
| 1011 | - return $js; |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * Takes a string containing xajax xjxobj XML or xjxquery XML and builds an |
|
| 1016 | - * array representation of it to pass as an argument to the PHP function |
|
| 1017 | - * being called. |
|
| 1018 | - * |
|
| 1019 | - * @param string the root tag of the XML |
|
| 1020 | - * @param string XML to convert |
|
| 1021 | - * @access private |
|
| 1022 | - * @return array |
|
| 1023 | - */ |
|
| 1024 | - function _xmlToArray($rootTag, $sXml) |
|
| 1025 | - { |
|
| 1026 | - $aArray = array(); |
|
| 1027 | - $sXml = str_replace("<$rootTag>","<$rootTag>|~|",$sXml); |
|
| 1028 | - $sXml = str_replace("</$rootTag>","</$rootTag>|~|",$sXml); |
|
| 1029 | - $sXml = str_replace("<e>","<e>|~|",$sXml); |
|
| 1030 | - $sXml = str_replace("</e>","</e>|~|",$sXml); |
|
| 1031 | - $sXml = str_replace("<k>","<k>|~|",$sXml); |
|
| 1032 | - $sXml = str_replace("</k>","|~|</k>|~|",$sXml); |
|
| 1033 | - $sXml = str_replace("<v>","<v>|~|",$sXml); |
|
| 1034 | - $sXml = str_replace("</v>","|~|</v>|~|",$sXml); |
|
| 1035 | - $sXml = str_replace("<q>","<q>|~|",$sXml); |
|
| 1036 | - $sXml = str_replace("</q>","|~|</q>|~|",$sXml); |
|
| 1037 | - |
|
| 1038 | - $this->aObjArray = explode("|~|",$sXml); |
|
| 1039 | - |
|
| 1040 | - $this->iPos = 0; |
|
| 1041 | - $aArray = $this->_parseObjXml($rootTag); |
|
| 1042 | - |
|
| 1043 | - return $aArray; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - /** |
|
| 1047 | - * A recursive function that generates an array from the contents of |
|
| 1048 | - * $this->aObjArray. |
|
| 1049 | - * |
|
| 1050 | - * @param string the root tag of the XML |
|
| 1051 | - * @access private |
|
| 1052 | - * @return array |
|
| 1053 | - */ |
|
| 1054 | - function _parseObjXml($rootTag) |
|
| 1055 | - { |
|
| 1056 | - $aArray = array(); |
|
| 1057 | - |
|
| 1058 | - if ($rootTag == "xjxobj") |
|
| 1059 | - { |
|
| 1060 | - while(!stristr($this->aObjArray[$this->iPos],"</xjxobj>")) |
|
| 1061 | - { |
|
| 1062 | - $this->iPos++; |
|
| 1063 | - if(stristr($this->aObjArray[$this->iPos],"<e>")) |
|
| 1064 | - { |
|
| 1065 | - $key = ""; |
|
| 1066 | - $value = null; |
|
| 1067 | - |
|
| 1068 | - $this->iPos++; |
|
| 1069 | - while(!stristr($this->aObjArray[$this->iPos],"</e>")) |
|
| 1070 | - { |
|
| 1071 | - if(stristr($this->aObjArray[$this->iPos],"<k>")) |
|
| 1072 | - { |
|
| 1073 | - $this->iPos++; |
|
| 1074 | - while(!stristr($this->aObjArray[$this->iPos],"</k>")) |
|
| 1075 | - { |
|
| 1076 | - $key .= $this->aObjArray[$this->iPos]; |
|
| 1077 | - $this->iPos++; |
|
| 1078 | - } |
|
| 1079 | - } |
|
| 1080 | - if(stristr($this->aObjArray[$this->iPos],"<v>")) |
|
| 1081 | - { |
|
| 1082 | - $this->iPos++; |
|
| 1083 | - while(!stristr($this->aObjArray[$this->iPos],"</v>")) |
|
| 1084 | - { |
|
| 1085 | - if(stristr($this->aObjArray[$this->iPos],"<xjxobj>")) |
|
| 1086 | - { |
|
| 1087 | - $value = $this->_parseObjXml("xjxobj"); |
|
| 1088 | - $this->iPos++; |
|
| 1089 | - } |
|
| 1090 | - else |
|
| 1091 | - { |
|
| 1092 | - $value .= $this->aObjArray[$this->iPos]; |
|
| 1093 | - if ($this->bDecodeUTF8Input) |
|
| 1094 | - { |
|
| 1095 | - $value = $this->_decodeUTF8Data($value); |
|
| 1096 | - } |
|
| 1097 | - } |
|
| 1098 | - $this->iPos++; |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - $this->iPos++; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - $aArray[$key]=$value; |
|
| 1105 | - } |
|
| 1106 | - } |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - if ($rootTag == "xjxquery") |
|
| 1110 | - { |
|
| 1111 | - $sQuery = ""; |
|
| 1112 | - $this->iPos++; |
|
| 1113 | - while(!stristr($this->aObjArray[$this->iPos],"</xjxquery>")) |
|
| 1114 | - { |
|
| 1115 | - if (stristr($this->aObjArray[$this->iPos],"<q>") || stristr($this->aObjArray[$this->iPos],"</q>")) |
|
| 1116 | - { |
|
| 1117 | - $this->iPos++; |
|
| 1118 | - continue; |
|
| 1119 | - } |
|
| 1120 | - $sQuery .= $this->aObjArray[$this->iPos]; |
|
| 1121 | - $this->iPos++; |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - parse_str($sQuery, $aArray); |
|
| 1125 | - if ($this->bDecodeUTF8Input) |
|
| 1126 | - { |
|
| 1127 | - foreach($aArray as $key => $value) |
|
| 1128 | - { |
|
| 1129 | - $aArray[$key] = $this->_decodeUTF8Data($value); |
|
| 1130 | - } |
|
| 1131 | - } |
|
| 1132 | - // If magic quotes is on, then we need to strip the slashes from the |
|
| 1133 | - // array values because of the parse_str pass which adds slashes |
|
| 1134 | - if (get_magic_quotes_gpc() == 1) { |
|
| 1135 | - $newArray = array(); |
|
| 1136 | - foreach ($aArray as $sKey => $sValue) { |
|
| 1137 | - if (is_string($sValue)) |
|
| 1138 | - $newArray[$sKey] = stripslashes($sValue); |
|
| 1139 | - else |
|
| 1140 | - $newArray[$sKey] = $sValue; |
|
| 1141 | - } |
|
| 1142 | - $aArray = $newArray; |
|
| 1143 | - } |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - return $aArray; |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - /** |
|
| 1150 | - * Decodes string data from UTF-8 to the current xajax encoding. |
|
| 1151 | - * |
|
| 1152 | - * @param string data to convert |
|
| 1153 | - * @access private |
|
| 1154 | - * @return string converted data |
|
| 1155 | - */ |
|
| 1156 | - function _decodeUTF8Data($sData) |
|
| 1157 | - { |
|
| 1158 | - $sValue = $sData; |
|
| 1159 | - if ($this->bDecodeUTF8Input) |
|
| 1160 | - { |
|
| 1161 | - $sFuncToUse = NULL; |
|
| 1162 | - |
|
| 1163 | - // An adaptation for the Dokeos LMS, 22-AUG-2009. |
|
| 1164 | - if (function_exists('api_convert_encoding')) |
|
| 1165 | - { |
|
| 1166 | - $sFuncToUse = "api_convert_encoding"; |
|
| 1167 | - } |
|
| 1168 | - //if (function_exists('iconv')) |
|
| 1169 | - elseif (function_exists('iconv')) |
|
| 1170 | - // |
|
| 1171 | - { |
|
| 1172 | - $sFuncToUse = "iconv"; |
|
| 1173 | - } |
|
| 1174 | - else if (function_exists('mb_convert_encoding')) |
|
| 1175 | - { |
|
| 1176 | - $sFuncToUse = "mb_convert_encoding"; |
|
| 1177 | - } |
|
| 1178 | - else if ($this->sEncoding == "ISO-8859-1") |
|
| 1179 | - { |
|
| 1180 | - $sFuncToUse = "utf8_decode"; |
|
| 1181 | - } |
|
| 1182 | - else |
|
| 1183 | - { |
|
| 1184 | - trigger_error("The incoming xajax data could not be converted from UTF-8", E_USER_NOTICE); |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - if ($sFuncToUse) |
|
| 1188 | - { |
|
| 1189 | - if (is_string($sValue)) |
|
| 1190 | - { |
|
| 1191 | - if ($sFuncToUse == "iconv") |
|
| 1192 | - { |
|
| 1193 | - $sValue = iconv("UTF-8", $this->sEncoding.'//TRANSLIT', $sValue); |
|
| 1194 | - } |
|
| 1195 | - else if ($sFuncToUse == "mb_convert_encoding") |
|
| 1196 | - { |
|
| 1197 | - $sValue = mb_convert_encoding($sValue, $this->sEncoding, "UTF-8"); |
|
| 1198 | - } |
|
| 1199 | - // Added code, an adaptation for the Dokeos LMS, 22-AUG-2009. |
|
| 1200 | - else if ($sFuncToUse == "api_convert_encoding") |
|
| 1201 | - { |
|
| 1202 | - $sValue = api_convert_encoding($sValue, $this->sEncoding, "UTF-8"); |
|
| 1203 | - } |
|
| 1204 | - // |
|
| 1205 | - else |
|
| 1206 | - { |
|
| 1207 | - $sValue = utf8_decode($sValue); |
|
| 1208 | - } |
|
| 1209 | - } |
|
| 1210 | - } |
|
| 1211 | - } |
|
| 1212 | - return $sValue; |
|
| 1213 | - } |
|
| 78 | + /** |
|
| 79 | + * @var array Array of PHP functions that will be callable through javascript wrappers |
|
| 80 | + */ |
|
| 81 | + var $aFunctions; |
|
| 82 | + /** |
|
| 83 | + * @var array Array of object callbacks that will allow Javascript to call PHP methods (key=function name) |
|
| 84 | + */ |
|
| 85 | + var $aObjects; |
|
| 86 | + /** |
|
| 87 | + * @var array Array of RequestTypes to be used with each function (key=function name) |
|
| 88 | + */ |
|
| 89 | + var $aFunctionRequestTypes; |
|
| 90 | + /** |
|
| 91 | + * @var array Array of Include Files for any external functions (key=function name) |
|
| 92 | + */ |
|
| 93 | + var $aFunctionIncludeFiles; |
|
| 94 | + /** |
|
| 95 | + * @var string Name of the PHP function to call if no callable function was found |
|
| 96 | + */ |
|
| 97 | + var $sCatchAllFunction; |
|
| 98 | + /** |
|
| 99 | + * @var string Name of the PHP function to call before any other function |
|
| 100 | + */ |
|
| 101 | + var $sPreFunction; |
|
| 102 | + /** |
|
| 103 | + * @var string The URI for making requests to the xajax object |
|
| 104 | + */ |
|
| 105 | + var $sRequestURI; |
|
| 106 | + /** |
|
| 107 | + * @var string The prefix to prepend to the javascript wraper function name |
|
| 108 | + */ |
|
| 109 | + var $sWrapperPrefix; |
|
| 110 | + /** |
|
| 111 | + * @var boolean Show debug messages (default false) |
|
| 112 | + */ |
|
| 113 | + var $bDebug; |
|
| 114 | + /** |
|
| 115 | + * @var boolean Show messages in the client browser's status bar (default false) |
|
| 116 | + */ |
|
| 117 | + var $bStatusMessages; |
|
| 118 | + /** |
|
| 119 | + * @var boolean Allow xajax to exit after processing a request (default true) |
|
| 120 | + */ |
|
| 121 | + var $bExitAllowed; |
|
| 122 | + /** |
|
| 123 | + * @var boolean Use wait cursor in browser (default true) |
|
| 124 | + */ |
|
| 125 | + var $bWaitCursor; |
|
| 126 | + /** |
|
| 127 | + * @var boolean Use an special xajax error handler so the errors are sent to the browser properly (default false) |
|
| 128 | + */ |
|
| 129 | + var $bErrorHandler; |
|
| 130 | + /** |
|
| 131 | + * @var string Specify what, if any, file xajax should log errors to (and more information in a future release) |
|
| 132 | + */ |
|
| 133 | + var $sLogFile; |
|
| 134 | + /** |
|
| 135 | + * @var boolean Clean all output buffers before outputting response (default false) |
|
| 136 | + */ |
|
| 137 | + var $bCleanBuffer; |
|
| 138 | + /** |
|
| 139 | + * @var string String containing the character encoding used |
|
| 140 | + */ |
|
| 141 | + var $sEncoding; |
|
| 142 | + /** |
|
| 143 | + * @var boolean Decode input request args from UTF-8 (default false) |
|
| 144 | + */ |
|
| 145 | + var $bDecodeUTF8Input; |
|
| 146 | + /** |
|
| 147 | + * @var boolean Convert special characters to HTML entities (default false) |
|
| 148 | + */ |
|
| 149 | + var $bOutputEntities; |
|
| 150 | + /** |
|
| 151 | + * @var array Array for parsing complex objects |
|
| 152 | + */ |
|
| 153 | + var $aObjArray; |
|
| 154 | + /** |
|
| 155 | + * @var integer Position in $aObjArray |
|
| 156 | + */ |
|
| 157 | + var $iPos; |
|
| 158 | + |
|
| 159 | + /**#@-*/ |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Constructor. You can set some extra xajax options right away or use |
|
| 163 | + * individual methods later to set options. |
|
| 164 | + * |
|
| 165 | + * @param string defaults to the current browser URI |
|
| 166 | + * @param string defaults to "xajax_"; |
|
| 167 | + * @param string defaults to XAJAX_DEFAULT_CHAR_ENCODING defined above |
|
| 168 | + * @param boolean defaults to false |
|
| 169 | + */ |
|
| 170 | + public function __construct($sRequestURI="",$sWrapperPrefix="xajax_",$sEncoding=XAJAX_DEFAULT_CHAR_ENCODING,$bDebug=false) |
|
| 171 | + { |
|
| 172 | + $this->aFunctions = array(); |
|
| 173 | + $this->aObjects = array(); |
|
| 174 | + $this->aFunctionIncludeFiles = array(); |
|
| 175 | + $this->sRequestURI = $sRequestURI; |
|
| 176 | + if ($this->sRequestURI == "") |
|
| 177 | + $this->sRequestURI = $this->_detectURI(); |
|
| 178 | + $this->sWrapperPrefix = $sWrapperPrefix; |
|
| 179 | + $this->bDebug = $bDebug; |
|
| 180 | + $this->bStatusMessages = false; |
|
| 181 | + $this->bWaitCursor = true; |
|
| 182 | + $this->bExitAllowed = true; |
|
| 183 | + $this->bErrorHandler = false; |
|
| 184 | + $this->sLogFile = ""; |
|
| 185 | + $this->bCleanBuffer = false; |
|
| 186 | + $this->setCharEncoding($sEncoding); |
|
| 187 | + $this->bDecodeUTF8Input = false; |
|
| 188 | + $this->bOutputEntities = false; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Sets the URI to which requests will be made. |
|
| 193 | + * <i>Usage:</i> <kbd>$xajax->setRequestURI("http://www.xajaxproject.org");</kbd> |
|
| 194 | + * |
|
| 195 | + * @param string the URI (can be absolute or relative) of the PHP script |
|
| 196 | + * that will be accessed when an xajax request occurs |
|
| 197 | + */ |
|
| 198 | + function setRequestURI($sRequestURI) |
|
| 199 | + { |
|
| 200 | + $this->sRequestURI = $sRequestURI; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Sets the prefix that will be appended to the Javascript wrapper |
|
| 205 | + * functions (default is "xajax_"). |
|
| 206 | + * |
|
| 207 | + * @param string |
|
| 208 | + */ |
|
| 209 | + // |
|
| 210 | + function setWrapperPrefix($sPrefix) |
|
| 211 | + { |
|
| 212 | + $this->sWrapperPrefix = $sPrefix; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Enables debug messages for xajax. |
|
| 217 | + * */ |
|
| 218 | + function debugOn() |
|
| 219 | + { |
|
| 220 | + $this->bDebug = true; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Disables debug messages for xajax (default behavior). |
|
| 225 | + */ |
|
| 226 | + function debugOff() |
|
| 227 | + { |
|
| 228 | + $this->bDebug = false; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Enables messages in the browser's status bar for xajax. |
|
| 233 | + */ |
|
| 234 | + function statusMessagesOn() |
|
| 235 | + { |
|
| 236 | + $this->bStatusMessages = true; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Disables messages in the browser's status bar for xajax (default behavior). |
|
| 241 | + */ |
|
| 242 | + function statusMessagesOff() |
|
| 243 | + { |
|
| 244 | + $this->bStatusMessages = false; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Enables the wait cursor to be displayed in the browser (default behavior). |
|
| 249 | + */ |
|
| 250 | + function waitCursorOn() |
|
| 251 | + { |
|
| 252 | + $this->bWaitCursor = true; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Disables the wait cursor to be displayed in the browser. |
|
| 257 | + */ |
|
| 258 | + function waitCursorOff() |
|
| 259 | + { |
|
| 260 | + $this->bWaitCursor = false; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Enables xajax to exit immediately after processing a request and |
|
| 265 | + * sending the response back to the browser (default behavior). |
|
| 266 | + */ |
|
| 267 | + function exitAllowedOn() |
|
| 268 | + { |
|
| 269 | + $this->bExitAllowed = true; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Disables xajax's default behavior of exiting immediately after |
|
| 274 | + * processing a request and sending the response back to the browser. |
|
| 275 | + */ |
|
| 276 | + function exitAllowedOff() |
|
| 277 | + { |
|
| 278 | + $this->bExitAllowed = false; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Turns on xajax's error handling system so that PHP errors that occur |
|
| 283 | + * during a request are trapped and pushed to the browser in the form of |
|
| 284 | + * a Javascript alert. |
|
| 285 | + */ |
|
| 286 | + function errorHandlerOn() |
|
| 287 | + { |
|
| 288 | + $this->bErrorHandler = true; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Turns off xajax's error handling system (default behavior). |
|
| 293 | + */ |
|
| 294 | + function errorHandlerOff() |
|
| 295 | + { |
|
| 296 | + $this->bErrorHandler = false; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Specifies a log file that will be written to by xajax during a request |
|
| 301 | + * (used only by the error handling system at present). If you don't invoke |
|
| 302 | + * this method, or you pass in "", then no log file will be written to. |
|
| 303 | + * <i>Usage:</i> <kbd>$xajax->setLogFile("/xajax_logs/errors.log");</kbd> |
|
| 304 | + */ |
|
| 305 | + function setLogFile($sFilename) |
|
| 306 | + { |
|
| 307 | + $this->sLogFile = $sFilename; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Causes xajax to clean out all output buffers before outputting a |
|
| 312 | + * response (default behavior). |
|
| 313 | + */ |
|
| 314 | + function cleanBufferOn() |
|
| 315 | + { |
|
| 316 | + $this->bCleanBuffer = true; |
|
| 317 | + } |
|
| 318 | + /** |
|
| 319 | + * Turns off xajax's output buffer cleaning. |
|
| 320 | + */ |
|
| 321 | + function cleanBufferOff() |
|
| 322 | + { |
|
| 323 | + $this->bCleanBuffer = false; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Sets the character encoding for the HTTP output based on |
|
| 328 | + * <kbd>$sEncoding</kbd>, which is a string containing the character |
|
| 329 | + * encoding to use. You don't need to use this method normally, since the |
|
| 330 | + * character encoding for the response gets set automatically based on the |
|
| 331 | + * <kbd>XAJAX_DEFAULT_CHAR_ENCODING</kbd> constant. |
|
| 332 | + * <i>Usage:</i> <kbd>$xajax->setCharEncoding("utf-8");</kbd> |
|
| 333 | + * |
|
| 334 | + * @param string the encoding type to use (utf-8, iso-8859-1, etc.) |
|
| 335 | + */ |
|
| 336 | + function setCharEncoding($sEncoding) |
|
| 337 | + { |
|
| 338 | + $this->sEncoding = $sEncoding; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Causes xajax to decode the input request args from UTF-8 to the current |
|
| 343 | + * encoding if possible. Either the iconv or mb_string extension must be |
|
| 344 | + * present for optimal functionality. |
|
| 345 | + */ |
|
| 346 | + function decodeUTF8InputOn() |
|
| 347 | + { |
|
| 348 | + $this->bDecodeUTF8Input = true; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Turns off decoding the input request args from UTF-8 (default behavior). |
|
| 353 | + */ |
|
| 354 | + function decodeUTF8InputOff() |
|
| 355 | + { |
|
| 356 | + $this->bDecodeUTF8Input = false; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Tells the response object to convert special characters to HTML entities |
|
| 361 | + * automatically (only works if the mb_string extension is available). |
|
| 362 | + */ |
|
| 363 | + function outputEntitiesOn() |
|
| 364 | + { |
|
| 365 | + $this->bOutputEntities = true; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * Tells the response object to output special characters intact. (default |
|
| 370 | + * behavior). |
|
| 371 | + */ |
|
| 372 | + function outputEntitiesOff() |
|
| 373 | + { |
|
| 374 | + $this->bOutputEntities = false; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Registers a PHP function or method to be callable through xajax in your |
|
| 379 | + * Javascript. If you want to register a function, pass in the name of that |
|
| 380 | + * function. If you want to register a static class method, pass in an |
|
| 381 | + * array like so: |
|
| 382 | + * <kbd>array("myFunctionName", "myClass", "myMethod")</kbd> |
|
| 383 | + * For an object instance method, use an object variable for the second |
|
| 384 | + * array element (and in PHP 4 make sure you put an & before the variable |
|
| 385 | + * to pass the object by reference). Note: the function name is what you |
|
| 386 | + * call via Javascript, so it can be anything as long as it doesn't |
|
| 387 | + * conflict with any other registered function name. |
|
| 388 | + * |
|
| 389 | + * <i>Usage:</i> <kbd>$xajax->registerFunction("myFunction");</kbd> |
|
| 390 | + * or: <kbd>$xajax->registerFunction(array("myFunctionName", &$myObject, "myMethod"));</kbd> |
|
| 391 | + * |
|
| 392 | + * @param mixed contains the function name or an object callback array |
|
| 393 | + * @param mixed request type (XAJAX_GET/XAJAX_POST) that should be used |
|
| 394 | + * for this function. Defaults to XAJAX_POST. |
|
| 395 | + */ |
|
| 396 | + function registerFunction($mFunction,$sRequestType=XAJAX_POST) |
|
| 397 | + { |
|
| 398 | + if (is_array($mFunction)) { |
|
| 399 | + $this->aFunctions[$mFunction[0]] = 1; |
|
| 400 | + $this->aFunctionRequestTypes[$mFunction[0]] = $sRequestType; |
|
| 401 | + $this->aObjects[$mFunction[0]] = array_slice($mFunction, 1); |
|
| 402 | + } |
|
| 403 | + else { |
|
| 404 | + $this->aFunctions[$mFunction] = 1; |
|
| 405 | + $this->aFunctionRequestTypes[$mFunction] = $sRequestType; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Registers a PHP function to be callable through xajax which is located |
|
| 411 | + * in some other file. If the function is requested the external file will |
|
| 412 | + * be included to define the function before the function is called. |
|
| 413 | + * |
|
| 414 | + * <i>Usage:</i> <kbd>$xajax->registerExternalFunction("myFunction","myFunction.inc.php",XAJAX_POST);</kbd> |
|
| 415 | + * |
|
| 416 | + * @param string contains the function name or an object callback array |
|
| 417 | + * ({@link xajax::registerFunction() see registerFunction} for |
|
| 418 | + * more info on object callback arrays) |
|
| 419 | + * @param string contains the path and filename of the include file |
|
| 420 | + * @param mixed the RequestType (XAJAX_GET/XAJAX_POST) that should be used |
|
| 421 | + * for this function. Defaults to XAJAX_POST. |
|
| 422 | + */ |
|
| 423 | + function registerExternalFunction($mFunction,$sIncludeFile,$sRequestType=XAJAX_POST) |
|
| 424 | + { |
|
| 425 | + $this->registerFunction($mFunction, $sRequestType); |
|
| 426 | + |
|
| 427 | + if (is_array($mFunction)) { |
|
| 428 | + $this->aFunctionIncludeFiles[$mFunction[0]] = $sIncludeFile; |
|
| 429 | + } |
|
| 430 | + else { |
|
| 431 | + $this->aFunctionIncludeFiles[$mFunction] = $sIncludeFile; |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Registers a PHP function to be called when xajax cannot find the |
|
| 437 | + * function being called via Javascript. Because this is technically |
|
| 438 | + * impossible when using "wrapped" functions, the catch-all feature is |
|
| 439 | + * only useful when you're directly using the xajax.call() Javascript |
|
| 440 | + * method. Use the catch-all feature when you want more dynamic ability to |
|
| 441 | + * intercept unknown calls and handle them in a custom way. |
|
| 442 | + * |
|
| 443 | + * <i>Usage:</i> <kbd>$xajax->registerCatchAllFunction("myCatchAllFunction");</kbd> |
|
| 444 | + * |
|
| 445 | + * @param string contains the function name or an object callback array |
|
| 446 | + * ({@link xajax::registerFunction() see registerFunction} for |
|
| 447 | + * more info on object callback arrays) |
|
| 448 | + */ |
|
| 449 | + function registerCatchAllFunction($mFunction) |
|
| 450 | + { |
|
| 451 | + if (is_array($mFunction)) { |
|
| 452 | + $this->sCatchAllFunction = $mFunction[0]; |
|
| 453 | + $this->aObjects[$mFunction[0]] = array_slice($mFunction, 1); |
|
| 454 | + } |
|
| 455 | + else { |
|
| 456 | + $this->sCatchAllFunction = $mFunction; |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Registers a PHP function to be called before xajax calls the requested |
|
| 462 | + * function. xajax will automatically add the request function's response |
|
| 463 | + * to the pre-function's response to create a single response. Another |
|
| 464 | + * feature is the ability to return not just a response, but an array with |
|
| 465 | + * the first element being false (a boolean) and the second being the |
|
| 466 | + * response. In this case, the pre-function's response will be returned to |
|
| 467 | + * the browser without xajax calling the requested function. |
|
| 468 | + * |
|
| 469 | + * <i>Usage:</i> <kbd>$xajax->registerPreFunction("myPreFunction");</kbd> |
|
| 470 | + * |
|
| 471 | + * @param string contains the function name or an object callback array |
|
| 472 | + * ({@link xajax::registerFunction() see registerFunction} for |
|
| 473 | + * more info on object callback arrays) |
|
| 474 | + */ |
|
| 475 | + function registerPreFunction($mFunction) |
|
| 476 | + { |
|
| 477 | + if (is_array($mFunction)) { |
|
| 478 | + $this->sPreFunction = $mFunction[0]; |
|
| 479 | + $this->aObjects[$mFunction[0]] = array_slice($mFunction, 1); |
|
| 480 | + } |
|
| 481 | + else { |
|
| 482 | + $this->sPreFunction = $mFunction; |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Returns true if xajax can process the request, false if otherwise. |
|
| 488 | + * You can use this to determine if xajax needs to process the request or |
|
| 489 | + * not. |
|
| 490 | + * |
|
| 491 | + * @return boolean |
|
| 492 | + */ |
|
| 493 | + function canProcessRequests() |
|
| 494 | + { |
|
| 495 | + if ($this->getRequestMode() != -1) return true; |
|
| 496 | + return false; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * Returns the current request mode (XAJAX_GET or XAJAX_POST), or -1 if |
|
| 501 | + * there is none. |
|
| 502 | + * |
|
| 503 | + * @return mixed |
|
| 504 | + */ |
|
| 505 | + function getRequestMode() |
|
| 506 | + { |
|
| 507 | + if (!empty($_GET["xajax"])) |
|
| 508 | + return XAJAX_GET; |
|
| 509 | + |
|
| 510 | + if (!empty($_POST["xajax"])) |
|
| 511 | + return XAJAX_POST; |
|
| 512 | + |
|
| 513 | + return -1; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * This is the main communications engine of xajax. The engine handles all |
|
| 518 | + * incoming xajax requests, calls the apporiate PHP functions (or |
|
| 519 | + * class/object methods) and passes the XML responses back to the |
|
| 520 | + * Javascript response handler. If your RequestURI is the same as your Web |
|
| 521 | + * page then this function should be called before any headers or HTML has |
|
| 522 | + * been sent. |
|
| 523 | + */ |
|
| 524 | + function processRequests() |
|
| 525 | + { |
|
| 526 | + |
|
| 527 | + $requestMode = -1; |
|
| 528 | + $sFunctionName = ""; |
|
| 529 | + $bFoundFunction = true; |
|
| 530 | + $bFunctionIsCatchAll = false; |
|
| 531 | + $sFunctionNameForSpecial = ""; |
|
| 532 | + $aArgs = array(); |
|
| 533 | + $sPreResponse = ""; |
|
| 534 | + $bEndRequest = false; |
|
| 535 | + $sResponse = ""; |
|
| 536 | + |
|
| 537 | + $requestMode = $this->getRequestMode(); |
|
| 538 | + if ($requestMode == -1) return; |
|
| 539 | + |
|
| 540 | + if ($requestMode == XAJAX_POST) |
|
| 541 | + { |
|
| 542 | + $sFunctionName = $_POST["xajax"]; |
|
| 543 | + |
|
| 544 | + if (!empty($_POST["xajaxargs"])) |
|
| 545 | + $aArgs = $_POST["xajaxargs"]; |
|
| 546 | + } |
|
| 547 | + else |
|
| 548 | + { |
|
| 549 | + header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 550 | + header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
| 551 | + header ("Cache-Control: no-cache, must-revalidate"); |
|
| 552 | + header ("Pragma: no-cache"); |
|
| 553 | + |
|
| 554 | + $sFunctionName = $_GET["xajax"]; |
|
| 555 | + |
|
| 556 | + if (!empty($_GET["xajaxargs"])) |
|
| 557 | + $aArgs = $_GET["xajaxargs"]; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + // Use xajax error handler if necessary |
|
| 561 | + if ($this->bErrorHandler) { |
|
| 562 | + $GLOBALS['xajaxErrorHandlerText'] = ""; |
|
| 563 | + set_error_handler("xajaxErrorHandler"); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + if ($this->sPreFunction) { |
|
| 567 | + if (!$this->_isFunctionCallable($this->sPreFunction)) { |
|
| 568 | + $bFoundFunction = false; |
|
| 569 | + $objResponse = new xajaxResponse(); |
|
| 570 | + $objResponse->addAlert("Unknown Pre-Function ". $this->sPreFunction); |
|
| 571 | + $sResponse = $objResponse->getXML(); |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + //include any external dependencies associated with this function name |
|
| 575 | + if (array_key_exists($sFunctionName,$this->aFunctionIncludeFiles)) |
|
| 576 | + { |
|
| 577 | + ob_start(); |
|
| 578 | + include_once($this->aFunctionIncludeFiles[$sFunctionName]); |
|
| 579 | + ob_end_clean(); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + if ($bFoundFunction) { |
|
| 583 | + $sFunctionNameForSpecial = $sFunctionName; |
|
| 584 | + if (!array_key_exists($sFunctionName, $this->aFunctions)) |
|
| 585 | + { |
|
| 586 | + if ($this->sCatchAllFunction) { |
|
| 587 | + $sFunctionName = $this->sCatchAllFunction; |
|
| 588 | + $bFunctionIsCatchAll = true; |
|
| 589 | + } |
|
| 590 | + else { |
|
| 591 | + $bFoundFunction = false; |
|
| 592 | + $objResponse = new xajaxResponse(); |
|
| 593 | + $objResponse->addAlert("Unknown Function $sFunctionName."); |
|
| 594 | + $sResponse = $objResponse->getXML(); |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + else if ($this->aFunctionRequestTypes[$sFunctionName] != $requestMode) |
|
| 598 | + { |
|
| 599 | + $bFoundFunction = false; |
|
| 600 | + $objResponse = new xajaxResponse(); |
|
| 601 | + $objResponse->addAlert("Incorrect Request Type."); |
|
| 602 | + $sResponse = $objResponse->getXML(); |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + if ($bFoundFunction) |
|
| 607 | + { |
|
| 608 | + for ($i = 0; $i < sizeof($aArgs); $i++) |
|
| 609 | + { |
|
| 610 | + // If magic quotes is on, then we need to strip the slashes from the args |
|
| 611 | + if (get_magic_quotes_gpc() == 1 && is_string($aArgs[$i])) { |
|
| 612 | + |
|
| 613 | + $aArgs[$i] = stripslashes($aArgs[$i]); |
|
| 614 | + } |
|
| 615 | + if (stristr($aArgs[$i],"<xjxobj>") != false) |
|
| 616 | + { |
|
| 617 | + $aArgs[$i] = $this->_xmlToArray("xjxobj",$aArgs[$i]); |
|
| 618 | + } |
|
| 619 | + else if (stristr($aArgs[$i],"<xjxquery>") != false) |
|
| 620 | + { |
|
| 621 | + $aArgs[$i] = $this->_xmlToArray("xjxquery",$aArgs[$i]); |
|
| 622 | + } |
|
| 623 | + else if ($this->bDecodeUTF8Input) |
|
| 624 | + { |
|
| 625 | + $aArgs[$i] = $this->_decodeUTF8Data($aArgs[$i]); |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + if ($this->sPreFunction) { |
|
| 630 | + $mPreResponse = $this->_callFunction($this->sPreFunction, array($sFunctionNameForSpecial, $aArgs)); |
|
| 631 | + if (is_array($mPreResponse) && $mPreResponse[0] === false) { |
|
| 632 | + $bEndRequest = true; |
|
| 633 | + $sPreResponse = $mPreResponse[1]; |
|
| 634 | + } |
|
| 635 | + else { |
|
| 636 | + $sPreResponse = $mPreResponse; |
|
| 637 | + } |
|
| 638 | + if (is_a($sPreResponse, "xajaxResponse")) { |
|
| 639 | + $sPreResponse = $sPreResponse->getXML(); |
|
| 640 | + } |
|
| 641 | + if ($bEndRequest) $sResponse = $sPreResponse; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + if (!$bEndRequest) { |
|
| 645 | + if (!$this->_isFunctionCallable($sFunctionName)) { |
|
| 646 | + $objResponse = new xajaxResponse(); |
|
| 647 | + $objResponse->addAlert("The Registered Function $sFunctionName Could Not Be Found."); |
|
| 648 | + $sResponse = $objResponse->getXML(); |
|
| 649 | + } |
|
| 650 | + else { |
|
| 651 | + if ($bFunctionIsCatchAll) { |
|
| 652 | + $aArgs = array($sFunctionNameForSpecial, $aArgs); |
|
| 653 | + } |
|
| 654 | + $sResponse = $this->_callFunction($sFunctionName, $aArgs); |
|
| 655 | + } |
|
| 656 | + if (is_a($sResponse, "xajaxResponse")) { |
|
| 657 | + $sResponse = $sResponse->getXML(); |
|
| 658 | + } |
|
| 659 | + if (!is_string($sResponse) || strpos($sResponse, "<xjx>") === FALSE) { |
|
| 660 | + $objResponse = new xajaxResponse(); |
|
| 661 | + $objResponse->addAlert("No XML Response Was Returned By Function $sFunctionName."); |
|
| 662 | + $sResponse = $objResponse->getXML(); |
|
| 663 | + } |
|
| 664 | + else if ($sPreResponse != "") { |
|
| 665 | + $sNewResponse = new xajaxResponse($this->sEncoding, $this->bOutputEntities); |
|
| 666 | + $sNewResponse->loadXML($sPreResponse); |
|
| 667 | + $sNewResponse->loadXML($sResponse); |
|
| 668 | + $sResponse = $sNewResponse->getXML(); |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + $sContentHeader = "Content-type: text/xml;"; |
|
| 674 | + if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0) |
|
| 675 | + $sContentHeader .= " charset=".$this->sEncoding; |
|
| 676 | + header($sContentHeader); |
|
| 677 | + if ($this->bErrorHandler && !empty( $GLOBALS['xajaxErrorHandlerText'] )) { |
|
| 678 | + $sErrorResponse = new xajaxResponse(); |
|
| 679 | + $sErrorResponse->addAlert("** PHP Error Messages: **" . $GLOBALS['xajaxErrorHandlerText']); |
|
| 680 | + if ($this->sLogFile) { |
|
| 681 | + $fH = @fopen($this->sLogFile, "a"); |
|
| 682 | + if (!$fH) { |
|
| 683 | + $sErrorResponse->addAlert("** Logging Error **\n\nxajax was unable to write to the error log file:\n" . $this->sLogFile); |
|
| 684 | + } |
|
| 685 | + else { |
|
| 686 | + fwrite($fH, "** xajax Error Log - " . strftime("%b %e %Y %I:%M:%S %p") . " **" . $GLOBALS['xajaxErrorHandlerText'] . "\n\n\n"); |
|
| 687 | + fclose($fH); |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + $sErrorResponse->loadXML($sResponse); |
|
| 692 | + $sResponse = $sErrorResponse->getXML(); |
|
| 693 | + |
|
| 694 | + } |
|
| 695 | + if ($this->bCleanBuffer) while (@ob_end_clean()); |
|
| 696 | + print $sResponse; |
|
| 697 | + if ($this->bErrorHandler) restore_error_handler(); |
|
| 698 | + |
|
| 699 | + if ($this->bExitAllowed) |
|
| 700 | + exit(); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Prints the xajax Javascript header and wrapper code into your page by |
|
| 705 | + * printing the output of the getJavascript() method. It should only be |
|
| 706 | + * called between the <pre><head> </head></pre> tags in your HTML page. |
|
| 707 | + * Remember, if you only want to obtain the result of this function, use |
|
| 708 | + * {@link xajax::getJavascript()} instead. |
|
| 709 | + * |
|
| 710 | + * <i>Usage:</i> |
|
| 711 | + * <code> |
|
| 712 | + * <head> |
|
| 713 | + * ... |
|
| 714 | + * < ?php $xajax->printJavascript(); ? > |
|
| 715 | + * </code> |
|
| 716 | + * |
|
| 717 | + * @param string the relative address of the folder where xajax has been |
|
| 718 | + * installed. For instance, if your PHP file is |
|
| 719 | + * "http://www.myserver.com/myfolder/mypage.php" |
|
| 720 | + * and xajax was installed in |
|
| 721 | + * "http://www.myserver.com/anotherfolder", then $sJsURI |
|
| 722 | + * should be set to "../anotherfolder". Defaults to assuming |
|
| 723 | + * xajax is in the same folder as your PHP file. |
|
| 724 | + * @param string the relative folder/file pair of the xajax Javascript |
|
| 725 | + * engine located within the xajax installation folder. |
|
| 726 | + * Defaults to xajax_js/xajax.js. |
|
| 727 | + */ |
|
| 728 | + function printJavascript($sJsURI="", $sJsFile=NULL) |
|
| 729 | + { |
|
| 730 | + print $this->getJavascript($sJsURI, $sJsFile); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * Returns the xajax Javascript code that should be added to your HTML page |
|
| 735 | + * between the <kbd><head> </head></kbd> tags. |
|
| 736 | + * |
|
| 737 | + * <i>Usage:</i> |
|
| 738 | + * <code> |
|
| 739 | + * < ?php $xajaxJSHead = $xajax->getJavascript(); ? > |
|
| 740 | + * <head> |
|
| 741 | + * ... |
|
| 742 | + * < ?php echo $xajaxJSHead; ? > |
|
| 743 | + * </code> |
|
| 744 | + * |
|
| 745 | + * @param string the relative address of the folder where xajax has been |
|
| 746 | + * installed. For instance, if your PHP file is |
|
| 747 | + * "http://www.myserver.com/myfolder/mypage.php" |
|
| 748 | + * and xajax was installed in |
|
| 749 | + * "http://www.myserver.com/anotherfolder", then $sJsURI |
|
| 750 | + * should be set to "../anotherfolder". Defaults to assuming |
|
| 751 | + * xajax is in the same folder as your PHP file. |
|
| 752 | + * @param string the relative folder/file pair of the xajax Javascript |
|
| 753 | + * engine located within the xajax installation folder. |
|
| 754 | + * Defaults to xajax_js/xajax.js. |
|
| 755 | + * @return string |
|
| 756 | + */ |
|
| 757 | + function getJavascript($sJsURI="", $sJsFile=NULL) |
|
| 758 | + { |
|
| 759 | + $html = $this->getJavascriptConfig(); |
|
| 760 | + $html .= $this->getJavascriptInclude($sJsURI, $sJsFile); |
|
| 761 | + |
|
| 762 | + return $html; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Returns a string containing inline Javascript that sets up the xajax |
|
| 767 | + * runtime (typically called internally by xajax from get/printJavascript). |
|
| 768 | + * |
|
| 769 | + * @return string |
|
| 770 | + */ |
|
| 771 | + function getJavascriptConfig() |
|
| 772 | + { |
|
| 773 | + $html = "\t<script type=\"text/javascript\">\n"; |
|
| 774 | + $html .= "var xajaxRequestUri=\"".$this->sRequestURI."\";\n"; |
|
| 775 | + $html .= "var xajaxDebug=".($this->bDebug?"true":"false").";\n"; |
|
| 776 | + $html .= "var xajaxStatusMessages=".($this->bStatusMessages?"true":"false").";\n"; |
|
| 777 | + $html .= "var xajaxWaitCursor=".($this->bWaitCursor?"true":"false").";\n"; |
|
| 778 | + $html .= "var xajaxDefinedGet=".XAJAX_GET.";\n"; |
|
| 779 | + $html .= "var xajaxDefinedPost=".XAJAX_POST.";\n"; |
|
| 780 | + $html .= "var xajaxLoaded=false;\n"; |
|
| 781 | + |
|
| 782 | + foreach($this->aFunctions as $sFunction => $bExists) { |
|
| 783 | + $html .= $this->_wrap($sFunction,$this->aFunctionRequestTypes[$sFunction]); |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + $html .= "\t</script>\n"; |
|
| 787 | + return $html; |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * Returns a string containing a Javascript include of the xajax.js file |
|
| 792 | + * along with a check to see if the file loaded after six seconds |
|
| 793 | + * (typically called internally by xajax from get/printJavascript). |
|
| 794 | + * |
|
| 795 | + * @param string the relative address of the folder where xajax has been |
|
| 796 | + * installed. For instance, if your PHP file is |
|
| 797 | + * "http://www.myserver.com/myfolder/mypage.php" |
|
| 798 | + * and xajax was installed in |
|
| 799 | + * "http://www.myserver.com/anotherfolder", then $sJsURI |
|
| 800 | + * should be set to "../anotherfolder". Defaults to assuming |
|
| 801 | + * xajax is in the same folder as your PHP file. |
|
| 802 | + * @param string the relative folder/file pair of the xajax Javascript |
|
| 803 | + * engine located within the xajax installation folder. |
|
| 804 | + * Defaults to xajax_js/xajax.js. |
|
| 805 | + * @return string |
|
| 806 | + */ |
|
| 807 | + function getJavascriptInclude($sJsURI="", $sJsFile=NULL) |
|
| 808 | + { |
|
| 809 | + if ($sJsFile == NULL) $sJsFile = "xajax_js/xajax.js"; |
|
| 810 | + |
|
| 811 | + if ($sJsURI != "" && substr($sJsURI, -1) != "/") $sJsURI .= "/"; |
|
| 812 | + |
|
| 813 | + $html = "\t<script type=\"text/javascript\" src=\"" . $sJsURI . $sJsFile . "\"></script>\n"; |
|
| 814 | + $html .= "\t<script type=\"text/javascript\">\n"; |
|
| 815 | + $html .= "window.setTimeout(function () { if (!xajaxLoaded) { alert('Error: the xajax Javascript file could not be included. Perhaps the URL is incorrect?\\nURL: {$sJsURI}{$sJsFile}'); } }, 6000);\n"; |
|
| 816 | + $html .= "\t</script>\n"; |
|
| 817 | + return $html; |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * This method can be used to create a new xajax.js file out of the |
|
| 822 | + * xajax_uncompressed.js file (which will only happen if xajax.js doesn't |
|
| 823 | + * already exist on the filesystem). |
|
| 824 | + * |
|
| 825 | + * @param string an optional argument containing the full server file path |
|
| 826 | + * of xajax.js. |
|
| 827 | + */ |
|
| 828 | + function autoCompressJavascript($sJsFullFilename=NULL) |
|
| 829 | + { |
|
| 830 | + $sJsFile = "xajax_js/xajax.js"; |
|
| 831 | + |
|
| 832 | + if ($sJsFullFilename) { |
|
| 833 | + $realJsFile = $sJsFullFilename; |
|
| 834 | + } |
|
| 835 | + else { |
|
| 836 | + $realPath = realpath(dirname(__FILE__)); |
|
| 837 | + $realJsFile = $realPath . "/". $sJsFile; |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + // Create a compressed file if necessary |
|
| 841 | + if (!file_exists($realJsFile)) { |
|
| 842 | + $srcFile = str_replace(".js", "_uncompressed.js", $realJsFile); |
|
| 843 | + if (!file_exists($srcFile)) { |
|
| 844 | + trigger_error("The xajax uncompressed Javascript file could not be found in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR); |
|
| 845 | + } |
|
| 846 | + require(dirname(__FILE__)."/xajaxCompress.php"); |
|
| 847 | + $javaScript = implode('', file($srcFile)); |
|
| 848 | + $compressedScript = xajaxCompressJavascript($javaScript); |
|
| 849 | + $fH = @fopen($realJsFile, "w"); |
|
| 850 | + if (!$fH) { |
|
| 851 | + trigger_error("The xajax compressed javascript file could not be written in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR); |
|
| 852 | + } |
|
| 853 | + else { |
|
| 854 | + fwrite($fH, $compressedScript); |
|
| 855 | + fclose($fH); |
|
| 856 | + } |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * Returns the current URL based upon the SERVER vars. |
|
| 862 | + * |
|
| 863 | + * @access private |
|
| 864 | + * @return string |
|
| 865 | + */ |
|
| 866 | + function _detectURI() { |
|
| 867 | + $aURL = array(); |
|
| 868 | + |
|
| 869 | + // Try to get the request URL |
|
| 870 | + if (!empty($_SERVER['REQUEST_URI'])) { |
|
| 871 | + $aURL = parse_url($_SERVER['REQUEST_URI']); |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + // Fill in the empty values |
|
| 875 | + if (empty($aURL['scheme'])) { |
|
| 876 | + if (!empty($_SERVER['HTTP_SCHEME'])) { |
|
| 877 | + $aURL['scheme'] = $_SERVER['HTTP_SCHEME']; |
|
| 878 | + } else { |
|
| 879 | + $aURL['scheme'] = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ? 'https' : 'http'; |
|
| 880 | + } |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + if (empty($aURL['host'])) { |
|
| 884 | + if (!empty($_SERVER['HTTP_HOST'])) { |
|
| 885 | + if (strpos($_SERVER['HTTP_HOST'], ':') > 0) { |
|
| 886 | + list($aURL['host'], $aURL['port']) = explode(':', $_SERVER['HTTP_HOST']); |
|
| 887 | + } else { |
|
| 888 | + $aURL['host'] = $_SERVER['HTTP_HOST']; |
|
| 889 | + } |
|
| 890 | + } else if (!empty($_SERVER['SERVER_NAME'])) { |
|
| 891 | + $aURL['host'] = $_SERVER['SERVER_NAME']; |
|
| 892 | + } else { |
|
| 893 | + print "xajax Error: xajax failed to automatically identify your Request URI."; |
|
| 894 | + print "Please set the Request URI explicitly when you instantiate the xajax object."; |
|
| 895 | + exit(); |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + if (empty($aURL['port']) && !empty($_SERVER['SERVER_PORT'])) { |
|
| 900 | + $aURL['port'] = $_SERVER['SERVER_PORT']; |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + if (empty($aURL['path'])) { |
|
| 904 | + if (!empty($_SERVER['PATH_INFO'])) { |
|
| 905 | + $sPath = parse_url($_SERVER['PATH_INFO']); |
|
| 906 | + } else { |
|
| 907 | + $sPath = parse_url(api_get_self()); |
|
| 908 | + } |
|
| 909 | + $aURL['path'] = $sPath['path']; |
|
| 910 | + unset($sPath); |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + if (!empty($aURL['query'])) { |
|
| 914 | + $aURL['query'] = '?'.$aURL['query']; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + // Build the URL: Start with scheme, user and pass |
|
| 918 | + $sURL = $aURL['scheme'].'://'; |
|
| 919 | + if (!empty($aURL['user'])) { |
|
| 920 | + $sURL.= $aURL['user']; |
|
| 921 | + if (!empty($aURL['pass'])) { |
|
| 922 | + $sURL.= ':'.$aURL['pass']; |
|
| 923 | + } |
|
| 924 | + $sURL.= '@'; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + // Add the host |
|
| 928 | + $sURL.= $aURL['host']; |
|
| 929 | + |
|
| 930 | + // Add the port if needed |
|
| 931 | + if (!empty($aURL['port']) && (($aURL['scheme'] == 'http' && $aURL['port'] != 80) || ($aURL['scheme'] == 'https' && $aURL['port'] != 443))) { |
|
| 932 | + $sURL.= ':'.$aURL['port']; |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + // Add the path and the query string |
|
| 936 | + $sURL.= $aURL['path'].@$aURL['query']; |
|
| 937 | + |
|
| 938 | + // Clean up |
|
| 939 | + unset($aURL); |
|
| 940 | + return $sURL; |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + /** |
|
| 944 | + * Returns true if the function name is associated with an object callback, |
|
| 945 | + * false if not. |
|
| 946 | + * |
|
| 947 | + * @param string the name of the function |
|
| 948 | + * @access private |
|
| 949 | + * @return boolean |
|
| 950 | + */ |
|
| 951 | + function _isObjectCallback($sFunction) |
|
| 952 | + { |
|
| 953 | + if (array_key_exists($sFunction, $this->aObjects)) return true; |
|
| 954 | + return false; |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * Returns true if the function or object callback can be called, false if |
|
| 959 | + * not. |
|
| 960 | + * |
|
| 961 | + * @param string the name of the function |
|
| 962 | + * @access private |
|
| 963 | + * @return boolean |
|
| 964 | + */ |
|
| 965 | + function _isFunctionCallable($sFunction) |
|
| 966 | + { |
|
| 967 | + if ($this->_isObjectCallback($sFunction)) { |
|
| 968 | + if (is_object($this->aObjects[$sFunction][0])) { |
|
| 969 | + return method_exists($this->aObjects[$sFunction][0], $this->aObjects[$sFunction][1]); |
|
| 970 | + } |
|
| 971 | + else { |
|
| 972 | + return is_callable($this->aObjects[$sFunction]); |
|
| 973 | + } |
|
| 974 | + } |
|
| 975 | + else { |
|
| 976 | + return function_exists($sFunction); |
|
| 977 | + } |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + /** |
|
| 981 | + * Calls the function, class method, or object method with the supplied |
|
| 982 | + * arguments. |
|
| 983 | + * |
|
| 984 | + * @param string the name of the function |
|
| 985 | + * @param array arguments to pass to the function |
|
| 986 | + * @access private |
|
| 987 | + * @return mixed the output of the called function or method |
|
| 988 | + */ |
|
| 989 | + function _callFunction($sFunction, $aArgs) |
|
| 990 | + { |
|
| 991 | + if ($this->_isObjectCallback($sFunction)) { |
|
| 992 | + $mReturn = call_user_func_array($this->aObjects[$sFunction], $aArgs); |
|
| 993 | + } |
|
| 994 | + else { |
|
| 995 | + $mReturn = call_user_func_array($sFunction, $aArgs); |
|
| 996 | + } |
|
| 997 | + return $mReturn; |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + /** |
|
| 1001 | + * Generates the Javascript wrapper for the specified PHP function. |
|
| 1002 | + * |
|
| 1003 | + * @param string the name of the function |
|
| 1004 | + * @param mixed the request type |
|
| 1005 | + * @access private |
|
| 1006 | + * @return string |
|
| 1007 | + */ |
|
| 1008 | + function _wrap($sFunction,$sRequestType=XAJAX_POST) |
|
| 1009 | + { |
|
| 1010 | + $js = "function ".$this->sWrapperPrefix."$sFunction(){return xajax.call(\"$sFunction\", arguments, ".$sRequestType.");}\n"; |
|
| 1011 | + return $js; |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * Takes a string containing xajax xjxobj XML or xjxquery XML and builds an |
|
| 1016 | + * array representation of it to pass as an argument to the PHP function |
|
| 1017 | + * being called. |
|
| 1018 | + * |
|
| 1019 | + * @param string the root tag of the XML |
|
| 1020 | + * @param string XML to convert |
|
| 1021 | + * @access private |
|
| 1022 | + * @return array |
|
| 1023 | + */ |
|
| 1024 | + function _xmlToArray($rootTag, $sXml) |
|
| 1025 | + { |
|
| 1026 | + $aArray = array(); |
|
| 1027 | + $sXml = str_replace("<$rootTag>","<$rootTag>|~|",$sXml); |
|
| 1028 | + $sXml = str_replace("</$rootTag>","</$rootTag>|~|",$sXml); |
|
| 1029 | + $sXml = str_replace("<e>","<e>|~|",$sXml); |
|
| 1030 | + $sXml = str_replace("</e>","</e>|~|",$sXml); |
|
| 1031 | + $sXml = str_replace("<k>","<k>|~|",$sXml); |
|
| 1032 | + $sXml = str_replace("</k>","|~|</k>|~|",$sXml); |
|
| 1033 | + $sXml = str_replace("<v>","<v>|~|",$sXml); |
|
| 1034 | + $sXml = str_replace("</v>","|~|</v>|~|",$sXml); |
|
| 1035 | + $sXml = str_replace("<q>","<q>|~|",$sXml); |
|
| 1036 | + $sXml = str_replace("</q>","|~|</q>|~|",$sXml); |
|
| 1037 | + |
|
| 1038 | + $this->aObjArray = explode("|~|",$sXml); |
|
| 1039 | + |
|
| 1040 | + $this->iPos = 0; |
|
| 1041 | + $aArray = $this->_parseObjXml($rootTag); |
|
| 1042 | + |
|
| 1043 | + return $aArray; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + /** |
|
| 1047 | + * A recursive function that generates an array from the contents of |
|
| 1048 | + * $this->aObjArray. |
|
| 1049 | + * |
|
| 1050 | + * @param string the root tag of the XML |
|
| 1051 | + * @access private |
|
| 1052 | + * @return array |
|
| 1053 | + */ |
|
| 1054 | + function _parseObjXml($rootTag) |
|
| 1055 | + { |
|
| 1056 | + $aArray = array(); |
|
| 1057 | + |
|
| 1058 | + if ($rootTag == "xjxobj") |
|
| 1059 | + { |
|
| 1060 | + while(!stristr($this->aObjArray[$this->iPos],"</xjxobj>")) |
|
| 1061 | + { |
|
| 1062 | + $this->iPos++; |
|
| 1063 | + if(stristr($this->aObjArray[$this->iPos],"<e>")) |
|
| 1064 | + { |
|
| 1065 | + $key = ""; |
|
| 1066 | + $value = null; |
|
| 1067 | + |
|
| 1068 | + $this->iPos++; |
|
| 1069 | + while(!stristr($this->aObjArray[$this->iPos],"</e>")) |
|
| 1070 | + { |
|
| 1071 | + if(stristr($this->aObjArray[$this->iPos],"<k>")) |
|
| 1072 | + { |
|
| 1073 | + $this->iPos++; |
|
| 1074 | + while(!stristr($this->aObjArray[$this->iPos],"</k>")) |
|
| 1075 | + { |
|
| 1076 | + $key .= $this->aObjArray[$this->iPos]; |
|
| 1077 | + $this->iPos++; |
|
| 1078 | + } |
|
| 1079 | + } |
|
| 1080 | + if(stristr($this->aObjArray[$this->iPos],"<v>")) |
|
| 1081 | + { |
|
| 1082 | + $this->iPos++; |
|
| 1083 | + while(!stristr($this->aObjArray[$this->iPos],"</v>")) |
|
| 1084 | + { |
|
| 1085 | + if(stristr($this->aObjArray[$this->iPos],"<xjxobj>")) |
|
| 1086 | + { |
|
| 1087 | + $value = $this->_parseObjXml("xjxobj"); |
|
| 1088 | + $this->iPos++; |
|
| 1089 | + } |
|
| 1090 | + else |
|
| 1091 | + { |
|
| 1092 | + $value .= $this->aObjArray[$this->iPos]; |
|
| 1093 | + if ($this->bDecodeUTF8Input) |
|
| 1094 | + { |
|
| 1095 | + $value = $this->_decodeUTF8Data($value); |
|
| 1096 | + } |
|
| 1097 | + } |
|
| 1098 | + $this->iPos++; |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + $this->iPos++; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + $aArray[$key]=$value; |
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + if ($rootTag == "xjxquery") |
|
| 1110 | + { |
|
| 1111 | + $sQuery = ""; |
|
| 1112 | + $this->iPos++; |
|
| 1113 | + while(!stristr($this->aObjArray[$this->iPos],"</xjxquery>")) |
|
| 1114 | + { |
|
| 1115 | + if (stristr($this->aObjArray[$this->iPos],"<q>") || stristr($this->aObjArray[$this->iPos],"</q>")) |
|
| 1116 | + { |
|
| 1117 | + $this->iPos++; |
|
| 1118 | + continue; |
|
| 1119 | + } |
|
| 1120 | + $sQuery .= $this->aObjArray[$this->iPos]; |
|
| 1121 | + $this->iPos++; |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + parse_str($sQuery, $aArray); |
|
| 1125 | + if ($this->bDecodeUTF8Input) |
|
| 1126 | + { |
|
| 1127 | + foreach($aArray as $key => $value) |
|
| 1128 | + { |
|
| 1129 | + $aArray[$key] = $this->_decodeUTF8Data($value); |
|
| 1130 | + } |
|
| 1131 | + } |
|
| 1132 | + // If magic quotes is on, then we need to strip the slashes from the |
|
| 1133 | + // array values because of the parse_str pass which adds slashes |
|
| 1134 | + if (get_magic_quotes_gpc() == 1) { |
|
| 1135 | + $newArray = array(); |
|
| 1136 | + foreach ($aArray as $sKey => $sValue) { |
|
| 1137 | + if (is_string($sValue)) |
|
| 1138 | + $newArray[$sKey] = stripslashes($sValue); |
|
| 1139 | + else |
|
| 1140 | + $newArray[$sKey] = $sValue; |
|
| 1141 | + } |
|
| 1142 | + $aArray = $newArray; |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + return $aArray; |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + /** |
|
| 1150 | + * Decodes string data from UTF-8 to the current xajax encoding. |
|
| 1151 | + * |
|
| 1152 | + * @param string data to convert |
|
| 1153 | + * @access private |
|
| 1154 | + * @return string converted data |
|
| 1155 | + */ |
|
| 1156 | + function _decodeUTF8Data($sData) |
|
| 1157 | + { |
|
| 1158 | + $sValue = $sData; |
|
| 1159 | + if ($this->bDecodeUTF8Input) |
|
| 1160 | + { |
|
| 1161 | + $sFuncToUse = NULL; |
|
| 1162 | + |
|
| 1163 | + // An adaptation for the Dokeos LMS, 22-AUG-2009. |
|
| 1164 | + if (function_exists('api_convert_encoding')) |
|
| 1165 | + { |
|
| 1166 | + $sFuncToUse = "api_convert_encoding"; |
|
| 1167 | + } |
|
| 1168 | + //if (function_exists('iconv')) |
|
| 1169 | + elseif (function_exists('iconv')) |
|
| 1170 | + // |
|
| 1171 | + { |
|
| 1172 | + $sFuncToUse = "iconv"; |
|
| 1173 | + } |
|
| 1174 | + else if (function_exists('mb_convert_encoding')) |
|
| 1175 | + { |
|
| 1176 | + $sFuncToUse = "mb_convert_encoding"; |
|
| 1177 | + } |
|
| 1178 | + else if ($this->sEncoding == "ISO-8859-1") |
|
| 1179 | + { |
|
| 1180 | + $sFuncToUse = "utf8_decode"; |
|
| 1181 | + } |
|
| 1182 | + else |
|
| 1183 | + { |
|
| 1184 | + trigger_error("The incoming xajax data could not be converted from UTF-8", E_USER_NOTICE); |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + if ($sFuncToUse) |
|
| 1188 | + { |
|
| 1189 | + if (is_string($sValue)) |
|
| 1190 | + { |
|
| 1191 | + if ($sFuncToUse == "iconv") |
|
| 1192 | + { |
|
| 1193 | + $sValue = iconv("UTF-8", $this->sEncoding.'//TRANSLIT', $sValue); |
|
| 1194 | + } |
|
| 1195 | + else if ($sFuncToUse == "mb_convert_encoding") |
|
| 1196 | + { |
|
| 1197 | + $sValue = mb_convert_encoding($sValue, $this->sEncoding, "UTF-8"); |
|
| 1198 | + } |
|
| 1199 | + // Added code, an adaptation for the Dokeos LMS, 22-AUG-2009. |
|
| 1200 | + else if ($sFuncToUse == "api_convert_encoding") |
|
| 1201 | + { |
|
| 1202 | + $sValue = api_convert_encoding($sValue, $this->sEncoding, "UTF-8"); |
|
| 1203 | + } |
|
| 1204 | + // |
|
| 1205 | + else |
|
| 1206 | + { |
|
| 1207 | + $sValue = utf8_decode($sValue); |
|
| 1208 | + } |
|
| 1209 | + } |
|
| 1210 | + } |
|
| 1211 | + } |
|
| 1212 | + return $sValue; |
|
| 1213 | + } |
|
| 1214 | 1214 | |
| 1215 | 1215 | }// end class xajax |
| 1216 | 1216 | |
@@ -1220,31 +1220,31 @@ discard block |
||
| 1220 | 1220 | */ |
| 1221 | 1221 | function xajaxErrorHandler($errno, $errstr, $errfile, $errline) |
| 1222 | 1222 | { |
| 1223 | - $errorReporting = error_reporting(); |
|
| 1224 | - if (($errno & $errorReporting) == 0) return; |
|
| 1225 | - |
|
| 1226 | - if ($errno == E_NOTICE) { |
|
| 1227 | - $errTypeStr = "NOTICE"; |
|
| 1228 | - } |
|
| 1229 | - else if ($errno == E_WARNING) { |
|
| 1230 | - $errTypeStr = "WARNING"; |
|
| 1231 | - } |
|
| 1232 | - else if ($errno == E_USER_NOTICE) { |
|
| 1233 | - $errTypeStr = "USER NOTICE"; |
|
| 1234 | - } |
|
| 1235 | - else if ($errno == E_USER_WARNING) { |
|
| 1236 | - $errTypeStr = "USER WARNING"; |
|
| 1237 | - } |
|
| 1238 | - else if ($errno == E_USER_ERROR) { |
|
| 1239 | - $errTypeStr = "USER FATAL ERROR"; |
|
| 1240 | - } |
|
| 1241 | - else if ($errno == E_STRICT) { |
|
| 1242 | - return; |
|
| 1243 | - } |
|
| 1244 | - else { |
|
| 1245 | - $errTypeStr = "UNKNOWN: $errno"; |
|
| 1246 | - } |
|
| 1247 | - $GLOBALS['xajaxErrorHandlerText'] .= "\n----\n[$errTypeStr] $errstr\nerror in line $errline of file $errfile"; |
|
| 1223 | + $errorReporting = error_reporting(); |
|
| 1224 | + if (($errno & $errorReporting) == 0) return; |
|
| 1225 | + |
|
| 1226 | + if ($errno == E_NOTICE) { |
|
| 1227 | + $errTypeStr = "NOTICE"; |
|
| 1228 | + } |
|
| 1229 | + else if ($errno == E_WARNING) { |
|
| 1230 | + $errTypeStr = "WARNING"; |
|
| 1231 | + } |
|
| 1232 | + else if ($errno == E_USER_NOTICE) { |
|
| 1233 | + $errTypeStr = "USER NOTICE"; |
|
| 1234 | + } |
|
| 1235 | + else if ($errno == E_USER_WARNING) { |
|
| 1236 | + $errTypeStr = "USER WARNING"; |
|
| 1237 | + } |
|
| 1238 | + else if ($errno == E_USER_ERROR) { |
|
| 1239 | + $errTypeStr = "USER FATAL ERROR"; |
|
| 1240 | + } |
|
| 1241 | + else if ($errno == E_STRICT) { |
|
| 1242 | + return; |
|
| 1243 | + } |
|
| 1244 | + else { |
|
| 1245 | + $errTypeStr = "UNKNOWN: $errno"; |
|
| 1246 | + } |
|
| 1247 | + $GLOBALS['xajaxErrorHandlerText'] .= "\n----\n[$errTypeStr] $errstr\nerror in line $errline of file $errfile"; |
|
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | ?> |
@@ -67,521 +67,521 @@ |
||
| 67 | 67 | */ |
| 68 | 68 | class xajaxResponse |
| 69 | 69 | { |
| 70 | - /**#@+ |
|
| 70 | + /**#@+ |
|
| 71 | 71 | * @access protected |
| 72 | 72 | */ |
| 73 | - /** |
|
| 74 | - * @var string internal XML storage |
|
| 75 | - */ |
|
| 76 | - var $xml; |
|
| 77 | - /** |
|
| 78 | - * @var string the encoding type to use |
|
| 79 | - */ |
|
| 80 | - var $sEncoding; |
|
| 81 | - /** |
|
| 82 | - * @var boolean if special characters in the XML should be converted to |
|
| 83 | - * entities |
|
| 84 | - */ |
|
| 85 | - var $bOutputEntities; |
|
| 86 | - |
|
| 87 | - /**#@-*/ |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * The constructor's main job is to set the character encoding for the |
|
| 91 | - * response. |
|
| 92 | - * |
|
| 93 | - * <i>Note:</i> to change the character encoding for all of the |
|
| 94 | - * responses, set the XAJAX_DEFAULT_ENCODING constant before you |
|
| 95 | - * instantiate xajax. |
|
| 96 | - * |
|
| 97 | - * @param string contains the character encoding string to use |
|
| 98 | - * @param boolean lets you set if you want special characters in the output |
|
| 99 | - * converted to HTML entities |
|
| 100 | - * |
|
| 101 | - */ |
|
| 102 | - public function __construct($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities=false) |
|
| 103 | - { |
|
| 104 | - $this->setCharEncoding($sEncoding); |
|
| 105 | - $this->bOutputEntities = $bOutputEntities; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Sets the character encoding for the response based on $sEncoding, which |
|
| 110 | - * is a string containing the character encoding to use. You don't need to |
|
| 111 | - * use this method normally, since the character encoding for the response |
|
| 112 | - * gets set automatically based on the XAJAX_DEFAULT_CHAR_ENCODING |
|
| 113 | - * constant. |
|
| 114 | - * |
|
| 115 | - * @param string |
|
| 116 | - */ |
|
| 117 | - function setCharEncoding($sEncoding) |
|
| 118 | - { |
|
| 119 | - $this->sEncoding = $sEncoding; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Tells the response object to convert special characters to HTML entities |
|
| 124 | - * automatically (only works if the mb_string extension is available). |
|
| 125 | - */ |
|
| 126 | - function outputEntitiesOn() |
|
| 127 | - { |
|
| 128 | - $this->bOutputEntities = true; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Tells the response object to output special characters intact. (default |
|
| 133 | - * behavior) |
|
| 134 | - */ |
|
| 135 | - function outputEntitiesOff() |
|
| 136 | - { |
|
| 137 | - $this->bOutputEntities = false; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Adds a confirm commands command message to the XML response. |
|
| 142 | - * |
|
| 143 | - * <i>Usage:</i> <kbd>$objResponse->addConfirmCommands(1, "Do you want to preview the new data?");</kbd> |
|
| 144 | - * |
|
| 145 | - * @param integer the number of commands to skip if the user presses |
|
| 146 | - * Cancel in the browsers's confirm dialog |
|
| 147 | - * @param string the message to show in the browser's confirm dialog |
|
| 148 | - */ |
|
| 149 | - function addConfirmCommands($iCmdNumber, $sMessage) |
|
| 150 | - { |
|
| 151 | - $this->xml .= $this->_cmdXML(array("n"=>"cc","t"=>$iCmdNumber),$sMessage); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Adds an assign command message to the XML response. |
|
| 156 | - * |
|
| 157 | - * <i>Usage:</i> <kbd>$objResponse->addAssign("contentDiv", "innerHTML", "Some Text");</kbd> |
|
| 158 | - * |
|
| 159 | - * @param string contains the id of an HTML element |
|
| 160 | - * @param string the part of the element you wish to modify ("innerHTML", |
|
| 161 | - * "value", etc.) |
|
| 162 | - * @param string the data you want to set the attribute to |
|
| 163 | - */ |
|
| 164 | - function addAssign($sTarget,$sAttribute,$sData) |
|
| 165 | - { |
|
| 166 | - $this->xml .= $this->_cmdXML(array("n"=>"as","t"=>$sTarget,"p"=>$sAttribute),$sData); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Adds an append command message to the XML response. |
|
| 171 | - * |
|
| 172 | - * <i>Usage:</i> <kbd>$objResponse->addAppend("contentDiv", "innerHTML", "Some New Text");</kbd> |
|
| 173 | - * |
|
| 174 | - * @param string contains the id of an HTML element |
|
| 175 | - * @param string the part of the element you wish to modify ("innerHTML", |
|
| 176 | - * "value", etc.) |
|
| 177 | - * @param string the data you want to append to the end of the attribute |
|
| 178 | - */ |
|
| 179 | - function addAppend($sTarget,$sAttribute,$sData) |
|
| 180 | - { |
|
| 181 | - $this->xml .= $this->_cmdXML(array("n"=>"ap","t"=>$sTarget,"p"=>$sAttribute),$sData); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Adds an prepend command message to the XML response. |
|
| 186 | - * |
|
| 187 | - * <i>Usage:</i> <kbd>$objResponse->addPrepend("contentDiv", "innerHTML", "Some Starting Text");</kbd> |
|
| 188 | - * |
|
| 189 | - * @param string contains the id of an HTML element |
|
| 190 | - * @param string the part of the element you wish to modify ("innerHTML", |
|
| 191 | - * "value", etc.) |
|
| 192 | - * @param string the data you want to prepend to the beginning of the |
|
| 193 | - * attribute |
|
| 194 | - */ |
|
| 195 | - function addPrepend($sTarget,$sAttribute,$sData) |
|
| 196 | - { |
|
| 197 | - $this->xml .= $this->_cmdXML(array("n"=>"pp","t"=>$sTarget,"p"=>$sAttribute),$sData); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Adds a replace command message to the XML response. |
|
| 202 | - * |
|
| 203 | - * <i>Usage:</i> <kbd>$objResponse->addReplace("contentDiv", "innerHTML", "text", "<b>text</b>");</kbd> |
|
| 204 | - * |
|
| 205 | - * @param string contains the id of an HTML element |
|
| 206 | - * @param string the part of the element you wish to modify ("innerHTML", |
|
| 207 | - * "value", etc.) |
|
| 208 | - * @param string the string to search for |
|
| 209 | - * @param string the string to replace the search string when found in the |
|
| 210 | - * attribute |
|
| 211 | - */ |
|
| 212 | - function addReplace($sTarget,$sAttribute,$sSearch,$sData) |
|
| 213 | - { |
|
| 214 | - $sDta = "<s><![CDATA[$sSearch]]></s><r><![CDATA[$sData]]></r>"; |
|
| 215 | - $this->xml .= $this->_cmdXML(array("n"=>"rp","t"=>$sTarget,"p"=>$sAttribute),$sDta); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Adds a clear command message to the XML response. |
|
| 220 | - * |
|
| 221 | - * <i>Usage:</i> <kbd>$objResponse->addClear("contentDiv", "innerHTML");</kbd> |
|
| 222 | - * |
|
| 223 | - * @param string contains the id of an HTML element |
|
| 224 | - * @param string the part of the element you wish to clear ("innerHTML", |
|
| 225 | - * "value", etc.) |
|
| 226 | - */ |
|
| 227 | - function addClear($sTarget,$sAttribute) |
|
| 228 | - { |
|
| 229 | - $this->addAssign($sTarget,$sAttribute,''); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Adds an alert command message to the XML response. |
|
| 234 | - * |
|
| 235 | - * <i>Usage:</i> <kbd>$objResponse->addAlert("This is important information");</kbd> |
|
| 236 | - * |
|
| 237 | - * @param string the text to be displayed in the Javascript alert box |
|
| 238 | - */ |
|
| 239 | - function addAlert($sMsg) |
|
| 240 | - { |
|
| 241 | - $this->xml .= $this->_cmdXML(array("n"=>"al"),$sMsg); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Uses the addScript() method to add a Javascript redirect to another URL. |
|
| 246 | - * |
|
| 247 | - * <i>Usage:</i> <kbd>$objResponse->addRedirect("http://www.xajaxproject.org");</kbd> |
|
| 248 | - * |
|
| 249 | - * @param string the URL to redirect the client browser to |
|
| 250 | - */ |
|
| 251 | - function addRedirect($sURL) |
|
| 252 | - { |
|
| 253 | - //we need to parse the query part so that the values are rawurlencode()'ed |
|
| 254 | - //can't just use parse_url() cos we could be dealing with a relative URL which |
|
| 255 | - // parse_url() can't deal with. |
|
| 256 | - $queryStart = strpos($sURL, '?', strrpos($sURL, '/')); |
|
| 257 | - if ($queryStart !== FALSE) |
|
| 258 | - { |
|
| 259 | - $queryStart++; |
|
| 260 | - $queryEnd = strpos($sURL, '#', $queryStart); |
|
| 261 | - if ($queryEnd === FALSE) |
|
| 262 | - $queryEnd = strlen($sURL); |
|
| 263 | - $queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart); |
|
| 73 | + /** |
|
| 74 | + * @var string internal XML storage |
|
| 75 | + */ |
|
| 76 | + var $xml; |
|
| 77 | + /** |
|
| 78 | + * @var string the encoding type to use |
|
| 79 | + */ |
|
| 80 | + var $sEncoding; |
|
| 81 | + /** |
|
| 82 | + * @var boolean if special characters in the XML should be converted to |
|
| 83 | + * entities |
|
| 84 | + */ |
|
| 85 | + var $bOutputEntities; |
|
| 86 | + |
|
| 87 | + /**#@-*/ |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * The constructor's main job is to set the character encoding for the |
|
| 91 | + * response. |
|
| 92 | + * |
|
| 93 | + * <i>Note:</i> to change the character encoding for all of the |
|
| 94 | + * responses, set the XAJAX_DEFAULT_ENCODING constant before you |
|
| 95 | + * instantiate xajax. |
|
| 96 | + * |
|
| 97 | + * @param string contains the character encoding string to use |
|
| 98 | + * @param boolean lets you set if you want special characters in the output |
|
| 99 | + * converted to HTML entities |
|
| 100 | + * |
|
| 101 | + */ |
|
| 102 | + public function __construct($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities=false) |
|
| 103 | + { |
|
| 104 | + $this->setCharEncoding($sEncoding); |
|
| 105 | + $this->bOutputEntities = $bOutputEntities; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Sets the character encoding for the response based on $sEncoding, which |
|
| 110 | + * is a string containing the character encoding to use. You don't need to |
|
| 111 | + * use this method normally, since the character encoding for the response |
|
| 112 | + * gets set automatically based on the XAJAX_DEFAULT_CHAR_ENCODING |
|
| 113 | + * constant. |
|
| 114 | + * |
|
| 115 | + * @param string |
|
| 116 | + */ |
|
| 117 | + function setCharEncoding($sEncoding) |
|
| 118 | + { |
|
| 119 | + $this->sEncoding = $sEncoding; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Tells the response object to convert special characters to HTML entities |
|
| 124 | + * automatically (only works if the mb_string extension is available). |
|
| 125 | + */ |
|
| 126 | + function outputEntitiesOn() |
|
| 127 | + { |
|
| 128 | + $this->bOutputEntities = true; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Tells the response object to output special characters intact. (default |
|
| 133 | + * behavior) |
|
| 134 | + */ |
|
| 135 | + function outputEntitiesOff() |
|
| 136 | + { |
|
| 137 | + $this->bOutputEntities = false; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Adds a confirm commands command message to the XML response. |
|
| 142 | + * |
|
| 143 | + * <i>Usage:</i> <kbd>$objResponse->addConfirmCommands(1, "Do you want to preview the new data?");</kbd> |
|
| 144 | + * |
|
| 145 | + * @param integer the number of commands to skip if the user presses |
|
| 146 | + * Cancel in the browsers's confirm dialog |
|
| 147 | + * @param string the message to show in the browser's confirm dialog |
|
| 148 | + */ |
|
| 149 | + function addConfirmCommands($iCmdNumber, $sMessage) |
|
| 150 | + { |
|
| 151 | + $this->xml .= $this->_cmdXML(array("n"=>"cc","t"=>$iCmdNumber),$sMessage); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Adds an assign command message to the XML response. |
|
| 156 | + * |
|
| 157 | + * <i>Usage:</i> <kbd>$objResponse->addAssign("contentDiv", "innerHTML", "Some Text");</kbd> |
|
| 158 | + * |
|
| 159 | + * @param string contains the id of an HTML element |
|
| 160 | + * @param string the part of the element you wish to modify ("innerHTML", |
|
| 161 | + * "value", etc.) |
|
| 162 | + * @param string the data you want to set the attribute to |
|
| 163 | + */ |
|
| 164 | + function addAssign($sTarget,$sAttribute,$sData) |
|
| 165 | + { |
|
| 166 | + $this->xml .= $this->_cmdXML(array("n"=>"as","t"=>$sTarget,"p"=>$sAttribute),$sData); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Adds an append command message to the XML response. |
|
| 171 | + * |
|
| 172 | + * <i>Usage:</i> <kbd>$objResponse->addAppend("contentDiv", "innerHTML", "Some New Text");</kbd> |
|
| 173 | + * |
|
| 174 | + * @param string contains the id of an HTML element |
|
| 175 | + * @param string the part of the element you wish to modify ("innerHTML", |
|
| 176 | + * "value", etc.) |
|
| 177 | + * @param string the data you want to append to the end of the attribute |
|
| 178 | + */ |
|
| 179 | + function addAppend($sTarget,$sAttribute,$sData) |
|
| 180 | + { |
|
| 181 | + $this->xml .= $this->_cmdXML(array("n"=>"ap","t"=>$sTarget,"p"=>$sAttribute),$sData); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Adds an prepend command message to the XML response. |
|
| 186 | + * |
|
| 187 | + * <i>Usage:</i> <kbd>$objResponse->addPrepend("contentDiv", "innerHTML", "Some Starting Text");</kbd> |
|
| 188 | + * |
|
| 189 | + * @param string contains the id of an HTML element |
|
| 190 | + * @param string the part of the element you wish to modify ("innerHTML", |
|
| 191 | + * "value", etc.) |
|
| 192 | + * @param string the data you want to prepend to the beginning of the |
|
| 193 | + * attribute |
|
| 194 | + */ |
|
| 195 | + function addPrepend($sTarget,$sAttribute,$sData) |
|
| 196 | + { |
|
| 197 | + $this->xml .= $this->_cmdXML(array("n"=>"pp","t"=>$sTarget,"p"=>$sAttribute),$sData); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Adds a replace command message to the XML response. |
|
| 202 | + * |
|
| 203 | + * <i>Usage:</i> <kbd>$objResponse->addReplace("contentDiv", "innerHTML", "text", "<b>text</b>");</kbd> |
|
| 204 | + * |
|
| 205 | + * @param string contains the id of an HTML element |
|
| 206 | + * @param string the part of the element you wish to modify ("innerHTML", |
|
| 207 | + * "value", etc.) |
|
| 208 | + * @param string the string to search for |
|
| 209 | + * @param string the string to replace the search string when found in the |
|
| 210 | + * attribute |
|
| 211 | + */ |
|
| 212 | + function addReplace($sTarget,$sAttribute,$sSearch,$sData) |
|
| 213 | + { |
|
| 214 | + $sDta = "<s><![CDATA[$sSearch]]></s><r><![CDATA[$sData]]></r>"; |
|
| 215 | + $this->xml .= $this->_cmdXML(array("n"=>"rp","t"=>$sTarget,"p"=>$sAttribute),$sDta); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Adds a clear command message to the XML response. |
|
| 220 | + * |
|
| 221 | + * <i>Usage:</i> <kbd>$objResponse->addClear("contentDiv", "innerHTML");</kbd> |
|
| 222 | + * |
|
| 223 | + * @param string contains the id of an HTML element |
|
| 224 | + * @param string the part of the element you wish to clear ("innerHTML", |
|
| 225 | + * "value", etc.) |
|
| 226 | + */ |
|
| 227 | + function addClear($sTarget,$sAttribute) |
|
| 228 | + { |
|
| 229 | + $this->addAssign($sTarget,$sAttribute,''); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Adds an alert command message to the XML response. |
|
| 234 | + * |
|
| 235 | + * <i>Usage:</i> <kbd>$objResponse->addAlert("This is important information");</kbd> |
|
| 236 | + * |
|
| 237 | + * @param string the text to be displayed in the Javascript alert box |
|
| 238 | + */ |
|
| 239 | + function addAlert($sMsg) |
|
| 240 | + { |
|
| 241 | + $this->xml .= $this->_cmdXML(array("n"=>"al"),$sMsg); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Uses the addScript() method to add a Javascript redirect to another URL. |
|
| 246 | + * |
|
| 247 | + * <i>Usage:</i> <kbd>$objResponse->addRedirect("http://www.xajaxproject.org");</kbd> |
|
| 248 | + * |
|
| 249 | + * @param string the URL to redirect the client browser to |
|
| 250 | + */ |
|
| 251 | + function addRedirect($sURL) |
|
| 252 | + { |
|
| 253 | + //we need to parse the query part so that the values are rawurlencode()'ed |
|
| 254 | + //can't just use parse_url() cos we could be dealing with a relative URL which |
|
| 255 | + // parse_url() can't deal with. |
|
| 256 | + $queryStart = strpos($sURL, '?', strrpos($sURL, '/')); |
|
| 257 | + if ($queryStart !== FALSE) |
|
| 258 | + { |
|
| 259 | + $queryStart++; |
|
| 260 | + $queryEnd = strpos($sURL, '#', $queryStart); |
|
| 261 | + if ($queryEnd === FALSE) |
|
| 262 | + $queryEnd = strlen($sURL); |
|
| 263 | + $queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart); |
|
| 264 | 264 | $queryParts = array(); |
| 265 | - parse_str($queryPart, $queryParts); |
|
| 266 | - $newQueryPart = ""; |
|
| 267 | - foreach($queryParts as $key => $value) |
|
| 268 | - { |
|
| 269 | - $newQueryPart .= rawurlencode($key).'='.rawurlencode($value).ini_get('arg_separator.output'); |
|
| 270 | - } |
|
| 271 | - $sURL = str_replace($queryPart, $newQueryPart, $sURL); |
|
| 272 | - } |
|
| 273 | - $this->addScript('window.location = "'.$sURL.'";'); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Adds a Javascript command message to the XML response. |
|
| 278 | - * |
|
| 279 | - * <i>Usage:</i> <kbd>$objResponse->addScript("var x = prompt('get some text');");</kbd> |
|
| 280 | - * |
|
| 281 | - * @param string contains Javascript code to be executed |
|
| 282 | - */ |
|
| 283 | - function addScript($sJS) |
|
| 284 | - { |
|
| 285 | - $this->xml .= $this->_cmdXML(array("n"=>"js"),$sJS); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Adds a Javascript function call command message to the XML response. |
|
| 290 | - * |
|
| 291 | - * <i>Usage:</i> <kbd>$objResponse->addScriptCall("myJSFunction", "arg 1", "arg 2", 12345);</kbd> |
|
| 292 | - * |
|
| 293 | - * @param string $sFunc the name of a Javascript function |
|
| 294 | - * @param mixed $args,... optional arguments to pass to the Javascript function |
|
| 295 | - */ |
|
| 296 | - function addScriptCall() { |
|
| 297 | - $arguments = func_get_args(); |
|
| 298 | - $sFunc = array_shift($arguments); |
|
| 299 | - $sData = $this->_buildObjXml($arguments); |
|
| 300 | - $this->xml .= $this->_cmdXML(array("n"=>"jc","t"=>$sFunc),$sData); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Adds a remove element command message to the XML response. |
|
| 305 | - * |
|
| 306 | - * <i>Usage:</i> <kbd>$objResponse->addRemove("Div2");</kbd> |
|
| 307 | - * |
|
| 308 | - * @param string contains the id of an HTML element to be removed |
|
| 309 | - */ |
|
| 310 | - function addRemove($sTarget) |
|
| 311 | - { |
|
| 312 | - $this->xml .= $this->_cmdXML(array("n"=>"rm","t"=>$sTarget),''); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Adds a create element command message to the XML response. |
|
| 317 | - * |
|
| 318 | - * <i>Usage:</i> <kbd>$objResponse->addCreate("parentDiv", "h3", "myid");</kbd> |
|
| 319 | - * |
|
| 320 | - * @param string contains the id of an HTML element to to which the new |
|
| 321 | - * element will be appended. |
|
| 322 | - * @param string the tag to be added |
|
| 323 | - * @param string the id to be assigned to the new element |
|
| 324 | - * @param string deprecated, use the addCreateInput() method instead |
|
| 325 | - */ |
|
| 326 | - function addCreate($sParent, $sTag, $sId, $sType="") |
|
| 327 | - { |
|
| 328 | - if ($sType) |
|
| 329 | - { |
|
| 330 | - trigger_error("The \$sType parameter of addCreate has been deprecated. Use the addCreateInput() method instead.", E_USER_WARNING); |
|
| 331 | - return; |
|
| 332 | - } |
|
| 333 | - $this->xml .= $this->_cmdXML(array("n"=>"ce","t"=>$sParent,"p"=>$sId),$sTag); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Adds a insert element command message to the XML response. |
|
| 338 | - * |
|
| 339 | - * <i>Usage:</i> <kbd>$objResponse->addInsert("childDiv", "h3", "myid");</kbd> |
|
| 340 | - * |
|
| 341 | - * @param string contains the id of the child before which the new element |
|
| 342 | - * will be inserted |
|
| 343 | - * @param string the tag to be added |
|
| 344 | - * @param string the id to be assigned to the new element |
|
| 345 | - */ |
|
| 346 | - function addInsert($sBefore, $sTag, $sId) |
|
| 347 | - { |
|
| 348 | - $this->xml .= $this->_cmdXML(array("n"=>"ie","t"=>$sBefore,"p"=>$sId),$sTag); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Adds a insert element command message to the XML response. |
|
| 353 | - * |
|
| 354 | - * <i>Usage:</i> <kbd>$objResponse->addInsertAfter("childDiv", "h3", "myid");</kbd> |
|
| 355 | - * |
|
| 356 | - * @param string contains the id of the child after which the new element |
|
| 357 | - * will be inserted |
|
| 358 | - * @param string the tag to be added |
|
| 359 | - * @param string the id to be assigned to the new element |
|
| 360 | - */ |
|
| 361 | - function addInsertAfter($sAfter, $sTag, $sId) |
|
| 362 | - { |
|
| 363 | - $this->xml .= $this->_cmdXML(array("n"=>"ia","t"=>$sAfter,"p"=>$sId),$sTag); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Adds a create input command message to the XML response. |
|
| 368 | - * |
|
| 369 | - * <i>Usage:</i> <kbd>$objResponse->addCreateInput("form1", "text", "username", "input1");</kbd> |
|
| 370 | - * |
|
| 371 | - * @param string contains the id of an HTML element to which the new input |
|
| 372 | - * will be appended |
|
| 373 | - * @param string the type of input to be created (text, radio, checkbox, |
|
| 374 | - * etc.) |
|
| 375 | - * @param string the name to be assigned to the new input and the variable |
|
| 376 | - * name when it is submitted |
|
| 377 | - * @param string the id to be assigned to the new input |
|
| 378 | - */ |
|
| 379 | - function addCreateInput($sParent, $sType, $sName, $sId) |
|
| 380 | - { |
|
| 381 | - $this->xml .= $this->_cmdXML(array("n"=>"ci","t"=>$sParent,"p"=>$sId,"c"=>$sType),$sName); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Adds an insert input command message to the XML response. |
|
| 386 | - * |
|
| 387 | - * <i>Usage:</i> <kbd>$objResponse->addInsertInput("input5", "text", "username", "input1");</kbd> |
|
| 388 | - * |
|
| 389 | - * @param string contains the id of the child before which the new element |
|
| 390 | - * will be inserted |
|
| 391 | - * @param string the type of input to be created (text, radio, checkbox, |
|
| 392 | - * etc.) |
|
| 393 | - * @param string the name to be assigned to the new input and the variable |
|
| 394 | - * name when it is submitted |
|
| 395 | - * @param string the id to be assigned to the new input |
|
| 396 | - */ |
|
| 397 | - function addInsertInput($sBefore, $sType, $sName, $sId) |
|
| 398 | - { |
|
| 399 | - $this->xml .= $this->_cmdXML(array("n"=>"ii","t"=>$sBefore,"p"=>$sId,"c"=>$sType),$sName); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * Adds an insert input command message to the XML response. |
|
| 404 | - * |
|
| 405 | - * <i>Usage:</i> <kbd>$objResponse->addInsertInputAfter("input7", "text", "email", "input2");</kbd> |
|
| 406 | - * |
|
| 407 | - * @param string contains the id of the child after which the new element |
|
| 408 | - * will be inserted |
|
| 409 | - * @param string the type of input to be created (text, radio, checkbox, |
|
| 410 | - * etc.) |
|
| 411 | - * @param string the name to be assigned to the new input and the variable |
|
| 412 | - * name when it is submitted |
|
| 413 | - * @param string the id to be assigned to the new input |
|
| 414 | - */ |
|
| 415 | - function addInsertInputAfter($sAfter, $sType, $sName, $sId) |
|
| 416 | - { |
|
| 417 | - $this->xml .= $this->_cmdXML(array("n"=>"iia","t"=>$sAfter,"p"=>$sId,"c"=>$sType),$sName); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * Adds an event command message to the XML response. |
|
| 422 | - * |
|
| 423 | - * <i>Usage:</i> <kbd>$objResponse->addEvent("contentDiv", "onclick", "alert(\'Hello World\');");</kbd> |
|
| 424 | - * |
|
| 425 | - * @param string contains the id of an HTML element |
|
| 426 | - * @param string the event you wish to set ("onclick", "onmouseover", etc.) |
|
| 427 | - * @param string the Javascript string you want the event to invoke |
|
| 428 | - */ |
|
| 429 | - function addEvent($sTarget,$sEvent,$sScript) |
|
| 430 | - { |
|
| 431 | - $this->xml .= $this->_cmdXML(array("n"=>"ev","t"=>$sTarget,"p"=>$sEvent),$sScript); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Adds a handler command message to the XML response. |
|
| 436 | - * |
|
| 437 | - * <i>Usage:</i> <kbd>$objResponse->addHandler("contentDiv", "onclick", "content_click");</kbd> |
|
| 438 | - * |
|
| 439 | - * @param string contains the id of an HTML element |
|
| 440 | - * @param string the event you wish to set ("onclick", "onmouseover", etc.) |
|
| 441 | - * @param string the name of a Javascript function that will handle the |
|
| 442 | - * event. Multiple handlers can be added for the same event |
|
| 443 | - */ |
|
| 444 | - function addHandler($sTarget,$sEvent,$sHandler) |
|
| 445 | - { |
|
| 446 | - $this->xml .= $this->_cmdXML(array("n"=>"ah","t"=>$sTarget,"p"=>$sEvent),$sHandler); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Adds a remove handler command message to the XML response. |
|
| 451 | - * |
|
| 452 | - * <i>Usage:</i> <kbd>$objResponse->addRemoveHandler("contentDiv", "onclick", "content_click");</kbd> |
|
| 453 | - * |
|
| 454 | - * @param string contains the id of an HTML element |
|
| 455 | - * @param string the event you wish to remove ("onclick", "onmouseover", |
|
| 456 | - * etc.) |
|
| 457 | - * @param string the name of a Javascript handler function that you want to |
|
| 458 | - * remove |
|
| 459 | - */ |
|
| 460 | - function addRemoveHandler($sTarget,$sEvent,$sHandler) |
|
| 461 | - { |
|
| 462 | - $this->xml .= $this->_cmdXML(array("n"=>"rh","t"=>$sTarget,"p"=>$sEvent),$sHandler); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Adds an include script command message to the XML response. |
|
| 467 | - * |
|
| 468 | - * <i>Usage:</i> <kbd>$objResponse->addIncludeScript("functions.js");</kbd> |
|
| 469 | - * |
|
| 470 | - * @param string URL of the Javascript file to include |
|
| 471 | - */ |
|
| 472 | - function addIncludeScript($sFileName) |
|
| 473 | - { |
|
| 474 | - $this->xml .= $this->_cmdXML(array("n"=>"in"),$sFileName); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * Returns the XML to be returned from your function to the xajax processor |
|
| 479 | - * on your page. Since xajax 0.2, you can also return an xajaxResponse |
|
| 480 | - * object from your function directly, and xajax will automatically request |
|
| 481 | - * the XML using this method call. |
|
| 482 | - * |
|
| 483 | - * <i>Usage:</i> <kbd>return $objResponse->getXML();</kbd> |
|
| 484 | - * |
|
| 485 | - * @return string response XML data |
|
| 486 | - */ |
|
| 487 | - function getXML() |
|
| 488 | - { |
|
| 489 | - $sXML = "<?xml version=\"1.0\""; |
|
| 490 | - if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0) |
|
| 491 | - $sXML .= " encoding=\"".$this->sEncoding."\""; |
|
| 492 | - $sXML .= " ?"."><xjx>" . $this->xml . "</xjx>"; |
|
| 493 | - |
|
| 494 | - return $sXML; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Adds the commands of the provided response XML output to this response |
|
| 499 | - * object |
|
| 500 | - * |
|
| 501 | - * <i>Usage:</i> |
|
| 502 | - * <code>$r1 = $objResponse1->getXML(); |
|
| 503 | - * $objResponse2->loadXML($r1); |
|
| 504 | - * return $objResponse2->getXML();</code> |
|
| 505 | - * |
|
| 506 | - * @param string the response XML (returned from a getXML() method) to add |
|
| 507 | - * to the end of this response object |
|
| 508 | - */ |
|
| 509 | - function loadXML($mXML) |
|
| 510 | - { |
|
| 511 | - if (is_a($mXML, "xajaxResponse")) { |
|
| 512 | - $mXML = $mXML->getXML(); |
|
| 513 | - } |
|
| 514 | - $sNewXML = ""; |
|
| 515 | - $iStartPos = strpos($mXML, "<xjx>") + 5; |
|
| 516 | - $sNewXML = substr($mXML, $iStartPos); |
|
| 517 | - $iEndPos = strpos($sNewXML, "</xjx>"); |
|
| 518 | - $sNewXML = substr($sNewXML, 0, $iEndPos); |
|
| 519 | - $this->xml .= $sNewXML; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Generates XML from command data |
|
| 524 | - * |
|
| 525 | - * @access private |
|
| 526 | - * @param array associative array of attributes |
|
| 527 | - * @param string data |
|
| 528 | - * @return string XML command |
|
| 529 | - */ |
|
| 530 | - function _cmdXML($aAttributes, $sData) |
|
| 531 | - { |
|
| 532 | - if ($this->bOutputEntities) { |
|
| 533 | - // An adaptation for the Dokeos LMS, 22-AUG-2009. |
|
| 534 | - if (function_exists('api_convert_encoding')) { |
|
| 535 | - $sData = call_user_func_array('api_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding)); |
|
| 536 | - } |
|
| 537 | - //if (function_exists('mb_convert_encoding')) { |
|
| 538 | - elseif (function_exists('mb_convert_encoding')) { |
|
| 539 | - // |
|
| 540 | - $sData = call_user_func_array('mb_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding)); |
|
| 541 | - } |
|
| 542 | - else { |
|
| 543 | - 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); |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - $xml = "<cmd"; |
|
| 547 | - foreach($aAttributes as $sAttribute => $sValue) |
|
| 548 | - $xml .= " $sAttribute=\"$sValue\""; |
|
| 549 | - if ($sData !== null && !stristr($sData,'<![CDATA[')) |
|
| 550 | - $xml .= "><![CDATA[$sData]]></cmd>"; |
|
| 551 | - else if ($sData !== null) |
|
| 552 | - $xml .= ">$sData</cmd>"; |
|
| 553 | - else |
|
| 554 | - $xml .= "></cmd>"; |
|
| 555 | - |
|
| 556 | - return $xml; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Recursively serializes a data structure in XML so it can be sent to |
|
| 561 | - * the client. It could be thought of as the opposite of |
|
| 562 | - * {@link xajax::_parseObjXml()}. |
|
| 563 | - * |
|
| 564 | - * @access private |
|
| 565 | - * @param mixed data structure to serialize to XML |
|
| 566 | - * @return string serialized XML |
|
| 567 | - */ |
|
| 568 | - function _buildObjXml($var) { |
|
| 569 | - if (gettype($var) == "object") $var = get_object_vars($var); |
|
| 570 | - if (!is_array($var)) { |
|
| 571 | - return "<![CDATA[$var]]>"; |
|
| 572 | - } |
|
| 573 | - else { |
|
| 574 | - $data = "<xjxobj>"; |
|
| 575 | - foreach ($var as $key => $value) { |
|
| 576 | - $data .= "<e>"; |
|
| 577 | - $data .= "<k>" . htmlspecialchars($key) . "</k>"; |
|
| 578 | - $data .= "<v>" . $this->_buildObjXml($value) . "</v>"; |
|
| 579 | - $data .= "</e>"; |
|
| 580 | - } |
|
| 581 | - $data .= "</xjxobj>"; |
|
| 582 | - return $data; |
|
| 583 | - } |
|
| 584 | - } |
|
| 265 | + parse_str($queryPart, $queryParts); |
|
| 266 | + $newQueryPart = ""; |
|
| 267 | + foreach($queryParts as $key => $value) |
|
| 268 | + { |
|
| 269 | + $newQueryPart .= rawurlencode($key).'='.rawurlencode($value).ini_get('arg_separator.output'); |
|
| 270 | + } |
|
| 271 | + $sURL = str_replace($queryPart, $newQueryPart, $sURL); |
|
| 272 | + } |
|
| 273 | + $this->addScript('window.location = "'.$sURL.'";'); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Adds a Javascript command message to the XML response. |
|
| 278 | + * |
|
| 279 | + * <i>Usage:</i> <kbd>$objResponse->addScript("var x = prompt('get some text');");</kbd> |
|
| 280 | + * |
|
| 281 | + * @param string contains Javascript code to be executed |
|
| 282 | + */ |
|
| 283 | + function addScript($sJS) |
|
| 284 | + { |
|
| 285 | + $this->xml .= $this->_cmdXML(array("n"=>"js"),$sJS); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Adds a Javascript function call command message to the XML response. |
|
| 290 | + * |
|
| 291 | + * <i>Usage:</i> <kbd>$objResponse->addScriptCall("myJSFunction", "arg 1", "arg 2", 12345);</kbd> |
|
| 292 | + * |
|
| 293 | + * @param string $sFunc the name of a Javascript function |
|
| 294 | + * @param mixed $args,... optional arguments to pass to the Javascript function |
|
| 295 | + */ |
|
| 296 | + function addScriptCall() { |
|
| 297 | + $arguments = func_get_args(); |
|
| 298 | + $sFunc = array_shift($arguments); |
|
| 299 | + $sData = $this->_buildObjXml($arguments); |
|
| 300 | + $this->xml .= $this->_cmdXML(array("n"=>"jc","t"=>$sFunc),$sData); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Adds a remove element command message to the XML response. |
|
| 305 | + * |
|
| 306 | + * <i>Usage:</i> <kbd>$objResponse->addRemove("Div2");</kbd> |
|
| 307 | + * |
|
| 308 | + * @param string contains the id of an HTML element to be removed |
|
| 309 | + */ |
|
| 310 | + function addRemove($sTarget) |
|
| 311 | + { |
|
| 312 | + $this->xml .= $this->_cmdXML(array("n"=>"rm","t"=>$sTarget),''); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Adds a create element command message to the XML response. |
|
| 317 | + * |
|
| 318 | + * <i>Usage:</i> <kbd>$objResponse->addCreate("parentDiv", "h3", "myid");</kbd> |
|
| 319 | + * |
|
| 320 | + * @param string contains the id of an HTML element to to which the new |
|
| 321 | + * element will be appended. |
|
| 322 | + * @param string the tag to be added |
|
| 323 | + * @param string the id to be assigned to the new element |
|
| 324 | + * @param string deprecated, use the addCreateInput() method instead |
|
| 325 | + */ |
|
| 326 | + function addCreate($sParent, $sTag, $sId, $sType="") |
|
| 327 | + { |
|
| 328 | + if ($sType) |
|
| 329 | + { |
|
| 330 | + trigger_error("The \$sType parameter of addCreate has been deprecated. Use the addCreateInput() method instead.", E_USER_WARNING); |
|
| 331 | + return; |
|
| 332 | + } |
|
| 333 | + $this->xml .= $this->_cmdXML(array("n"=>"ce","t"=>$sParent,"p"=>$sId),$sTag); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Adds a insert element command message to the XML response. |
|
| 338 | + * |
|
| 339 | + * <i>Usage:</i> <kbd>$objResponse->addInsert("childDiv", "h3", "myid");</kbd> |
|
| 340 | + * |
|
| 341 | + * @param string contains the id of the child before which the new element |
|
| 342 | + * will be inserted |
|
| 343 | + * @param string the tag to be added |
|
| 344 | + * @param string the id to be assigned to the new element |
|
| 345 | + */ |
|
| 346 | + function addInsert($sBefore, $sTag, $sId) |
|
| 347 | + { |
|
| 348 | + $this->xml .= $this->_cmdXML(array("n"=>"ie","t"=>$sBefore,"p"=>$sId),$sTag); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Adds a insert element command message to the XML response. |
|
| 353 | + * |
|
| 354 | + * <i>Usage:</i> <kbd>$objResponse->addInsertAfter("childDiv", "h3", "myid");</kbd> |
|
| 355 | + * |
|
| 356 | + * @param string contains the id of the child after which the new element |
|
| 357 | + * will be inserted |
|
| 358 | + * @param string the tag to be added |
|
| 359 | + * @param string the id to be assigned to the new element |
|
| 360 | + */ |
|
| 361 | + function addInsertAfter($sAfter, $sTag, $sId) |
|
| 362 | + { |
|
| 363 | + $this->xml .= $this->_cmdXML(array("n"=>"ia","t"=>$sAfter,"p"=>$sId),$sTag); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Adds a create input command message to the XML response. |
|
| 368 | + * |
|
| 369 | + * <i>Usage:</i> <kbd>$objResponse->addCreateInput("form1", "text", "username", "input1");</kbd> |
|
| 370 | + * |
|
| 371 | + * @param string contains the id of an HTML element to which the new input |
|
| 372 | + * will be appended |
|
| 373 | + * @param string the type of input to be created (text, radio, checkbox, |
|
| 374 | + * etc.) |
|
| 375 | + * @param string the name to be assigned to the new input and the variable |
|
| 376 | + * name when it is submitted |
|
| 377 | + * @param string the id to be assigned to the new input |
|
| 378 | + */ |
|
| 379 | + function addCreateInput($sParent, $sType, $sName, $sId) |
|
| 380 | + { |
|
| 381 | + $this->xml .= $this->_cmdXML(array("n"=>"ci","t"=>$sParent,"p"=>$sId,"c"=>$sType),$sName); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Adds an insert input command message to the XML response. |
|
| 386 | + * |
|
| 387 | + * <i>Usage:</i> <kbd>$objResponse->addInsertInput("input5", "text", "username", "input1");</kbd> |
|
| 388 | + * |
|
| 389 | + * @param string contains the id of the child before which the new element |
|
| 390 | + * will be inserted |
|
| 391 | + * @param string the type of input to be created (text, radio, checkbox, |
|
| 392 | + * etc.) |
|
| 393 | + * @param string the name to be assigned to the new input and the variable |
|
| 394 | + * name when it is submitted |
|
| 395 | + * @param string the id to be assigned to the new input |
|
| 396 | + */ |
|
| 397 | + function addInsertInput($sBefore, $sType, $sName, $sId) |
|
| 398 | + { |
|
| 399 | + $this->xml .= $this->_cmdXML(array("n"=>"ii","t"=>$sBefore,"p"=>$sId,"c"=>$sType),$sName); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * Adds an insert input command message to the XML response. |
|
| 404 | + * |
|
| 405 | + * <i>Usage:</i> <kbd>$objResponse->addInsertInputAfter("input7", "text", "email", "input2");</kbd> |
|
| 406 | + * |
|
| 407 | + * @param string contains the id of the child after which the new element |
|
| 408 | + * will be inserted |
|
| 409 | + * @param string the type of input to be created (text, radio, checkbox, |
|
| 410 | + * etc.) |
|
| 411 | + * @param string the name to be assigned to the new input and the variable |
|
| 412 | + * name when it is submitted |
|
| 413 | + * @param string the id to be assigned to the new input |
|
| 414 | + */ |
|
| 415 | + function addInsertInputAfter($sAfter, $sType, $sName, $sId) |
|
| 416 | + { |
|
| 417 | + $this->xml .= $this->_cmdXML(array("n"=>"iia","t"=>$sAfter,"p"=>$sId,"c"=>$sType),$sName); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * Adds an event command message to the XML response. |
|
| 422 | + * |
|
| 423 | + * <i>Usage:</i> <kbd>$objResponse->addEvent("contentDiv", "onclick", "alert(\'Hello World\');");</kbd> |
|
| 424 | + * |
|
| 425 | + * @param string contains the id of an HTML element |
|
| 426 | + * @param string the event you wish to set ("onclick", "onmouseover", etc.) |
|
| 427 | + * @param string the Javascript string you want the event to invoke |
|
| 428 | + */ |
|
| 429 | + function addEvent($sTarget,$sEvent,$sScript) |
|
| 430 | + { |
|
| 431 | + $this->xml .= $this->_cmdXML(array("n"=>"ev","t"=>$sTarget,"p"=>$sEvent),$sScript); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Adds a handler command message to the XML response. |
|
| 436 | + * |
|
| 437 | + * <i>Usage:</i> <kbd>$objResponse->addHandler("contentDiv", "onclick", "content_click");</kbd> |
|
| 438 | + * |
|
| 439 | + * @param string contains the id of an HTML element |
|
| 440 | + * @param string the event you wish to set ("onclick", "onmouseover", etc.) |
|
| 441 | + * @param string the name of a Javascript function that will handle the |
|
| 442 | + * event. Multiple handlers can be added for the same event |
|
| 443 | + */ |
|
| 444 | + function addHandler($sTarget,$sEvent,$sHandler) |
|
| 445 | + { |
|
| 446 | + $this->xml .= $this->_cmdXML(array("n"=>"ah","t"=>$sTarget,"p"=>$sEvent),$sHandler); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Adds a remove handler command message to the XML response. |
|
| 451 | + * |
|
| 452 | + * <i>Usage:</i> <kbd>$objResponse->addRemoveHandler("contentDiv", "onclick", "content_click");</kbd> |
|
| 453 | + * |
|
| 454 | + * @param string contains the id of an HTML element |
|
| 455 | + * @param string the event you wish to remove ("onclick", "onmouseover", |
|
| 456 | + * etc.) |
|
| 457 | + * @param string the name of a Javascript handler function that you want to |
|
| 458 | + * remove |
|
| 459 | + */ |
|
| 460 | + function addRemoveHandler($sTarget,$sEvent,$sHandler) |
|
| 461 | + { |
|
| 462 | + $this->xml .= $this->_cmdXML(array("n"=>"rh","t"=>$sTarget,"p"=>$sEvent),$sHandler); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Adds an include script command message to the XML response. |
|
| 467 | + * |
|
| 468 | + * <i>Usage:</i> <kbd>$objResponse->addIncludeScript("functions.js");</kbd> |
|
| 469 | + * |
|
| 470 | + * @param string URL of the Javascript file to include |
|
| 471 | + */ |
|
| 472 | + function addIncludeScript($sFileName) |
|
| 473 | + { |
|
| 474 | + $this->xml .= $this->_cmdXML(array("n"=>"in"),$sFileName); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * Returns the XML to be returned from your function to the xajax processor |
|
| 479 | + * on your page. Since xajax 0.2, you can also return an xajaxResponse |
|
| 480 | + * object from your function directly, and xajax will automatically request |
|
| 481 | + * the XML using this method call. |
|
| 482 | + * |
|
| 483 | + * <i>Usage:</i> <kbd>return $objResponse->getXML();</kbd> |
|
| 484 | + * |
|
| 485 | + * @return string response XML data |
|
| 486 | + */ |
|
| 487 | + function getXML() |
|
| 488 | + { |
|
| 489 | + $sXML = "<?xml version=\"1.0\""; |
|
| 490 | + if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0) |
|
| 491 | + $sXML .= " encoding=\"".$this->sEncoding."\""; |
|
| 492 | + $sXML .= " ?"."><xjx>" . $this->xml . "</xjx>"; |
|
| 493 | + |
|
| 494 | + return $sXML; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Adds the commands of the provided response XML output to this response |
|
| 499 | + * object |
|
| 500 | + * |
|
| 501 | + * <i>Usage:</i> |
|
| 502 | + * <code>$r1 = $objResponse1->getXML(); |
|
| 503 | + * $objResponse2->loadXML($r1); |
|
| 504 | + * return $objResponse2->getXML();</code> |
|
| 505 | + * |
|
| 506 | + * @param string the response XML (returned from a getXML() method) to add |
|
| 507 | + * to the end of this response object |
|
| 508 | + */ |
|
| 509 | + function loadXML($mXML) |
|
| 510 | + { |
|
| 511 | + if (is_a($mXML, "xajaxResponse")) { |
|
| 512 | + $mXML = $mXML->getXML(); |
|
| 513 | + } |
|
| 514 | + $sNewXML = ""; |
|
| 515 | + $iStartPos = strpos($mXML, "<xjx>") + 5; |
|
| 516 | + $sNewXML = substr($mXML, $iStartPos); |
|
| 517 | + $iEndPos = strpos($sNewXML, "</xjx>"); |
|
| 518 | + $sNewXML = substr($sNewXML, 0, $iEndPos); |
|
| 519 | + $this->xml .= $sNewXML; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Generates XML from command data |
|
| 524 | + * |
|
| 525 | + * @access private |
|
| 526 | + * @param array associative array of attributes |
|
| 527 | + * @param string data |
|
| 528 | + * @return string XML command |
|
| 529 | + */ |
|
| 530 | + function _cmdXML($aAttributes, $sData) |
|
| 531 | + { |
|
| 532 | + if ($this->bOutputEntities) { |
|
| 533 | + // An adaptation for the Dokeos LMS, 22-AUG-2009. |
|
| 534 | + if (function_exists('api_convert_encoding')) { |
|
| 535 | + $sData = call_user_func_array('api_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding)); |
|
| 536 | + } |
|
| 537 | + //if (function_exists('mb_convert_encoding')) { |
|
| 538 | + elseif (function_exists('mb_convert_encoding')) { |
|
| 539 | + // |
|
| 540 | + $sData = call_user_func_array('mb_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding)); |
|
| 541 | + } |
|
| 542 | + else { |
|
| 543 | + 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); |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + $xml = "<cmd"; |
|
| 547 | + foreach($aAttributes as $sAttribute => $sValue) |
|
| 548 | + $xml .= " $sAttribute=\"$sValue\""; |
|
| 549 | + if ($sData !== null && !stristr($sData,'<![CDATA[')) |
|
| 550 | + $xml .= "><![CDATA[$sData]]></cmd>"; |
|
| 551 | + else if ($sData !== null) |
|
| 552 | + $xml .= ">$sData</cmd>"; |
|
| 553 | + else |
|
| 554 | + $xml .= "></cmd>"; |
|
| 555 | + |
|
| 556 | + return $xml; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Recursively serializes a data structure in XML so it can be sent to |
|
| 561 | + * the client. It could be thought of as the opposite of |
|
| 562 | + * {@link xajax::_parseObjXml()}. |
|
| 563 | + * |
|
| 564 | + * @access private |
|
| 565 | + * @param mixed data structure to serialize to XML |
|
| 566 | + * @return string serialized XML |
|
| 567 | + */ |
|
| 568 | + function _buildObjXml($var) { |
|
| 569 | + if (gettype($var) == "object") $var = get_object_vars($var); |
|
| 570 | + if (!is_array($var)) { |
|
| 571 | + return "<![CDATA[$var]]>"; |
|
| 572 | + } |
|
| 573 | + else { |
|
| 574 | + $data = "<xjxobj>"; |
|
| 575 | + foreach ($var as $key => $value) { |
|
| 576 | + $data .= "<e>"; |
|
| 577 | + $data .= "<k>" . htmlspecialchars($key) . "</k>"; |
|
| 578 | + $data .= "<v>" . $this->_buildObjXml($value) . "</v>"; |
|
| 579 | + $data .= "</e>"; |
|
| 580 | + } |
|
| 581 | + $data .= "</xjxobj>"; |
|
| 582 | + return $data; |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | 585 | |
| 586 | 586 | }// end class xajaxResponse |
| 587 | 587 | ?> |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * converted to HTML entities |
| 100 | 100 | * |
| 101 | 101 | */ |
| 102 | - public function __construct($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities=false) |
|
| 102 | + public function __construct($sEncoding = XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities = false) |
|
| 103 | 103 | { |
| 104 | 104 | $this->setCharEncoding($sEncoding); |
| 105 | 105 | $this->bOutputEntities = $bOutputEntities; |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | function addConfirmCommands($iCmdNumber, $sMessage) |
| 150 | 150 | { |
| 151 | - $this->xml .= $this->_cmdXML(array("n"=>"cc","t"=>$iCmdNumber),$sMessage); |
|
| 151 | + $this->xml .= $this->_cmdXML(array("n"=>"cc", "t"=>$iCmdNumber), $sMessage); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -161,9 +161,9 @@ discard block |
||
| 161 | 161 | * "value", etc.) |
| 162 | 162 | * @param string the data you want to set the attribute to |
| 163 | 163 | */ |
| 164 | - function addAssign($sTarget,$sAttribute,$sData) |
|
| 164 | + function addAssign($sTarget, $sAttribute, $sData) |
|
| 165 | 165 | { |
| 166 | - $this->xml .= $this->_cmdXML(array("n"=>"as","t"=>$sTarget,"p"=>$sAttribute),$sData); |
|
| 166 | + $this->xml .= $this->_cmdXML(array("n"=>"as", "t"=>$sTarget, "p"=>$sAttribute), $sData); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | * "value", etc.) |
| 177 | 177 | * @param string the data you want to append to the end of the attribute |
| 178 | 178 | */ |
| 179 | - function addAppend($sTarget,$sAttribute,$sData) |
|
| 179 | + function addAppend($sTarget, $sAttribute, $sData) |
|
| 180 | 180 | { |
| 181 | - $this->xml .= $this->_cmdXML(array("n"=>"ap","t"=>$sTarget,"p"=>$sAttribute),$sData); |
|
| 181 | + $this->xml .= $this->_cmdXML(array("n"=>"ap", "t"=>$sTarget, "p"=>$sAttribute), $sData); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | * @param string the data you want to prepend to the beginning of the |
| 193 | 193 | * attribute |
| 194 | 194 | */ |
| 195 | - function addPrepend($sTarget,$sAttribute,$sData) |
|
| 195 | + function addPrepend($sTarget, $sAttribute, $sData) |
|
| 196 | 196 | { |
| 197 | - $this->xml .= $this->_cmdXML(array("n"=>"pp","t"=>$sTarget,"p"=>$sAttribute),$sData); |
|
| 197 | + $this->xml .= $this->_cmdXML(array("n"=>"pp", "t"=>$sTarget, "p"=>$sAttribute), $sData); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -209,10 +209,10 @@ discard block |
||
| 209 | 209 | * @param string the string to replace the search string when found in the |
| 210 | 210 | * attribute |
| 211 | 211 | */ |
| 212 | - function addReplace($sTarget,$sAttribute,$sSearch,$sData) |
|
| 212 | + function addReplace($sTarget, $sAttribute, $sSearch, $sData) |
|
| 213 | 213 | { |
| 214 | 214 | $sDta = "<s><![CDATA[$sSearch]]></s><r><![CDATA[$sData]]></r>"; |
| 215 | - $this->xml .= $this->_cmdXML(array("n"=>"rp","t"=>$sTarget,"p"=>$sAttribute),$sDta); |
|
| 215 | + $this->xml .= $this->_cmdXML(array("n"=>"rp", "t"=>$sTarget, "p"=>$sAttribute), $sDta); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -224,9 +224,9 @@ discard block |
||
| 224 | 224 | * @param string the part of the element you wish to clear ("innerHTML", |
| 225 | 225 | * "value", etc.) |
| 226 | 226 | */ |
| 227 | - function addClear($sTarget,$sAttribute) |
|
| 227 | + function addClear($sTarget, $sAttribute) |
|
| 228 | 228 | { |
| 229 | - $this->addAssign($sTarget,$sAttribute,''); |
|
| 229 | + $this->addAssign($sTarget, $sAttribute, ''); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | */ |
| 239 | 239 | function addAlert($sMsg) |
| 240 | 240 | { |
| 241 | - $this->xml .= $this->_cmdXML(array("n"=>"al"),$sMsg); |
|
| 241 | + $this->xml .= $this->_cmdXML(array("n"=>"al"), $sMsg); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | $queryEnd = strpos($sURL, '#', $queryStart); |
| 261 | 261 | if ($queryEnd === FALSE) |
| 262 | 262 | $queryEnd = strlen($sURL); |
| 263 | - $queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart); |
|
| 263 | + $queryPart = substr($sURL, $queryStart, $queryEnd - $queryStart); |
|
| 264 | 264 | $queryParts = array(); |
| 265 | 265 | parse_str($queryPart, $queryParts); |
| 266 | 266 | $newQueryPart = ""; |
| 267 | - foreach($queryParts as $key => $value) |
|
| 267 | + foreach ($queryParts as $key => $value) |
|
| 268 | 268 | { |
| 269 | 269 | $newQueryPart .= rawurlencode($key).'='.rawurlencode($value).ini_get('arg_separator.output'); |
| 270 | 270 | } |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | function addScript($sJS) |
| 284 | 284 | { |
| 285 | - $this->xml .= $this->_cmdXML(array("n"=>"js"),$sJS); |
|
| 285 | + $this->xml .= $this->_cmdXML(array("n"=>"js"), $sJS); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | $arguments = func_get_args(); |
| 298 | 298 | $sFunc = array_shift($arguments); |
| 299 | 299 | $sData = $this->_buildObjXml($arguments); |
| 300 | - $this->xml .= $this->_cmdXML(array("n"=>"jc","t"=>$sFunc),$sData); |
|
| 300 | + $this->xml .= $this->_cmdXML(array("n"=>"jc", "t"=>$sFunc), $sData); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | function addRemove($sTarget) |
| 311 | 311 | { |
| 312 | - $this->xml .= $this->_cmdXML(array("n"=>"rm","t"=>$sTarget),''); |
|
| 312 | + $this->xml .= $this->_cmdXML(array("n"=>"rm", "t"=>$sTarget), ''); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
@@ -323,14 +323,14 @@ discard block |
||
| 323 | 323 | * @param string the id to be assigned to the new element |
| 324 | 324 | * @param string deprecated, use the addCreateInput() method instead |
| 325 | 325 | */ |
| 326 | - function addCreate($sParent, $sTag, $sId, $sType="") |
|
| 326 | + function addCreate($sParent, $sTag, $sId, $sType = "") |
|
| 327 | 327 | { |
| 328 | 328 | if ($sType) |
| 329 | 329 | { |
| 330 | 330 | trigger_error("The \$sType parameter of addCreate has been deprecated. Use the addCreateInput() method instead.", E_USER_WARNING); |
| 331 | 331 | return; |
| 332 | 332 | } |
| 333 | - $this->xml .= $this->_cmdXML(array("n"=>"ce","t"=>$sParent,"p"=>$sId),$sTag); |
|
| 333 | + $this->xml .= $this->_cmdXML(array("n"=>"ce", "t"=>$sParent, "p"=>$sId), $sTag); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | function addInsert($sBefore, $sTag, $sId) |
| 347 | 347 | { |
| 348 | - $this->xml .= $this->_cmdXML(array("n"=>"ie","t"=>$sBefore,"p"=>$sId),$sTag); |
|
| 348 | + $this->xml .= $this->_cmdXML(array("n"=>"ie", "t"=>$sBefore, "p"=>$sId), $sTag); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | */ |
| 361 | 361 | function addInsertAfter($sAfter, $sTag, $sId) |
| 362 | 362 | { |
| 363 | - $this->xml .= $this->_cmdXML(array("n"=>"ia","t"=>$sAfter,"p"=>$sId),$sTag); |
|
| 363 | + $this->xml .= $this->_cmdXML(array("n"=>"ia", "t"=>$sAfter, "p"=>$sId), $sTag); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | function addCreateInput($sParent, $sType, $sName, $sId) |
| 380 | 380 | { |
| 381 | - $this->xml .= $this->_cmdXML(array("n"=>"ci","t"=>$sParent,"p"=>$sId,"c"=>$sType),$sName); |
|
| 381 | + $this->xml .= $this->_cmdXML(array("n"=>"ci", "t"=>$sParent, "p"=>$sId, "c"=>$sType), $sName); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | */ |
| 397 | 397 | function addInsertInput($sBefore, $sType, $sName, $sId) |
| 398 | 398 | { |
| 399 | - $this->xml .= $this->_cmdXML(array("n"=>"ii","t"=>$sBefore,"p"=>$sId,"c"=>$sType),$sName); |
|
| 399 | + $this->xml .= $this->_cmdXML(array("n"=>"ii", "t"=>$sBefore, "p"=>$sId, "c"=>$sType), $sName); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | */ |
| 415 | 415 | function addInsertInputAfter($sAfter, $sType, $sName, $sId) |
| 416 | 416 | { |
| 417 | - $this->xml .= $this->_cmdXML(array("n"=>"iia","t"=>$sAfter,"p"=>$sId,"c"=>$sType),$sName); |
|
| 417 | + $this->xml .= $this->_cmdXML(array("n"=>"iia", "t"=>$sAfter, "p"=>$sId, "c"=>$sType), $sName); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -426,9 +426,9 @@ discard block |
||
| 426 | 426 | * @param string the event you wish to set ("onclick", "onmouseover", etc.) |
| 427 | 427 | * @param string the Javascript string you want the event to invoke |
| 428 | 428 | */ |
| 429 | - function addEvent($sTarget,$sEvent,$sScript) |
|
| 429 | + function addEvent($sTarget, $sEvent, $sScript) |
|
| 430 | 430 | { |
| 431 | - $this->xml .= $this->_cmdXML(array("n"=>"ev","t"=>$sTarget,"p"=>$sEvent),$sScript); |
|
| 431 | + $this->xml .= $this->_cmdXML(array("n"=>"ev", "t"=>$sTarget, "p"=>$sEvent), $sScript); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -441,9 +441,9 @@ discard block |
||
| 441 | 441 | * @param string the name of a Javascript function that will handle the |
| 442 | 442 | * event. Multiple handlers can be added for the same event |
| 443 | 443 | */ |
| 444 | - function addHandler($sTarget,$sEvent,$sHandler) |
|
| 444 | + function addHandler($sTarget, $sEvent, $sHandler) |
|
| 445 | 445 | { |
| 446 | - $this->xml .= $this->_cmdXML(array("n"=>"ah","t"=>$sTarget,"p"=>$sEvent),$sHandler); |
|
| 446 | + $this->xml .= $this->_cmdXML(array("n"=>"ah", "t"=>$sTarget, "p"=>$sEvent), $sHandler); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -457,9 +457,9 @@ discard block |
||
| 457 | 457 | * @param string the name of a Javascript handler function that you want to |
| 458 | 458 | * remove |
| 459 | 459 | */ |
| 460 | - function addRemoveHandler($sTarget,$sEvent,$sHandler) |
|
| 460 | + function addRemoveHandler($sTarget, $sEvent, $sHandler) |
|
| 461 | 461 | { |
| 462 | - $this->xml .= $this->_cmdXML(array("n"=>"rh","t"=>$sTarget,"p"=>$sEvent),$sHandler); |
|
| 462 | + $this->xml .= $this->_cmdXML(array("n"=>"rh", "t"=>$sTarget, "p"=>$sEvent), $sHandler); |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | /** |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | */ |
| 472 | 472 | function addIncludeScript($sFileName) |
| 473 | 473 | { |
| 474 | - $this->xml .= $this->_cmdXML(array("n"=>"in"),$sFileName); |
|
| 474 | + $this->xml .= $this->_cmdXML(array("n"=>"in"), $sFileName); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | $sXML = "<?xml version=\"1.0\""; |
| 490 | 490 | if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0) |
| 491 | 491 | $sXML .= " encoding=\"".$this->sEncoding."\""; |
| 492 | - $sXML .= " ?"."><xjx>" . $this->xml . "</xjx>"; |
|
| 492 | + $sXML .= " ?"."><xjx>".$this->xml."</xjx>"; |
|
| 493 | 493 | |
| 494 | 494 | return $sXML; |
| 495 | 495 | } |
@@ -544,9 +544,9 @@ discard block |
||
| 544 | 544 | } |
| 545 | 545 | } |
| 546 | 546 | $xml = "<cmd"; |
| 547 | - foreach($aAttributes as $sAttribute => $sValue) |
|
| 547 | + foreach ($aAttributes as $sAttribute => $sValue) |
|
| 548 | 548 | $xml .= " $sAttribute=\"$sValue\""; |
| 549 | - if ($sData !== null && !stristr($sData,'<![CDATA[')) |
|
| 549 | + if ($sData !== null && !stristr($sData, '<![CDATA[')) |
|
| 550 | 550 | $xml .= "><![CDATA[$sData]]></cmd>"; |
| 551 | 551 | else if ($sData !== null) |
| 552 | 552 | $xml .= ">$sData</cmd>"; |
@@ -574,8 +574,8 @@ discard block |
||
| 574 | 574 | $data = "<xjxobj>"; |
| 575 | 575 | foreach ($var as $key => $value) { |
| 576 | 576 | $data .= "<e>"; |
| 577 | - $data .= "<k>" . htmlspecialchars($key) . "</k>"; |
|
| 578 | - $data .= "<v>" . $this->_buildObjXml($value) . "</v>"; |
|
| 577 | + $data .= "<k>".htmlspecialchars($key)."</k>"; |
|
| 578 | + $data .= "<v>".$this->_buildObjXml($value)."</v>"; |
|
| 579 | 579 | $data .= "</e>"; |
| 580 | 580 | } |
| 581 | 581 | $data .= "</xjxobj>"; |
@@ -657,6 +657,7 @@ discard block |
||
| 657 | 657 | * retrieves all the courses that the user has already subscribed to |
| 658 | 658 | * @author Patrick Cool <[email protected]>, Ghent University, Belgium |
| 659 | 659 | * @param int $user_id: the id of the user |
| 660 | + * @param integer $user_id |
|
| 660 | 661 | * @return array an array containing all the information of the courses of the given user |
| 661 | 662 | */ |
| 662 | 663 | public function get_courses_of_user($user_id) |
@@ -707,13 +708,13 @@ discard block |
||
| 707 | 708 | |
| 708 | 709 | /** |
| 709 | 710 | * @todo use the template system |
| 710 | - * @param $title |
|
| 711 | - * @param $content |
|
| 711 | + * @param string|null $title |
|
| 712 | + * @param string $content |
|
| 712 | 713 | * @param string $id |
| 713 | 714 | * @param array $params |
| 714 | 715 | * @param string $idAccordion |
| 715 | 716 | * @param string $idCollapse |
| 716 | - * @return null|string |
|
| 717 | + * @return string |
|
| 717 | 718 | */ |
| 718 | 719 | public function show_right_block( |
| 719 | 720 | $title, |
@@ -937,7 +938,7 @@ discard block |
||
| 937 | 938 | } |
| 938 | 939 | |
| 939 | 940 | /** |
| 940 | - * @return null|string |
|
| 941 | + * @return string |
|
| 941 | 942 | */ |
| 942 | 943 | public function return_course_block() |
| 943 | 944 | { |
@@ -1590,8 +1591,8 @@ discard block |
||
| 1590 | 1591 | |
| 1591 | 1592 | /** |
| 1592 | 1593 | * Return HTML code for personal user course category |
| 1593 | - * @param $id |
|
| 1594 | - * @param $title |
|
| 1594 | + * @param integer $id |
|
| 1595 | + * @param string $title |
|
| 1595 | 1596 | * @return string |
| 1596 | 1597 | */ |
| 1597 | 1598 | private static function getHtmlForUserCategory($id, $title) |
@@ -1612,7 +1613,7 @@ discard block |
||
| 1612 | 1613 | /** |
| 1613 | 1614 | * return HTML code for course display in session view |
| 1614 | 1615 | * @param array $courseInfo |
| 1615 | - * @param $userCategoryId |
|
| 1616 | + * @param integer $userCategoryId |
|
| 1616 | 1617 | * @param bool $displayButton |
| 1617 | 1618 | * @param $loadDirs |
| 1618 | 1619 | * @return string |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | { |
| 45 | 45 | $exercise_list = array(); |
| 46 | 46 | if (!empty($personal_course_list)) { |
| 47 | - foreach($personal_course_list as $course_item) { |
|
| 47 | + foreach ($personal_course_list as $course_item) { |
|
| 48 | 48 | $course_code = $course_item['c']; |
| 49 | 49 | $session_id = $course_item['id_session']; |
| 50 | 50 | |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | $session_id |
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | - foreach($exercises as $exercise_item) { |
|
| 57 | - $exercise_item['course_code'] = $course_code; |
|
| 58 | - $exercise_item['session_id'] = $session_id; |
|
| 59 | - $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC'); |
|
| 56 | + foreach ($exercises as $exercise_item) { |
|
| 57 | + $exercise_item['course_code'] = $course_code; |
|
| 58 | + $exercise_item['session_id'] = $session_id; |
|
| 59 | + $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC'); |
|
| 60 | 60 | |
| 61 | 61 | $exercise_list[] = $exercise_item; |
| 62 | 62 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - if ($show_menu && ($show_create_link || $show_course_link )) { |
|
| 174 | + if ($show_menu && ($show_create_link || $show_course_link)) { |
|
| 175 | 175 | $show_menu = true; |
| 176 | 176 | } else { |
| 177 | 177 | $show_menu = false; |
@@ -183,14 +183,14 @@ discard block |
||
| 183 | 183 | if ($show_menu) { |
| 184 | 184 | $html .= '<ul class="nav nav-pills nav-stacked">'; |
| 185 | 185 | if ($show_create_link) { |
| 186 | - $html .= '<li class="add-course"><a href="' . api_get_path(WEB_CODE_PATH) . 'create_course/add_course.php">'.Display::return_icon('new-course.png', get_lang('CourseCreate')).(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>'; |
|
| 186 | + $html .= '<li class="add-course"><a href="'.api_get_path(WEB_CODE_PATH).'create_course/add_course.php">'.Display::return_icon('new-course.png', get_lang('CourseCreate')).(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>'; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | if ($show_course_link) { |
| 190 | 190 | if (!api_is_drh() && !api_is_session_admin()) { |
| 191 | - $html .= '<li class="list-course"><a href="'. api_get_path(WEB_CODE_PATH) . 'auth/courses.php">'. Display::return_icon('catalog-course.png', get_lang('CourseCatalog')) .get_lang('CourseCatalog').'</a></li>'; |
|
| 191 | + $html .= '<li class="list-course"><a href="'.api_get_path(WEB_CODE_PATH).'auth/courses.php">'.Display::return_icon('catalog-course.png', get_lang('CourseCatalog')).get_lang('CourseCatalog').'</a></li>'; |
|
| 192 | 192 | } else { |
| 193 | - $html .= '<li><a href="' . api_get_path(WEB_CODE_PATH) . 'dashboard/index.php">'.get_lang('Dashboard').'</a></li>'; |
|
| 193 | + $html .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'dashboard/index.php">'.get_lang('Dashboard').'</a></li>'; |
|
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | $html .= '</ul>'; |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | $html = ''; |
| 215 | 215 | |
| 216 | 216 | if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) { |
| 217 | - $open = @(string)file_get_contents(api_get_path(SYS_PATH).$this->home.$_GET['include']); |
|
| 217 | + $open = @(string) file_get_contents(api_get_path(SYS_PATH).$this->home.$_GET['include']); |
|
| 218 | 218 | $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
| 219 | 219 | } else { |
| 220 | 220 | // Hiding home top when user not connected. |
@@ -244,15 +244,15 @@ discard block |
||
| 244 | 244 | $home_top_temp = file_get_contents($this->home.'home_top.html'); |
| 245 | 245 | } else { |
| 246 | 246 | if (file_exists($this->default_home.'home_top.html')) { |
| 247 | - $home_top_temp = file_get_contents($this->default_home . 'home_top.html'); |
|
| 247 | + $home_top_temp = file_get_contents($this->default_home.'home_top.html'); |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | if (trim($home_top_temp) == '' && api_is_platform_admin()) { |
| 253 | - $home_top_temp = '<div class="welcome-mascot">' . get_lang('PortalHomepageDefaultIntroduction') . '</div>'; |
|
| 253 | + $home_top_temp = '<div class="welcome-mascot">'.get_lang('PortalHomepageDefaultIntroduction').'</div>'; |
|
| 254 | 254 | } else { |
| 255 | - $home_top_temp = '<div class="welcome-home-top-temp">' . $home_top_temp . '</div>'; |
|
| 255 | + $home_top_temp = '<div class="welcome-home-top-temp">'.$home_top_temp.'</div>'; |
|
| 256 | 256 | } |
| 257 | 257 | $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp); |
| 258 | 258 | $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | |
| 269 | 269 | $html = ''; |
| 270 | 270 | // Notice |
| 271 | - $home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice_'.$user_selected_language.'.html'); |
|
| 271 | + $home_notice = @(string) file_get_contents($sys_path.$this->home.'home_notice_'.$user_selected_language.'.html'); |
|
| 272 | 272 | if (empty($home_notice)) { |
| 273 | - $home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice.html'); |
|
| 273 | + $home_notice = @(string) file_get_contents($sys_path.$this->home.'home_notice.html'); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | if (!empty($home_notice)) { |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | $html = null; |
| 305 | - $home_menu = @(string)file_get_contents($sys_path.$this->home.'home_menu_'.$user_selected_language.'.html'); |
|
| 305 | + $home_menu = @(string) file_get_contents($sys_path.$this->home.'home_menu_'.$user_selected_language.'.html'); |
|
| 306 | 306 | if (!empty($home_menu)) { |
| 307 | 307 | $home_menu_content = '<ul class="nav nav-pills nav-stacked">'; |
| 308 | 308 | $home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); |
@@ -332,9 +332,9 @@ discard block |
||
| 332 | 332 | if (!api_is_anonymous()) { |
| 333 | 333 | $certificatesItem = Display::tag( |
| 334 | 334 | 'li', |
| 335 | - Display::url(Display::return_icon('graduation.png',get_lang('MyCertificates'),null,ICON_SIZE_SMALL). |
|
| 335 | + Display::url(Display::return_icon('graduation.png', get_lang('MyCertificates'), null, ICON_SIZE_SMALL). |
|
| 336 | 336 | get_lang('MyCertificates'), |
| 337 | - api_get_path(WEB_CODE_PATH) . "gradebook/my_certificates.php" |
|
| 337 | + api_get_path(WEB_CODE_PATH)."gradebook/my_certificates.php" |
|
| 338 | 338 | ) |
| 339 | 339 | ); |
| 340 | 340 | } |
@@ -344,29 +344,29 @@ discard block |
||
| 344 | 344 | if (api_get_setting('allow_public_certificates') == 'true') { |
| 345 | 345 | $searchItem = Display::tag( |
| 346 | 346 | 'li', |
| 347 | - Display::url(Display::return_icon('search_graduation.png',get_lang('Search'),null,ICON_SIZE_SMALL). |
|
| 347 | + Display::url(Display::return_icon('search_graduation.png', get_lang('Search'), null, ICON_SIZE_SMALL). |
|
| 348 | 348 | get_lang('Search'), |
| 349 | - api_get_path(WEB_CODE_PATH) . "gradebook/search.php" |
|
| 349 | + api_get_path(WEB_CODE_PATH)."gradebook/search.php" |
|
| 350 | 350 | ) |
| 351 | 351 | ); |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | if (empty($certificatesItem) && empty($searchItem)) { |
| 355 | 355 | return null; |
| 356 | - }else{ |
|
| 357 | - $content.= $certificatesItem; |
|
| 358 | - $content.= $searchItem; |
|
| 356 | + } else { |
|
| 357 | + $content .= $certificatesItem; |
|
| 358 | + $content .= $searchItem; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | if (api_get_setting('allow_skills_tool') == 'true') { |
| 362 | 362 | |
| 363 | - $content .= Display::tag('li', Display::url(Display::return_icon('skill-badges.png',get_lang('MySkills'),null,ICON_SIZE_SMALL).get_lang('MySkills'), api_get_path(WEB_CODE_PATH).'social/my_skills_report.php')); |
|
| 363 | + $content .= Display::tag('li', Display::url(Display::return_icon('skill-badges.png', get_lang('MySkills'), null, ICON_SIZE_SMALL).get_lang('MySkills'), api_get_path(WEB_CODE_PATH).'social/my_skills_report.php')); |
|
| 364 | 364 | $allowSkillsManagement = api_get_setting('allow_hr_skills_management') == 'true'; |
| 365 | 365 | if (($allowSkillsManagement && api_is_drh()) || api_is_platform_admin()) { |
| 366 | 366 | $content .= Display::tag('li', |
| 367 | 367 | Display::url(Display::return_icon('edit-skill.png', get_lang('MySkills'), null, |
| 368 | - ICON_SIZE_SMALL) . get_lang('ManageSkills'), |
|
| 369 | - api_get_path(WEB_CODE_PATH) . 'admin/skills_wheel.php')); |
|
| 368 | + ICON_SIZE_SMALL).get_lang('ManageSkills'), |
|
| 369 | + api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php')); |
|
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | 372 | $content .= '</ul>'; |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | FROM $main_category_table t1 |
| 466 | 466 | LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id |
| 467 | 467 | LEFT JOIN $main_course_table t3 ON (t3.category_code = t1.code $platform_visible_courses) |
| 468 | - WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")." |
|
| 468 | + WHERE t1.parent_id ".(empty ($category) ? "IS NULL" : "='$category'")." |
|
| 469 | 469 | GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name"; |
| 470 | 470 | |
| 471 | 471 | // Showing only the category of courses of the current access_url_id |
@@ -542,10 +542,10 @@ discard block |
||
| 542 | 542 | } |
| 543 | 543 | $result .= $htmlTitre; |
| 544 | 544 | if ($thereIsSubCat) { |
| 545 | - $result .= $htmlListCat; |
|
| 545 | + $result .= $htmlListCat; |
|
| 546 | 546 | } |
| 547 | 547 | while ($categoryName = Database::fetch_array($resCats)) { |
| 548 | - $result .= '<h3>' . $categoryName['name'] . "</h3>\n"; |
|
| 548 | + $result .= '<h3>'.$categoryName['name']."</h3>\n"; |
|
| 549 | 549 | } |
| 550 | 550 | $numrows = Database::num_rows($sql_result_courses); |
| 551 | 551 | $courses_list_string = ''; |
@@ -643,12 +643,12 @@ discard block |
||
| 643 | 643 | if ($courses_shown > 0) { |
| 644 | 644 | // Only display the list of courses and categories if there was more than |
| 645 | 645 | // 0 courses visible to the world (we're in the anonymous list here). |
| 646 | - $result .= $courses_list_string; |
|
| 646 | + $result .= $courses_list_string; |
|
| 647 | 647 | } |
| 648 | 648 | if ($category != '') { |
| 649 | - $result .= '<p><a href="'.api_get_self().'"> ' . |
|
| 649 | + $result .= '<p><a href="'.api_get_self().'"> '. |
|
| 650 | 650 | Display :: return_icon('back.png', get_lang('BackToHomePage')). |
| 651 | - get_lang('BackToHomePage') . '</a></p>'; |
|
| 651 | + get_lang('BackToHomePage').'</a></p>'; |
|
| 652 | 652 | } |
| 653 | 653 | return $result; |
| 654 | 654 | } |
@@ -725,14 +725,14 @@ discard block |
||
| 725 | 725 | ) { |
| 726 | 726 | if (!empty($idAccordion)) { |
| 727 | 727 | $html = null; |
| 728 | - $html .= '<div class="panel-group" id="'.$idAccordion.'" role="tablist" aria-multiselectable="true">' . PHP_EOL; |
|
| 729 | - $html .= '<div class="panel panel-default" id="'.$id.'">' . PHP_EOL; |
|
| 730 | - $html .= '<div class="panel-heading" role="tab"><h4 class="panel-title">' . PHP_EOL; |
|
| 731 | - $html .= '<a role="button" data-toggle="collapse" data-parent="#'.$idAccordion.'" href="#'.$idCollapse.'" aria-expanded="true" aria-controls="'.$idCollapse.'">'.$title.'</a>' . PHP_EOL; |
|
| 732 | - $html .= '</h4></div>' . PHP_EOL; |
|
| 733 | - $html .= '<div id="'.$idCollapse.'" class="panel-collapse collapse in" role="tabpanel">' . PHP_EOL; |
|
| 734 | - $html .= '<div class="panel-body">'.$content.'</div>' . PHP_EOL; |
|
| 735 | - $html .= '</div></div></div>' . PHP_EOL; |
|
| 728 | + $html .= '<div class="panel-group" id="'.$idAccordion.'" role="tablist" aria-multiselectable="true">'.PHP_EOL; |
|
| 729 | + $html .= '<div class="panel panel-default" id="'.$id.'">'.PHP_EOL; |
|
| 730 | + $html .= '<div class="panel-heading" role="tab"><h4 class="panel-title">'.PHP_EOL; |
|
| 731 | + $html .= '<a role="button" data-toggle="collapse" data-parent="#'.$idAccordion.'" href="#'.$idCollapse.'" aria-expanded="true" aria-controls="'.$idCollapse.'">'.$title.'</a>'.PHP_EOL; |
|
| 732 | + $html .= '</h4></div>'.PHP_EOL; |
|
| 733 | + $html .= '<div id="'.$idCollapse.'" class="panel-collapse collapse in" role="tabpanel">'.PHP_EOL; |
|
| 734 | + $html .= '<div class="panel-body">'.$content.'</div>'.PHP_EOL; |
|
| 735 | + $html .= '</div></div></div>'.PHP_EOL; |
|
| 736 | 736 | |
| 737 | 737 | } else { |
| 738 | 738 | if (!empty($id)) { |
@@ -741,9 +741,9 @@ discard block |
||
| 741 | 741 | $params['class'] = 'panel panel-default'; |
| 742 | 742 | $html = null; |
| 743 | 743 | if (!empty($title)) { |
| 744 | - $html .= '<div class="panel-heading">'.$title.'</div>' . PHP_EOL; |
|
| 744 | + $html .= '<div class="panel-heading">'.$title.'</div>'.PHP_EOL; |
|
| 745 | 745 | } |
| 746 | - $html.= '<div class="panel-body">'.$content.'</div>' . PHP_EOL; |
|
| 746 | + $html .= '<div class="panel-body">'.$content.'</div>'.PHP_EOL; |
|
| 747 | 747 | $html = Display::div($html, $params); |
| 748 | 748 | } |
| 749 | 749 | return $html; |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id()); |
| 790 | 790 | $classes = ''; |
| 791 | 791 | if (!empty($usergroup_list)) { |
| 792 | - foreach($usergroup_list as $group_id) { |
|
| 792 | + foreach ($usergroup_list as $group_id) { |
|
| 793 | 793 | $data = $usergroup->get($group_id); |
| 794 | 794 | $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']); |
| 795 | 795 | $classes .= Display::tag('li', $data['name']); |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | if (api_is_platform_admin()) { |
| 799 | 799 | $classes .= Display::tag( |
| 800 | 800 | 'li', |
| 801 | - Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add') |
|
| 801 | + Display::url(get_lang('AddClasses'), api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add') |
|
| 802 | 802 | ); |
| 803 | 803 | } |
| 804 | 804 | if (!empty($classes)) { |
@@ -820,11 +820,11 @@ discard block |
||
| 820 | 820 | $content = null; |
| 821 | 821 | |
| 822 | 822 | if (api_get_setting('allow_social_tool') == 'true') { |
| 823 | - $content .= '<a style="text-align:center" href="' . api_get_path(WEB_PATH) . 'main/social/home.php"> |
|
| 824 | - <img class="img-circle" src="' . $userPicture . '" ></a>'; |
|
| 823 | + $content .= '<a style="text-align:center" href="'.api_get_path(WEB_PATH).'main/social/home.php"> |
|
| 824 | + <img class="img-circle" src="' . $userPicture.'" ></a>'; |
|
| 825 | 825 | } else { |
| 826 | - $content .= '<a style="text-align:center" href="' . api_get_path(WEB_PATH) . 'main/auth/profile.php"> |
|
| 827 | - <img class="img-circle" title="' . get_lang('EditProfile') . '" src="' . $userPicture. '" ></a>'; |
|
| 826 | + $content .= '<a style="text-align:center" href="'.api_get_path(WEB_PATH).'main/auth/profile.php"> |
|
| 827 | + <img class="img-circle" title="' . get_lang('EditProfile').'" src="'.$userPicture.'" ></a>'; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | $html = self::show_right_block( |
@@ -876,12 +876,12 @@ discard block |
||
| 876 | 876 | if (api_get_setting('allow_social_tool') == 'true') { |
| 877 | 877 | $link = '?f=social'; |
| 878 | 878 | } |
| 879 | - $profile_content .= '<li class="inbox-message-social"><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'">'.Display::return_icon('inbox.png',get_lang('Inbox'),null,ICON_SIZE_SMALL).get_lang('Inbox').$cant_msg.' </a></li>'; |
|
| 880 | - $profile_content .= '<li class="new-message-social"><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'">'.Display::return_icon('new-message.png',get_lang('Compose'),null,ICON_SIZE_SMALL).get_lang('Compose').' </a></li>'; |
|
| 879 | + $profile_content .= '<li class="inbox-message-social"><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'">'.Display::return_icon('inbox.png', get_lang('Inbox'), null, ICON_SIZE_SMALL).get_lang('Inbox').$cant_msg.' </a></li>'; |
|
| 880 | + $profile_content .= '<li class="new-message-social"><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'">'.Display::return_icon('new-message.png', get_lang('Compose'), null, ICON_SIZE_SMALL).get_lang('Compose').' </a></li>'; |
|
| 881 | 881 | |
| 882 | 882 | if (api_get_setting('allow_social_tool') == 'true') { |
| 883 | 883 | $total_invitations = Display::badge($total_invitations); |
| 884 | - $profile_content .= '<li class="invitations-social"><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.Display::return_icon('invitations.png',get_lang('PendingInvitations'),null,ICON_SIZE_SMALL).get_lang('PendingInvitations').$total_invitations.'</a></li>'; |
|
| 884 | + $profile_content .= '<li class="invitations-social"><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.Display::return_icon('invitations.png', get_lang('PendingInvitations'), null, ICON_SIZE_SMALL).get_lang('PendingInvitations').$total_invitations.'</a></li>'; |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | if (isset($_configuration['allow_my_files_link_in_homepage']) && $_configuration['allow_my_files_link_in_homepage']) { |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | |
| 898 | 898 | $editProfileUrl = Display::getProfileEditionLink($user_id); |
| 899 | 899 | |
| 900 | - $profile_content .= '<li class="profile-social"><a href="' . $editProfileUrl . '">'.Display::return_icon('edit-profile.png',get_lang('EditProfile'),null,ICON_SIZE_SMALL).get_lang('EditProfile').'</a></li>'; |
|
| 900 | + $profile_content .= '<li class="profile-social"><a href="'.$editProfileUrl.'">'.Display::return_icon('edit-profile.png', get_lang('EditProfile'), null, ICON_SIZE_SMALL).get_lang('EditProfile').'</a></li>'; |
|
| 901 | 901 | $profile_content .= '</ul>'; |
| 902 | 902 | $html = self::show_right_block( |
| 903 | 903 | get_lang('Profile'), |
@@ -972,17 +972,17 @@ discard block |
||
| 972 | 972 | if ($show_create_link) { |
| 973 | 973 | $my_account_content .= '<li class="add-course"><a href="main/create_course/add_course.php">'; |
| 974 | 974 | if (api_get_setting('course_validation') == 'true' && !api_is_platform_admin()) { |
| 975 | - $my_account_content .= Display::return_icon('new-course.png',get_lang('CreateCourseRequest'),null,ICON_SIZE_SMALL); |
|
| 975 | + $my_account_content .= Display::return_icon('new-course.png', get_lang('CreateCourseRequest'), null, ICON_SIZE_SMALL); |
|
| 976 | 976 | $my_account_content .= get_lang('CreateCourseRequest'); |
| 977 | 977 | } else { |
| 978 | - $my_account_content .= Display::return_icon('new-course.png',get_lang('CourseCreate'),null,ICON_SIZE_SMALL); |
|
| 978 | + $my_account_content .= Display::return_icon('new-course.png', get_lang('CourseCreate'), null, ICON_SIZE_SMALL); |
|
| 979 | 979 | $my_account_content .= get_lang('CourseCreate'); |
| 980 | 980 | } |
| 981 | 981 | $my_account_content .= '</a></li>'; |
| 982 | 982 | |
| 983 | 983 | if (SessionManager::allowToManageSessions()) { |
| 984 | 984 | $my_account_content .= '<li class="add-course"><a href="main/session/session_add.php">'; |
| 985 | - $my_account_content .= Display::return_icon('session.png',get_lang('AddSession'),null,ICON_SIZE_SMALL); |
|
| 985 | + $my_account_content .= Display::return_icon('session.png', get_lang('AddSession'), null, ICON_SIZE_SMALL); |
|
| 986 | 986 | $my_account_content .= get_lang('AddSession'); |
| 987 | 987 | $my_account_content .= '</a></li>'; |
| 988 | 988 | } |
@@ -990,21 +990,21 @@ discard block |
||
| 990 | 990 | |
| 991 | 991 | //Sort courses |
| 992 | 992 | $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses'; |
| 993 | - $img_order= Display::return_icon('order-course.png',get_lang('SortMyCourses'),null,ICON_SIZE_SMALL); |
|
| 993 | + $img_order = Display::return_icon('order-course.png', get_lang('SortMyCourses'), null, ICON_SIZE_SMALL); |
|
| 994 | 994 | $my_account_content .= '<li class="order-course">'.Display::url($img_order.get_lang('SortMyCourses'), $url, array('class' => 'sort course')).'</li>'; |
| 995 | 995 | |
| 996 | 996 | // Session history |
| 997 | 997 | if (isset($_GET['history']) && intval($_GET['history']) == 1) { |
| 998 | - $my_account_content .= '<li class="history-course"><a href="user_portal.php">'.Display::return_icon('history-course.png',get_lang('DisplayTrainingList'),null,ICON_SIZE_SMALL).get_lang('DisplayTrainingList').'</a></li>'; |
|
| 998 | + $my_account_content .= '<li class="history-course"><a href="user_portal.php">'.Display::return_icon('history-course.png', get_lang('DisplayTrainingList'), null, ICON_SIZE_SMALL).get_lang('DisplayTrainingList').'</a></li>'; |
|
| 999 | 999 | } else { |
| 1000 | - $my_account_content .= '<li class="history-course"><a href="user_portal.php?history=1" >'.Display::return_icon('history-course.png',get_lang('HistoryTrainingSessions'),null,ICON_SIZE_SMALL).get_lang('HistoryTrainingSessions').'</a></li>'; |
|
| 1000 | + $my_account_content .= '<li class="history-course"><a href="user_portal.php?history=1" >'.Display::return_icon('history-course.png', get_lang('HistoryTrainingSessions'), null, ICON_SIZE_SMALL).get_lang('HistoryTrainingSessions').'</a></li>'; |
|
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | // Course catalog |
| 1004 | 1004 | |
| 1005 | 1005 | if ($show_course_link) { |
| 1006 | 1006 | if (!api_is_drh()) { |
| 1007 | - $my_account_content .= '<li class="list-course"><a href="main/auth/courses.php" >'.Display::return_icon('catalog-course.png',get_lang('CourseCatalog'),null,ICON_SIZE_SMALL).get_lang('CourseCatalog').'</a></li>'; |
|
| 1007 | + $my_account_content .= '<li class="list-course"><a href="main/auth/courses.php" >'.Display::return_icon('catalog-course.png', get_lang('CourseCatalog'), null, ICON_SIZE_SMALL).get_lang('CourseCatalog').'</a></li>'; |
|
| 1008 | 1008 | } else { |
| 1009 | 1009 | $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>'; |
| 1010 | 1010 | } |
@@ -1183,10 +1183,10 @@ discard block |
||
| 1183 | 1183 | |
| 1184 | 1184 | $extra_info = !empty($session_box['coach']) ? $session_box['coach'] : null; |
| 1185 | 1185 | $extra_info .= !empty($session_box['coach']) |
| 1186 | - ? ' - ' . $session_box['dates'] |
|
| 1186 | + ? ' - '.$session_box['dates'] |
|
| 1187 | 1187 | : $session_box['dates']; |
| 1188 | 1188 | $extra_info .= isset($session_box['duration']) |
| 1189 | - ? ' ' . $session_box['duration'] |
|
| 1189 | + ? ' '.$session_box['duration'] |
|
| 1190 | 1190 | : null; |
| 1191 | 1191 | |
| 1192 | 1192 | $params['extra_fields'] = $session_box['extra_fields']; |
@@ -1308,8 +1308,8 @@ discard block |
||
| 1308 | 1308 | $sessionParams['course_list_session_style'] = $coursesListSessionStyle; |
| 1309 | 1309 | $sessionParams['title'] = $session_box['title']; |
| 1310 | 1310 | $sessionParams['subtitle'] = (!empty($session_box['coach']) |
| 1311 | - ? $session_box['coach'] . ' | ' |
|
| 1312 | - : '') . $session_box['dates']; |
|
| 1311 | + ? $session_box['coach'].' | ' |
|
| 1312 | + : '').$session_box['dates']; |
|
| 1313 | 1313 | $sessionParams['show_actions'] = api_is_platform_admin(); |
| 1314 | 1314 | $sessionParams['courses'] = $html_courses_session; |
| 1315 | 1315 | $sessionParams['show_simple_session_info'] = false; |
@@ -1359,14 +1359,14 @@ discard block |
||
| 1359 | 1359 | !empty($session_category_start_date) && |
| 1360 | 1360 | $session_category_start_date != '0000-00-00' |
| 1361 | 1361 | ) { |
| 1362 | - $categoryParams['subtitle'] = get_lang('From') . ' ' . $session_category_start_date; |
|
| 1362 | + $categoryParams['subtitle'] = get_lang('From').' '.$session_category_start_date; |
|
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | 1365 | if ( |
| 1366 | 1366 | !empty($session_category_end_date) && |
| 1367 | 1367 | $session_category_end_date != '0000-00-00' |
| 1368 | 1368 | ) { |
| 1369 | - $categoryParams['subtitle'] = get_lang('Until') . ' ' . $session_category_end_date; |
|
| 1369 | + $categoryParams['subtitle'] = get_lang('Until').' '.$session_category_end_date; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | } |
| 1372 | 1372 | |
@@ -1440,7 +1440,7 @@ discard block |
||
| 1440 | 1440 | if ($load_history) { |
| 1441 | 1441 | $html .= Display::page_subheader(get_lang('HistoryTrainingSession')); |
| 1442 | 1442 | if (empty($session_categories)) { |
| 1443 | - $html .= get_lang('YouDoNotHaveAnySessionInItsHistory'); |
|
| 1443 | + $html .= get_lang('YouDoNotHaveAnySessionInItsHistory'); |
|
| 1444 | 1444 | } |
| 1445 | 1445 | } |
| 1446 | 1446 | |
@@ -1513,7 +1513,7 @@ discard block |
||
| 1513 | 1513 | } else { |
| 1514 | 1514 | $htmlCategory .= '<div class="session-view-row" >'; |
| 1515 | 1515 | } |
| 1516 | - $coursesInfo = $listCourse['course']; |
|
| 1516 | + $coursesInfo = $listCourse['course']; |
|
| 1517 | 1517 | |
| 1518 | 1518 | $htmlCategory .= self::getHtmlForCourse( |
| 1519 | 1519 | $coursesInfo, |
@@ -1530,7 +1530,7 @@ discard block |
||
| 1530 | 1530 | $listCategorySession['catSessionName'] |
| 1531 | 1531 | ); |
| 1532 | 1532 | // list of session |
| 1533 | - $htmlSession = ''; // start |
|
| 1533 | + $htmlSession = ''; // start |
|
| 1534 | 1534 | foreach ($listCategorySession['sessionList'] as $k => $listSession) { |
| 1535 | 1535 | // add session |
| 1536 | 1536 | $htmlSession .= '<div class="session-view-row">'; |
@@ -1547,8 +1547,8 @@ discard block |
||
| 1547 | 1547 | $htmlSessionCategory .= $htmlSession; |
| 1548 | 1548 | } |
| 1549 | 1549 | $htmlSessionCategory .= '</div>'; // end session cat block |
| 1550 | - $htmlCategory .= $htmlSessionCategory .'</div>' ; |
|
| 1551 | - $htmlCategory .= ''; // end course block |
|
| 1550 | + $htmlCategory .= $htmlSessionCategory.'</div>'; |
|
| 1551 | + $htmlCategory .= ''; // end course block |
|
| 1552 | 1552 | } |
| 1553 | 1553 | $userCategoryHtml .= $htmlCategory; |
| 1554 | 1554 | } |
@@ -1573,11 +1573,11 @@ discard block |
||
| 1573 | 1573 | } |
| 1574 | 1574 | } |
| 1575 | 1575 | $htmlCategory .= ''; |
| 1576 | - $userCategoryHtml .= $htmlCategory; // end user cat block |
|
| 1576 | + $userCategoryHtml .= $htmlCategory; // end user cat block |
|
| 1577 | 1577 | if ($userCategoryId != 0) { |
| 1578 | 1578 | $userCategoryHtml .= '</div>'; |
| 1579 | 1579 | } |
| 1580 | - $html .= $userCategoryHtml; // |
|
| 1580 | + $html .= $userCategoryHtml; // |
|
| 1581 | 1581 | } |
| 1582 | 1582 | $html .= '</div>'; |
| 1583 | 1583 | |
@@ -1718,11 +1718,11 @@ discard block |
||
| 1718 | 1718 | $html = ''; |
| 1719 | 1719 | |
| 1720 | 1720 | if ($categorySessionId == 0) { |
| 1721 | - $class1 = 'session-view-lvl-2'; // session |
|
| 1722 | - $class2 = 'session-view-lvl-4'; // got to course in session link |
|
| 1721 | + $class1 = 'session-view-lvl-2'; // session |
|
| 1722 | + $class2 = 'session-view-lvl-4'; // got to course in session link |
|
| 1723 | 1723 | } else { |
| 1724 | - $class1 = 'session-view-lvl-3'; // session |
|
| 1725 | - $class2 = 'session-view-lvl-5'; // got to course in session link |
|
| 1724 | + $class1 = 'session-view-lvl-3'; // session |
|
| 1725 | + $class2 = 'session-view-lvl-5'; // got to course in session link |
|
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | 1728 | $icon = Display::return_icon( |
@@ -1750,7 +1750,7 @@ discard block |
||
| 1750 | 1750 | if ($listA['userCatTitle'] == $listB['userCatTitle']) { |
| 1751 | 1751 | if ($listA['title'] == $listB['title']) { |
| 1752 | 1752 | return 0; |
| 1753 | - } else if($listA['title'] > $listB['title']) { |
|
| 1753 | + } else if ($listA['title'] > $listB['title']) { |
|
| 1754 | 1754 | return 1; |
| 1755 | 1755 | } else { |
| 1756 | 1756 | return -1; |
@@ -1771,7 +1771,7 @@ discard block |
||
| 1771 | 1771 | { |
| 1772 | 1772 | if ($listA['title'] == $listB['title']) { |
| 1773 | 1773 | return 0; |
| 1774 | - } else if($listA['title'] > $listB['title']) { |
|
| 1774 | + } else if ($listA['title'] > $listB['title']) { |
|
| 1775 | 1775 | return 1; |
| 1776 | 1776 | } else { |
| 1777 | 1777 | return -1; |