1 | <?php |
---|
2 | /* |
---|
3 | File: xajax.inc.php |
---|
4 | |
---|
5 | Main xajax class and setup file. |
---|
6 | |
---|
7 | Title: xajax class |
---|
8 | |
---|
9 | Please see <copyright.inc.php> for a detailed description, copyright |
---|
10 | and license information. |
---|
11 | */ |
---|
12 | |
---|
13 | /* |
---|
14 | @package xajax |
---|
15 | @version $Id: xajax.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $ |
---|
16 | @copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson |
---|
17 | @license http://www.xajaxproject.org/bsd_license.txt BSD License |
---|
18 | */ |
---|
19 | |
---|
20 | /* |
---|
21 | Section: Standard Definitions |
---|
22 | */ |
---|
23 | |
---|
24 | /* |
---|
25 | String: XAJAX_DEFAULT_CHAR_ENCODING |
---|
26 | |
---|
27 | Default character encoding used by both the <xajax> and |
---|
28 | <xajaxResponse> classes. |
---|
29 | */ |
---|
30 | if (!defined ('XAJAX_DEFAULT_CHAR_ENCODING')) define ('XAJAX_DEFAULT_CHAR_ENCODING', 'utf-8'); |
---|
31 | |
---|
32 | /* |
---|
33 | String: XAJAX_PROCESSING_EVENT |
---|
34 | String: XAJAX_PROCESSING_EVENT_BEFORE |
---|
35 | String: XAJAX_PROCESSING_EVENT_AFTER |
---|
36 | String: XAJAX_PROCESSING_EVENT_INVALID |
---|
37 | |
---|
38 | Identifiers used to register processing events. Processing events are essentially |
---|
39 | hooks into the xajax core that can be used to add functionality into the request |
---|
40 | processing sequence. |
---|
41 | */ |
---|
42 | if (!defined ('XAJAX_PROCESSING_EVENT')) define ('XAJAX_PROCESSING_EVENT', 'xajax processing event'); |
---|
43 | if (!defined ('XAJAX_PROCESSING_EVENT_BEFORE')) define ('XAJAX_PROCESSING_EVENT_BEFORE', 'beforeProcessing'); |
---|
44 | if (!defined ('XAJAX_PROCESSING_EVENT_AFTER')) define ('XAJAX_PROCESSING_EVENT_AFTER', 'afterProcessing'); |
---|
45 | if (!defined ('XAJAX_PROCESSING_EVENT_INVALID')) define ('XAJAX_PROCESSING_EVENT_INVALID', 'invalidRequest'); |
---|
46 | |
---|
47 | /* |
---|
48 | Class: xajax |
---|
49 | |
---|
50 | The xajax class uses a modular plug-in system to facilitate the processing |
---|
51 | of special Ajax requests made by a PHP page. It generates Javascript that |
---|
52 | the page must include in order to make requests. It handles the output |
---|
53 | of response commands (see <xajaxResponse>). Many flags and settings can be |
---|
54 | adjusted to effect the behavior of the xajax class as well as the client-side |
---|
55 | javascript. |
---|
56 | */ |
---|
57 | class xajax |
---|
58 | { |
---|
59 | /**#@+ |
---|
60 | * @access protected |
---|
61 | */ |
---|
62 | |
---|
63 | /* |
---|
64 | Array: aSettings |
---|
65 | |
---|
66 | This array is used to store all the configuration settings that are set during |
---|
67 | the run of the script. This provides a single data store for the settings |
---|
68 | in case we need to return the value of a configuration option for some reason. |
---|
69 | |
---|
70 | It is advised that individual plugins store a local copy of the settings they |
---|
71 | wish to track, however, settings are available via a reference to the <xajax> |
---|
72 | object using <xajax->getConfiguration>. |
---|
73 | */ |
---|
74 | var $aSettings; |
---|
75 | |
---|
76 | /* |
---|
77 | Boolean: bErrorHandler |
---|
78 | |
---|
79 | This is a configuration setting that the main xajax object tracks. It is used |
---|
80 | to enable an error handler function which will trap php errors and return them |
---|
81 | to the client as part of the response. The client can then display the errors |
---|
82 | to the user if so desired. |
---|
83 | */ |
---|
84 | var $bErrorHandler; |
---|
85 | |
---|
86 | /* |
---|
87 | Array: aProcessingEvents |
---|
88 | |
---|
89 | Stores the processing event handlers that have been assigned during this run |
---|
90 | of the script. |
---|
91 | */ |
---|
92 | var $aProcessingEvents; |
---|
93 | |
---|
94 | /* |
---|
95 | Boolean: bExitAllowed |
---|
96 | |
---|
97 | A configuration option that is tracked by the main <xajax>object. Setting this |
---|
98 | to true allows <xajax> to exit immediatly after processing a xajax request. If |
---|
99 | this is set to false, xajax will allow the remaining code and HTML to be sent |
---|
100 | as part of the response. Typically this would result in an error, however, |
---|
101 | a response processor on the client side could be designed to handle this condition. |
---|
102 | */ |
---|
103 | var $bExitAllowed; |
---|
104 | |
---|
105 | /* |
---|
106 | Boolean: bCleanBuffer |
---|
107 | |
---|
108 | A configuration option that is tracked by the main <xajax> object. Setting this |
---|
109 | to true allows <xajax> to clear out any pending output buffers so that the |
---|
110 | <xajaxResponse> is (virtually) the only output when handling a request. |
---|
111 | */ |
---|
112 | var $bCleanBuffer; |
---|
113 | |
---|
114 | /* |
---|
115 | String: sLogFile |
---|
116 | |
---|
117 | A configuration setting tracked by the main <xajax> object. Set the name of the |
---|
118 | file on the server that you wish to have php error messages written to during |
---|
119 | the processing of <xajax> requests. |
---|
120 | */ |
---|
121 | var $sLogFile; |
---|
122 | |
---|
123 | /* |
---|
124 | String: sCoreIncludeOutput |
---|
125 | |
---|
126 | This is populated with any errors or warnings produced while including the xajax |
---|
127 | core components. This is useful for debugging core updates. |
---|
128 | */ |
---|
129 | var $sCoreIncludeOutput; |
---|
130 | |
---|
131 | /* |
---|
132 | Object: objPluginManager |
---|
133 | |
---|
134 | This stores a reference to the global <xajaxPluginManager> |
---|
135 | */ |
---|
136 | var $objPluginManager; |
---|
137 | |
---|
138 | /* |
---|
139 | Object: objArgumentManager |
---|
140 | |
---|
141 | Stores a reference to the global <xajaxArgumentManager> |
---|
142 | */ |
---|
143 | var $objArgumentManager; |
---|
144 | |
---|
145 | /* |
---|
146 | Object: objResponseManager |
---|
147 | |
---|
148 | Stores a reference to the global <xajaxResponseManager> |
---|
149 | */ |
---|
150 | var $objResponseManager; |
---|
151 | |
---|
152 | /* |
---|
153 | Object: objLanguageManager |
---|
154 | |
---|
155 | Stores a reference to the global <xajaxLanguageManager> |
---|
156 | */ |
---|
157 | var $objLanguageManager; |
---|
158 | |
---|
159 | /**#@-*/ |
---|
160 | |
---|
161 | /* |
---|
162 | Constructor: xajax |
---|
163 | |
---|
164 | Constructs a xajax instance and initializes the plugin system. |
---|
165 | |
---|
166 | sRequestURI - (optional): The <xajax->sRequestURI> to be used |
---|
167 | for calls back to the server. If empty, xajax fills in the current |
---|
168 | URI that initiated this request. |
---|
169 | */ |
---|
170 | function xajax($sRequestURI=null, $sLanguage=null) |
---|
171 | { |
---|
172 | $this->bErrorHandler = false; |
---|
173 | $this->aProcessingEvents = array(); |
---|
174 | $this->bExitAllowed = true; |
---|
175 | $this->bCleanBuffer = true; |
---|
176 | $this->sLogFile = ''; |
---|
177 | |
---|
178 | $this->__wakeup(); |
---|
179 | |
---|
180 | // The default configuration settings. |
---|
181 | $this->configureMany( |
---|
182 | array( |
---|
183 | 'characterEncoding' => XAJAX_DEFAULT_CHAR_ENCODING, |
---|
184 | 'decodeUTF8Input' => false, |
---|
185 | 'outputEntities' => false, |
---|
186 | 'defaultMode' => 'asynchronous', |
---|
187 | 'defaultMethod' => 'POST', // W3C: Method is case sensitive |
---|
188 | 'wrapperPrefix' => 'xajax_', |
---|
189 | 'debug' => false, |
---|
190 | 'verbose' => false, |
---|
191 | 'useUncompressedScripts' => false, |
---|
192 | 'statusMessages' => false, |
---|
193 | 'waitCursor' => true, |
---|
194 | 'scriptDeferral' => false, |
---|
195 | 'exitAllowed' => true, |
---|
196 | 'errorHandler' => false, |
---|
197 | 'cleanBuffer' => false, |
---|
198 | 'allowBlankResponse' => false, |
---|
199 | 'allowAllResponseTypes' => false, |
---|
200 | 'generateStubs' => true, |
---|
201 | 'logFile' => '', |
---|
202 | 'timeout' => 6000, |
---|
203 | 'version' => $this->getVersion() |
---|
204 | ) |
---|
205 | ); |
---|
206 | |
---|
207 | if (null !== $sRequestURI) |
---|
208 | $this->configure('requestURI', $sRequestURI); |
---|
209 | else |
---|
210 | $this->configure('requestURI', $this->_detectURI()); |
---|
211 | |
---|
212 | if (null !== $sLanguage) |
---|
213 | $this->configure('language', $sLanguage); |
---|
214 | } |
---|
215 | |
---|
216 | /* |
---|
217 | Function: __sleep |
---|
218 | */ |
---|
219 | function __sleep() |
---|
220 | { |
---|
221 | $aMembers = get_class_vars(get_class($this)); |
---|
222 | |
---|
223 | if (isset($aMembers['objLanguageManager'])) |
---|
224 | unset($aMembers['objLanguageManager']); |
---|
225 | |
---|
226 | if (isset($aMembers['objPluginManager'])) |
---|
227 | unset($aMembers['objPluginManager']); |
---|
228 | |
---|
229 | if (isset($aMembers['objArgumentManager'])) |
---|
230 | unset($aMembers['objArgumentManager']); |
---|
231 | |
---|
232 | if (isset($aMembers['objResponseManager'])) |
---|
233 | unset($aMembers['objResponseManager']); |
---|
234 | |
---|
235 | if (isset($aMembers['sCoreIncludeOutput'])) |
---|
236 | unset($aMembers['sCoreIncludeOutput']); |
---|
237 | |
---|
238 | return array_keys($aMembers); |
---|
239 | } |
---|
240 | |
---|
241 | /* |
---|
242 | Function: __wakeup |
---|
243 | */ |
---|
244 | function __wakeup() |
---|
245 | { |
---|
246 | ob_start(); |
---|
247 | |
---|
248 | $sLocalFolder = dirname(__FILE__); |
---|
249 | |
---|
250 | //SkipAIO |
---|
251 | require $sLocalFolder . '/xajaxPluginManager.inc.php'; |
---|
252 | require $sLocalFolder . '/xajaxLanguageManager.inc.php'; |
---|
253 | require $sLocalFolder . '/xajaxArgumentManager.inc.php'; |
---|
254 | require $sLocalFolder . '/xajaxResponseManager.inc.php'; |
---|
255 | require $sLocalFolder . '/xajaxRequest.inc.php'; |
---|
256 | require $sLocalFolder . '/xajaxResponse.inc.php'; |
---|
257 | //EndSkipAIO |
---|
258 | |
---|
259 | // this is the list of folders where xajax will look for plugins |
---|
260 | // that will be automatically included at startup. |
---|
261 | $aPluginFolders = array(); |
---|
262 | $aPluginFolders[] = dirname($sLocalFolder) . '/xajax_plugins'; |
---|
263 | |
---|
264 | //SkipAIO |
---|
265 | $aPluginFolders[] = $sLocalFolder . '/plugin_layer'; |
---|
266 | //EndSkipAIO |
---|
267 | |
---|
268 | // Setup plugin manager |
---|
269 | $this->objPluginManager =& xajaxPluginManager::getInstance(); |
---|
270 | $this->objPluginManager->loadPlugins($aPluginFolders); |
---|
271 | |
---|
272 | $this->objLanguageManager =& xajaxLanguageManager::getInstance(); |
---|
273 | $this->objArgumentManager =& xajaxArgumentManager::getInstance(); |
---|
274 | $this->objResponseManager =& xajaxResponseManager::getInstance(); |
---|
275 | |
---|
276 | $this->sCoreIncludeOutput = ob_get_clean(); |
---|
277 | } |
---|
278 | |
---|
279 | /* |
---|
280 | Function: getGlobalResponse |
---|
281 | |
---|
282 | Returns the <xajaxResponse> object preconfigured with the encoding |
---|
283 | and entity settings from this instance of <xajax>. This is used |
---|
284 | for singleton-pattern response development. |
---|
285 | |
---|
286 | Returns: |
---|
287 | |
---|
288 | <xajaxResponse> - A <xajaxResponse> object which can be used to return |
---|
289 | response commands. See also the <xajaxResponseManager> class. |
---|
290 | */ |
---|
291 | function &getGlobalResponse() |
---|
292 | { |
---|
293 | static $obj; |
---|
294 | if (!$obj) { |
---|
295 | $obj = new xajaxResponse(); |
---|
296 | } |
---|
297 | return $obj; |
---|
298 | } |
---|
299 | |
---|
300 | /* |
---|
301 | Function: getVersion |
---|
302 | |
---|
303 | Returns: |
---|
304 | |
---|
305 | string - The current xajax version. |
---|
306 | */ |
---|
307 | function getVersion() |
---|
308 | { |
---|
309 | return 'xajax 0.5 Beta 4'; |
---|
310 | } |
---|
311 | |
---|
312 | /* |
---|
313 | Function: register |
---|
314 | |
---|
315 | Call this function to register request handlers, including functions, |
---|
316 | callable objects and events. New plugins can be added that support |
---|
317 | additional registration methods and request processors. |
---|
318 | |
---|
319 | $sType - (string): Type of request handler being registered; standard |
---|
320 | options include: |
---|
321 | XAJAX_FUNCTION: a function declared at global scope. |
---|
322 | XAJAX_CALLABLE_OBJECT: an object who's methods are to be registered. |
---|
323 | XAJAX_EVENT: an event which will cause zero or more event handlers |
---|
324 | to be called. |
---|
325 | XAJAX_EVENT_HANDLER: register an event handler function. |
---|
326 | |
---|
327 | $sFunction || $objObject || $sEvent - (mixed): |
---|
328 | when registering a function, this is the name of the function |
---|
329 | when registering a callable object, this is the object being registered |
---|
330 | when registering an event or event handler, this is the name of the event |
---|
331 | |
---|
332 | $sIncludeFile || $aCallOptions || $sEventHandler |
---|
333 | when registering a function, this is the (optional) include file. |
---|
334 | when registering a callable object, this is an (optional) array |
---|
335 | of call options for the functions being registered. |
---|
336 | when registering an event handler, this is the name of the function. |
---|
337 | */ |
---|
338 | function register($sType, $mArg) |
---|
339 | { |
---|
340 | $aArgs = func_get_args(); |
---|
341 | $nArgs = func_num_args(); |
---|
342 | |
---|
343 | if (2 < $nArgs) |
---|
344 | { |
---|
345 | if (XAJAX_PROCESSING_EVENT == $aArgs[0]) |
---|
346 | { |
---|
347 | $sEvent = $aArgs[1]; |
---|
348 | $xuf =& $aArgs[2]; |
---|
349 | |
---|
350 | if (false == is_a($xuf, 'xajaxUserFunction')) |
---|
351 | $xuf =& new xajaxUserFunction($xuf); |
---|
352 | |
---|
353 | $this->aProcessingEvents[$sEvent] =& $xuf; |
---|
354 | |
---|
355 | return true; |
---|
356 | } |
---|
357 | } |
---|
358 | |
---|
359 | if (1 < $nArgs) |
---|
360 | { |
---|
361 | // for php4 |
---|
362 | $aArgs[1] =& $mArg; |
---|
363 | } |
---|
364 | |
---|
365 | return $this->objPluginManager->register($aArgs); |
---|
366 | } |
---|
367 | |
---|
368 | /* |
---|
369 | Function: configure |
---|
370 | |
---|
371 | Call this function to set options that will effect the processing of |
---|
372 | xajax requests. Configuration settings can be specific to the xajax |
---|
373 | core, request processor plugins and response plugins. |
---|
374 | |
---|
375 | Options include: |
---|
376 | javascript URI - (string): The path to the folder that contains the |
---|
377 | xajax javascript files. |
---|
378 | errorHandler - (boolean): true to enable the xajax error handler, see |
---|
379 | <xajax->bErrorHandler> |
---|
380 | exitAllowed - (boolean): true to allow xajax to exit after processing |
---|
381 | a request. See <xajax->bExitAllowed> for more information. |
---|
382 | */ |
---|
383 | function configure($sName, $mValue) |
---|
384 | { |
---|
385 | if ('errorHandler' == $sName) { |
---|
386 | if (true === $mValue || false === $mValue) |
---|
387 | $this->bErrorHandler = $mValue; |
---|
388 | } else if ('exitAllowed' == $sName) { |
---|
389 | if (true === $mValue || false === $mValue) |
---|
390 | $this->bExitAllowed = $mValue; |
---|
391 | } else if ('cleanBuffer' == $sName) { |
---|
392 | if (true === $mValue || false === $mValue) |
---|
393 | $this->bCleanBuffer = $mValue; |
---|
394 | } else if ('logFile' == $sName) { |
---|
395 | $this->sLogFile = $mValue; |
---|
396 | } |
---|
397 | |
---|
398 | $this->objLanguageManager->configure($sName, $mValue); |
---|
399 | $this->objArgumentManager->configure($sName, $mValue); |
---|
400 | $this->objPluginManager->configure($sName, $mValue); |
---|
401 | $this->objResponseManager->configure($sName, $mValue); |
---|
402 | |
---|
403 | $this->aSettings[$sName] = $mValue; |
---|
404 | } |
---|
405 | |
---|
406 | /* |
---|
407 | Function: configureMany |
---|
408 | |
---|
409 | Set an array of configuration options. |
---|
410 | |
---|
411 | $aOptions - (array): Associative array of configuration settings |
---|
412 | */ |
---|
413 | function configureMany($aOptions) |
---|
414 | { |
---|
415 | foreach ($aOptions as $sName => $mValue) |
---|
416 | $this->configure($sName, $mValue); |
---|
417 | } |
---|
418 | |
---|
419 | /* |
---|
420 | Function: getConfiguration |
---|
421 | |
---|
422 | Get the current value of a configuration setting that was previously set |
---|
423 | via <xajax->configure> or <xajax->configureMany> |
---|
424 | |
---|
425 | Returns: |
---|
426 | |
---|
427 | $mValue - (mixed): The value of the setting if set, null otherwise. |
---|
428 | */ |
---|
429 | function getConfiguration($sName) |
---|
430 | { |
---|
431 | if (isset($this->aSettings[$sName])) |
---|
432 | return $this->aSettings[$sName]; |
---|
433 | return NULL; |
---|
434 | } |
---|
435 | |
---|
436 | /* |
---|
437 | Function: canProcessRequest |
---|
438 | |
---|
439 | Determines if a call is a xajax request or a page load request. |
---|
440 | |
---|
441 | Return: |
---|
442 | |
---|
443 | boolean - True if this is a xajax request, false otherwise. |
---|
444 | */ |
---|
445 | function canProcessRequest() |
---|
446 | { |
---|
447 | return $this->objPluginManager->canProcessRequest(); |
---|
448 | } |
---|
449 | |
---|
450 | /* |
---|
451 | Function: processRequest |
---|
452 | |
---|
453 | If this is a xajax request (see <xajax->canProcessRequest>), call the |
---|
454 | requested PHP function, build the response and send it back to the |
---|
455 | browser. |
---|
456 | |
---|
457 | This is the main server side engine for xajax. It handles all the |
---|
458 | incoming requests, including the firing of events and handling of the |
---|
459 | response. If your RequestURI is the same as your web page, then this |
---|
460 | function should be called before ANY headers or HTML is output from |
---|
461 | your script. |
---|
462 | |
---|
463 | This function may exit, if a request is processed. See <xajax->bAllowExit> |
---|
464 | */ |
---|
465 | function processRequest() |
---|
466 | { |
---|
467 | //SkipDebug |
---|
468 | // Check to see if headers have already been sent out, in which case we can't do our job |
---|
469 | if (headers_sent($filename, $linenumber)) { |
---|
470 | echo "Output has already been sent to the browser at {$filename}:{$linenumber}.\n"; |
---|
471 | echo 'Please make sure the command $xajax->processRequest() is placed before this.'; |
---|
472 | exit(); |
---|
473 | } |
---|
474 | //EndSkipDebug |
---|
475 | |
---|
476 | if ($this->canProcessRequest()) |
---|
477 | { |
---|
478 | // Use xajax error handler if necessary |
---|
479 | if ($this->bErrorHandler) { |
---|
480 | $GLOBALS['xajaxErrorHandlerText'] = ""; |
---|
481 | set_error_handler("xajaxErrorHandler"); |
---|
482 | } |
---|
483 | |
---|
484 | $mResult = true; |
---|
485 | |
---|
486 | // handle beforeProcessing event |
---|
487 | if (isset($this->aProcessingEvents[XAJAX_PROCESSING_EVENT_BEFORE])) |
---|
488 | { |
---|
489 | $bEndRequest = false; |
---|
490 | $this->aProcessingEvents[XAJAX_PROCESSING_EVENT_BEFORE]->call(array(&$bEndRequest)); |
---|
491 | $mResult = (false === $bEndRequest); |
---|
492 | } |
---|
493 | |
---|
494 | if (true === $mResult) |
---|
495 | $mResult = $this->objPluginManager->processRequest(); |
---|
496 | |
---|
497 | if (true === $mResult) |
---|
498 | { |
---|
499 | if ($this->bCleanBuffer) { |
---|
500 | $er = error_reporting(0); |
---|
501 | while (ob_get_level() > 0) ob_end_clean(); |
---|
502 | error_reporting($er); |
---|
503 | } |
---|
504 | |
---|
505 | // handle afterProcessing event |
---|
506 | if (isset($this->aProcessingEvents[XAJAX_PROCESSING_EVENT_AFTER])) |
---|
507 | { |
---|
508 | $bEndRequest = false; |
---|
509 | $this->aProcessingEvents[XAJAX_PROCESSING_EVENT_AFTER]->call(array(&$bEndRequest)); |
---|
510 | if (true === $bEndRequest) |
---|
511 | { |
---|
512 | $this->objResponseManager->clear(); |
---|
513 | $this->objResponseManager->append($aResult[1]); |
---|
514 | } |
---|
515 | } |
---|
516 | } |
---|
517 | else if (is_string($mResult)) |
---|
518 | { |
---|
519 | if ($this->bCleanBuffer) { |
---|
520 | $er = error_reporting(0); |
---|
521 | while (ob_get_level() > 0) ob_end_clean(); |
---|
522 | error_reporting($er); |
---|
523 | } |
---|
524 | |
---|
525 | // $mResult contains an error message |
---|
526 | // the request was missing the cooresponding handler function |
---|
527 | // or an error occurred while attempting to execute the |
---|
528 | // handler. replace the response, if one has been started |
---|
529 | // and send a debug message. |
---|
530 | |
---|
531 | $this->objResponseManager->clear(); |
---|
532 | $this->objResponseManager->append(new xajaxResponse()); |
---|
533 | |
---|
534 | // handle invalidRequest event |
---|
535 | if (isset($this->aProcessingEvents[XAJAX_PROCESSING_EVENT_INVALID])) |
---|
536 | $this->aProcessingEvents[XAJAX_PROCESSING_EVENT_INVALID]->call(); |
---|
537 | else |
---|
538 | $this->objResponseManager->debug($mResult); |
---|
539 | } |
---|
540 | |
---|
541 | if ($this->bErrorHandler) { |
---|
542 | $sErrorMessage = $GLOBALS['xajaxErrorHandlerText']; |
---|
543 | if (!empty($sErrorMessage)) { |
---|
544 | if (0 < strlen($this->sLogFile)) { |
---|
545 | $fH = @fopen($this->sLogFile, "a"); |
---|
546 | if (NULL != $fH) { |
---|
547 | fwrite( |
---|
548 | $fH, |
---|
549 | $this->objLanguageManager->getText('LOGHDR:01') |
---|
550 | . strftime("%b %e %Y %I:%M:%S %p") |
---|
551 | . $this->objLanguageManager->getText('LOGHDR:02') |
---|
552 | . $sErrorMessage |
---|
553 | . $this->objLanguageManager->getText('LOGHDR:03') |
---|
554 | ); |
---|
555 | fclose($fH); |
---|
556 | } else { |
---|
557 | $this->objResponseManager->debug( |
---|
558 | $this->objLanguageManager->getText('LOGERR:01') |
---|
559 | . $this->sLogFile |
---|
560 | ); |
---|
561 | } |
---|
562 | } |
---|
563 | $this->objResponseManager->debug( |
---|
564 | $this->objLanguageManager->getText('LOGMSG:01') |
---|
565 | . $sErrorMessage |
---|
566 | ); |
---|
567 | } |
---|
568 | } |
---|
569 | |
---|
570 | $this->objResponseManager->send(); |
---|
571 | |
---|
572 | if ($this->bErrorHandler) restore_error_handler(); |
---|
573 | |
---|
574 | if ($this->bExitAllowed) exit(); |
---|
575 | } |
---|
576 | } |
---|
577 | |
---|
578 | /* |
---|
579 | Function: printJavascript |
---|
580 | |
---|
581 | Prints the xajax Javascript header and wrapper code into your page. |
---|
582 | This should be used to print the javascript code between the HEAD |
---|
583 | and /HEAD tags at the top of the page. |
---|
584 | |
---|
585 | The javascript code output by this function is dependent on the plugins |
---|
586 | that are included and the functions that are registered. |
---|
587 | |
---|
588 | $sJsURI - (string, optional, deprecated): the path to the xajax javascript file(s) |
---|
589 | This option is deprecated and will be removed in future versions; instead |
---|
590 | please use <xajax->configure> with the option name 'javascript URI' |
---|
591 | $aJsFiles - (array, optional, deprecated): an array of xajax javascript files |
---|
592 | that will be loaded via SCRIPT tags. This option is deprecated and will |
---|
593 | be removed in future versions; please use <xajax->configure> with the |
---|
594 | option name 'javascript files' instead. |
---|
595 | */ |
---|
596 | function printJavascript($sJsURI="", $aJsFiles=array()) |
---|
597 | { |
---|
598 | if (0 < strlen($sJsURI)) |
---|
599 | $this->configure("javascript URI", $sJsURI); |
---|
600 | |
---|
601 | if (0 < count($aJsFiles)) |
---|
602 | $this->configure("javascript files", $aJsFiles); |
---|
603 | |
---|
604 | $this->objPluginManager->generateClientScript(); |
---|
605 | } |
---|
606 | |
---|
607 | /* |
---|
608 | Function: getJavascript |
---|
609 | |
---|
610 | See <xajax->printJavascript> for more information. |
---|
611 | */ |
---|
612 | function getJavascript($sJsURI='', $aJsFiles=array()) |
---|
613 | { |
---|
614 | ob_start(); |
---|
615 | $this->printJavascript($sJsURI, $aJsFiles); |
---|
616 | return ob_get_clean(); |
---|
617 | } |
---|
618 | |
---|
619 | /* |
---|
620 | Function: autoCompressJavascript |
---|
621 | |
---|
622 | Creates a new xajax_core, xajax_debug, etc... file out of the |
---|
623 | _uncompressed file with a similar name. This strips out the |
---|
624 | comments and extraneous whitespace so the file is as small as |
---|
625 | possible without modifying the function of the code. |
---|
626 | |
---|
627 | sJsFullFilename - (string): The relative path and name of the file |
---|
628 | to be compressed. |
---|
629 | bAlways - (boolean): Compress the file, even if it already exists. |
---|
630 | */ |
---|
631 | function autoCompressJavascript($sJsFullFilename=NULL, $bAlways=false) |
---|
632 | { |
---|
633 | $sJsFile = 'xajax_js/xajax_core.js'; |
---|
634 | |
---|
635 | if ($sJsFullFilename) { |
---|
636 | $realJsFile = $sJsFullFilename; |
---|
637 | } |
---|
638 | else { |
---|
639 | $realPath = realpath(dirname(dirname(__FILE__))); |
---|
640 | $realJsFile = $realPath . '/'. $sJsFile; |
---|
641 | } |
---|
642 | |
---|
643 | // Create a compressed file if necessary |
---|
644 | if (!file_exists($realJsFile) || true == $bAlways) { |
---|
645 | $srcFile = str_replace('.js', '_uncompressed.js', $realJsFile); |
---|
646 | if (!file_exists($srcFile)) { |
---|
647 | trigger_error( |
---|
648 | $this->objLanguageManager->getText('CMPRSJS:RDERR:01') |
---|
649 | . dirname($realJsFile) |
---|
650 | . $this->objLanguageManager->getText('CMPRSJS:RDERR:02') |
---|
651 | , E_USER_ERROR |
---|
652 | ); |
---|
653 | } |
---|
654 | require_once(dirname(__FILE__) . '/xajaxCompress.inc.php'); |
---|
655 | $javaScript = implode('', file($srcFile)); |
---|
656 | $compressedScript = xajaxCompressFile($javaScript); |
---|
657 | $fH = @fopen($realJsFile, 'w'); |
---|
658 | if (!$fH) { |
---|
659 | trigger_error( |
---|
660 | $this->objLanguageManager->getText('CMPRSJS:WTERR:01') |
---|
661 | . dirname($realJsFile) |
---|
662 | . $this->objLanguageManager->getText('CMPRSJS:WTERR:02') |
---|
663 | , E_USER_ERROR |
---|
664 | ); |
---|
665 | } |
---|
666 | else { |
---|
667 | fwrite($fH, $compressedScript); |
---|
668 | fclose($fH); |
---|
669 | } |
---|
670 | } |
---|
671 | } |
---|
672 | |
---|
673 | function _compressSelf($sFolder=null) |
---|
674 | { |
---|
675 | if (null == $sFolder) |
---|
676 | $sFolder = dirname(dirname(__FILE__)); |
---|
677 | |
---|
678 | require_once(dirname(__FILE__) . '/xajaxCompress.inc.php'); |
---|
679 | |
---|
680 | if ($handle = opendir($sFolder)) { |
---|
681 | while (!(false === ($sName = readdir($handle)))) { |
---|
682 | if ('.' != $sName && '..' != $sName && is_dir($sFolder . '/' . $sName)) { |
---|
683 | $this->_compressSelf($sFolder . '/' . $sName); |
---|
684 | } else if (8 < strlen($sName) && 0 == strpos($sName, '.compressed')) { |
---|
685 | if ('.inc.php' == substr($sName, strlen($sName) - 8, 8)) { |
---|
686 | $sName = substr($sName, 0, strlen($sName) - 8); |
---|
687 | $sPath = $sFolder . '/' . $sName . '.inc.php'; |
---|
688 | if (file_exists($sPath)) { |
---|
689 | |
---|
690 | $aParsed = array(); |
---|
691 | $aFile = file($sPath); |
---|
692 | $nSkip = 0; |
---|
693 | foreach (array_keys($aFile) as $sKey) |
---|
694 | if ('//SkipDebug' == $aFile[$sKey]) |
---|
695 | ++$nSkip; |
---|
696 | else if ('//EndSkipDebug' == $aFile[$sKey]) |
---|
697 | --$nSkip; |
---|
698 | else if (0 == $nSkip) |
---|
699 | $aParsed[] = $aFile[$sKey]; |
---|
700 | unset($aFile); |
---|
701 | |
---|
702 | $compressedScript = xajaxCompressFile(implode('', $aParsed)); |
---|
703 | |
---|
704 | $sNewPath = $sPath; |
---|
705 | $fH = @fopen($sNewPath, 'w'); |
---|
706 | if (!$fH) { |
---|
707 | trigger_error( |
---|
708 | $this->objLanguageManager->getText('CMPRSPHP:WTERR:01') |
---|
709 | . $sNewPath |
---|
710 | . $this->objLanguageManager->getText('CMPRSPHP:WTERR:02') |
---|
711 | , E_USER_ERROR |
---|
712 | ); |
---|
713 | } |
---|
714 | else { |
---|
715 | fwrite($fH, $compressedScript); |
---|
716 | fclose($fH); |
---|
717 | } |
---|
718 | } |
---|
719 | } |
---|
720 | } |
---|
721 | } |
---|
722 | |
---|
723 | closedir($handle); |
---|
724 | } |
---|
725 | } |
---|
726 | |
---|
727 | function _compile($sFolder=null, $bWriteFile=true) |
---|
728 | { |
---|
729 | if (null == $sFolder) |
---|
730 | $sFolder = dirname(__FILE__); |
---|
731 | |
---|
732 | require_once(dirname(__FILE__) . '/xajaxCompress.inc.php'); |
---|
733 | |
---|
734 | $aOutput = array(); |
---|
735 | |
---|
736 | if ($handle = opendir($sFolder)) { |
---|
737 | while (!(false === ($sName = readdir($handle)))) { |
---|
738 | if ('.' != $sName && '..' != $sName && is_dir($sFolder . '/' . $sName)) { |
---|
739 | $aOutput[] = $this->_compile($sFolder . '/' . $sName, false); |
---|
740 | } else if (8 < strlen($sName)) { |
---|
741 | if ('.inc.php' == substr($sName, strlen($sName) - 8, 8)) { |
---|
742 | $sName = substr($sName, 0, strlen($sName) - 8); |
---|
743 | $sPath = $sFolder . '/' . $sName . '.inc.php'; |
---|
744 | if ( |
---|
745 | 'xajaxAIO' != $sName && |
---|
746 | 'legacy' != $sName && |
---|
747 | 'xajaxCompress' != $sName |
---|
748 | ) { |
---|
749 | if (file_exists($sPath)) { |
---|
750 | |
---|
751 | $aParsed = array(); |
---|
752 | $aFile = file($sPath); |
---|
753 | $nSkip = 0; |
---|
754 | foreach (array_keys($aFile) as $sKey) |
---|
755 | if ('//SkipDebug' == substr($aFile[$sKey], 0, 11)) |
---|
756 | ++$nSkip; |
---|
757 | else if ('//EndSkipDebug' == substr($aFile[$sKey], 0, 14)) |
---|
758 | --$nSkip; |
---|
759 | else if ('//SkipAIO' == substr($aFile[$sKey], 0, 9)) |
---|
760 | ++$nSkip; |
---|
761 | else if ('//EndSkipAIO' == substr($aFile[$sKey], 0, 12)) |
---|
762 | --$nSkip; |
---|
763 | else if ('<'.'?php' == substr($aFile[$sKey], 0, 5)) {} |
---|
764 | else if ('?'.'>' == substr($aFile[$sKey], 0, 2)) {} |
---|
765 | else if (0 == $nSkip) |
---|
766 | $aParsed[] = $aFile[$sKey]; |
---|
767 | unset($aFile); |
---|
768 | |
---|
769 | $aOutput[] = xajaxCompressFile(implode('', $aParsed)); |
---|
770 | } |
---|
771 | } |
---|
772 | } |
---|
773 | } |
---|
774 | } |
---|
775 | |
---|
776 | closedir($handle); |
---|
777 | } |
---|
778 | |
---|
779 | if ($bWriteFile) |
---|
780 | { |
---|
781 | $fH = @fopen($sFolder . '/xajaxAIO.inc.php', 'w'); |
---|
782 | if (!$fH) { |
---|
783 | trigger_error( |
---|
784 | $this->objLanguageManager->getText('CMPRSAIO:WTERR:01') |
---|
785 | . $sFolder |
---|
786 | . $this->objLanguageManager->getText('CMPRSAIO:WTERR:02') |
---|
787 | , E_USER_ERROR |
---|
788 | ); |
---|
789 | } |
---|
790 | else { |
---|
791 | fwrite($fH, '<'.'?php '); |
---|
792 | fwrite($fH, implode('', $aOutput)); |
---|
793 | fclose($fH); |
---|
794 | } |
---|
795 | } |
---|
796 | |
---|
797 | return implode('', $aOutput); |
---|
798 | } |
---|
799 | |
---|
800 | /* |
---|
801 | Function: _detectURI |
---|
802 | |
---|
803 | Returns the current requests URL based upon the SERVER vars. |
---|
804 | |
---|
805 | Returns: |
---|
806 | |
---|
807 | string - The URL of the current request. |
---|
808 | */ |
---|
809 | function _detectURI() { |
---|
810 | $aURL = array(); |
---|
811 | |
---|
812 | // Try to get the request URL |
---|
813 | if (!empty($_SERVER['REQUEST_URI'])) { |
---|
814 | |
---|
815 | $_SERVER['REQUEST_URI'] = str_replace( |
---|
816 | array('"',"'",'<','>'), |
---|
817 | array('%22','%27','%3C','%3E'), |
---|
818 | $_SERVER['REQUEST_URI'] |
---|
819 | ); |
---|
820 | |
---|
821 | $aURL = parse_url($_SERVER['REQUEST_URI']); |
---|
822 | } |
---|
823 | |
---|
824 | // Fill in the empty values |
---|
825 | if (empty($aURL['scheme'])) { |
---|
826 | if (!empty($_SERVER['HTTP_SCHEME'])) { |
---|
827 | $aURL['scheme'] = $_SERVER['HTTP_SCHEME']; |
---|
828 | } else { |
---|
829 | $aURL['scheme'] = |
---|
830 | (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') |
---|
831 | ? 'https' |
---|
832 | : 'http'; |
---|
833 | } |
---|
834 | } |
---|
835 | |
---|
836 | if (empty($aURL['host'])) { |
---|
837 | if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
---|
838 | if (strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ':') > 0) { |
---|
839 | list($aURL['host'], $aURL['port']) = explode(':', $_SERVER['HTTP_X_FORWARDED_HOST']); |
---|
840 | } else { |
---|
841 | $aURL['host'] = $_SERVER['HTTP_X_FORWARDED_HOST']; |
---|
842 | } |
---|
843 | } else if (!empty($_SERVER['HTTP_HOST'])) { |
---|
844 | if (strpos($_SERVER['HTTP_HOST'], ':') > 0) { |
---|
845 | list($aURL['host'], $aURL['port']) = explode(':', $_SERVER['HTTP_HOST']); |
---|
846 | } else { |
---|
847 | $aURL['host'] = $_SERVER['HTTP_HOST']; |
---|
848 | } |
---|
849 | } else if (!empty($_SERVER['SERVER_NAME'])) { |
---|
850 | $aURL['host'] = $_SERVER['SERVER_NAME']; |
---|
851 | } else { |
---|
852 | print $this->objLanguageManager->getText('DTCTURI:01'); |
---|
853 | print $this->objLanguageManager->getText('DTCTURI:02'); |
---|
854 | exit(); |
---|
855 | } |
---|
856 | } |
---|
857 | |
---|
858 | if (empty($aURL['port']) && !empty($_SERVER['SERVER_PORT'])) { |
---|
859 | $aURL['port'] = $_SERVER['SERVER_PORT']; |
---|
860 | } |
---|
861 | |
---|
862 | if (!empty($aURL['path'])) |
---|
863 | if (0 == strlen(basename($aURL['path']))) |
---|
864 | unset($aURL['path']); |
---|
865 | |
---|
866 | if (empty($aURL['path'])) { |
---|
867 | $sPath = array(); |
---|
868 | if (!empty($_SERVER['PATH_INFO'])) { |
---|
869 | $sPath = parse_url($_SERVER['PATH_INFO']); |
---|
870 | } else { |
---|
871 | $sPath = parse_url($_SERVER['PHP_SELF']); |
---|
872 | } |
---|
873 | if (isset($sPath['path'])) |
---|
874 | $aURL['path'] = str_replace(array('"',"'",'<','>'), array('%22','%27','%3C','%3E'), $sPath['path']); |
---|
875 | unset($sPath); |
---|
876 | } |
---|
877 | |
---|
878 | if (empty($aURL['query']) && !empty($_SERVER['QUERY_STRING'])) { |
---|
879 | $aURL['query'] = $_SERVER['QUERY_STRING']; |
---|
880 | } |
---|
881 | |
---|
882 | if (!empty($aURL['query'])) { |
---|
883 | $aURL['query'] = '?'.$aURL['query']; |
---|
884 | } |
---|
885 | |
---|
886 | // Build the URL: Start with scheme, user and pass |
---|
887 | $sURL = $aURL['scheme'].'://'; |
---|
888 | if (!empty($aURL['user'])) { |
---|
889 | $sURL.= $aURL['user']; |
---|
890 | if (!empty($aURL['pass'])) { |
---|
891 | $sURL.= ':'.$aURL['pass']; |
---|
892 | } |
---|
893 | $sURL.= '@'; |
---|
894 | } |
---|
895 | |
---|
896 | // Add the host |
---|
897 | $sURL.= $aURL['host']; |
---|
898 | |
---|
899 | // Add the port if needed |
---|
900 | if (!empty($aURL['port']) |
---|
901 | && (($aURL['scheme'] == 'http' && $aURL['port'] != 80) |
---|
902 | || ($aURL['scheme'] == 'https' && $aURL['port'] != 443))) { |
---|
903 | $sURL.= ':'.$aURL['port']; |
---|
904 | } |
---|
905 | |
---|
906 | // Add the path and the query string |
---|
907 | $sURL.= $aURL['path'].@$aURL['query']; |
---|
908 | |
---|
909 | // Clean up |
---|
910 | unset($aURL); |
---|
911 | |
---|
912 | $aURL = explode("?", $sURL); |
---|
913 | |
---|
914 | if (1 < count($aURL)) |
---|
915 | { |
---|
916 | $aQueries = explode("&", $aURL[1]); |
---|
917 | |
---|
918 | foreach ($aQueries as $sKey => $sQuery) |
---|
919 | { |
---|
920 | if ("xjxGenerate" == substr($sQuery, 0, 11)) |
---|
921 | unset($aQueries[$sKey]); |
---|
922 | } |
---|
923 | |
---|
924 | $sQueries = implode("&", $aQueries); |
---|
925 | |
---|
926 | $aURL[1] = $sQueries; |
---|
927 | |
---|
928 | $sURL = implode("?", $aURL); |
---|
929 | } |
---|
930 | |
---|
931 | return $sURL; |
---|
932 | } |
---|
933 | |
---|
934 | |
---|
935 | /* |
---|
936 | Deprecated functions |
---|
937 | */ |
---|
938 | |
---|
939 | /* |
---|
940 | Function: setCharEncoding |
---|
941 | |
---|
942 | Sets the character encoding that will be used for the HTTP output. |
---|
943 | Typically, you will not need to use this method since the default |
---|
944 | character encoding can be configured using the constant |
---|
945 | <XAJAX_DEFAULT_CHAR_ENCODING>. |
---|
946 | |
---|
947 | sEncoding - (string): The encoding to use. |
---|
948 | - examples include (UTF-8, ISO-8859-1) |
---|
949 | |
---|
950 | deprecated - This function will be removed in future versions. Please |
---|
951 | use <xajax->configure> instead. |
---|
952 | */ |
---|
953 | function setCharEncoding($sEncoding) |
---|
954 | { |
---|
955 | $this->configure('characterEncoding', $sEncoding); |
---|
956 | } |
---|
957 | |
---|
958 | /* |
---|
959 | Function: getCharEncoding |
---|
960 | |
---|
961 | Returns the current character encoding. See also <xajax->setCharEncoding> |
---|
962 | and <XAJAX_DEFAULT_CHAR_ENCODING> |
---|
963 | |
---|
964 | Returns: |
---|
965 | |
---|
966 | string - The character encoding. |
---|
967 | |
---|
968 | deprecated - This function will be removed in future versions. Please |
---|
969 | use <xajax->getConfiguration> instead. |
---|
970 | */ |
---|
971 | function getCharEncoding() |
---|
972 | { |
---|
973 | return $this->getConfiguration('characterEncoding'); |
---|
974 | } |
---|
975 | |
---|
976 | /* |
---|
977 | Function: setFlags |
---|
978 | |
---|
979 | Sets a series of flags. See also, <xajax->setFlag>. |
---|
980 | |
---|
981 | flags - (array): An associative array containing the name of the flag |
---|
982 | and the value to set. |
---|
983 | |
---|
984 | deprecated - This function will be removed in future versions. Please |
---|
985 | use <xajax->configureMany> instead. |
---|
986 | */ |
---|
987 | function setFlags($flags) |
---|
988 | { |
---|
989 | foreach ($flags as $name => $value) { |
---|
990 | $this->configure($name, $value); |
---|
991 | } |
---|
992 | } |
---|
993 | |
---|
994 | /* |
---|
995 | Function: setFlag |
---|
996 | |
---|
997 | Sets a single flag (boolean true or false). |
---|
998 | |
---|
999 | Available flags are as follows (flag, default value): |
---|
1000 | - debug, false |
---|
1001 | - verbose, false |
---|
1002 | - statusMessages, false |
---|
1003 | - waitCursor, true |
---|
1004 | - scriptDeferral, false |
---|
1005 | - exitAllowed, true |
---|
1006 | - errorHandler, false |
---|
1007 | - cleanBuffer, false |
---|
1008 | - decodeUTF8Input, false |
---|
1009 | - outputEntities, false |
---|
1010 | - allowBlankResponse, false |
---|
1011 | - allowAllResponseTypes, false |
---|
1012 | - generateStubs, true |
---|
1013 | |
---|
1014 | name - (string): The name of the flag to set. |
---|
1015 | value - (boolean): The value to set. |
---|
1016 | |
---|
1017 | deprecated - This function will be removed in future versions. Please |
---|
1018 | use <xajax->configure> instead. |
---|
1019 | */ |
---|
1020 | function setFlag($name, $value) |
---|
1021 | { |
---|
1022 | $this->configure($name, $value); |
---|
1023 | } |
---|
1024 | |
---|
1025 | /* |
---|
1026 | Function: getFlag |
---|
1027 | |
---|
1028 | Returns the current value of the flag. See also <xajax->setFlag>. |
---|
1029 | |
---|
1030 | name - (string): The name of the flag. |
---|
1031 | |
---|
1032 | Returns: |
---|
1033 | |
---|
1034 | boolean - The value currently associated with the flag. |
---|
1035 | |
---|
1036 | deprecated - This function will be removed in future versions. Instead, |
---|
1037 | use <xajax->getConfiguration>. |
---|
1038 | */ |
---|
1039 | function getFlag($name) |
---|
1040 | { |
---|
1041 | return $this->getConfiguration($name); |
---|
1042 | } |
---|
1043 | |
---|
1044 | /* |
---|
1045 | Function: setRequestURI |
---|
1046 | |
---|
1047 | Sets the URI to which requests will be sent. |
---|
1048 | |
---|
1049 | sRequestURI - (string): The URI |
---|
1050 | |
---|
1051 | Note: Usage |
---|
1052 | |
---|
1053 | $xajax->setRequestURI("http://www.xajaxproject.org"); |
---|
1054 | |
---|
1055 | deprecated - This function will be removed in future versions. Please |
---|
1056 | use <xajax->configure> instead. |
---|
1057 | */ |
---|
1058 | function setRequestURI($sRequestURI) |
---|
1059 | { |
---|
1060 | $this->configure('requestURI', $sRequestURI); |
---|
1061 | } |
---|
1062 | |
---|
1063 | /* |
---|
1064 | Function: getRequestURI |
---|
1065 | |
---|
1066 | Returns: |
---|
1067 | |
---|
1068 | string - The current request URI that will be configured on the client |
---|
1069 | side. This is the default URI for all requests made from the current |
---|
1070 | page. See <xajax->setRequestURI>. |
---|
1071 | |
---|
1072 | deprecated - This function will be removed in future versions. Please |
---|
1073 | use <xajax->getConfiguration> instead. |
---|
1074 | */ |
---|
1075 | function getRequestURI() |
---|
1076 | { |
---|
1077 | return $this->getConfiguration('requestURI'); |
---|
1078 | } |
---|
1079 | |
---|
1080 | /* |
---|
1081 | Function: setDefaultMode |
---|
1082 | |
---|
1083 | Sets the default mode for requests from the browser. |
---|
1084 | |
---|
1085 | sDefaultMode - (string): The mode to set as the default. |
---|
1086 | |
---|
1087 | - 'synchronous' |
---|
1088 | - 'asynchronous' |
---|
1089 | |
---|
1090 | Example: |
---|
1091 | |
---|
1092 | $xajax->setDefaultMode("synchronous"); |
---|
1093 | |
---|
1094 | deprecated - This function will be removed in future versions. Please |
---|
1095 | use <xajax->configure> instead. |
---|
1096 | */ |
---|
1097 | function setDefaultMode($sDefaultMode) |
---|
1098 | { |
---|
1099 | $this->configure('defaultMode', $sDefaultMode); |
---|
1100 | } |
---|
1101 | |
---|
1102 | /* |
---|
1103 | Function: getDefaultMode |
---|
1104 | |
---|
1105 | Get the default request mode that will be used by the browser |
---|
1106 | for submitting requests to the server. See also <xajax->setDefaultMode> |
---|
1107 | |
---|
1108 | Returns: |
---|
1109 | |
---|
1110 | string - The default mode to be used by the browser for each |
---|
1111 | request. |
---|
1112 | |
---|
1113 | deprecated - This function will be removed in future versions. Please |
---|
1114 | use <xajax->getConfiguration> instead. |
---|
1115 | */ |
---|
1116 | function getDefaultMode() |
---|
1117 | { |
---|
1118 | return $this->getConfiguration('defaultMode'); |
---|
1119 | } |
---|
1120 | |
---|
1121 | /* |
---|
1122 | Function: setDefaultMethod |
---|
1123 | |
---|
1124 | Sets the default method for making xajax requests: |
---|
1125 | |
---|
1126 | sMethod - (string): The name of the method. |
---|
1127 | |
---|
1128 | - 'GET' |
---|
1129 | - 'POST' |
---|
1130 | |
---|
1131 | deprecated - This function will be removed in future versions. Please |
---|
1132 | use <xajax->configure> instead. |
---|
1133 | */ |
---|
1134 | function setDefaultMethod($sMethod) |
---|
1135 | { |
---|
1136 | $this->configure('defaultMethod', $sMethod); |
---|
1137 | } |
---|
1138 | |
---|
1139 | /* |
---|
1140 | Function: getDefaultMethod |
---|
1141 | |
---|
1142 | Gets the default method for making xajax requests. |
---|
1143 | |
---|
1144 | Returns: |
---|
1145 | |
---|
1146 | string - The current method configured. |
---|
1147 | |
---|
1148 | deprecated - This function will be removed in future versions. Please |
---|
1149 | use <xajax->getConfiguration> instead. |
---|
1150 | */ |
---|
1151 | function getDefaultMethod() |
---|
1152 | { |
---|
1153 | return $this->getConfiguration('defaultMethod'); |
---|
1154 | } |
---|
1155 | |
---|
1156 | /* |
---|
1157 | Function: setWrapperPrefix |
---|
1158 | |
---|
1159 | Sets the prefix that will be prepended to the javascript wrapper |
---|
1160 | functions. This allows a little flexibility in setting the naming |
---|
1161 | for the wrapper functions. |
---|
1162 | |
---|
1163 | sPrefix - (string): The prefix to be used. |
---|
1164 | - default is 'xajax_' |
---|
1165 | |
---|
1166 | deprecated - This function will be removed in future versions. Please |
---|
1167 | use <xajax->configure> instead. |
---|
1168 | */ |
---|
1169 | function setWrapperPrefix($sPrefix) |
---|
1170 | { |
---|
1171 | $this->configure('wrapperPrefix', $sPrefix); |
---|
1172 | } |
---|
1173 | |
---|
1174 | /* |
---|
1175 | Function: getWrapperPrefix |
---|
1176 | |
---|
1177 | Gets the current javascript wrapper prefix. See also, <xajax->setWrapperPrefix> |
---|
1178 | |
---|
1179 | Returns: |
---|
1180 | |
---|
1181 | string - The current wrapper prefix. |
---|
1182 | |
---|
1183 | deprecated - This function will be removed in future versions. Please |
---|
1184 | use <xajax->getConfiguration> instead. |
---|
1185 | */ |
---|
1186 | function getWrapperPrefix() |
---|
1187 | { |
---|
1188 | return $this->getConfiguration('wrapperPrefix'); |
---|
1189 | } |
---|
1190 | |
---|
1191 | /* |
---|
1192 | Function: setLogFile |
---|
1193 | |
---|
1194 | Specifies a log file that will be written to by xajax during a |
---|
1195 | request. This is only used by the error handling system at this |
---|
1196 | point. If you do not invoke this method or you pass in an empty |
---|
1197 | string, then no log file will be written to. |
---|
1198 | |
---|
1199 | sFilename - (string): The full or reletive path to the log file. |
---|
1200 | |
---|
1201 | deprecated - This function will be removed in future versions. Please |
---|
1202 | use <xajax->configure> instead. |
---|
1203 | */ |
---|
1204 | function setLogFile($sFilename) |
---|
1205 | { |
---|
1206 | $this->configure('logFile', $sFilename); |
---|
1207 | } |
---|
1208 | |
---|
1209 | /* |
---|
1210 | Function: getLogFile |
---|
1211 | |
---|
1212 | Returns the current log file path. See also <xajax->setLogFile>. |
---|
1213 | |
---|
1214 | Returns: |
---|
1215 | |
---|
1216 | string - The log file path. |
---|
1217 | |
---|
1218 | deprecated - This function will be removed in future versions. Please |
---|
1219 | use <xajax->getConfiguration> instead. |
---|
1220 | */ |
---|
1221 | function getLogFile() |
---|
1222 | { |
---|
1223 | return $this->getConfiguration('logFile'); |
---|
1224 | } |
---|
1225 | |
---|
1226 | /* |
---|
1227 | Function: registerFunction |
---|
1228 | |
---|
1229 | Registers a PHP function or method with the xajax request processor. This |
---|
1230 | makes the function available to the browser via an asynchronous |
---|
1231 | (or synchronous) javascript call. |
---|
1232 | |
---|
1233 | mFunction - (string or array): The string containing the function name |
---|
1234 | or an array containing the following: |
---|
1235 | - (string) The function name as it will be called from javascript. |
---|
1236 | - (object, by reference) A reference to an instance of a class |
---|
1237 | containing the specified function. |
---|
1238 | - (string) The function as it is found in the class passed in the second |
---|
1239 | parameter. |
---|
1240 | sIncludeFile - (string, optional): The server path to the PHP file to |
---|
1241 | include when calling this function. This will enable xajax to load |
---|
1242 | only the include file that is needed for this function call, thus |
---|
1243 | reducing server load. |
---|
1244 | |
---|
1245 | Examples: |
---|
1246 | - $xajax->registerFunction("myFunction"); |
---|
1247 | - $xajax->registerFunction(array("myFunctionName", &$myObject, "myMethod")); |
---|
1248 | |
---|
1249 | deprecated - This function will be removed in future versions. Please |
---|
1250 | use <xajax->register> instead. |
---|
1251 | */ |
---|
1252 | function registerFunction($mFunction, $sIncludeFile=null) |
---|
1253 | { |
---|
1254 | $xuf =& new xajaxUserFunction($mFunction, $sIncludeFile); |
---|
1255 | return $this->register(XAJAX_FUNCTION, $xuf); |
---|
1256 | } |
---|
1257 | |
---|
1258 | /* |
---|
1259 | Function: registerCallableObject |
---|
1260 | |
---|
1261 | Registers an object whose methods will be searched for a match to the |
---|
1262 | incoming request. If more than one callable object is registered, the |
---|
1263 | first on that contains the requested method will be used. |
---|
1264 | |
---|
1265 | oObject - (object, by reference): The object whose methods will be |
---|
1266 | registered. |
---|
1267 | |
---|
1268 | deprecated - This function will be removed in future versions. Please |
---|
1269 | use <xajax->register> instead. |
---|
1270 | */ |
---|
1271 | function registerCallableObject(&$oObject) |
---|
1272 | { |
---|
1273 | $mResult = false; |
---|
1274 | |
---|
1275 | if (0 > version_compare(PHP_VERSION, '5.0')) |
---|
1276 | // for PHP4; using eval because PHP5 will complain it is deprecated |
---|
1277 | eval('$mResult = $this->register(XAJAX_CALLABLE_OBJECT, &$oObject);'); |
---|
1278 | else |
---|
1279 | // for PHP5 |
---|
1280 | $mResult = $this->register(XAJAX_CALLABLE_OBJECT, $oObject); |
---|
1281 | |
---|
1282 | return $mResult; |
---|
1283 | } |
---|
1284 | |
---|
1285 | /* |
---|
1286 | Function: registerEvent |
---|
1287 | |
---|
1288 | Assigns a callback function with the specified xajax event. Events |
---|
1289 | are triggered during the processing of a request. |
---|
1290 | |
---|
1291 | List: Available events: |
---|
1292 | - beforeProcessing: triggered before the request is processed. |
---|
1293 | - afterProcessing: triggered after the request is processed. |
---|
1294 | - invalidRequest: triggered if no matching function/method is found. |
---|
1295 | |
---|
1296 | mCallback - (function): The function or object callback to be assigned. |
---|
1297 | sEventName - (string): The name of the event. |
---|
1298 | |
---|
1299 | deprecated - This function will be removed in future versions. Please |
---|
1300 | use <xajax->register> instead. |
---|
1301 | */ |
---|
1302 | function registerEvent($sEventName, $mCallback) |
---|
1303 | { |
---|
1304 | $this->register(XAJAX_PROCESSING_EVENT, $sEventName, $mCallback); |
---|
1305 | } |
---|
1306 | |
---|
1307 | } |
---|
1308 | |
---|
1309 | /* |
---|
1310 | Section: Global functions |
---|
1311 | */ |
---|
1312 | |
---|
1313 | /* |
---|
1314 | Function xajaxErrorHandler |
---|
1315 | |
---|
1316 | This function is registered with PHP's set_error_handler if the xajax |
---|
1317 | error handling system is enabled. |
---|
1318 | |
---|
1319 | See <xajax->bUserErrorHandler> |
---|
1320 | */ |
---|
1321 | function xajaxErrorHandler($errno, $errstr, $errfile, $errline) |
---|
1322 | { |
---|
1323 | $errorReporting = error_reporting(); |
---|
1324 | if (($errno & $errorReporting) == 0) return; |
---|
1325 | |
---|
1326 | if ($errno == E_NOTICE) { |
---|
1327 | $errTypeStr = 'NOTICE'; |
---|
1328 | } |
---|
1329 | else if ($errno == E_WARNING) { |
---|
1330 | $errTypeStr = 'WARNING'; |
---|
1331 | } |
---|
1332 | else if ($errno == E_USER_NOTICE) { |
---|
1333 | $errTypeStr = 'USER NOTICE'; |
---|
1334 | } |
---|
1335 | else if ($errno == E_USER_WARNING) { |
---|
1336 | $errTypeStr = 'USER WARNING'; |
---|
1337 | } |
---|
1338 | else if ($errno == E_USER_ERROR) { |
---|
1339 | $errTypeStr = 'USER FATAL ERROR'; |
---|
1340 | } |
---|
1341 | else if (defined('E_STRICT') && $errno == E_STRICT) { |
---|
1342 | return; |
---|
1343 | } |
---|
1344 | else { |
---|
1345 | $errTypeStr = 'UNKNOWN: ' . $errno; |
---|
1346 | } |
---|
1347 | |
---|
1348 | $sCrLf = "\n"; |
---|
1349 | |
---|
1350 | ob_start(); |
---|
1351 | print $GLOBALS['xajaxErrorHandlerText']; |
---|
1352 | print $sCrLf; |
---|
1353 | print '----'; |
---|
1354 | print $sCrLf; |
---|
1355 | print '['; |
---|
1356 | print $errTypeStr; |
---|
1357 | print '] '; |
---|
1358 | print $errstr; |
---|
1359 | print $sCrLf; |
---|
1360 | print 'Error on line '; |
---|
1361 | print $errline; |
---|
1362 | print ' of file '; |
---|
1363 | print $errfile; |
---|
1364 | $GLOBALS['xajaxErrorHandlerText'] = ob_get_clean(); |
---|
1365 | } |
---|
1366 | |
---|