⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workspaceforms.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
	function buildEditForm() {		$content = '';		$table = 'sys_workspace';		$prevPageID = '';		$trData = t3lib_div::makeInstance('t3lib_transferData');		$trData->addRawData = TRUE;		$trData->defVals = $this->defVals;		$trData->lockRecords=1;		$trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];		$trData->prevPageID = $prevPageID;		$trData->fetchRecord($table, $this->workspaceId, '');		reset($trData->regTableItems_data);		$rec = current($trData->regTableItems_data);		// Setting variables in TCEforms object:		$this->tceforms->hiddenFieldList = '';		// Register default language labels, if any:		$this->tceforms->registerDefaultLanguageData($table,$rec);		$this->fixVariousTCAFields();		if (!$GLOBALS['BE_USER']->isAdmin()) {			// Non-admins cannot select users from the root. We "fix" it for them.			$this->fixTCAUserField('adminusers');			$this->fixTCAUserField('members');			$this->fixTCAUserField('reviewers');		}		// Create form for the record (either specific list of fields or the whole record):		$form = '';		$form .= $this->tceforms->getMainFields($table,$rec);		$form .= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />';		$form .= '<input type="hidden" name="workspace_form_submited" value="1" />';		$form .= '<input type="hidden" name="returnUrl" value="index.php" />';		$form .= '<input type="hidden" name="action" value="edit" />';		$form .= '<input type="hidden" name="closeDoc" value="0" />';		$form .= '<input type="hidden" name="doSave" value="0" />';		$form .= '<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />';		$form .= '<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'" />';		$form .= '<input type="hidden" name="wkspId" value="' . htmlspecialchars($this->workspaceId) . '" />';		$form = $this->tceforms->wrapTotal($form, $rec, $table);		$buttons = $this->createButtons() . $this->doc->spacer(5);		// Combine it all:		$content .= $buttons . $form . $buttons;		return $content;	}	/**	 * Creates a form for new workspace. Parts are adopted from <code>alt_doc.php</code>.	 *	 * @return	string		Generated form	 */	function buildNewForm() {		$content = '';		$table = 'sys_workspace';		$prevPageID = '';		$trData = t3lib_div::makeInstance('t3lib_transferData');		$trData->addRawData = TRUE;		$trData->defVals = $this->defVals;		$trData->lockRecords=1;		$trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];		$trData->prevPageID = $prevPageID;		$trData->fetchRecord($table, 0, 'new');		reset($trData->regTableItems_data);		$rec = current($trData->regTableItems_data);		$rec['uid'] = uniqid('NEW');		$rec['pid'] = 0;		$rec['adminusers'] = $this->getOwnerUser($rec['uid']);		// Setting variables in TCEforms object:		$this->tceforms->hiddenFieldList = '';		// Register default language labels, if any:		$this->tceforms->registerDefaultLanguageData($table,$rec);		$this->fixVariousTCAFields();		if (!$GLOBALS['BE_USER']->isAdmin()) {			// Non-admins cannot select users from the root. We "fix" it for them.			$this->fixTCAUserField('adminusers');			$this->fixTCAUserField('members');			$this->fixTCAUserField('reviewers');		}		// Create form for the record (either specific list of fields or the whole record):		$form = '';		$form .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': ' . $this->tceforms->getRecordPath($table,$rec);		$form .= $this->doc->spacer(5);		$form .= $this->tceforms->getMainFields($table,$rec);		$form .= '<input type="hidden" name="workspace_form_submited" value="1" />';		$form .= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />';		$form .= '<input type="hidden" name="returnUrl" value="index.php" />';		$form .= '<input type="hidden" name="action" value="new" />';		$form .= '<input type="hidden" name="closeDoc" value="0" />';		$form .= '<input type="hidden" name="doSave" value="0" />';		$form .= '<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />';		$form .= '<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'" />';		$form = $this->tceforms->wrapTotal($form, $rec, $table);		$buttons = $this->createButtons() . $this->doc->spacer(5);		// Combine it all:		$content .= $buttons . $form . $buttons;		return $content;	}	/**	 * Creates standard buttons for form. Adopted from <code>alt_doc.php</code>.	 *	 * @return	string		Generated buttons code	 */	function createButtons() {		global	$LANG;		$content = '';		$content .= '<input type="image" class="c-inputButton" name="_savedok"' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedok.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc',1).'" value="_savedok" />';		$content .= '<input type="image" class="c-inputButton" name="_saveandclosedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/saveandclosedok.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc',1).'" value="_saveandclosedok" />';		// `n` below is simply to prevent caching		$content .= '<a href="index.php?n=' . uniqid('wksp') . '"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/closedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'" alt="" /></a>';		return $content;	}	/**	 * Returns owner user (i.e. current BE user) in the format suitable for TCE forms. This function uses <code>t3lib_loadDBGroup</code> to create value. Code is adopted from <code>t3lib_transferdata::renderRecord_groupProc()</code>.	 *	 * @param	string		$uid	UID of the record (as <code>NEW...</code>)	 * @return	string		User record formatted for TCEForms	 */	function getOwnerUser($uid) {		$loadDB = t3lib_div::makeInstance('t3lib_loadDBGroup');		// Make sure that `sys_workspace` is in $TCA		t3lib_div::loadTCA('sys_workspace');		// shortcut to `config` of `adminusers` field -- shorter code and better PHP performance		$config = &$GLOBALS['TCA']['sys_workspace']['columns']['adminusers']['config'];		// Notice: $config['MM'] is not set in the current version of $TCA but		// we still pass it to ensure compatibility with feature versions!		$loadDB->start($GLOBALS['BE_USER']->user['uid'], $config['allowed'], $config['MM'], $uid, 'sys_workspace', $config);		$loadDB->getFromDB();		return $loadDB->readyForInterface();	}	/**	 * Processes submitted data. This function uses <code>t3lib_TCEmain::process_datamap()</code> to create/update records in the <code>sys_workspace</code> table. It will print error messages just like any other Typo3 module with similar functionality. Function also changes workspace ID and module mode to 'edit' if new record was just created.	 *	 * @return	void	 */	function processData() {		$tce = t3lib_div::makeInstance('t3lib_TCEmain');		$tce->stripslashes_values = 0;		$TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');		if (is_array($TCAdefaultOverride))	{			$tce->setDefaultsFromUserTS($TCAdefaultOverride);		}		$tce->stripslashes_values = 0;			// The following is a security precaution; It makes sure that the input data array can ONLY contain data for the sys_workspace table and ONLY one record.			// If this is not present it could be mis-used for nasty XSS attacks which can escalate rights to admin for even non-admin users.		$inputData_tmp = t3lib_div::_GP('data');		$inputData = array();		if (is_array($inputData_tmp['sys_workspace']))	{			reset($inputData_tmp['sys_workspace']);			$inputData['sys_workspace'][key($inputData_tmp['sys_workspace'])] = current($inputData_tmp['sys_workspace']);		}		$tce->start($inputData, array(), $GLOBALS['BE_USER']);		$tce->admin = 1;	// Bypass table restrictions		$tce->bypassWorkspaceRestrictions = true;		$tce->process_datamap();			// print error messages (if any)		$script = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT');		$tce->printLogErrorMessages($script . '?' .			($this->isEditAction ? 'action=edit&wkspId=' . $this->workspaceId : 'action=new'));		// If there was saved any new items, load them and update mode and workspace id		if (count($tce->substNEWwithIDs_table))	{			reset($tce->substNEWwithIDs_table);	// not really necessary but better be safe...			$this->workspaceId = current($tce->substNEWwithIDs);			$this->isEditAction = true;		}	}	/**	 * Fixes various <code>$TCA</code> fields for better visual representation of workspace editor.	 *	 * @return	void	 */	function fixVariousTCAFields() {		// enable tabs		$GLOBALS['TCA']['sys_workspace']['ctrl']['dividers2tabs'] = true;	}	/**	 * "Fixes" <code>$TCA</code> to enable blinding for users/groups for non-admin users only.	 *	 * @param	string		$fieldName	Name of the field to change	 * @return	void	 */	function fixTCAUserField($fieldName) {		// fix fields for non-admin		if (!$GLOBALS['BE_USER']->isAdmin()) {			// make a shortcut to field			t3lib_div::loadTCA('sys_workspace');			$field = &$GLOBALS['TCA']['sys_workspace']['columns'][$fieldName];			$newField = array (				'label' => $field['label'],				'config' => Array (					'type' => 'select',					'itemsProcFunc' => 'user_SC_mod_user_ws_workspaceForms->processUserAndGroups',					//'iconsInOptionTags' => true,					'size' => 10,					'maxitems' => $field['config']['maxitems'],					'autoSizeMax' => $field['config']['autoSizeMax'],					'mod_ws_allowed' => $field['config']['allowed']	// let us know what we can use in itemProcFunc				)			);			$field = $newField;		}	}	/**	 * Checks if use has editing access to the workspace.	 *	 * @return	boolean		Returns true if user can edit workspace	 */	function checkWorkspaceAccess() {		$workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','uid=' . intval($this->workspaceId) . ' AND pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'));		if (is_array($workspaces) && count($workspaces) != 0 && false !== ($rec = $GLOBALS['BE_USER']->checkWorkspace($workspaces[0])))	{			return ($rec['_ACCESS'] == 'owner' || $rec['_ACCESS'] == 'admin');		}		return false;	}}/** * This class contains Typo3 callback functions. Class name must start from <code>user_</code> thus we use a separate class. * */class user_SC_mod_user_ws_workspaceForms {	/**	 * Callback function to blind user and group accounts. Used as <code>itemsProcFunc</code> in <code>$TCA</code>.	 *	 * @param	array		$conf	Configuration array. The following elements are set:<ul><li>items - initial set of items (empty in our case)</li><li>config - field config from <code>$TCA</code></li><li>TSconfig - this function name</li><li>table - table name</li><li>row - record row (???)</li><li>field - field name</li></ul>	 * @param	object		$tceforms	<code>t3lib_div::TCEforms</code> object	 * @return	void	 */	function processUserAndGroups($conf, $tceforms) {			// Get usernames and groupnames		$be_group_Array = t3lib_BEfunc::getListGroupNames('title,uid');		$groupArray = array_keys($be_group_Array);		$be_user_Array = t3lib_BEfunc::getUserNames();		$be_user_Array = t3lib_BEfunc::blindUserNames($be_user_Array,$groupArray,1);		// users		$title = $GLOBALS['LANG']->sL($GLOBALS['TCA']['be_users']['ctrl']['title']);		foreach ($be_user_Array as $uid => $user) {			$conf['items'][] = array(				$user['username'] . ' (' . $title . ')',				'be_users_' . $user['uid'],				t3lib_iconWorks::getIcon('be_users', $user)			);		}		// Process groups only if necessary -- save time!		if (strstr($conf['config']['mod_ws_allowed'], 'be_groups')) {			// groups			$be_group_Array = $be_group_Array_o = t3lib_BEfunc::getGroupNames();			$be_group_Array = t3lib_BEfunc::blindGroupNames($be_group_Array_o,$groupArray,1);			$title = $GLOBALS['LANG']->sL($GLOBALS['TCA']['be_groups']['ctrl']['title']);			foreach ($be_group_Array as $uid => $group) {				$conf['items'][] = array(					$group['title'] . ' (' . $title . ')',					'be_groups_' . $group['uid'],					t3lib_iconWorks::getIcon('be_groups', $user)				);			}		}	}}// Include extension?if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/workspaceforms.php'])	{	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/workspaceforms.php']);}// Make instance:$SOBE = t3lib_div::makeInstance('SC_mod_user_ws_workspaceForms');$SOBE->init();$SOBE->main();$SOBE->printContent();?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -