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 protected $tce;
00046
00047
00048
00049
00050
00051
00052
00053 protected $ext_forcePreview = false;
00054
00055
00056
00057
00058
00059
00060 protected $extPublishList = '';
00061
00062
00063
00064
00065
00066
00067 public function __construct() {
00068 $this->tce = t3lib_div::makeInstance('t3lib_TCEmain');
00069 $this->tce->stripslashes_values=0;
00070 }
00071
00072
00073
00074
00075
00076
00077 public function initConfigOptions() {
00078 $this->saveConfigOptions();
00079 $this->TSFE_EDIT = t3lib_div::_POST('TSFE_EDIT');
00080
00081
00082 $GLOBALS['TSFE']->forceTemplateParsing = $this->extGetFeAdminValue('tsdebug', 'forceTemplateParsing');
00083 $GLOBALS['TSFE']->displayEditIcons = $this->extGetFeAdminValue('edit', 'displayIcons');
00084 $GLOBALS['TSFE']->displayFieldEditIcons = $this->extGetFeAdminValue('edit', 'displayFieldIcons');
00085
00086 if ($this->extGetFeAdminValue('tsdebug', 'displayQueries')) {
00087 if ($GLOBALS['TYPO3_DB']->explainOutput == 0) {
00088
00089 $GLOBALS['TYPO3_DB']->explainOutput = 3;
00090 }
00091 }
00092
00093 if (t3lib_div::_GP('ADMCMD_editIcons')) {
00094 $GLOBALS['TSFE']->displayFieldEditIcons=1;
00095 $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['edit_editNoPopup']=1;
00096 }
00097
00098 if (t3lib_div::_GP('ADMCMD_simUser')) {
00099 $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['preview_simulateUserGroup']=intval(t3lib_div::_GP('ADMCMD_simUser'));
00100 $this->ext_forcePreview = true;
00101 }
00102
00103 if (t3lib_div::_GP('ADMCMD_simTime')) {
00104 $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['preview_simulateDate']=intval(t3lib_div::_GP('ADMCMD_simTime'));
00105 $this->ext_forcePreview = true;
00106 }
00107
00108
00109 if (($this->isAdminModuleEnabled('edit') && $this->isAdminModuleOpen('edit')) || $GLOBALS['TSFE']->displayEditIcons == 1) {
00110 $GLOBALS['TSFE']->includeTCA();
00111 if ($this->isEditAction()) {
00112 require_once (PATH_t3lib . 'class.t3lib_tcemain.php');
00113 $this->editAction();
00114 }
00115
00116 if ($this->isEditFormShown()) {
00117 require_once(PATH_t3lib . 'class.t3lib_tceforms.php');
00118 require_once(PATH_t3lib . 'class.t3lib_iconworks.php');
00119 require_once(PATH_t3lib . 'class.t3lib_loaddbgroup.php');
00120 require_once(PATH_t3lib . 'class.t3lib_transferdata.php');
00121 }
00122 }
00123
00124 if ($GLOBALS['TSFE']->forceTemplateParsing || $GLOBALS['TSFE']->displayEditIcons || $GLOBALS['TSFE']->displayFieldEditIcons) {
00125 $GLOBALS['TSFE']->set_no_cache();
00126 }
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 public function displayAdmin() {
00136 $content = '';
00137 $adminClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/classes/class.frontendedit.php']['admin'];
00138 if ($adminClass && !$GLOBALS['BE_USER']->extAdminConfig['hide']) {
00139 $admin = &t3lib_div::getUserObj($adminClass);
00140 if (is_object($admin)) {
00141 $content = $admin->display();
00142 }
00143 }
00144
00145 return $content;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 public function displayEditPanel($content, array $conf, $currentRecord, array $dataArray) {
00161 if ($conf['newRecordFromTable']) {
00162 $currentRecord = $conf['newRecordFromTable'] . ':NEW';
00163 $conf['allow'] = 'new';
00164 }
00165
00166 list($table, $uid) = explode(':', $currentRecord);
00167
00168
00169 $newRecordPid = intval($conf['newRecordInPid']);
00170 if (!$conf['onlyCurrentPid'] || $dataArray['pid'] == $GLOBALS['TSFE']->id) {
00171 if ($table=='pages') {
00172 $newUid = $uid;
00173 } else {
00174 if ($conf['newRecordFromTable']) {
00175 $newUid = $GLOBALS['TSFE']->id;
00176 if ($newRecordPid) {
00177 $newUid = $newRecordPid;
00178 }
00179 } else {
00180 $newUid = -1 * $uid;
00181 }
00182 }
00183 }
00184
00185 if ($GLOBALS['TSFE']->displayEditIcons && $table && $this->allowedToEdit($table, $dataArray, $conf) && $this->allowedToEditLanguage($table, $dataArray)) {
00186 $editClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/classes/class.frontendedit.php']['edit'];
00187 if ($editClass) {
00188 $edit = &t3lib_div::getUserObj($editClass, false);
00189 if (is_object($edit)) {
00190 $allowedActions = $this->getAllowedEditActions($table, $conf, $dataArray['pid']);
00191 $content = $edit->editPanel($content, $conf, $currentRecord, $dataArray, $table, $allowedActions, $newUid, $this->getHiddenFieldArray($dataArray));
00192 }
00193 }
00194 }
00195
00196 return $content;
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206 public function getHiddenFieldArray(array $dataArray) {
00207
00208 return array();
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 public function displayEditIcons($content, $params, array $conf=array(), $currentRecord = '', array $dataArray = array(), $addUrlParamStr = '') {
00225
00226 list($currentRecordTable, $currentRecordUID) = explode(':', $currentRecord);
00227 list($fieldList, $table) = array_reverse(t3lib_div::trimExplode(':', $params, 1));
00228 if (!$table) {
00229 $table = $currentRecordTable;
00230 } elseif ($table != $currentRecordTable) {
00231 return $content;
00232 }
00233
00234 $editUid = $dataArray['_LOCALIZED_UID'] ? $dataArray['_LOCALIZED_UID'] : $currentRecordUID;
00235
00236
00237 if(!array_key_exists('allow', $conf)) {
00238 $conf['allow'] = 'edit';
00239 }
00240
00241 if ($GLOBALS['TSFE']->displayFieldEditIcons && $table && $this->allowedToEdit($table, $dataArray, $conf) && $fieldList && $this->allowedToEditLanguage($table, $dataArray)) {
00242 $editClass = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/classes/class.frontendedit.php']['edit'];
00243 if ($editClass) {
00244 $edit = &t3lib_div::getUserObj($editClass);
00245 if (is_object($edit)) {
00246 $content = $edit->editIcons($content, $params, $conf, $currentRecord, $dataArray, $addURLParamStr, $table, $editUid, $fieldList);
00247 }
00248 }
00249 }
00250
00251 return $content;
00252 }
00253
00254
00255
00256
00257
00258
00259
00260 public function isAdminModuleEnabled($key) {
00261
00262 if ($key=='preview' && $this->ext_forcePreview) {
00263 return true;
00264 }
00265
00266
00267 if ($GLOBALS['BE_USER']->extAdminConfig['enable.']['all']) {
00268 return true;
00269 }
00270
00271 if ($GLOBALS['BE_USER']->extAdminConfig['enable.'][$key]) {
00272 return true;
00273 }
00274 }
00275
00276
00277
00278
00279
00280
00281
00282 public function saveConfigOptions() {
00283 $input = t3lib_div::_GP('TSFE_ADMIN_PANEL');
00284 if (is_array($input)) {
00285
00286 $GLOBALS['BE_USER']->uc['TSFE_adminConfig'] = array_merge(!is_array($GLOBALS['BE_USER']->uc['TSFE_adminConfig']) ? array() : $GLOBALS['BE_USER']->uc['TSFE_adminConfig'], $input);
00287 unset($GLOBALS['BE_USER']->uc['TSFE_adminConfig']['action']);
00288
00289
00290 if ($input['action']['clearCache'] && $this->isAdminModuleEnabled('cache')) {
00291 $GLOBALS['BE_USER']->extPageInTreeInfo=array();
00292 $theStartId = intval($input['cache_clearCacheId']);
00293 $GLOBALS['TSFE']->clearPageCacheContent_pidList($GLOBALS['BE_USER']->extGetTreeList($theStartId, $this->extGetFeAdminValue('cache', 'clearCacheLevels'), 0, $GLOBALS['BE_USER']->getPagePermsClause(1)) . $theStartId);
00294 }
00295 if ($input['action']['publish'] && $this->isAdminModuleEnabled('publish')) {
00296 $theStartId = intval($input['publish_id']);
00297 $this->extPublishList = $GLOBALS['BE_USER']->extGetTreeList($theStartId, $this->extGetFeAdminValue('publish', 'levels'), 0, $GLOBALS['BE_USER']->getPagePermsClause(1)) . $theStartId;
00298 }
00299
00300
00301 $GLOBALS['BE_USER']->writeUC();
00302 }
00303 $GLOBALS['TT']->LR = $this->extGetFeAdminValue('tsdebug', 'LR');
00304
00305 if ($this->extGetFeAdminValue('cache', 'noCache')) {
00306 $GLOBALS['TSFE']->set_no_cache();
00307 }
00308
00309
00310
00311 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extSaveFeAdminConfig-postProc'])) {
00312 $_params = array('input' => &$input, 'pObj' => &$this);
00313 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extSaveFeAdminConfig-postProc'] as $_funcRef) {
00314 t3lib_div::callUserFunction($_funcRef, $_params, $this);
00315 }
00316 }
00317 }
00318
00319
00320
00321
00322
00323
00324
00325
00326 public function extGetFeAdminValue($pre, $val='') {
00327
00328 if ($this->isAdminModuleEnabled($pre)) {
00329
00330
00331 if ($pre . '_' . $val == 'edit_displayIcons' && $GLOBALS['BE_USER']->extAdminConfig['module.']['edit.']['forceDisplayIcons']) {
00332 return true;
00333 }
00334 if ($pre . '_' . $val == 'edit_displayFieldIcons' && $GLOBALS['BE_USER']->extAdminConfig['module.']['edit.']['forceDisplayFieldIcons']) {
00335 return true;
00336 }
00337
00338
00339 if ($GLOBALS['BE_USER']->extAdminConfig['override.'][$pre . '.'][$val] && $val) {
00340 return $GLOBALS['BE_USER']->extAdminConfig['override.'][$pre . '.'][$val];
00341 }
00342 if ($GLOBALS['BE_USER']->extAdminConfig['override.'][$pre]) {
00343 return $GLOBALS['BE_USER']->extAdminConfig['override.'][$pre];
00344 }
00345
00346 $retVal = $val ? $GLOBALS['BE_USER']->uc['TSFE_adminConfig'][$pre . '_' . $val] : 1;
00347
00348 if ($pre=='preview' && $this->ext_forcePreview) {
00349 if (!$val) {
00350 return true;
00351 } else {
00352 return $retVal;
00353 }
00354 }
00355
00356 if ($this->isAdminModuleOpen($pre)) {
00357 return $retVal;
00358 }
00359
00360
00361
00362 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extEditAction-postProc'])) {
00363 $_params = array('cmd' => &$cmd, 'tce' => &$this->tce, 'pObj' => &$this);
00364 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extEditAction-postProc'] as $_funcRef) {
00365 t3lib_div::callUserFunction($_funcRef, $_params, $this);
00366 }
00367 }
00368 }
00369 }
00370
00371
00372
00373
00374
00375
00376 public function getExtPublishList() {
00377 return $this->extPublishList;
00378 }
00379
00380
00381
00382
00383
00384
00385
00386 public function isAdminModuleOpen($pre) {
00387 return $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_top'] && $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_' . $pre];
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402 public function isEditAction() {
00403 if (is_array($this->TSFE_EDIT)) {
00404 if ($this->TSFE_EDIT['cancel']) {
00405 unset($this->TSFE_EDIT['cmd']);
00406 } else {
00407 $cmd = (string) $this->TSFE_EDIT['cmd'];
00408 if (($cmd != 'edit' || (is_array($this->TSFE_EDIT['data']) && ($this->TSFE_EDIT['update'] || $this->TSFE_EDIT['update_close']))) && $cmd != 'new') {
00409
00410 return true;
00411 }
00412 }
00413 }
00414 return false;
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424 public function isEditFormShown() {
00425 if (is_array($this->TSFE_EDIT)) {
00426 $cmd = (string) $this->TSFE_EDIT['cmd'];
00427 if ($cmd=='edit' || $cmd=='new') {
00428 return true;
00429 }
00430 }
00431 }
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441 public function editAction() {
00442
00443 list($table, $uid) = explode(':', $this->TSFE_EDIT['record']);
00444 $cmd = $this->TSFE_EDIT['cmd'];
00445
00446 if ($cmd && $table && $uid && isset($GLOBALS['TCA'][$table])) {
00447
00448 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extEditAction'])) {
00449 $_params = array();
00450 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['extEditAction'] as $_funcRef) {
00451 t3lib_div::callUserFunction($_funcRef, $_params, $this);
00452 }
00453 }
00454
00455 if(is_callable(array($this, $cmd))) {
00456 $this->$cmd($table, $uid);
00457 } else {
00458 throw new UnexpectedValueException(
00459 'The specified frontend edit command (' . $cmd . ') is not valid.',
00460 1225818120
00461 );
00462 }
00463 }
00464
00465 if (($this->TSFE_EDIT['doSave'] || $this->TSFE_EDIT['update'] || $this->TSFE_EDIT['update_close']) && is_array($this->TSFE_EDIT['data'])) {
00466 $this->save($this->TSFE_EDIT['data']);
00467
00468 if ($newuid = $this->tce->substNEWwithIDs['NEW']) {
00469 $this->TSFE_EDIT['newUID'] = $newuid;
00470 }
00471 }
00472 }
00473
00474
00475
00476
00477
00478
00479
00480
00481 public function hide($table, $uid) {
00482 $hideField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
00483 if ($hideField) {
00484 $recData = array();
00485 $recData[$table][$uid][$hideField] = 1;
00486 $this->tce->start($recData, array());
00487 $this->tce->process_datamap();
00488 }
00489 }
00490
00491
00492
00493
00494
00495
00496
00497
00498 public function unhide($table, $uid) {
00499 $hideField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
00500 if ($hideField) {
00501 $recData = array();
00502 $recData[$table][$uid][$hideField] = 0;
00503 $this->tce->start($recData, array());
00504 $this->tce->process_datamap();
00505 }
00506 }
00507
00508
00509
00510
00511
00512
00513
00514
00515 public function up($table, $uid) {
00516 $this->move($table, $uid, 'up');
00517 }
00518
00519
00520
00521
00522
00523
00524
00525
00526 public function down($table, $uid) {
00527 $this->move($table, $uid, 'down');
00528 }
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 protected function move($table, $uid, $direction) {
00539 $cmdData = array();
00540 if ($direction == 'up') {
00541 $operator = '<';
00542 $order = 'DESC';
00543 } else {
00544 $operator = '>';
00545 $order = 'ASC';
00546 }
00547
00548 $sortField = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
00549 if ($sortField) {
00550
00551 $fields = array_unique(t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields'] . ',uid,pid,' . $sortField, true));
00552 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',', $fields), $table, 'uid=' . $uid);
00553 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00554
00555 $preview = $this->extGetFeAdminValue('preview');
00556 $copyAfterFieldsQuery = '';
00557 if ($preview) {
00558 $ignore = array('starttime'=>1, 'endtime'=>1, 'disabled'=>1, 'fe_group'=>1);
00559 }
00560 if ($GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields']) {
00561 $cAFields = t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['copyAfterDuplFields'], false);
00562 foreach($cAFields as $fieldName) {
00563 $copyAfterFieldsQuery .= ' AND ' . $fieldName . '="' . $row[$fieldName] . '"';
00564 }
00565 }
00566
00567 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00568 'uid,pid',
00569 $table,
00570 'pid=' . intval($row['pid']) .
00571 ' AND ' . $sortField . $operator . intval($row[$sortField]) .
00572 $copyAfterFieldsQuery .
00573 $GLOBALS['TSFE']->sys_page->enableFields($table, '', $ignore),
00574 '',
00575 $sortField . ' ' . $order,
00576 '2'
00577 );
00578 if ($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00579 if ($direction == 'down') {
00580 $cmdData[$table][$uid]['move'] = -$row2['uid'];
00581 } elseif ($row3 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00582 $cmdData[$table][$uid]['move'] = -$row3['uid'];
00583 } else {
00584 $cmdData[$table][$uid]['move'] = $row['pid'];
00585 }
00586 } elseif ($direction == 'up') {
00587 $cmdData[$table][$uid]['move'] = $row['pid'];
00588 }
00589 }
00590 if (count($cmdData)) {
00591 $this->tce->start(array(), $cmdData);
00592 $this->tce->process_cmdmap();
00593 }
00594 }
00595 }
00596
00597
00598
00599
00600
00601
00602
00603
00604 public function delete($table, $uid) {
00605 $cmdData[$table][$uid]['delete'] = 1;
00606 if (count($cmdData)) {
00607 $this->tce->start(array(), $cmdData);
00608 $this->tce->process_cmdmap();
00609 }
00610 }
00611
00612
00613
00614
00615
00616
00617
00618 public function save(array $data) {
00619 $this->tce->start($data, array());
00620 $this->tce->process_uploads($_FILES);
00621 $this->tce->process_datamap();
00622 }
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632 protected function allowedToEditLanguage($table, array $currentRecord) {
00633
00634 if ($table === 'pages') {
00635 $lang = $GLOBALS['TSFE']->sys_language_uid;
00636 } elseif ($table === 'tt_content') {
00637 $lang = $GLOBALS['TSFE']->sys_language_content;
00638 } elseif ($GLOBALS['TCA'][$table]['ctrl']['languageField']) {
00639 $lang = $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']];
00640 } else {
00641 $lang = -1;
00642 }
00643
00644 if ($GLOBALS['BE_USER']->checkLanguageAccess($lang)) {
00645 $languageAccess = true;
00646 } else {
00647 $languageAccess = false;
00648 }
00649
00650 return $languageAccess;
00651 }
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661 protected function allowedToEdit($table, array $dataArray, array $conf) {
00662
00663
00664 $mayEdit = false;
00665
00666 if ($table=='pages') {
00667
00668 if($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->doesUserHaveAccess($dataArray, 2)) {
00669 $mayEdit = true;
00670 }
00671 } else {
00672
00673 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->doesUserHaveAccess(t3lib_BEfunc::getRecord('pages', $dataArray['pid']), 16)) {
00674 $mayEdit = true;
00675 }
00676 }
00677
00678 if (!$conf['onlyCurrentPid'] || ($dataArray['pid'] == $GLOBALS['TSFE']->id)) {
00679
00680 $types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']),1);
00681 $allow = array_flip($types);
00682
00683 $perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
00684 if ($table == 'pages') {
00685 $allow = $this->getAllowedEditActions($table, $conf, $dataArray['pid'], $allow);
00686
00687
00688 if (count($allow)) {
00689 $mayEdit = true;
00690 }
00691 } else {
00692 $mayEdit = count($allow) && ($perms & 16);
00693 }
00694 }
00695
00696 return $mayEdit;
00697 }
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708 protected function getAllowedEditActions($table, array $conf, $pid, $allow = '') {
00709
00710 if (!$allow) {
00711 $types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']), true);
00712 $allow = array_flip($types);
00713 }
00714
00715 if (!$conf['onlyCurrentPid'] || $pid == $GLOBALS['TSFE']->id) {
00716
00717 $types = t3lib_div::trimExplode(',', t3lib_div::strtolower($conf['allow']), true);
00718 $allow = array_flip($types);
00719
00720 $perms = $GLOBALS['BE_USER']->calcPerms($GLOBALS['TSFE']->page);
00721 if ($table=='pages') {
00722
00723 if (count($GLOBALS['TSFE']->config['rootLine']) == 1) {
00724 unset($allow['move']);
00725 unset($allow['hide']);
00726 unset($allow['delete']);
00727 }
00728 if (!($perms & 2)){
00729 unset($allow['edit']);
00730 unset($allow['move']);
00731 unset($allow['hide']);
00732 }
00733 if (!($perms & 4)) {
00734 unset($allow['delete']);
00735 }
00736 if (!($perms&8)) {
00737 unset($allow['new']);
00738 }
00739 }
00740 }
00741
00742 return $allow;
00743 }
00744 }
00745
00746 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_frontendedit.php']) {
00747 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_frontendedit.php']);
00748 }
00749
00750 ?>