コード例 #1
0
ファイル: index.php プロジェクト: rod86/t3sandbox
 /**
  * Checks various GET / POST parameters for submitted commands and handles them accordingly.
  * All commands will trigger a redirect by sending a location header after they work is done.
  *
  * Currently supported commands: 'createNewRecord', 'unlinkRecord', 'deleteRecord','pasteRecord',
  * 'makeLocalRecord', 'localizeElement', 'createNewPageTranslation' and 'editPageLanguageOverlay'
  *
  * @return	void
  * @access protected
  */
 function handleIncomingCommands()
 {
     $possibleCommands = array('createNewRecord', 'unlinkRecord', 'deleteRecord', 'pasteRecord', 'makeLocalRecord', 'localizeElement', 'createNewPageTranslation', 'editPageLanguageOverlay');
     $hooks = $this->hooks_prepareObjectsArray('handleIncomingCommands');
     foreach ($possibleCommands as $command) {
         if (($commandParameters = t3lib_div::_GP($command)) != '') {
             $redirectLocation = 'index.php?' . $this->link_getParameters();
             $skipCurrentCommand = false;
             foreach ($hooks as $hookObj) {
                 if (method_exists($hookObj, 'handleIncomingCommands_preProcess')) {
                     $skipCurrentCommand = $skipCurrentCommand || $hookObj->handleIncomingCommands_preProcess($command, $redirectLocation, $this);
                 }
             }
             if ($skipCurrentCommand) {
                 continue;
             }
             switch ($command) {
                 case 'createNewRecord':
                     // Historically "defVals" has been used for submitting the preset row data for the new element, so we still support it here:
                     $defVals = t3lib_div::_GP('defVals');
                     $newRow = is_array($defVals['tt_content']) ? $defVals['tt_content'] : array();
                     // Create new record and open it for editing
                     $destinationPointer = $this->apiObj->flexform_getPointerFromString($commandParameters);
                     $newUid = $this->apiObj->insertElement($destinationPointer, $newRow);
                     if ($this->editingOfNewElementIsEnabled($newRow['tx_templavoila_ds'], $newRow['tx_templavoila_to'])) {
                         // TODO If $newUid==0, than we could create new element. Need to handle it...
                         $redirectLocation = $GLOBALS['BACK_PATH'] . 'alt_doc.php?edit[tt_content][' . $newUid . ']=edit&returnUrl=' . rawurlencode(t3lib_extMgm::extRelPath('templavoila') . 'mod1/index.php?' . $this->link_getParameters());
                     }
                     break;
                 case 'unlinkRecord':
                     $unlinkDestinationPointer = $this->apiObj->flexform_getPointerFromString($commandParameters);
                     $this->apiObj->unlinkElement($unlinkDestinationPointer);
                     break;
                 case 'deleteRecord':
                     $deleteDestinationPointer = $this->apiObj->flexform_getPointerFromString($commandParameters);
                     $this->apiObj->deleteElement($deleteDestinationPointer);
                     break;
                 case 'pasteRecord':
                     $sourcePointer = $this->apiObj->flexform_getPointerFromString(t3lib_div::_GP('source'));
                     $destinationPointer = $this->apiObj->flexform_getPointerFromString(t3lib_div::_GP('destination'));
                     switch ($commandParameters) {
                         case 'copy':
                             $this->apiObj->copyElement($sourcePointer, $destinationPointer);
                             break;
                         case 'copyref':
                             $this->apiObj->copyElement($sourcePointer, $destinationPointer, FALSE);
                             break;
                         case 'cut':
                             $this->apiObj->moveElement($sourcePointer, $destinationPointer);
                             break;
                         case 'ref':
                             list(, $uid) = explode(':', t3lib_div::_GP('source'));
                             $this->apiObj->referenceElementByUid($uid, $destinationPointer);
                             break;
                     }
                     break;
                 case 'makeLocalRecord':
                     $sourcePointer = $this->apiObj->flexform_getPointerFromString($commandParameters);
                     $this->apiObj->copyElement($sourcePointer, $sourcePointer);
                     $this->apiObj->unlinkElement($sourcePointer);
                     break;
                 case 'localizeElement':
                     $sourcePointer = $this->apiObj->flexform_getPointerFromString(t3lib_div::_GP('source'));
                     $this->apiObj->localizeElement($sourcePointer, $commandParameters);
                     break;
                 case 'createNewPageTranslation':
                     // Create parameters and finally run the classic page module for creating a new page translation
                     $params = '&edit[pages_language_overlay][' . intval(t3lib_div::_GP('pid')) . ']=new&overrideVals[pages_language_overlay][doktype]=' . intval(t3lib_div::_GP('doktype')) . '&overrideVals[pages_language_overlay][sys_language_uid]=' . intval($commandParameters);
                     $returnUrl = '&returnUrl=' . rawurlencode(t3lib_extMgm::extRelPath('templavoila') . 'mod1/index.php?' . $this->link_getParameters());
                     $redirectLocation = $GLOBALS['BACK_PATH'] . 'alt_doc.php?' . $params . $returnUrl;
                     break;
                 case 'editPageLanguageOverlay':
                     // Look for pages language overlay record for language:
                     $sys_language_uid = intval($commandParameters);
                     $params = '';
                     if ($sys_language_uid != 0) {
                         // Edit overlay record
                         list($pLOrecord) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'pages_language_overlay', 'pid=' . intval($this->id) . ' AND sys_language_uid=' . $sys_language_uid . t3lib_BEfunc::deleteClause('pages_language_overlay') . t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'));
                         if ($pLOrecord) {
                             t3lib_beFunc::workspaceOL('pages_language_overlay', $pLOrecord);
                             if (is_array($pLOrecord)) {
                                 $params = '&edit[pages_language_overlay][' . $pLOrecord['uid'] . ']=edit';
                             }
                         }
                     } else {
                         // Edit default language (page properties)
                         // No workspace overlay because we already on this page
                         $params = '&edit[pages][' . intval($this->id) . ']=edit';
                     }
                     if ($params) {
                         $returnUrl = '&returnUrl=' . rawurlencode(t3lib_extMgm::extRelPath('templavoila') . 'mod1/index.php?' . $this->link_getParameters());
                         $redirectLocation = $GLOBALS['BACK_PATH'] . 'alt_doc.php?' . $params . $returnUrl;
                         //.'&localizationMode=text';
                     }
                     break;
             }
             foreach ($hooks as $hookObj) {
                 if (method_exists($hookObj, 'handleIncomingCommands_postProcess')) {
                     $hookObj->handleIncomingCommands_postProcess($command, $redirectLocation, $this);
                 }
             }
         }
     }
     if (isset($redirectLocation)) {
         header('Location: ' . t3lib_div::locationHeaderUrl($redirectLocation));
     }
 }