Ejemplo n.º 1
0
    /**
     * Process editing of a TO for renderTO() function
     *
     * @param	array		Data Structure. Passed by reference; The sheets found inside will be resolved if found!
     * @param	array		TO record row
     * @param	string		Template file path (absolute)
     * @param   integer		Process the headerPart instead of the bodyPart
     * @return	array		Array with two keys (0/1) with a) content and b) currentMappingInfo which is retrieved inside (currentMappingInfo will be different based on whether "head" or "body" content is "mapped")
     * @see renderTO()
     */
    function renderTO_editProcessing(&$dataStruct, $row, $theFile, $headerPart = 0)
    {
        $msg = array();
        // Converting GPvars into a "cmd" value:
        $cmd = '';
        if (t3lib_div::GPvar('_reload_from')) {
            // Reverting to old values in TO
            $cmd = 'reload_from';
        } elseif (t3lib_div::GPvar('_clear')) {
            // Resetting mapping
            $cmd = 'clear';
        } elseif (t3lib_div::GPvar('_save_data_mapping')) {
            // Saving to Session
            $cmd = 'save_data_mapping';
        } elseif (t3lib_div::GPvar('_save_to') || t3lib_div::GPvar('_save_to_return')) {
            // Saving to Template Object
            $cmd = 'save_to';
        }
        // Getting data from tmplobj
        $templatemapping = unserialize($row['templatemapping']);
        if (!is_array($templatemapping)) {
            $templatemapping = array();
        }
        // If that array contains sheets, then traverse them:
        if (is_array($dataStruct['sheets'])) {
            $dSheets = t3lib_div::resolveAllSheetsInDS($dataStruct);
            $dataStruct = array('ROOT' => array('tx_templavoila' => array('title' => 'ROOT of MultiTemplate', 'description' => 'Select the ROOT container for this template project. Probably just select a body-tag or some other HTML element which encapsulates ALL sub templates!'), 'type' => 'array', 'el' => array()));
            foreach ($dSheets['sheets'] as $nKey => $lDS) {
                if (is_array($lDS['ROOT'])) {
                    $dataStruct['ROOT']['el'][$nKey] = $lDS['ROOT'];
                }
            }
        }
        // Get session data:
        $sesDat = $GLOBALS['BE_USER']->getSessionData($this->MCONF['name'] . '_mappingInfo');
        // Set current mapping info arrays:
        $currentMappingInfo_head = is_array($sesDat['currentMappingInfo_head']) ? $sesDat['currentMappingInfo_head'] : array();
        $currentMappingInfo = is_array($sesDat['currentMappingInfo']) ? $sesDat['currentMappingInfo'] : array();
        $this->cleanUpMappingInfoAccordingToDS($currentMappingInfo, $dataStruct);
        // Perform processing for head
        // GPvars, incoming data
        $checkboxElement = t3lib_div::GPvar('checkboxElement', 1);
        $addBodyTag = t3lib_div::GPvar('addBodyTag');
        // Update session data:
        if ($cmd == 'reload_from' || $cmd == 'clear') {
            $currentMappingInfo_head = is_array($templatemapping['MappingInfo_head']) && $cmd != 'clear' ? $templatemapping['MappingInfo_head'] : array();
            $sesDat['currentMappingInfo_head'] = $currentMappingInfo_head;
            $GLOBALS['BE_USER']->setAndSaveSessionData($this->MCONF['name'] . '_mappingInfo', $sesDat);
        } else {
            if ($cmd == 'save_data_mapping' || $cmd == 'save_to') {
                $sesDat['currentMappingInfo_head'] = $currentMappingInfo_head = array('headElementPaths' => $checkboxElement, 'addBodyTag' => $addBodyTag ? 1 : 0);
                $GLOBALS['BE_USER']->setAndSaveSessionData($this->MCONF['name'] . '_mappingInfo', $sesDat);
            }
        }
        // Perform processing for  body
        // GPvars, incoming data
        $inputData = t3lib_div::GPvar('dataMappingForm', 1);
        // Update session data:
        if ($cmd == 'reload_from' || $cmd == 'clear') {
            $currentMappingInfo = is_array($templatemapping['MappingInfo']) && $cmd != 'clear' ? $templatemapping['MappingInfo'] : array();
            $this->cleanUpMappingInfoAccordingToDS($currentMappingInfo, $dataStruct);
            $sesDat['currentMappingInfo'] = $currentMappingInfo;
            $sesDat['dataStruct'] = $dataStruct;
            $GLOBALS['BE_USER']->setAndSaveSessionData($this->MCONF['name'] . '_mappingInfo', $sesDat);
        } else {
            if ($cmd == 'save_data_mapping' && is_array($inputData)) {
                $sesDat['currentMappingInfo'] = $currentMappingInfo = t3lib_div::array_merge_recursive_overrule($currentMappingInfo, $inputData);
                $sesDat['dataStruct'] = $dataStruct;
                // Adding data structure to session data so that the PREVIEW window can access the DS easily...
                $GLOBALS['BE_USER']->setAndSaveSessionData($this->MCONF['name'] . '_mappingInfo', $sesDat);
            }
        }
        // SAVE to template object
        if ($cmd == 'save_to') {
            $dataArr = array();
            // Set content, either for header or body:
            $templatemapping['MappingInfo_head'] = $currentMappingInfo_head;
            $templatemapping['MappingInfo'] = $currentMappingInfo;
            // Getting cached data:
            reset($dataStruct);
            // Init; read file, init objects:
            $fileContent = t3lib_div::getUrl($theFile);
            $htmlParse = t3lib_div::makeInstance('t3lib_parsehtml');
            $this->markupObj = t3lib_div::makeInstance('tx_templavoila_htmlmarkup');
            // Fix relative paths in source:
            $relPathFix = dirname(substr($theFile, strlen(PATH_site))) . '/';
            $uniqueMarker = uniqid('###') . '###';
            $fileContent = $htmlParse->prefixResourcePath($relPathFix, $fileContent, array('A' => $uniqueMarker));
            $fileContent = $this->fixPrefixForLinks($relPathFix, $fileContent, $uniqueMarker);
            // Get BODY content for caching:
            $contentSplittedByMapping = $this->markupObj->splitContentToMappingInfo($fileContent, $currentMappingInfo);
            $templatemapping['MappingData_cached'] = $contentSplittedByMapping['sub']['ROOT'];
            // Get HEAD content for caching:
            list($html_header) = $this->markupObj->htmlParse->getAllParts($htmlParse->splitIntoBlock('head', $fileContent), 1, 0);
            $this->markupObj->tags = $this->head_markUpTags;
            // Set up the markupObject to process only header-section tags:
            $h_currentMappingInfo = array();
            if (is_array($currentMappingInfo_head['headElementPaths'])) {
                foreach ($currentMappingInfo_head['headElementPaths'] as $kk => $vv) {
                    $h_currentMappingInfo['el_' . $kk]['MAP_EL'] = $vv;
                }
            }
            $contentSplittedByMapping = $this->markupObj->splitContentToMappingInfo($html_header, $h_currentMappingInfo);
            $templatemapping['MappingData_head_cached'] = $contentSplittedByMapping;
            // Get <body> tag:
            $reg = '';
            //#
            //### Mansoor Ahmad - change because of PHP5.3
            //#
            //eregi('<body[^>]*>',$fileContent,$reg);
            preg_match('/<body[^>]*>/i', $fileContent, $reg);
            $templatemapping['BodyTag_cached'] = $currentMappingInfo_head['addBodyTag'] ? $reg[0] : '';
            $TOuid = t3lib_BEfunc::wsMapId('tx_templavoila_tmplobj', $row['uid']);
            $dataArr['tx_templavoila_tmplobj'][$TOuid]['templatemapping'] = serialize($templatemapping);
            $dataArr['tx_templavoila_tmplobj'][$TOuid]['fileref_mtime'] = @filemtime($theFile);
            $dataArr['tx_templavoila_tmplobj'][$TOuid]['fileref_md5'] = @md5_file($theFile);
            $tce = t3lib_div::makeInstance('t3lib_TCEmain');
            $tce->stripslashes_values = 0;
            $tce->start($dataArr, array());
            $tce->process_datamap();
            unset($tce);
            $msg[] = $GLOBALS['LANG']->getLL('msgMappingSaved');
            $row = t3lib_BEfunc::getRecordWSOL('tx_templavoila_tmplobj', $this->displayUid);
            $templatemapping = unserialize($row['templatemapping']);
            if (t3lib_div::GPvar('_save_to_return')) {
                header('Location: ' . t3lib_div::locationHeaderUrl($this->returnUrl));
                exit;
            }
        }
        // Making the menu
        $menuItems = array();
        $menuItems[] = '<input type="submit" name="_clear" value="Clear all" title="Clears all mapping information currently set." />';
        // Make either "Preview" button (body) or "Set" button (header)
        if ($headerPart) {
            // Header:
            $menuItems[] = '<input type="submit" name="_save_data_mapping" value="Set" title="Will update session data with current settings." />';
        } else {
            // Body:
            $menuItems[] = '<input type="submit" name="_preview" value="Preview" title="Will merge sample content into the template according to the current mapping information." />';
        }
        $menuItems[] = '<input type="submit" name="_save_to" value="Save" title="Saving all mapping data into the Template Object." />';
        if ($this->returnUrl) {
            $menuItems[] = '<input type="submit" name="_save_to_return" value="Save and Return" title="Saving all mapping data into the Template Object and return." />';
        }
        // If a difference is detected...:
        if (serialize($templatemapping['MappingInfo_head']) != serialize($currentMappingInfo_head) || serialize($templatemapping['MappingInfo']) != serialize($currentMappingInfo)) {
            $menuItems[] = '<input type="submit" name="_reload_from" value="Revert" title="' . sprintf('Reverting %s mapping data to original data in the Template Object.', $headerPart ? 'HEAD' : 'BODY') . '" />';
            $msg[] = 'The current mapping information is different from the mapping information in the Template Object';
        }
        $content = '

			<!--
				Menu for saving Template Objects
			-->
			<table border="0" cellpadding="2" cellspacing="2" id="c-toMenu">
				<tr class="bgColor5">
					<td>' . implode('</td>
					<td>', $menuItems) . '</td>
				</tr>
			</table>
		';
        // Making messages:
        foreach ($msg as $msgStr) {
            $content .= '
			<p><img src="' . $GLOBALS['BACK_PATH'] . 'gfx/icon_note.gif" width="18" height="16" border="0" align="top" class="absmiddle" alt="" /><strong>' . htmlspecialchars($msgStr) . '</strong></p>';
        }
        return array($content, $headerPart ? $currentMappingInfo_head : $currentMappingInfo);
    }
Ejemplo n.º 2
0
 /**
  * Substition of softreference tokens
  *
  * @param	string		Content of field with soft reference tokens in.
  * @param	array		Soft reference configurations
  * @param	string		Table for which the processing occurs
  * @param	string		UID of record from table
  * @return	string		The input content with tokens substituted according to entries in softRefCfgs
  */
 function processSoftReferences_substTokens($tokenizedContent, $softRefCfgs, $table, $uid)
 {
     // traverse each softref type for this field:
     foreach ($softRefCfgs as $cfg) {
         // Get token ID:
         $tokenID = $cfg['subst']['tokenID'];
         // Default is current token value:
         $insertValue = $cfg['subst']['tokenValue'];
         // Based on mode:
         switch ((string) $this->softrefCfg[$tokenID]['mode']) {
             case 'exclude':
                 // Exclude is a simple passthrough of the value
                 break;
             case 'editable':
                 // Editable always picks up the value from this input array:
                 $insertValue = $this->softrefInputValues[$tokenID];
                 break;
             default:
                 // Mapping IDs/creating files: Based on type, look up new value:
                 switch ((string) $cfg['subst']['type']) {
                     case 'db':
                     default:
                         // Trying to map database element if found in the mapID array:
                         list($tempTable, $tempUid) = explode(':', $cfg['subst']['recordRef']);
                         if (isset($this->import_mapId[$tempTable][$tempUid])) {
                             $insertValue = t3lib_BEfunc::wsMapId($tempTable, $this->import_mapId[$tempTable][$tempUid]);
                             // Look if reference is to a page and the original token value was NOT an integer - then we assume is was an alias and try to look up the new one!
                             if ($tempTable === 'pages' && !t3lib_div::testInt($cfg['subst']['tokenValue'])) {
                                 $recWithUniqueValue = t3lib_BEfunc::getRecord($tempTable, $insertValue, 'alias');
                                 if ($recWithUniqueValue['alias']) {
                                     $insertValue = $recWithUniqueValue['alias'];
                                 }
                             }
                         }
                         break;
                         break;
                     case 'file':
                         // Create / Overwrite file:
                         $insertValue = $this->processSoftReferences_saveFile($cfg['subst']['relFileName'], $cfg, $table, $uid);
                         break;
                 }
                 break;
         }
         // Finally, swap the soft reference token in tokenized content with the insert value:
         $tokenizedContent = str_replace('{softref:' . $tokenID . '}', $insertValue, $tokenizedContent);
     }
     return $tokenizedContent;
 }
 /**
  * Executing dbAnalysisStore
  * This will save MM relations for new records but is executed after records are created because we need to know the ID of them
  *
  * @return	void
  */
 function dbAnalysisStoreExec()
 {
     foreach ($this->dbAnalysisStore as $action) {
         $id = t3lib_BEfunc::wsMapId($action[4], t3lib_div::testInt($action[2]) ? $action[2] : $this->substNEWwithIDs[$action[2]]);
         if ($id) {
             $action[0]->writeMM($action[1], $id, $action[3]);
         }
     }
 }
Ejemplo n.º 4
0
	/**
	 * Step 3: Begin template mapping
	 *
	 * @return	void
	 */
	function wizard_step3()	{

			// Save session data with filename:
		$cfg = t3lib_div::_POST('CFG');
		if (isset($cfg['sitetitle']))	{
			$this->wizardData['sitetitle'] = trim($cfg['sitetitle']);
		}
		if (isset($cfg['siteurl']))	{
			$this->wizardData['siteurl'] = trim($cfg['siteurl']);
		}
		if (isset($cfg['username']))	{
			$this->wizardData['username'] = trim($cfg['username']);
		}

			// If the create-site button WAS clicked:
		if (t3lib_div::_POST('_create_site'))	{

				// Show selected template file:
			if ($this->wizardData['file'] && $this->wizardData['sitetitle'] && $this->wizardData['username'])	{

					// DO import:
				$import = $this->getImportObj();
				if (isset($this->modTSconfig['properties']['newTvSiteFile'])) {
					$inFile = t3lib_div::getFileAbsFileName($this->modTSconfig['properties']['newTVsiteTemplate']);
				} else {
					$inFile = t3lib_extMgm::extPath('templavoila') . 'mod2/new_tv_site.xml';
				}
				if (@is_file($inFile) && $import->loadFile($inFile,1))	{

					$import->importData($this->importPageUid);

						// Update various fields (the index values, eg. the "1" in "$import->import_mapId['pages'][1]]..." are the UIDs of the original records from the import file!)
					$data = array();
					$data['pages'][t3lib_BEfunc::wsMapId('pages',$import->import_mapId['pages'][1])]['title'] = $this->wizardData['sitetitle'];
					$data['sys_template'][t3lib_BEfunc::wsMapId('sys_template',$import->import_mapId['sys_template'][1])]['title'] = $GLOBALS['LANG']->getLL('newsitewizard_maintemplate', 1) . ' ' . $this->wizardData['sitetitle'];
					$data['sys_template'][t3lib_BEfunc::wsMapId('sys_template',$import->import_mapId['sys_template'][1])]['sitetitle'] = $this->wizardData['sitetitle'];
					$data['tx_templavoila_tmplobj'][t3lib_BEfunc::wsMapId('tx_templavoila_tmplobj',$import->import_mapId['tx_templavoila_tmplobj'][1])]['fileref'] = $this->wizardData['file'];
					$data['tx_templavoila_tmplobj'][t3lib_BEfunc::wsMapId('tx_templavoila_tmplobj',$import->import_mapId['tx_templavoila_tmplobj'][1])]['templatemapping'] = serialize(
						array(
							'MappingInfo' => array(
								'ROOT' => array(
									'MAP_EL' => 'body[1]/INNER'
								)
							),
							'MappingInfo_head' => array(
								'headElementPaths' => array('link[1]','link[2]','link[3]','style[1]','style[2]','style[3]'),
								'addBodyTag' => 1
							)
						)
					);

						// Update user settings
					$newUserID = t3lib_BEfunc::wsMapId('be_users',$import->import_mapId['be_users'][2]);
					$newGroupID = t3lib_BEfunc::wsMapId('be_groups',$import->import_mapId['be_groups'][1]);

					$data['be_users'][$newUserID]['username'] = $this->wizardData['username'];
					$data['be_groups'][$newGroupID]['title'] = $this->wizardData['username'];

					foreach($import->import_mapId['pages'] as $newID)	{
						$data['pages'][$newID]['perms_userid'] = $newUserID;
						$data['pages'][$newID]['perms_groupid'] = $newGroupID;
					}

						// Set URL if applicable:
					if (strlen($this->wizardData['siteurl']))	{
						$data['sys_domain']['NEW']['pid'] = t3lib_BEfunc::wsMapId('pages',$import->import_mapId['pages'][1]);
						$data['sys_domain']['NEW']['domainName'] = $this->wizardData['siteurl'];
					}

						// Execute changes:
					$tce = t3lib_div::makeInstance('t3lib_TCEmain');
					$tce->stripslashes_values = 0;
					$tce->dontProcessTransformations = 1;
					$tce->start($data,Array());
					$tce->process_datamap();

						// Setting environment:
					$this->wizardData['rootPageId'] = $import->import_mapId['pages'][1];
					$this->wizardData['templateObjectId'] = t3lib_BEfunc::wsMapId('tx_templavoila_tmplobj',$import->import_mapId['tx_templavoila_tmplobj'][1]);
					$this->wizardData['typoScriptTemplateID'] = t3lib_BEfunc::wsMapId('sys_template',$import->import_mapId['sys_template'][1]);

					t3lib_BEfunc::setUpdateSignal('updatePageTree');

					$outputString .= $GLOBALS['LANG']->getLL('newsitewizard_maintemplate', 1) . '<hr/>';
				}
			} else {
				$outputString .= $GLOBALS['LANG']->getLL('newsitewizard_maintemplate', 1);
			}
		}

			// If a template Object id was found, continue with mapping:
		if ($this->wizardData['templateObjectId'])	{
			$url = '../cm1/index.php?table=tx_templavoila_tmplobj&uid='.$this->wizardData['templateObjectId'].'&SET[selectHeaderContent]=0&_reload_from=1&id=' . $this->id . '&returnUrl='.rawurlencode('../mod2/index.php?SET[wiz_step]=4');

			$outputString.= $GLOBALS['LANG']->getLL('newsitewizard_step3ready') . '
				<br/>
				<br/>
				<img src="mapbody_animation.gif" style="border: 2px black solid;" alt=""><br/>
				<br/>
				<br/><input type="submit" value="' . $GLOBALS['LANG']->getLL('newsitewizard_startmapping', 1) . '" onclick="'.htmlspecialchars('document.location=\''.$url.'\'; return false;').'" />
			';
		}

			// Add output:
		$this->content.= $this->doc->section($GLOBALS['LANG']->getLL('newsitewizard_beginmapping', 1), $outputString, 0, 1);
	}
Ejemplo n.º 5
0
	/**
	 * Process editing of a TO for renderTO() function
	 *
	 * @param	array		Data Structure. Passed by reference; The sheets found inside will be resolved if found!
	 * @param	array		TO record row
	 * @param	string		Template file path (absolute)
	 * @param   integer		Process the headerPart instead of the bodyPart
	 * @return	array		Array with two keys (0/1) with a) content and b) currentMappingInfo which is retrieved inside (currentMappingInfo will be different based on whether "head" or "body" content is "mapped")
	 * @see renderTO()
	 */
	function renderTO_editProcessing(&$dataStruct,$row,$theFile, $headerPart = 0)	{
		$msg = array();

			// Converting GPvars into a "cmd" value:
		$cmd = '';
		if (t3lib_div::_GP('_reload_from'))	{	// Reverting to old values in TO
			$cmd = 'reload_from';
		} elseif (t3lib_div::_GP('_clear'))	{	// Resetting mapping
			$cmd = 'clear';
		} elseif (t3lib_div::_GP('_save_data_mapping'))	{	// Saving to Session
			$cmd = 'save_data_mapping';
		} elseif (t3lib_div::_GP('_save_to') || t3lib_div::_GP('_save_to_return'))	{	// Saving to Template Object
			$cmd = 'save_to';
		}

			// Getting data from tmplobj
		$templatemapping = unserialize($row['templatemapping']);
		if (!is_array($templatemapping))	$templatemapping=array();

			// If that array contains sheets, then traverse them:
		if (is_array($dataStruct['sheets']))	{
			$dSheets = t3lib_div::resolveAllSheetsInDS($dataStruct);
			$dataStruct=array(
				'ROOT' => array (
					'tx_templavoila' => array (
						'title' => $GLOBALS['LANG']->getLL('rootMultiTemplate_title'),
						'description' => $GLOBALS['LANG']->getLL('rootMultiTemplate_description'),
					),
					'type' => 'array',
					'el' => array()
				)
			);
			foreach($dSheets['sheets'] as $nKey => $lDS)	{
				if (is_array($lDS['ROOT']))	{
					$dataStruct['ROOT']['el'][$nKey] = $lDS['ROOT'];
				}
			}
		}

			// Get session data:
		$sesDat = $GLOBALS['BE_USER']->getSessionData($this->sessionKey);

			// Set current mapping info arrays:
		$currentMappingInfo_head = is_array($sesDat['currentMappingInfo_head']) ? $sesDat['currentMappingInfo_head'] : array();
		$currentMappingInfo = is_array($sesDat['currentMappingInfo']) ? $sesDat['currentMappingInfo'] : array();
		$this->cleanUpMappingInfoAccordingToDS($currentMappingInfo,$dataStruct);

		// Perform processing for head
			// GPvars, incoming data
		$checkboxElement = t3lib_div::_GP('checkboxElement',1);
		$addBodyTag = t3lib_div::_GP('addBodyTag');

			// Update session data:
		if ($cmd=='reload_from' || $cmd=='clear')	{
			$currentMappingInfo_head = is_array($templatemapping['MappingInfo_head'])&&$cmd!='clear' ? $templatemapping['MappingInfo_head'] : array();
			$sesDat['currentMappingInfo_head'] = $currentMappingInfo_head;
			$GLOBALS['BE_USER']->setAndSaveSessionData($this->sessionKey, $sesDat);
		} else {
			if ($cmd=='save_data_mapping' || $cmd=='save_to')	{
				$sesDat['currentMappingInfo_head'] = $currentMappingInfo_head = array(
					'headElementPaths' => $checkboxElement,
					'addBodyTag' => $addBodyTag?1:0
				);
				$GLOBALS['BE_USER']->setAndSaveSessionData($this->sessionKey, $sesDat);
			}
		}

		// Perform processing for  body
			// GPvars, incoming data
		$inputData = t3lib_div::_GP('dataMappingForm',1);

			// Update session data:
		if ($cmd=='reload_from' || $cmd=='clear')	{
			$currentMappingInfo = is_array($templatemapping['MappingInfo'])&&$cmd!='clear' ? $templatemapping['MappingInfo'] : array();
			$this->cleanUpMappingInfoAccordingToDS($currentMappingInfo,$dataStruct);
			$sesDat['currentMappingInfo'] = $currentMappingInfo;
			$sesDat['dataStruct'] = $dataStruct;
			$GLOBALS['BE_USER']->setAndSaveSessionData($this->sessionKey, $sesDat);
		} else {
			if ($cmd=='save_data_mapping' && is_array($inputData))	{
				$sesDat['currentMappingInfo'] = $currentMappingInfo = $this->array_merge_recursive_overrule($currentMappingInfo,$inputData);
				$sesDat['dataStruct'] = $dataStruct;		// Adding data structure to session data so that the PREVIEW window can access the DS easily...
				$GLOBALS['BE_USER']->setAndSaveSessionData($this->sessionKey, $sesDat);
			}
		}

			// SAVE to template object
		if ($cmd=='save_to')	{
			$dataArr=array();

				// Set content, either for header or body:
			$templatemapping['MappingInfo_head'] = $currentMappingInfo_head;
			$templatemapping['MappingInfo'] = $currentMappingInfo;

				// Getting cached data:
			reset($dataStruct);
				// Init; read file, init objects:
			$fileContent = t3lib_div::getUrl($theFile);
			$htmlParse = t3lib_div::makeInstance('t3lib_parsehtml');
			$this->markupObj = t3lib_div::makeInstance('tx_templavoila_htmlmarkup');

				// Fix relative paths in source:
			$relPathFix=dirname(substr($theFile,strlen(PATH_site))).'/';
			$uniqueMarker = uniqid('###') . '###';
			$fileContent = $htmlParse->prefixResourcePath($relPathFix,$fileContent, array('A' => $uniqueMarker));
			$fileContent = $this->fixPrefixForLinks($relPathFix, $fileContent, $uniqueMarker);


				// Get BODY content for caching:
			$contentSplittedByMapping=$this->markupObj->splitContentToMappingInfo($fileContent,$currentMappingInfo);
			$templatemapping['MappingData_cached'] = $contentSplittedByMapping['sub']['ROOT'];

				// Get HEAD content for caching:
			list($html_header) =  $this->markupObj->htmlParse->getAllParts($htmlParse->splitIntoBlock('head',$fileContent),1,0);
			$this->markupObj->tags = $this->head_markUpTags;	// Set up the markupObject to process only header-section tags:

			$h_currentMappingInfo=array();
			if (is_array($currentMappingInfo_head['headElementPaths']))	{
				foreach($currentMappingInfo_head['headElementPaths'] as $kk => $vv)	{
					$h_currentMappingInfo['el_'.$kk]['MAP_EL'] = $vv;
				}
			}

			$contentSplittedByMapping = $this->markupObj->splitContentToMappingInfo($html_header,$h_currentMappingInfo);
			$templatemapping['MappingData_head_cached'] = $contentSplittedByMapping;

				// Get <body> tag:
			$reg='';
			preg_match('/<body[^>]*>/i',$fileContent,$reg);
			$templatemapping['BodyTag_cached'] = $currentMappingInfo_head['addBodyTag'] ? $reg[0] : '';

			$TOuid = t3lib_BEfunc::wsMapId('tx_templavoila_tmplobj',$row['uid']);
			$dataArr['tx_templavoila_tmplobj'][$TOuid]['templatemapping'] = serialize($templatemapping);
			$dataArr['tx_templavoila_tmplobj'][$TOuid]['fileref_mtime'] = @filemtime($theFile);
			$dataArr['tx_templavoila_tmplobj'][$TOuid]['fileref_md5'] = @md5_file($theFile);

			$tce = t3lib_div::makeInstance('t3lib_TCEmain');
			$tce->stripslashes_values=0;
			$tce->start($dataArr,array());
			$tce->process_datamap();
			unset($tce);
			$flashMessage = t3lib_div::makeInstance(
				't3lib_FlashMessage',
				$GLOBALS['LANG']->getLL('msgMappingSaved'),
				'',
				t3lib_FlashMessage::OK
			);
			$msg[] .= $flashMessage->render();
			$row = t3lib_BEfunc::getRecordWSOL('tx_templavoila_tmplobj',$this->displayUid);
			$templatemapping = unserialize($row['templatemapping']);

			if (t3lib_div::_GP('_save_to_return'))	{
				header('Location: '.t3lib_div::locationHeaderUrl($this->returnUrl));
				exit;
			}
		}

			// Making the menu
		$menuItems=array();
		$menuItems[]='<input type="submit" name="_clear" value="' . $GLOBALS['LANG']->getLL('buttonClearAll') . '" title="' . $GLOBALS['LANG']->getLL('buttonClearAllMappingTitle') . '" />';

			// Make either "Preview" button (body) or "Set" button (header)
		if ($headerPart)	{	// Header:
			$menuItems[] = '<input type="submit" name="_save_data_mapping" value="' . $GLOBALS['LANG']->getLL('buttonSet') . '" title="' . $GLOBALS['LANG']->getLL('buttonSetTitle') . '" />';
		} else {	// Body:
			$menuItems[] = '<input type="submit" name="_preview" value="' . $GLOBALS['LANG']->getLL('buttonPreview') . '" title="' . $GLOBALS['LANG']->getLL('buttonPreviewMappingTitle') . '" />';
		}

		$menuItems[]='<input type="submit" name="_save_to" value="' . $GLOBALS['LANG']->getLL('buttonSave') . '" title="' . $GLOBALS['LANG']->getLL('buttonSaveTOTitle') . '" />';

		if ($this->returnUrl)	{
			$menuItems[]='<input type="submit" name="_save_to_return" value="' . $GLOBALS['LANG']->getLL('buttonSaveAndReturn') . '" title="' . $GLOBALS['LANG']->getLL('buttonSaveAndReturnTitle') . '" />';
		}

			// If a difference is detected...:
		if (
				(serialize($templatemapping['MappingInfo_head']) != serialize($currentMappingInfo_head))	||
				(serialize($templatemapping['MappingInfo']) != serialize($currentMappingInfo))
			)	{
			$menuItems[]='<input type="submit" name="_reload_from" value="' . $GLOBALS['LANG']->getLL('buttonRevert') . '" title="'.sprintf($GLOBALS['LANG']->getLL('buttonRevertTitle'), $headerPart ? 'HEAD' : 'BODY') . '" />';

			$flashMessage = t3lib_div::makeInstance(
				't3lib_FlashMessage',
				$GLOBALS['LANG']->getLL('msgMappingIsDifferent'),
				'',
				t3lib_FlashMessage::INFO
			);
			$msg[] .= $flashMessage->render();
		}

		$content = '

			<!--
				Menu for saving Template Objects
			-->
			<table border="0" cellpadding="2" cellspacing="2" id="c-toMenu">
				<tr class="bgColor5">
					<td>'.implode('</td>
					<td>',$menuItems).'</td>
				</tr>
			</table>
		';

			// @todo - replace with FlashMessage Queue
		$content .= implode('', $msg);
		return array($content, $headerPart ? $currentMappingInfo_head : $currentMappingInfo);
	}
 /**
  * Submit incoming content as translated language to database. Must match what is available in $accum.
  *
  * @param array $accum Translation configuration
  * @param array $inputArray Array with incoming translation. Must match what is found in $accum
  * @return mixed False if error - else flexFormDiffArray (if $inputArray was an array and processing was performed.)
  */
 function _submitContentAsTranslatedLanguageAndGetFlexFormDiff($accum, $inputArray)
 {
     if (is_array($inputArray)) {
         // Initialize:
         /** @var $flexToolObj t3lib_flexformtools */
         $flexToolObj = t3lib_div::makeInstance('t3lib_flexformtools');
         $TCEmain_data = array();
         $TCEmain_cmd = array();
         $_flexFormDiffArray = array();
         // Traverse:
         foreach ($accum as $pId => $page) {
             foreach ($accum[$pId]['items'] as $table => $elements) {
                 foreach ($elements as $elementUid => $data) {
                     if (is_array($data['fields'])) {
                         foreach ($data['fields'] as $key => $tData) {
                             if (is_array($tData) && isset($inputArray[$table][$elementUid][$key])) {
                                 list($Ttable, $TuidString, $Tfield, $Tpath) = explode(':', $key);
                                 list($Tuid, $Tlang, $TdefRecord) = explode('/', $TuidString);
                                 if (!$this->createTranslationAlsoIfEmpty && $inputArray[$table][$elementUid][$key] == '' && $Tuid == 'NEW') {
                                     //if data is empty do not save it
                                     unset($inputArray[$table][$elementUid][$key]);
                                     continue;
                                 }
                                 // If new element is required, we prepare for localization
                                 if ($Tuid === 'NEW') {
                                     //print "\nNEW\n";
                                     $TCEmain_cmd[$table][$elementUid]['localize'] = $Tlang;
                                 }
                                 // If FlexForm, we set value in special way:
                                 if ($Tpath) {
                                     if (!is_array($TCEmain_data[$Ttable][$TuidString][$Tfield])) {
                                         $TCEmain_data[$Ttable][$TuidString][$Tfield] = array();
                                     }
                                     //TCEMAINDATA is passed as reference here:
                                     $flexToolObj->setArrayValueByPath($Tpath, $TCEmain_data[$Ttable][$TuidString][$Tfield], $inputArray[$table][$elementUid][$key]);
                                     $_flexFormDiffArray[$key] = array('translated' => $inputArray[$table][$elementUid][$key], 'default' => $tData['defaultValue']);
                                 } else {
                                     $TCEmain_data[$Ttable][$TuidString][$Tfield] = $inputArray[$table][$elementUid][$key];
                                 }
                                 unset($inputArray[$table][$elementUid][$key]);
                                 // Unsetting so in the end we can see if $inputArray was fully processed.
                             } else {
                                 //debug($tData,'fields not set for: '.$elementUid.'-'.$key);
                                 //debug($inputArray[$table],'inputarray');
                             }
                         }
                         if (is_array($inputArray[$table][$elementUid]) && !count($inputArray[$table][$elementUid])) {
                             unset($inputArray[$table][$elementUid]);
                             // Unsetting so in the end we can see if $inputArray was fully processed.
                         }
                     }
                 }
                 if (is_array($inputArray[$table]) && !count($inputArray[$table])) {
                     unset($inputArray[$table]);
                     // Unsetting so in the end we can see if $inputArray was fully processed.
                 }
             }
         }
         //debug($TCEmain_cmd,'$TCEmain_cmd');
         //debug($TCEmain_data,'$TCEmain_data');
         self::$targetLanguageID = $Tlang;
         // Execute CMD array: Localizing records:
         /** @var $tce t3lib_TCEmain */
         $tce = t3lib_div::makeInstance('t3lib_TCEmain');
         if ($this->extensionConfiguration['enable_neverHideAtCopy'] == 1) {
             $tce->neverHideAtCopy = TRUE;
         }
         $tce->stripslashes_values = FALSE;
         if (count($TCEmain_cmd)) {
             $tce->start(array(), $TCEmain_cmd);
             $tce->process_cmdmap();
             if (count($tce->errorLog)) {
                 debug($tce->errorLog, 'TCEmain localization errors:');
             }
         }
         // Before remapping
         if (TYPO3_DLOG) {
             t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': TCEmain_data before remapping: ' . t3lib_div::arrayToLogString($TCEmain_data), 'l10nmgr');
         }
         // Remapping those elements which are new:
         $this->lastTCEMAINCommandsCount = 0;
         foreach ($TCEmain_data as $table => $items) {
             foreach ($TCEmain_data[$table] as $TuidString => $fields) {
                 list($Tuid, $Tlang, $TdefRecord) = explode('/', $TuidString);
                 $this->lastTCEMAINCommandsCount++;
                 if ($Tuid === 'NEW') {
                     if ($tce->copyMappingArray_merged[$table][$TdefRecord]) {
                         $TCEmain_data[$table][t3lib_BEfunc::wsMapId($table, $tce->copyMappingArray_merged[$table][$TdefRecord])] = $fields;
                     } else {
                         t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': Record "' . $table . ':' . $TdefRecord . '" was NOT localized as it should have been!', 'l10nmgr');
                     }
                     unset($TCEmain_data[$table][$TuidString]);
                 }
             }
         }
         // After remapping
         if (TYPO3_DLOG) {
             t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': TCEmain_data after remapping: ' . t3lib_div::arrayToLogString($TCEmain_data), 'l10nmgr');
         }
         // Now, submitting translation data:
         /** @var $tce t3lib_TCEmain */
         $tce = t3lib_div::makeInstance('t3lib_TCEmain');
         if ($this->extensionConfiguration['enable_neverHideAtCopy'] == 1) {
             $tce->neverHideAtCopy = TRUE;
         }
         $tce->stripslashes_values = FALSE;
         $tce->dontProcessTransformations = TRUE;
         //print_r($TCEmain_data);
         $tce->start($TCEmain_data, array());
         // check has been done previously that there is a backend user which is Admin and also in live workspace
         $tce->process_datamap();
         self::$targetLanguageID = NULL;
         if (count($tce->errorLog)) {
             t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': TCEmain update errors: ' . t3lib_div::arrayToLogString($tce->errorLog), 'l10nmgr');
         }
         if (count($tce->autoVersionIdMap) && count($_flexFormDiffArray)) {
             if (TYPO3_DLOG) {
                 t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': flexFormDiffArry: ' . t3lib_div::arrayToLogString($this->flexFormDiffArray), 'l10nmgr');
             }
             foreach ($_flexFormDiffArray as $key => $value) {
                 list($Ttable, $Tuid, $Trest) = explode(':', $key, 3);
                 if ($tce->autoVersionIdMap[$Ttable][$Tuid]) {
                     $_flexFormDiffArray[$Ttable . ':' . $tce->autoVersionIdMap[$Ttable][$Tuid] . ':' . $Trest] = $_flexFormDiffArray[$key];
                     unset($_flexFormDiffArray[$key]);
                 }
             }
             if (TYPO3_DLOG) {
                 t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': autoVersionIdMap: ' . $tce->autoVersionIdMap, 'l10nmgr');
                 t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': _flexFormDiffArray: ' . t3lib_div::arrayToLogString($_flexFormDiffArray), 'l10nmgr');
             }
         }
         // Should be empty now - or there were more information in the incoming array than there should be!
         if (count($inputArray)) {
             debug($inputArray, 'These fields were ignored since they were not in the configuration:');
         }
         return $_flexFormDiffArray;
     } else {
         return FALSE;
     }
 }
 /**
  * FlexForm call back function, see translationDetails
  *
  * @param   array   $dsArr          Data Structure
  * @param   string  $dataValue      Data value
  * @param   array   $PA             Various stuff in an array
  * @param   string  $structurePath  Path to location in flexform
  * @param   object  $pObj           Reference to parent object
  * @return  void
  */
 function translationDetails_flexFormCallBack($dsArr, $dataValue, $PA, $structurePath, &$pObj)
 {
     // Only take lead from default values (since this is "Inheritance" localization we parse for)
     if (substr($structurePath, -5) == '/vDEF') {
         // So, find translated value:
         $baseStructPath = substr($structurePath, 0, -3);
         $structurePath = $baseStructPath . $this->detailsOutput['ISOcode'];
         $translValue = $pObj->getArrayValueByPath($structurePath, $pObj->traverseFlexFormXMLData_Data);
         // Generate preview values:
         $previewLanguageValues = array();
         foreach ($this->previewLanguages as $prevSysUid) {
             $previewLanguageValues[$prevSysUid] = $pObj->getArrayValueByPath($baseStructPath . $this->sysLanguages[$prevSysUid]['ISOcode'], $pObj->traverseFlexFormXMLData_Data);
         }
         $key = $ffKey = $PA['table'] . ':' . t3lib_BEfunc::wsMapId($PA['table'], $PA['uid']) . ':' . $PA['field'] . ':' . $structurePath;
         $ffKeyOrig = $PA['table'] . ':' . $PA['uid'] . ':' . $PA['field'] . ':' . $structurePath;
         // Now, in case this record has just been created in the workspace the diff-information is still found bound to the UID of the original record. So we will look for that until it has been created for the workspace record:
         if (!is_array($this->flexFormDiff[$ffKey]) && is_array($this->flexFormDiff[$ffKeyOrig])) {
             $ffKey = $ffKeyOrig;
             #	debug('orig...');
         }
         // Look for diff-value inside the XML (new way):
         if ($GLOBALS['TYPO3_CONF_VARS']['BE']['flexFormXMLincludeDiffBase']) {
             $diffDefaultValue = $pObj->getArrayValueByPath($structurePath . '.vDEFbase', $pObj->traverseFlexFormXMLData_Data);
         } else {
             // Set diff-value from l10n-cfg record (deprecated)
             if (is_array($this->flexFormDiff[$ffKey]) && trim($this->flexFormDiff[$ffKey]['translated']) === trim($translValue)) {
                 $diffDefaultValue = $this->flexFormDiff[$ffKey]['default'];
             } else {
                 $diffDefaultValue = '';
             }
         }
         // Add field:
         $this->translationDetails_addField($key, $dsArr['TCEforms'], $dataValue, $translValue, $diffDefaultValue, $previewLanguageValues);
     }
 }
Ejemplo n.º 8
0
    /**
     * Step 3: Begin template mapping
     *
     * @return	void
     */
    function wizard_step3()
    {
        // Save session data with filename:
        $cfg = t3lib_div::_POST('CFG');
        if (isset($cfg['sitetitle'])) {
            $this->wizardData['sitetitle'] = trim($cfg['sitetitle']);
        }
        if (isset($cfg['siteurl'])) {
            $this->wizardData['siteurl'] = trim($cfg['siteurl']);
        }
        if (isset($cfg['username'])) {
            $this->wizardData['username'] = trim($cfg['username']);
        }
        // If the create-site button WAS clicked:
        if (t3lib_div::_POST('_create_site')) {
            // Show selected template file:
            if ($this->wizardData['file'] && $this->wizardData['sitetitle'] && $this->wizardData['username']) {
                // DO import:
                $import = $this->getImportObj();
                $inFile = t3lib_extMgm::extPath('templavoila') . 'mod2/new_tv_site.xml';
                if (@is_file($inFile) && $import->loadFile($inFile, 1)) {
                    $import->importData($this->importPageUid);
                    // Update various fields (the index values, eg. the "1" in "$import->import_mapId['pages'][1]]..." are the UIDs of the original records from the import file!)
                    $data = array();
                    $data['pages'][t3lib_BEfunc::wsMapId('pages', $import->import_mapId['pages'][1])]['title'] = $this->wizardData['sitetitle'];
                    $data['sys_template'][t3lib_BEfunc::wsMapId('sys_template', $import->import_mapId['sys_template'][1])]['title'] = 'Main template: ' . $this->wizardData['sitetitle'];
                    $data['sys_template'][t3lib_BEfunc::wsMapId('sys_template', $import->import_mapId['sys_template'][1])]['sitetitle'] = $this->wizardData['sitetitle'];
                    $data['tx_templavoila_tmplobj'][t3lib_BEfunc::wsMapId('tx_templavoila_tmplobj', $import->import_mapId['tx_templavoila_tmplobj'][1])]['fileref'] = $this->wizardData['file'];
                    $data['tx_templavoila_tmplobj'][t3lib_BEfunc::wsMapId('tx_templavoila_tmplobj', $import->import_mapId['tx_templavoila_tmplobj'][1])]['templatemapping'] = serialize(array('MappingInfo' => array('ROOT' => array('MAP_EL' => 'body[1]/INNER')), 'MappingInfo_head' => array('headElementPaths' => array('link[1]', 'link[2]', 'link[3]', 'style[1]', 'style[2]', 'style[3]'), 'addBodyTag' => 1)));
                    // Update user settings
                    $newUserID = t3lib_BEfunc::wsMapId('be_users', $import->import_mapId['be_users'][2]);
                    $newGroupID = t3lib_BEfunc::wsMapId('be_groups', $import->import_mapId['be_groups'][1]);
                    $data['be_users'][$newUserID]['username'] = $this->wizardData['username'];
                    $data['be_groups'][$newGroupID]['title'] = $this->wizardData['username'];
                    foreach ($import->import_mapId['pages'] as $newID) {
                        $data['pages'][$newID]['perms_userid'] = $newUserID;
                        $data['pages'][$newID]['perms_groupid'] = $newGroupID;
                    }
                    // Set URL if applicable:
                    if (strlen($this->wizardData['siteurl'])) {
                        $data['sys_domain']['NEW']['pid'] = t3lib_BEfunc::wsMapId('pages', $import->import_mapId['pages'][1]);
                        $data['sys_domain']['NEW']['domainName'] = $this->wizardData['siteurl'];
                    }
                    // Execute changes:
                    $tce = t3lib_div::makeInstance('t3lib_TCEmain');
                    $tce->stripslashes_values = 0;
                    $tce->dontProcessTransformations = 1;
                    $tce->start($data, array());
                    $tce->process_datamap();
                    // Setting environment:
                    $this->wizardData['rootPageId'] = $import->import_mapId['pages'][1];
                    $this->wizardData['templateObjectId'] = t3lib_BEfunc::wsMapId('tx_templavoila_tmplobj', $import->import_mapId['tx_templavoila_tmplobj'][1]);
                    $this->wizardData['typoScriptTemplateID'] = t3lib_BEfunc::wsMapId('sys_template', $import->import_mapId['sys_template'][1]);
                    t3lib_BEfunc::getSetUpdateSignal('updatePageTree');
                    $outputString .= 'New site has been created and adapted. <hr/>';
                }
            } else {
                $outputString .= 'Error happened: Either you did not specify a website name or username in the previous form!';
            }
        }
        // If a template Object id was found, continue with mapping:
        if ($this->wizardData['templateObjectId']) {
            $url = '../cm1/index.php?table=tx_templavoila_tmplobj&uid=' . $this->wizardData['templateObjectId'] . '&SET[selectHeaderContent]=0&_reload_from=1&returnUrl=' . rawurlencode('../mod2/index.php?SET[wiz_step]=4');
            $outputString .= '
				You are now ready to point out at which position in the HTML code to insert the TYPO3 generated page content and the main menu. This process is called "mapping".<br/>
				The process of mapping is shown with this little animation. Please study it closely to understand the flow, then click the button below to start the mapping process on your own. Complete the mapping process by pressing "Save and Return".<br/>
				<br/>
				<img src="mapbody_animation.gif" style="border: 2px black solid;" alt=""><br/>
				<br/>
				<br/><input type="submit" value="Start the mapping process" onclick="' . htmlspecialchars('document.location=\'' . $url . '\'; return false;') . '" />
			';
        }
        // Add output:
        $this->content .= $this->doc->section('Step 3: Begin mapping', $outputString, 0, 1);
    }