Completed
Push — 1.10.x ( c135db...ea3352 )
by Julito
26:21
created
main/inc/lib/xajax/xajax.inc.php 4 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 	 * Returns the current request mode (XAJAX_GET or XAJAX_POST), or -1 if
501 501
 	 * there is none.
502 502
 	 *
503
-	 * @return mixed
503
+	 * @return integer
504 504
 	 */
505 505
 	function getRequestMode()
506 506
 	{
@@ -1018,6 +1018,7 @@  discard block
 block discarded – undo
1018 1018
 	 *
1019 1019
 	 * @param string the root tag of the XML
1020 1020
 	 * @param string XML to convert
1021
+	 * @param string $rootTag
1021 1022
 	 * @access private
1022 1023
 	 * @return array
1023 1024
 	 */
Please login to merge, or discard this patch.
Braces   +84 added lines, -86 removed lines patch added patch discarded remove patch
@@ -173,8 +173,9 @@  discard block
 block discarded – undo
173 173
 		$this->aObjects = array();
174 174
 		$this->aFunctionIncludeFiles = array();
175 175
 		$this->sRequestURI = $sRequestURI;
176
-		if ($this->sRequestURI == "")
177
-			$this->sRequestURI = $this->_detectURI();
176
+		if ($this->sRequestURI == "") {
177
+					$this->sRequestURI = $this->_detectURI();
178
+		}
178 179
 		$this->sWrapperPrefix = $sWrapperPrefix;
179 180
 		$this->bDebug = $bDebug;
180 181
 		$this->bStatusMessages = false;
@@ -399,8 +400,7 @@  discard block
 block discarded – undo
399 400
 			$this->aFunctions[$mFunction[0]] = 1;
400 401
 			$this->aFunctionRequestTypes[$mFunction[0]] = $sRequestType;
401 402
 			$this->aObjects[$mFunction[0]] = array_slice($mFunction, 1);
402
-		}
403
-		else {
403
+		} else {
404 404
 			$this->aFunctions[$mFunction] = 1;
405 405
 			$this->aFunctionRequestTypes[$mFunction] = $sRequestType;
406 406
 		}
@@ -426,8 +426,7 @@  discard block
 block discarded – undo
426 426
 
427 427
 		if (is_array($mFunction)) {
428 428
 			$this->aFunctionIncludeFiles[$mFunction[0]] = $sIncludeFile;
429
-		}
430
-		else {
429
+		} else {
431 430
 			$this->aFunctionIncludeFiles[$mFunction] = $sIncludeFile;
432 431
 		}
433 432
 	}
@@ -451,8 +450,7 @@  discard block
 block discarded – undo
451 450
 		if (is_array($mFunction)) {
452 451
 			$this->sCatchAllFunction = $mFunction[0];
453 452
 			$this->aObjects[$mFunction[0]] = array_slice($mFunction, 1);
454
-		}
455
-		else {
453
+		} else {
456 454
 			$this->sCatchAllFunction = $mFunction;
457 455
 		}
458 456
 	}
@@ -477,8 +475,7 @@  discard block
 block discarded – undo
477 475
 		if (is_array($mFunction)) {
478 476
 			$this->sPreFunction = $mFunction[0];
479 477
 			$this->aObjects[$mFunction[0]] = array_slice($mFunction, 1);
480
-		}
481
-		else {
478
+		} else {
482 479
 			$this->sPreFunction = $mFunction;
483 480
 		}
484 481
 	}
@@ -492,7 +489,9 @@  discard block
 block discarded – undo
492 489
 	 */
493 490
 	function canProcessRequests()
494 491
 	{
495
-		if ($this->getRequestMode() != -1) return true;
492
+		if ($this->getRequestMode() != -1) {
493
+		    return true;
494
+		}
496 495
 		return false;
497 496
 	}
498 497
 
@@ -504,11 +503,13 @@  discard block
 block discarded – undo
504 503
 	 */
505 504
 	function getRequestMode()
506 505
 	{
507
-		if (!empty($_GET["xajax"]))
508
-			return XAJAX_GET;
506
+		if (!empty($_GET["xajax"])) {
507
+					return XAJAX_GET;
508
+		}
509 509
 
510
-		if (!empty($_POST["xajax"]))
511
-			return XAJAX_POST;
510
+		if (!empty($_POST["xajax"])) {
511
+					return XAJAX_POST;
512
+		}
512 513
 
513 514
 		return -1;
514 515
 	}
@@ -535,16 +536,18 @@  discard block
 block discarded – undo
535 536
 		$sResponse = "";
536 537
 
537 538
 		$requestMode = $this->getRequestMode();
538
-		if ($requestMode == -1) return;
539
+		if ($requestMode == -1) {
540
+		    return;
541
+		}
539 542
 
540 543
 		if ($requestMode == XAJAX_POST)
541 544
 		{
542 545
 			$sFunctionName = $_POST["xajax"];
543 546
 
544
-			if (!empty($_POST["xajaxargs"]))
545
-				$aArgs = $_POST["xajaxargs"];
546
-		}
547
-		else
547
+			if (!empty($_POST["xajaxargs"])) {
548
+							$aArgs = $_POST["xajaxargs"];
549
+			}
550
+		} else
548 551
 		{
549 552
 			header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
550 553
 			header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
@@ -553,8 +556,9 @@  discard block
 block discarded – undo
553 556
 
554 557
 			$sFunctionName = $_GET["xajax"];
555 558
 
556
-			if (!empty($_GET["xajaxargs"]))
557
-				$aArgs = $_GET["xajaxargs"];
559
+			if (!empty($_GET["xajaxargs"])) {
560
+							$aArgs = $_GET["xajaxargs"];
561
+			}
558 562
 		}
559 563
 
560 564
 		// Use xajax error handler if necessary
@@ -586,15 +590,13 @@  discard block
 block discarded – undo
586 590
 				if ($this->sCatchAllFunction) {
587 591
 					$sFunctionName = $this->sCatchAllFunction;
588 592
 					$bFunctionIsCatchAll = true;
589
-				}
590
-				else {
593
+				} else {
591 594
 					$bFoundFunction = false;
592 595
 					$objResponse = new xajaxResponse();
593 596
 					$objResponse->addAlert("Unknown Function $sFunctionName.");
594 597
 					$sResponse = $objResponse->getXML();
595 598
 				}
596
-			}
597
-			else if ($this->aFunctionRequestTypes[$sFunctionName] != $requestMode)
599
+			} else if ($this->aFunctionRequestTypes[$sFunctionName] != $requestMode)
598 600
 			{
599 601
 				$bFoundFunction = false;
600 602
 				$objResponse = new xajaxResponse();
@@ -615,12 +617,10 @@  discard block
 block discarded – undo
615 617
 				if (stristr($aArgs[$i],"<xjxobj>") != false)
616 618
 				{
617 619
 					$aArgs[$i] = $this->_xmlToArray("xjxobj",$aArgs[$i]);
618
-				}
619
-				else if (stristr($aArgs[$i],"<xjxquery>") != false)
620
+				} else if (stristr($aArgs[$i],"<xjxquery>") != false)
620 621
 				{
621 622
 					$aArgs[$i] = $this->_xmlToArray("xjxquery",$aArgs[$i]);
622
-				}
623
-				else if ($this->bDecodeUTF8Input)
623
+				} else if ($this->bDecodeUTF8Input)
624 624
 				{
625 625
 					$aArgs[$i] = $this->_decodeUTF8Data($aArgs[$i]);
626 626
 				}
@@ -631,14 +631,15 @@  discard block
 block discarded – undo
631 631
 				if (is_array($mPreResponse) && $mPreResponse[0] === false) {
632 632
 					$bEndRequest = true;
633 633
 					$sPreResponse = $mPreResponse[1];
634
-				}
635
-				else {
634
+				} else {
636 635
 					$sPreResponse = $mPreResponse;
637 636
 				}
638 637
 				if (is_a($sPreResponse, "xajaxResponse")) {
639 638
 					$sPreResponse = $sPreResponse->getXML();
640 639
 				}
641
-				if ($bEndRequest) $sResponse = $sPreResponse;
640
+				if ($bEndRequest) {
641
+				    $sResponse = $sPreResponse;
642
+				}
642 643
 			}
643 644
 
644 645
 			if (!$bEndRequest) {
@@ -646,8 +647,7 @@  discard block
 block discarded – undo
646 647
 					$objResponse = new xajaxResponse();
647 648
 					$objResponse->addAlert("The Registered Function $sFunctionName Could Not Be Found.");
648 649
 					$sResponse = $objResponse->getXML();
649
-				}
650
-				else {
650
+				} else {
651 651
 					if ($bFunctionIsCatchAll) {
652 652
 						$aArgs = array($sFunctionNameForSpecial, $aArgs);
653 653
 					}
@@ -660,8 +660,7 @@  discard block
 block discarded – undo
660 660
 					$objResponse = new xajaxResponse();
661 661
 					$objResponse->addAlert("No XML Response Was Returned By Function $sFunctionName.");
662 662
 					$sResponse = $objResponse->getXML();
663
-				}
664
-				else if ($sPreResponse != "") {
663
+				} else if ($sPreResponse != "") {
665 664
 					$sNewResponse = new xajaxResponse($this->sEncoding, $this->bOutputEntities);
666 665
 					$sNewResponse->loadXML($sPreResponse);
667 666
 					$sNewResponse->loadXML($sResponse);
@@ -671,8 +670,9 @@  discard block
 block discarded – undo
671 670
 		}
672 671
 
673 672
 		$sContentHeader = "Content-type: text/xml;";
674
-		if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0)
675
-			$sContentHeader .= " charset=".$this->sEncoding;
673
+		if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0) {
674
+					$sContentHeader .= " charset=".$this->sEncoding;
675
+		}
676 676
 		header($sContentHeader);
677 677
 		if ($this->bErrorHandler && !empty( $GLOBALS['xajaxErrorHandlerText'] )) {
678 678
 			$sErrorResponse = new xajaxResponse();
@@ -681,8 +681,7 @@  discard block
 block discarded – undo
681 681
 				$fH = @fopen($this->sLogFile, "a");
682 682
 				if (!$fH) {
683 683
 					$sErrorResponse->addAlert("** Logging Error **\n\nxajax was unable to write to the error log file:\n" . $this->sLogFile);
684
-				}
685
-				else {
684
+				} else {
686 685
 					fwrite($fH, "** xajax Error Log - " . strftime("%b %e %Y %I:%M:%S %p") . " **" . $GLOBALS['xajaxErrorHandlerText'] . "\n\n\n");
687 686
 					fclose($fH);
688 687
 				}
@@ -692,12 +691,17 @@  discard block
 block discarded – undo
692 691
 			$sResponse = $sErrorResponse->getXML();
693 692
 
694 693
 		}
695
-		if ($this->bCleanBuffer) while (@ob_end_clean());
694
+		if ($this->bCleanBuffer) {
695
+		    while (@ob_end_clean());
696
+		}
696 697
 		print $sResponse;
697
-		if ($this->bErrorHandler) restore_error_handler();
698
+		if ($this->bErrorHandler) {
699
+		    restore_error_handler();
700
+		}
698 701
 
699
-		if ($this->bExitAllowed)
700
-			exit();
702
+		if ($this->bExitAllowed) {
703
+					exit();
704
+		}
701 705
 	}
702 706
 
703 707
 	/**
@@ -806,9 +810,13 @@  discard block
 block discarded – undo
806 810
 	 */
807 811
 	function getJavascriptInclude($sJsURI="", $sJsFile=NULL)
808 812
 	{
809
-		if ($sJsFile == NULL) $sJsFile = "xajax_js/xajax.js";
813
+		if ($sJsFile == NULL) {
814
+		    $sJsFile = "xajax_js/xajax.js";
815
+		}
810 816
 
811
-		if ($sJsURI != "" && substr($sJsURI, -1) != "/") $sJsURI .= "/";
817
+		if ($sJsURI != "" && substr($sJsURI, -1) != "/") {
818
+		    $sJsURI .= "/";
819
+		}
812 820
 
813 821
 		$html = "\t<script type=\"text/javascript\" src=\"" . $sJsURI . $sJsFile . "\"></script>\n";
814 822
 		$html .= "\t<script type=\"text/javascript\">\n";
@@ -831,8 +839,7 @@  discard block
 block discarded – undo
831 839
 
832 840
 		if ($sJsFullFilename) {
833 841
 			$realJsFile = $sJsFullFilename;
834
-		}
835
-		else {
842
+		} else {
836 843
 			$realPath = realpath(dirname(__FILE__));
837 844
 			$realJsFile = $realPath . "/". $sJsFile;
838 845
 		}
@@ -849,8 +856,7 @@  discard block
 block discarded – undo
849 856
 			$fH = @fopen($realJsFile, "w");
850 857
 			if (!$fH) {
851 858
 				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 {
859
+			} else {
854 860
 				fwrite($fH, $compressedScript);
855 861
 				fclose($fH);
856 862
 			}
@@ -950,7 +956,9 @@  discard block
 block discarded – undo
950 956
 	 */
951 957
 	function _isObjectCallback($sFunction)
952 958
 	{
953
-		if (array_key_exists($sFunction, $this->aObjects)) return true;
959
+		if (array_key_exists($sFunction, $this->aObjects)) {
960
+		    return true;
961
+		}
954 962
 		return false;
955 963
 	}
956 964
 
@@ -967,12 +975,10 @@  discard block
 block discarded – undo
967 975
 		if ($this->_isObjectCallback($sFunction)) {
968 976
 			if (is_object($this->aObjects[$sFunction][0])) {
969 977
 				return method_exists($this->aObjects[$sFunction][0], $this->aObjects[$sFunction][1]);
970
-			}
971
-			else {
978
+			} else {
972 979
 				return is_callable($this->aObjects[$sFunction]);
973 980
 			}
974
-		}
975
-		else {
981
+		} else {
976 982
 			return function_exists($sFunction);
977 983
 		}
978 984
 	}
@@ -990,8 +996,7 @@  discard block
 block discarded – undo
990 996
 	{
991 997
 		if ($this->_isObjectCallback($sFunction)) {
992 998
 			$mReturn = call_user_func_array($this->aObjects[$sFunction], $aArgs);
993
-		}
994
-		else {
999
+		} else {
995 1000
 			$mReturn = call_user_func_array($sFunction, $aArgs);
996 1001
 		}
997 1002
 		return $mReturn;
@@ -1086,8 +1091,7 @@  discard block
 block discarded – undo
1086 1091
 								{
1087 1092
 									$value = $this->_parseObjXml("xjxobj");
1088 1093
 									$this->iPos++;
1089
-								}
1090
-								else
1094
+								} else
1091 1095
 								{
1092 1096
 									$value .= $this->aObjArray[$this->iPos];
1093 1097
 									if ($this->bDecodeUTF8Input)
@@ -1134,10 +1138,11 @@  discard block
 block discarded – undo
1134 1138
 			if (get_magic_quotes_gpc() == 1) {
1135 1139
 				$newArray = array();
1136 1140
 				foreach ($aArray as $sKey => $sValue) {
1137
-					if (is_string($sValue))
1138
-						$newArray[$sKey] = stripslashes($sValue);
1139
-					else
1140
-						$newArray[$sKey] = $sValue;
1141
+					if (is_string($sValue)) {
1142
+											$newArray[$sKey] = stripslashes($sValue);
1143
+					} else {
1144
+											$newArray[$sKey] = $sValue;
1145
+					}
1141 1146
 				}
1142 1147
 				$aArray = $newArray;
1143 1148
 			}
@@ -1166,20 +1171,18 @@  discard block
 block discarded – undo
1166 1171
 				$sFuncToUse = "api_convert_encoding";
1167 1172
 			}
1168 1173
 			//if (function_exists('iconv'))
1169
-			elseif (function_exists('iconv'))
1170
-			//
1174
+			elseif (function_exists('iconv')) {
1175
+						//
1171 1176
 			{
1172 1177
 				$sFuncToUse = "iconv";
1173 1178
 			}
1174
-			else if (function_exists('mb_convert_encoding'))
1179
+			} else if (function_exists('mb_convert_encoding'))
1175 1180
 			{
1176 1181
 				$sFuncToUse = "mb_convert_encoding";
1177
-			}
1178
-			else if ($this->sEncoding == "ISO-8859-1")
1182
+			} else if ($this->sEncoding == "ISO-8859-1")
1179 1183
 			{
1180 1184
 				$sFuncToUse = "utf8_decode";
1181
-			}
1182
-			else
1185
+			} else
1183 1186
 			{
1184 1187
 				trigger_error("The incoming xajax data could not be converted from UTF-8", E_USER_NOTICE);
1185 1188
 			}
@@ -1191,8 +1194,7 @@  discard block
 block discarded – undo
1191 1194
 					if ($sFuncToUse == "iconv")
1192 1195
 					{
1193 1196
 						$sValue = iconv("UTF-8", $this->sEncoding.'//TRANSLIT', $sValue);
1194
-					}
1195
-					else if ($sFuncToUse == "mb_convert_encoding")
1197
+					} else if ($sFuncToUse == "mb_convert_encoding")
1196 1198
 					{
1197 1199
 						$sValue = mb_convert_encoding($sValue, $this->sEncoding, "UTF-8");
1198 1200
 					}
@@ -1221,27 +1223,23 @@  discard block
 block discarded – undo
1221 1223
 function xajaxErrorHandler($errno, $errstr, $errfile, $errline)
1222 1224
 {
1223 1225
 	$errorReporting = error_reporting();
1224
-	if (($errno & $errorReporting) == 0) return;
1226
+	if (($errno & $errorReporting) == 0) {
1227
+	    return;
1228
+	}
1225 1229
 
1226 1230
 	if ($errno == E_NOTICE) {
1227 1231
 		$errTypeStr = "NOTICE";
1228
-	}
1229
-	else if ($errno == E_WARNING) {
1232
+	} else if ($errno == E_WARNING) {
1230 1233
 		$errTypeStr = "WARNING";
1231
-	}
1232
-	else if ($errno == E_USER_NOTICE) {
1234
+	} else if ($errno == E_USER_NOTICE) {
1233 1235
 		$errTypeStr = "USER NOTICE";
1234
-	}
1235
-	else if ($errno == E_USER_WARNING) {
1236
+	} else if ($errno == E_USER_WARNING) {
1236 1237
 		$errTypeStr = "USER WARNING";
1237
-	}
1238
-	else if ($errno == E_USER_ERROR) {
1238
+	} else if ($errno == E_USER_ERROR) {
1239 1239
 		$errTypeStr = "USER FATAL ERROR";
1240
-	}
1241
-	else if ($errno == E_STRICT) {
1240
+	} else if ($errno == E_STRICT) {
1242 1241
 		return;
1243
-	}
1244
-	else {
1242
+	} else {
1245 1243
 		$errTypeStr = "UNKNOWN: $errno";
1246 1244
 	}
1247 1245
 	$GLOBALS['xajaxErrorHandlerText'] .= "\n----\n[$errTypeStr] $errstr\nerror in line $errline of file $errfile";
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 				}
Please login to merge, or discard this patch.
Indentation   +1165 added lines, -1165 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 ?>
Please login to merge, or discard this patch.
main/inc/lib/xajax/xajaxCompress.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -39,6 +39,7 @@
 block discarded – undo
39 39
  * (used internally)
40 40
  *
41 41
  * @param string contains the Javascript code to compress
42
+ * @param string $sJS
42 43
  */
43 44
 function xajaxCompressJavascript($sJS)
44 45
 {
Please login to merge, or discard this patch.
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -42,141 +42,141 @@
 block discarded – undo
42 42
  */
43 43
 function xajaxCompressJavascript($sJS)
44 44
 {
45
-	//remove windows cariage returns
46
-	$sJS = str_replace("\r","",$sJS);
47
-
48
-	//array to store replaced literal strings
49
-	$literal_strings = array();
50
-
51
-	//explode the string into lines
52
-	$lines = explode("\n",$sJS);
53
-	//loop through all the lines, building a new string at the same time as removing literal strings
54
-	$clean = "";
55
-	$inComment = false;
56
-	$literal = "";
57
-	$inQuote = false;
58
-	$escaped = false;
59
-	$quoteChar = "";
60
-
61
-	for($i=0;$i<count($lines);$i++)
62
-	{
63
-		$line = $lines[$i];
64
-		$inNormalComment = false;
65
-
66
-		//loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
67
-		for($j=0;$j<strlen($line);$j++)
68
-		{
69
-			$c = substr($line,$j,1);
70
-			$d = substr($line,$j,2);
71
-
72
-			//look for start of quote
73
-			if(!$inQuote && !$inComment)
74
-			{
75
-				//is this character a quote or a comment
76
-				if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
77
-				{
78
-					$inQuote = true;
79
-					$inComment = false;
80
-					$escaped = false;
81
-					$quoteChar = $c;
82
-					$literal = $c;
83
-				}
84
-				else if($d=="/*" && !$inNormalComment)
85
-				{
86
-					$inQuote = false;
87
-					$inComment = true;
88
-					$escaped = false;
89
-					$quoteChar = $d;
90
-					$literal = $d;
91
-					$j++;
92
-				}
93
-				else if($d=="//") //ignore string markers that are found inside comments
94
-				{
95
-					$inNormalComment = true;
96
-					$clean .= $c;
97
-				}
98
-				else
99
-				{
100
-					$clean .= $c;
101
-				}
102
-			}
103
-			else //allready in a string so find end quote
104
-			{
105
-				if($c == $quoteChar && !$escaped && !$inComment)
106
-				{
107
-					$inQuote = false;
108
-					$literal .= $c;
109
-
110
-					//subsitute in a marker for the string
111
-					$clean .= "___" . count($literal_strings) . "___";
112
-
113
-					//push the string onto our array
114
-					array_push($literal_strings,$literal);
115
-
116
-				}
117
-				else if($inComment && $d=="*/")
118
-				{
119
-					$inComment = false;
120
-					$literal .= $d;
121
-
122
-					//subsitute in a marker for the string
123
-					$clean .= "___" . count($literal_strings) . "___";
124
-
125
-					//push the string onto our array
126
-					array_push($literal_strings,$literal);
127
-
128
-					$j++;
129
-				}
130
-				else if($c == "\\" && !$escaped)
131
-					$escaped = true;
132
-				else
133
-					$escaped = false;
134
-
135
-				$literal .= $c;
136
-			}
137
-		}
138
-		if($inComment) $literal .= "\n";
139
-		$clean .= "\n";
140
-	}
141
-	//explode the clean string into lines again
142
-	$lines = explode("\n",$clean);
143
-
144
-	//now process each line at a time
145
-	for($i=0;$i<count($lines);$i++)
146
-	{
147
-		$line = $lines[$i];
148
-
149
-		//remove comments
150
-		$line = preg_replace("/\/\/(.*)/","",$line);
151
-
152
-		//strip leading and trailing whitespace
153
-		$line = trim($line);
154
-
155
-		//remove all whitespace with a single space
156
-		$line = preg_replace("/\s+/"," ",$line);
157
-
158
-		//remove any whitespace that occurs after/before an operator
159
-		$line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
160
-
161
-		$lines[$i] = $line;
162
-	}
163
-
164
-	//implode the lines
165
-	$sJS = implode("\n",$lines);
166
-
167
-	//make sure there is a max of 1 \n after each line
168
-	$sJS = preg_replace("/[\n]+/","\n",$sJS);
169
-
170
-	//strip out line breaks that immediately follow a semi-colon
171
-	$sJS = preg_replace("/;\n/",";",$sJS);
172
-
173
-	//curly brackets aren't on their own
174
-	$sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
175
-
176
-	//finally loop through and replace all the literal strings:
177
-	for($i=0;$i<count($literal_strings);$i++)
178
-		$sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
179
-
180
-	return $sJS;
45
+    //remove windows cariage returns
46
+    $sJS = str_replace("\r","",$sJS);
47
+
48
+    //array to store replaced literal strings
49
+    $literal_strings = array();
50
+
51
+    //explode the string into lines
52
+    $lines = explode("\n",$sJS);
53
+    //loop through all the lines, building a new string at the same time as removing literal strings
54
+    $clean = "";
55
+    $inComment = false;
56
+    $literal = "";
57
+    $inQuote = false;
58
+    $escaped = false;
59
+    $quoteChar = "";
60
+
61
+    for($i=0;$i<count($lines);$i++)
62
+    {
63
+        $line = $lines[$i];
64
+        $inNormalComment = false;
65
+
66
+        //loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
67
+        for($j=0;$j<strlen($line);$j++)
68
+        {
69
+            $c = substr($line,$j,1);
70
+            $d = substr($line,$j,2);
71
+
72
+            //look for start of quote
73
+            if(!$inQuote && !$inComment)
74
+            {
75
+                //is this character a quote or a comment
76
+                if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
77
+                {
78
+                    $inQuote = true;
79
+                    $inComment = false;
80
+                    $escaped = false;
81
+                    $quoteChar = $c;
82
+                    $literal = $c;
83
+                }
84
+                else if($d=="/*" && !$inNormalComment)
85
+                {
86
+                    $inQuote = false;
87
+                    $inComment = true;
88
+                    $escaped = false;
89
+                    $quoteChar = $d;
90
+                    $literal = $d;
91
+                    $j++;
92
+                }
93
+                else if($d=="//") //ignore string markers that are found inside comments
94
+                {
95
+                    $inNormalComment = true;
96
+                    $clean .= $c;
97
+                }
98
+                else
99
+                {
100
+                    $clean .= $c;
101
+                }
102
+            }
103
+            else //allready in a string so find end quote
104
+            {
105
+                if($c == $quoteChar && !$escaped && !$inComment)
106
+                {
107
+                    $inQuote = false;
108
+                    $literal .= $c;
109
+
110
+                    //subsitute in a marker for the string
111
+                    $clean .= "___" . count($literal_strings) . "___";
112
+
113
+                    //push the string onto our array
114
+                    array_push($literal_strings,$literal);
115
+
116
+                }
117
+                else if($inComment && $d=="*/")
118
+                {
119
+                    $inComment = false;
120
+                    $literal .= $d;
121
+
122
+                    //subsitute in a marker for the string
123
+                    $clean .= "___" . count($literal_strings) . "___";
124
+
125
+                    //push the string onto our array
126
+                    array_push($literal_strings,$literal);
127
+
128
+                    $j++;
129
+                }
130
+                else if($c == "\\" && !$escaped)
131
+                    $escaped = true;
132
+                else
133
+                    $escaped = false;
134
+
135
+                $literal .= $c;
136
+            }
137
+        }
138
+        if($inComment) $literal .= "\n";
139
+        $clean .= "\n";
140
+    }
141
+    //explode the clean string into lines again
142
+    $lines = explode("\n",$clean);
143
+
144
+    //now process each line at a time
145
+    for($i=0;$i<count($lines);$i++)
146
+    {
147
+        $line = $lines[$i];
148
+
149
+        //remove comments
150
+        $line = preg_replace("/\/\/(.*)/","",$line);
151
+
152
+        //strip leading and trailing whitespace
153
+        $line = trim($line);
154
+
155
+        //remove all whitespace with a single space
156
+        $line = preg_replace("/\s+/"," ",$line);
157
+
158
+        //remove any whitespace that occurs after/before an operator
159
+        $line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
160
+
161
+        $lines[$i] = $line;
162
+    }
163
+
164
+    //implode the lines
165
+    $sJS = implode("\n",$lines);
166
+
167
+    //make sure there is a max of 1 \n after each line
168
+    $sJS = preg_replace("/[\n]+/","\n",$sJS);
169
+
170
+    //strip out line breaks that immediately follow a semi-colon
171
+    $sJS = preg_replace("/;\n/",";",$sJS);
172
+
173
+    //curly brackets aren't on their own
174
+    $sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
175
+
176
+    //finally loop through and replace all the literal strings:
177
+    for($i=0;$i<count($literal_strings);$i++)
178
+        $sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
179
+
180
+    return $sJS;
181 181
 }
182 182
 ?>
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
 function xajaxCompressJavascript($sJS)
44 44
 {
45 45
 	//remove windows cariage returns
46
-	$sJS = str_replace("\r","",$sJS);
46
+	$sJS = str_replace("\r", "", $sJS);
47 47
 
48 48
 	//array to store replaced literal strings
49 49
 	$literal_strings = array();
50 50
 
51 51
 	//explode the string into lines
52
-	$lines = explode("\n",$sJS);
52
+	$lines = explode("\n", $sJS);
53 53
 	//loop through all the lines, building a new string at the same time as removing literal strings
54 54
 	$clean = "";
55 55
 	$inComment = false;
@@ -58,22 +58,22 @@  discard block
 block discarded – undo
58 58
 	$escaped = false;
59 59
 	$quoteChar = "";
60 60
 
61
-	for($i=0;$i<count($lines);$i++)
61
+	for ($i = 0; $i < count($lines); $i++)
62 62
 	{
63 63
 		$line = $lines[$i];
64 64
 		$inNormalComment = false;
65 65
 
66 66
 		//loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
67
-		for($j=0;$j<strlen($line);$j++)
67
+		for ($j = 0; $j < strlen($line); $j++)
68 68
 		{
69
-			$c = substr($line,$j,1);
70
-			$d = substr($line,$j,2);
69
+			$c = substr($line, $j, 1);
70
+			$d = substr($line, $j, 2);
71 71
 
72 72
 			//look for start of quote
73
-			if(!$inQuote && !$inComment)
73
+			if (!$inQuote && !$inComment)
74 74
 			{
75 75
 				//is this character a quote or a comment
76
-				if(($c=="\"" || $c=="'") && !$inComment && !$inNormalComment)
76
+				if (($c == "\"" || $c == "'") && !$inComment && !$inNormalComment)
77 77
 				{
78 78
 					$inQuote = true;
79 79
 					$inComment = false;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 					$quoteChar = $c;
82 82
 					$literal = $c;
83 83
 				}
84
-				else if($d=="/*" && !$inNormalComment)
84
+				else if ($d == "/*" && !$inNormalComment)
85 85
 				{
86 86
 					$inQuote = false;
87 87
 					$inComment = true;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 					$literal = $d;
91 91
 					$j++;
92 92
 				}
93
-				else if($d=="//") //ignore string markers that are found inside comments
93
+				else if ($d == "//") //ignore string markers that are found inside comments
94 94
 				{
95 95
 					$inNormalComment = true;
96 96
 					$clean .= $c;
@@ -102,32 +102,32 @@  discard block
 block discarded – undo
102 102
 			}
103 103
 			else //allready in a string so find end quote
104 104
 			{
105
-				if($c == $quoteChar && !$escaped && !$inComment)
105
+				if ($c == $quoteChar && !$escaped && !$inComment)
106 106
 				{
107 107
 					$inQuote = false;
108 108
 					$literal .= $c;
109 109
 
110 110
 					//subsitute in a marker for the string
111
-					$clean .= "___" . count($literal_strings) . "___";
111
+					$clean .= "___".count($literal_strings)."___";
112 112
 
113 113
 					//push the string onto our array
114
-					array_push($literal_strings,$literal);
114
+					array_push($literal_strings, $literal);
115 115
 
116 116
 				}
117
-				else if($inComment && $d=="*/")
117
+				else if ($inComment && $d == "*/")
118 118
 				{
119 119
 					$inComment = false;
120 120
 					$literal .= $d;
121 121
 
122 122
 					//subsitute in a marker for the string
123
-					$clean .= "___" . count($literal_strings) . "___";
123
+					$clean .= "___".count($literal_strings)."___";
124 124
 
125 125
 					//push the string onto our array
126
-					array_push($literal_strings,$literal);
126
+					array_push($literal_strings, $literal);
127 127
 
128 128
 					$j++;
129 129
 				}
130
-				else if($c == "\\" && !$escaped)
130
+				else if ($c == "\\" && !$escaped)
131 131
 					$escaped = true;
132 132
 				else
133 133
 					$escaped = false;
@@ -135,47 +135,47 @@  discard block
 block discarded – undo
135 135
 				$literal .= $c;
136 136
 			}
137 137
 		}
138
-		if($inComment) $literal .= "\n";
138
+		if ($inComment) $literal .= "\n";
139 139
 		$clean .= "\n";
140 140
 	}
141 141
 	//explode the clean string into lines again
142
-	$lines = explode("\n",$clean);
142
+	$lines = explode("\n", $clean);
143 143
 
144 144
 	//now process each line at a time
145
-	for($i=0;$i<count($lines);$i++)
145
+	for ($i = 0; $i < count($lines); $i++)
146 146
 	{
147 147
 		$line = $lines[$i];
148 148
 
149 149
 		//remove comments
150
-		$line = preg_replace("/\/\/(.*)/","",$line);
150
+		$line = preg_replace("/\/\/(.*)/", "", $line);
151 151
 
152 152
 		//strip leading and trailing whitespace
153 153
 		$line = trim($line);
154 154
 
155 155
 		//remove all whitespace with a single space
156
-		$line = preg_replace("/\s+/"," ",$line);
156
+		$line = preg_replace("/\s+/", " ", $line);
157 157
 
158 158
 		//remove any whitespace that occurs after/before an operator
159
-		$line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/","\\1",$line);
159
+		$line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/", "\\1", $line);
160 160
 
161 161
 		$lines[$i] = $line;
162 162
 	}
163 163
 
164 164
 	//implode the lines
165
-	$sJS = implode("\n",$lines);
165
+	$sJS = implode("\n", $lines);
166 166
 
167 167
 	//make sure there is a max of 1 \n after each line
168
-	$sJS = preg_replace("/[\n]+/","\n",$sJS);
168
+	$sJS = preg_replace("/[\n]+/", "\n", $sJS);
169 169
 
170 170
 	//strip out line breaks that immediately follow a semi-colon
171
-	$sJS = preg_replace("/;\n/",";",$sJS);
171
+	$sJS = preg_replace("/;\n/", ";", $sJS);
172 172
 
173 173
 	//curly brackets aren't on their own
174
-	$sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
174
+	$sJS = preg_replace("/[\n]*\{[\n]*/", "{", $sJS);
175 175
 
176 176
 	//finally loop through and replace all the literal strings:
177
-	for($i=0;$i<count($literal_strings);$i++)
178
-		$sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
177
+	for ($i = 0; $i < count($literal_strings); $i++)
178
+		$sJS = str_replace("___".$i."___", $literal_strings[$i], $sJS);
179 179
 
180 180
 	return $sJS;
181 181
 }
Please login to merge, or discard this patch.
Braces   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -80,8 +80,7 @@  discard block
 block discarded – undo
80 80
 					$escaped = false;
81 81
 					$quoteChar = $c;
82 82
 					$literal = $c;
83
-				}
84
-				else if($d=="/*" && !$inNormalComment)
83
+				} else if($d=="/*" && !$inNormalComment)
85 84
 				{
86 85
 					$inQuote = false;
87 86
 					$inComment = true;
@@ -89,18 +88,17 @@  discard block
 block discarded – undo
89 88
 					$quoteChar = $d;
90 89
 					$literal = $d;
91 90
 					$j++;
92
-				}
93
-				else if($d=="//") //ignore string markers that are found inside comments
91
+				} else if($d=="//") {
92
+				    //ignore string markers that are found inside comments
94 93
 				{
95 94
 					$inNormalComment = true;
96
-					$clean .= $c;
97 95
 				}
98
-				else
96
+					$clean .= $c;
97
+				} else
99 98
 				{
100 99
 					$clean .= $c;
101 100
 				}
102
-			}
103
-			else //allready in a string so find end quote
101
+			} else //allready in a string so find end quote
104 102
 			{
105 103
 				if($c == $quoteChar && !$escaped && !$inComment)
106 104
 				{
@@ -113,8 +111,7 @@  discard block
 block discarded – undo
113 111
 					//push the string onto our array
114 112
 					array_push($literal_strings,$literal);
115 113
 
116
-				}
117
-				else if($inComment && $d=="*/")
114
+				} else if($inComment && $d=="*/")
118 115
 				{
119 116
 					$inComment = false;
120 117
 					$literal .= $d;
@@ -126,16 +123,18 @@  discard block
 block discarded – undo
126 123
 					array_push($literal_strings,$literal);
127 124
 
128 125
 					$j++;
126
+				} else if($c == "\\" && !$escaped) {
127
+									$escaped = true;
128
+				} else {
129
+									$escaped = false;
129 130
 				}
130
-				else if($c == "\\" && !$escaped)
131
-					$escaped = true;
132
-				else
133
-					$escaped = false;
134 131
 
135 132
 				$literal .= $c;
136 133
 			}
137 134
 		}
138
-		if($inComment) $literal .= "\n";
135
+		if($inComment) {
136
+		    $literal .= "\n";
137
+		}
139 138
 		$clean .= "\n";
140 139
 	}
141 140
 	//explode the clean string into lines again
@@ -174,8 +173,9 @@  discard block
 block discarded – undo
174 173
 	$sJS = preg_replace("/[\n]*\{[\n]*/","{",$sJS);
175 174
 
176 175
 	//finally loop through and replace all the literal strings:
177
-	for($i=0;$i<count($literal_strings);$i++)
178
-		$sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
176
+	for($i=0;$i<count($literal_strings);$i++) {
177
+			$sJS = str_replace("___".$i."___",$literal_strings[$i],$sJS);
178
+	}
179 179
 
180 180
 	return $sJS;
181 181
 }
Please login to merge, or discard this patch.
main/inc/lib/xajax/xajaxResponse.inc.php 4 patches
Doc Comments   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -97,6 +97,7 @@  discard block
 block discarded – undo
97 97
 	 * @param string  contains the character encoding string to use
98 98
 	 * @param boolean lets you set if you want special characters in the output
99 99
 	 *                converted to HTML entities
100
+	 * @param string $sEncoding
100 101
 	 *
101 102
 	 */
102 103
 	function xajaxResponse($sEncoding=XAJAX_DEFAULT_CHAR_ENCODING, $bOutputEntities=false)
@@ -223,6 +224,8 @@  discard block
 block discarded – undo
223 224
 	 * @param string contains the id of an HTML element
224 225
 	 * @param string the part of the element you wish to clear ("innerHTML",
225 226
 	 *               "value", etc.)
227
+	 * @param string $sTarget
228
+	 * @param string $sAttribute
226 229
 	 */
227 230
 	function addClear($sTarget,$sAttribute)
228 231
 	{
@@ -279,6 +282,7 @@  discard block
 block discarded – undo
279 282
 	 * <i>Usage:</i> <kbd>$objResponse->addScript("var x = prompt('get some text');");</kbd>
280 283
 	 *
281 284
 	 * @param string contains Javascript code to be executed
285
+	 * @param string $sJS
282 286
 	 */
283 287
 	function addScript($sJS)
284 288
 	{
@@ -290,8 +294,6 @@  discard block
 block discarded – undo
290 294
 	 *
291 295
 	 * <i>Usage:</i> <kbd>$objResponse->addScriptCall("myJSFunction", "arg 1", "arg 2", 12345);</kbd>
292 296
 	 *
293
-	 * @param string $sFunc the name of a Javascript function
294
-	 * @param mixed $args,... optional arguments to pass to the Javascript function
295 297
 	 */
296 298
 	function addScriptCall() {
297 299
 		$arguments = func_get_args();
Please login to merge, or discard this patch.
Braces   +21 added lines, -17 removed lines patch added patch discarded remove patch
@@ -258,8 +258,9 @@  discard block
 block discarded – undo
258 258
 		{
259 259
 			$queryStart++;
260 260
 			$queryEnd = strpos($sURL, '#', $queryStart);
261
-			if ($queryEnd === FALSE)
262
-				$queryEnd = strlen($sURL);
261
+			if ($queryEnd === FALSE) {
262
+							$queryEnd = strlen($sURL);
263
+			}
263 264
 			$queryPart = substr($sURL, $queryStart, $queryEnd-$queryStart);
264 265
             $queryParts = array();
265 266
 			parse_str($queryPart, $queryParts);
@@ -487,8 +488,9 @@  discard block
 block discarded – undo
487 488
 	function getXML()
488 489
 	{
489 490
 		$sXML = "<?xml version=\"1.0\"";
490
-		if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0)
491
-			$sXML .= " encoding=\"".$this->sEncoding."\"";
491
+		if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0) {
492
+					$sXML .= " encoding=\"".$this->sEncoding."\"";
493
+		}
492 494
 		$sXML .= " ?"."><xjx>" . $this->xml . "</xjx>";
493 495
 
494 496
 		return $sXML;
@@ -538,20 +540,21 @@  discard block
 block discarded – undo
538 540
 			elseif (function_exists('mb_convert_encoding')) {
539 541
 			//
540 542
 				$sData = call_user_func_array('mb_convert_encoding', array(&$sData, 'HTML-ENTITIES', $this->sEncoding));
541
-			}
542
-			else {
543
+			} else {
543 544
 				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
 			}
545 546
 		}
546 547
 		$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>";
548
+		foreach($aAttributes as $sAttribute => $sValue) {
549
+					$xml .= " $sAttribute=\"$sValue\"";
550
+		}
551
+		if ($sData !== null && !stristr($sData,'<![CDATA[')) {
552
+					$xml .= "><![CDATA[$sData]]></cmd>";
553
+		} else if ($sData !== null) {
554
+					$xml .= ">$sData</cmd>";
555
+		} else {
556
+					$xml .= "></cmd>";
557
+		}
555 558
 
556 559
 		return $xml;
557 560
 	}
@@ -566,11 +569,12 @@  discard block
 block discarded – undo
566 569
 	 * @return string serialized XML
567 570
 	 */
568 571
 	function _buildObjXml($var) {
569
-		if (gettype($var) == "object") $var = get_object_vars($var);
572
+		if (gettype($var) == "object") {
573
+		    $var = get_object_vars($var);
574
+		}
570 575
 		if (!is_array($var)) {
571 576
 			return "<![CDATA[$var]]>";
572
-		}
573
-		else {
577
+		} else {
574 578
 			$data = "<xjxobj>";
575 579
 			foreach ($var as $key => $value) {
576 580
 				$data .= "<e>";
Please login to merge, or discard this patch.
Indentation   +512 added lines, -512 removed lines patch added patch discarded remove patch
@@ -67,521 +67,521 @@
 block discarded – undo
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
 ?>
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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>";
Please login to merge, or discard this patch.
main/inc/lib/zombie/zombie_report.class.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -121,6 +121,9 @@
 block discarded – undo
121 121
         return $form->isSubmitted() == false || $form->validate();
122 122
     }
123 123
 
124
+    /**
125
+     * @param string $format
126
+     */
124 127
     function get_ceiling($format = null)
125 128
     {
126 129
         $result = Request::get('ceiling');
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
         }
168 168
 
169 169
         $action = $this->get_action();
170
-        $f = array($this, 'action_' . $action);
170
+        $f = array($this, 'action_'.$action);
171 171
         if (is_callable($f)) {
172 172
             return call_user_func($f, $ids);
173 173
         }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
             $text = get_lang('No');
293 293
         }
294 294
 
295
-        $result = Display::return_icon($image . '.png', $text);
295
+        $result = Display::return_icon($image.'.png', $text);
296 296
         return $result;
297 297
     }
298 298
 
Please login to merge, or discard this patch.
main/install/install.lib.php 4 patches
Doc Comments   +14 added lines, -5 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
  * This function return the value of a php.ini setting if not "" or if exists,
98 98
  * otherwise return false
99 99
  * @param   string  $phpSetting The name of a PHP setting
100
- * @return  mixed   The value of the setting, or false if not found
100
+ * @return  string|false   The value of the setting, or false if not found
101 101
  */
102 102
 function checkPhpSettingExists($phpSetting)
103 103
 {
@@ -1268,6 +1268,10 @@  discard block
 block discarded – undo
1268 1268
  * @param   string  Extra notice (to show on the right side)
1269 1269
  * @param   boolean Whether to display in update mode
1270 1270
  * @param   string  Additional attribute for the <tr> element
1271
+ * @param string $installType
1272
+ * @param string $parameterName
1273
+ * @param string $formFieldName
1274
+ * @param string $extra_notice
1271 1275
  * @return  void    Direct output
1272 1276
  */
1273 1277
 function displayDatabaseParameter(
@@ -1481,6 +1485,11 @@  discard block
 block discarded – undo
1481 1485
 
1482 1486
     <?php
1483 1487
 }
1488
+/**
1489
+ * @param string $content
1490
+ * @param string $title
1491
+ * @param string $id
1492
+ */
1484 1493
 function panel($content = null, $title = null, $id = null, $style = null) {
1485 1494
     $html = '';
1486 1495
     if (empty($style)) {
@@ -1837,8 +1846,8 @@  discard block
 block discarded – undo
1837 1846
 }
1838 1847
 
1839 1848
 /**
1840
- * @param $current_value
1841
- * @param $wanted_value
1849
+ * @param string $current_value
1850
+ * @param string $wanted_value
1842 1851
  * @return string
1843 1852
  */
1844 1853
 function compare_setting_values($current_value, $wanted_value)
@@ -1855,8 +1864,8 @@  discard block
 block discarded – undo
1855 1864
 }
1856 1865
 
1857 1866
 /**
1858
- * @param $course_dir
1859
- * @param $course_attempt_name
1867
+ * @param string $course_dir
1868
+ * @param string $course_attempt_name
1860 1869
  * @param string $file
1861 1870
  * @return bool
1862 1871
  */
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
     if (!is_array($result)) {
397 397
         $result = array();
398 398
         $exceptions = array('.', '..', 'CVS', '.svn');
399
-        $search       = array('_latin',   '_unicode',   '_corporate',   '_org'  , '_KM',   '_');
399
+        $search       = array('_latin', '_unicode', '_corporate', '_org', '_KM', '_');
400 400
         $replace_with = array(' (Latin)', ' (unicode)', ' (corporate)', ' (org)', ' (KM)', ' ');
401 401
         $dirname = api_get_path(SYS_LANG_PATH);
402 402
         $handle = opendir($dirname);
@@ -430,9 +430,9 @@  discard block
 block discarded – undo
430 430
     if ($handle = opendir($directory)) {
431 431
         while (false !== ($file = readdir($handle))) {
432 432
             if ($file != "." && $file != "..") {
433
-                if (is_dir($directory. "/" . $file)) {
434
-                    $array_items = array_merge($array_items, my_directory_to_array($directory. '/' . $file));
435
-                    $file = $directory . "/" . $file;
433
+                if (is_dir($directory."/".$file)) {
434
+                    $array_items = array_merge($array_items, my_directory_to_array($directory.'/'.$file));
435
+                    $file = $directory."/".$file;
436 436
                     $array_items[] = preg_replace("/\/\//si", '/', $file);
437 437
                 }
438 438
             }
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
     <h2><?php get_lang('WelcomeToTheChamiloInstaller'); ?></h2>
637 637
     <div class="RequirementHeading">
638 638
         <h2><?php echo display_step_sequence(); ?>
639
-            <?php echo get_lang('InstallationLanguage');?>
639
+            <?php echo get_lang('InstallationLanguage'); ?>
640 640
         </h2>
641 641
         <p><?php echo get_lang('PleaseSelectInstallationProcessLanguage'); ?>:</p>
642 642
         <form id="lang_form" method="post" action="<?php echo api_get_self(); ?>">
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
     if (phpversion() < REQUIRED_PHP_VERSION) {
710 710
         echo '<strong><font color="red">'.get_lang('PHPVersionError').'</font></strong>';
711 711
     } else {
712
-        echo '<strong><font color="green">'.get_lang('PHPVersionOK'). ' '.phpversion().'</font></strong>';
712
+        echo '<strong><font color="green">'.get_lang('PHPVersionOK').' '.phpversion().'</font></strong>';
713 713
     }
714 714
     echo '</td>
715 715
             </tr>
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
             if ($file_course_test_was_created == true) {
882 882
                 break;
883 883
             }
884
-            $r = @touch($course_dir.'/test.php',$perm);
884
+            $r = @touch($course_dir.'/test.php', $perm);
885 885
             if ($r === true) {
886 886
                 $fil_perm_verified = $perm;
887 887
                 if (check_course_script_interpretation($course_dir, $course_attempt_name, 'test.php')) {
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 function get_contact_registration_form()
1138 1138
 {
1139 1139
 
1140
-    $html ='
1140
+    $html = '
1141 1141
    <form class="form-horizontal">
1142 1142
     <div class="panel panel-default">
1143 1143
     <div class="panel-body">
@@ -1234,7 +1234,7 @@  discard block
 block discarded – undo
1234 1234
             <div class="col-sm-9">
1235 1235
                 <div class="radio">
1236 1236
                     <label>
1237
-                        <input type="radio" name="financial_decision" id="financial_decision1" value="1" checked /> ' . get_lang('Yes') . '
1237
+                        <input type="radio" name="financial_decision" id="financial_decision1" value="1" checked /> ' . get_lang('Yes').'
1238 1238
                     </label>
1239 1239
                 </div>
1240 1240
                 <div class="radio">
@@ -1293,8 +1293,8 @@  discard block
 block discarded – undo
1293 1293
             echo '<input type="hidden" name="'.$formFieldName.'" id="'.$formFieldName.'" value="'.api_htmlentities($parameterValue).'" />';
1294 1294
             echo api_htmlentities($parameterValue);
1295 1295
         } else {
1296
-            echo '<div class="col-sm-5"><input type="' . $inputType . '" class="form-control" size="' . DATABASE_FORM_FIELD_DISPLAY_LENGTH . '" maxlength="' . $maxLength . '" name="' . $formFieldName . '" id="' . $formFieldName . '" value="' . api_htmlentities($parameterValue) . '" />' . "</div>";
1297
-            echo '<div class="col-sm-3">' . $extra_notice . '</div>';
1296
+            echo '<div class="col-sm-5"><input type="'.$inputType.'" class="form-control" size="'.DATABASE_FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.$maxLength.'" name="'.$formFieldName.'" id="'.$formFieldName.'" value="'.api_htmlentities($parameterValue).'" />'."</div>";
1297
+            echo '<div class="col-sm-3">'.$extra_notice.'</div>';
1298 1298
         }
1299 1299
 
1300 1300
     }
@@ -1330,12 +1330,12 @@  discard block
 block discarded – undo
1330 1330
         $dbNameForm = $_configuration['main_database'];
1331 1331
         $dbPortForm = isset($_configuration['db_port']) ? $_configuration['db_port'] : '';
1332 1332
 
1333
-        echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>';
1333
+        echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('DBSetting').'</h2></div>';
1334 1334
         echo '<div class="RequirementContent">';
1335 1335
         echo get_lang('DBSettingUpgradeIntro');
1336 1336
         echo '</div>';
1337 1337
     } else {
1338
-        echo '<div class="RequirementHeading"><h2>' . display_step_sequence() .get_lang('DBSetting') . '</h2></div>';
1338
+        echo '<div class="RequirementHeading"><h2>'.display_step_sequence().get_lang('DBSetting').'</h2></div>';
1339 1339
         echo '<div class="RequirementContent">';
1340 1340
         echo get_lang('DBSettingIntro');
1341 1341
         echo '</div>';
@@ -1345,12 +1345,12 @@  discard block
 block discarded – undo
1345 1345
         <div class="panel-body">
1346 1346
         <div class="form-group">
1347 1347
             <label class="col-sm-4"><?php echo get_lang('DBHost'); ?> </label>
1348
-            <?php if ($installType == 'update'){ ?>
1348
+            <?php if ($installType == 'update') { ?>
1349 1349
             <div class="col-sm-5">
1350 1350
                 <input type="hidden" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /><?php echo $dbHostForm; ?>
1351 1351
             </div>
1352 1352
             <div class="col-sm-3"></div>
1353
-            <?php }else{ ?>
1353
+            <?php } else { ?>
1354 1354
             <div class="col-sm-5">
1355 1355
                 <input type="text" class="form-control" size="25" maxlength="50" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" />
1356 1356
             </div>
@@ -1359,12 +1359,12 @@  discard block
 block discarded – undo
1359 1359
         </div>
1360 1360
         <div class="form-group">
1361 1361
             <label class="col-sm-4"><?php echo get_lang('DBPort'); ?> </label>
1362
-            <?php if ($installType == 'update'){ ?>
1362
+            <?php if ($installType == 'update') { ?>
1363 1363
             <div class="col-sm-5">
1364 1364
                 <input type="hidden" name="dbPortForm" value="<?php echo htmlentities($dbPortForm); ?>" /><?php echo $dbPortForm; ?>
1365 1365
             </div>
1366 1366
             <div class="col-sm-3"></div>
1367
-            <?php }else{ ?>
1367
+            <?php } else { ?>
1368 1368
             <div class="col-sm-5">
1369 1369
                 <input type="text" class="form-control" size="25" maxlength="50" name="dbPortForm" value="<?php echo htmlentities($dbPortForm); ?>" />
1370 1370
             </div>
@@ -1390,7 +1390,7 @@  discard block
 block discarded – undo
1390 1390
             <?php
1391 1391
             //Database Name fix replace weird chars
1392 1392
             if ($installType != INSTALL_TYPE_UPDATE) {
1393
-                $dbNameForm = str_replace(array('-','*', '$', ' ', '.'), '', $dbNameForm);
1393
+                $dbNameForm = str_replace(array('-', '*', '$', ' ', '.'), '', $dbNameForm);
1394 1394
             }
1395 1395
 
1396 1396
             displayDatabaseParameter(
@@ -1489,7 +1489,7 @@  discard block
 block discarded – undo
1489 1489
     if (!empty($title)) {
1490 1490
         $panelTitle = Display::div($title, array('class' => 'panel-heading'));
1491 1491
         $panelBody = Display::div($content, array('class' => 'panel-body'));
1492
-        $panelParent = Display::div($panelTitle . $panelBody, array('id' => $id, 'class' => 'panel panel-'.$style));
1492
+        $panelParent = Display::div($panelTitle.$panelBody, array('id' => $id, 'class' => 'panel panel-'.$style));
1493 1493
     } else {
1494 1494
         $panelBody = Display::div($html, array('class' => 'panel-body'));
1495 1495
         $panelParent = Display::div($panelBody, array('id' => $id, 'class' => 'panel panel-'.$style));
@@ -1514,9 +1514,9 @@  discard block
 block discarded – undo
1514 1514
     $displayWhenUpdate = 'true'
1515 1515
 ) {
1516 1516
     $html = '<div class="form-group">';
1517
-    $html .= '<label class="col-sm-6 control-label">' . $parameterName . '</label>';
1517
+    $html .= '<label class="col-sm-6 control-label">'.$parameterName.'</label>';
1518 1518
     if ($installType == INSTALL_TYPE_UPDATE && $displayWhenUpdate) {
1519
-        $html .= '<input type="hidden" name="' . $formFieldName . '" value="'. api_htmlentities($parameterValue, ENT_QUOTES). '" />' . $parameterValue;
1519
+        $html .= '<input type="hidden" name="'.$formFieldName.'" value="'.api_htmlentities($parameterValue, ENT_QUOTES).'" />'.$parameterValue;
1520 1520
     } else {
1521 1521
         $html .= '<div class="col-sm-6"><input class="form-control" type="text" size="'.FORM_FIELD_DISPLAY_LENGTH.'" maxlength="'.MAX_FORM_FIELD_LENGTH.'" name="'.$formFieldName.'" value="'.api_htmlentities($parameterValue, ENT_QUOTES).'" />'."</div>";
1522 1522
     }
@@ -1563,7 +1563,7 @@  discard block
 block discarded – undo
1563 1563
         $languageForm = $_SESSION['install_language'];
1564 1564
     }
1565 1565
     echo '<div class="RequirementHeading">';
1566
-    echo "<h2>" . display_step_sequence() . get_lang("CfgSetting") . "</h2>";
1566
+    echo "<h2>".display_step_sequence().get_lang("CfgSetting")."</h2>";
1567 1567
     echo '</div>';
1568 1568
 
1569 1569
     echo '<p>'.get_lang('ConfigSettingsInfo').' <strong>app/config/configuration.php</strong></p>';
@@ -1581,14 +1581,14 @@  discard block
 block discarded – undo
1581 1581
 
1582 1582
     // Parameters 3 and 4: administrator's names
1583 1583
 
1584
-    $html .=  display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
1585
-    $html .=  display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
1584
+    $html .= display_configuration_parameter($installType, get_lang('AdminFirstName'), 'adminFirstName', $adminFirstName);
1585
+    $html .= display_configuration_parameter($installType, get_lang('AdminLastName'), 'adminLastName', $adminLastName);
1586 1586
 
1587 1587
     //Parameter 3: administrator's email
1588
-    $html .=  display_configuration_parameter($installType, get_lang('AdminEmail'), 'emailForm', $emailForm);
1588
+    $html .= display_configuration_parameter($installType, get_lang('AdminEmail'), 'emailForm', $emailForm);
1589 1589
 
1590 1590
     //Parameter 6: administrator's telephone
1591
-    $html .=  display_configuration_parameter($installType, get_lang('AdminPhone'), 'adminPhoneForm', $adminPhoneForm);
1591
+    $html .= display_configuration_parameter($installType, get_lang('AdminPhone'), 'adminPhoneForm', $adminPhoneForm);
1592 1592
 
1593 1593
 
1594 1594
     echo panel($html, get_lang('Administrator'), 'administrator');
@@ -1607,12 +1607,12 @@  discard block
 block discarded – undo
1607 1607
         $html .= display_language_selection_box('languageForm', $languageForm);
1608 1608
         $html .= '</div>';
1609 1609
     }
1610
-    $html.= "</div>";
1610
+    $html .= "</div>";
1611 1611
 
1612 1612
 
1613 1613
     //Second parameter: Chamilo URL
1614 1614
     $html .= '<div class="form-group">';
1615
-    $html .= '<label class="col-sm-6 control-label">'.get_lang('ChamiloURL') .get_lang('ThisFieldIsRequired').'</label>';
1615
+    $html .= '<label class="col-sm-6 control-label">'.get_lang('ChamiloURL').get_lang('ThisFieldIsRequired').'</label>';
1616 1616
 
1617 1617
 
1618 1618
 
@@ -1636,34 +1636,34 @@  discard block
 block discarded – undo
1636 1636
 
1637 1637
 
1638 1638
     $html .= '<div class="form-group">
1639
-            <label class="col-sm-6 control-label">' . get_lang("EncryptMethodUserPass") . '</label>
1639
+            <label class="col-sm-6 control-label">' . get_lang("EncryptMethodUserPass").'</label>
1640 1640
         <div class="col-sm-6">';
1641 1641
     if ($installType == 'update') {
1642
-        $html .= '<input type="hidden" name="encryptPassForm" value="'. $encryptPassForm .'" />'. $encryptPassForm;
1642
+        $html .= '<input type="hidden" name="encryptPassForm" value="'.$encryptPassForm.'" />'.$encryptPassForm;
1643 1643
     } else {
1644 1644
 
1645 1645
         $html .= '<div class="checkbox">
1646 1646
                     <label>
1647
-                        <input  type="radio" name="encryptPassForm" value="bcrypt" id="encryptPass1" '. ($encryptPassForm == 'bcrypt' ? 'checked="checked" ':'') .'/> bcrypt
1647
+                        <input  type="radio" name="encryptPassForm" value="bcrypt" id="encryptPass1" '. ($encryptPassForm == 'bcrypt' ? 'checked="checked" ' : '').'/> bcrypt
1648 1648
                     </label>';
1649 1649
 
1650 1650
         $html .= '<label>
1651
-                        <input  type="radio" name="encryptPassForm" value="sha1" id="encryptPass1" '. ($encryptPassForm == 'sha1' ? 'checked="checked" ':'') .'/> sha1
1651
+                        <input  type="radio" name="encryptPassForm" value="sha1" id="encryptPass1" '. ($encryptPassForm == 'sha1' ? 'checked="checked" ' : '').'/> sha1
1652 1652
                     </label>';
1653 1653
 
1654 1654
         $html .= '<label>
1655
-                        <input type="radio" name="encryptPassForm" value="md5" id="encryptPass0" '. ($encryptPassForm == 'md5' ? 'checked="checked" ':'') .'/> md5
1655
+                        <input type="radio" name="encryptPassForm" value="md5" id="encryptPass0" '. ($encryptPassForm == 'md5' ? 'checked="checked" ' : '').'/> md5
1656 1656
                     </label>';
1657 1657
 
1658 1658
         $html .= '<label>
1659
-                        <input type="radio" name="encryptPassForm" value="none" id="encryptPass2" '. ($encryptPassForm == 'none' ? 'checked="checked" ':'') .'/>'. get_lang('None').'
1659
+                        <input type="radio" name="encryptPassForm" value="none" id="encryptPass2" '. ($encryptPassForm == 'none' ? 'checked="checked" ' : '').'/>'.get_lang('None').'
1660 1660
                     </label>';
1661 1661
         $html .= '</div>';
1662 1662
     }
1663 1663
     $html .= '</div></div>';
1664 1664
 
1665 1665
     $html .= '<div class="form-group">
1666
-            <label class="col-sm-6 control-label">' . get_lang('AllowSelfReg') . '</label>
1666
+            <label class="col-sm-6 control-label">' . get_lang('AllowSelfReg').'</label>
1667 1667
             <div class="col-sm-6">';
1668 1668
     if ($installType == 'update') {
1669 1669
         if ($allowSelfReg == 'true') {
@@ -1673,17 +1673,17 @@  discard block
 block discarded – undo
1673 1673
         } else {
1674 1674
             $label = get_lang('AfterApproval');
1675 1675
         }
1676
-        $html .= '<input type="hidden" name="allowSelfReg" value="'. $allowSelfReg .'" />'. $label;
1676
+        $html .= '<input type="hidden" name="allowSelfReg" value="'.$allowSelfReg.'" />'.$label;
1677 1677
     } else {
1678 1678
         $html .= '<div class="control-group">';
1679 1679
         $html .= '<label class="checkbox-inline">
1680
-                        <input type="radio" name="allowSelfReg" value="1" id="allowSelfReg1" '. ($allowSelfReg == 'true' ? 'checked="checked" ' : '') . ' /> '. get_lang('Yes') .'
1680
+                        <input type="radio" name="allowSelfReg" value="1" id="allowSelfReg1" '. ($allowSelfReg == 'true' ? 'checked="checked" ' : '').' /> '.get_lang('Yes').'
1681 1681
                     </label>';
1682 1682
         $html .= '<label class="checkbox-inline">
1683
-                        <input type="radio" name="allowSelfReg" value="0" id="allowSelfReg0" '. ($allowSelfReg == 'false' ? '' : 'checked="checked" ') .' /> '. get_lang('No') .'
1683
+                        <input type="radio" name="allowSelfReg" value="0" id="allowSelfReg0" '. ($allowSelfReg == 'false' ? '' : 'checked="checked" ').' /> '.get_lang('No').'
1684 1684
                     </label>';
1685 1685
          $html .= '<label class="checkbox-inline">
1686
-                    <input type="radio" name="allowSelfReg" value="0" id="allowSelfReg0" '. ($allowSelfReg == 'approval' ? '' : 'checked="checked" ') .' /> '. get_lang('AfterApproval') .'
1686
+                    <input type="radio" name="allowSelfReg" value="0" id="allowSelfReg0" '. ($allowSelfReg == 'approval' ? '' : 'checked="checked" ').' /> '.get_lang('AfterApproval').'
1687 1687
                 </label>';
1688 1688
         $html .= '</div>';
1689 1689
     }
@@ -1691,7 +1691,7 @@  discard block
 block discarded – undo
1691 1691
     $html .= '</div>';
1692 1692
 
1693 1693
     $html .= '<div class="form-group">';
1694
-    $html .= '<label class="col-sm-6 control-label">'. get_lang('AllowSelfRegProf') .'</label>
1694
+    $html .= '<label class="col-sm-6 control-label">'.get_lang('AllowSelfRegProf').'</label>
1695 1695
         <div class="col-sm-6">';
1696 1696
     if ($installType == 'update') {
1697 1697
         if ($allowSelfRegProf == 'true') {
@@ -1699,16 +1699,16 @@  discard block
 block discarded – undo
1699 1699
         } else {
1700 1700
             $label = get_lang('No');
1701 1701
         }
1702
-        $html .= '<input type="hidden" name="allowSelfRegProf" value="'. $allowSelfRegProf.'" />'. $label;
1702
+        $html .= '<input type="hidden" name="allowSelfRegProf" value="'.$allowSelfRegProf.'" />'.$label;
1703 1703
     } else {
1704 1704
         $html .= '<div class="control-group">
1705 1705
                 <label class="checkbox-inline">
1706
-                    <input type="radio" name="allowSelfRegProf" value="1" id="allowSelfRegProf1" '. ($allowSelfRegProf ? 'checked="checked" ' : '') .'/>
1707
-                ' . get_lang('Yes') .'
1706
+                    <input type="radio" name="allowSelfRegProf" value="1" id="allowSelfRegProf1" '. ($allowSelfRegProf ? 'checked="checked" ' : '').'/>
1707
+                ' . get_lang('Yes').'
1708 1708
                 </label>';
1709 1709
         $html .= '<label class="checkbox-inline">
1710
-                    <input type="radio" name="allowSelfRegProf" value="0" id="allowSelfRegProf0" '. ($allowSelfRegProf ? '' : 'checked="checked" ') .' />
1711
-                   '. get_lang('No') .'
1710
+                    <input type="radio" name="allowSelfRegProf" value="0" id="allowSelfRegProf0" '. ($allowSelfRegProf ? '' : 'checked="checked" ').' />
1711
+                   '. get_lang('No').'
1712 1712
                 </label>';
1713 1713
         $html .= '</div>';
1714 1714
     }
@@ -1773,7 +1773,7 @@  discard block
 block discarded – undo
1773 1773
         "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Morocco", "Mozambique", "Myanmar",
1774 1774
         "Namibia", "Nauru", "Nepa", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway",
1775 1775
         "Oman",
1776
-        "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland","Portugal",
1776
+        "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal",
1777 1777
         "Qatar",
1778 1778
         "Romania", "Russia", "Rwanda",
1779 1779
         "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia and Montenegro", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland", "Syria",
@@ -1820,11 +1820,11 @@  discard block
 block discarded – undo
1820 1820
     $permissions_for_new_directories = isset($_SESSION['permissions_for_new_directories']) ? $_SESSION['permissions_for_new_directories'] : 0770;
1821 1821
     $permissions_for_new_files = isset($_SESSION['permissions_for_new_files']) ? $_SESSION['permissions_for_new_files'] : 0660;
1822 1822
     // use decoct() to store as string
1823
-    $sql = "UPDATE $table SET selected_value = '0" . decoct($permissions_for_new_directories) . "'
1823
+    $sql = "UPDATE $table SET selected_value = '0".decoct($permissions_for_new_directories)."'
1824 1824
               WHERE variable  = 'permissions_for_new_directories'";
1825 1825
     Database::query($sql);
1826 1826
 
1827
-    $sql = "UPDATE $table SET selected_value = '0" . decoct($permissions_for_new_files) . "' WHERE variable  = 'permissions_for_new_files'";
1827
+    $sql = "UPDATE $table SET selected_value = '0".decoct($permissions_for_new_files)."' WHERE variable  = 'permissions_for_new_files'";
1828 1828
     Database::query($sql);
1829 1829
 
1830 1830
     if (isset($_SESSION['permissions_for_new_directories'])) {
@@ -1844,8 +1844,8 @@  discard block
 block discarded – undo
1844 1844
 function compare_setting_values($current_value, $wanted_value)
1845 1845
 {
1846 1846
     $current_value_string = $current_value;
1847
-    $current_value = (float)$current_value;
1848
-    $wanted_value = (float)$wanted_value;
1847
+    $current_value = (float) $current_value;
1848
+    $wanted_value = (float) $wanted_value;
1849 1849
 
1850 1850
     if ($current_value >= $wanted_value) {
1851 1851
         return Display::label($current_value_string, 'success');
@@ -1896,7 +1896,7 @@  discard block
 block discarded – undo
1896 1896
 
1897 1897
                     fwrite($fp, $out);
1898 1898
                     while (!feof($fp)) {
1899
-                        $result = str_replace("\r\n", '',fgets($fp, 128));
1899
+                        $result = str_replace("\r\n", '', fgets($fp, 128));
1900 1900
                         if (!empty($result) && $result == '123') {
1901 1901
                             $output = true;
1902 1902
                         }
@@ -1919,7 +1919,7 @@  discard block
 block discarded – undo
1919 1919
                     curl_setopt($ch, CURLOPT_URL, $url);
1920 1920
                     //curl_setopt($ch, CURLOPT_TIMEOUT, 30);
1921 1921
                     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1922
-                    $result = curl_exec ($ch);
1922
+                    $result = curl_exec($ch);
1923 1923
                     if (!empty($result) && $result == '123') {
1924 1924
                         $output = true;
1925 1925
                     }
@@ -2679,12 +2679,12 @@  discard block
 block discarded – undo
2679 2679
         $adminPhoneForm,
2680 2680
         '', //$picture_uri = '',
2681 2681
         PLATFORM_AUTH_SOURCE,
2682
-        '',//$expirationDate,
2682
+        '', //$expirationDate,
2683 2683
         1,
2684 2684
         0,
2685 2685
         null,
2686 2686
         '',
2687
-        false,  //$send_mail = false,
2687
+        false, //$send_mail = false,
2688 2688
         true //$isAdmin = false
2689 2689
     );
2690 2690
 
@@ -2706,7 +2706,7 @@  discard block
 block discarded – undo
2706 2706
         0,
2707 2707
         null,
2708 2708
         '',
2709
-        false,  //$send_mail = false,
2709
+        false, //$send_mail = false,
2710 2710
         false //$isAdmin = false
2711 2711
     );
2712 2712
 
@@ -2772,7 +2772,7 @@  discard block
 block discarded – undo
2772 2772
                 SET selected_value = '".$param->selected_value."'
2773 2773
                 WHERE variable = '".$param->variable."'";
2774 2774
         if (!empty($param->subkey)) {
2775
-            $sql .= " AND subkey='" . $param->subkey . "'";
2775
+            $sql .= " AND subkey='".$param->subkey."'";
2776 2776
         }
2777 2777
         Database::query($sql);
2778 2778
     }
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1682,7 +1682,7 @@  discard block
 block discarded – undo
1682 1682
         $html .= '<label class="checkbox-inline">
1683 1683
                         <input type="radio" name="allowSelfReg" value="0" id="allowSelfReg0" '. ($allowSelfReg == 'false' ? '' : 'checked="checked" ') .' /> '. get_lang('No') .'
1684 1684
                     </label>';
1685
-         $html .= '<label class="checkbox-inline">
1685
+            $html .= '<label class="checkbox-inline">
1686 1686
                     <input type="radio" name="allowSelfReg" value="0" id="allowSelfReg0" '. ($allowSelfReg == 'approval' ? '' : 'checked="checked" ') .' /> '. get_lang('AfterApproval') .'
1687 1687
                 </label>';
1688 1688
         $html .= '</div>';
@@ -1716,7 +1716,7 @@  discard block
 block discarded – undo
1716 1716
     </div>';
1717 1717
 
1718 1718
     echo panel($html, get_lang('Platform'), 'platform');
1719
- ?>
1719
+    ?>
1720 1720
     <div class='form-group'>
1721 1721
         <div class="col-sm-6">
1722 1722
             <button type="submit" class="btn btn-default pull-right" name="step3" value="&lt; <?php echo get_lang('Previous'); ?>" ><em class="fa fa-backward"> </em> <?php echo get_lang('Previous'); ?></button>
Please login to merge, or discard this patch.
Braces   +15 added lines, -8 removed lines patch added patch discarded remove patch
@@ -973,8 +973,7 @@  discard block
 block discarded – undo
973 973
                 <?php echo get_lang('Error'); ?>!<br />
974 974
                 Chamilo <?php echo implode('|', $update_from_version_8).' '.get_lang('HasNotBeenFoundInThatDir'); ?>.
975 975
             </div>
976
-        <?php }
977
-        else {
976
+        <?php } else {
978 977
             echo '<br />';
979 978
         }
980 979
         ?>
@@ -1060,14 +1059,19 @@  discard block
 block discarded – undo
1060 1059
         <button type="submit" name="step1" class="btn btn-default" onclick="javascript: window.location='index.php'; return false;" value="<?php echo get_lang('Previous'); ?>" >
1061 1060
             <em class="fa fa-backward"> </em> <?php echo get_lang('Previous'); ?>
1062 1061
         </button>
1063
-        <button type="submit" name="step2_install" class="btn btn-success" value="<?php echo get_lang("NewInstallation"); ?>" <?php if ($error) echo 'disabled="disabled"'; ?> >
1062
+        <button type="submit" name="step2_install" class="btn btn-success" value="<?php echo get_lang("NewInstallation"); ?>" <?php if ($error) {
1063
+    echo 'disabled="disabled"';
1064
+}
1065
+?> >
1064 1066
             <em class="fa fa-forward"> </em> <?php echo get_lang('NewInstallation'); ?>
1065 1067
         </button>
1066 1068
         <input type="hidden" name="is_executable" id="is_executable" value="-" />
1067 1069
         <?php
1068 1070
         // Real code
1069 1071
         echo '<button type="submit" class="btn btn-default" name="step2_update_8" value="Upgrade from Chamilo 1.9.x"';
1070
-        if ($error) echo ' disabled="disabled"';
1072
+        if ($error) {
1073
+            echo ' disabled="disabled"';
1074
+        }
1071 1075
         echo ' ><em class="fa fa-forward"> </em> '.get_lang('UpgradeFromLMS19x').'</button>';
1072 1076
 
1073 1077
         echo '</p>';
@@ -1350,7 +1354,7 @@  discard block
 block discarded – undo
1350 1354
                 <input type="hidden" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" /><?php echo $dbHostForm; ?>
1351 1355
             </div>
1352 1356
             <div class="col-sm-3"></div>
1353
-            <?php }else{ ?>
1357
+            <?php } else{ ?>
1354 1358
             <div class="col-sm-5">
1355 1359
                 <input type="text" class="form-control" size="25" maxlength="50" name="dbHostForm" value="<?php echo htmlentities($dbHostForm); ?>" />
1356 1360
             </div>
@@ -1364,7 +1368,7 @@  discard block
 block discarded – undo
1364 1368
                 <input type="hidden" name="dbPortForm" value="<?php echo htmlentities($dbPortForm); ?>" /><?php echo $dbPortForm; ?>
1365 1369
             </div>
1366 1370
             <div class="col-sm-3"></div>
1367
-            <?php }else{ ?>
1371
+            <?php } else{ ?>
1368 1372
             <div class="col-sm-5">
1369 1373
                 <input type="text" class="form-control" size="25" maxlength="50" name="dbPortForm" value="<?php echo htmlentities($dbPortForm); ?>" />
1370 1374
             </div>
@@ -1446,9 +1450,12 @@  discard block
 block discarded – undo
1446 1450
             Database port: <strong><?php echo $manager->getConnection()->getPort(); ?></strong><br/>
1447 1451
             Database driver: <strong><?php echo $manager->getConnection()->getDriver()->getName(); ?></strong><br/>
1448 1452
         </div>
1449
-    <?php else: ?>
1453
+    <?php else {
1454
+    : ?>
1450 1455
         <div id="db_status" class="alert alert-danger">
1451
-            <p><?php echo get_lang('FailedConectionDatabase'); ?></strong></p>
1456
+            <p><?php echo get_lang('FailedConectionDatabase');
1457
+}
1458
+?></strong></p>
1452 1459
             <code><?php echo $database_exists_text ?></code>
1453 1460
         </div>
1454 1461
     <?php endif; ?>
Please login to merge, or discard this patch.
main/newscorm/aicc.class.php 4 patches
Doc Comments   +5 added lines, -3 removed lines patch added patch discarded remove patch
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     /**
217 217
      * Import the aicc object (as a result from the parse_config_files function) into the database structure
218 218
      * @param	string	$course_code
219
-     * @return	bool	Returns -1 on error
219
+     * @return	false|null	Returns -1 on error
220 220
      */
221 221
     public function import_aicc($course_code)
222 222
     {
@@ -780,7 +780,8 @@  discard block
 block discarded – undo
780 780
      * Static function to parse AICC ini files.
781 781
      * Based on work by sinedeo at gmail dot com published on php.net (parse_ini_file()).
782 782
      * @param	string	File path
783
-     * @return	array	Structured array
783
+     * @param string $f
784
+     * @return	string	Structured array
784 785
      */
785 786
     function parse_ini_file_quotes_safe($f) {
786 787
         $null = '';
@@ -831,7 +832,7 @@  discard block
 block discarded – undo
831 832
      * Based on work by sinedeo at gmail dot com published on php.net (parse_ini_file()).
832 833
      * @param		string	INI File string
833 834
      * @param		array	List of names of sections that should be considered as containing only hard string data (no variables), provided in lower case
834
-     * @return	array	Structured array
835
+     * @return	string	Structured array
835 836
      */
836 837
     function parse_ini_string_quotes_safe($s, $pure_strings = array()) {
837 838
         $null = '';
@@ -894,6 +895,7 @@  discard block
 block discarded – undo
894 895
      * @param	string	CSV delimiter
895 896
      * @param	string	CSV enclosure
896 897
      * @param	boolean	Might one field name happen more than once on the same line? (then split by comma in the values)
898
+     * @param string $f
897 899
      * @return array	Simple structured array
898 900
      */
899 901
     function parse_csv_file($f, $delim = ',', $enclosure = '"', $multiples = false) {
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -320,12 +320,12 @@  discard block
 block discarded – undo
320 320
         }
321 321
     }
322 322
 
323
-     /**
324
-     * Intermediate to import_package only to allow import from local zip files
325
-     * @param	string	Path to the zip file, from the dokeos sys root
326
-     * @param	string	Current path (optional)
327
-     * @return string	Absolute path to the AICC description files or empty string on error
328
-     */
323
+        /**
324
+         * Intermediate to import_package only to allow import from local zip files
325
+         * @param	string	Path to the zip file, from the dokeos sys root
326
+         * @param	string	Current path (optional)
327
+         * @return string	Absolute path to the AICC description files or empty string on error
328
+         */
329 329
     function import_local_package($file_path, $current_dir = '')
330 330
     {
331 331
         // TODO: Prepare info as given by the $_FILES[''] vector.
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
         $current_dir = api_replace_dangerous_char(trim($current_dir)); // Current dir we are in, inside scorm/
356 356
         if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Current_dir = '.$current_dir, 0); }
357 357
 
358
-         //$uploaded_filename = $_FILES['userFile']['name'];
358
+            //$uploaded_filename = $_FILES['userFile']['name'];
359 359
         // Get the name of the zip file without the extension.
360 360
         if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Received zip file name: '.$zip_file_path, 0); }
361 361
         $file_info = pathinfo($zip_file_name);
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 class aicc extends learnpath
13 13
 {
14 14
     public $config = array();
15
-    public $config_basename = '';	// The configuration files might be multiple and might have
15
+    public $config_basename = ''; // The configuration files might be multiple and might have
16 16
                                     // funny names. We need to keep the name of that file while we
17 17
                                     // install the content.
18 18
     public $config_files = array();
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
     public $cstlist = array();
33 33
     public $orelist = array();
34 34
 
35
-    public $subdir = '';	// Path between the scorm/ directory and the config files e.g. maritime_nav/maritime_nav. This is the path that will be used in the lp_path when importing a package.
36
-    public $zipname = '';	// Keeps the zipfile safe for the object's life so that we can use it if there is no title available.
37
-    public $lastzipnameindex = 0;	// Keeps an index of the number of uses of the zipname so far.
35
+    public $subdir = ''; // Path between the scorm/ directory and the config files e.g. maritime_nav/maritime_nav. This is the path that will be used in the lp_path when importing a package.
36
+    public $zipname = ''; // Keeps the zipfile safe for the object's life so that we can use it if there is no title available.
37
+    public $lastzipnameindex = 0; // Keeps an index of the number of uses of the zipname so far.
38 38
     public $config_encoding = 'ISO-8859-1';
39 39
     public $debug = 0;
40 40
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             //echo '<pre>des:'.print_r($des_params, true).'</pre>';
133 133
             if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$des_file.' has been parsed', 0); }
134 134
             // Distribute des params into the aicc object.
135
-            foreach ($des_params as $des){
135
+            foreach ($des_params as $des) {
136 136
                 // One AU in AICC is equivalent to one SCO in SCORM (scormItem class).
137 137
                 $oDes = new aiccResource('config', $des);
138 138
                 $this->deslist[$oDes->identifier] = $oDes;
@@ -242,12 +242,12 @@  discard block
 block discarded – undo
242 242
 
243 243
         $this->config_encoding = "ISO-8859-1"; // TODO: We may apply detection for this value, see the function api_detect_encoding().
244 244
 
245
-        $sql = "INSERT INTO $new_lp (c_id, lp_type, name, ref, description, path, force_commit, default_view_mod, default_encoding, js_lib, content_maker,display_order)" .
246
-                "VALUES " .
247
-                "($course_id, 3, '".$this->course_title."', '".$this->course_id."','".$this->course_description."'," .
248
-                "'".$this->subdir."', 0, 'embedded', '".$this->config_encoding."'," .
245
+        $sql = "INSERT INTO $new_lp (c_id, lp_type, name, ref, description, path, force_commit, default_view_mod, default_encoding, js_lib, content_maker,display_order)".
246
+                "VALUES ".
247
+                "($course_id, 3, '".$this->course_title."', '".$this->course_id."','".$this->course_description."',".
248
+                "'".$this->subdir."', 0, 'embedded', '".$this->config_encoding."',".
249 249
                 "'aicc_api.php','".$this->course_creator."',$dsp)";
250
-        if ($this->debug > 2) { error_log('New LP - In import_aicc(), inserting path: '. $sql, 0); }
250
+        if ($this->debug > 2) { error_log('New LP - In import_aicc(), inserting path: '.$sql, 0); }
251 251
         Database::query($sql);
252 252
         $lp_id = Database::insert_id();
253 253
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 
277 277
         $previous = 0;
278 278
         foreach ($this->aulist as $identifier => $dummy) {
279
-            $oAu =& $this->aulist[$identifier];
279
+            $oAu = & $this->aulist[$identifier];
280 280
             //echo "Item ".$oAu->identifier;
281 281
             $field_add = '';
282 282
             $value_add = '';
@@ -294,12 +294,12 @@  discard block
 block discarded – undo
294 294
             $parent = 0; // TODO: Deal with the parent.
295 295
             $previous = 0;
296 296
             $prereq = $oAu->prereq_string;
297
-            $sql_item = "INSERT INTO $new_lp_item (c_id, lp_id,item_type,ref,title, path,min_score,max_score, $field_add parent_item_id,previous_item_id,next_item_id, prerequisite,display_order,parameters) " .
298
-                    "VALUES " .
299
-                    "($course_id, $lp_id, 'au','".$oAu->identifier."','".$title."'," .
300
-                    "'$path',0,100, $value_add" .
301
-                    "$parent, $previous, 0, " .
302
-                    "'$prereq', 0,'".(!empty($oAu->parameters)?Database::escape_string($oAu->parameters):'')."'" .
297
+            $sql_item = "INSERT INTO $new_lp_item (c_id, lp_id,item_type,ref,title, path,min_score,max_score, $field_add parent_item_id,previous_item_id,next_item_id, prerequisite,display_order,parameters) ".
298
+                    "VALUES ".
299
+                    "($course_id, $lp_id, 'au','".$oAu->identifier."','".$title."',".
300
+                    "'$path',0,100, $value_add".
301
+                    "$parent, $previous, 0, ".
302
+                    "'$prereq', 0,'".(!empty($oAu->parameters) ? Database::escape_string($oAu->parameters) : '')."'".
303 303
                     ")";
304 304
             Database::query($sql_item);
305 305
             if ($this->debug > 1) { error_log('New LP - In aicc::import_aicc() - inserting item : '.$sql_item.' : ', 0); }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
         $zip_file_name = $zip_file_info['name'];
351 351
 
352 352
         if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Zip file path = '.$zip_file_path.', zip file name = '.$zip_file_name, 0); }
353
-        $course_rel_dir  = api_get_course_path().'/scorm'; // Scorm dir web path starting from /courses
353
+        $course_rel_dir = api_get_course_path().'/scorm'; // Scorm dir web path starting from /courses
354 354
         $course_sys_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; // The absolute system path of this course.
355 355
         $current_dir = api_replace_dangerous_char(trim($current_dir)); // Current dir we are in, inside scorm/
356 356
         if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Current_dir = '.$current_dir, 0); }
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
         if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Base file name is : '.$file_base_name, 0); }
368 368
         $new_dir = api_replace_dangerous_char(trim($file_base_name));
369 369
         $this->subdir = $new_dir;
370
-        if($this->debug > 0) { error_log('New LP - aicc::import_package() - Subdir is first set to : '.$this->subdir, 0); }
370
+        if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Subdir is first set to : '.$this->subdir, 0); }
371 371
 
372 372
         /*
373 373
         if (check_name_exist($course_sys_dir.$current_dir.'/'.$new_dir)) {
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
                         $subdir_isset = true;
414 414
                     } else {
415 415
                         if (!$subdir_isset) {
416
-                            if (preg_match('?^.*/aicc$?i',dirname($thisContent['filename']))) {
416
+                            if (preg_match('?^.*/aicc$?i', dirname($thisContent['filename']))) {
417 417
                                 //echo "Cutting subdir<br/>";
418 418
                                 $this->subdir .= '/'.substr(dirname($thisContent['filename']), 0, -5);
419 419
                             } else {
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
                         // TODO: RENAMING FILES CAN BE VERY DANGEROUS AICC-WISE, avoid that as much as possible!
517 517
                         //$safe_file = api_replace_dangerous_char($file, 'strict');
518 518
                         $find_str = array('\\', '.php', '.phtml');
519
-                        $repl_str = array('/',  '.txt', '.txt');
519
+                        $repl_str = array('/', '.txt', '.txt');
520 520
                         $safe_file = str_replace($find_str, $repl_str, $file);
521 521
 
522 522
                         if ($safe_file != $file) {
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
         if ($this->debug > 0) { error_log('In aicc::get_res_path('.$id.') method', 0); }
718 718
         $path = '';
719 719
         if (isset($this->resources[$id])) {
720
-            $oRes =& $this->resources[$id];
720
+            $oRes = & $this->resources[$id];
721 721
             $path = @$oRes->get_path();
722 722
         }
723 723
         return $path;
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
         if ($this->debug > 0) { error_log('In aicc::get_res_type('.$id.') method', 0); }
734 734
         $type = '';
735 735
         if (isset($this->resources[$id])) {
736
-            $oRes =& $this->resources[$id];
736
+            $oRes = & $this->resources[$id];
737 737
             $temptype = $oRes->get_scorm_type();
738 738
             if (!empty($temptype)) {
739 739
                 $type = $temptype;
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
      * Gets the default organisation's title
747 747
      * @return	string	The organization's title
748 748
      */
749
-    function get_title(){
749
+    function get_title() {
750 750
         if ($this->debug > 0) { error_log('In aicc::get_title() method', 0); }
751 751
         $title = '';
752 752
         if (isset($this->config['organizations']['default'])) {
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
             $chr = $data{$i};
908 908
             switch ($chr) {
909 909
                 case $enclosure:
910
-                    if ($enclosed && $data{$i+1} == $enclosure) {
910
+                    if ($enclosed && $data{$i + 1} == $enclosure) {
911 911
                         $fldval .= $chr;
912 912
                         ++$i; // Skip the next character.
913 913
                     } else
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
                         $fldval .= $chr;
922 922
                     break;
923 923
                 case "\r":
924
-                    if (!$enclosed&&$data{$i+1} == "\n")
924
+                    if (!$enclosed && $data{$i + 1} == "\n")
925 925
                         continue;
926 926
                 case "\n":
927 927
                     if (!$enclosed) {
@@ -932,7 +932,7 @@  discard block
 block discarded – undo
932 932
                         $fldval .= $chr;
933 933
                     break;
934 934
                 case "\\r":
935
-                    if (!$enclosed&&$data{$i+1} == "\\n")
935
+                    if (!$enclosed && $data{$i + 1} == "\\n")
936 936
                         continue;
937 937
                 case "\\n":
938 938
                     if (!$enclosed) {
Please login to merge, or discard this patch.
Braces   +24 added lines, -15 removed lines patch added patch discarded remove patch
@@ -459,11 +459,12 @@  discard block
 block discarded – undo
459 459
             }
460 460
         }
461 461
 
462
-        if ($package_type == '' || !$mandatory)
463
-        // && defined('CHECK_FOR_AICC') && CHECK_FOR_AICC)
462
+        if ($package_type == '' || !$mandatory) {
463
+                // && defined('CHECK_FOR_AICC') && CHECK_FOR_AICC)
464 464
         {
465 465
             return api_failure::set_failure('not_aicc_content');
466 466
         }
467
+        }
467 468
 
468 469
         if (!enough_size($realFileSize, $course_sys_dir, $maxFilledSpace)) {
469 470
             return api_failure::set_failure('not_enough_space');
@@ -511,7 +512,9 @@  discard block
 block discarded – undo
511 512
                     if ($file != '.' && $file != '..') {
512 513
                         $filetype = 'file';
513 514
 
514
-                        if (is_dir($course_sys_dir.$new_dir.$file)) $filetype = 'folder';
515
+                        if (is_dir($course_sys_dir.$new_dir.$file)) {
516
+                            $filetype = 'folder';
517
+                        }
515 518
 
516 519
                         // TODO: RENAMING FILES CAN BE VERY DANGEROUS AICC-WISE, avoid that as much as possible!
517 520
                         //$safe_file = api_replace_dangerous_char($file, 'strict');
@@ -910,37 +913,43 @@  discard block
 block discarded – undo
910 913
                     if ($enclosed && $data{$i+1} == $enclosure) {
911 914
                         $fldval .= $chr;
912 915
                         ++$i; // Skip the next character.
913
-                    } else
914
-                        $enclosed = !$enclosed;
916
+                    } else {
917
+                                            $enclosed = !$enclosed;
918
+                    }
915 919
                     break;
916 920
                 case $delim:
917 921
                     if (!$enclosed) {
918 922
                         $ret_array[$linecount][$fldcount++] = $fldval;
919 923
                         $fldval = '';
920
-                    } else
921
-                        $fldval .= $chr;
924
+                    } else {
925
+                                            $fldval .= $chr;
926
+                    }
922 927
                     break;
923 928
                 case "\r":
924
-                    if (!$enclosed&&$data{$i+1} == "\n")
925
-                        continue;
929
+                    if (!$enclosed&&$data{$i+1} == "\n") {
930
+                                            continue;
931
+                    }
926 932
                 case "\n":
927 933
                     if (!$enclosed) {
928 934
                         $ret_array[$linecount++][$fldcount] = $fldval;
929 935
                         $fldcount = 0;
930 936
                         $fldval = '';
931
-                    } else
932
-                        $fldval .= $chr;
937
+                    } else {
938
+                                            $fldval .= $chr;
939
+                    }
933 940
                     break;
934 941
                 case "\\r":
935
-                    if (!$enclosed&&$data{$i+1} == "\\n")
936
-                        continue;
942
+                    if (!$enclosed&&$data{$i+1} == "\\n") {
943
+                                            continue;
944
+                    }
937 945
                 case "\\n":
938 946
                     if (!$enclosed) {
939 947
                         $ret_array[$linecount++][$fldcount] = $fldval;
940 948
                         $fldcount = 0;
941 949
                         $fldval = '';
942
-                    } else
943
-                        $fldval .= $chr;
950
+                    } else {
951
+                                            $fldval .= $chr;
952
+                    }
944 953
                     break;
945 954
                 default:
946 955
                     $fldval .= $chr;
Please login to merge, or discard this patch.
main/newscorm/learnpath_functions.inc.php 1 patch
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -60,6 +60,7 @@
 block discarded – undo
60 60
 /**
61 61
  * This function deletes an entire directory
62 62
  * @param	string	The directory path
63
+ * @param string $dir
63 64
  * @return boolean	True on success, false on failure
64 65
  */
65 66
 function deldir($dir) {
Please login to merge, or discard this patch.
main/newscorm/learnpathList.class.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
      * @param   int     $categoryId
35 35
      * @param bool $ignoreCategoryFilter
36 36
      *
37
-     * @return	void
37
+     * @return	false|null
38 38
      */
39 39
     public function __construct(
40 40
         $user_id,
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
                     ";
106 106
         $res = Database::query($sql);
107 107
         $names = array();
108
-        while ($row = Database::fetch_array($res,'ASSOC')) {
108
+        while ($row = Database::fetch_array($res, 'ASSOC')) {
109 109
             // Use domesticate here instead of Database::escape_string because
110 110
             // it prevents ' to be slashed and the input (done by learnpath.class.php::toggle_visibility())
111 111
             // is done using domesticate()
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 
236 236
         $lessons = array();
237 237
         while ($row = Database::fetch_array($result)) {
238
-            if (api_get_item_visibility($course, 'learnpath', $row['id'],  $session_id)) {
238
+            if (api_get_item_visibility($course, 'learnpath', $row['id'], $session_id)) {
239 239
                 $lessons[$row['id']] = $row;
240 240
             }
241 241
         }
Please login to merge, or discard this patch.
main/newscorm/lp_ajax_save_item.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,9 +20,9 @@
 block discarded – undo
20 20
  * @param   int $user_id User ID
21 21
  * @param   int $view_id View ID
22 22
  * @param   int $item_id Item ID
23
- * @param   float  $score Current score
24
- * @param   float  $max Maximum score
25
- * @param   float  $min Minimum score
23
+ * @param   integer  $score Current score
24
+ * @param   integer  $max Maximum score
25
+ * @param   integer  $min Minimum score
26 26
  * @param   string  $status Lesson status
27 27
  * @param   int  $time Session time
28 28
  * @param   string  $suspend Suspend data
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -458,7 +458,7 @@
 block discarded – undo
458 458
     }
459 459
 
460 460
     if ($myLP->get_type() == 2) {
461
-         $return .= "update_stats();";
461
+            $return .= "update_stats();";
462 462
     }
463 463
 
464 464
     // To be sure progress is updated.
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         // Set status to completed for hotpotatoes if score > 80%.
164 164
         if ($my_type == 'hotpotatoes') {
165 165
             if ((empty($status) || $status == 'undefined' || $status == 'not attempted') && $max > 0) {
166
-                if (($score/$max) > 0.8) {
166
+                if (($score / $max) > 0.8) {
167 167
                     $myStatus = 'completed';
168 168
                     if ($debug > 1) {
169 169
                         error_log('Calling set_status('.$myStatus.') for hotpotatoes', 0);
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
                         error_log('Done calling set_status for hotpotatoes - now '.$myLPI->get_status(false), 0);
175 175
                     }
176 176
                 }
177
-            } elseif ($status == 'completed' && $max > 0 && ($score/$max) < 0.8) {
177
+            } elseif ($status == 'completed' && $max > 0 && ($score / $max) < 0.8) {
178 178
                 $myStatus = 'failed';
179 179
                 if ($debug > 1) {
180 180
                     error_log('Calling set_status('.$myStatus.') for hotpotatoes', 0);
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
             $myLPI->current_data = $suspend;
368 368
         }
369 369
 
370
-        if (isset($location) && $location != '' && $location!='undefined') {
370
+        if (isset($location) && $location != '' && $location != 'undefined') {
371 371
             $myLPI->set_lesson_location($location);
372 372
         }
373 373
 
Please login to merge, or discard this patch.