/**
  * General processor for AJAX requests.
  * (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 processAjaxRequest($params, TYPO3AJAX &$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(intval(t3lib_div::_GP('pageId'))));
         $ajaxObj->setContentFormat('jsonbody');
     }
 }
 /**
  * General processor for AJAX requests.
  * (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 processAjaxRequest($params, TYPO3AJAX &$ajaxObj)
 {
     $this->ajaxObj = $ajaxObj;
     // Load the TSref XML information:
     $this->loadFile(t3lib_extMgm::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(t3lib_div::_GP('typeId'), t3lib_div::_GP('parameterName')));
         $ajaxObj->setContentFormat('plain');
     }
 }
 /**
  * Dispatches the incoming calls to methods about the ExtDirect API.
  *
  * @param aray $ajaxParams ajax parameters
  * @param TYPO3AJAX $ajaxObj typo3ajax instance
  * @return void
  */
 public function route($ajaxParams, TYPO3AJAX $ajaxObj)
 {
     try {
         $isForm = FALSE;
         $isUpload = FALSE;
         $rawPostData = file_get_contents('php://input');
         $postParameters = t3lib_div::_POST();
         $namespace = t3lib_div::_GET('namespace');
         if (!empty($postParameters['extAction'])) {
             $isForm = TRUE;
             $isUpload = $postParameters['extUpload'] === 'true';
             $request->action = $postParameters['extAction'];
             $request->method = $postParameters['extMethod'];
             $request->tid = $postParameters['extTID'];
             $request->data = array($_POST + $_FILES);
         } elseif (!empty($rawPostData)) {
             $request = json_decode($rawPostData);
         } else {
             throw new t3lib_error_Exception('ExtDirect: Missing Parameters!');
         }
         $response = NULL;
         if (is_array($request)) {
             $response = array();
             foreach ($request as $singleRequest) {
                 $response[] = $this->processRpc($singleRequest, $namespace);
             }
         } else {
             $response = $this->processRpc($request, $namespace);
         }
         if ($isForm && $isUpload) {
             $ajaxObj->setContentFormat('plain');
             $response = json_encode($response);
             $response = preg_replace('/&quot;/', '\\&quot;', $response);
             $response = array('<html><body><textarea>' . $response . '</textarea></body></html>');
         } else {
             $ajaxObj->setContentFormat('jsonbody');
         }
     } catch (t3lib_error_Exception $exception) {
         $response = array('type' => 'exception', 'message' => $exception->getMessage(), 'where' => $exception->getTraceAsString());
     }
     $ajaxObj->setContent($response);
 }
 /**
  * Create a tag
  *
  * @param array $params
  * @param TYPO3AJAX $ajaxObj
  * @return void
  * @throws Exception
  */
 public function createTag(array $params, TYPO3AJAX $ajaxObj)
 {
     $request = t3lib_div::_POST();
     try {
         // Check if a tag is submitted
         if (!isset($request['item']) || empty($request['item'])) {
             throw new Exception('error_no-tag');
         }
         $newsUid = $request['newsid'];
         if ((int) $newsUid === 0 && (strlen($newsUid) == 16 && !t3lib_div::isFirstPartOfStr($newsUid, 'NEW'))) {
             throw new Exception('error_no-newsid');
         }
         // Get tag uid
         $newTagId = $this->getTagUid($request);
         $ajaxObj->setContentFormat('javascript');
         $ajaxObj->setContent('');
         $response = array($newTagId, $request['item'], self::TAG, self::NEWS, 'tags', 'data[tx_news_domain_model_news][' . $newsUid . '][tags]', $newsUid);
         $ajaxObj->setJavascriptCallbackWrap(implode('-', $response));
     } catch (Exception $e) {
         $errorMsg = $GLOBALS['LANG']->sL(self::LLPATH . $e->getMessage());
         $ajaxObj->setError($errorMsg);
     }
 }
 /**
  * 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, TYPO3AJAX &$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');
 }
    /**
     * 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 TYPO3AJAX $ajaxObj typo3ajax instance
     * @return void
     */
    public function getAPI($ajaxParams, TYPO3AJAX $ajaxObj)
    {
        $filterNamespace = t3lib_div::_GET('namespace');
        // Check GET-parameter no_cache and extCache setting
        $extCache = isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache']) && ($GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] === 0 || $GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] === '0');
        $noCache = t3lib_div::_GET('no_cache') ? TRUE : $extCache;
        // look up into the cache
        $cacheIdentifier = 'ExtDirectApi';
        $cacheHash = md5($cacheIdentifier . $filterNamespace . serialize($this->settings));
        // with no_cache always generate the javascript content
        $cacheContent = $noCache ? '' : t3lib_pageSelect::getHash($cacheHash);
        // generate the javascript content if it wasn't found inside the cache and cache it!
        if (!$cacheContent) {
            $javascriptNamespaces = $this->generateAPI($filterNamespace);
            if (!empty($javascriptNamespaces)) {
                t3lib_pageSelect::storeHash($cacheHash, serialize($javascriptNamespaces), $cacheIdentifier);
            }
        } else {
            $javascriptNamespaces = unserialize($cacheContent);
        }
        // return the generated javascript API configuration
        if (count($javascriptNamespaces)) {
            $setup = '
				if (typeof Ext.app.ExtDirectAPI !== "object") {
					Ext.app.ExtDirectAPI = {};
				}

				if (typeof Object.extend !== "function") {
					Object.extend = function(destination, source) {
						for (var property in source) {
							destination[property] = source[property];
						}
						return destination;
					};
				}
			';
            $ajaxObj->setContent($javascriptNamespaces);
            $ajaxObj->setContentFormat('javascript');
            $ajaxObj->setJavascriptCallbackWrap($setup . 'Ext.app.ExtDirectAPI = Object.extend(Ext.app.ExtDirectAPI, |);');
        } else {
            if ($filterNamespace) {
                // namespace error
                $errorMessage = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:ExtDirect.namespaceError'), __CLASS__, $filterNamespace);
            } else {
                // no namespace given
                $errorMessage = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:ExtDirect.noNamespace'), __CLASS__);
            }
            // make js multiline message
            $msg = t3lib_div::trimExplode(LF, str_replace('"', '\\"', $errorMessage), TRUE);
            $errorMessage = '';
            foreach ($msg as $line) {
                $errorMessage .= '"' . $line . '" + ' . LF;
            }
            $errorMessage = substr(trim($errorMessage), 0, -1);
            //generate the javascript
            $ajaxObj->setContentFormat('javascript');
            $ajaxObj->setJavascriptCallbackWrap('
				errorMessage = ' . $errorMessage . ';
				if (typeof console === "object") {
					console.log(errorMessage);
				} else {
					alert(errorMessage);
				}
			');
        }
    }
 /**
  * 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 TYPO3AJAX $ajaxObj typo3ajax instance
  * @return void
  */
 public function getAPI($ajaxParams, TYPO3AJAX $ajaxObj)
 {
     $ajaxObj->setContent(array());
 }
 /**
  * Get the contacts for the given node for AJAX
  *
  * @param array $params
  * @param TYPO3AJAX $ajaxObj
  */
 public function ajaxGetNodeContacts($params, &$ajaxObj)
 {
     $node_id = t3lib_div::_GP('node');
     $node_repository = tx_caretaker_NodeRepository::getInstance();
     if ($node_id && ($node = $node_repository->id2node($node_id, true))) {
         $count = 0;
         $contacts = array();
         $nodeContacts = $node->getContacts();
         foreach ($nodeContacts as $nodeContact) {
             if ($role = $nodeContact->getRole()) {
                 $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');
     }
 }
 /**
  * Dispatches the incoming calls to methods about the ExtDirect API.
  *
  * @param aray $ajaxParams ajax parameters
  * @param TYPO3AJAX $ajaxObj typo3ajax instance
  * @return void
  */
 public function route($ajaxParams, TYPO3AJAX $ajaxObj)
 {
     $GLOBALS['error'] = t3lib_div::makeInstance('t3lib_extjs_ExtDirectDebug');
     $isForm = FALSE;
     $isUpload = FALSE;
     $rawPostData = file_get_contents('php://input');
     $postParameters = t3lib_div::_POST();
     $namespace = t3lib_div::_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 = t3lib_formprotection_Factory::get();
                 $validToken = $formprotection->validateToken($token, 'extDirect');
             }
             try {
                 if (!$validToken) {
                     throw new t3lib_formprotection_InvalidTokenException('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('/&quot;/', '\\&quot;', $response);
         $response = array('<html><body><textarea>' . $response . '</textarea></body></html>');
     } else {
         $ajaxObj->setContentFormat('jsonbody');
     }
     $ajaxObj->setContent($response);
 }