本文整理汇总了PHP中TYPO3\CMS\Core\Http\AjaxRequestHandler类的典型用法代码示例。如果您正苦于以下问题:PHP AjaxRequestHandler类的具体用法?PHP AjaxRequestHandler怎么用?PHP AjaxRequestHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AjaxRequestHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createTag
/**
* Create a tag
*
* @param array $params
* @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj
* @return void
* @throws \Exception
*/
public function createTag(array $params, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj)
{
$request = GeneralUtility::_POST();
try {
// Check if a tag is submitted
if (!isset($request['item']) || empty($request['item'])) {
throw new \Exception('error_no-tag');
}
$itemUid = $request['uid'];
if ((int) $itemUid === 0 && (strlen($itemUid) == 16 && !GeneralUtility::isFirstPartOfStr($itemUid, 'NEW'))) {
throw new \Exception('error_no-uid');
}
$table = $request['table'];
if (empty($table)) {
throw new \Exception('error_no-table');
}
// Get tag uid
$newTagId = $this->getTagUid($request);
$ajaxObj->setContentFormat('javascript');
$ajaxObj->setContent('');
$response = array($newTagId, $request['item'], self::TAG, $table, 'tags', 'data[' . htmlspecialchars($table) . '][' . $itemUid . '][tags]', $itemUid);
$ajaxObj->setJavascriptCallbackWrap(implode('-', $response));
} catch (\Exception $e) {
$errorMsg = $GLOBALS['LANG']->sL(self::LLPATH . $e->getMessage());
$ajaxObj->setError($errorMsg);
}
}
示例2: setWorkspace
/**
* Sets the TYPO3 Backend context to a certain workspace,
* called by the Backend toolbar menu
*
* @param array $parameters
* @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler
* @return void
*/
public function setWorkspace($parameters, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler)
{
$workspaceId = (int) GeneralUtility::_GP('workspaceId');
$pageId = (int) GeneralUtility::_GP('pageId');
$finalPageUid = 0;
$originalPageId = $pageId;
$this->getBackendUser()->setWorkspace($workspaceId);
while ($pageId) {
$page = BackendUtility::getRecordWSOL('pages', $pageId, '*', ' AND pages.t3ver_wsid IN (0, ' . $workspaceId . ')');
if ($page) {
if ($this->getBackendUser()->doesUserHaveAccess($page, 1)) {
break;
}
} else {
$page = BackendUtility::getRecord('pages', $pageId);
}
$pageId = $page['pid'];
}
if (isset($page['uid'])) {
$finalPageUid = (int) $page['uid'];
}
$response = array('title' => \TYPO3\CMS\Workspaces\Service\WorkspaceService::getWorkspaceTitle($workspaceId), 'workspaceId' => $workspaceId, 'pageId' => $finalPageUid && $originalPageId == $finalPageUid ? NULL : $finalPageUid);
$ajaxRequestHandler->setContent($response);
$ajaxRequestHandler->setContentFormat('json');
}
示例3: processAjaxRequest
/**
* Processes all AJAX calls and returns a JSON for the data
*
* @param array $parameters
* @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler
*/
public function processAjaxRequest($parameters, AjaxRequestHandler $ajaxRequestHandler)
{
// do the regular / main logic, depending on the action parameter
$action = GeneralUtility::_GP('action');
$key = GeneralUtility::_GP('key');
$value = GeneralUtility::_GP('value');
$content = $this->process($action, $key, $value);
$ajaxRequestHandler->setContentFormat('json');
$ajaxRequestHandler->setContent($content);
}
示例4: dispatch
/**
* The main dispatcher function. Collect data and prepare HTML output.
*
* @param array $params array of parameters, currently unused
* @param AjaxRequestHandler $ajaxObj object of type AjaxRequestHandler
* @return void
*/
public function dispatch($params = array(), AjaxRequestHandler $ajaxObj = NULL)
{
$params = GeneralUtility::_GP('params');
if ($params['action'] === 'getContextHelp') {
$result = $this->getContextHelp($params['table'], $params['field']);
$ajaxObj->addContent('title', $result['title']);
$ajaxObj->addContent('content', $result['description']);
$ajaxObj->addContent('link', $result['moreInfo']);
$ajaxObj->setContentFormat('json');
}
}
示例5: ajaxBroker
/**
* Used to broker incoming requests to other calls.
* Called by typo3/ajax.php
*
* @param array $unused additional parameters (not used)
* @param AjaxRequestHandler $ajax the AJAX object for this request
*
* @return void
*/
public function ajaxBroker(array $unused, AjaxRequestHandler $ajax)
{
$state = (bool) GeneralUtility::_POST('state');
$checkbox = GeneralUtility::_POST('checkbox');
if (in_array($checkbox, $this->validCheckboxKeys, true)) {
$ajax->setContentFormat('json');
$this->userSettingsService->set($checkbox, $state);
$ajax->addContent('success', true);
} else {
$ajax->setContentFormat('plain');
$ajax->setError('Illegal input parameters.');
}
}
示例6: ajaxLoadTree
/**
* @param array $params
* @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj
*/
public function ajaxLoadTree($params, &$ajaxObj)
{
$node_id = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('node');
if ($node_id == 'root') {
$node_repository = tx_caretaker_NodeRepository::getInstance();
$node = $node_repository->getRootNode(true);
$result = $this->nodeToArray($node, 2);
} else {
$node_repository = tx_caretaker_NodeRepository::getInstance();
$node = $node_repository->id2node($node_id, 1);
$result = $this->nodeToArray($node);
}
$ajaxObj->setContent($result['children']);
$ajaxObj->setContentFormat('jsonbody');
}
示例7: getRsaPublicKey
/**
* Gets RSA Public Key.
*
* @param array $parameters Parameters (not used)
* @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $parent The calling parent AJAX object
* @return void
*/
public function getRsaPublicKey(array $parameters, \TYPO3\CMS\Core\Http\AjaxRequestHandler $parent)
{
$backend = BackendFactory::getBackend();
if ($backend !== NULL) {
$keyPair = $backend->createNewKeyPair();
$storage = \TYPO3\CMS\Rsaauth\Storage\StorageFactory::getStorage();
$storage->put($keyPair->getPrivateKey());
session_commit();
$parent->addContent('publicKeyModulus', $keyPair->getPublicKeyModulus());
$parent->addContent('exponent', sprintf('%x', $keyPair->getExponent()));
$parent->setContentFormat('json');
} else {
$parent->setError('No OpenSSL backend could be obtained for rsaauth.');
}
}
示例8: getModuleData
/**
* ModuleMenu Store loading data
*
* @param array $params
* @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj
* @return array
*/
public function getModuleData($params, $ajaxObj)
{
$data = array('success' => TRUE, 'root' => array());
$rawModuleData = $this->getRawModuleData();
$index = 0;
foreach ($rawModuleData as $moduleKey => $moduleData) {
$key = substr($moduleKey, 8);
$num = count($data['root']);
if ($moduleData['link'] != 'dummy.php' || $moduleData['link'] == 'dummy.php' && is_array($moduleData['subitems'])) {
$data['root'][$num]['key'] = $key;
$data['root'][$num]['menuState'] = $GLOBALS['BE_USER']->uc['moduleData']['menuState'][$moduleKey];
$data['root'][$num]['label'] = $moduleData['title'];
$data['root'][$num]['subitems'] = is_array($moduleData['subitems']) ? count($moduleData['subitems']) : 0;
if ($moduleData['link'] && $this->linkModules) {
$data['root'][$num]['link'] = 'top.goToModule(\'' . $moduleData['name'] . '\')';
}
// Traverse submodules
if (is_array($moduleData['subitems'])) {
foreach ($moduleData['subitems'] as $subKey => $subData) {
$data['root'][$num]['sub'][] = array('name' => $subData['name'], 'description' => $subData['description'], 'label' => $subData['title'], 'icon' => $subData['icon']['filename'], 'navframe' => $subData['parentNavigationFrameScript'], 'link' => $subData['link'], 'originalLink' => $subData['originalLink'], 'index' => $index++, 'navigationFrameScript' => $subData['navigationFrameScript'], 'navigationFrameScriptParam' => $subData['navigationFrameScriptParam'], 'navigationComponentId' => $subData['navigationComponentId']);
}
}
}
}
if ($ajaxObj) {
$ajaxObj->setContent($data);
$ajaxObj->setContentFormat('jsonbody');
} else {
return $data;
}
}
示例9: ajaxUpdate
/**
* make the ajax update
*
* @param array $params Array of parameters from the AJAX interface, currently unused
* @param AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
* @return void
*/
public function ajaxUpdate($params = array(), AjaxRequestHandler &$ajaxObj = NULL)
{
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->evaluationRepository = $this->objectManager->get(EvaluationRepository::class);
$this->persistenceManager = $this->objectManager->get(PersistenceManager::class);
// get parameter
if (empty($params)) {
$uid = $GLOBALS['GLOBALS']['HTTP_POST_VARS']['uid'];
} else {
$attr = $params['request']->getParsedBody();
$uid = $attr['uid'];
}
$this->processResults($uid);
$ajaxObj->addContent('uid', $uid);
}
示例10: processAjaxRequestUploadProcess
/**
* @test
*/
public function processAjaxRequestUploadProcess()
{
$this->fileController = $this->getAccessibleMock('TYPO3\\CMS\\Backend\\Controller\\File\\FileController', array('init', 'main'));
$this->mockAjaxRequestHandler = $this->getMock('TYPO3\\CMS\\Core\\Http\\AjaxRequestHandler', array('addContent', 'setContentFormat'), array(), '', FALSE);
$fileData = array('upload' => array(array($this->fileResourceMock)));
$result = array('upload' => array(array('id' => 'foo', 'date' => '29-11-73', 'iconClasses' => 't3-icon t3-icon-mimetypes t3-icon-mimetypes-text t3-icon-text-html')));
$this->fileController->_set('fileProcessor', $this->mockFileProcessor);
$this->fileController->_set('fileData', $fileData);
$this->fileController->_set('redirect', FALSE);
$this->fileController->expects($this->once())->method('init');
$this->fileController->expects($this->once())->method('main');
$this->mockAjaxRequestHandler->expects($this->once())->method('addContent')->with('result', $result);
$this->mockAjaxRequestHandler->expects($this->once())->method('setContentFormat')->with('json');
$this->fileController->processAjaxRequest(array(), $this->mockAjaxRequestHandler);
}
示例11: getListRows
/**
* get list rows
*
* @param AjaxRequestHandler $ajaxObj the parent ajax object
*
* @return void
*/
public function getListRows(AjaxRequestHandler &$ajaxObj)
{
$uid = (int) $this->getParamValue('uid');
if ($uid > 0) {
$table = (string) $this->getParamValue('table');
$table = $table ? $table : 'tt_content';
$level = (int) $this->getParamValue('level');
$this->initializeTemplateContainer();
$elementChildren = Helper::getInstance()->getChildren($table, $uid, GeneralUtility::_GP('sortField'), (int) GeneralUtility::_GP('sortRev'));
$row = BackendUtility::getRecord($table, $uid);
$recordList = $this->getRecordList($table, $uid, $row);
if ($recordList instanceof DatabaseRecordList) {
$level++;
foreach ($elementChildren as $elementChild) {
$listRows[] = $recordList->renderListRow($elementChild->getTable(), BackendUtility::getRecord($elementChild->getTable(), $elementChild->getId()), 0, $GLOBALS['TCA'][$table]['ctrl']['label'], $GLOBALS['TCA'][$table]['ctrl']['thumbnail'], 1, $level);
}
}
$ajaxObj->addContent('list', $listRows);
}
}
示例12: setAjaxShortcut
/**
* Gets called when a shortcut is changed, checks whether the user has
* permissions to do so and saves the changes if everything is ok
*
* @param array $params Array of parameters from the AJAX interface, currently unused
* @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
* @return void
*/
public function setAjaxShortcut($params = array(), AjaxRequestHandler $ajaxObj = NULL)
{
$databaseConnection = $this->getDatabaseConnection();
$backendUser = $this->getBackendUser();
$shortcutId = (int) GeneralUtility::_POST('shortcutId');
$shortcutName = strip_tags(GeneralUtility::_POST('shortcutTitle'));
$shortcutGroupId = (int) GeneralUtility::_POST('shortcutGroup');
if ($shortcutGroupId > 0 || $backendUser->isAdmin()) {
// Users can delete only their own shortcuts (except admins)
$addUserWhere = !$backendUser->isAdmin() ? ' AND userid=' . (int) $backendUser->user['uid'] : '';
$fieldValues = array('description' => $shortcutName, 'sc_group' => $shortcutGroupId);
if ($fieldValues['sc_group'] < 0 && !$backendUser->isAdmin()) {
$fieldValues['sc_group'] = 0;
}
$databaseConnection->exec_UPDATEquery('sys_be_shortcuts', 'uid=' . $shortcutId . $addUserWhere, $fieldValues);
$affectedRows = $databaseConnection->sql_affected_rows();
if ($affectedRows == 1) {
$ajaxObj->addContent('shortcut', $shortcutName);
} else {
$ajaxObj->addContent('shortcut', 'failed');
}
}
$ajaxObj->setContentFormat('plain');
}
示例13: processAjaxRequest
/**
* Handles the actual process from within the ajaxExec function
* therefore, it does exactly the same as the real typo3/tce_file.php
* but without calling the "finish" method, thus makes it simpler to deal with the
* actual return value
*
* @param array $params Always empty.
* @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The Ajax object used to return content and set content types
* @return void
*/
public function processAjaxRequest(array $params, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj)
{
$this->init();
$this->main();
$errors = $this->fileProcessor->getErrorMessages();
if (count($errors)) {
$ajaxObj->setError(implode(',', $errors));
} else {
$ajaxObj->addContent('result', $this->fileData);
if ($this->redirect) {
$ajaxObj->addContent('redirect', $this->redirect);
}
$ajaxObj->setContentFormat('json');
}
}
示例14: ajaxExpandCollapseWithoutProduct
/**
* Makes the AJAX call to expand or collapse the categorytree.
* Called by typo3/ajax.php
*
* @param array $params Additional parameters (not used here)
* @param AjaxRequestHandler $ajaxObj Ajax object
*
* @return void
*/
public function ajaxExpandCollapseWithoutProduct(array $params, AjaxRequestHandler &$ajaxObj)
{
$parameter = $this->getParameter();
// Get the category tree without the products and the articles
$this->init(TRUE);
$tree = $this->categoryTree->getBrowseableAjaxTree($parameter);
$ajaxObj->addContent('tree', $tree);
}
示例15: dispatch
/**
* The main dispatcher function. Collect data and prepare HTML output.
*
* @param array $params array of parameters from the AJAX interface, currently unused
* @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj object of type AjaxRequestHandler
* @return void
*/
public function dispatch($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL)
{
$content = '';
// Basic test for required value
if ($this->conf['page'] > 0) {
// Init TCE for execution of update
/** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
$tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
$tce->stripslashes_values = 1;
// Determine the scripts to execute
switch ($this->conf['action']) {
case 'show_change_owner_selector':
$content = $this->renderUserSelector($this->conf['page'], $this->conf['ownerUid'], $this->conf['username']);
break;
case 'change_owner':
if (is_int($this->conf['new_owner_uid'])) {
// Prepare data to change
$data = array();
$data['pages'][$this->conf['page']]['perms_userid'] = $this->conf['new_owner_uid'];
// Execute TCE Update
$tce->start($data, array());
$tce->process_datamap();
$content = self::renderOwnername($this->conf['page'], $this->conf['new_owner_uid'], $this->conf['new_owner_username']);
} else {
$ajaxObj->setError('An error occurred: No page owner uid specified.');
}
break;
case 'show_change_group_selector':
$content = $this->renderGroupSelector($this->conf['page'], $this->conf['groupUid'], $this->conf['groupname']);
break;
case 'change_group':
if (is_int($this->conf['new_group_uid'])) {
// Prepare data to change
$data = array();
$data['pages'][$this->conf['page']]['perms_groupid'] = $this->conf['new_group_uid'];
// Execute TCE Update
$tce->start($data, array());
$tce->process_datamap();
$content = self::renderGroupname($this->conf['page'], $this->conf['new_group_uid'], $this->conf['new_group_username']);
} else {
$ajaxObj->setError('An error occurred: No page group uid specified.');
}
break;
case 'toggle_edit_lock':
// Prepare data to change
$data = array();
$data['pages'][$this->conf['page']]['editlock'] = $this->conf['editLockState'] === 1 ? 0 : 1;
// Execute TCE Update
$tce->start($data, array());
$tce->process_datamap();
$content = $this->renderToggleEditLock($this->conf['page'], $data['pages'][$this->conf['page']]['editlock']);
break;
default:
if ($this->conf['mode'] == 'delete') {
$this->conf['permissions'] = (int) ($this->conf['permissions'] - $this->conf['bits']);
} else {
$this->conf['permissions'] = (int) ($this->conf['permissions'] + $this->conf['bits']);
}
// Prepare data to change
$data = array();
$data['pages'][$this->conf['page']]['perms_' . $this->conf['who']] = $this->conf['permissions'];
// Execute TCE Update
$tce->start($data, array());
$tce->process_datamap();
$content = self::renderPermissions($this->conf['permissions'], $this->conf['page'], $this->conf['who']);
}
} else {
$ajaxObj->setError('This script cannot be called directly.');
}
$ajaxObj->addContent($this->conf['page'] . '_' . $this->conf['who'], $content);
}