Project

General

Profile

Bug #22410 » 14050_cleaning_t3lib_frontendedit.patch

Administrator Admin, 2010-11-24 11:57

View differences:

t3lib/class.t3lib_frontendedit.php (revision )
<?php
/***************************************************************
* Copyright notice
*
* (c) 2008-2010 Jeff Segars <jeff@webempoweredchurch.org>
* (c) 2008-2010 David Slayback <dave@webempoweredchurch.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
* Copyright notice
*
* (c) 2008-2010 Jeff Segars <jeff@webempoweredchurch.org>
* (c) 2008-2010 David Slayback <dave@webempoweredchurch.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Controller class for frontend editing.
*
......
// Page ID for new records, 0 if not specified
$newRecordPid = intval($conf['newRecordInPid']);
if (!$conf['onlyCurrentPid'] || $dataArray['pid'] == $GLOBALS['TSFE']->id) {
if ($table=='pages') {
if ($table == 'pages') {
$newUid = $uid;
} else {
if ($conf['newRecordFromTable']) {
$newUid = $GLOBALS['TSFE']->id;
if ($newRecordPid) {
$newUid = $newRecordPid;
$newUid = $newRecordPid;
}
} else {
$newUid = -1 * $uid;
......
if ($GLOBALS['TSFE']->displayEditIcons && $table && $this->allowedToEdit($table, $dataArray, $conf, $checkEditAccessInternals) && $this->allowedToEditLanguage($table, $dataArray)) {
$editClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/classes/class.frontendedit.php']['edit'];
if ($editClass) {
$edit = t3lib_div::getUserObj($editClass, false);
$edit = t3lib_div::getUserObj($editClass, FALSE);
if (is_object($edit)) {
$allowedActions = $this->getAllowedEditActions($table, $conf, $dataArray['pid']);
$content = $edit->editPanel($content, $conf, $currentRecord, $dataArray, $table, $allowedActions, $newUid, $this->getHiddenFields($dataArray));
......
* @return string The input content string, possibly with edit icons added (not necessarily in the end but just after the last string of normal content.
*/
public function displayEditIcons($content, $params, array $conf=array(), $currentRecord = '', array $dataArray = array(), $addUrlParamStr = '') {
public function displayEditIcons($content, $params, array $conf = array(), $currentRecord = '', array $dataArray = array(), $addUrlParamStr = '') {
// Check incoming params:
list($currentRecordTable, $currentRecordUID) = explode(':', $currentRecord);
list($fieldList, $table) = array_reverse(t3lib_div::trimExplode(':', $params, 1)); // Reverse the array because table is optional
if (!$table) {
$table = $currentRecordTable;
} elseif ($table != $currentRecordTable) {
return $content; // If the table is set as the first parameter, and does not match the table of the current record, then just return.
return $content; // If the table is set as the first parameter, and does not match the table of the current record, then just return.
}
$editUid = $dataArray['_LOCALIZED_UID'] ? $dataArray['_LOCALIZED_UID'] : $currentRecordUID;
......
$cmd = (string) $this->TSFE_EDIT['cmd'];
if (($cmd != 'edit' || (is_array($this->TSFE_EDIT['data']) && ($this->TSFE_EDIT['doSave'] || $this->TSFE_EDIT['update'] || $this->TSFE_EDIT['update_close']))) && $cmd != 'new') {
// $cmd can be a command like "hide" or "move". If $cmd is "edit" or "new" it's an indication to show the formfields. But if data is sent with update-flag then $cmd = edit is accepted because edit may be sent because of .keepGoing flag.
return true;
return TRUE;
}
}
}
return false;
return FALSE;
}
/**
......
if (is_array($this->TSFE_EDIT)) {
$cmd = (string) $this->TSFE_EDIT['cmd'];
if ($cmd == 'edit' || $cmd == 'new') {
return true;
return TRUE;
}
}
}
......
* @param integer The UID of record to move after. This is specified for dragging only.
* @return void
*/
protected function move($table, $uid, $direction='', $afterUID=0) {
protected function move($table, $uid, $direction = '', $afterUID = 0) {
$cmdData = array();
$sortField = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
if ($sortField) {
// Get self:
$fields = array_unique(t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields'] . ',uid,pid,' . $sortField, true));
$fields = array_unique(t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields'] . ',uid,pid,' . $sortField, TRUE));
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',', $fields), $table, 'uid=' . $uid);
if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
// record before or after
if (($GLOBALS['BE_USER']->adminPanel instanceOf tslib_AdminPanel) && ($GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview'))) {
$ignore = array('starttime'=>1, 'endtime'=>1, 'disabled'=>1, 'fe_group'=>1);
$ignore = array('starttime' => 1, 'endtime' => 1, 'disabled' => 1, 'fe_group' => 1);
}
$copyAfterFieldsQuery = '';
if ($GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields']) {
$cAFields = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields'], true);
$cAFields = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields'], TRUE);
foreach($cAFields as $fieldName) {
foreach ($cAFields as $fieldName) {
$copyAfterFieldsQuery .= ' AND ' . $fieldName . '="' . $row[$fieldName] . '"';
}
}
......
$sortCheck = ' AND ' . $sortField . $operator . intval($row[$sortField]);
}
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'uid,pid',
$table,
'pid=' . intval($row['pid']) .
'uid,pid',
$table,
'pid=' . intval($row['pid']) .
$sortCheck .
$copyAfterFieldsQuery .
$GLOBALS['TSFE']->sys_page->enableFields($table, '', $ignore),
'',
$sortField . ' ' . $order,
'2'
);
'',
$sortField . ' ' . $order,
'2'
);
if ($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
if ($afterUID) {
$cmdData[$table][$uid]['move'] = -$afterUID;
......
elseif ($direction == 'down') {
$cmdData[$table][$uid]['move'] = -$row2['uid'];
}
elseif ($row3 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // Must take the second record above...
elseif ($row3 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // Must take the second record above...
$cmdData[$table][$uid]['move'] = -$row3['uid'];
}
else { // ... and if that does not exist, use pid
else { // ... and if that does not exist, use pid
$cmdData[$table][$uid]['move'] = $row['pid'];
}
} elseif ($direction == 'up') {
......
}
if ($GLOBALS['BE_USER']->checkLanguageAccess($lang)) {
$languageAccess = true;
$languageAccess = TRUE;
} else {
$languageAccess = false;
$languageAccess = FALSE;
}
return $languageAccess;
......
* @param array The data array.
* @param array The configuration array for the edit panel.
* @param boolean Boolean indicating whether recordEditAccessInternals should not be checked. Defaults
* to true but doesn't makes sense when creating new records on a page.
* to true but doesn't makes sense when creating new records on a page.
* @return boolean
*/
protected function allowedToEdit($table, array $dataArray, array $conf, $checkEditAccessInternals = TRUE) {
......
} else {
$editAccessInternals = TRUE;
}
if ($editAccessInternals) {
if ($table=='pages') {
if ($table == 'pages') {
// 2 = permission to edit the page
if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->doesUserHaveAccess($dataArray, 2)) {
$mayEdit = true;
$mayEdit = TRUE;
}
} else {
// 16 = permission to edit content on the page
if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->doesUserHaveAccess(t3lib_BEfunc::getRecord('pages', $dataArray['pid']), 16)) {
$mayEdit = true;
$mayEdit = TRUE;
}
}
if (!$conf['onlyCurrentPid'] || ($dataArray['pid'] == $GLOBALS['TSFE']->id)) {
// Permissions:
$types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']),1);
$types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']), 1);
$allow = array_flip($types);
$perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
......
// Can only display editbox if there are options in the menu
if (count($allow)) {
$mayEdit = true;
$mayEdit = TRUE;
}
} else {
$mayEdit = count($allow) && ($perms & 16);
......
protected function getAllowedEditActions($table, array $conf, $pid, $allow = '') {
if (!$allow) {
$types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']), true);
$types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']), TRUE);
$allow = array_flip($types);
}
if (!$conf['onlyCurrentPid'] || $pid == $GLOBALS['TSFE']->id) {
// Permissions:
$types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']), true);
$types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']), TRUE);
$allow = array_flip($types);
$perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
if ($table=='pages') {
if ($table == 'pages') {
// rootpage!
if (count($GLOBALS['TSFE']->config['rootLine']) == 1) {
unset($allow['move']);
unset($allow['hide']);
unset($allow['delete']);
}
if (!($perms & 2)){
if (!($perms & 2)) {
unset($allow['edit']);
unset($allow['move']);
unset($allow['hide']);
......
if (!($perms & 4)) {
unset($allow['delete']);
}
if (!($perms&8)) {
if (!($perms & 8)) {
unset($allow['new']);
}
}
......
protected function initializeTceMain() {
if (!isset($this->tce)) {
$this->tce = t3lib_div::makeInstance('t3lib_TCEmain');
$this->tce->stripslashes_values=0;
$this->tce->stripslashes_values = 0;
}
}
}
(29-29/93)