/**
  * 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);
     }
 }
    /**
     * 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);
				}
			');
        }
    }