Index: class.tx_templavoila_extdeveval.php =================================================================== --- class.tx_templavoila_extdeveval.php (revision 27977) +++ class.tx_templavoila_extdeveval.php (working copy) @@ -62,18 +62,18 @@ 2 => 'Flexible Content Element DS', 0 => 'Unspecified DS', ); - - + + // Internal: var $newFlexFormData = array(); - + var $language; - - + + /** * Initialization (none needed) - * + * * @return void */ function init() { @@ -97,7 +97,7 @@ // Look for a selected data structure: $dsIdForConversion = t3lib_div::_GP('dsId'); - + // Select output: if (!$dsIdForConversion) { $output = $this->renderMenuOfDataStructures(); @@ -114,7 +114,7 @@ * @return string HTML content */ function renderMenuOfDataStructures() { - + // Get data structures we should display $arrayOfDS = $this->getDataStructures(); @@ -152,23 +152,6 @@ */ function getDataStructures() { - // Select all Data Structures in the PID and put into an array: - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( - '*', - 'tx_templavoila_datastructure', - 'pid>=0'. - t3lib_BEfunc::deleteClause('tx_templavoila_datastructure'), - '', - 'title' - ); - $dsRecords = array(); - while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - $row['_languageMode'] = $this->DSlanguageMode($row['dataprot']); - if ($row['_languageMode']!='Disabled') { - $dsRecords[$row['scope']][] = $row; - } - } - // Select all static Data Structures and add to array: if (is_array($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'])) { foreach($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'] as $staticDS) { @@ -183,6 +166,23 @@ $dsRecords[$staticDS['scope']][] = $staticDS; } } + } else { + // Select all Data Structures in the PID and put into an array: + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( + '*', + 'tx_templavoila_datastructure', + 'pid>=0'. + t3lib_BEfunc::deleteClause('tx_templavoila_datastructure'), + '', + 'title' + ); + $dsRecords = array(); + while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { + $row['_languageMode'] = $this->DSlanguageMode($row['dataprot']); + if ($row['_languageMode']!='Disabled') { + $dsRecords[$row['scope']][] = $row; + } + } } return $dsRecords; @@ -232,8 +232,8 @@ $DStitle = $row['title']; } } - - // Define which method you should use + + // Define which method you should use if($language == 'Inheritance'){ $traverseMethod = 'traverseFlexFormXMLData_callBackFunction_Inheritance'; } elseif ($language == 'Separate') { @@ -241,13 +241,13 @@ } elseif ($language == 'Disabled') { $traverseMethod = 'traverseFlexFormXMLData_callBackFunction_Disabled'; } - + // If POST, then update in database if(is_array($SET = t3lib_div::_POST('SET'))){ - + if(in_array($SET['ds']['table'], array_keys($TCA))) $setTable = $SET['ds']['table']; - + $setField = $SET['ds']['field']; foreach($SET['content'] as $key => $val){ if($val){ @@ -255,24 +255,24 @@ if($dbRes = $GLOBALS['TYPO3_DB']->sql_query($dbQuery)){ if(mysql_num_rows($dbRes) == 1){ $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($dbRes); - + $this->newFlexFormData = array(); $flexObj = t3lib_div::makeInstance('t3lib_flexformtools'); $flexObj->reNumberIndexesOfSectionData = TRUE; $flexObj->traverseFlexFormXMLData($setTable,$setField,$row,$this,$traverseMethod); - $dbQuery = "UPDATE $setTable + $dbQuery = "UPDATE $setTable SET $setField='".addslashes($flexObj->flexArray2Xml($this->newFlexFormData))."' WHERE uid='".(int) $key."' "; - + if(!$dbRes = $GLOBALS['TYPO3_DB']->sql_query($dbQuery)){ print mysql_error(); - } + } } } - } + } } } - + // First, find all flexform fields where we could find relations to data structures: $fieldsToCheck = array(); foreach($TCA as $table => $tmp) { @@ -303,7 +303,7 @@ if (count($rows)) { foreach($rows as $row) { - + // Set up result array: $this->newFlexFormData = array(); @@ -312,20 +312,20 @@ $flexObj->reNumberIndexesOfSectionData = TRUE; $flexObj->traverseFlexFormXMLData($table,$field,$row,$this,$traverseMethod); - /* + /* debug(t3lib_div::xml2array($row[$field]),'Old: '.$language); debug($this->newFlexFormData,'New: '.$language); debug(array($flexObj->flexArray2Xml($this->newFlexFormData))); - */ - + */ + if(t3lib_div::xml2array($row[$field]) === $this->newFlexFormData){ $checked = NULL; - $bgColor = 'bgColor3'; + $bgColor = 'bgColor3'; } else { $checked = 'checked'; $bgColor = 'bgColor4'; } - + // then add a new line $htmlTABLE .= ' @@ -334,7 +334,7 @@ '.(!empty($row['header']) ? $row['header'] : 'no header').' '; } - + // build the Table $htmlTABLE = ' @@ -379,7 +379,7 @@ $langId = $pathArray[2] ; if(substr($langId,0,1) == 'l'){ if( $PA['lKey'] == $langId ){ - + $langId = substr($langId,1); $oldPattern = array("/vDEF/","/l$langId/"); $newPattern = array("v$langId","lDEF"); @@ -389,28 +389,28 @@ // Just setting value in our own result array, basically replicating the structure: $pObj->setArrayValueByPath($path,$this->newFlexFormData,$data); } - + function traverseFlexFormXMLData_callBackFunction_Disabled($dsArr, $data, $PA, $path, &$pObj) { // Just setting value in our own result array, basically replicating the structure: $pObj->setArrayValueByPath($path."/kqsper",$this->newFlexFormData,$data); debug('TODO'); } - + /** * Call back function for t3lib_flexformtools class - * + * * @param array Data structure for the current value * @param mixed Current value * @param array Additional configuration used in calling function * @param string Path of value in DS structure * @param object Object reference to caller * @return void - */ + */ /*function traverseFlexFormXMLData_callBackFunction($dsArr, $data, $PA, $path, &$pObj) { // Just setting value in our own result array, basically replicating the structure: $pObj->setArrayValueByPath($path."/kqsper",$this->newFlexFormData,$data); debug($this->language); - + }*/ } Index: class.tx_templavoila_handlestaticdatastructures.php =================================================================== --- class.tx_templavoila_handlestaticdatastructures.php (revision 27977) +++ class.tx_templavoila_handlestaticdatastructures.php (working copy) @@ -170,7 +170,7 @@ foreach ($dsList as $dsRecord) { $icon = ''; if ($dsRecord['previewicon']) { - $icon = $this->iconPath . $dsRecord['previewicon']; + $icon = $this->iconPath . $dsRecord['previewicon']; } $params['items'][] = array( $dsRecord['title'], @@ -196,11 +196,11 @@ * @return void */ public function templateObjectItemsProcFunc(array &$params, t3lib_TCEforms &$pObj) { - $conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['templavoila']); - if ($conf['enable.']['selectDataSource']) { + $this->conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['templavoila']); + + if ($this->conf['enable.']['selectDataSource']) { $this->templateObjectItemsProcFuncForCurrentDS($params, $pObj); - } - else { + } else { $this->templateObjectItemsProcFuncForAllDSes($params, $pObj); } } @@ -253,11 +253,17 @@ $this->dsList = $this->getDSList($params, $pObj); if (count($this->dsList) > 0) { + if ($this->conf['staticDS.']['enable']) { + $list = t3lib_div::csvValues(array_keys($this->dsList)); + } else { + $list = implode(',', array_keys($this->dsList)); + } // Get all TOs for these DSes $this->toRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 'uid,title,previewicon,datastructure', 'tx_templavoila_tmplobj', - 'datastructure IN (' . implode(',', array_keys($this->dsList)) . ')' . + 'datastructure IN (' . $list . ')' . self::enableFields('tx_templavoila_tmplobj')); + // Sort by DS name than by TO name uksort($this->toRows, array($this, 'sortTemplateObjects')); $currentDS = 0; @@ -302,16 +308,24 @@ protected function getDSList(array &$params, t3lib_TCEforms& $pObj) { // Find DS scope $scope = ($params['table'] == 'pages' ? 1 : 2); + if ($this->conf['staticDS.']['enable']) { + $rows = array(); + foreach ($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'] as $staticDataStructure) { + if ($staticDataStructure['scope'] == $scope) { + $rows[$staticDataStructure['path']] = $staticDataStructure; + } + } + } else { + // Get storage folder + $storagePid = $this->getStoragePid($params, $pObj); - // Get storage folder - $storagePid = $this->getStoragePid($params, $pObj); - - // Get all DSes from the current storage folder - $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,previewicon', - 'tx_templavoila_datastructure', - 'scope=' . $scope . ' AND pid=' . $storagePid . - self::enableFields('tx_templavoila_datastructure'), - '', 'title', '', 'uid'); + // Get all DSes from the current storage folder + $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,previewicon', + 'tx_templavoila_datastructure', + 'scope=' . $scope . ' AND pid=' . $storagePid . + self::enableFields('tx_templavoila_datastructure'), + '', 'title', '', 'uid'); + } return $rows; } Index: classes/class.tx_staticdstools.php =================================================================== --- classes/class.tx_staticdstools.php (revision 0) +++ classes/class.tx_staticdstools.php (revision 0) @@ -0,0 +1,233 @@ + + */ +class tx_staticDStools { + + + /** + * + * @param array Parameter array. Contains fieldName and fieldValue. + * @param object Instance of the class t3lib_tsStyleConfig + */ + function staticDsWizard($params, $pObj) { + $step = t3lib_div::_GP('dsWizardDoIt') ? intval(t3lib_div::_GP('dsWizardStep')) : 0; + $conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['templavoila']); + + $title = $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.title.' . $step); + $description = $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.description.' . $step); + $out = '

' . htmlspecialchars($title) . '

'; + + switch($step) { + case 1: + $ok = array(TRUE, TRUE); + if (t3lib_div::_GP('dsWizardDoIt')) { + $ok[0] = $this->checkDirectory($conf['staticDS.']['path_fce']); + if ($ok[0]) { + $description .= sprintf('||' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.dircheck.ok'), htmlspecialchars($conf['staticDS.']['path_fce'])); + } else { + $description .= sprintf('||' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.dircheck.ok'), htmlspecialchars($conf['staticDS.']['path_fce'])); + } + $ok[1] = $this->checkDirectory($conf['path_page']); + if ($ok[1]) { + $description .= sprintf('|' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.dircheck.ok'), htmlspecialchars($conf['staticDS.']['path_page'])); + } else { + $description .= sprintf('|' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.dircheck.ok'), htmlspecialchars($conf['staticDS.']['path_page'])); + } + if ($ok == array(TRUE, TRUE)) { + $controls .= $this->getDsRecords($conf['staticDS.']); + } + } + $submitText = $conf['staticDS.']['enable'] ? $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.submit3') : $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.submit2'); + $controls .= '
+ '; + break; + default: + $controls .= ' + '; + break; + } + + + $out .= '

' . str_replace('|', '
', $description) . '

' . + '

' . $controls . '

'; + + return $out; + } + + /** + * + * @param string $path + */ + protected function checkDirectory($path) { + $path = $path . (substr($path, -1) == '/' ? '' : '/'); + if (!is_dir(PATH_site . $path)) { + t3lib_div::mkdir_deep(PATH_site, $path); + } + return TRUE; #is_dir(path_site . substr($path, 0, -1)); + } + + /** + * + * @param array $conf + */ + protected function getDsRecords($conf) { + $updateMessage = ''; + $writeDsIds = array(); + $writeIds = t3lib_div::_GP('staticDSwizard'); + $options = t3lib_div::_GP('staticDSwizardoptions'); + + if (count($writeIds)) { + $writeDsIds = array_keys($writeIds); + } + $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( + '*', + 'tx_templavoila_datastructure', + 'deleted=0', + '', + 'scope, title' + ); + $out = ' + + + + + + + + '; + foreach($rows as $row) { + $dirPath = PATH_site . ($row['scope'] == 2 ? $conf['path_fce'] : $conf['path_page']); + $dirPath = $dirPath . (substr($dirPath, -1) == '/' ? '' : '/'); + $title = preg_replace('|[/,\."\']+|', '_', $row['title']); + $path = $dirPath . $title . ' (' . ($row['scope'] == 1 ? 'page' : 'fce') . ').xml'; + $outPath = substr($path, strlen(PATH_site)); + + $usage = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( + 'count(*)', + 'tx_templavoila_tmplobj', + 'datastructure=' . $row['uid'] . t3lib_BEfunc::BEenableFields('tx_templavoila_tmplobj') + ); + if (count($writeDsIds) && in_array($row['uid'], $writeDsIds)) { + t3lib_div::writeFile($path, $row['dataprot']); + if ($row['previewicon']) { + copy(PATH_site . 'uploads/tx_templavoila/' . $row['previewicon'], $dirPath . $title . ' (' . ($row['scope'] == 1 ? 'page' : 'fce') . ').gif'); + } + if ($options['updateRecords']) { + // update TO records + $GLOBALS['TYPO3_DB']->exec_UPDATEquery( + 'tx_templavoila_tmplobj', + 'datastructure="' . $row['uid'] . '"', + array('datastructure' => $outPath) + ); + // update page records + $GLOBALS['TYPO3_DB']->exec_UPDATEquery( + 'pages', + 'tx_templavoila_ds="' . $row['uid'] . '"', + array('tx_templavoila_ds' => $outPath) + ); + $GLOBALS['TYPO3_DB']->exec_UPDATEquery( + 'pages', + 'tx_templavoila_next_ds="' . $row['uid'] . '"', + array('tx_templavoila_next_ds' => $outPath) + ); + // update tt_content records + $GLOBALS['TYPO3_DB']->exec_UPDATEquery( + 'tt_content', + 'tx_templavoila_ds="' . $row['uid'] . '"', + array('tx_templavoila_ds' => $outPath) + ); + // delete DS records + $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_templavoila_datastructure', 'uid=' . $row['uid'], array('deleted' => 1)); + $updateMessage = $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.updated'); + } + + + } + $out .= ' + + + + + '; + if (count($writeDsIds) && in_array($row['uid'], $writeDsIds)) { + $out .= ''; + } else { + $out .= ''; + } + $out .= ''; + } + $out .= '
' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.uid') . '' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.pid') . '' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.title') . '' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.scope') . '' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.usage') . ' + +
' .$row['uid'] . '' .$row['pid'] . '' .htmlspecialchars($row['title']) . '' .($row['scope'] == 1 ? 'Page' : 'FCE') . '' .$usage[0]['count(*)'] . 'written to "' . $outPath . '"
'; + + if ($conf['enable']) { + if ($updateMessage) { + $out .= '

' . $updateMessage . '

' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.clearcache') . '

'; + } else { + $out .= '

' . $GLOBALS['LANG']->sL('LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard.description2.1') . '

'; + $out .= '

+ +
+

'; + } + } + return $out; + } + + /** + * + * @param unknown_type $conf + */ + public function readStaticDsFilesIntoArray($conf) { + $paths = array_unique(array($conf['staticDS.']['path_fce'],$conf['staticDS.']['path_page'])); + foreach ($paths as $path) { + $absolutePath = t3lib_div::getFileAbsFileName($path); + $files = t3lib_div::getFilesInDir($absolutePath, 'xml', true); + foreach($files as $filePath) { + $staticDataStructure = array(); + $pathInfo = pathinfo($filePath); + + $staticDataStructure['title'] = $pathInfo['filename']; + $staticDataStructure['path'] = substr($filePath, strlen(PATH_site)); + $iconPath = $pathInfo['dirname'] . '/' . $pathInfo['filename'] . '.gif'; + if (file_exists($iconPath)) { + $staticDataStructure['icon'] = substr($iconPath, strlen(PATH_site)); + } + $staticDataStructure['scope'] = strpos($pathInfo['filename'], '(fce)') !== FALSE ? 2 : 1; + + $GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'][] = $staticDataStructure; + } + } + } +} + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_staticdstools.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_staticdstools.php']); +} +?> Index: cm1/index.php =================================================================== --- cm1/index.php (revision 28109) +++ cm1/index.php (working copy) @@ -194,6 +194,8 @@ var $dsEdit; // instance of class tx_templavoila_cm1_dsEdit var $eTypes; // instance of class tx_templavoila_cm1_eTypes + var $extConf; // holds the extconf configuration + var $staticDS = FALSE; // Boolean; if true DS records are file based /** * Adds items to the ->MOD_MENU array. Used for the function menu selector. @@ -254,6 +256,8 @@ $this->eTypes = t3lib_div::getUserObj ('tx_templavoila_cm1_eTypes',''); $this->eTypes->init($this); + $this->extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['templavoila']); + $this->staticDS = ($this->extConf['staticDS.']['enable']); // Setting GPvars: $this->mode = t3lib_div::_GP('mode'); @@ -544,7 +548,11 @@ } if ($this->_load_ds_xml_to) { $toREC = t3lib_BEfunc::getRecordWSOL('tx_templavoila_tmplobj', $this->_load_ds_xml_to); - $dsREC = t3lib_BEfunc::getRecordWSOL('tx_templavoila_datastructure',$toREC['datastructure']); + if ($this->staticDS) { + $dsREC['dataprot'] = t3lib_div::getURL(PATH_site . $toREC['datastructure']); + } else { + $dsREC = t3lib_BEfunc::getRecordWSOL('tx_templavoila_datastructure', $toREC['datastructure']); + } } // Loading DS from either XML or a Template Object (containing reference to DS) @@ -683,45 +691,59 @@ switch($cmd) { // If it is requested to save the current DS and mapping information to a DS and TO record, then...: case 'saveDSandTO': + $newID = ''; + // Init TCEmain object and store: + $tce = t3lib_div::makeInstance("t3lib_TCEmain"); + $tce->stripslashes_values=0; - // DS: - $dataArr=array(); - $dataArr['tx_templavoila_datastructure']['NEW']['pid']=intval($this->_saveDSandTO_pid); - $dataArr['tx_templavoila_datastructure']['NEW']['title']=$this->_saveDSandTO_title; - $dataArr['tx_templavoila_datastructure']['NEW']['scope']=$this->_saveDSandTO_type; + // DS: + // Modifying data structure with conversion of preset values for field types to actual settings: $storeDataStruct = $dataStruct; - if (is_array($storeDataStruct['ROOT']['el'])) + if (is_array($storeDataStruct['ROOT']['el'])) { $this->eTypes->substEtypeWithRealStuff($storeDataStruct['ROOT']['el'],$contentSplittedByMapping['sub']['ROOT'],$dataArr['tx_templavoila_datastructure']['NEW']['scope']); + } $dataProtXML = t3lib_div::array2xml_cs($storeDataStruct,'T3DataStructure', array('useCDATA' => 1)); - $dataArr['tx_templavoila_datastructure']['NEW']['dataprot'] = $dataProtXML; - // Init TCEmain object and store: - $tce = t3lib_div::makeInstance("t3lib_TCEmain"); - $tce->stripslashes_values=0; - $tce->start($dataArr,array()); - $tce->process_datamap(); + if ($this->staticDS) { + $title = preg_replace('|[/,\."\']+|', '_', $this->_saveDSandTO_title) . ' (' . ($this->_saveDSandTO_type == 1 ? 'page' : 'fce') . ').xml'; + $path = PATH_site . ($this->_saveDSandTO_type == 2 ? $this->extConf['staticDS.']['path_fce'] : $this->extConf['staticDS.']['path_page']) . $title; + t3lib_div::writeFile($path, $dataProtXML); + $newID = substr($path, strlen(PATH_site)); + } else { + $dataArr=array(); + $dataArr['tx_templavoila_datastructure']['NEW']['pid'] = intval($this->_saveDSandTO_pid); + $dataArr['tx_templavoila_datastructure']['NEW']['title'] = $this->_saveDSandTO_title; + $dataArr['tx_templavoila_datastructure']['NEW']['scope'] = $this->_saveDSandTO_type; + $dataArr['tx_templavoila_datastructure']['NEW']['dataprot'] = $dataProtXML; + // start data processing + $tce->start($dataArr,array()); + $tce->process_datamap(); + $newID = intval($tce->substNEWwithIDs['NEW']); + } + // If that succeeded, create the TO as well: - if ($tce->substNEWwithIDs['NEW']) { + if ($newID) { $dataArr=array(); - $dataArr['tx_templavoila_tmplobj']['NEW']['pid']=intval($this->_saveDSandTO_pid); - $dataArr['tx_templavoila_tmplobj']['NEW']['title']=$this->_saveDSandTO_title.' [Template]'; - $dataArr['tx_templavoila_tmplobj']['NEW']['datastructure']=intval($tce->substNEWwithIDs['NEW']); - $dataArr['tx_templavoila_tmplobj']['NEW']['fileref']=substr($this->displayFile,strlen(PATH_site)); - $dataArr['tx_templavoila_tmplobj']['NEW']['templatemapping']=serialize($templatemapping); + $dataArr['tx_templavoila_tmplobj']['NEW']['pid'] = intval($this->_saveDSandTO_pid); + $dataArr['tx_templavoila_tmplobj']['NEW']['title'] = $this->_saveDSandTO_title . ' [Template]'; + $dataArr['tx_templavoila_tmplobj']['NEW']['datastructure'] = $newID; + $dataArr['tx_templavoila_tmplobj']['NEW']['fileref'] = substr($this->displayFile, strlen(PATH_site)); + $dataArr['tx_templavoila_tmplobj']['NEW']['templatemapping'] = serialize($templatemapping); $dataArr['tx_templavoila_tmplobj']['NEW']['fileref_mtime'] = @filemtime($this->displayFile); $dataArr['tx_templavoila_tmplobj']['NEW']['fileref_md5'] = @md5_file($this->displayFile); // Init TCEmain object and store: - $tce = t3lib_div::makeInstance("t3lib_TCEmain"); - $tce->stripslashes_values=0; $tce->start($dataArr,array()); $tce->process_datamap(); if ($tce->substNEWwithIDs['NEW']) { - $msg[] = ''.sprintf($GLOBALS['LANG']->getLL('msgDSTOSaved'), $dataArr['tx_templavoila_tmplobj']['NEW']['datastructure'], $tce->substNEWwithIDs['NEW'], $this->_saveDSandTO_pid); + $msg[] = '' . + sprintf($GLOBALS['LANG']->getLL('msgDSTOSaved'), + $dataArr['tx_templavoila_tmplobj']['NEW']['datastructure'], + $tce->substNEWwithIDs['NEW'], $this->_saveDSandTO_pid); } else { $msg[] = ''.$GLOBALS['LANG']->getLL('error').': '.sprintf($GLOBALS['LANG']->getLL('errorTONotSaved'), $dataArr['tx_templavoila_tmplobj']['NEW']['datastructure']); } @@ -743,28 +765,41 @@ if ($cmd == 'updateDSandTO') { // Looking up the records by their uids: $toREC = t3lib_BEfunc::getRecordWSOL('tx_templavoila_tmplobj',$this->_saveDSandTO_TOuid); - $dsREC = t3lib_BEfunc::getRecordWSOL('tx_templavoila_datastructure',$toREC['datastructure']); + } else { + $toREC = t3lib_BEfunc::getRecordWSOL('tx_templavoila_tmplobj',$this->_load_ds_xml_to); } + if ($this->staticDS) { + $dsREC['uid'] = $toREC['datastructure']; + } else { + $dsREC = t3lib_BEfunc::getRecordWSOL('tx_templavoila_datastructure', $toREC['datastructure']); + } // If they are found, continue: if ($toREC['uid'] && $dsREC['uid']) { + // Init TCEmain object and store: + $tce = t3lib_div::makeInstance('t3lib_TCEmain'); + $tce->stripslashes_values=0; - // DS: - $dataArr=array(); - // Modifying data structure with conversion of preset values for field types to actual settings: $storeDataStruct=$dataStruct; - if (is_array($storeDataStruct['ROOT']['el'])) + if (is_array($storeDataStruct['ROOT']['el'])) { $this->eTypes->substEtypeWithRealStuff($storeDataStruct['ROOT']['el'],$contentSplittedByMapping['sub']['ROOT'],$dsREC['scope']); + } $dataProtXML = t3lib_div::array2xml_cs($storeDataStruct,'T3DataStructure', array('useCDATA' => 1)); - $dataArr['tx_templavoila_datastructure'][$dsREC['uid']]['dataprot'] = $dataProtXML; - // Init TCEmain object and store: - $tce = t3lib_div::makeInstance('t3lib_TCEmain'); - $tce->stripslashes_values=0; - $tce->start($dataArr,array()); - $tce->process_datamap(); + // DS: + if ($this->staticDS) { + $path = PATH_site . $dsREC['uid']; + t3lib_div::writeFile($path, $dataProtXML); + } else { + $dataArr=array(); + $dataArr['tx_templavoila_datastructure'][$dsREC['uid']]['dataprot'] = $dataProtXML; + // process data + $tce->start($dataArr,array()); + $tce->process_datamap(); + } + // TO: $TOuid = t3lib_BEfunc::wsMapId('tx_templavoila_tmplobj',$toREC['uid']); $dataArr=array(); @@ -773,9 +808,7 @@ $dataArr['tx_templavoila_tmplobj'][$TOuid]['fileref_mtime'] = @filemtime($this->displayFile); $dataArr['tx_templavoila_tmplobj'][$TOuid]['fileref_md5'] = @md5_file($this->displayFile); - // Init TCEmain object and store: - $tce = t3lib_div::makeInstance('t3lib_TCEmain'); - $tce->stripslashes_values=0; + $tce->start($dataArr,array()); $tce->process_datamap(); @@ -809,14 +842,24 @@   ' . $GLOBALS['LANG']->getLL('templateObject') . ': ' . ($toREC ? htmlspecialchars($toREC['title']) : $GLOBALS['LANG']->getLL('mappingNEW')) . ' - + '; + if ($this->staticDS) { + $onClick = 'return top.openUrlInWindow(\'' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . $toREC['datastructure'] . '\',\'FileView\');'; + $tRows[]='   + ' . $GLOBALS['LANG']->getLL('renderDSO_XML') . ': + '.htmlspecialchars($toREC['datastructure']).' + '; + } else { + $tRows[]=' + +   ' . $GLOBALS['LANG']->getLL('renderTO_dsRecord') . ': ' . ($dsREC ? htmlspecialchars($dsREC['title']) : $GLOBALS['LANG']->getLL('mappingNEW')) . ' - + '; + } - '; // Write header of page: $content.=' @@ -858,15 +901,29 @@ // Template Object records: $opt=array(); $opt[]=''; - $res = $TYPO3_DB->exec_SELECTquery ( - 'tx_templavoila_tmplobj.*,tx_templavoila_datastructure.scope', - 'tx_templavoila_tmplobj LEFT JOIN tx_templavoila_datastructure ON tx_templavoila_datastructure.uid=tx_templavoila_tmplobj.datastructure', - 'tx_templavoila_tmplobj.pid IN ('.$this->storageFolders_pidList.') AND tx_templavoila_tmplobj.datastructure>0 '. - t3lib_BEfunc::deleteClause('tx_templavoila_tmplobj'). - t3lib_BEfunc::versioningPlaceholderClause('tx_templavoila_tmplobj'), - '', - 'tx_templavoila_datastructure.scope, tx_templavoila_tmplobj.title' - ); + if ($this->staticDS) { + $res = $TYPO3_DB->exec_SELECTquery ( + '*, CASE WHEN LOCATE(' . $GLOBALS['TYPO3_DB']->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure)>0 THEN 2 ELSE 1 END scope', + 'tx_templavoila_tmplobj', + 'pid IN ('.$this->storageFolders_pidList.') AND datastructure!=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('', 'tx_templavoila_tmplobj') . + t3lib_BEfunc::deleteClause('tx_templavoila_tmplobj'). + t3lib_BEfunc::versioningPlaceholderClause('tx_templavoila_tmplobj'), + '', + 'scope,title' + ); + + } else { + $res = $TYPO3_DB->exec_SELECTquery ( + 'tx_templavoila_tmplobj.*,tx_templavoila_datastructure.scope', + 'tx_templavoila_tmplobj LEFT JOIN tx_templavoila_datastructure ON tx_templavoila_datastructure.uid=tx_templavoila_tmplobj.datastructure', + 'tx_templavoila_tmplobj.pid IN ('.$this->storageFolders_pidList.') AND tx_templavoila_tmplobj.datastructure>0 '. + t3lib_BEfunc::deleteClause('tx_templavoila_tmplobj'). + t3lib_BEfunc::versioningPlaceholderClause('tx_templavoila_tmplobj'), + '', + 'tx_templavoila_datastructure.scope, tx_templavoila_tmplobj.title' + ); + + } $sFolder = ''; $optGroupOpen = false; while(false !== ($row = $TYPO3_DB->sql_fetch_assoc($res))) { @@ -1023,7 +1080,7 @@ */ function renderDSO() { global $TYPO3_DB; - if (intval($this->displayUid)>0) { + if (intval($this->displayUid)>0) { // TODO: static ds support $row = t3lib_BEfunc::getRecordWSOL('tx_templavoila_datastructure',$this->displayUid); if (is_array($row)) { @@ -1242,6 +1299,20 @@ ' . $GLOBALS['LANG']->getLL('renderTO_dsFile') . ': '.htmlspecialchars($relFilePath).' '; + $onCl = 'index.php?file=' . rawurlencode($theFile) . '&_load_ds_xml=1&_load_ds_xml_to=' . $row['uid'] . '&uid=' . rawurlencode($DSOfile) . '&returnUrl=' . $this->returnUrl; + $onClMsg = ' + if (confirm(unescape(\''.rawurlencode($GLOBALS['LANG']->getLL('renderTO_updateWarningConfirm')).'\'))) { + document.location=\''.$onCl.'\'; + } + return false; + '; + $tRows[]=' + +   + '. + $this->cshItem('xMOD_tx_templavoila','mapping_to_modifyDSTO',$this->doc->backPath,''). + ' + '; // Read Data Structure: $dataStruct = $this->getDataStructFromDSO('',$DSOfile); Index: ext_conf_template.txt =================================================================== --- ext_conf_template.txt (revision 27987) +++ ext_conf_template.txt (working copy) @@ -1,8 +1,20 @@ - # cat=basic/enable; type=boolean; label=Enable the classic Page module:Check this box to enable classic Page module in the list of modules. + # cat=basic/enable; type=boolean; label=LLL:EXT:templavoila/res1/language/template_conf.xml:enable.oldPageModule enable.oldPageModule = 0 - # cat=basic/enable; type=boolean; label=Enable data source selection:If this checkbox is checked, page and content elements will have data source selector as they had in older TemplaVoila versions. If current installation has very few template objects, it is recommended to have this checkbox unchecked. + # cat=basic/enable; type=boolean; label=LLL:EXT:templavoila/res1/language/template_conf.xml:enable.selectDataSource enable.selectDataSource = 0 - # cat=basic/enable; type=boolean; label=Enable Header for FCE's:If this checkbox is checked the header of Content Element type FCE will be rendered like headers of other Content Elements. + # cat=basic/enable; type=boolean; label=LLL:EXT:templavoila/res1/language/template_conf.xml:enable.renderFCEHeader enable.renderFCEHeader = 0 + + # cat=static DS; type=boolean; label=LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.enable +staticDS.enable = 0 + + #cat=static DS;type=string;label=LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.path_fce +staticDS.path_fce = fileadmin/templates/ds/fce/ + + #cat=static DS;type=string;label=LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.path_page +staticDS.path_page = fileadmin/templates/ds/page/ + + #cat=static DS;type=user[EXT:templavoila/classes/class.tx_staticdstools.php:&tx_staticDStools->staticDsWizard];label=LLL:EXT:templavoila/res1/language/template_conf.xml:staticDS.wizard +staticDS.wizard = Index: ext_tables.php =================================================================== --- ext_tables.php (revision 27977) +++ ext_tables.php (working copy) @@ -42,6 +42,12 @@ t3lib_extMgm::extPath($_EXTKEY).'class.tx_templavoila_extdeveval.php', 'TemplaVoila L10N Mode Conversion Tool' ); + + // Static DS + if ($_EXTCONF['staticDS.']['enable']) { + include_once(t3lib_extMgm::extPath('templavoila') . 'classes/class.tx_staticdstools.php'); + tx_staticDStools::readStaticDsFilesIntoArray($_EXTCONF); + } } // Adding tables: Index: mod1/db_new_content_el.php =================================================================== --- mod1/db_new_content_el.php (revision 27977) +++ mod1/db_new_content_el.php (working copy) @@ -407,23 +407,23 @@ $dataStructureRecords = array(); $storageFolderPID = $this->apiObj->getStorageFolderPid($positionPid); - // Fetch data structures stored in the database: - $addWhere = $this->buildRecordWhere('tx_templavoila_datastructure'); - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_templavoila_datastructure', 'pid=' . intval($storageFolderPID) . ' AND scope=2' . $addWhere . t3lib_BEfunc::deleteClause('tx_templavoila_datastructure') . t3lib_BEfunc::versioningPlaceholderClause('tx_templavoila_datastructure')); - while ( FALSE !== ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) ) { - $dataStructureRecords[$row['uid']] = $row; - } -/* - // Fetch static data structures which are stored in XML files: - if (is_array($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'])) { + if (is_array($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'])) { + // Fetch static data structures which are stored in XML files: foreach($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'] as $staticDataStructureArr) { $staticDataStructureArr['_STATIC'] = TRUE; $dataStructureRecords[$staticDataStructureArr['path']] = $staticDataStructureArr; } + } else { + // Fetch data structures stored in the database: + $addWhere = $this->buildRecordWhere('tx_templavoila_datastructure'); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_templavoila_datastructure', 'pid=' . intval($storageFolderPID) . ' AND scope=2' . $addWhere . t3lib_BEfunc::deleteClause('tx_templavoila_datastructure') . t3lib_BEfunc::versioningPlaceholderClause('tx_templavoila_datastructure')); + while ( FALSE !== ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) ) { + $dataStructureRecords[$row['uid']] = $row; + } } -*/ + // Fetch all template object records which uare based one of the previously fetched data structures: $templateObjectRecords = array(); $recordDataStructure = array(); Index: mod1/index.php =================================================================== --- mod1/index.php (revision 28205) +++ mod1/index.php (working copy) @@ -152,6 +152,9 @@ var $sortableContainers = array(); // Contains the containers for drag and drop var $sortableItems = array(); // Registry for all id => flexPointer-Pairs + var $extConf; // holds the extconf configuration + var $staticDS = FALSE; // Boolean; if true DS records are file based + var $blindIcons = array(); // Icons which shouldn't be rendered by configuration, can contain elements of "new,edit,copy,cut,ref,paste,browse,delete,makeLocal,unlink,hide" protected $debug = FALSE; @@ -177,6 +180,9 @@ $this->modSharedTSconfig = t3lib_BEfunc::getModTSconfig($this->id, 'mod.SHARED'); $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']); + $this->extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['templavoila']); + $this->staticDS = ($this->extConf['staticDS.']['enable']); + $this->altRoot = t3lib_div::_GP('altRoot'); $this->versionId = t3lib_div::_GP('versionId'); @@ -950,11 +956,18 @@ $beTemplate = t3lib_div::getURL(PATH_site . $toRecord['belayout']); } else { // when TO doesn't have the beLayout look in DS record + if ($this->staticDS) { + $beLayoutFile = PATH_site . substr($toRecord['datastructure'], 0, -3) . 'html'; + if ($toRecord['datastructure'] && file_exists($beLayoutFile)) { + $beTemplate = t3lib_div::getURL($beLayoutFile); + } + } else { $dsRecord = t3lib_BEfunc::getRecordWSOL('tx_templavoila_datastructure', $toRecord['datastructure'], 'belayout'); if ($dsRecord['belayout']) { $beTemplate = t3lib_div::getURL(PATH_site . $dsRecord['belayout']); } } + } // no layout, no special rendering $flagRenderBeLayout = $beTemplate? TRUE : FALSE; Index: mod2/index.php =================================================================== --- mod2/index.php (revision 27977) +++ mod2/index.php (working copy) @@ -115,8 +115,8 @@ var $errorsWarnings=array(); var $cm1Link = '../cm1/index.php'; - + function init() { parent::init(); $this->templatesDir = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'templates/'; @@ -322,7 +322,7 @@ if ($path) { $tRows[] = ' - ' . + ' . t3lib_iconWorks::getIconImage('pages', t3lib_BEfunc::getRecord('pages', $pid), $this->doc->backPath, 'class="absmiddle" title="'. htmlspecialchars($alttext) . '"') . htmlspecialchars($path).' '.htmlspecialchars($stat['DS']).' @@ -348,27 +348,29 @@ function renderModuleContent_mainView() { global $LANG; - // Select all Data Structures in the PID and put into an array: - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( - '*', - 'tx_templavoila_datastructure', - 'pid='.intval($this->id).t3lib_BEfunc::deleteClause('tx_templavoila_datastructure'), - '', - 'title' - ); - $dsRecords = array(); - while($res && false !== ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) { - t3lib_BEfunc::workspaceOL('tx_templavoila_datastructure',$row); - $dsRecords[$row['scope']][] = $row; - } - $GLOBALS['TYPO3_DB']->sql_free_result($res); + // Select all static Data Structures and add to array: if (is_array($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'])) { foreach($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'] as $staticDS) { $staticDS['_STATIC'] = 1; $dsRecords[$staticDS['scope']][] = $staticDS; } + } else { + // Select all Data Structures in the PID and put into an array: + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( + '*', + 'tx_templavoila_datastructure', + 'pid='.intval($this->id).t3lib_BEfunc::deleteClause('tx_templavoila_datastructure'), + '', + 'title' + ); + $dsRecords = array(); + while($res && false !== ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) { + t3lib_BEfunc::workspaceOL('tx_templavoila_datastructure',$row); + $dsRecords[$row['scope']][] = $row; + } + $GLOBALS['TYPO3_DB']->sql_free_result($res); } // Select all Template Records in PID: @@ -605,12 +607,12 @@ // Put together the records icon including content sensitive menu link wrapped around it: $recordIcon = t3lib_iconWorks::getIconImage('tx_templavoila_datastructure',$dsR,$this->doc->backPath,'class="absmiddle"'); $recordIcon = $this->doc->wrapClickMenuOnIcon($recordIcon, 'tx_templavoila_datastructure', $dsR['uid'], 1, '&callingScriptId='.rawurlencode($this->doc->scriptID)); - + // Preview icon: if ($dsR['previewicon']) { if (isset($this->modTSconfig['properties']['dsPreviewIconThumb']) && $this->modTSconfig['properties']['dsPreviewIconThumb'] != '0') { - $icon = t3lib_BEfunc::getThumbNail($this->doc->backPath . 'thumbs.php', PATH_site . 'uploads/tx_templavoila/' . $dsR['previewicon'], - 'hspace="5" vspace="5" border="1"', + $icon = t3lib_BEfunc::getThumbNail($this->doc->backPath . 'thumbs.php', PATH_site . 'uploads/tx_templavoila/' . $dsR['previewicon'], + 'hspace="5" vspace="5" border="1"', strpos($this->modTSconfig['properties']['dsPreviewIconThumb'], 'x') ? $this->modTSconfig['properties']['dsPreviewIconThumb'] : ''); } else { $icon = ''; @@ -679,13 +681,14 @@ } else { // DS was a file: // XML file icon: - $recordIcon = 'doc->backPath,'gfx/fileicons/xml.gif','width="18" height="16"').' alt="" class="absmiddle" />'; + $onClick = 'document.location=\'' . $this->doc->backPath . 'file_edit.php?target=' . rawurlencode(PATH_site . $dsR['path']) . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')) . '\';'; + $recordIcon = 'doc->backPath,'gfx/fileicons/xml.gif','width="18" height="16"').' alt="" class="absmiddle" />'; // Preview icon: if ($dsR['icon'] && $iconPath = t3lib_div::getFileAbsFileName($dsR['icon'])) { if (isset($this->modTSconfig['properties']['dsPreviewIconThumb']) && $this->modTSconfig['properties']['dsPreviewIconThumb'] != '0') { - $icon = t3lib_BEfunc::getThumbNail($this->doc->backPath . 'thumbs.php', PATH_site . 'uploads/tx_templavoila/' . $dsR['previewicon'], - 'hspace="5" vspace="5" border="1"', + $icon = t3lib_BEfunc::getThumbNail($this->doc->backPath . 'thumbs.php', PATH_site . 'uploads/tx_templavoila/' . $dsR['previewicon'], + 'hspace="5" vspace="5" border="1"', strpos($this->modTSconfig['properties']['dsPreviewIconThumb'], 'x') ? $this->modTSconfig['properties']['dsPreviewIconThumb'] : ''); } else { $icon = ''; @@ -779,7 +782,7 @@ if ($toObj['previewicon']) { if (isset($this->modTSconfig['properties']['toPreviewIconThumb']) && $this->modTSconfig['properties']['toPreviewIconThumb'] != '0') { $icon = t3lib_BEfunc::getThumbNail($this->doc->backPath . 'thumbs.php', PATH_site . 'uploads/tx_templavoila/' . $toObj['previewicon'], - 'hspace="5" vspace="5" border="1"', + 'hspace="5" vspace="5" border="1"', strpos($this->modTSconfig['properties']['toPreviewIconThumb'], 'x') ? $this->modTSconfig['properties']['toPreviewIconThumb'] : ''); } else { $icon = ''; @@ -1292,8 +1295,8 @@ // TEMPLATE ARCHIVE: if ($this->modTSconfig['properties']['templatePath']) { - $paths = t3lib_div::trimExplode(',', $this->modTSconfig['properties']['templatePath'], true); - $prefix = t3lib_div::getFileAbsFileName($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']); + $paths = t3lib_div::trimExplode(',', $this->modTSconfig['properties']['templatePath'], true); + $prefix = t3lib_div::getFileAbsFileName($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir']); if (count($paths) > 0 && is_array($GLOBALS['FILEMOUNTS'])) { foreach($GLOBALS['FILEMOUNTS'] as $mountCfg) { // look in paths if it's part of mounted path @@ -1301,9 +1304,9 @@ $files = array(); foreach ($paths as $path) { if (t3lib_div::isFirstPartOfStr($prefix . $path, $mountCfg['path'])) { - $isPart = true; + $isPart = true; $files = array_merge(t3lib_div::getFilesInDir($prefix . $path, 'html,htm,tmpl',1), $files); - } + } } if ($isPart) { // USED FILES: @@ -1314,7 +1317,7 @@ Usage count New DS/TO '; - + $i = 0; foreach($files as $tFile) { $tRows[] = ' Index: res1/language/template_conf.xml =================================================================== --- res1/language/template_conf.xml (revision 0) +++ res1/language/template_conf.xml (revision 0) @@ -0,0 +1,42 @@ + + + + Language file for TV template settings + module + + EXT:templavoila/res1/language/template_conf.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file