/** * 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); } }
/** * @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)); } }
/** * 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'); }
/** * Renders/Echoes the ajax output * * @param ServerRequestInterface $request * @param ResponseInterface $response * @return ResponseInterface|NULL * @throws \InvalidArgumentException */ public function processRequest(ServerRequestInterface $request, ResponseInterface $response) { $action = isset($request->getParsedBody()['action']) ? $request->getParsedBody()['action'] : (isset($request->getQueryParams()['action']) ? $request->getQueryParams()['action'] : ''); if (!in_array($action, array('route', 'getAPI'), true)) { return null; } $this->routeAction($action); return $this->ajaxObject->render(); }
/** * 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'); } }
/** * 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.'); } }
/** * @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.'); } }
/** * Get description * * @param string $typeId * @param string $parameterName * @return string */ protected function getDescription($typeId, $parameterName = '') { if (!$typeId) { $this->ajaxObj->setError($GLOBALS['LANG']->getLL('typeIDMissing')); return ''; } // getElementById does only work with schema $type = $this->getType($typeId); // Retrieve propertyDescription if ($parameterName) { $properties = $type->getElementsByTagName('property'); foreach ($properties as $propery) { $propName = $propery->getAttribute('name'); if ($propName == $parameterName) { $descriptions = $propery->getElementsByTagName('description'); if ($descriptions->length) { $description = $descriptions->item(0)->textContent; $description = htmlspecialchars($description); $description = nl2br($description); return $description; } } } } return ''; }
/** * 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; } }
/** * Loads all templates up to a given page id (walking the rootline) and * cleans parts that are not required for the t3editor codecompletion. * * @param integer $pageId ID of the page * @param integer $templateId Currently unused (default: 0) * @return array Cleaned array of TypoScript information * @author Oliver Hader <*****@*****.**> */ protected function loadTemplates($pageId, $templateId = 0) { $templates = array(); // Check whether access is granted (only admin have access to sys_template records): if ($GLOBALS['BE_USER']->isAdmin()) { // Check whether there is a pageId given: if ($pageId) { $templates = $this->getMergedTemplates($pageId); } else { $this->ajaxObj->setError($GLOBALS['LANG']->getLL('pageIDInteger')); } } else { $this->ajaxObj->setError($GLOBALS['LANG']->getLL('noPermission')); } return $templates; }
/** * 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'); }
/** * 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); }
/** * @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); }
/** * 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); } }
/** * 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'); } }
/** * 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); }
/** * 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); }
/** * Ajax handler for the "suggest" feature in TCEforms. * * @param array $params The parameters from the AJAX call * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The AJAX object representing the AJAX call * @return void */ public function processAjaxRequest($params, &$ajaxObj) { // Get parameters from $_GET/$_POST $search = GeneralUtility::_GP('value'); $table = GeneralUtility::_GP('table'); $field = GeneralUtility::_GP('field'); $uid = GeneralUtility::_GP('uid'); $pageId = GeneralUtility::_GP('pid'); $newRecordRow = GeneralUtility::_GP('newRecordRow'); // If the $uid is numeric, we have an already existing element, so get the // TSconfig of the page itself or the element container (for non-page elements) // otherwise it's a new element, so use given id of parent page (i.e., don't modify it here) $row = NULL; if (is_numeric($uid)) { $row = BackendUtility::getRecord($table, $uid); if ($table == 'pages') { $pageId = $uid; } else { $pageId = $row['pid']; } } else { $row = unserialize($newRecordRow); } $TSconfig = BackendUtility::getPagesTSconfig($pageId); $queryTables = array(); $foreign_table_where = ''; $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config']; $parts = explode('|', $field); if ($GLOBALS['TCA'][$table]['columns'][$parts[0]]['config']['type'] === 'flex') { $flexfieldTCAConfig = $GLOBALS['TCA'][$table]['columns'][$parts[0]]['config']; $flexformDSArray = BackendUtility::getFlexFormDS($flexfieldTCAConfig, $row, $table, $parts[0]); $flexformDSArray = GeneralUtility::resolveAllSheetsInDS($flexformDSArray); $flexformElement = $parts[count($parts) - 2]; $continue = TRUE; foreach ($flexformDSArray as $sheet) { foreach ($sheet as $dataStructure) { $fieldConfig = $this->getNestedDsFieldConfig($dataStructure, $flexformElement); if (!empty($fieldConfig)) { $continue = FALSE; break; } } if (!$continue) { break; } } $field = str_replace('|', '][', $field); } $wizardConfig = $fieldConfig['wizards']['suggest']; if (isset($fieldConfig['allowed'])) { if ($fieldConfig['allowed'] === '*') { foreach ($GLOBALS['TCA'] as $tableName => $tableConfig) { // @todo Refactor function to BackendUtility if (empty($tableConfig['ctrl']['hideTable']) && ($GLOBALS['BE_USER']->isAdmin() || empty($tableConfig['ctrl']['adminOnly']) && (empty($tableConfig['ctrl']['rootLevel']) || !empty($tableConfig['ctrl']['security']['ignoreRootLevelRestriction'])))) { $queryTables[] = $tableName; } } unset($tableName, $tableConfig); } else { $queryTables = GeneralUtility::trimExplode(',', $fieldConfig['allowed']); } } elseif (isset($fieldConfig['foreign_table'])) { $queryTables = array($fieldConfig['foreign_table']); $foreign_table_where = $fieldConfig['foreign_table_where']; // strip ORDER BY clause $foreign_table_where = trim(preg_replace('/ORDER[[:space:]]+BY.*/i', '', $foreign_table_where)); } $resultRows = array(); // fetch the records for each query table. A query table is a table from which records are allowed to // be added to the TCEForm selector, originally fetched from the "allowed" config option in the TCA foreach ($queryTables as $queryTable) { // if the table does not exist, skip it if (!is_array($GLOBALS['TCA'][$queryTable]) || empty($GLOBALS['TCA'][$queryTable])) { continue; } $config = (array) $wizardConfig['default']; if (is_array($wizardConfig[$queryTable])) { \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($config, $wizardConfig[$queryTable]); } // merge the configurations of different "levels" to get the working configuration for this table and // field (i.e., go from the most general to the most special configuration) if (is_array($TSconfig['TCEFORM.']['suggest.']['default.'])) { \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($config, $TSconfig['TCEFORM.']['suggest.']['default.']); } if (is_array($TSconfig['TCEFORM.']['suggest.'][$queryTable . '.'])) { \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($config, $TSconfig['TCEFORM.']['suggest.'][$queryTable . '.']); } // use $table instead of $queryTable here because we overlay a config // for the input-field here, not for the queried table if (is_array($TSconfig['TCEFORM.'][$table . '.'][$field . '.']['suggest.']['default.'])) { \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($config, $TSconfig['TCEFORM.'][$table . '.'][$field . '.']['suggest.']['default.']); } if (is_array($TSconfig['TCEFORM.'][$table . '.'][$field . '.']['suggest.'][$queryTable . '.'])) { \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($config, $TSconfig['TCEFORM.'][$table . '.'][$field . '.']['suggest.'][$queryTable . '.']); } //process addWhere if (!isset($config['addWhere']) && $foreign_table_where) { $config['addWhere'] = $foreign_table_where; } if (isset($config['addWhere'])) { $replacement = array('###THIS_UID###' => (int) $uid, '###CURRENT_PID###' => (int) $pageId); if (isset($TSconfig['TCEFORM.'][$table . '.'][$field . '.'])) { $fieldTSconfig = $TSconfig['TCEFORM.'][$table . '.'][$field . '.']; if (isset($fieldTSconfig['PAGE_TSCONFIG_ID'])) { $replacement['###PAGE_TSCONFIG_ID###'] = (int) $fieldTSconfig['PAGE_TSCONFIG_ID']; } if (isset($fieldTSconfig['PAGE_TSCONFIG_IDLIST'])) { $replacement['###PAGE_TSCONFIG_IDLIST###'] = $GLOBALS['TYPO3_DB']->cleanIntList($fieldTSconfig['PAGE_TSCONFIG_IDLIST']); } if (isset($fieldTSconfig['PAGE_TSCONFIG_STR'])) { $replacement['###PAGE_TSCONFIG_STR###'] = $GLOBALS['TYPO3_DB']->quoteStr($fieldTSconfig['PAGE_TSCONFIG_STR'], $fieldConfig['foreign_table']); } } $config['addWhere'] = strtr(' ' . $config['addWhere'], $replacement); } // instantiate the class that should fetch the records for this $queryTable $receiverClassName = $config['receiverClass']; if (!class_exists($receiverClassName)) { $receiverClassName = SuggestWizardDefaultReceiver::class; } $receiverObj = GeneralUtility::makeInstance($receiverClassName, $queryTable, $config); $params = array('value' => $search); $rows = $receiverObj->queryTable($params); if (empty($rows)) { continue; } $resultRows = $rows + $resultRows; unset($rows); } $listItems = array(); if (!empty($resultRows)) { // traverse all found records and sort them $rowsSort = array(); foreach ($resultRows as $key => $row) { $rowsSort[$key] = $row['text']; } asort($rowsSort); $rowsSort = array_keys($rowsSort); // Limit the number of items in the result list $maxItems = $config['maxItemsInResultList'] ?: 10; $maxItems = min(count($resultRows), $maxItems); // put together the selector entry for ($i = 0; $i < $maxItems; $i++) { $row = $resultRows[$rowsSort[$i]]; $rowId = $row['table'] . '-' . $row['uid'] . '-' . $table . '-' . $uid . '-' . $field; $listItems[] = '<li' . ($row['class'] != '' ? ' class="' . $row['class'] . '"' : '') . ' id="' . $rowId . '"' . ($row['style'] != '' ? ' style="' . $row['style'] . '"' : '') . '>' . $row['sprite'] . $row['text'] . '</li>'; } } if (!empty($listItems)) { $list = implode('', $listItems); } else { $list = '<li class="suggest-noresults"><i>' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noRecordFound') . '</i></li>'; } $list = '<ul class="' . $this->cssClass . '-resultlist">' . $list . '</ul>'; $ajaxObj->addContent(0, $list); }
/** * Makes the AJAX call to expand or collapse the categorytree. * Called by typo3/ajax.php * * @param array $params Additional parameters (not used here) * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Ajax object * * @return void */ public function ajaxExpandCollapse(array $params, \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj) { $parameter = GeneralUtility::_GP('PM'); // IE takes anchor as parameter if (($parameterPosition = strpos($parameter, '#')) !== FALSE) { $parameter = substr($parameter, 0, $parameterPosition); } $parameter = GeneralUtility::trimExplode('_', $parameter); // Load the tree $this->initTree(); $tree = $this->treeObj->getBrowseableAjaxTree($parameter); $ajaxObj->addContent('tree', $tree); }
/** * Ajax callback that reads the smd file and modiefies the target URL to include * the module token. * * @param array $parameters (unused) * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler * @return void */ public function getWiringEditorSmd(array $parameters, AjaxRequestHandler $ajaxRequestHandler) { $smdJsonString = file_get_contents(ExtensionManagementUtility::extPath('extension_builder') . 'Resources/Public/jsDomainModeling/phpBackend/WiringEditor.smd'); $smdJson = json_decode($smdJsonString); $parameters = array('tx_extensionbuilder_tools_extensionbuilderextensionbuilder' => array('controller' => 'BuilderModule', 'action' => 'dispatchRpc')); $smdJson->target = BackendUtility::getModuleUrl('tools_ExtensionBuilderExtensionbuilder', $parameters); $smdJsonString = json_encode($smdJson); $ajaxRequestHandler->setContent(array($smdJsonString)); }
/** * 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'); }
/** * Makes the AJAX call to expand or collapse the pagetree. * Called by typo3/ajax.php * * @param array $params Additional parameters (not used here) * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The TYPO3AJAX object of this request * @return void */ public function ajaxExpandCollapse($params, $ajaxObj) { $this->init(); $tree = $this->pagetree->getBrowsableTree(); if (!$this->pagetree->ajaxStatus) { $ajaxObj->setError($tree); } else { $ajaxObj->addContent('tree', $tree); } }
/** * 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); }
/** * 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; } } }
/** * 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'); }
/** * 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'); }
/** * Renders the menu so that it can be returned as response to an AJAX call * * @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 renderAjax($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj = NULL) { $ajaxObj->addContent('opendocsMenu', $this->getDropDown()); }