00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 class t3lib_frontendedit {
00039
00040
00041
00042
00043
00044
00045 public $TSFE_EDIT;
00046
00047
00048
00049
00050
00051
00052 protected $tce;
00053
00054
00055
00056
00057
00058
00059 public function initConfigOptions() {
00060 $this->TSFE_EDIT = t3lib_div::_GP('TSFE_EDIT');
00061
00062
00063 if ($GLOBALS['BE_USER']->isFrontendEditingActive()) {
00064 $GLOBALS['TSFE']->includeTCA();
00065 if ($this->isEditAction()) {
00066 $this->editAction();
00067 }
00068 }
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 public function displayEditPanel($content, array $conf, $currentRecord, array $dataArray) {
00084 if ($conf['newRecordFromTable']) {
00085 $currentRecord = $conf['newRecordFromTable'] . ':NEW';
00086 $conf['allow'] = 'new';
00087 }
00088
00089 list($table, $uid) = explode(':', $currentRecord);
00090
00091
00092 $newRecordPid = intval($conf['newRecordInPid']);
00093 if (!$conf['onlyCurrentPid'] || $dataArray['pid'] == $GLOBALS['TSFE']->id) {
00094 if ($table=='pages') {
00095 $newUid = $uid;
00096 } else {
00097 if ($conf['newRecordFromTable']) {
00098 $newUid = $GLOBALS['TSFE']->id;
00099 if ($newRecordPid) {
00100 $newUid = $newRecordPid;
00101 }
00102 } else {
00103 $newUid = -1 * $uid;
00104 }
00105 }
00106 }
00107
00108 if ($GLOBALS['TSFE']->displayEditIcons && $table && $this->allowedToEdit($table, $dataArray, $conf) && $this->allowedToEditLanguage($table, $dataArray)) {
00109 $editClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/classes/class.frontendedit.php']['edit'];
00110 if ($editClass) {
00111 $edit = t3lib_div::getUserObj($editClass, false);
00112 if (is_object($edit)) {
00113 $allowedActions = $this->getAllowedEditActions($table, $conf, $dataArray['pid']);
00114 $content = $edit->editPanel($content, $conf, $currentRecord, $dataArray, $table, $allowedActions, $newUid, $this->getHiddenFields($dataArray));
00115 }
00116 }
00117 }
00118
00119 return $content;
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 public function displayEditIcons($content, $params, array $conf=array(), $currentRecord = '', array $dataArray = array(), $addUrlParamStr = '') {
00136
00137 list($currentRecordTable, $currentRecordUID) = explode(':', $currentRecord);
00138 list($fieldList, $table) = array_reverse(t3lib_div::trimExplode(':', $params, 1));
00139 if (!$table) {
00140 $table = $currentRecordTable;
00141 } elseif ($table != $currentRecordTable) {
00142 return $content;
00143 }
00144
00145 $editUid = $dataArray['_LOCALIZED_UID'] ? $dataArray['_LOCALIZED_UID'] : $currentRecordUID;
00146
00147
00148 if (!array_key_exists('allow', $conf)) {
00149 $conf['allow'] = 'edit';
00150 }
00151
00152 if ($GLOBALS['TSFE']->displayFieldEditIcons && $table && $this->allowedToEdit($table, $dataArray, $conf) && $fieldList && $this->allowedToEditLanguage($table, $dataArray)) {
00153 $editClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/classes/class.frontendedit.php']['edit'];
00154 if ($editClass) {
00155 $edit = t3lib_div::getUserObj($editClass);
00156 if (is_object($edit)) {
00157 $content = $edit->editIcons($content, $params, $conf, $currentRecord, $dataArray, $addURLParamStr, $table, $editUid, $fieldList);
00158 }
00159 }
00160 }
00161
00162 return $content;
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 public function isEditAction() {
00178 if (is_array($this->TSFE_EDIT)) {
00179 if ($this->TSFE_EDIT['cancel']) {
00180 unset($this->TSFE_EDIT['cmd']);
00181 } else {
00182 $cmd = (string) $this->TSFE_EDIT['cmd'];
00183 if (($cmd != 'edit' || (is_array($this->TSFE_EDIT['data']) && ($this->TSFE_EDIT['doSave'] || $this->TSFE_EDIT['update'] || $this->TSFE_EDIT['update_close']))) && $cmd != 'new') {
00184
00185 return true;
00186 }
00187 }
00188 }
00189 return false;
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199 public function isEditFormShown() {
00200 if (is_array($this->TSFE_EDIT)) {
00201 $cmd = (string) $this->TSFE_EDIT['cmd'];
00202 if ($cmd == 'edit' || $cmd == 'new') {
00203 return true;
00204 }
00205 }
00206 }
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 public function editAction() {
00217
00218 list($table, $uid) = explode(':', $this->TSFE_EDIT['record']);
00219 $uid = intval($uid);
00220 $cmd = $this->TSFE_EDIT['cmd'];
00221
00222
00223 if (($this->TSFE_EDIT['doSave'] || $this->TSFE_EDIT['update'] || $this->TSFE_EDIT['update_close']) && is_array($this->TSFE_EDIT['data'])) {
00224 $cmd = 'save';
00225 }
00226
00227 if (($cmd == 'save') || ($cmd && $table && $uid && isset($GLOBALS['TCA'][$table]))) {
00228
00229 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extEditAction'])) {
00230 $_params = array();
00231 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extEditAction'] as $_funcRef) {
00232 t3lib_div::callUserFunction($_funcRef, $_params, $this);
00233 }
00234 }
00235
00236
00237 $cmdAction = 'do' . ucwords($cmd);
00238 if (is_callable(array($this, $cmdAction))) {
00239 $this->$cmdAction($table, $uid);
00240 } else {
00241 throw new UnexpectedValueException(
00242 'The specified frontend edit command (' . $cmd . ') is not valid.',
00243 1225818120
00244 );
00245 }
00246 }
00247 }
00248
00249
00250
00251
00252
00253
00254
00255
00256 public function doHide($table, $uid) {
00257 $hideField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
00258 if ($hideField) {
00259 $recData = array();
00260 $recData[$table][$uid][$hideField] = 1;
00261
00262 $this->initializeTceMain();
00263 $this->tce->start($recData, array());
00264 $this->tce->process_datamap();
00265 }
00266 }
00267
00268
00269
00270
00271
00272
00273
00274
00275 public function doUnhide($table, $uid) {
00276 $hideField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
00277 if ($hideField) {
00278 $recData = array();
00279 $recData[$table][$uid][$hideField] = 0;
00280
00281 $this->initializeTceMain();
00282 $this->tce->start($recData, array());
00283 $this->tce->process_datamap();
00284 }
00285 }
00286
00287
00288
00289
00290
00291
00292
00293
00294 public function doUp($table, $uid) {
00295 $this->move($table, $uid, 'up');
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305 public function doDown($table, $uid) {
00306 $this->move($table, $uid, 'down');
00307 }
00308
00309
00310
00311
00312
00313
00314
00315
00316 public function doMoveAfter($table, $uid) {
00317 $afterUID = $GLOBALS['BE_USER']->frontendEdit->TSFE_EDIT['moveAfter'];
00318 $this->move($table, $uid, '', $afterUID);
00319 }
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 protected function move($table, $uid, $direction='', $afterUID=0) {
00331 $cmdData = array();
00332 $sortField = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
00333 if ($sortField) {
00334
00335 $fields = array_unique(t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields'] . ',uid,pid,' . $sortField, true));
00336 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',', $fields), $table, 'uid=' . $uid);
00337 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00338
00339 if (($GLOBALS['BE_USER']->adminPanel instanceOf tslib_AdminPanel) && ($GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview'))) {
00340 $ignore = array('starttime'=>1, 'endtime'=>1, 'disabled'=>1, 'fe_group'=>1);
00341 }
00342 $copyAfterFieldsQuery = '';
00343 if ($GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields']) {
00344 $cAFields = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields'], true);
00345 foreach($cAFields as $fieldName) {
00346 $copyAfterFieldsQuery .= ' AND ' . $fieldName . '="' . $row[$fieldName] . '"';
00347 }
00348 }
00349 if (!empty($direction)) {
00350 if ($direction == 'up') {
00351 $operator = '<';
00352 $order = 'DESC';
00353 } else {
00354 $operator = '>';
00355 $order = 'ASC';
00356 }
00357 $sortCheck = ' AND ' . $sortField . $operator . intval($row[$sortField]);
00358 }
00359 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00360 'uid,pid',
00361 $table,
00362 'pid=' . intval($row['pid']) .
00363 $sortCheck .
00364 $copyAfterFieldsQuery .
00365 $GLOBALS['TSFE']->sys_page->enableFields($table, '', $ignore),
00366 '',
00367 $sortField . ' ' . $order,
00368 '2'
00369 );
00370 if ($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00371 if ($afterUID) {
00372 $cmdData[$table][$uid]['move'] = -$afterUID;
00373 }
00374 elseif ($direction == 'down') {
00375 $cmdData[$table][$uid]['move'] = -$row2['uid'];
00376 }
00377 elseif ($row3 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00378 $cmdData[$table][$uid]['move'] = -$row3['uid'];
00379 }
00380 else {
00381 $cmdData[$table][$uid]['move'] = $row['pid'];
00382 }
00383 } elseif ($direction == 'up') {
00384 $cmdData[$table][$uid]['move'] = $row['pid'];
00385 }
00386 }
00387 if (!empty($cmdData)) {
00388 $this->initializeTceMain();
00389 $this->tce->start(array(), $cmdData);
00390 $this->tce->process_cmdmap();
00391 }
00392 }
00393 }
00394
00395
00396
00397
00398
00399
00400
00401
00402 public function doDelete($table, $uid) {
00403 $cmdData[$table][$uid]['delete'] = 1;
00404 if (count($cmdData)) {
00405 $this->initializeTceMain();
00406 $this->tce->start(array(), $cmdData);
00407 $this->tce->process_cmdmap();
00408 }
00409 }
00410
00411
00412
00413
00414
00415
00416
00417
00418 public function doSave($table, $uid) {
00419 $data = $this->TSFE_EDIT['data'];
00420
00421 if (!empty($data)) {
00422 $this->initializeTceMain();
00423 $this->tce->start($data, array());
00424 $this->tce->process_uploads($_FILES);
00425 $this->tce->process_datamap();
00426
00427
00428 $newUID = $this->tce->substNEWwithIDs['NEW'];
00429 if ($newUID) {
00430 $GLOBALS['BE_USER']->frontendEdit->TSFE_EDIT['newUID'] = $newUID;
00431 }
00432 }
00433 }
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 public function doSaveAndClose($table, $uid) {
00449 $this->doSave($table, $uid);
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461 public function doClose($table, $uid) {
00462
00463 }
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473 protected function allowedToEditLanguage($table, array $currentRecord) {
00474
00475 if ($table === 'pages') {
00476 $lang = $GLOBALS['TSFE']->sys_language_uid;
00477 } elseif ($table === 'tt_content') {
00478 $lang = $GLOBALS['TSFE']->sys_language_content;
00479 } elseif ($GLOBALS['TCA'][$table]['ctrl']['languageField']) {
00480 $lang = $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']];
00481 } else {
00482 $lang = -1;
00483 }
00484
00485 if ($GLOBALS['BE_USER']->checkLanguageAccess($lang)) {
00486 $languageAccess = true;
00487 } else {
00488 $languageAccess = false;
00489 }
00490
00491 return $languageAccess;
00492 }
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502 protected function allowedToEdit($table, array $dataArray, array $conf) {
00503
00504
00505 $mayEdit = false;
00506
00507 if ($table=='pages') {
00508
00509 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->doesUserHaveAccess($dataArray, 2)) {
00510 $mayEdit = true;
00511 }
00512 } else {
00513
00514 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->doesUserHaveAccess(t3lib_BEfunc::getRecord('pages', $dataArray['pid']), 16)) {
00515 $mayEdit = true;
00516 }
00517 }
00518
00519 if (!$conf['onlyCurrentPid'] || ($dataArray['pid'] == $GLOBALS['TSFE']->id)) {
00520
00521 $types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']),1);
00522 $allow = array_flip($types);
00523
00524 $perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
00525 if ($table == 'pages') {
00526 $allow = $this->getAllowedEditActions($table, $conf, $dataArray['pid'], $allow);
00527
00528
00529 if (count($allow)) {
00530 $mayEdit = true;
00531 }
00532 } else {
00533 $mayEdit = count($allow) && ($perms & 16);
00534 }
00535 }
00536
00537 return $mayEdit;
00538 }
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549 protected function getAllowedEditActions($table, array $conf, $pid, $allow = '') {
00550
00551 if (!$allow) {
00552 $types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']), true);
00553 $allow = array_flip($types);
00554 }
00555
00556 if (!$conf['onlyCurrentPid'] || $pid == $GLOBALS['TSFE']->id) {
00557
00558 $types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']), true);
00559 $allow = array_flip($types);
00560
00561 $perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
00562 if ($table=='pages') {
00563
00564 if (count($GLOBALS['TSFE']->config['rootLine']) == 1) {
00565 unset($allow['move']);
00566 unset($allow['hide']);
00567 unset($allow['delete']);
00568 }
00569 if (!($perms & 2)){
00570 unset($allow['edit']);
00571 unset($allow['move']);
00572 unset($allow['hide']);
00573 }
00574 if (!($perms & 4)) {
00575 unset($allow['delete']);
00576 }
00577 if (!($perms&8)) {
00578 unset($allow['new']);
00579 }
00580 }
00581 }
00582
00583 return $allow;
00584 }
00585
00586
00587
00588
00589
00590
00591
00592 public function getJavascriptIncludes() {
00593
00594 return '';
00595 }
00596
00597
00598
00599
00600
00601
00602
00603
00604 public function getHiddenFields(array $dataArray) {
00605
00606 return array();
00607 }
00608
00609
00610
00611
00612
00613
00614 protected function initializeTceMain() {
00615 if (!isset($this->tce)) {
00616 $this->tce = t3lib_div::makeInstance('t3lib_TCEmain');
00617 $this->tce->stripslashes_values=0;
00618 }
00619 }
00620 }
00621
00622 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_frontendedit.php']) {
00623 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_frontendedit.php']);
00624 }
00625
00626 ?>