本文整理汇总了PHP中TYPO3\CMS\Core\Http\AjaxRequestHandler::setContentFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP AjaxRequestHandler::setContentFormat方法的具体用法?PHP AjaxRequestHandler::setContentFormat怎么用?PHP AjaxRequestHandler::setContentFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Http\AjaxRequestHandler
的用法示例。
在下文中一共展示了AjaxRequestHandler::setContentFormat方法的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
/**
* 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');
}
}
示例4: 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);
}
示例5: 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');
}
}
示例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;
$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');
}
}
示例7: 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.');
}
}
示例8: init
/**
* 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);
}
示例9: 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');
}
示例10: 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.');
}
}
示例11: 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');
}
示例12: 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');
}
}
示例13: renderFlashMessages
/**
* 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');
}
示例14: 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);
}
示例15: 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');
}
}