本文整理汇总了PHP中TYPO3\CMS\Core\Http\AjaxRequestHandler::setContent方法的典型用法代码示例。如果您正苦于以下问题:PHP AjaxRequestHandler::setContent方法的具体用法?PHP AjaxRequestHandler::setContent怎么用?PHP AjaxRequestHandler::setContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Http\AjaxRequestHandler
的用法示例。
在下文中一共展示了AjaxRequestHandler::setContent方法的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: processAjaxRequest
/**
* 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 <oliver@typo3.org>
*/
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');
}
}
示例5: 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');
}
示例6: processAjaxRequest
/**
* 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 <oliver@typo3.org>
*/
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');
}
}
示例7: route
/**
* 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);
}
示例8: getWiringEditorSmd
/**
* 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));
}
示例9: getPlugins
/**
* 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 <oliver@typo3.org>
*/
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');
}
示例10: 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;
$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;
}
}
示例11: processInlineAjaxRequest
/**
* 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);
}
}
}
示例12: createTarget
/**
* 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);
}
}
示例13: processAjaxRequest
/**
* 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);
}
示例14: ajaxGetNodeContacts
/**
* 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');
}
}
示例15: getAPI
/**
* Parses the ExtDirect configuration array "$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']"
* and feeds the given typo3ajax instance with the resulting information. The get parameter
* "namespace" will be used to filter the configuration.
*
* This method makes usage of the reflection mechanism to fetch the methods inside the
* defined classes together with their amount of parameters. This information are building
* the API and are required by ExtDirect. The result is cached to improve the overall
* performance.
*
* @param array $ajaxParams Ajax parameters
* @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj typo3ajax instance
* @return void
*/
public function getAPI($ajaxParams, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj)
{
$ajaxObj->setContent(array());
}