コード例 #1
0
    /**
     * method that adds JS files within the page renderer
     *
     * @param    array $parameters : An array of available parameters while adding JS to the page renderer
     * @param    \TYPO3\CMS\Core\Page\PageRenderer $pageRenderer : The parent object that triggered this hook
     *
     * @return    void
     */
    protected function addJS($parameters, &$pageRenderer)
    {
        $formprotection = FormProtectionFactory::get();
        if (count($parameters['jsFiles'])) {
            if (method_exists($GLOBALS['SOBE']->doc, 'issueCommand')) {
                /** @var \TYPO3\CMS\Backend\Clipboard\Clipboard $clipObj */
                $clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
                // Start clipboard
                $clipObj->initializeClipboard();
                $clipBoardHasContent = FALSE;
                if (isset($clipObj->clipData['normal']['el']) && strpos(key($clipObj->clipData['normal']['el']), 'tt_content') !== FALSE) {
                    $pasteURL = str_replace('&', '&', $clipObj->pasteUrl('tt_content', 'DD_PASTE_UID', 0));
                    if (isset($clipObj->clipData['normal']['mode'])) {
                        $clipBoardHasContent = 'copy';
                    } else {
                        $clipBoardHasContent = 'move';
                    }
                }
                $moveParams = '&cmd[tt_content][DD_DRAG_UID][move]=DD_DROP_UID';
                $moveURL = str_replace('&', '&', htmlspecialchars($GLOBALS['SOBE']->doc->issueCommand($moveParams, 1)));
                $copyParams = '&cmd[tt_content][DD_DRAG_UID][copy]=DD_DROP_UID&DDcopy=1';
                $copyURL = str_replace('&', '&', htmlspecialchars($GLOBALS['SOBE']->doc->issueCommand($copyParams, 1)));
                // add JavaScript library
                $pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . ExtensionManagementUtility::extRelPath('gridelements') . 'Resources/Public/Backend/JavaScript/dbNewContentElWizardFixDTM.js', $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '');
                // add JavaScript library
                $pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . ExtensionManagementUtility::extRelPath('gridelements') . 'Resources/Public/Backend/JavaScript/GridElementsDD.js', $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '');
                // add JavaScript library
                $pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . ExtensionManagementUtility::extRelPath('gridelements') . 'Resources/Public/Backend/JavaScript/GridElementsListView.js', $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '');
                if (!$pageRenderer->getCharSet()) {
                    $pageRenderer->setCharSet($GLOBALS['LANG']->charSet ? $GLOBALS['LANG']->charSet : 'utf-8');
                }
                if (is_array($clipObj->clipData['normal']['el'])) {
                    $arrCBKeys = array_keys($clipObj->clipData['normal']['el']);
                    $intFirstCBEl = str_replace('tt_content|', '', $arrCBKeys[0]);
                }
                // pull locallang_db.xml to JS side - only the tx_gridelements_js-prefixed keys
                $pageRenderer->addInlineLanguageLabelFile('EXT:gridelements/Resources/Private/Language/locallang_db.xml', 'tx_gridelements_js');
                $pRaddExtOnReadyCode = '
					TYPO3.l10n = {
						localize: function(langKey){
							return TYPO3.lang[langKey];
						}
					}
				';
                $allowedCTypesAndGridTypesClassesByColPos = array();
                $layoutSetup = GeneralUtility::callUserFunction('TYPO3\\CMS\\Backend\\View\\BackendLayoutView->getSelectedBackendLayout', intval(GeneralUtility::_GP('id')), $this);
                if (is_array($layoutSetup) && !empty($layoutSetup['__config']['backend_layout.']['rows.'])) {
                    foreach ($layoutSetup['__config']['backend_layout.']['rows.'] as $rows) {
                        foreach ($rows as $row) {
                            if (!empty($layoutSetup['__config']['backend_layout.']['rows.'])) {
                                foreach ($row as $col) {
                                    $classes = '';
                                    if ($col['allowed']) {
                                        $allowed = explode(',', $col['allowed']);
                                        foreach ($allowed as $ctypes) {
                                            $ctypes = trim($ctypes);
                                            if ($ctypes === '*') {
                                                $classes = 't3-allow-all';
                                                break;
                                            } else {
                                                $ctypes = explode(',', $ctypes);
                                                foreach ($ctypes as $ctype) {
                                                    $classes .= 't3-allow-' . $ctype . ' ';
                                                }
                                            }
                                        }
                                    } else {
                                        $classes = 't3-allow-all';
                                    }
                                    if ($col['allowedGridTypes']) {
                                        $allowedGridTypes = explode(',', $col['allowedGridTypes']);
                                        $classes .= 't3-allow-gridelements_pi1 ';
                                        foreach ($allowedGridTypes as $gridTypes) {
                                            $gridTypes = trim($gridTypes);
                                            if ($gridTypes !== '*') {
                                                $gridTypes = explode(',', $gridTypes);
                                                foreach ($gridTypes as $gridType) {
                                                    $classes .= 't3-allow-gridtype-' . $gridType . ' ';
                                                }
                                            }
                                        }
                                    } else {
                                        if ($classes !== 't3-allow-all') {
                                            $classes .= 't3-allow-gridelements_pi1 ';
                                        }
                                    }
                                    $allowedCTypesAndGridTypesClassesByColPos[] = $col['colPos'] . ':' . trim($classes);
                                }
                            }
                        }
                    }
                }
                // add Ext.onReady() code from file
                $modTSconfig = BackendUtility::getModTSconfig((int) GeneralUtility::_GP('id'), 'mod.web_layout');
                $pageRenderer->addExtOnReadyCode($pRaddExtOnReadyCode . "\n\t\t\t\t\t\ttop.pageColumnsAllowedCTypes = '" . join('|', $allowedCTypesAndGridTypesClassesByColPos) . "';\n\t\t\t\t\t\ttop.pasteURL = '" . $pasteURL . "';\n\t\t\t\t\t\ttop.moveURL = '" . $moveURL . "';\n\t\t\t\t\t\ttop.copyURL = '" . $copyURL . "';\n\t\t\t\t\t\ttop.pasteTpl = '" . str_replace('&redirect=1', '', str_replace('DDcopy=1', 'DDcopy=1&reference=DD_REFYN', $copyURL)) . "';\n\t\t\t\t\t\ttop.DDtceActionToken = '" . $formprotection->generateToken('tceAction') . "';\n\t\t\t\t\t\ttop.DDtoken = '" . $formprotection->generateToken('editRecord') . "';\n\t\t\t\t\t\ttop.DDpid = '" . (int) GeneralUtility::_GP('id') . "';\n\t\t\t\t\t\ttop.DDclipboardfilled = '" . ($clipBoardHasContent ? $clipBoardHasContent : 'false') . "';\n\t\t\t\t\t\ttop.pasteReferenceAllowed = '" . ($GLOBALS['BE_USER']->checkAuthMode('tt_content', 'CType', 11, 'explicitAllow') ? 'true' : 'false') . "';\n\t\t\t\t\t\ttop.newElementWizard = '" . ($modTSconfig['properties']['disableNewContentElementWizard'] ? 'false' : 'true') . "';\n\t\t\t\t\t\ttop.DDclipboardElId = '" . $intFirstCBEl . "';\n\t\t\t\t\t" . str_replace(array('top.skipDraggableDetails = 0;', 'insert_ext_baseurl_here', 'insert_server_time_here', 'top.geSprites = {};', "top.backPath = '';"), array($GLOBALS['BE_USER']->uc['dragAndDropHideNewElementWizardInfoOverlay'] ? 'top.skipDraggableDetails = true;' : 'top.skipDraggableDetails = false;', GeneralUtility::locationHeaderUrl('/' . ExtensionManagementUtility::siteRelPath('gridelements')), time() . '000', "top.geSprites = {\n\t\t\t\t\t\t\tcopyfrompage: '" . IconUtility::getSpriteIconClasses('extensions-gridelements-copyfrompage') . "',\n\t\t\t\t\t\t\t\tpastecopy: '" . IconUtility::getSpriteIconClasses('extensions-gridelements-pastecopy') . "',\n\t\t\t\t\t\t\t\tpasteref: '" . IconUtility::getSpriteIconClasses('extensions-gridelements-pasteref') . "'\n\t\t\t\t\t\t\t};", "top.backPath = '" . $GLOBALS['BACK_PATH'] . "';"), file_get_contents(ExtensionManagementUtility::extPath('gridelements') . 'Resources/Public/Backend/JavaScript/GridElementsDD_onReady.js')), TRUE);
            }
        }
    }
コード例 #2
0
 /**
  * wrapper function called by hook (\TYPO3\CMS\Core\Page\PageRenderer->render-preProcess)
  *
  * @param array $parameters : An array of available parameters
  * @param \TYPO3\CMS\Core\Page\PageRenderer $pageRenderer : The parent object that triggered this hook
  *
  * @return void
  */
 public function addJSCSS($parameters, &$pageRenderer)
 {
     if (get_class($GLOBALS['SOBE']) === 'TYPO3\\CMS\\Recordlist\\RecordList') {
         $pageRenderer->loadRequireJsModule('TYPO3/CMS/Gridelements/GridElementsOnReady');
         return;
     }
     if (get_class($GLOBALS['SOBE']) === 'TYPO3\\CMS\\Backend\\Controller\\PageLayoutController') {
         $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
         $pageRenderer->loadRequireJsModule('TYPO3/CMS/Gridelements/GridElementsOnReady');
         $pageRenderer->loadRequireJsModule('TYPO3/CMS/Gridelements/GridElementsDragDrop');
         $pageRenderer->loadRequireJsModule('TYPO3/CMS/Gridelements/GridElementsDragInWizard');
         /** @var Clipboard $clipObj */
         $clipObj = GeneralUtility::makeInstance(Clipboard::class);
         // Start clipboard
         $clipObj->initializeClipboard();
         $clipObj->lockToNormal();
         if (!$pageRenderer->getCharSet()) {
             $pageRenderer->setCharSet($GLOBALS['LANG']->charSet ? $GLOBALS['LANG']->charSet : 'utf-8');
         }
         // pull locallang_db.xml to JS side - only the tx_gridelements_js-prefixed keys
         $pageRenderer->addInlineLanguageLabelFile('EXT:gridelements/Resources/Private/Language/locallang_db.xml', 'tx_gridelements_js');
         $pAddExtOnReadyCode = '
             TYPO3.l10n = {
                 localize: function(langKey){
                     return TYPO3.lang[langKey];
                 }
             }
         ';
         $allowedContentTypesClassesByColPos = array();
         $allowedGridTypesClassesByColPos = array();
         $layoutSetup = GeneralUtility::callUserFunction('TYPO3\\CMS\\Backend\\View\\BackendLayoutView->getSelectedBackendLayout', intval(GeneralUtility::_GP('id')), $this);
         if (is_array($layoutSetup) && !empty($layoutSetup['__config']['backend_layout.']['rows.'])) {
             foreach ($layoutSetup['__config']['backend_layout.']['rows.'] as $rows) {
                 foreach ($rows as $row) {
                     if (!empty($layoutSetup['__config']['backend_layout.']['rows.'])) {
                         foreach ($row as $col) {
                             $classes = '';
                             $gridClasses = '';
                             if ($col['allowed']) {
                                 $allowed = explode(',', $col['allowed']);
                                 foreach ($allowed as $contentTypes) {
                                     $contentTypes = trim($contentTypes);
                                     if ($contentTypes === '*') {
                                         $classes = 't3-allow-all';
                                         break;
                                     } else {
                                         $contentTypes = explode(',', $contentTypes);
                                         foreach ($contentTypes as $contentType) {
                                             $classes .= 't3-allow-' . $contentType . ' ';
                                         }
                                     }
                                 }
                             } else {
                                 $classes = 't3-allow-all';
                             }
                             if ($col['allowedGridTypes']) {
                                 $allowedGridTypes = explode(',', $col['allowedGridTypes']);
                                 $classes .= 't3-allow-gridelements_pi1 ';
                                 foreach ($allowedGridTypes as $gridTypes) {
                                     $gridTypes = trim($gridTypes);
                                     if ($gridTypes !== '*') {
                                         $gridTypes = explode(',', $gridTypes);
                                         foreach ($gridTypes as $gridType) {
                                             $gridClasses .= 't3-allow-gridtype t3-allow-gridtype-' . $gridType . ' ';
                                         }
                                     }
                                 }
                                 if ($classes !== 't3-allow-all') {
                                     $classes .= 't3-allow-gridelements_pi1 ';
                                 }
                             }
                             $allowedContentTypesClassesByColPos[$col['colPos']] .= ' ' . trim($classes);
                             $allowedGridTypesClassesByColPos[$col['colPos']] .= ' ' . trim($gridClasses);
                         }
                     }
                 }
             }
         }
         // add Ext.onReady() code from file
         $pAddExtOnReadyCode .= "\n            top.pageColumnsAllowedCTypes = " . json_encode($allowedContentTypesClassesByColPos) . ";\n            top.pageColumnsAllowedGridTypes = " . json_encode($allowedGridTypesClassesByColPos) . ";\n            top.pasteReferenceAllowed = " . ($this->getBackendUser()->checkAuthMode('tt_content', 'CType', 'shortcut', 'explicitAllow') ? 'true' : 'false') . ";\n            top.skipDraggableDetails = " . ($this->getBackendUser()->uc['dragAndDropHideNewElementWizardInfoOverlay'] ? 'true' : 'false') . ";\n            top.backPath = '" . $GLOBALS['BACK_PATH'] . "';\n            top.browserUrl = '" . BackendUtility::getModuleUrl('wizard_element_browser') . "'";
         $elFromTable = $clipObj->elFromTable('tt_content');
         if (!empty($elFromTable)) {
             $pasteItem = substr(key($elFromTable), 11);
             $pasteRecord = BackendUtility::getRecord('tt_content', (int) $pasteItem);
             $pasteTitle = $pasteRecord['header'] ? $pasteRecord['header'] : $pasteItem;
             $copyMode = $clipObj->clipData['normal']['mode'] ? '-' . $clipObj->clipData['normal']['mode'] : '';
             $pAddExtOnReadyCode .= "\n                    top.pasteIntoLinkTemplate = " . json_encode('<a data-pasteitem="' . $pasteItem . '" data-pastetitle="' . $pasteTitle . '" class="t3js-paste t3js-paste' . $copyMode . ' t3js-paste-into btn btn-default" title="' . $this->getLanguageService()->sL('LLL:EXT:gridelements/Resources/Private/Language/locallang_db.xml:tx_gridelements_js.pasteinto') . '">' . $iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render() . '</a>') . ";\n                    top.pasteAfterLinkTemplate = " . json_encode('<a data-pasteitem="' . $pasteItem . '" data-pastetitle="' . $pasteTitle . '"  class="t3js-paste t3js-paste' . $copyMode . ' t3js-paste-after btn btn-default" title="' . $this->getLanguageService()->sL('LLL:EXT:gridelements/Resources/Private/Language/locallang_db.xml:tx_gridelements_js.pasteafter') . '">' . $iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render() . '</a>') . ";";
             if ($this->getBackendUser()->checkAuthMode('tt_content', 'CType', 'shortcut', 'explicitAllow')) {
                 $pAddExtOnReadyCode .= "\n                        top.pasteReferencesAllowed = true;";
             }
         } else {
             $pAddExtOnReadyCode .= "\n                    top.pasteIntoLinkTemplate = '';\n                    top.pasteAfterLinkTemplate = '';";
         }
         $pAddExtOnReadyCode .= "\n                    top.copyFromAnotherPageLinkTemplate = " . json_encode('<a class="t3js-paste-new btn btn-default" title="' . $this->getLanguageService()->sL('LLL:EXT:gridelements/Resources/Private/Language/locallang_db.xml:tx_gridelements_js.copyfrompage') . '">' . $iconFactory->getIcon('actions-insert-reference', Icon::SIZE_SMALL)->render() . '</a>') . ";";
         $pageRenderer->addJsInlineCode('gridelementsExtOnReady', $pAddExtOnReadyCode);
     }
 }