[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/installation/includes/xajax/ -> xajax.inc.php (source)

   1  <?php
   2  ///////////////////////////////////////////////////////////////////////////////
   3  // xajax.inc.php::Main xajax class and setup file
   4  //
   5  // xajax version 0.2
   6  // Copyright (C) 2005 - 2006 by Jared White & J. Max Wilson
   7  // http://xajax.sourceforge.net
   8  //
   9  // xajax is an open source PHP class library for easily creating powerful
  10  // PHP-driven, web-based AJAX Applications. Using xajax, you can asynchronously
  11  // call PHP functions and update the content of your your webpage without
  12  // reloading the page.
  13  //
  14  // xajax is released under the terms of the LGPL license
  15  // http://www.gnu.org/copyleft/lesser.html#SEC3
  16  //
  17  // This library is free software; you can redistribute it and/or
  18  // modify it under the terms of the GNU Lesser General Public
  19  // License as published by the Free Software Foundation; either
  20  // version 2.1 of the License, or (at your option) any later version.
  21  //
  22  // This library is distributed in the hope that it will be useful,
  23  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  24  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  25  // Lesser General Public License for more details.
  26  //
  27  // You should have received a copy of the GNU Lesser General Public
  28  // License along with this library; if not, write to the Free Software
  29  // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  30  ///////////////////////////////////////////////////////////////////////////////
  31  
  32  // Define XAJAX_DEFAULT_CHAR_ENCODING that is used by both
  33  // the xajax and xajaxResponse classes
  34  if (!defined ('XAJAX_DEFAULT_CHAR_ENCODING')) {
  35      define ('XAJAX_DEFAULT_CHAR_ENCODING', 'utf-8' );
  36  }
  37  
  38  require_once(dirname( __FILE__ ).DIRECTORY_SEPARATOR."xajaxResponse.inc.php");
  39  
  40  // Communication Method Defines
  41  if (!defined ('XAJAX_GET'))
  42  {
  43      define ('XAJAX_GET', 0);
  44  }
  45  if (!defined ('XAJAX_POST'))
  46  {
  47      define ('XAJAX_POST', 1);
  48  }
  49  
  50  // the xajax class generates the xajax javascript for your page including the
  51  // javascript wrappers for the PHP functions that you want to call from your page.
  52  // It also handles processing and executing the command messages in the xml responses
  53  // sent back to your page from your PHP functions.
  54  class xajax
  55  {
  56      var $aFunctions;                // Array of PHP functions that will be callable through javascript wrappers
  57      var $aObjects;                // Array of object callbacks that will allow Javascript to call PHP methods (key=function name)
  58      var $aFunctionRequestTypes;    // Array of RequestTypes to be used with each function (key=function name)
  59      var $aFunctionIncludeFiles;    // Array of Include Files for any external functions (key=function name)
  60      var $sCatchAllFunction;        // Name of the PHP function to call if no callable function was found
  61      var $sPreFunction;            // Name of the PHP function to call before any other function
  62      var $sRequestURI;            // The URI for making requests to the xajax object
  63      var $bDebug;                    // Show debug messages (true/false)
  64      var $bExitAllowed;            // Allow xajax to exit after processing a request (true/false)
  65      var $bErrorHandler;            // Use an special xajax error handler so the errors are sent to the browser properly
  66      var $sLogFile;                // Specify if xajax should log errors (and more information in a future release)
  67      var $sWrapperPrefix;            // The prefix to prepend to the javascript wraper function name
  68      var $bStatusMessages;            // Show debug messages (true/false)
  69      var $bWaitCursor;            // Use wait cursor in browser (true/false)
  70      var $bCleanBuffer;            // Clean all output buffers before outputting response (true/false)
  71      var $aObjArray;                // Array for parsing complex objects
  72      var $iPos;                    // Position in $aObjArray
  73      var $sEncoding;                // The Character Encoding to use
  74  
  75      // Contructor
  76      // $sRequestURI - defaults to the current page
  77      // $sWrapperPrefix - defaults to "xajax_";
  78      // $sEncoding - defaults to XAJAX_DEFAULT_CHAR_ENCODING defined above
  79      // $bDebug Mode - defaults to false
  80      // usage: $xajax = new xajax();
  81  	function xajax($sRequestURI="",$sWrapperPrefix="xajax_",$sEncoding=XAJAX_DEFAULT_CHAR_ENCODING,$bDebug=false)
  82      {
  83          $this->aFunctions = array();
  84          $this->aObjects = array();
  85          $this->aFunctionIncludeFiles = array();
  86          $this->sRequestURI = $sRequestURI;
  87          if ($this->sRequestURI == "")
  88              $this->sRequestURI = $this->_detectURI();
  89          $this->sWrapperPrefix = $sWrapperPrefix;
  90          $this->setCharEncoding($sEncoding);
  91          $this->bDebug = $bDebug;
  92          $this->bWaitCursor = true;
  93          $this->bExitAllowed = true;
  94          $this->bErrorHandler = false;
  95          $this->sLogFile = "";
  96          $this->bCleanBuffer = true;
  97      }
  98  
  99      // setRequestURI() sets the URI to which requests will be made
 100      // usage: $xajax->setRequestURI("http://xajax.sourceforge.net");
 101  	function setRequestURI($sRequestURI)
 102      {
 103          $this->sRequestURI = $sRequestURI;
 104      }
 105  
 106      // debugOn() enables debug messages for xajax
 107  	function debugOn()
 108      {
 109          $this->bDebug = true;
 110      }
 111  
 112      // debugOff() disables debug messages for xajax (default behavior)
 113  	function debugOff()
 114      {
 115          $this->bDebug = false;
 116      }
 117  
 118      // statusMessagesOn() enables messages in the statusbar for xajax
 119  	function statusMessagesOn()
 120      {
 121          $this->bStatusMessages = true;
 122      }
 123  
 124      // statusMessagesOff() disables messages in the statusbar for xajax (default behavior)
 125  	function statusMessagesOff()
 126      {
 127          $this->bStatusMessages = false;
 128      }
 129  
 130      // waitCursor() enables the wait cursor to be displayed in the browser (default behavior)
 131  	function waitCursorOn()
 132      {
 133          $this->bWaitCursor = true;
 134      }
 135  
 136      // waitCursorOff() disables the wait cursor to be displayed in the browser
 137  	function waitCursorOff()
 138      {
 139          $this->bWaitCursor = false;
 140      }
 141  
 142      // exitAllowedOn() enables xajax to exit immediately after processing a request
 143      // and sending the response back to the browser (default behavior)
 144  	function exitAllowedOn()
 145      {
 146          $this->bExitAllowed = true;
 147      }
 148  
 149      // exitAllowedOff() disables xajax's default behavior of exiting immediately
 150      // after processing a request and sending the response back to the browser
 151  	function exitAllowedOff()
 152      {
 153          $this->bExitAllowed = false;
 154      }
 155  
 156      // errorHandlerOn() turns on xajax's error handling system so that PHP errors
 157      // that occur during a request are trapped and pushed to the browser in the
 158      // form of a Javascript alert
 159  	function errorHandlerOn()
 160      {
 161          $this->bErrorHandler = true;
 162      }
 163      // errorHandlerOff() turns off xajax's error handling system (default behavior)
 164  	function errorHandlerOff()
 165      {
 166          $this->bErrorHandler = false;
 167      }
 168  
 169      // setLogFile() specifies a log file that will be written to by xajax during
 170      // a request (used only by the error handling system at present). If you don't
 171      // invoke this method, or you pass in "", then no log file will be written to.
 172      // usage: $xajax->setLogFile("/xajax_logs/errors.log");
 173  	function setLogFile($sFilename)
 174      {
 175          $this->sLogFile = $sFilename;
 176      }
 177  
 178      // cleanBufferOn() causes xajax to clean out all output buffers before outputting
 179      // a response (default behavior)
 180  	function cleanBufferOn()
 181      {
 182          $this->bCleanBuffer = true;
 183      }
 184      // cleanBufferOff() turns off xajax's output buffer cleaning
 185  	function cleanBufferOff()
 186      {
 187          $this->bCleanBuffer = false;
 188      }
 189  
 190      // setWrapperPrefix() sets the prefix that will be appended to the Javascript
 191      // wrapper functions (default is "xajax_").
 192  	function setWrapperPrefix($sPrefix)
 193      {
 194          $this->sWrapperPrefix = $sPrefix;
 195      }
 196  
 197      // setCharEncoding() sets the character encoding to be used by xajax
 198      // usage: $xajax->setCharEncoding("utf-8");
 199      // *Note: to change the default character encoding for all xajax responses, set
 200      // the XAJAX_DEFAULT_CHAR_ENCODING constant near the beginning of the xajax.inc.php file
 201  	function setCharEncoding($sEncoding)
 202      {
 203          $this->sEncoding = $sEncoding;
 204      }
 205  
 206      // registerFunction() registers a PHP function or method to be callable through
 207      // xajax in your Javascript. If you want to register a function, pass in the name
 208      // of that function. If you want to register a static class method, pass in an array
 209      // like so:
 210      // array("myFunctionName", "myClass", "myMethod")
 211      // For an object instance method, use an object variable for the second array element
 212      // (and in PHP 4 make sure you put an & before the variable to pass the object by
 213      // reference). Note: the function name is what you call via Javascript, so it can be
 214      // anything as long as it doesn't conflict with any other registered function name.
 215      //
 216      // $mFunction is a string containing the function name or an object callback array
 217      // $sRequestType is the RequestType (XAJAX_GET/XAJAX_POST) that should be used
 218      //        for this function.  Defaults to XAJAX_POST.
 219      // usage: $xajax->registerFunction("myFunction");
 220      //    or: $xajax->registerFunction(array("myFunctionName", &$myObject, "myMethod"));
 221  	function registerFunction($mFunction,$sRequestType=XAJAX_POST)
 222      {
 223          if (is_array($mFunction)) {
 224              $this->aFunctions[$mFunction[0]] = 1;
 225              $this->aFunctionRequestTypes[$mFunction[0]] = $sRequestType;
 226              $this->aObjects[$mFunction[0]] = array_slice($mFunction, 1);
 227          }
 228          else {
 229              $this->aFunctions[$mFunction] = 1;
 230              $this->aFunctionRequestTypes[$mFunction] = $sRequestType;
 231          }
 232      }
 233  
 234      // registerExternalFunction() registers a PHP function to be callable through xajax
 235      // which is located in some other file.  If the function is requested the external
 236      // file will be included to define the function before the function is called
 237      // $mFunction is a string containing the function name or an object callback array
 238      //   see registerFunction() for more info on object callback arrays
 239      // $sIncludeFile is a string containing the path and filename of the include file
 240      // $sRequestType is the RequestType (XAJAX_GET/XAJAX_POST) that should be used
 241      //        for this function.  Defaults to XAJAX_POST.
 242      // usage: $xajax->registerExternalFunction("myFunction","myFunction.inc.php",XAJAX_POST);
 243  	function registerExternalFunction($mFunction,$sIncludeFile,$sRequestType=XAJAX_POST)
 244      {
 245          $this->registerFunction($mFunction, $sRequestType);
 246  
 247          if (is_array($mFunction)) {
 248              $this->aFunctionIncludeFiles[$mFunction[0]] = $sIncludeFile;
 249          }
 250          else {
 251              $this->aFunctionIncludeFiles[$mFunction] = $sIncludeFile;
 252          }
 253      }
 254  
 255      // registerCatchAllFunction() registers a PHP function to be called when xajax cannot
 256      // find the function being called via Javascript. Because this is technically
 257      // impossible when using "wrapped" functions, the catch-all feature is only useful
 258      // when you're directly using the xajax.call() Javascript method. Use the catch-all
 259      // feature when you want more dynamic ability to intercept unknown calls and handle
 260      // them in a custom way.
 261      // $mFunction is a string containing the function name or an object callback array
 262      //   see registerFunction() for more info on object callback arrays
 263      // usage: $xajax->registerCatchAllFunction("myCatchAllFunction");
 264  	function registerCatchAllFunction($mFunction)
 265      {
 266          if (is_array($mFunction)) {
 267              $this->sCatchAllFunction = $mFunction[0];
 268              $this->aObjects[$mFunction[0]] = array_slice($mFunction, 1);
 269          }
 270          else {
 271              $this->sCatchAllFunction = $mFunction;
 272          }
 273      }
 274  
 275      // registerPreFunction() registers a PHP function to be called before xajax calls
 276      // the requested function. xajax will automatically add the request function's response
 277      // to the pre-function's response to create a single response. Another feature is
 278      // the ability to return not just a response, but an array with the first element
 279      // being false (a boolean) and the second being the response. In this case, the
 280      // pre-function's response will be returned to the browser without xajax calling
 281      // the requested function.
 282      // $mFunction is a string containing the function name or an object callback array
 283      //   see registerFunction() for more info on object callback arrays
 284      // usage $xajax->registerPreFunction("myPreFunction");
 285  	function registerPreFunction($mFunction)
 286      {
 287          if (is_array($mFunction)) {
 288              $this->sPreFunction = $mFunction[0];
 289              $this->aObjects[$mFunction[0]] = array_slice($mFunction, 1);
 290          }
 291          else {
 292              $this->sPreFunction = $mFunction;
 293          }
 294      }
 295  
 296      // returns true if xajax can process the request, false if otherwise
 297      // you can use this to determine if xajax needs to process the request or not
 298  	function canProcessRequests()
 299      {
 300          if ($this->getRequestMode() != -1) return true;
 301          return false;
 302      }
 303  
 304      // returns the current request mode, or -1 if there is none
 305  	function getRequestMode()
 306      {
 307          if (!empty($_GET["xajax"]))
 308              return XAJAX_GET;
 309  
 310          if (!empty($_POST["xajax"]))
 311              return XAJAX_POST;
 312  
 313          return -1;
 314      }
 315  
 316      // processRequests() is the main communications engine of xajax
 317      // The engine handles all incoming xajax requests, calls the apporiate PHP functions
 318      // and passes the xml responses back to the javascript response handler
 319      // if your RequestURI is the same as your web page then this function should
 320      // be called before any headers or html has been sent.
 321      // usage: $xajax->processRequests()
 322  	function processRequests()
 323      {
 324  
 325          $requestMode = -1;
 326          $sFunctionName = "";
 327          $bFoundFunction = true;
 328          $bFunctionIsCatchAll = false;
 329          $sFunctionNameForSpecial = "";
 330          $aArgs = array();
 331          $sPreResponse = "";
 332          $bEndRequest = false;
 333          $sResponse = "";
 334  
 335          $requestMode = $this->getRequestMode();
 336          if ($requestMode == -1) return;
 337  
 338          if ($requestMode == XAJAX_POST)
 339          {
 340              $sFunctionName = $_POST["xajax"];
 341  
 342              if (!empty($_POST["xajaxargs"]))
 343                  $aArgs = $_POST["xajaxargs"];
 344          }
 345          else
 346          {
 347              header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
 348              header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
 349              header ("Cache-Control: no-cache, must-revalidate");
 350              header ("Pragma: no-cache");
 351              header("Content-type: text/xml");
 352  
 353              $sFunctionName = $_GET["xajax"];
 354  
 355              if (!empty($_GET["xajaxargs"]))
 356                  $aArgs = $_GET["xajaxargs"];
 357          }
 358  
 359          // Use xajax error handler if necessary
 360          if ($this->bErrorHandler) {
 361              $GLOBALS['xajaxErrorHandlerText'] = "";
 362              set_error_handler("xajaxErrorHandler");
 363          }
 364  
 365          if ($this->sPreFunction) {
 366              if (!$this->_isFunctionCallable($this->sPreFunction)) {
 367                  $bFoundFunction = false;
 368                  $objResponse = new xajaxResponse();
 369                  $objResponse->addAlert("Unknown Pre-Function ". $this->sPreFunction);
 370                  $sResponse = $objResponse->getXML();
 371              }
 372          }
 373          //include any external dependencies associated with this function name
 374          if (array_key_exists($sFunctionName,$this->aFunctionIncludeFiles))
 375          {
 376              ob_start();
 377              include_once($this->aFunctionIncludeFiles[$sFunctionName]);
 378              ob_end_clean();
 379          }
 380  
 381          if ($bFoundFunction) {
 382              $sFunctionNameForSpecial = $sFunctionName;
 383              if (!array_key_exists($sFunctionName, $this->aFunctions))
 384              {
 385                  if ($this->sCatchAllFunction) {
 386                      $sFunctionName = $this->sCatchAllFunction;
 387                      $bFunctionIsCatchAll = true;
 388                  }
 389                  else {
 390                      $bFoundFunction = false;
 391                      $objResponse = new xajaxResponse();
 392                      $objResponse->addAlert("Unknown Function $sFunctionName.");
 393                      $sResponse = $objResponse->getXML();
 394                  }
 395              }
 396              else if ($this->aFunctionRequestTypes[$sFunctionName] != $requestMode)
 397              {
 398                  $bFoundFunction = false;
 399                  $objResponse = new xajaxResponse();
 400                  $objResponse->addAlert("Incorrect Request Type.");
 401                  $sResponse = $objResponse->getXML();
 402              }
 403          }
 404  
 405          if ($bFoundFunction)
 406          {
 407              for ($i = 0; $i < sizeof($aArgs); $i++)
 408              {
 409                  // If magic quotes is on, then we need to strip the slashes from the args
 410                  if (get_magic_quotes_gpc() == 1 && is_string($aArgs[$i])) {
 411  
 412                      $aArgs[$i] = stripslashes($aArgs[$i]);
 413                  }
 414                  if (stristr($aArgs[$i],"<xjxobj>") != false)
 415                  {
 416                      $aArgs[$i] = $this->_xmlToArray("xjxobj",$aArgs[$i]);
 417                  }
 418                  else if (stristr($aArgs[$i],"<xjxquery>") != false)
 419                  {
 420                      $aArgs[$i] = $this->_xmlToArray("xjxquery",$aArgs[$i]);
 421                  }
 422              }
 423  
 424              if ($this->sPreFunction) {
 425                  $mPreResponse = $this->_callFunction($this->sPreFunction, array($sFunctionNameForSpecial, $aArgs));
 426                  if (is_array($mPreResponse) && $mPreResponse[0] === false) {
 427                      $bEndRequest = true;
 428                      $sPreResponse = $mPreResponse[1];
 429                  }
 430                  else {
 431                      $sPreResponse = $mPreResponse;
 432                  }
 433                  if (is_a($sPreResponse, "xajaxResponse")) {
 434                      $sPreResponse = $sPreResponse->getXML();
 435                  }
 436                  if ($bEndRequest) $sResponse = $sPreResponse;
 437              }
 438  
 439              if (!$bEndRequest) {
 440                  if (!$this->_isFunctionCallable($sFunctionName)) {
 441                      $objResponse = new xajaxResponse();
 442                      $objResponse->addAlert("The Registered Function $sFunctionName Could Not Be Found.");
 443                      $sResponse = $objResponse->getXML();
 444                  }
 445                  else {
 446                      if ($bFunctionIsCatchAll) {
 447                          $aArgs = array($sFunctionNameForSpecial, $aArgs);
 448                      }
 449                      $sResponse = $this->_callFunction($sFunctionName, $aArgs);
 450                  }
 451                  if (is_a($sResponse, "xajaxResponse")) {
 452                      $sResponse = $sResponse->getXML();
 453                  }
 454                  if (!is_string($sResponse) || strpos($sResponse, "<xjx>") === FALSE) {
 455                      $objResponse = new xajaxResponse();
 456                      $objResponse->addAlert("No XML Response Was Returned By Function $sFunctionName.");
 457                      $sResponse = $objResponse->getXML();
 458                  }
 459                  else if ($sPreResponse != "") {
 460                      $sNewResponse = new xajaxResponse();
 461                      $sNewResponse->loadXML($sPreResponse);
 462                      $sNewResponse->loadXML($sResponse);
 463                      $sResponse = $sNewResponse->getXML();
 464                  }
 465              }
 466          }
 467  
 468          $sContentHeader = "Content-type: text/xml;";
 469          if ($this->sEncoding && strlen(trim($this->sEncoding)) > 0)
 470              $sContentHeader .= " charset=".$this->sEncoding;
 471          header($sContentHeader);
 472          if ($this->bErrorHandler && !empty( $GLOBALS['xajaxErrorHandlerText'] )) {
 473              $sErrorResponse = new xajaxResponse();
 474              $sErrorResponse->addAlert("** PHP Error Messages: **" . $GLOBALS['xajaxErrorHandlerText']);
 475              if ($this->sLogFile) {
 476                  $fH = @fopen($this->sLogFile, "a");
 477                  if (!$fH) {
 478                      $sErrorResponse->addAlert("** Logging Error **\n\nxajax was unable to write to the error log file:\n" . $this->sLogFile);
 479                  }
 480                  else {
 481                      fwrite($fH, "** xajax Error Log - " . strftime("%b %e %Y %I:%M:%S %p") . " **" . $GLOBALS['xajaxErrorHandlerText'] . "\n\n\n");
 482                      fclose($fH);
 483                  }
 484              }
 485  
 486              $sErrorResponse->loadXML($sResponse);
 487              $sResponse = $sErrorResponse->getXML();
 488  
 489          }
 490          if ($this->bCleanBuffer) while (@ob_end_clean());
 491          print $sResponse;
 492          if ($this->bErrorHandler) restore_error_handler();
 493  
 494          if ($this->bExitAllowed)
 495              exit();
 496      }
 497  
 498      // printJavascript() prints the xajax javascript code into your page by printing
 499      // the output of the getJavascript() method. It should only be called between the
 500      // <head> </head> tags in your HTML page. Remember, if you only want to obtain the
 501      // result of this function, use getJavascript() instead.
 502      // $sJsURI is the relative address of the folder where xajax has been installed.
 503      //   For instance, if your PHP file is "http://www.myserver.com/myfolder/mypage.php"
 504      //   and xajax was installed in "http://www.myserver.com/anotherfolder", then
 505      //   $sJsURI should be set to "../anotherfolder". Defaults to assuming xajax is in
 506      //   the same folder as your PHP file.
 507      // $sJsFile is the relative folder/file pair of the xajax Javascript engine located
 508      // within the xajax installation folder. Defaults to xajax_js/xajax.js.
 509      // usage:
 510      //    <head>
 511      //        ...
 512      //        < ?php $xajax->printJavascript(); ? >
 513  	function printJavascript($sJsURI="", $sJsFile=NULL, $sJsFullFilename=NULL)
 514      {
 515          print $this->getJavascript($sJsURI, $sJsFile, $sJsFullFilename);
 516      }
 517  
 518      // getJavascript() returns the xajax javascript code that should be added to
 519      // your HTML page between the <head> </head> tags. See printJavascript()
 520      // for information about the function arguments.
 521      // usage:
 522      //  < ?php $xajaxJSHead = $xajax->getJavascript(); ? >
 523      //    <head>
 524      //        ...
 525      //        < ?php echo $xajaxJSHead; ? >
 526  	function getJavascript($sJsURI="", $sJsFile=NULL, $sJsFullFilename=NULL)
 527      {
 528          if ($sJsFile == NULL) $sJsFile = "xajax_js/xajax.js";
 529  
 530          if ($sJsURI != "" && substr($sJsURI, -1) != "/") $sJsURI .= "/";
 531  
 532          $html  = "\t<script type=\"text/javascript\">\n";
 533          $html .= "var xajaxRequestUri=\"".$this->sRequestURI."\";\n";
 534          $html .= "var xajaxDebug=".($this->bDebug?"true":"false").";\n";
 535          $html .= "var xajaxStatusMessages=".($this->bStatusMessages?"true":"false").";\n";
 536          $html .= "var xajaxWaitCursor=".($this->bWaitCursor?"true":"false").";\n";
 537          $html .= "var xajaxDefinedGet=".XAJAX_GET.";\n";
 538          $html .= "var xajaxDefinedPost=".XAJAX_POST.";\n";
 539  
 540          foreach($this->aFunctions as $sFunction => $bExists) {
 541              $html .= $this->_wrap($sFunction,$this->aFunctionRequestTypes[$sFunction]);
 542          }
 543  
 544          $html .= "</script>\n";
 545  
 546          // Create a compressed file if necessary
 547          if ($sJsFullFilename) {
 548              $realJsFile = $sJsFullFilename;
 549          }
 550          else {
 551              $realPath = realpath(dirname(__FILE__));
 552              $realJsFile = $realPath . "/". $sJsFile;
 553          }
 554          $srcFile = str_replace(".js", "_uncompressed.js", $realJsFile);
 555          if (!file_exists($srcFile)) {
 556              trigger_error("The xajax uncompressed Javascript file could not be found in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR);
 557          }
 558  
 559          if ($this->bDebug) {
 560              if (!@copy($srcFile, $realJsFile)) {
 561                  trigger_error("The xajax uncompressed javascript file could not be copied to the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR);
 562              }
 563          }
 564          else if (!file_exists($realJsFile)) {
 565              require(dirname($realJsFile) . "/xajaxCompress.php");
 566              $javaScript = implode('', file($srcFile));
 567              $compressedScript = xajaxCompressJavascript($javaScript);
 568              $fH = @fopen($realJsFile, "w");
 569              if (!$fH) {
 570                  trigger_error("The xajax compressed javascript file could not be written in the <b>" . dirname($realJsFile) . "</b> folder. Error ", E_USER_ERROR);
 571              }
 572              else {
 573                  fwrite($fH, $compressedScript);
 574                  fclose($fH);
 575              }
 576          }
 577  
 578          $html .= "\t<script type=\"text/javascript\" src=\"" . $sJsURI . $sJsFile . "\"></script>\n";
 579  
 580          return $html;
 581      }
 582  
 583      // _detectURL() returns the current URL based upon the SERVER vars
 584      // used internally
 585  	function _detectURI() {
 586          $aURL = array();
 587  
 588          // Try to get the request URL
 589          if (!empty($_SERVER['REQUEST_URI'])) {
 590              $aURL = parse_url($_SERVER['REQUEST_URI']);
 591          }
 592  
 593          // Fill in the empty values
 594          if (empty($aURL['scheme'])) {
 595              if (!empty($_SERVER['HTTP_SCHEME'])) {
 596                  $aURL['scheme'] = $_SERVER['HTTP_SCHEME'];
 597              } else {
 598                  $aURL['scheme'] = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ? 'https' : 'http';
 599              }
 600          }
 601  
 602          if (empty($aURL['host'])) {
 603              if (!empty($_SERVER['HTTP_HOST'])) {
 604                  if (strpos($_SERVER['HTTP_HOST'], ':') > 0) {
 605                      list($aURL['host'], $aURL['port']) = explode(':', $_SERVER['HTTP_HOST']);
 606                  } else {
 607                      $aURL['host'] = $_SERVER['HTTP_HOST'];
 608                  }
 609              } else if (!empty($_SERVER['SERVER_NAME'])) {
 610                  $aURL['host'] = $_SERVER['SERVER_NAME'];
 611              } else {
 612                  print "xajax Error: xajax failed to automatically identify your Request URI.";
 613                  print "Please set the Request URI explicitly when you instantiate the xajax object.";
 614                  exit();
 615              }
 616          }
 617  
 618          if (empty($aURL['port']) && !empty($_SERVER['SERVER_PORT'])) {
 619              $aURL['port'] = $_SERVER['SERVER_PORT'];
 620          }
 621  
 622          if (empty($aURL['path'])) {
 623              if (!empty($_SERVER['PATH_INFO'])) {
 624                  $sPath = parse_url($_SERVER['PATH_INFO']);
 625              } else {
 626                  $sPath = parse_url(str_replace(array('"', '<', '>', "'"), '', $_SERVER["PHP_SELF"]));
 627              }
 628              $aURL['path'] = $sPath['path'];
 629              unset($sPath);
 630          }
 631  
 632          if (!empty($aURL['query'])) {
 633              $aURL['query'] = '?'.$aURL['query'];
 634          }
 635  
 636          // Build the URL: Start with scheme, user and pass
 637          $sURL = $aURL['scheme'].'://';
 638          if (!empty($aURL['user'])) {
 639              $sURL.= $aURL['user'];
 640              if (!empty($aURL['pass'])) {
 641                  $sURL.= ':'.$aURL['pass'];
 642              }
 643              $sURL.= '@';
 644          }
 645  
 646          // Add the host
 647          $sURL.= $aURL['host'];
 648  
 649          // Add the port if needed
 650          if (!empty($aURL['port']) && (($aURL['scheme'] == 'http' && $aURL['port'] != 80) || ($aURL['scheme'] == 'https' && $aURL['port'] != 443))) {
 651              $sURL.= ':'.$aURL['port'];
 652          }
 653  
 654          // Add the path and the query string
 655          $sURL.= $aURL['path'].@$aURL['query'];
 656  
 657          // Clean up
 658          unset($aURL);
 659          return $sURL;
 660      }
 661  
 662      // returns true if the function name is associated with an object callback,
 663      // false if not.
 664      // user internally
 665  	function _isObjectCallback($sFunction)
 666      {
 667          if (array_key_exists($sFunction, $this->aObjects)) return true;
 668          return false;
 669      }
 670  
 671      // return true if the function or object callback can be called, false if not
 672      // user internally
 673  	function _isFunctionCallable($sFunction)
 674      {
 675          if ($this->_isObjectCallback($sFunction)) {
 676              if (is_object($this->aObjects[$sFunction][0])) {
 677                  return method_exists($this->aObjects[$sFunction][0], $this->aObjects[$sFunction][1]);
 678              }
 679              else {
 680                  return is_callable($this->aObjects[$sFunction]);
 681              }
 682          }
 683          else {
 684              return function_exists($sFunction);
 685          }
 686      }
 687  
 688      // calls the function, class method, or object method with the supplied arguments
 689      // user internally
 690  	function _callFunction($sFunction, $aArgs)
 691      {
 692          if ($this->_isObjectCallback($sFunction)) {
 693              $mReturn = call_user_func_array($this->aObjects[$sFunction], $aArgs);
 694          }
 695          else {
 696              $mReturn = call_user_func_array($sFunction, $aArgs);
 697          }
 698          return $mReturn;
 699      }
 700  
 701      // generates the javascript wrapper for the specified PHP function
 702      // used internally
 703  	function _wrap($sFunction,$sRequestType=XAJAX_POST)
 704      {
 705          $js = "function ".$this->sWrapperPrefix."$sFunction(){return xajax.call(\"$sFunction\", arguments, ".$sRequestType.");}\n";
 706          return $js;
 707      }
 708  
 709      // _xmlToArray() takes a string containing xajax xjxobj xml or xjxquery xml
 710      // and builds an array representation of it to pass as an argument to
 711      // the php function being called. Returns an array.
 712      // used internally
 713  	function _xmlToArray($rootTag, $sXml)
 714      {
 715          $aArray = array();
 716          $sXml = str_replace("<$rootTag>","<$rootTag>|~|",$sXml);
 717          $sXml = str_replace("</$rootTag>","</$rootTag>|~|",$sXml);
 718          $sXml = str_replace("<e>","<e>|~|",$sXml);
 719          $sXml = str_replace("</e>","</e>|~|",$sXml);
 720          $sXml = str_replace("<k>","<k>|~|",$sXml);
 721          $sXml = str_replace("</k>","|~|</k>|~|",$sXml);
 722          $sXml = str_replace("<v>","<v>|~|",$sXml);
 723          $sXml = str_replace("</v>","|~|</v>|~|",$sXml);
 724          $sXml = str_replace("<q>","<q>|~|",$sXml);
 725          $sXml = str_replace("</q>","|~|</q>|~|",$sXml);
 726  
 727          $this->aObjArray = explode("|~|",$sXml);
 728  
 729          $this->iPos = 0;
 730          $aArray = $this->_parseObjXml($rootTag);
 731  
 732          return $aArray;
 733      }
 734  
 735      // _parseObjXml() is a recursive function that generates an array from the
 736      // contents of $this->aObjArray. Returns an array.
 737      // used internally
 738  	function _parseObjXml($rootTag)
 739      {
 740          $aArray = array();
 741  
 742          if ($rootTag == "xjxobj")
 743          {
 744              while(!stristr($this->aObjArray[$this->iPos],"</xjxobj>"))
 745              {
 746                  $this->iPos++;
 747                  if(stristr($this->aObjArray[$this->iPos],"<e>"))
 748                  {
 749                      $key = "";
 750                      $value = null;
 751  
 752                      $this->iPos++;
 753                      while(!stristr($this->aObjArray[$this->iPos],"</e>"))
 754                      {
 755                          if(stristr($this->aObjArray[$this->iPos],"<k>"))
 756                          {
 757                              $this->iPos++;
 758                              while(!stristr($this->aObjArray[$this->iPos],"</k>"))
 759                              {
 760                                  $key .= $this->aObjArray[$this->iPos];
 761                                  $this->iPos++;
 762                              }
 763                          }
 764                          if(stristr($this->aObjArray[$this->iPos],"<v>"))
 765                          {
 766                              $this->iPos++;
 767                              while(!stristr($this->aObjArray[$this->iPos],"</v>"))
 768                              {
 769                                  if(stristr($this->aObjArray[$this->iPos],"<xjxobj>"))
 770                                  {
 771                                      $value = $this->_parseObjXml("xjxobj");
 772                                      $this->iPos++;
 773                                  }
 774                                  else
 775                                  {
 776                                      $value .= $this->aObjArray[$this->iPos];
 777                                  }
 778                                  $this->iPos++;
 779                              }
 780                          }
 781                          $this->iPos++;
 782                      }
 783  
 784                      $aArray[$key]=$value;
 785                  }
 786              }
 787          }
 788  
 789          if ($rootTag == "xjxquery")
 790          {
 791              $sQuery = "";
 792              $this->iPos++;
 793              while(!stristr($this->aObjArray[$this->iPos],"</xjxquery>"))
 794              {
 795                  if (stristr($this->aObjArray[$this->iPos],"<q>") || stristr($this->aObjArray[$this->iPos],"</q>"))
 796                  {
 797                      $this->iPos++;
 798                      continue;
 799                  }
 800                  $sQuery    .= $this->aObjArray[$this->iPos];
 801                  $this->iPos++;
 802              }
 803  
 804              parse_str($sQuery, $aArray);
 805              // If magic quotes is on, then we need to strip the slashes from the
 806              // array values because of the parse_str pass which adds slashes
 807              if (get_magic_quotes_gpc() == 1) {
 808                  $newArray = array();
 809                  foreach ($aArray as $sKey => $sValue) {
 810                      if (is_string($sValue))
 811                          $newArray[$sKey] = stripslashes($sValue);
 812                      else
 813                          $newArray[$sKey] = $sValue;
 814                  }
 815                  $aArray = $newArray;
 816              }
 817          }
 818  
 819          return $aArray;
 820      }
 821  
 822  }// end class xajax
 823  
 824  // xajaxErrorHandler() is registered with PHP's set_error_handler() function if
 825  // the xajax error handling system is turned on
 826  // used by the xajax class
 827  function xajaxErrorHandler($errno, $errstr, $errfile, $errline)
 828  {
 829      $errorReporting = error_reporting();
 830      if ($errorReporting == 0) return;
 831  
 832      if ($errno == E_NOTICE) {
 833          $errTypeStr = "NOTICE";
 834      }
 835      else if ($errno == E_WARNING) {
 836          $errTypeStr = "WARNING";
 837      }
 838      else if ($errno == E_USER_NOTICE) {
 839          $errTypeStr = "USER NOTICE";
 840      }
 841      else if ($errno == E_USER_WARNING) {
 842          $errTypeStr = "USER WARNING";
 843      }
 844      else if ($errno == E_USER_ERROR) {
 845          $errTypeStr = "USER FATAL ERROR";
 846      }
 847      else if ($errno == E_STRICT) {
 848          return;
 849      }
 850      else {
 851          $errTypeStr = "UNKNOWN: $errno";
 852      }
 853      $GLOBALS['xajaxErrorHandlerText'] .= "\n----\n[$errTypeStr] $errstr\nerror in line $errline of file $errfile";
 854  }
 855  
 856  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1