ajax.php 2.57 KB
Newer Older
1
2
<?php
/***************************************************************
3
4
 *  Copyright notice
 *
5
 *  (c) 2007-2013 Benjamin Mack
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *  A copy is found in the textfile GPL.txt and important notices to the license
 *  from the author is found in LICENSE.txt distributed with these scripts.
 *
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
27

28
29
/**
 * AJAX dispatcher
30
31
 *
 * @author Benjamin Mack <mack@xnos.org>
32
 */
33

34
$TYPO3_AJAX = TRUE;
35

36
// This is a list of requests that don't necessarily need a valid BE user
37
38
39
40
$noUserAjaxIDs = array(
	'BackendLogin::login',
	'BackendLogin::logout',
	'BackendLogin::refreshLogin',
41
	'BackendLogin::isTimedOut',
42
	'BackendLogin::getChallenge'
43
);
44
45
46
47
48
49
50

// First get the ajaxID
$ajaxID = isset($_POST['ajaxID']) ? $_POST['ajaxID'] : $_GET['ajaxID'];
if (isset($ajaxID)) {
	$ajaxID = (string)stripslashes($ajaxID);
}

51
// If we're trying to do an ajax login, don't require a user.
52
if (in_array($ajaxID, $noUserAjaxIDs)) {
53
	define('TYPO3_PROCEED_IF_NO_USER', 2);
54
}
55

56
require 'init.php';
57

58
// finding the script path from the variable
59
$ajaxScript = $TYPO3_CONF_VARS['BE']['AJAX'][$ajaxID];
60
61
// Instantiating the AJAX object
$ajaxObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Http\\AjaxRequestHandler', $ajaxID);
62
$ajaxParams = array();
63
// Evaluating the arguments and calling the AJAX method/function
64
65
if (empty($ajaxID)) {
	$ajaxObj->setError('No valid ajaxID parameter given.');
66
} elseif (empty($ajaxScript)) {
67
	$ajaxObj->setError('No backend function registered for ajaxID "' . $ajaxID . '".');
68
} else {
69
	$ret = \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($ajaxScript, $ajaxParams, $ajaxObj, FALSE, TRUE);
70
	if ($ret === FALSE) {
71
		$ajaxObj->setError('Registered backend function for ajaxID "' . $ajaxID . '" was not found.');
72
73
	}
}
74
// Outputting the content (and setting the X-JSON-Header)
75
$ajaxObj->render();
76
?>