Exemplo n.º 1
0
    /**
     * Main function, rendering the document with the iframe with the RTE in.
     *
     * @return void
     * @todo Define visibility
     */
    public function main()
    {
        // Translate id to the workspace version:
        if ($versionRec = \TYPO3\CMS\Backend\Utility\BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $this->P['table'], $this->P['uid'], 'uid')) {
            $this->P['uid'] = $versionRec['uid'];
        }
        // If all parameters are available:
        if ($this->P['table'] && $this->P['field'] && $this->P['uid'] && $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
            // Getting the raw record (we need only the pid-value from here...)
            $rawRec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($this->P['table'], $this->P['uid']);
            \TYPO3\CMS\Backend\Utility\BackendUtility::fixVersioningPid($this->P['table'], $rawRec);
            // Setting JavaScript, including the pid value for viewing:
            $this->doc->JScode = $this->doc->wrapScriptTags('
					function jumpToUrl(URL,formEl) {	//
						if (document.editform) {
							if (!TBE_EDITOR.isFormChanged()) {
								window.location.href = URL;
							} else if (formEl) {
								if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
							}
						} else window.location.href = URL;
					}
				' . ($this->popView ? \TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($rawRec['pid'], '', \TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($rawRec['pid'])) : '') . '
			');
            // Initialize TCeforms - for rendering the field:
            $tceforms = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormEngine');
            // Init...
            $tceforms->initDefaultBEMode();
            // SPECIAL: Disables all wizards - we are NOT going to need them.
            $tceforms->disableWizards = 1;
            // SPECIAL: Setting background color of the RTE to ordinary background
            $tceforms->colorScheme[0] = $this->doc->bgColor;
            // Initialize style for RTE object:
            // Getting reference to the RTE object used to render the field!
            $RTEobj = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEgetObj();
            if ($RTEobj->ID == 'rte') {
                $RTEobj->RTEdivStyle = 'position:relative; left:0px; top:0px; height:100%; width:100%; border:solid 0px;';
            }
            // Fetching content of record:
            $trData = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\DataPreprocessor');
            $trData->lockRecords = 1;
            $trData->fetchRecord($this->P['table'], $this->P['uid'], '');
            // Getting the processed record content out:
            $rec = reset($trData->regTableItems_data);
            $rec['uid'] = $this->P['uid'];
            $rec['pid'] = $rawRec['pid'];
            // TSconfig, setting width:
            $fieldTSConfig = $tceforms->setTSconfig($this->P['table'], $rec, $this->P['field']);
            if (strcmp($fieldTSConfig['RTEfullScreenWidth'], '')) {
                $width = $fieldTSConfig['RTEfullScreenWidth'];
            } else {
                $width = '100%';
            }
            // Get the form field and wrap it in the table with the buttons:
            $formContent = $tceforms->getSoloField($this->P['table'], $rec, $this->P['field']);
            $formContent = '


			<!--
				RTE wizard:
			-->
				<table border="0" cellpadding="0" cellspacing="0" width="' . $width . '" id="typo3-rtewizard">
					<tr>
						<td width="' . $width . '" colspan="2" id="c-formContent">' . $formContent . '</td>
						<td></td>
					</tr>
				</table>';
            // Adding hidden fields:
            $formContent .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($this->R_URI) . '" />
						<input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction');
            // Finally, add the whole setup:
            $this->content .= $tceforms->printNeededJSFunctions_top() . $formContent . $tceforms->printNeededJSFunctions();
        } else {
            // ERROR:
            $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('forms_title'), '<span class="typo3-red">' . $GLOBALS['LANG']->getLL('table_noData', 1) . '</span>', 0, 1);
        }
        // Setting up the buttons and markers for docheader
        $docHeaderButtons = $this->getButtons();
        $markers['CONTENT'] = $this->content;
        // Build the <body> for the module
        $this->content = $this->doc->startPage('');
        $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
        $this->content .= $this->doc->endPage();
        $this->content = $this->doc->insertStylesAndJS($this->content);
    }
Exemplo n.º 2
0
 /**
  * Return the original or workspace page depending on workspace-mode
  *
  * @param integer $pageUid
  * @return array|boolean
  */
 public function getPage($pageUid)
 {
     $table = 'pages';
     $wsId = intval($GLOBALS['BE_USER']->workspace);
     $pageUid = intval($pageUid);
     if (1 > $pageUid) {
         return FALSE;
     }
     // check if active workspace is available
     $page = BackendUtility::getWorkspaceVersionOfRecord($wsId, $table, $pageUid);
     if (FALSE === $page) {
         // no workspace available ... use original one
         $page = BackendUtility::getRecord($table, $pageUid, '*');
     }
     return $page;
 }
Exemplo n.º 3
0
    /**
     * Main function, rendering the document with the iFrame with the RTE in.
     *
     * @return void
     */
    public function main()
    {
        $this->content .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_db')) . '" method="post" enctype="multipart/form-data" id="RteController" name="editform" ' . ' onsubmit="return TBE_EDITOR.checkSubmit(1);">';
        // Translate id to the workspace version:
        if ($versionedRecord = BackendUtility::getWorkspaceVersionOfRecord($this->getBackendUserAuthentication()->workspace, $this->P['table'], $this->P['uid'], 'uid')) {
            $this->P['uid'] = $versionedRecord['uid'];
        }
        // If all parameters are available:
        if ($this->P['table'] && $this->P['field'] && $this->P['uid'] && $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
            /** @var TcaDatabaseRecord $formDataGroup */
            $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
            /** @var FormDataCompiler $formDataCompiler */
            $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
            /** @var NodeFactory $nodeFactory */
            $nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
            $formDataCompilerInput = ['vanillaUid' => (int) $this->P['uid'], 'tableName' => $this->P['table'], 'command' => 'edit', 'disabledWizards' => true];
            $formData = $formDataCompiler->compile($formDataCompilerInput);
            $formData['fieldListToRender'] = $this->P['field'];
            $formData['renderType'] = 'outerWrapContainer';
            $formResult = $nodeFactory->create($formData)->render();
            /** @var FormResultCompiler $formResultCompiler */
            $formResultCompiler = GeneralUtility::makeInstance(FormResultCompiler::class);
            $formResultCompiler->mergeResult($formResult);
            // override the default jumpToUrl
            $this->moduleTemplate->addJavaScriptCode('RteWizardInlineCode', 'function jumpToUrl(URL,formEl) {
					if (document.editform) {
						if (!TBE_EDITOR.isFormChanged()) {
							window.location.href = URL;
						} else if (formEl) {
							if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
						}
					} else {
						window.location.href = URL;
					}
				}
			');
            // Setting JavaScript of the pid value for viewing:
            if ($this->popView) {
                $this->moduleTemplate->addJavaScriptCode('PopupViewInlineJS', BackendUtility::viewOnClick($formData['databaseRow']['pid'], '', BackendUtility::BEgetRootLine($formData['databaseRow']['pid'])));
            }
            $pageTsConfigMerged = $formData['pageTsConfigMerged'];
            if ((string) $pageTsConfigMerged['TCEFORM.'][$this->P['table'] . '.'][$this->P['field'] . '.']['RTEfullScreenWidth'] !== '') {
                $width = (string) $pageTsConfigMerged['TCEFORM.'][$this->P['table'] . '.'][$this->P['field'] . '.']['RTEfullScreenWidth'];
            } else {
                $width = '100%';
            }
            // Get the form field and wrap it in the table with the buttons:
            $formContent = $formResult['html'];
            $formContent = '
				<table border="0" cellpadding="0" cellspacing="0" width="' . $width . '" id="typo3-rtewizard">
					<tr>
						<td width="' . $width . '" colspan="2" id="c-formContent">' . $formContent . '</td>
						<td></td>
					</tr>
				</table>';
            // Adding hidden fields:
            $formContent .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($this->R_URI) . '" />
						<input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />';
            // Finally, add the whole setup:
            $this->content .= $formResultCompiler->JStop() . $formContent . $formResultCompiler->printNeededJSFunctions();
        } else {
            // ERROR:
            $this->content .= '<h2>' . $this->getLanguageService()->getLL('forms_title', true) . '</h2>' . '<div><span class="text-danger">' . $this->getLanguageService()->getLL('table_noData', true) . '</span></div>';
        }
        // Setting up the buttons and markers for docHeader
        $this->getButtons();
        // Build the <body> for the module
        $this->content .= '</form>';
        $this->moduleTemplate->setContent($this->content);
    }
Exemplo n.º 4
0
 /**
  * Get a single record row for a TCA table from the database.
  * t3lib_transferData is used for "upgrading" the values, especially the relations.
  *
  * @param integer $pid The pid of the page the record should be stored (only relevant for NEW records)
  * @param string $table The table to fetch data from (= foreign_table)
  * @param string $uid The uid of the record to fetch, or the pid if a new record should be created
  * @param string $cmd The command to perform, empty or 'new'
  * @return array A record row from the database post-processed by t3lib_transferData
  * @todo Define visibility
  */
 public function getRecord($pid, $table, $uid, $cmd = '')
 {
     // Fetch workspace version of a record (if any):
     if ($cmd !== 'new' && $GLOBALS['BE_USER']->workspace !== 0) {
         $workspaceVersion = \TYPO3\CMS\Backend\Utility\BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $uid, 'uid');
         if ($workspaceVersion !== FALSE) {
             $uid = $workspaceVersion['uid'];
         }
     }
     $trData = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\DataPreprocessor');
     $trData->addRawData = TRUE;
     $trData->lockRecords = 1;
     $trData->disableRTE = $GLOBALS['SOBE']->MOD_SETTINGS['disableRTE'];
     // If a new record should be created
     $trData->fetchRecord($table, $uid, $cmd === 'new' ? 'new' : '');
     $rec = reset($trData->regTableItems_data);
     return $rec;
 }
Exemplo n.º 5
0
 /**
  * Creates a new version of a record
  * (Requires support in the table)
  *
  * @param string $table Table name
  * @param int $id Record uid to versionize
  * @param string $label Version label
  * @param bool $delete If TRUE, the version is created to delete the record.
  * @return int|NULL Returns the id of the new version (if any)
  * @see copyRecord()
  */
 public function versionizeRecord($table, $id, $label, $delete = false)
 {
     $id = (int) $id;
     // Stop any actions if the record is marked to be deleted:
     // (this can occur if IRRE elements are versionized and child elements are removed)
     if ($this->isElementToBeDeleted($table, $id)) {
         return null;
     }
     if (!$GLOBALS['TCA'][$table] || !$GLOBALS['TCA'][$table]['ctrl']['versioningWS'] || $id <= 0) {
         if ($this->enableLogging) {
             $this->newlog('Versioning is not supported for this table "' . $table . '" / ' . $id, 1);
         }
         return null;
     }
     if (!$this->doesRecordExist($table, $id, 'show')) {
         if ($this->enableLogging) {
             $this->newlog('You didn\'t have correct permissions to make a new version (copy) of this record "' . $table . '" / ' . $id, 1);
         }
         return null;
     }
     // Select main record:
     $row = $this->recordInfo($table, $id, 'pid,t3ver_id,t3ver_state');
     if (!is_array($row)) {
         if ($this->enableLogging) {
             $this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize did not exist!', 1);
         }
         return null;
     }
     // Record must be online record
     if ($row['pid'] < 0) {
         if ($this->enableLogging) {
             $this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize was already a version in archive (pid=-1)!', 1);
         }
         return null;
     }
     // Record must not be placeholder for moving.
     if (VersionState::cast($row['t3ver_state'])->equals(VersionState::MOVE_PLACEHOLDER)) {
         if ($this->enableLogging) {
             $this->newlog('Record cannot be versioned because it is a placeholder for a moving operation', 1);
         }
         return null;
     }
     if ($delete && $this->cannotDeleteRecord($table, $id)) {
         if ($this->enableLogging) {
             $this->newlog('Record cannot be deleted: ' . $this->cannotDeleteRecord($table, $id), 1);
         }
         return null;
     }
     // Look for next version number:
     $res = $this->databaseConnection->exec_SELECTquery('t3ver_id', $table, '((pid=-1 && t3ver_oid=' . $id . ') OR uid=' . $id . ')' . $this->deleteClause($table), '', 't3ver_id DESC', '1');
     list($highestVerNumber) = $this->databaseConnection->sql_fetch_row($res);
     $this->databaseConnection->sql_free_result($res);
     // Look for version number of the current:
     $subVer = $row['t3ver_id'] . '.' . ($highestVerNumber + 1);
     // Set up the values to override when making a raw-copy:
     $overrideArray = array('t3ver_id' => $highestVerNumber + 1, 't3ver_oid' => $id, 't3ver_label' => $label ?: $subVer . ' / ' . date('d-m-Y H:m:s'), 't3ver_wsid' => $this->BE_USER->workspace, 't3ver_state' => (string) ($delete ? new VersionState(VersionState::DELETE_PLACEHOLDER) : new VersionState(VersionState::DEFAULT_STATE)), 't3ver_count' => 0, 't3ver_stage' => 0, 't3ver_tstamp' => 0);
     if ($GLOBALS['TCA'][$table]['ctrl']['editlock']) {
         $overrideArray[$GLOBALS['TCA'][$table]['ctrl']['editlock']] = 0;
     }
     // Checking if the record already has a version in the current workspace of the backend user
     if ($this->BE_USER->workspace !== 0) {
         // Look for version already in workspace:
         $versionRecord = BackendUtility::getWorkspaceVersionOfRecord($this->BE_USER->workspace, $table, $id, 'uid');
     }
     // Create new version of the record and return the new uid
     if (empty($versionRecord['uid'])) {
         // Create raw-copy and return result:
         // The information of the label to be used for the workspace record
         // as well as the information whether the record shall be removed
         // must be forwarded (creating remove placeholders on a workspace are
         // done by copying the record and override several fields).
         $workspaceOptions = array('delete' => $delete, 'label' => $label);
         return $this->copyRecord_raw($table, $id, -1, $overrideArray, $workspaceOptions);
         // Reuse the existing record and return its uid
         // (prior to TYPO3 CMS 6.2, an error was thrown here, which
         // did not make much sense since the information is available)
     } else {
         return $versionRecord['uid'];
     }
     return null;
 }
Exemplo n.º 6
0
 /**
  * Convert input element reference to workspace version if any.
  *
  * @param string $table Table of input element
  * @param integer $uid UID of record
  * @return integer converted UID of record
  * @todo Define visibility
  */
 public function resolveElement($table, $uid)
 {
     if (isset($GLOBALS['TCA'][$table])) {
         if ($workspaceVersion = BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $uid, 'uid')) {
             $uid = $workspaceVersion['uid'];
         }
     }
     return $uid;
 }
Exemplo n.º 7
0
 /**
  * Processes a single field of a moved record and follows references.
  *
  * @param DataHandler $dataHandler Calling DataHandler instance
  * @param int $resolvedPageId Resolved real destination page id
  * @param string $table Name of parent table
  * @param int $uid UID of the parent record
  * @param string $field Name of the field of the parent record
  * @param string $value Value of the field of the parent record
  * @param array $configuration TCA field configuration of the parent record
  * @return void
  */
 protected function moveRecord_processFieldValue(DataHandler $dataHandler, $resolvedPageId, $table, $uid, $field, $value, array $configuration)
 {
     $inlineFieldType = $dataHandler->getInlineFieldType($configuration);
     $inlineProcessing = ($inlineFieldType === 'list' || $inlineFieldType === 'field') && BackendUtility::isTableMovePlaceholderAware($configuration['foreign_table']) && (!isset($configuration['behaviour']['disableMovingChildrenWithParent']) || !$configuration['behaviour']['disableMovingChildrenWithParent']);
     if ($inlineProcessing) {
         if ($table === 'pages') {
             // If the inline elements are related to a page record,
             // make sure they reside at that page and not at its parent
             $resolvedPageId = $uid;
         }
         $dbAnalysis = $this->createRelationHandlerInstance();
         $dbAnalysis->start($value, $configuration['foreign_table'], '', $uid, $table, $configuration);
         // Moving records to a positive destination will insert each
         // record at the beginning, thus the order is reversed here:
         foreach ($dbAnalysis->itemArray as $item) {
             $versionedRecord = BackendUtility::getWorkspaceVersionOfRecord($dataHandler->BE_USER->workspace, $item['table'], $item['id'], 'uid,t3ver_state');
             if (empty($versionedRecord) || VersionState::cast($versionedRecord['t3ver_state'])->indicatesPlaceholder()) {
                 continue;
             }
             $dataHandler->moveRecord($item['table'], $item['id'], $resolvedPageId);
         }
     }
 }
    /**
     * Rendering the quick-edit view.
     *
     * @return void
     * @todo Define visibility
     */
    public function renderQuickEdit()
    {
        // Alternative template
        $this->doc->setModuleTemplate('templates/db_layout_quickedit.html');
        // Alternative form tag; Quick Edit submits its content to tce_db.php.
        $this->doc->form = '<form action="' . htmlspecialchars($GLOBALS['BACK_PATH'] . 'tce_db.php?&prErr=1&uPT=1') . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
        // Setting up the context sensitive menu:
        $this->doc->getContextMenuCode();
        // Set the edit_record value for internal use in this function:
        $edit_record = $this->edit_record;
        // If a command to edit all records in a column is issue, then select all those elements, and redirect to alt_doc.php:
        if (substr($edit_record, 0, 9) == '_EDIT_COL') {
            $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_content', 'pid=' . intval($this->id) . ' AND colPos=' . intval(substr($edit_record, 10)) . ' AND sys_language_uid=' . intval($this->current_sys_language) . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tt_content')) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tt_content') . \TYPO3\CMS\Backend\Utility\BackendUtility::versioningPlaceholderClause('tt_content'), '', 'sorting');
            $idListA = array();
            while ($cRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                $idListA[] = $cRow['uid'];
            }
            $url = $GLOBALS['BACK_PATH'] . 'alt_doc.php?edit[tt_content][' . implode(',', $idListA) . ']=edit&returnUrl=' . rawurlencode($this->local_linkThisScript(array('edit_record' => '')));
            \TYPO3\CMS\Core\Utility\HttpUtility::redirect($url);
        }
        // If the former record edited was the creation of a NEW record, this will look up the created records uid:
        if ($this->new_unique_uid) {
            $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_log', 'userid=' . intval($GLOBALS['BE_USER']->user['uid']) . ' AND NEWid=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->new_unique_uid, 'sys_log'));
            $sys_log_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
            if (is_array($sys_log_row)) {
                $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
            }
        }
        // Creating the selector box, allowing the user to select which element to edit:
        $opt = array();
        $is_selected = 0;
        $languageOverlayRecord = '';
        if ($this->current_sys_language) {
            list($languageOverlayRecord) = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $this->id, 'AND sys_language_uid=' . intval($this->current_sys_language));
        }
        if (is_array($languageOverlayRecord)) {
            $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
            $is_selected += intval($edit_record == $inValue);
            $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $GLOBALS['LANG']->getLL('editLanguageHeader', 1) . ' ]</option>';
        } else {
            $inValue = 'pages:' . $this->id;
            $is_selected += intval($edit_record == $inValue);
            $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $GLOBALS['LANG']->getLL('editPageProperties', 1) . ' ]</option>';
        }
        // Selecting all content elements from this language and allowed colPos:
        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_content', 'pid=' . intval($this->id) . ' AND sys_language_uid=' . intval($this->current_sys_language) . ' AND colPos IN (' . $this->colPosList . ')' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tt_content')) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tt_content') . \TYPO3\CMS\Backend\Utility\BackendUtility::versioningPlaceholderClause('tt_content'), '', 'colPos,sorting');
        $colPos = '';
        $first = 1;
        // Page is the pid if no record to put this after.
        $prev = $this->id;
        while ($cRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
            \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL('tt_content', $cRow);
            if (is_array($cRow)) {
                if ($first) {
                    if (!$edit_record) {
                        $edit_record = 'tt_content:' . $cRow['uid'];
                    }
                    $first = 0;
                }
                if (strcmp($cRow['colPos'], $colPos)) {
                    $colPos = $cRow['colPos'];
                    $opt[] = '<option value=""></option>';
                    $opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $GLOBALS['LANG']->sL(\TYPO3\CMS\Backend\Utility\BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), 1) . ':__</option>';
                }
                $inValue = 'tt_content:' . $cRow['uid'];
                $is_selected += intval($edit_record == $inValue);
                $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($cRow['header'] ? $cRow['header'] : '[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title') . '] ' . strip_tags($cRow['bodytext']), $GLOBALS['BE_USER']->uc['titleLen'])) . '</option>';
                $prev = -$cRow['uid'];
            }
        }
        // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
        if (!$edit_record) {
            $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
            $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
            $is_selected += intval($edit_record == $inValue);
            $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $GLOBALS['LANG']->getLL('newLabel', 1) . ' ]</option>';
        }
        // If none is yet selected...
        if (!$is_selected) {
            $opt[] = '<option value=""></option>';
            $opt[] = '<option value="' . $edit_record . '"  selected="selected">[ ' . $GLOBALS['LANG']->getLL('newLabel', 1) . ' ]</option>';
        }
        // Splitting the edit-record cmd value into table/uid:
        $this->eRParts = explode(':', $edit_record);
        // Delete-button flag?
        $this->deleteButton = \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($this->eRParts[0] != 'pages' && $this->EDIT_CONTENT || $this->eRParts[0] == 'pages' && $this->CALC_PERMS & 4);
        // If undo-button should be rendered (depends on available items in sys_history)
        $this->undoButton = 0;
        $undoRes = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->eRParts[0], 'sys_history') . ' AND recuid=' . intval($this->eRParts[1]), '', 'tstamp DESC', '1');
        if ($this->undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes)) {
            $this->undoButton = 1;
        }
        // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
        $R_URL_parts = parse_url(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'));
        $R_URL_getvars = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET();
        unset($R_URL_getvars['popView']);
        unset($R_URL_getvars['new_unique_uid']);
        $R_URL_getvars['edit_record'] = $edit_record;
        $this->R_URI = $R_URL_parts['path'] . '?' . \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
        // Setting close url/return url for exiting this script:
        // Goes to 'Columns' view if close is pressed (default)
        $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
        if ($GLOBALS['BE_USER']->uc['condensedMode']) {
            $this->closeUrl = $GLOBALS['BACK_PATH'] . 'alt_db_navframe.php';
        }
        if ($this->returnUrl) {
            $this->closeUrl = $this->returnUrl;
        }
        // Return-url for JavaScript:
        $retUrlStr = $this->returnUrl ? '+\'&returnUrl=\'+\'' . rawurlencode($this->returnUrl) . '\'' : '';
        // Drawing the edit record selectbox
        $this->editSelect = '<select name="edit_record" onchange="' . htmlspecialchars('jumpToUrl(\'db_layout.php?id=' . $this->id . '&edit_record=\'+escape(this.options[this.selectedIndex].value)' . $retUrlStr . ',this);') . '">' . implode('', $opt) . '</select>';
        // Creating editing form:
        if ($GLOBALS['BE_USER']->check('tables_modify', $this->eRParts[0]) && $edit_record && ($this->eRParts[0] !== 'pages' && $this->EDIT_CONTENT || $this->eRParts[0] === 'pages' && $this->CALC_PERMS & 1)) {
            // Splitting uid parts for special features, if new:
            list($uidVal, $ex_pid, $ex_colPos) = explode('/', $this->eRParts[1]);
            // Convert $uidVal to workspace version if any:
            if ($uidVal != 'new') {
                if ($draftRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $this->eRParts[0], $uidVal, 'uid')) {
                    $uidVal = $draftRecord['uid'];
                }
            }
            // Initializing transfer-data object:
            $trData = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\DataPreprocessor');
            $trData->addRawData = TRUE;
            $trData->defVals[$this->eRParts[0]] = array('colPos' => intval($ex_colPos), 'sys_language_uid' => intval($this->current_sys_language));
            $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
            $trData->lockRecords = 1;
            // 'new'
            $trData->fetchRecord($this->eRParts[0], $uidVal == 'new' ? $this->id : $uidVal, $uidVal);
            // Getting/Making the record:
            reset($trData->regTableItems_data);
            $rec = current($trData->regTableItems_data);
            if ($uidVal == 'new') {
                $new_unique_uid = uniqid('NEW');
                $rec['uid'] = $new_unique_uid;
                $rec['pid'] = intval($ex_pid) ? intval($ex_pid) : $this->id;
                $recordAccess = TRUE;
            } else {
                $rec['uid'] = $uidVal;
                // Checking internals access:
                $recordAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($this->eRParts[0], $uidVal);
            }
            if (!$recordAccess) {
                // If no edit access, print error message:
                $content .= $this->doc->section($GLOBALS['LANG']->getLL('noAccess'), $GLOBALS['LANG']->getLL('noAccess_msg') . '<br /><br />' . ($GLOBALS['BE_USER']->errorMsg ? 'Reason: ' . $GLOBALS['BE_USER']->errorMsg . '<br /><br />' : ''), 0, 1);
            } elseif (is_array($rec)) {
                // If the record is an array (which it will always be... :-)
                // Create instance of TCEforms, setting defaults:
                $tceforms = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormEngine');
                $tceforms->backPath = $GLOBALS['BACK_PATH'];
                $tceforms->initDefaultBEMode();
                $tceforms->fieldOrder = $this->modTSconfig['properties']['tt_content.']['fieldOrder'];
                $tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
                $tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
                $tceforms->enableClickMenu = TRUE;
                // Clipboard is initialized:
                // Start clipboard
                $tceforms->clipObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
                // Initialize - reads the clipboard content from the user session
                $tceforms->clipObj->initializeClipboard();
                // Render form, wrap it:
                $panel = '';
                $panel .= $tceforms->getMainFields($this->eRParts[0], $rec);
                $panel = $tceforms->wrapTotal($panel, $rec, $this->eRParts[0]);
                // Add hidden fields:
                $theCode = $panel;
                if ($uidVal == 'new') {
                    $theCode .= '<input type="hidden" name="data[' . $this->eRParts[0] . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
                }
                $theCode .= '
					<input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
					<input type="hidden" name="_disableRTE" value="' . $tceforms->disableRTE . '" />
					<input type="hidden" name="edit_record" value="' . $edit_record . '" />
					<input type="hidden" name="redirect" value="' . htmlspecialchars($uidVal == 'new' ? \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('cms') . 'layout/db_layout.php?id=' . $this->id . '&new_unique_uid=' . $new_unique_uid . '&returnUrl=' . rawurlencode($this->returnUrl) : $this->R_URI) . '" />
					' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction');
                // Add JavaScript as needed around the form:
                $theCode = $tceforms->printNeededJSFunctions_top() . $theCode . $tceforms->printNeededJSFunctions();
                // Add warning sign if record was "locked":
                if ($lockInfo = \TYPO3\CMS\Backend\Utility\BackendUtility::isRecordLocked($this->eRParts[0], $rec['uid'])) {
                    $lockedMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', htmlspecialchars($lockInfo['msg']), '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
                    \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($lockedMessage);
                }
                // Add whole form as a document section:
                $content .= $this->doc->section('', $theCode);
            }
        } else {
            // If no edit access, print error message:
            $content .= $this->doc->section($GLOBALS['LANG']->getLL('noAccess'), $GLOBALS['LANG']->getLL('noAccess_msg') . '<br /><br />', 0, 1);
        }
        // Bottom controls (function menus):
        $q_count = $this->getNumberOfHiddenElements();
        $h_func_b = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], 'db_layout.php', '', 'id="checkTt_content_showHidden"') . '<label for="checkTt_content_showHidden">' . (!$q_count ? $GLOBALS['TBE_TEMPLATE']->dfw($GLOBALS['LANG']->getLL('hiddenCE', 1)) : $GLOBALS['LANG']->getLL('hiddenCE', 1) . ' (' . $q_count . ')') . '</label>';
        $h_func_b .= '<br />' . \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->id, 'SET[showPalettes]', $this->MOD_SETTINGS['showPalettes'], 'db_layout.php', '', 'id="checkShowPalettes"') . '<label for="checkShowPalettes">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPalettes', 1) . '</label>';
        if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('context_help')) {
            $h_func_b .= '<br />' . \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->id, 'SET[showDescriptions]', $this->MOD_SETTINGS['showDescriptions'], 'db_layout.php', '', 'id="checkShowDescriptions"') . '<label for="checkShowDescriptions">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showDescriptions', 1) . '</label>';
        }
        if ($GLOBALS['BE_USER']->isRTE()) {
            $h_func_b .= '<br />' . \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->id, 'SET[disableRTE]', $this->MOD_SETTINGS['disableRTE'], 'db_layout.php', '', 'id="checkDisableRTE"') . '<label for="checkDisableRTE">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.disableRTE', 1) . '</label>';
        }
        // Add the function menus to bottom:
        $content .= $this->doc->section('', $h_func_b, 0, 0);
        $content .= $this->doc->spacer(10);
        // Select element matrix:
        if ($this->eRParts[0] == 'tt_content' && \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
            $posMap = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('ext_posMap');
            $posMap->backPath = $GLOBALS['BACK_PATH'];
            $posMap->cur_sys_language = $this->current_sys_language;
            $HTMLcode = '';
            // CSH:
            $HTMLcode .= \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', $GLOBALS['BACK_PATH'], '|<br />');
            $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
            $content .= $this->doc->spacer(20);
            $content .= $this->doc->section($GLOBALS['LANG']->getLL('CEonThisPage'), $HTMLcode, 0, 1);
            $content .= $this->doc->spacer(20);
        }
        // Finally, if comments were generated in TCEforms object, print these as a HTML comment:
        if (count($tceforms->commentMessages)) {
            $content .= '
	<!-- TCEFORM messages
	' . htmlspecialchars(implode(LF, $tceforms->commentMessages)) . '
	-->
	';
        }
        return $content;
    }
 /**
  * Evaluates if auto creation of a version of a record is allowed.
  *
  * @param string $table Table of the record
  * @param integer $id UID of record
  * @param integer $recpid PID of record
  * @return boolean TRUE if ok.
  * @todo Define visibility
  */
 public function workspaceAllowAutoCreation($table, $id, $recpid)
 {
     // Auto-creation of version: In offline workspace, test if versioning is
     // enabled and look for workspace version of input record.
     // If there is no versionized record found we will create one and save to that.
     if ($this->workspace !== 0 && !$this->workspaceRec['disable_autocreate'] && $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $recpid >= 0 && !BackendUtility::getWorkspaceVersionOfRecord($this->workspace, $table, $id, 'uid')) {
         // There must be no existing version of this record in workspace.
         return TRUE;
     } elseif ($this->workspaceRec['disable_autocreate']) {
         GeneralUtility::deprecationLog('Usage of disable_autocreate feature is deprecated since 4.5.');
     }
     return FALSE;
 }
Exemplo n.º 10
0
 /**
  * Creates a new version of a record
  * (Requires support in the table)
  *
  * @param string $table Table name
  * @param integer $id Record uid to versionize
  * @param string $label Version label
  * @param boolean $delete If TRUE, the version is created to delete the record.
  * @return integer Returns the id of the new version (if any)
  * @see copyRecord()
  * @todo Define visibility
  */
 public function versionizeRecord($table, $id, $label, $delete = FALSE)
 {
     $id = intval($id);
     // Stop any actions if the record is marked to be deleted:
     // (this can occur if IRRE elements are versionized and child elements are removed)
     if ($this->isElementToBeDeleted($table, $id)) {
         return NULL;
     }
     if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $id > 0) {
         if ($this->doesRecordExist($table, $id, 'show')) {
             // Select main record:
             $row = $this->recordInfo($table, $id, 'pid,t3ver_id,t3ver_state');
             if (is_array($row)) {
                 // Record must be online record
                 if ($row['pid'] >= 0) {
                     // Record must not be placeholder for moving.
                     if ($row['t3ver_state'] != 3) {
                         if (!$delete || !$this->cannotDeleteRecord($table, $id)) {
                             // Look for next version number:
                             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('t3ver_id', $table, '((pid=-1 && t3ver_oid=' . $id . ') OR uid=' . $id . ')' . $this->deleteClause($table), '', 't3ver_id DESC', '1');
                             list($highestVerNumber) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
                             $GLOBALS['TYPO3_DB']->sql_free_result($res);
                             // Look for version number of the current:
                             $subVer = $row['t3ver_id'] . '.' . ($highestVerNumber + 1);
                             // Set up the values to override when making a raw-copy:
                             $overrideArray = array('t3ver_id' => $highestVerNumber + 1, 't3ver_oid' => $id, 't3ver_label' => $label ? $label : $subVer . ' / ' . date('d-m-Y H:m:s'), 't3ver_wsid' => $this->BE_USER->workspace, 't3ver_state' => $delete ? 2 : 0, 't3ver_count' => 0, 't3ver_stage' => 0, 't3ver_tstamp' => 0);
                             if ($GLOBALS['TCA'][$table]['ctrl']['editlock']) {
                                 $overrideArray[$GLOBALS['TCA'][$table]['ctrl']['editlock']] = 0;
                             }
                             // Checking if the record already has a version in the current workspace of the backend user
                             $workspaceCheck = TRUE;
                             if ($this->BE_USER->workspace !== 0) {
                                 // Look for version already in workspace:
                                 $workspaceCheck = \TYPO3\CMS\Backend\Utility\BackendUtility::getWorkspaceVersionOfRecord($this->BE_USER->workspace, $table, $id, 'uid') ? FALSE : TRUE;
                             }
                             if ($workspaceCheck) {
                                 // Create raw-copy and return result:
                                 // The information of the label to be used for the workspace record
                                 // as well as the information whether the record shall be removed
                                 // must be forwarded (creating remove placeholders on a workspace are
                                 // done by copying the record and override several fields).
                                 $workspaceOptions = array();
                                 if ($delete) {
                                     $workspaceOptions['delete'] = $delete;
                                     $workspaceOptions['label'] = $label;
                                 }
                                 return $this->copyRecord_raw($table, $id, -1, $overrideArray, $workspaceOptions);
                             } else {
                                 $this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize was already a version in the workspace (wsid=' . $this->BE_USER->workspace . ')!', 1);
                             }
                         } else {
                             $this->newlog('Record cannot be deleted: ' . $this->cannotDeleteRecord($table, $id), 1);
                         }
                     } else {
                         $this->newlog('Record cannot be versioned because it is a placeholder for a moving operation', 1);
                     }
                 } else {
                     $this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize was already a version in archive (pid=-1)!', 1);
                 }
             } else {
                 $this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize did not exist!', 1);
             }
         } else {
             $this->newlog('You didnt have correct permissions to make a new version (copy) of this record "' . $table . '" / ' . $id, 1);
         }
     } else {
         $this->newlog('Versioning is not supported for this table "' . $table . '" / ' . $id, 1);
     }
 }
Exemplo n.º 11
0
 /**
  * Evaluates if auto creation of a version of a record is allowed.
  *
  * @param string $table Table of the record
  * @param int $id UID of record
  * @param int $recpid PID of record
  * @return bool TRUE if ok.
  */
 public function workspaceAllowAutoCreation($table, $id, $recpid)
 {
     // Auto-creation of version: In offline workspace, test if versioning is
     // enabled and look for workspace version of input record.
     // If there is no versionized record found we will create one and save to that.
     if ($this->workspace !== 0 && $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $recpid >= 0 && !BackendUtility::getWorkspaceVersionOfRecord($this->workspace, $table, $id, 'uid')) {
         // There must be no existing version of this record in workspace.
         return true;
     }
     return false;
 }
Exemplo n.º 12
0
 /**
  * Substitute given list of uids in child table with workspace uid if needed
  *
  * @param array $connectedUids List of connected uids
  * @param string $childTableName Name of child table
  * @return array List of uids in workspace
  */
 protected function getWorkspacedUids(array $connectedUids, $childTableName)
 {
     $backendUser = $this->getBackendUser();
     $newConnectedUids = [];
     foreach ($connectedUids as $uid) {
         // Fetch workspace version of a record (if any):
         // @todo: Needs handling
         if ($backendUser->workspace !== 0 && BackendUtility::isTableWorkspaceEnabled($childTableName)) {
             $workspaceVersion = BackendUtility::getWorkspaceVersionOfRecord($backendUser->workspace, $childTableName, $uid, 'uid,t3ver_state');
             if ($workspaceVersion !== false) {
                 $versionState = VersionState::cast($workspaceVersion['t3ver_state']);
                 if ($versionState->equals(VersionState::DELETE_PLACEHOLDER)) {
                     return [];
                 }
                 $uid = $workspaceVersion['uid'];
             }
         }
         $newConnectedUids[] = $uid;
     }
     return $newConnectedUids;
 }
 /**
  * Get a single record row for a TCA table from the database.
  * \TYPO3\CMS\Backend\Form\DataPreprocessor is used for "upgrading" the
  * values, especially the relations.
  * Used in inline context
  *
  * @param string $table The table to fetch data from (= foreign_table)
  * @param string $uid The uid of the record to fetch, or the pid if a new record should be created
  * @param string $cmd The command to perform, empty or 'new'
  * @return array A record row from the database post-processed by \TYPO3\CMS\Backend\Form\DataPreprocessor
  * @internal
  */
 public function getRecord($table, $uid, $cmd = '')
 {
     $backendUser = $this->getBackendUserAuthentication();
     // Fetch workspace version of a record (if any):
     if ($cmd !== 'new' && $backendUser->workspace !== 0 && BackendUtility::isTableWorkspaceEnabled($table)) {
         $workspaceVersion = BackendUtility::getWorkspaceVersionOfRecord($backendUser->workspace, $table, $uid, 'uid,t3ver_state');
         if ($workspaceVersion !== FALSE) {
             $versionState = VersionState::cast($workspaceVersion['t3ver_state']);
             if ($versionState->equals(VersionState::DELETE_PLACEHOLDER)) {
                 return FALSE;
             }
             $uid = $workspaceVersion['uid'];
         }
     }
     /** @var $trData DataPreprocessor */
     $trData = GeneralUtility::makeInstance(DataPreprocessor::class);
     $trData->addRawData = TRUE;
     $trData->lockRecords = 1;
     // If a new record should be created
     $trData->fetchRecord($table, $uid, $cmd === 'new' ? 'new' : '');
     $rec = reset($trData->regTableItems_data);
     return $rec;
 }
Exemplo n.º 14
0
    /**
     * Main function, rendering the document with the iFrame with the RTE in.
     *
     * @return void
     */
    public function main()
    {
        // Translate id to the workspace version:
        if ($versionedRecord = BackendUtility::getWorkspaceVersionOfRecord($this->getBackendUserAuthentication()->workspace, $this->P['table'], $this->P['uid'], 'uid')) {
            $this->P['uid'] = $versionedRecord['uid'];
        }
        // If all parameters are available:
        if ($this->P['table'] && $this->P['field'] && $this->P['uid'] && $this->checkEditAccess($this->P['table'], $this->P['uid'])) {
            // Getting the raw record (we need only the pid-value from here...)
            $rawRecord = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
            BackendUtility::fixVersioningPid($this->P['table'], $rawRecord);
            // override the default jumpToUrl
            $this->doc->JScodeArray['jumpToUrl'] = '
		function jumpToUrl(URL,formEl) {
			if (document.editform) {
				if (!TBE_EDITOR.isFormChanged()) {
					window.location.href = URL;
				} else if (formEl) {
					if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
				}
			} else {
				window.location.href = URL;
			}
		}
';
            // Setting JavaScript of the pid value for viewing:
            if ($this->popView) {
                $this->doc->JScode = $this->doc->wrapScriptTags(BackendUtility::viewOnClick($rawRecord['pid'], '', BackendUtility::BEgetRootLine($rawRecord['pid'])));
            }
            // Initialize FormEngine - for rendering the field:
            /** @var FormEngine $formEngine */
            $formEngine = GeneralUtility::makeInstance(FormEngine::class);
            // SPECIAL: Disables all wizards - we are NOT going to need them.
            $formEngine->disableWizards = 1;
            // Fetching content of record:
            /** @var DataPreprocessor $dataPreprocessor */
            $dataPreprocessor = GeneralUtility::makeInstance(DataPreprocessor::class);
            $dataPreprocessor->lockRecords = 1;
            $dataPreprocessor->fetchRecord($this->P['table'], $this->P['uid'], '');
            // Getting the processed record content out:
            $processedRecord = reset($dataPreprocessor->regTableItems_data);
            $processedRecord['uid'] = $this->P['uid'];
            $processedRecord['pid'] = $rawRecord['pid'];
            // TSconfig, setting width:
            $fieldTSConfig = FormEngineUtility::getTSconfigForTableRow($this->P['table'], $processedRecord, $this->P['field']);
            if ((string) $fieldTSConfig['RTEfullScreenWidth'] !== '') {
                $width = $fieldTSConfig['RTEfullScreenWidth'];
            } else {
                $width = '100%';
            }
            // Get the form field and wrap it in the table with the buttons:
            $formContent = $formEngine->getSoloField($this->P['table'], $processedRecord, $this->P['field']);
            $formContent = '

			<!-- RTE wizard: -->
				<table border="0" cellpadding="0" cellspacing="0" width="' . $width . '" id="typo3-rtewizard">
					<tr>
						<td width="' . $width . '" colspan="2" id="c-formContent">' . $formContent . '</td>
						<td></td>
					</tr>
				</table>';
            // Adding hidden fields:
            $formContent .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($this->R_URI) . '" />
						<input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />' . FormEngine::getHiddenTokenField('tceAction');
            // Finally, add the whole setup:
            $this->content .= $formEngine->printNeededJSFunctions_top() . $formContent . $formEngine->printNeededJSFunctions();
        } else {
            // ERROR:
            $this->content .= $this->doc->section($this->getLanguageService()->getLL('forms_title'), '<span class="text-danger">' . $this->getLanguageService()->getLL('table_noData', TRUE) . '</span>', 0, 1);
        }
        // Setting up the buttons and markers for docHeader
        $docHeaderButtons = $this->getButtons();
        $markers['CONTENT'] = $this->content;
        // Build the <body> for the module
        $this->content = $this->doc->startPage('');
        $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markers);
        $this->content .= $this->doc->endPage();
        $this->content = $this->doc->insertStylesAndJS($this->content);
    }
Exemplo n.º 15
0
 /**
  * Rendering the quick-edit view.
  *
  * @return string
  */
 public function renderQuickEdit()
 {
     $databaseConnection = $this->getDatabaseConnection();
     $beUser = $this->getBackendUser();
     $lang = $this->getLanguageService();
     // Set the edit_record value for internal use in this function:
     $edit_record = $this->edit_record;
     // If a command to edit all records in a column is issue, then select all those elements, and redirect to FormEngine
     if (substr($edit_record, 0, 9) == '_EDIT_COL') {
         $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', 'pid=' . (int) $this->id . ' AND colPos=' . (int) substr($edit_record, 10) . ' AND sys_language_uid=' . (int) $this->current_sys_language . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'), '', 'sorting');
         $idListA = array();
         while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
             $idListA[] = $cRow['uid'];
         }
         $url = BackendUtility::getModuleUrl('record_edit', array('edit[tt_content][' . implode(',', $idListA) . ']' => 'edit', 'returnUrl' => $this->local_linkThisScript(array('edit_record' => ''))));
         HttpUtility::redirect($url);
     }
     // If the former record edited was the creation of a NEW record, this will look up the created records uid:
     if ($this->new_unique_uid) {
         $res = $databaseConnection->exec_SELECTquery('*', 'sys_log', 'userid=' . (int) $beUser->user['uid'] . ' AND NEWid=' . $databaseConnection->fullQuoteStr($this->new_unique_uid, 'sys_log'));
         $sys_log_row = $databaseConnection->sql_fetch_assoc($res);
         if (is_array($sys_log_row)) {
             $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
         }
     }
     $edit_record = $this->makeQuickEditMenu($edit_record);
     // Splitting the edit-record cmd value into table/uid:
     $this->eRParts = explode(':', $edit_record);
     $tableName = $this->eRParts[0];
     // Delete-button flag?
     $this->deleteButton = MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($tableName !== 'pages' && $this->EDIT_CONTENT || $tableName === 'pages' && $this->CALC_PERMS & Permission::PAGE_DELETE);
     // If undo-button should be rendered (depends on available items in sys_history)
     $this->undoButton = false;
     $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($tableName, 'sys_history') . ' AND recuid=' . (int) $this->eRParts[1], '', 'tstamp DESC', '1');
     if ($this->undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
         $this->undoButton = true;
     }
     // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
     $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
     $R_URL_getvars = GeneralUtility::_GET();
     unset($R_URL_getvars['popView']);
     unset($R_URL_getvars['new_unique_uid']);
     $R_URL_getvars['edit_record'] = $edit_record;
     $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
     // Creating editing form:
     if ($edit_record) {
         // Splitting uid parts for special features, if new:
         list($uidVal, $neighborRecordUid, $ex_colPos) = explode('/', $this->eRParts[1]);
         if ($uidVal === 'new') {
             $command = 'new';
             // Page id of this new record
             $theUid = $this->id;
             if ($neighborRecordUid) {
                 $theUid = $neighborRecordUid;
             }
         } else {
             $command = 'edit';
             $theUid = $uidVal;
             // Convert $uidVal to workspace version if any:
             $draftRecord = BackendUtility::getWorkspaceVersionOfRecord($beUser->workspace, $tableName, $theUid, 'uid');
             if ($draftRecord) {
                 $theUid = $draftRecord['uid'];
             }
         }
         // @todo: Hack because DatabaseInitializeNewRow reads from _GP directly
         $GLOBALS['_GET']['defVals'][$tableName] = array('colPos' => (int) $ex_colPos, 'sys_language_uid' => (int) $this->current_sys_language);
         /** @var TcaDatabaseRecord $formDataGroup */
         $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
         /** @var FormDataCompiler $formDataCompiler */
         $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
         /** @var NodeFactory $nodeFactory */
         $nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
         try {
             $formDataCompilerInput = ['tableName' => $tableName, 'vanillaUid' => (int) $theUid, 'command' => $command];
             $formData = $formDataCompiler->compile($formDataCompilerInput);
             if ($command !== 'new') {
                 BackendUtility::lockRecords($tableName, $formData['databaseRow']['uid'], $tableName === 'tt_content' ? $formData['databaseRow']['pid'] : 0);
             }
             $formData['renderType'] = 'outerWrapContainer';
             $formResult = $nodeFactory->create($formData)->render();
             $panel = $formResult['html'];
             $formResult['html'] = '';
             /** @var FormResultCompiler $formResultCompiler */
             $formResultCompiler = GeneralUtility::makeInstance(FormResultCompiler::class);
             $formResultCompiler->mergeResult($formResult);
             $row = $formData['databaseRow'];
             $new_unique_uid = '';
             if ($command === 'new') {
                 $new_unique_uid = $row['uid'];
             }
             // Add hidden fields:
             if ($uidVal == 'new') {
                 $panel .= '<input type="hidden" name="data[' . $tableName . '][' . $row['uid'] . '][pid]" value="' . $row['pid'] . '" />';
             }
             $redirect = $uidVal == 'new' ? BackendUtility::getModuleUrl($this->moduleName, ['id' => $this->id, 'new_unique_uid' => $new_unique_uid, 'returnUrl' => $this->returnUrl]) : $this->R_URI;
             $panel .= '
                 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
                 <input type="hidden" name="edit_record" value="' . $edit_record . '" />
                 <input type="hidden" name="redirect" value="' . htmlspecialchars($redirect) . '" />
                 ';
             // Add JavaScript as needed around the form:
             $content = $formResultCompiler->JStop() . $panel . $formResultCompiler->printNeededJSFunctions();
             // Display "is-locked" message:
             if ($command === 'edit') {
                 $lockInfo = BackendUtility::isRecordLocked($tableName, $formData['databaseRow']['uid']);
                 if ($lockInfo) {
                     /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
                     $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
                     /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
                     $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
                     /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
                     $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
                     $defaultFlashMessageQueue->enqueue($flashMessage);
                 }
             }
         } catch (AccessDeniedException $e) {
             // If no edit access, print error message:
             $content = '<h2>' . $lang->getLL('noAccess', true) . '</h2>';
             $content .= '<div>' . $lang->getLL('noAccess_msg') . '<br /><br />' . ($beUser->errorMsg ? 'Reason: ' . $beUser->errorMsg . '<br /><br />' : '') . '</div>';
         }
     } else {
         // If no edit access, print error message:
         $content = '<h2>' . $lang->getLL('noAccess') . '</h2>';
         $content .= '<div>' . $lang->getLL('noAccess_msg') . '</div>';
     }
     // Element selection matrix:
     if ($tableName === 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
         $content .= '<h2>' . $lang->getLL('CEonThisPage') . '</h2>';
         // PositionMap
         $posMap = GeneralUtility::makeInstance(ContentLayoutPagePositionMap::class);
         $posMap->cur_sys_language = $this->current_sys_language;
         $content .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
         // Toggle hidden ContentElements
         $numberOfHiddenElements = $this->getNumberOfHiddenElements();
         if ($numberOfHiddenElements) {
             $content .= '<div class="checkbox">';
             $content .= '<label for="checkTt_content_showHidden">';
             $content .= BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], '', '', 'id="checkTt_content_showHidden"');
             $content .= !$numberOfHiddenElements ? '<span class="text-muted">' . $lang->getLL('hiddenCE', true) . '</span>' : $lang->getLL('hiddenCE', true) . ' (' . $numberOfHiddenElements . ')';
             $content .= '</label>';
             $content .= '</div>';
         }
         // CSH
         $content .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement');
     }
     return $content;
 }
Exemplo n.º 16
0
 /**
  * Find orphan records
  * VERY CPU and memory intensive since it will look up the whole page tree!
  *
  * @return array
  */
 public function main()
 {
     // Initialize result array:
     $resultArray = array('message' => $this->cli_help['name'] . LF . LF . $this->cli_help['description'], 'headers' => array('versions' => array('All versions', 'Showing all versions of records found', 0), 'versions_published' => array('All published versions', 'This is all records that has been published and can therefore be removed permanently', 1), 'versions_liveWS' => array('All versions in Live workspace', 'This is all records that are offline versions in the Live workspace. You may wish to flush these if you only use workspaces for versioning since then you might find lots of versions piling up in the live workspace which have simply been disconnected from the workspace before they were published.', 1), 'versions_lost_workspace' => array('Versions outside a workspace', 'Versions that has lost their connection to a workspace in TYPO3.', 3), 'versions_inside_versioned_page' => array('Versions in versions', 'Versions inside an already versioned page. Something that is confusing to users and therefore should not happen but is technically possible.', 2), 'versions_unused_placeholders' => array('Unused placeholder records', 'Placeholder records which are not used anymore by offline versions.', 2), 'versions_move_placeholders_ok' => array('Move placeholders', 'Move-to placeholder records which has good integrity', 0), 'versions_move_placeholders_bad' => array('Move placeholders with bad integrity', 'Move-to placeholder records which has bad integrity', 2), 'versions_move_id_check' => array('Checking if t3ver_move_id is correct', 't3ver_move_id must only be set with online records having t3ver_state=3.', 2)), 'versions' => array());
     $startingPoint = $this->cli_isArg('--pid') ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->cli_argValue('--pid'), 0) : 0;
     $depth = $this->cli_isArg('--depth') ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->cli_argValue('--depth'), 0) : 1000;
     $this->genTree($startingPoint, $depth, (int) $this->cli_argValue('--echotree'));
     $resultArray['versions'] = $this->recStats['versions'];
     $resultArray['versions_published'] = $this->recStats['versions_published'];
     $resultArray['versions_liveWS'] = $this->recStats['versions_liveWS'];
     $resultArray['versions_lost_workspace'] = $this->recStats['versions_lost_workspace'];
     $resultArray['versions_inside_versioned_page'] = $this->recStats['versions_inside_versioned_page'];
     // Finding all placeholders with no records attached!
     $resultArray['versions_unused_placeholders'] = array();
     foreach ($GLOBALS['TCA'] as $table => $cfg) {
         if ($cfg['ctrl']['versioningWS']) {
             $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pid', $table, 't3ver_state=' . new VersionState(VersionState::NEW_PLACEHOLDER) . ' AND pid>=0' . BackendUtility::deleteClause($table));
             foreach ($placeHolders as $phrec) {
                 if (count(BackendUtility::selectVersionsOfRecord($table, $phrec['uid'], 'uid', '*', null)) <= 1) {
                     $resultArray['versions_unused_placeholders'][GeneralUtility::shortMD5($table . ':' . $phrec['uid'])] = $table . ':' . $phrec['uid'];
                 }
             }
         }
     }
     asort($resultArray['versions_unused_placeholders']);
     // Finding all move placeholders with inconsistencies:
     $resultArray['versions_move_placeholders_ok'] = array();
     $resultArray['versions_move_placeholders_bad'] = array();
     foreach ($GLOBALS['TCA'] as $table => $cfg) {
         if (BackendUtility::isTableWorkspaceEnabled($table)) {
             $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pid,t3ver_move_id,t3ver_wsid,t3ver_state', $table, 't3ver_state=' . new VersionState(VersionState::MOVE_PLACEHOLDER) . ' AND pid>=0' . BackendUtility::deleteClause($table));
             foreach ($placeHolders as $phrec) {
                 $shortID = GeneralUtility::shortMD5($table . ':' . $phrec['uid']);
                 if ((int) $phrec['t3ver_wsid'] != 0) {
                     $phrecCopy = $phrec;
                     if (BackendUtility::movePlhOL($table, $phrec)) {
                         if ($wsAlt = BackendUtility::getWorkspaceVersionOfRecord($phrecCopy['t3ver_wsid'], $table, $phrec['uid'], 'uid,pid,t3ver_state')) {
                             if (!VersionState::cast($wsAlt['t3ver_state'])->equals(VersionState::MOVE_POINTER)) {
                                 $resultArray['versions_move_placeholders_bad'][$shortID] = array($table . ':' . $phrec['uid'], 'State for version was not "4" as it should be!', $phrecCopy);
                             } else {
                                 $resultArray['versions_move_placeholders_ok'][$shortID] = array($table . ':' . $phrec['uid'], 'PLH' => $phrecCopy, 'online' => $phrec, 'PNT' => $wsAlt);
                             }
                         } else {
                             $resultArray['versions_move_placeholders_bad'][$shortID] = array($table . ':' . $phrec['uid'], 'No version was found for online record to be moved. A version must exist.', $phrecCopy);
                         }
                     } else {
                         $resultArray['versions_move_placeholders_bad'][$shortID] = array($table . ':' . $phrec['uid'], 'Did not find online record for "t3ver_move_id" value ' . $phrec['t3ver_move_id'], $phrec);
                     }
                 } else {
                     $resultArray['versions_move_placeholders_bad'][$shortID] = array($table . ':' . $phrec['uid'], 'Placeholder was not assigned a workspace value in t3ver_wsid.', $phrec);
                 }
             }
         }
     }
     ksort($resultArray['versions_move_placeholders_ok']);
     ksort($resultArray['versions_move_placeholders_bad']);
     // Finding move_id_check inconsistencies:
     $resultArray['versions_move_id_check'] = array();
     foreach ($GLOBALS['TCA'] as $table => $cfg) {
         if (BackendUtility::isTableWorkspaceEnabled($table)) {
             $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pid,t3ver_move_id,t3ver_wsid,t3ver_state', $table, 't3ver_move_id<>0' . BackendUtility::deleteClause($table));
             foreach ($placeHolders as $phrec) {
                 if (VersionState::cast($phrec['t3ver_state'])->equals(VersionState::MOVE_PLACEHOLDER)) {
                     if ($phrec['pid'] != -1) {
                     } else {
                         $resultArray['versions_move_id_check'][] = array($table . ':' . $phrec['uid'], 'Record was offline, must not be!', $phrec);
                     }
                 } else {
                     $resultArray['versions_move_id_check'][] = array($table . ':' . $phrec['uid'], 'Record had t3ver_move_id set to "' . $phrec['t3ver_move_id'] . '" while having t3ver_state=' . $phrec['t3ver_state'], $phrec);
                 }
             }
         }
     }
     return $resultArray;
 }
Exemplo n.º 17
0
 /**
  * @param array $record
  * @return array
  */
 protected function getWorkspaceVersionOfRecordOrRecordItself(array $record)
 {
     $workspaceId = $this->getActiveWorkspaceId();
     if (0 < $workspaceId) {
         $workspaceRecord = BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, 'tt_content', $record['uid']);
         $record = FALSE !== $workspaceRecord ? $workspaceRecord : $record;
     }
     return $record;
 }
Exemplo n.º 18
0
 /**
  * Get record for editing.
  *
  * @param string $table Table name
  * @param int $theUid Record UID
  * @return array Returns record to edit, FALSE if none
  */
 public function getRecordForEdit($table, $theUid)
 {
     // Fetch requested record:
     $reqRecord = BackendUtility::getRecord($table, $theUid, 'uid,pid');
     if (is_array($reqRecord)) {
         // If workspace is OFFLINE:
         if ($this->getBackendUser()->workspace != 0) {
             // Check for versioning support of the table:
             if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
                 // If the record is already a version of "something" pass it by.
                 if ($reqRecord['pid'] == -1) {
                     // (If it turns out not to be a version of the current workspace there will be trouble, but
                     // that is handled inside TCEmain then and in the interface it would clearly be an error of
                     // links if the user accesses such a scenario)
                     return $reqRecord;
                 } else {
                     // The input record was online and an offline version must be found or made:
                     // Look for version of this workspace:
                     $versionRec = BackendUtility::getWorkspaceVersionOfRecord($this->getBackendUser()->workspace, $table, $reqRecord['uid'], 'uid,pid,t3ver_oid');
                     return is_array($versionRec) ? $versionRec : $reqRecord;
                 }
             } else {
                 // This means that editing cannot occur on this record because it was not supporting versioning
                 // which is required inside an offline workspace.
                 return false;
             }
         } else {
             // In ONLINE workspace, just return the originally requested record:
             return $reqRecord;
         }
     } else {
         // Return FALSE because the table/uid was not found anyway.
         return false;
     }
 }
Exemplo n.º 19
0
 /**
  * Callback to add additional data to new elements created in the dependency resolver utility.
  *
  * @throws \RuntimeException
  * @param ElementEntity $caller
  * @param array $callerArguments
  * @param array $targetArgument
  * @param string $eventName
  * @return void
  */
 public function createNewDependentElementCallback(array $callerArguments, array $targetArgument, ElementEntity $caller, $eventName)
 {
     if (!BackendUtility::isTableWorkspaceEnabled($caller->getTable())) {
         $caller->setInvalid(true);
         return;
     }
     $versionRecord = $caller->getRecord();
     // If version record does not exist, it probably has been deleted (cleared from workspace), this means,
     // that the reference index still has an old reference pointer, which is "fine" for deleted parents
     if (empty($versionRecord)) {
         throw new \RuntimeException('Element "' . $caller::getIdentifier($caller->getTable(), $caller->getId()) . '" does not exist', 1393960943);
     }
     // If version is on live workspace, but the pid is negative, mark the record as invalid.
     // This happens if a change has been discarded (clearWSID) - it will be removed from the command map.
     if ((int) $versionRecord['t3ver_wsid'] === 0 && (int) $versionRecord['pid'] === -1) {
         $caller->setDataValue('liveId', $caller->getId());
         $caller->setInvalid(true);
         return;
     }
     if ($caller->hasDataValue('liveId') === false) {
         // Set the original uid from the version record
         if (!empty($versionRecord['t3ver_oid']) && (int) $versionRecord['pid'] === -1 && (int) $versionRecord['t3ver_wsid'] === $this->getWorkspace()) {
             $caller->setDataValue('liveId', $versionRecord['t3ver_oid']);
             // The current version record is actually a live record or an accordant placeholder for live
         } elseif ((int) $versionRecord['t3ver_wsid'] === 0 || (int) $versionRecord['pid'] !== -1) {
             $caller->setDataValue('liveId', $caller->getId());
             $versionRecord = BackendUtility::getWorkspaceVersionOfRecord($this->getWorkspace(), $caller->getTable(), $caller->getId(), 'uid,t3ver_state');
             // Set version uid to caller, most likely it's a delete placeholder
             // for a child record that is not recognized in the reference index
             if (!empty($versionRecord['uid'])) {
                 $caller->setId($versionRecord['uid']);
                 // If no version could be determined, mark record as invalid
                 // (thus, it will be removed from the command map)
             } else {
                 $caller->setInvalid(true);
             }
             // In case of an unexpected record state, mark the record as invalid
         } else {
             $caller->setInvalid(true);
         }
     }
 }
Exemplo n.º 20
0
    /**
     * Rendering the quick-edit view.
     *
     * @return string
     */
    public function renderQuickEdit()
    {
        $databaseConnection = $this->getDatabaseConnection();
        $beUser = $this->getBackendUser();
        $lang = $this->getLanguageService();
        // Alternative template
        $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout_quickedit.html');
        // Alternative form tag; Quick Edit submits its content to tce_db.php.
        $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_db', ['prErr' => 1, 'uPT' => 1])) . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
        // Setting up the context sensitive menu:
        $this->doc->getContextMenuCode();
        // Set the edit_record value for internal use in this function:
        $edit_record = $this->edit_record;
        // If a command to edit all records in a column is issue, then select all those elements, and redirect to FormEngine
        if (substr($edit_record, 0, 9) == '_EDIT_COL') {
            $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', 'pid=' . (int) $this->id . ' AND colPos=' . (int) substr($edit_record, 10) . ' AND sys_language_uid=' . (int) $this->current_sys_language . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'), '', 'sorting');
            $idListA = array();
            while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
                $idListA[] = $cRow['uid'];
            }
            $url = BackendUtility::getModuleUrl('record_edit', array('edit[tt_content][' . implode(',', $idListA) . ']' => 'edit', 'returnUrl' => $this->local_linkThisScript(array('edit_record' => ''))));
            HttpUtility::redirect($url);
        }
        // If the former record edited was the creation of a NEW record, this will look up the created records uid:
        if ($this->new_unique_uid) {
            $res = $databaseConnection->exec_SELECTquery('*', 'sys_log', 'userid=' . (int) $beUser->user['uid'] . ' AND NEWid=' . $databaseConnection->fullQuoteStr($this->new_unique_uid, 'sys_log'));
            $sys_log_row = $databaseConnection->sql_fetch_assoc($res);
            if (is_array($sys_log_row)) {
                $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
            }
        }
        // Creating the selector box, allowing the user to select which element to edit:
        $opt = array();
        $is_selected = 0;
        $languageOverlayRecord = '';
        if ($this->current_sys_language) {
            list($languageOverlayRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $this->id, 'AND sys_language_uid=' . (int) $this->current_sys_language);
        }
        if (is_array($languageOverlayRecord)) {
            $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
            $is_selected += (int) $edit_record == $inValue;
            $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editLanguageHeader', TRUE) . ' ]</option>';
        } else {
            $inValue = 'pages:' . $this->id;
            $is_selected += (int) $edit_record == $inValue;
            $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editPageProperties', TRUE) . ' ]</option>';
        }
        // Selecting all content elements from this language and allowed colPos:
        $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', 'pid=' . (int) $this->id . ' AND sys_language_uid=' . (int) $this->current_sys_language . ' AND colPos IN (' . $this->colPosList . ')' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'), '', 'colPos,sorting');
        $colPos = NULL;
        $first = 1;
        // Page is the pid if no record to put this after.
        $prev = $this->id;
        while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
            BackendUtility::workspaceOL('tt_content', $cRow);
            if (is_array($cRow)) {
                if ($first) {
                    if (!$edit_record) {
                        $edit_record = 'tt_content:' . $cRow['uid'];
                    }
                    $first = 0;
                }
                if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
                    $colPos = $cRow['colPos'];
                    $opt[] = '<option value=""></option>';
                    $opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $lang->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), TRUE) . ':__</option>';
                }
                $inValue = 'tt_content:' . $cRow['uid'];
                $is_selected += (int) $edit_record == $inValue;
                $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($cRow['header'] ? $cRow['header'] : '[' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title') . '] ' . strip_tags($cRow['bodytext']), $beUser->uc['titleLen'])) . '</option>';
                $prev = -$cRow['uid'];
            }
        }
        // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
        if (!$edit_record) {
            $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
            $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
            $is_selected += (int) $edit_record == $inValue;
            $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('newLabel', 1) . ' ]</option>';
        }
        // If none is yet selected...
        if (!$is_selected) {
            $opt[] = '<option value=""></option>';
            $opt[] = '<option value="' . $edit_record . '"  selected="selected">[ ' . $lang->getLL('newLabel', TRUE) . ' ]</option>';
        }
        // Splitting the edit-record cmd value into table/uid:
        $this->eRParts = explode(':', $edit_record);
        // Delete-button flag?
        $this->deleteButton = MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($this->eRParts[0] != 'pages' && $this->EDIT_CONTENT || $this->eRParts[0] == 'pages' && $this->CALC_PERMS & Permission::PAGE_DELETE);
        // If undo-button should be rendered (depends on available items in sys_history)
        $this->undoButton = FALSE;
        $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($this->eRParts[0], 'sys_history') . ' AND recuid=' . (int) $this->eRParts[1], '', 'tstamp DESC', '1');
        if ($this->undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
            $this->undoButton = TRUE;
        }
        // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
        $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
        $R_URL_getvars = GeneralUtility::_GET();
        unset($R_URL_getvars['popView']);
        unset($R_URL_getvars['new_unique_uid']);
        $R_URL_getvars['edit_record'] = $edit_record;
        $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
        // Setting close url/return url for exiting this script:
        // Goes to 'Columns' view if close is pressed (default)
        $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
        if ($this->returnUrl) {
            $this->closeUrl = $this->returnUrl;
        }
        // Return-url for JavaScript:
        $retUrlStr = $this->returnUrl ? '+\'&returnUrl=\'+' . GeneralUtility::quoteJSvalue(rawurlencode($this->returnUrl)) : '';
        // Drawing the edit record selectbox
        $this->editSelect = '<select name="edit_record" onchange="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('web_layout') . '&id=' . $this->id . '&edit_record=') . '+escape(this.options[this.selectedIndex].value)' . $retUrlStr . ',this);') . '">' . implode('', $opt) . '</select>';
        $content = '';
        // Creating editing form:
        if ($beUser->check('tables_modify', $this->eRParts[0]) && $edit_record && ($this->eRParts[0] !== 'pages' && $this->EDIT_CONTENT || $this->eRParts[0] === 'pages' && $this->CALC_PERMS & Permission::PAGE_SHOW)) {
            // Splitting uid parts for special features, if new:
            list($uidVal, $ex_pid, $ex_colPos) = explode('/', $this->eRParts[1]);
            // Convert $uidVal to workspace version if any:
            if ($uidVal != 'new') {
                if ($draftRecord = BackendUtility::getWorkspaceVersionOfRecord($beUser->workspace, $this->eRParts[0], $uidVal, 'uid')) {
                    $uidVal = $draftRecord['uid'];
                }
            }
            // Initializing transfer-data object:
            $trData = GeneralUtility::makeInstance(DataPreprocessor::class);
            $trData->addRawData = TRUE;
            $trData->defVals[$this->eRParts[0]] = array('colPos' => (int) $ex_colPos, 'sys_language_uid' => (int) $this->current_sys_language);
            $trData->lockRecords = 1;
            // 'new'
            $trData->fetchRecord($this->eRParts[0], $uidVal == 'new' ? $this->id : $uidVal, $uidVal);
            $new_unique_uid = '';
            // Getting/Making the record:
            reset($trData->regTableItems_data);
            $rec = current($trData->regTableItems_data);
            if ($uidVal == 'new') {
                $new_unique_uid = uniqid('NEW', TRUE);
                $rec['uid'] = $new_unique_uid;
                $rec['pid'] = (int) $ex_pid ?: $this->id;
                $recordAccess = TRUE;
            } else {
                $rec['uid'] = $uidVal;
                // Checking internals access:
                $recordAccess = $beUser->recordEditAccessInternals($this->eRParts[0], $uidVal);
            }
            if (!$recordAccess) {
                // If no edit access, print error message:
                $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />' . ($beUser->errorMsg ? 'Reason: ' . $beUser->errorMsg . '<br /><br />' : ''), 0, 1);
            } elseif (is_array($rec)) {
                // If the record is an array (which it will always be... :-)
                // Create instance of TCEforms, setting defaults:
                $tceForms = GeneralUtility::makeInstance(FormEngine::class);
                // Render form, wrap it:
                $panel = '';
                $panel .= $tceForms->getMainFields($this->eRParts[0], $rec);
                $panel = $tceForms->wrapTotal($panel, $rec, $this->eRParts[0]);
                // Add hidden fields:
                $theCode = $panel;
                if ($uidVal == 'new') {
                    $theCode .= '<input type="hidden" name="data[' . $this->eRParts[0] . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
                }
                $theCode .= '
					<input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
					<input type="hidden" name="edit_record" value="' . $edit_record . '" />
					<input type="hidden" name="redirect" value="' . htmlspecialchars($uidVal == 'new' ? BackendUtility::getModuleUrl('web_layout', array('id' => $this->id, 'new_unique_uid' => $new_unique_uid, 'returnUrl' => $this->returnUrl)) : $this->R_URI) . '" />
					' . FormEngine::getHiddenTokenField('tceAction');
                // Add JavaScript as needed around the form:
                $theCode = $tceForms->printNeededJSFunctions_top() . $theCode . $tceForms->printNeededJSFunctions();
                // Add warning sign if record was "locked":
                if ($lockInfo = BackendUtility::isRecordLocked($this->eRParts[0], $rec['uid'])) {
                    /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
                    $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
                    /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
                    $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
                    /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
                    $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
                    $defaultFlashMessageQueue->enqueue($flashMessage);
                }
                // Add whole form as a document section:
                $content = $this->doc->section('', $theCode);
            }
        } else {
            // If no edit access, print error message:
            $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />', 0, 1);
        }
        // Bottom controls (function menus):
        $q_count = $this->getNumberOfHiddenElements();
        if ($q_count) {
            $h_func_b = '<div class="checkbox">' . '<label for="checkTt_content_showHidden">' . BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], '', '', 'id="checkTt_content_showHidden"') . (!$q_count ? '<span class="text-muted">' . $lang->getLL('hiddenCE', TRUE) . '</span>' : $lang->getLL('hiddenCE', TRUE) . ' (' . $q_count . ')') . '</label>' . '</div>';
            $content .= $this->doc->section('', $h_func_b, 0, 0);
            $content .= $this->doc->spacer(10);
        }
        // Select element matrix:
        if ($this->eRParts[0] == 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
            $posMap = GeneralUtility::makeInstance(ContentLayoutPagePositionMap::class);
            $posMap->backPath = $GLOBALS['BACK_PATH'];
            $posMap->cur_sys_language = $this->current_sys_language;
            $HTMLcode = '';
            // CSH:
            $HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', NULL, '|<br />');
            $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
            $content .= $this->doc->spacer(20);
            $content .= $this->doc->section($lang->getLL('CEonThisPage'), $HTMLcode, 0, 1);
            $content .= $this->doc->spacer(20);
        }
        return $content;
    }
Exemplo n.º 21
0
 /**
  * Get a single record row for a TCA table from the database.
  * \TYPO3\CMS\Backend\Form\DataPreprocessor is used for "upgrading" the
  * values, especially the relations.
  *
  * @param integer $pid The pid of the page the record should be stored (only relevant for NEW records)
  * @param string $table The table to fetch data from (= foreign_table)
  * @param string $uid The uid of the record to fetch, or the pid if a new record should be created
  * @param string $cmd The command to perform, empty or 'new'
  * @return array A record row from the database post-processed by \TYPO3\CMS\Backend\Form\DataPreprocessor
  * @todo Define visibility
  */
 public function getRecord($pid, $table, $uid, $cmd = '')
 {
     // Fetch workspace version of a record (if any):
     if ($cmd !== 'new' && $GLOBALS['BE_USER']->workspace !== 0 && BackendUtility::isTableWorkspaceEnabled($table)) {
         $workspaceVersion = BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $uid, 'uid,t3ver_state');
         if ($workspaceVersion !== FALSE) {
             $versionState = VersionState::cast($workspaceVersion['t3ver_state']);
             if ($versionState->equals(VersionState::DELETE_PLACEHOLDER)) {
                 return FALSE;
             }
             $uid = $workspaceVersion['uid'];
         }
     }
     /** @var $trData \TYPO3\CMS\Backend\Form\DataPreprocessor */
     $trData = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\DataPreprocessor');
     $trData->addRawData = TRUE;
     $trData->lockRecords = 1;
     $trData->disableRTE = $GLOBALS['SOBE']->MOD_SETTINGS['disableRTE'];
     // If a new record should be created
     $trData->fetchRecord($table, $uid, $cmd === 'new' ? 'new' : '');
     $rec = reset($trData->regTableItems_data);
     return $rec;
 }
Exemplo n.º 22
0
 /**
  * Find orphan records
  * VERY CPU and memory intensive since it will look up the whole page tree!
  *
  * @return array
  */
 public function main()
 {
     // Initialize result array:
     $resultArray = ['message' => $this->cli_help['name'] . LF . LF . $this->cli_help['description'], 'headers' => ['versions' => ['All versions', 'Showing all versions of records found', 0], 'versions_published' => ['All published versions', 'This is all records that has been published and can therefore be removed permanently', 1], 'versions_liveWS' => ['All versions in Live workspace', 'This is all records that are offline versions in the Live workspace. You may wish to flush these if you only use workspaces for versioning since then you might find lots of versions piling up in the live workspace which have simply been disconnected from the workspace before they were published.', 1], 'versions_lost_workspace' => ['Versions outside a workspace', 'Versions that has lost their connection to a workspace in TYPO3.', 3], 'versions_inside_versioned_page' => ['Versions in versions', 'Versions inside an already versioned page. Something that is confusing to users and therefore should not happen but is technically possible.', 2], 'versions_unused_placeholders' => ['Unused placeholder records', 'Placeholder records which are not used anymore by offline versions.', 2], 'versions_move_placeholders_ok' => ['Move placeholders', 'Move-to placeholder records which has good integrity', 0], 'versions_move_placeholders_bad' => ['Move placeholders with bad integrity', 'Move-to placeholder records which has bad integrity', 2], 'versions_move_id_check' => ['Checking if t3ver_move_id is correct', 't3ver_move_id must only be set with online records having t3ver_state=3.', 2]], 'versions' => []];
     $startingPoint = $this->cli_isArg('--pid') ? MathUtility::forceIntegerInRange($this->cli_argValue('--pid'), 0) : 0;
     $depth = $this->cli_isArg('--depth') ? MathUtility::forceIntegerInRange($this->cli_argValue('--depth'), 0) : 1000;
     $this->genTree($startingPoint, $depth, (int) $this->cli_argValue('--echotree'));
     $resultArray['versions'] = $this->recStats['versions'];
     $resultArray['versions_published'] = $this->recStats['versions_published'];
     $resultArray['versions_liveWS'] = $this->recStats['versions_liveWS'];
     $resultArray['versions_lost_workspace'] = $this->recStats['versions_lost_workspace'];
     $resultArray['versions_inside_versioned_page'] = $this->recStats['versions_inside_versioned_page'];
     // Finding all placeholders with no records attached!
     $resultArray['versions_unused_placeholders'] = [];
     foreach ($GLOBALS['TCA'] as $table => $cfg) {
         if ($cfg['ctrl']['versioningWS']) {
             $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
             $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
             $result = $queryBuilder->select('uid', 'pid')->from($table)->where($queryBuilder->expr()->gte('pid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)), $queryBuilder->expr()->eq('t3ver_state', $queryBuilder->createNamedParameter((string) new VersionState(VersionState::NEW_PLACEHOLDER), \PDO::PARAM_INT)))->execute();
             while ($placeholderRecord = $result->fetch()) {
                 if (count(BackendUtility::selectVersionsOfRecord($table, $placeholderRecord['uid'], 'uid', '*', null)) <= 1) {
                     $resultArray['versions_unused_placeholders'][GeneralUtility::shortMD5($table . ':' . $placeholderRecord['uid'])] = $table . ':' . $placeholderRecord['uid'];
                 }
             }
         }
     }
     asort($resultArray['versions_unused_placeholders']);
     // Finding all move placeholders with inconsistencies:
     $resultArray['versions_move_placeholders_ok'] = [];
     $resultArray['versions_move_placeholders_bad'] = [];
     foreach ($GLOBALS['TCA'] as $table => $cfg) {
         if (BackendUtility::isTableWorkspaceEnabled($table)) {
             $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
             $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
             $result = $queryBuilder->select('uid', 'pid', 't3ver_move_id', 't3ver_wsid', 't3ver_state')->from($table)->where($queryBuilder->expr()->gte('pid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)), $queryBuilder->expr()->eq('t3ver_state', $queryBuilder->createNamedParameter((string) new VersionState(VersionState::MOVE_PLACEHOLDER), \PDO::PARAM_INT)))->execute();
             while ($placeholderRecord = $result->fetch()) {
                 $shortID = GeneralUtility::shortMD5($table . ':' . $placeholderRecord['uid']);
                 if ((int) $placeholderRecord['t3ver_wsid'] !== 0) {
                     $phrecCopy = $placeholderRecord;
                     if (BackendUtility::movePlhOL($table, $placeholderRecord)) {
                         if ($wsAlt = BackendUtility::getWorkspaceVersionOfRecord($phrecCopy['t3ver_wsid'], $table, $placeholderRecord['uid'], 'uid,pid,t3ver_state')) {
                             if (!VersionState::cast($wsAlt['t3ver_state'])->equals(VersionState::MOVE_POINTER)) {
                                 $resultArray['versions_move_placeholders_bad'][$shortID] = [$table . ':' . $placeholderRecord['uid'], 'State for version was not "4" as it should be!', $phrecCopy];
                             } else {
                                 $resultArray['versions_move_placeholders_ok'][$shortID] = [$table . ':' . $placeholderRecord['uid'], 'PLH' => $phrecCopy, 'online' => $placeholderRecord, 'PNT' => $wsAlt];
                             }
                         } else {
                             $resultArray['versions_move_placeholders_bad'][$shortID] = [$table . ':' . $placeholderRecord['uid'], 'No version was found for online record to be moved. A version must exist.', $phrecCopy];
                         }
                     } else {
                         $resultArray['versions_move_placeholders_bad'][$shortID] = [$table . ':' . $placeholderRecord['uid'], 'Did not find online record for "t3ver_move_id" value ' . $placeholderRecord['t3ver_move_id'], $placeholderRecord];
                     }
                 } else {
                     $resultArray['versions_move_placeholders_bad'][$shortID] = [$table . ':' . $placeholderRecord['uid'], 'Placeholder was not assigned a workspace value in t3ver_wsid.', $placeholderRecord];
                 }
             }
         }
     }
     ksort($resultArray['versions_move_placeholders_ok']);
     ksort($resultArray['versions_move_placeholders_bad']);
     // Finding move_id_check inconsistencies:
     $resultArray['versions_move_id_check'] = [];
     foreach ($GLOBALS['TCA'] as $table => $cfg) {
         if (BackendUtility::isTableWorkspaceEnabled($table)) {
             $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
             $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
             $result = $queryBuilder->select('uid', 'pid', 't3ver_move_id', 't3ver_wsid', 't3ver_state')->from($table)->where($queryBuilder->expr()->neq('t3ver_move_id', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)))->execute();
             while ($placeholderRecord = $result->fetch()) {
                 if (VersionState::cast($placeholderRecord['t3ver_state'])->equals(VersionState::MOVE_PLACEHOLDER)) {
                     if ($placeholderRecord['pid'] != -1) {
                     } else {
                         $resultArray['versions_move_id_check'][] = [$table . ':' . $placeholderRecord['uid'], 'Record was offline, must not be!', $placeholderRecord];
                     }
                 } else {
                     $resultArray['versions_move_id_check'][] = [$table . ':' . $placeholderRecord['uid'], 'Record had t3ver_move_id set to "' . $placeholderRecord['t3ver_move_id'] . '" while having t3ver_state=' . $placeholderRecord['t3ver_state'], $placeholderRecord];
                 }
             }
         }
     }
     return $resultArray;
 }