/** * 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); } }
/** * 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'); }
/** * @param array $ajaxParams * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObject * @return string */ public function updateConfigurationFile($ajaxParams, $ajaxObject) { $extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('extensionKey'); if (!empty($extensionKey)) { $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getEarlyInstance('TYPO3\\Flow\\Package\\PackageManager'); $extensionConfigurationPath = $packageManager->getPackage($extensionKey)->getPackagePath() . 'ext_emconf.php'; $_EXTKEY = $extensionKey; $EM_CONF = NULL; $extension = NULL; if (file_exists($extensionConfigurationPath)) { include $extensionConfigurationPath; if (is_array($EM_CONF[$_EXTKEY])) { $extension = $EM_CONF[$_EXTKEY]; } } if ($EM_CONF !== NULL) { $currentMd5HashArray = \IchHabRecht\Devtools\Utility\ExtensionUtility::getMd5HashArrayForExtension($extensionKey); $EM_CONF[$extensionKey]['_md5_values_when_last_written'] = serialize($currentMd5HashArray); /** @var \TYPO3\CMS\Extensionmanager\Utility\EmConfUtility $emConfUtility */ $emConfUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\\TYPO3\\CMS\\Extensionmanager\\Utility\\EmConfUtility'); $extensionData = array('extKey' => $extensionKey, 'EM_CONF' => $EM_CONF[$extensionKey]); $emConfContent = $emConfUtility->constructEmConf($extensionData); \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($extensionConfigurationPath, $emConfContent); } $ajaxObject->setContentFormat('json'); $ajaxObject->addContent('title', $this->translate('title')); $ajaxObject->addContent('message', sprintf($this->translate('message'), $extensionKey)); } }
/** * General processor for AJAX requests. * (called by typo3/ajax.php) * * @param array $params Additional parameters (not used here) * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj The AjaxRequestHandler object of this request * @return void * @author Oliver Hader <*****@*****.**> */ public function processAjaxRequest($params, \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj) { $this->ajaxObj = $ajaxObj; // Load the TSref XML information: $this->loadFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('t3editor') . 'res/tsref/tsref.xml'); $ajaxIdParts = explode('::', $ajaxObj->getAjaxID(), 2); $ajaxMethod = $ajaxIdParts[1]; $response = array(); // Process the AJAX requests: if ($ajaxMethod == 'getTypes') { $ajaxObj->setContent($this->getTypes()); $ajaxObj->setContentFormat('jsonbody'); } elseif ($ajaxMethod == 'getDescription') { $ajaxObj->addContent('', $this->getDescription(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('typeId'), \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('parameterName'))); $ajaxObj->setContentFormat('plain'); } }
/** * 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); }
/** * 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'); } }
/** * General processor for AJAX requests. * (called by typo3/ajax.php) * * @param array $params Additional parameters (not used here) * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj The AjaxRequestHandler object of this request * @return void * @author Oliver Hader <*****@*****.**> */ public function processAjaxRequest($params, \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj) { $this->ajaxObj = $ajaxObj; $ajaxIdParts = explode('::', $ajaxObj->getAjaxID(), 2); $ajaxMethod = $ajaxIdParts[1]; $response = array(); // Process the AJAX requests: if ($ajaxMethod == 'loadTemplates') { $ajaxObj->setContent($this->loadTemplates((int) \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pageId'))); $ajaxObj->setContentFormat('jsonbody'); } }
/** * 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.'); } }
/** * Initialize method * * @param array $params not used yet * @param AjaxRequestHandler $ajaxObj the parent ajax object * * @return void */ public function init($params, AjaxRequestHandler &$ajaxObj) { // fill local params because that's not done in typo3/ajax.php yet ($params is always empty) foreach ($this->validParams as $validParam) { $gpValue = GeneralUtility::_GP($validParam); if ($gpValue !== NULL) { $this->paramValues[$validParam] = $gpValue; } } // set ajaxObj to render JSON $ajaxObj->setContentFormat('jsonbody'); $this->dispatch($ajaxObj); }
/** * @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'); }
/** * 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.'); } }
/** * Returns the html for the AJAX API * * @param array $params * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler * @return void */ public function getHtmlForImageManipulationWizard($params, $ajaxRequestHandler) { if (!$this->checkHmacToken()) { HttpUtility::setResponseCodeAndExit(HttpUtility::HTTP_STATUS_403); } $fileUid = GeneralUtility::_GET('file'); $image = NULL; if (MathUtility::canBeInterpretedAsInteger($fileUid)) { try { $image = ResourceFactory::getInstance()->getFileObject($fileUid); } catch (FileDoesNotExistException $e) {} } $view = $this->getFluidTemplateObject($this->templatePath . 'Wizards/ImageManipulationWizard.html'); $view->assign('image', $image); $view->assign('zoom', (bool)GeneralUtility::_GET('zoom')); $view->assign('ratios', $this->getRatiosArray()); $content = $view->render(); $ajaxRequestHandler->addContent('content', $content); $ajaxRequestHandler->setContentFormat('html'); }
/** * 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'); }
/** * 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'); } }
/** * Renders the FlashMessages from queue and returns them as AJAX. * * @param array $params Always empty. * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The AjaxRequestHandler object used to return content and set content types * @return void */ public function renderFlashMessages(array $params, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj) { $ajaxObj->addContent('result', $this->getFlashMessages()); $ajaxObj->setContentFormat('html'); }
/** * Dispatches the incoming calls to methods about the ExtDirect API. * * @param aray $ajaxParams Ajax parameters * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj typo3ajax instance * @return void */ public function route($ajaxParams, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj) { $GLOBALS['error'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\ExtDirect\\ExtDirectDebug'); $isForm = FALSE; $isUpload = FALSE; $rawPostData = file_get_contents('php://input'); $postParameters = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST(); $namespace = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('namespace'); $response = array(); $request = NULL; $isValidRequest = TRUE; if (!empty($postParameters['extAction'])) { $isForm = TRUE; $isUpload = $postParameters['extUpload'] === 'true'; $request = new \stdClass(); $request->action = $postParameters['extAction']; $request->method = $postParameters['extMethod']; $request->tid = $postParameters['extTID']; unset($_POST['securityToken']); $request->data = array($_POST + $_FILES); $request->data[] = $postParameters['securityToken']; } elseif (!empty($rawPostData)) { $request = json_decode($rawPostData); } else { $response[] = array('type' => 'exception', 'message' => 'Something went wrong with an ExtDirect call!', 'code' => 'router'); $isValidRequest = FALSE; } if (!is_array($request)) { $request = array($request); } if ($isValidRequest) { $validToken = FALSE; $firstCall = TRUE; foreach ($request as $index => $singleRequest) { $response[$index] = array('tid' => $singleRequest->tid, 'action' => $singleRequest->action, 'method' => $singleRequest->method); $token = array_pop($singleRequest->data); if ($firstCall) { $firstCall = FALSE; $formprotection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get(); $validToken = $formprotection->validateToken($token, 'extDirect'); } try { if (!$validToken) { throw new \TYPO3\CMS\Core\FormProtection\Exception('ExtDirect: Invalid Security Token!'); } $response[$index]['type'] = 'rpc'; $response[$index]['result'] = $this->processRpc($singleRequest, $namespace); $response[$index]['debug'] = $GLOBALS['error']->toString(); } catch (\Exception $exception) { $response[$index]['type'] = 'exception'; $response[$index]['message'] = $exception->getMessage(); $response[$index]['code'] = 'router'; } } } if ($isForm && $isUpload) { $ajaxObj->setContentFormat('plain'); $response = json_encode($response); $response = preg_replace('/"/', '\\"', $response); $response = array('<html><body><textarea>' . $response . '</textarea></body></html>'); } else { $ajaxObj->setContentFormat('jsonbody'); } $ajaxObj->setContent($response); }
/** * Get the contacts for the given node for AJAX * * @param array $params * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj */ public function ajaxGetNodeContacts($params, &$ajaxObj) { $node_id = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('node'); $node_repository = tx_caretaker_NodeRepository::getInstance(); $node = $node_repository->id2node($node_id, true); if ($node_id && $node) { $count = 0; $contacts = array(); $nodeContacts = $node->getContacts(); /** @var tx_caretaker_Contact $nodeContact */ foreach ($nodeContacts as $nodeContact) { $role = $nodeContact->getRole(); if ($role) { $role_assoc = array('uid' => $role->getUid(), 'id' => $role->getId(), 'name' => $role->getTitle(), 'description' => $role->getDescription()); } else { $role_assoc = array('uid' => '', 'id' => '', 'name' => '', 'description' => ''); } $address = $nodeContact->getAddress(); if ($address) { $address['email_md5'] = md5($address['email']); } $contact = array('num' => $count++, 'id' => $node->getCaretakerNodeId() . '_role_' . $role_assoc['uid'] . '_address_' . $address['uid'], 'node_title' => $node->getTitle(), 'node_type' => $node->getType(), 'node_type_ll' => $node->getTypeDescription(), 'node_id' => $node->getCaretakerNodeId(), 'role' => $role_assoc, 'address' => $address); foreach ($address as $key => $value) { $contact['address_' . $key] = $value; } foreach ($role_assoc as $key => $value) { $contact['role_' . $key] = $value; } $contacts[] = $contact; } $content = array(); $content['contacts'] = $contacts; $content['totalCount'] = $count; $ajaxObj->setContent($content); $ajaxObj->setContentFormat('jsonbody'); } }
/** * 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 AjaxRequestHandler 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 (!empty($errors)) { $ajaxObj->setError(implode(',', $errors)); } else { $flatResult = array(); foreach ($this->fileData as $action => $results) { foreach ($results as $result) { if (is_array($result)) { foreach ($result as $subResult) { $flatResult[$action][] = $this->flattenResultDataValue($subResult); } } else { $flatResult[$action][] = $this->flattenResultDataValue($result); } } } $ajaxObj->addContent('result', $flatResult); if ($this->redirect) { $ajaxObj->addContent('redirect', $this->redirect); } $ajaxObj->setContentFormat('json'); } }
/** * this is an intermediate clickmenu handler * * @param array $parameters * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler */ public function printContentForAjaxRequest($parameters, AjaxRequestHandler $ajaxRequestHandler) { // XML has to be parsed, no parse errors allowed @ini_set('display_errors', 0); $clipObj = GeneralUtility::makeInstance(Clipboard::class); $clipObj->initializeClipboard(); // This locks the clipboard to the Normal for this request. $clipObj->lockToNormal(); // Update clipboard if some actions are sent. $CB = GeneralUtility::_GET('CB'); $clipObj->setCmd($CB); $clipObj->cleanCurrent(); // Saves $clipObj->endClipboard(); // Create clickmenu object $clickMenu = GeneralUtility::makeInstance(ClickMenu::class); // Set internal vars in clickmenu object: $clickMenu->clipObj = $clipObj; $clickMenu->extClassArray = $this->extClassArray; // Set content of the clickmenu with the incoming var, "item" $ajaxContent = $clickMenu->init(); // send the data $ajaxContent = '<?xml version="1.0"?><t3ajax>' . $ajaxContent . '</t3ajax>'; $ajaxRequestHandler->addContent('ClickMenu', $ajaxContent); $ajaxRequestHandler->setContentFormat('xml'); }
/** * 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; $dummyLink = BackendUtility::getModuleUrl('dummy'); foreach ($rawModuleData as $moduleKey => $moduleData) { $key = substr($moduleKey, 8); $num = count($data['root']); if ($moduleData['link'] != $dummyLink || $moduleData['link'] == $dummyLink && 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(' . GeneralUtility::quoteJSvalue($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; } }
/** * Processes all AJAX calls and returns a JSON formatted string * * @param array $parameters * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler */ public function processAjaxRequest($parameters, AjaxRequestHandler $ajaxRequestHandler) { // do the regular / main logic $this->initClipboard(); $this->main(); /** @var \TYPO3\CMS\Core\Messaging\FlashMessageService $flashMessageService */ $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class); $content = array('redirect' => $this->redirect, 'messages' => array(), 'hasErrors' => FALSE); // Prints errors (= write them to the message queue) if ($this->prErr) { $content['hasErrors'] = TRUE; $this->tce->printLogErrorMessages($this->redirect); } $messages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush(); if (!empty($messages)) { foreach ($messages as $message) { $content['messages'][] = array('title' => $message->getTitle(), 'message' => $message->getMessage(), 'severity' => $message->getSeverity()); if ($message->getSeverity() === AbstractMessage::ERROR) { $content['hasErrors'] = TRUE; } } } $ajaxRequestHandler->setContentFormat('json'); $ajaxRequestHandler->setContent($content); }
/** * Create a target * * @param array $params * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj * @return void * @throws Exception */ public function createTarget(array $params, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj) { $request = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST(); try { // Check if a tag is submitted if (!isset($request['item']) || empty($request['item'])) { throw new Exception('error_no-target'); } $newsUid = $request['newsid']; if ((int) $newsUid === 0 && (strlen($newsUid) == 16 && !\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($newsUid, 'NEW'))) { throw new Exception('error_no-newsid'); } // Get tag uid $newTargetId = $this->getTargetUid($request); $ajaxObj->setContentFormat('javascript'); $ajaxObj->setContent(''); $response = array($newTargetId, $request['item'], self::TARGET, self::NEWS, 'tags', 'data[tx_mooxnews_domain_model_news][' . $newsUid . '][targets]', $newsUid); $ajaxObj->setJavascriptCallbackWrap(implode('-', $response)); } catch (Exception $e) { $errorMsg = $GLOBALS['LANG']->sL(self::LLPATHTARGET . $e->getMessage()); $ajaxObj->setError($errorMsg); } }
/** * General processor for AJAX requests concerning IRRE. * (called by typo3/ajax.php) * * @param array $params Additional parameters (not used here) * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The AjaxRequestHandler object of this request * @return void */ public function processAjaxRequest($params, $ajaxObj) { $ajaxArguments = GeneralUtility::_GP('ajax'); $ajaxIdParts = explode('::', $GLOBALS['ajaxID'], 2); if (isset($ajaxArguments) && is_array($ajaxArguments) && count($ajaxArguments)) { $ajaxMethod = $ajaxIdParts[1]; switch ($ajaxMethod) { case 'createNewRecord': case 'synchronizeLocalizeRecords': case 'getRecordDetails': $this->isAjaxCall = TRUE; // Construct runtime environment for Inline Relational Record Editing: $this->processAjaxRequestConstruct($ajaxArguments); // Parse the DOM identifier (string), add the levels to the structure stack (array) and load the TCA config: $this->parseStructureString($ajaxArguments[0], TRUE); $this->injectAjaxConfiguration($ajaxArguments); // Render content: $ajaxObj->setContentFormat('jsonbody'); $ajaxObj->setContent(call_user_func_array(array(&$this, $ajaxMethod), $ajaxArguments)); break; case 'setExpandedCollapsedState': $ajaxObj->setContentFormat('jsonbody'); call_user_func_array(array(&$this, $ajaxMethod), $ajaxArguments); break; } } }
/** * General processor for AJAX requests concerning IRRE. * * @param array $_ Additional parameters (not used here) * @param AjaxRequestHandler $ajaxObj The AjaxRequestHandler object of this request * @throws \RuntimeException * @return void */ public function processInlineAjaxRequest($_, AjaxRequestHandler $ajaxObj) { $ajaxArguments = GeneralUtility::_GP('ajax'); $ajaxIdParts = explode('::', $GLOBALS['ajaxID'], 2); if (isset($ajaxArguments) && is_array($ajaxArguments) && count($ajaxArguments)) { $ajaxMethod = $ajaxIdParts[1]; $ajaxObj->setContentFormat('jsonbody'); // Construct runtime environment for Inline Relational Record Editing $this->setUpRuntimeEnvironmentForAjaxRequests(); // @todo: ajaxArguments[2] is "returnUrl" in the first 3 calls - still needed? switch ($ajaxMethod) { case 'synchronizeLocalizeRecords': $domObjectId = $ajaxArguments[0]; $type = $ajaxArguments[1]; // Parse the DOM identifier (string), add the levels to the structure stack (array), load the TCA config: $this->inlineStackProcessor->initializeByParsingDomObjectIdString($domObjectId); $this->inlineStackProcessor->injectAjaxConfiguration($ajaxArguments['context']); $inlineFirstPid = FormEngineUtility::getInlineFirstPidFromDomObjectId($domObjectId); $ajaxObj->setContent($this->renderInlineSynchronizeLocalizeRecords($type, $inlineFirstPid)); break; case 'createNewRecord': $domObjectId = $ajaxArguments[0]; $createAfterUid = 0; if (isset($ajaxArguments[1])) { $createAfterUid = $ajaxArguments[1]; } // Parse the DOM identifier (string), add the levels to the structure stack (array), load the TCA config: $this->inlineStackProcessor->initializeByParsingDomObjectIdString($domObjectId); $this->inlineStackProcessor->injectAjaxConfiguration($ajaxArguments['context']); $ajaxObj->setContent($this->renderInlineNewChildRecord($domObjectId, $createAfterUid)); break; case 'getRecordDetails': $domObjectId = $ajaxArguments[0]; // Parse the DOM identifier (string), add the levels to the structure stack (array), load the TCA config: $this->inlineStackProcessor->initializeByParsingDomObjectIdString($domObjectId); $this->inlineStackProcessor->injectAjaxConfiguration($ajaxArguments['context']); $ajaxObj->setContent($this->renderInlineChildRecord($domObjectId)); break; case 'setExpandedCollapsedState': $domObjectId = $ajaxArguments[0]; // Parse the DOM identifier (string), add the levels to the structure stack (array), don't load TCA config $this->inlineStackProcessor->initializeByParsingDomObjectIdString($domObjectId, FALSE); $expand = $ajaxArguments[1]; $collapse = $ajaxArguments[2]; $this->setInlineExpandedCollapsedState($expand, $collapse); break; default: throw new \RuntimeException('Not a valid ajax identifier', 1428227862); } } }
/** * Returns the Module menu for the AJAX API * * @param array $params * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler * @return void */ public function getModuleMenuForReload($params, $ajaxRequestHandler) { $content = $this->generateModuleMenu(); $ajaxRequestHandler->addContent('menu', $content); $ajaxRequestHandler->setContentFormat('json'); }
/** * Gets plugins that are defined at $TYPO3_CONF_VARS['EXTCONF']['t3editor']['plugins'] * (called by typo3/ajax.php) * * @param array $params additional parameters (not used here) * @param TYPO3AJAX &$ajaxObj: the TYPO3AJAX object of this request * @return void * @author Oliver Hader <*****@*****.**> */ public function getPlugins($params, \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj) { $result = array(); $plugins =& $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3editor']['plugins']; if (is_array($plugins)) { $result = array_values($plugins); } $ajaxObj->setContent($result); $ajaxObj->setContentFormat('jsonbody'); }
/** * 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 TYPO3AJAX * @return void */ public function setAjaxShortcut($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) { $shortcutId = (int) \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('shortcutId'); $shortcutName = strip_tags(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('value')); $shortcutGroupId = (int) \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('shortcut-group'); if ($shortcutGroupId > 0 || $GLOBALS['BE_USER']->isAdmin()) { // Users can delete only their own shortcuts (except admins) $addUserWhere = !$GLOBALS['BE_USER']->isAdmin() ? ' AND userid=' . intval($GLOBALS['BE_USER']->user['uid']) : ''; $fieldValues = array('description' => $shortcutName, 'sc_group' => $shortcutGroupId); if ($fieldValues['sc_group'] < 0 && !$GLOBALS['BE_USER']->isAdmin()) { $fieldValues['sc_group'] = 0; } $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_be_shortcuts', 'uid=' . $shortcutId . $addUserWhere, $fieldValues); $affectedRows = $GLOBALS['TYPO3_DB']->sql_affected_rows(); if ($affectedRows == 1) { $ajaxObj->addContent('shortcut', $shortcutName); } else { $ajaxObj->addContent('shortcut', 'failed'); } } $ajaxObj->setContentFormat('plain'); }
/** * Checks if the user session is expired yet * * @param array $parameters Parameters (not used) * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The calling parent AJAX object * @return void */ public function isTimedOut(array $parameters, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj) { $ajaxObj->setContentFormat('json'); if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) { $ajaxObj->addContent('login', array('will_time_out' => FALSE, 'locked' => TRUE)); } elseif (!isset($GLOBALS['BE_USER']->user['uid'])) { $ajaxObj->addContent('login', array('timed_out' => TRUE)); } else { $GLOBALS['BE_USER']->fetchUserSession(TRUE); $ses_tstamp = $GLOBALS['BE_USER']->user['ses_tstamp']; $timeout = $GLOBALS['BE_USER']->auth_timeout_field; // If 120 seconds from now is later than the session timeout, we need to show the refresh dialog. // 120 is somewhat arbitrary to allow for a little room during the countdown and load times, etc. if ($GLOBALS['EXEC_TIME'] >= $ses_tstamp + $timeout - 120) { $ajaxObj->addContent('login', array('will_time_out' => TRUE)); } else { $ajaxObj->addContent('login', array('will_time_out' => FALSE)); } } }
/** * Gets a MD5 challenge. * * @param array $parameters Parameters (not used) * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $parent The calling parent AJAX object * @return void */ public function getChallenge(array $parameters, \TYPO3\CMS\Core\Http\AjaxRequestHandler $parent) { session_start(); $_SESSION['login_challenge'] = md5(uniqid('', TRUE) . getmypid()); session_commit(); $parent->addContent('challenge', $_SESSION['login_challenge']); $parent->setContentFormat('json'); }
/** * Checks if a key for an element is available * * @param array $params Array of parameters from the AJAX interface, not * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler * @author Benjamin Butschell <*****@*****.**> * @return void */ public function checkElementKey($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) { $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $this->storageRepository = $this->objectManager->get("MASK\\Mask\\Domain\\Repository\\StorageRepository"); // Get parameters, is there a better way? $params is not used yet $elementKey = $_GET["key"]; // check if elementKey is available $isAvailable = TRUE; if ($this->storageRepository->loadElement("tt_content", $elementKey)) { $isAvailable = FALSE; } // return infos as json $ajaxObj->setContentFormat("plain"); $ajaxObj->addContent("isAvailable", json_encode($isAvailable)); }