[TASK] Use simple file backend for core php cache
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_ajax.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Contains the class "t3lib_ajax" containing functions for doing XMLHTTP requests
30 * to the TYPO3 backend and as well for generating replys. This technology is also known as ajax.
31 * Call ALL methods without making an object!
32 *
33 * IMPORTANT NOTICE: The API the class provides is still NOT STABLE and SUBJECT TO CHANGE!
34 * It is planned to integrate an external AJAX library, so the API will most likely change again.
35 *
36 * TYPO3 XMLHTTP class (new in TYPO3 4.0.0)
37 * This class contains two main parts:
38 * (1) generation of JavaScript code which creates an XMLHTTP object in a cross-browser manner
39 * (2) generation of XML data as a reply
40 *
41 * @author Sebastian Kurfürst <sebastian@garbage-group.de>
42 * @package TYPO3
43 * @subpackage t3lib
44 * @deprecated since 6.0, the class will be removed from core with 6.2
45 */
46 class t3lib_ajax {
47
48 /**
49 * Default constructor writes deprecation log.
50 */
51 public function __construct() {
52 t3lib_div::deprecationLog(
53 'Class t3lib_ajax is deprecated and unused since TYPO3 6.0. ' .
54 'It will be removed with version 6.2.'
55 );
56 }
57
58 /**
59 * Gets the JavaScript code needed to handle an XMLHTTP request in the frontend.
60 * All JS functions have to call ajax_doRequest(url) to make a request to the server.
61 * USE:
62 * See examples of using this function in template.php -> getContextMenuCode and alt_clickmenu.php -> printContent
63 *
64 * @param string $handler Function JS function handling the XML data from the server. That function gets the returned XML data as parameter.
65 * @param string $fallback JS fallback function which is called with the URL of the request in case ajax is not available.
66 * @param boolean $debug If set to 1, the returned XML data is outputted as text in an alert window - useful for debugging, PHP errors are shown there, ...
67 * @return string JavaScript code needed to make and handle an XMLHTTP request
68 * @deprecated since 6.0, class will be removed with 6.2
69 */
70 public function getJScode($handlerFunction, $fallback = '', $debug = 0) {
71 t3lib_div::logDeprecatedFunction();
72
73 // Init the XMLHTTP request object
74 $code = '
75 function ajax_initObject() {
76 var A;
77 try {
78 A=new ActiveXObject("Msxml2.XMLHTTP");
79 } catch (e) {
80 try {
81 A=new ActiveXObject("Microsoft.XMLHTTP");
82 } catch (oc) {
83 A=null;
84 }
85 }
86 if (!A && typeof XMLHttpRequest != "undefined") {
87 A = new XMLHttpRequest();
88 }
89 return A;
90 }';
91 // In case AJAX is not available, fallback function
92 if ($fallback) {
93 $fallback .= '(url)';
94 } else {
95 $fallback = 'return';
96 }
97 $code .= '
98 function ajax_doRequest(url) {
99 var x;
100
101 x = ajax_initObject();
102 if (!x) {
103 ' . $fallback . ';
104 }
105 x.open("GET", url, true);
106
107 x.onreadystatechange = function() {
108 if (x.readyState != 4) {
109 return;
110 }
111 ' . ($debug ? 'alert(x.responseText)' : '') . '
112 var xmldoc = x.responseXML;
113 var t3ajax = xmldoc.getElementsByTagName("t3ajax")[0];
114 ' . $handlerFunction . '(t3ajax);
115 }
116 x.send("");
117
118 delete x;
119 }';
120
121 return $code;
122 }
123
124 /**
125 * Function outputting XML data for TYPO3 ajax. The function directly outputs headers and content to the browser.
126 *
127 * @param string $innerXML XML data which will be sent to the browser
128 * @return void
129 * @deprecated since 6.0, class will be removed with 6.2
130 */
131 public function outputXMLreply($innerXML) {
132 t3lib_div::logDeprecatedFunction();
133
134 // AJAX needs some XML data
135 header('Content-Type: text/xml');
136 $xml = '<?xml version="1.0"?>
137 <t3ajax>' . $innerXML . '</t3ajax>';
138 echo $xml;
139 }
140 }
141
142 ?>