Index: class.tx_templavoila_handlestaticdatastructures.php =================================================================== --- class.tx_templavoila_handlestaticdatastructures.php (revision 32853) +++ class.tx_templavoila_handlestaticdatastructures.php (working copy) @@ -132,25 +132,29 @@ class tx_templavoila_handleStaticDataStructures { */ public function dataSourceItemsProcFunc(array &$params, t3lib_TCEforms& $pObj) { - // Get all DSes - $dsList = $this->getDSList($params, $pObj); + $storagePid = $this->getStoragePid($params, $pObj); + $scope = $this->getScope($params); + + $removeDSItems = $this->getRemoveItems($params, substr($params['field'], 0, -2) . 'ds'); + + $dsRepo = t3lib_div::makeInstance('tx_templavoila_datastructureRepository'); + $dsList = $dsRepo->getDatastructuresByStoragePidAndScope($storagePid, $scope); + $params['items'] = array( array( '', '' ) ); - foreach ($dsList as $dsRecord) { - $icon = ''; - if ($dsRecord['previewicon']) { - $icon = $this->iconPath . $dsRecord['previewicon']; + + foreach ($dsList as $dsObj) { + if($dsObj->isPermittedForUser($params['row'], $removeDSItems)) { + $params['items'][] = array( + $dsObj->getLabel(), + $dsObj->getKey(), + $dsObj->getIcon() + ); } - $params['items'][] = array( - $GLOBALS['LANG']->sL($dsRecord['title']), - isset($dsRecord['path']) ? $dsRecord['path'] : $dsRecord['uid'], - $icon - ); } - tx_templavoila_handleStaticDataStructures::check_permissions($params, $pObj); } /** @@ -180,31 +184,34 @@ class tx_templavoila_handleStaticDataStructures { * @return void */ protected function templateObjectItemsProcFuncForCurrentDS(array &$params, t3lib_TCEforms &$pObj) { - // Get DS - $tsConfig = &$pObj->cachedTSconfig[$params['table'].':'.$params['row']['uid']]; - - $fieldName = $params['field'] == 'tx_templavoila_next_to' ? 'tx_templavoila_next_ds': 'tx_templavoila_ds'; + // Get DS + $tsConfig = &$pObj->cachedTSconfig[$params['table'] . ':' . $params['row']['uid']]; + $fieldName = $params['field'] == 'tx_templavoila_next_to' ? 'tx_templavoila_next_ds' : 'tx_templavoila_ds'; $dataSource = $tsConfig['_THIS_ROW'][$fieldName]; - $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - 'uid,title,previewicon,datastructure', 'tx_templavoila_tmplobj', - 'datastructure=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($dataSource, 'tx_templavoila_tmplobj') . - self::enableFields('tx_templavoila_tmplobj')); + + $removeTOItems = $this->getRemoveItems($params, substr($params['field'], 0, -2) . 'to'); + + $dsRepo = t3lib_div::makeInstance('tx_templavoila_datastructureRepository'); + $toRepo = t3lib_div::makeInstance('tx_templavoila_templateRepository'); + $params['items'] = array( array( '', '' ) ); - // Create items sorted visually by DS and title - foreach ($rows as $row) { - $icon = ''; - if ($row['previewicon']) { - $icon = $this->iconPath . $row['previewicon']; + + if (strlen($dataSource)) { + $ds = $dsRepo->getDatastructureByUidOrFilename($dataSource); + $toList = $toRepo->getTemplatesByDatastructure($ds); + foreach ($toList as $toObj) { + if($toObj->isPermittedForUser($params['table'], $removeTOItems)) { + $params['items'][] = array( + $toObj->getLabel(), + $toObj->getKey(), + $toObj->getIcon() + ); + } } - $params['items'][] = array( - $GLOBALS['LANG']->sL($row['title']), - $row['uid'], - $icon - ); } } @@ -217,95 +224,50 @@ class tx_templavoila_handleStaticDataStructures { * @return void */ protected function templateObjectItemsProcFuncForAllDSes(array &$params, t3lib_TCEforms &$pObj) { - // Find DSes - $this->dsList = $this->getDSList($params, $pObj); - if (count($this->dsList) > 0) { - $keys = array(); - foreach (array_keys($this->dsList) as $key) { - $keys[] = $GLOBALS['TYPO3_DB']->fullQuoteStr($key, 'tx_templavoila_tmplobj'); - } - $list = implode(',', $keys); - // Get all TOs for these DSes - $this->toRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - 'uid,title,previewicon,datastructure', 'tx_templavoila_tmplobj', - 'datastructure IN (' . $list . ')' . - self::enableFields('tx_templavoila_tmplobj')); - - // Sort by DS name than by TO name - uksort($this->toRows, array($this, 'sortTemplateObjects')); - $currentDS = 0; - $params['items'] = array( - array( - '', '' - ) - ); - // Create items sorted visually by DS and title - foreach ($this->toRows as $row) { - // Check if we got a new DS - if ($currentDS != $row['datastructure']) { - $params['items'][] = array( - $this->dsList[$row['datastructure']]['title'], - '--div--' - ); - $currentDS = $row['datastructure']; - } - // Add TO - $icon = ''; - if ($row['previewicon']) { - $icon = $this->iconPath . $row['previewicon']; - } - $params['items'][] = array( - $GLOBALS['LANG']->sL($row['title']), - $row['uid'], - $icon - ); - } - } - unset($this->dsList); - unset($this->toRows); - } + $storagePid = $this->getStoragePid($params, $pObj); + $scope = $this->getScope($params); - /** - * Retrieves DS list for the current itemsProcFunc parameters - * - * @param array $params Parameters to the itemsProcFunc - * @param t3lib_TCEforms $pObj Calling function - * @return array Rows with DSes (uid, title, previewicon) - */ - protected function getDSList(array &$params, t3lib_TCEforms& $pObj) { + $removeDSItems = $this->getRemoveItems($params, substr($params['field'], 0, -2) . 'ds'); + $removeTOItems = $this->getRemoveItems($params, substr($params['field'], 0, -2) . 'to'); - $rows = array(); + $dsRepo = t3lib_div::makeInstance('tx_templavoila_datastructureRepository'); + $toRepo = t3lib_div::makeInstance('tx_templavoila_templateRepository'); - // Find DS scope - $scope = ($params['table'] == 'pages' ? 1 : 2); - if (is_array($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'])) { - foreach ($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'] as $staticDataStructure) { - if ($staticDataStructure['scope'] == $scope) { - $rows[$staticDataStructure['path']] = $staticDataStructure; - } + $dsList = $dsRepo->getDatastructuresByStoragePidAndScope($storagePid, $scope); + + $params['items'] = array( + array( + '', '' + ) + ); + + foreach($dsList as $dsObj) { + if(!$dsObj->isPermittedForUser($params['row'], $removeDSItems)) { + continue; } - } + $curDS = array(); + $curDS[] = array( + $dsObj->getLabel(), + '--div--' + ); - if (!$this->conf['staticDS.']['enable']) { - // Get storage folder - $storagePid = $this->getStoragePid($params, $pObj); + $toList = $toRepo->getTemplatesByDatastructure($dsObj); - $addWhere = ''; - $modTSConfig = t3lib_BEfunc::getModTSconfig($params['row']['uid'], 'TCEFORM.pages.' . $params['field'] . '.removeItems'); - if (isset($modTSConfig['value'])) { - $removedItems = implode(',', t3lib_div::trimExplode(',', $modTSConfig['value'], TRUE)); - $addWhere = ' AND uid NOT IN(' . $removedItems . ')'; + foreach ($toList as $toObj) { + if($toObj->isPermittedForUser($params['row'], $removeTOItems)) { + $curDS[] = array( + $toObj->getLabel(), + $toObj->getKey(), + $toObj->getIcon() + ); + } } - // Get all DSes from the current storage folder - $rows = t3lib_div::array_merge_recursive_overrule($rows, $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,title,previewicon', - 'tx_templavoila_datastructure', - 'scope=' . $scope . ' AND pid=' . $storagePid . $addWhere . - self::enableFields('tx_templavoila_datastructure'), - '', 'title', '', 'uid')); + if (count($curDS) > 1) { + $params['items'] = array_merge($params['items'], $curDS); + } } - return $rows; } /** @@ -321,7 +283,7 @@ class tx_templavoila_handleStaticDataStructures { $tsConfig = &$pObj->cachedTSconfig[$params['table'].':'.$params['row']['uid']]; $storagePid = intval($tsConfig['_STORAGE_PID']); - // Check for alternative storage folder + // Check for alternative storage folder $field = $params['table'] == 'pages' ? 'uid' : 'pid'; $modTSConfig = t3lib_BEfunc::getModTSconfig($params['row'][$field], 'tx_templavoila.storagePid'); if (is_array($modTSConfig) && t3lib_div::testInt($modTSConfig['value'])) { @@ -331,88 +293,32 @@ class tx_templavoila_handleStaticDataStructures { } /** - * Provides 'enableFields' functionality while fixing some bugs in the older - * TYPO3 versions - * - * @param string $tableName Table name - * @return string Additional WHERE expression (starting from ' AND') or empty string - */ - protected function enableFields($tableName) { - $where1 = trim(t3lib_BEfunc::BEenableFields($tableName)); - if (strcasecmp($where1, 'AND') == 0) { - $where1 = ''; - } - $where2 = trim(t3lib_BEfunc::deleteClause($tableName)); - if (strcasecmp($where2, 'AND') == 0) { - $where2 = ''; - } - $where = trim($where1 . ' ' . $where2); - return ($where ? ' ' . $where : ''); - } - - /** - * Sorts template objects by DS and than by title + * Determine scope from current paramset * - * @param int $key1 Key 1 to $this->toRows - * @param int $key2 Key 2 to $this->toRows - * @return int Result of the comparison (see strcmp()) - * @see uksort() - * @see strcmp() + * @param array $params + * @return integer */ - public function sortTemplateObjects($key1, $key2) { - $result = 0; - $row1 = $this->toRows[$key1]; - $row2 = $this->toRows[$key2]; - if ($row1['datastructure'] == $row2['datastructure']) { - $result = strcmp($GLOBALS['LANG']->sL($row1['title']), $GLOBALS['LANG']->sL($row2['title'])); - } - else { - $result = strcmp($GLOBALS['LANG']->sL($this->dsList[$row1['datastructure']]['title']), $GLOBALS['LANG']->sL($this->dsList[$row2['datastructure']]['title'])); + protected function getScope(array $params) { + $scope = tx_templavoila_datastructure::SCOPE_UNKNOWN; + if ($params['table'] == 'pages') { + $scope = tx_templavoila_datastructure::SCOPE_PAGE; + } elseif ($params['table'] == 'tt_content') { + $scope = tx_templavoila_datastructure::SCOPE_FCE; } - return $result; + return $scope; } /** - * Adds static data structures to selector box items arrays. - * Adds only structures for Page Templates + * Find relevant removeItems blocks for a certain field with the given paramst * - * @param array Array of items passed by reference. - * @param object The parent object (t3lib_TCEforms / t3lib_transferData depending on context) - * @return void + * @param array $params + * @param string $field + * @return array */ - function check_permissions(&$params,&$pObj) { - global $BE_USER; - - if ($BE_USER->isAdmin()) { - return; - } - foreach ($BE_USER->userGroups as $group) { - // Get list of DS & TO - $items = t3lib_div::trimExplode(',', $group['tx_templavoila_access'], true); - - foreach ($items as $ref) { - if (strstr($ref, 'tx_templavoila_tmplobj_')) { - $value1 = $params['row']['tx_templavoila_to']; - $value2 = ($params['table'] == 'pages' ? $params['row']['tx_templavoila_next_to'] : -1); - $test = substr($ref, 23); - } - else { - $value1 = $params['row']['tx_templavoila_ds']; - $value2 = ($params['table'] == 'pages' ? $params['row']['tx_templavoila_next_ds'] : -1); - $test = substr($ref, 29); - } - - if ($test == $value1 || $test == $value2) { - continue; - } - - foreach ($params['items'] as $key => $item) { - if ($item[1] == $test) { - unset($params['items'][$key]); - } - } - } - } + protected function getRemoveItems($params, $field) { + $pid = $params['row'][$params['table'] == 'pages' ? 'uid' : 'pid']; + $modTSConfig = t3lib_BEfunc::getModTSconfig($pid, 'TCEFORM.' . $params['table'] . '.' . $field . '.removeItems'); + return t3lib_div::trimExplode(',', $modTSConfig['value'], TRUE); } } Index: classes/class.tx_templavoila_datastructure.php new file mode 100644 =================================================================== --- classes/class.tx_templavoila_datastructure.php (revision 32853) +++ classes/class.tx_templavoila_datastructure.php (working copy) @@ -0,0 +1,134 @@ + +* All rights reserved +* +* This script is part of the Typo3 project. The Typo3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + +/** + * Class to provide unique access to datastructure + * + * @author Tolleiv Nietsch + */ +abstract class tx_templavoila_datastructure { + + const SCOPE_UNKNOWN = 0; + const SCOPE_PAGE = 1; + const SCOPE_FCE = 2; + + protected $scope = self::SCOPE_UNKNOWN; + protected $label = ''; + protected $iconFile = ''; + + /** + * Retrieve the label of the datastructure + * + * @return string + */ + public function getLabel() { + return $GLOBALS['LANG']->sL($this->label); + } + + /** + * + * @param string $str + * @return void + */ + protected function setLabel($str) { + $this->label = $str; + } + + /** + * Retrieve the label of the datastructure + * + * @return string + */ + public function getScope() { + return $this->scope; + } + + /** + * + * @param integer $scope + * @return void + */ + protected function setScope($scope) { + if ($scope == self::SCOPE_PAGE || $scope == self::SCOPE_FCE) { + $this->scope = $scope; + } else { + $this->scope = self::SCOPE_UNKNOWN; + } + } + + /** + * However the datastructure is identifiable (uid or filepath + * This method deliver the relevant key + * + * @return string + */ + abstract public function getKey(); + + /** + * Determine the icon and append the path - relative to the TYPO3 main folder + * + * @return string + */ + public function getIcon() { + $icon = ''; + if ($this->iconFile) { + $icon = '../uploads/tx_templavoila/' . $this->iconFile; + } + return $icon; + } + + /** + * + * @param string $filename + * @return void + */ + protected function setIcon($filename) { + $this->iconFile = $filename; + } + + /** + * Determine relevant storage pids for this element, + * usually one uid but in certain situations this might contain multiple uids (see staticds) + * + * @return string + */ + abstract public function getStoragePids(); + + /** + * Determine whether the current user has permission to create elements based on this + * datastructure or not + * + * @param mixed $parentRow + * @param mixed $removeItems + * @return boolean + */ + abstract public function isPermittedForUser($parentRow = array(), $removeItems = array()); + +} + + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_datastructure.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_datastructure.php']); +} +?> \ No newline at end of file Index: classes/class.tx_templavoila_datastructureRepository.php new file mode 100644 =================================================================== --- classes/class.tx_templavoila_datastructureRepository.php (revision 32853) +++ classes/class.tx_templavoila_datastructureRepository.php (working copy) @@ -0,0 +1,181 @@ + +* All rights reserved +* +* This script is part of the Typo3 project. The Typo3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + +/** + * Class to provide unique access to datastructure + * + * @author Tolleiv Nietsch + */ +class tx_templavoila_datastructureRepository { + + /** + * Retrieve a single datastructure by uid or xml-file path + * + * @param integer $uid + * @return tx_templavoila_datastructure + */ + public function getDatastructureByUidOrFilename($uidOrFile) { + + $className = ''; + if(is_numeric($uidOrFile)) { + $className = 'tx_templavoila_datastructure_dbbase'; + } else if(($staticKey = $this->validateStaticDS($uidOrFile)) !== FALSE) { + $uidOrFile = $staticKey; + $className = 'tx_templavoila_datastructure_staticbase'; + } else { + throw new InvalidArgumentException( + 'Argument was supposed to be either a uid or a filename', + 1273409810 + ); + } + + $ds = null; + if(version_compare(TYPO3_version,'4.3.0','<')) { + $className = t3lib_div::makeInstanceClassName($className); + $ds = new $className($uidOrFile); + } else { + $ds = t3lib_div::makeInstance($className, $uidOrFile); + } + return $ds; + } + + /** + * Retrieve a collection (array) of tx_templavoila_datastructure objects + * + * @param integer $pid + * @return array + */ + public function getDatastructuresByStoragePid($pid) { + + $dscollection = array(); + if (is_array($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'])) { + $confArr = $GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures']; + foreach ($confArr as $key=>$conf) { + $ds = $this->getDatastructureByUidOrFilename($conf['path']); + $pids = $ds->getStoragePids(); + if ($pids == '' || t3lib_div::inList($pids, $pid)) { + $dscollection[] = $ds; + } + } + } + + if(!self::staticDsIsEnabled()) { + $dsRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( + 'uid', + 'tx_templavoila_datastructure', + 'pid=' . intval($pid) . t3lib_BEfunc::deleteClause('tx_templavoila_datastructure') + ); + foreach ($dsRows as $ds) { + $dscollection[] = $this->getDatastructureByUidOrFilename($ds['uid']); + } + } + usort($dscollection, array($this, 'sortDatastructures')); + return $dscollection; + } + + /** + * Retrieve a collection (array) of tx_templavoila_datastructure objects + * + * @param integer $pid + * @param integer $scope + * @return array + */ + public function getDatastructuresByStoragePidAndScope($pid, $scope) { + $dscollection = array(); + if (is_array($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'])) { + $confArr = $GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures']; + foreach ($confArr as $key=>$conf) { + if ($conf['scope'] == $scope) { + $ds = $this->getDatastructureByUidOrFilename($conf['path']); + $pids = $ds->getStoragePids(); + if ($pids == '' || t3lib_div::inList($pids, $pid)) { + $dscollection[] = $ds; + } + } + } + } + + if(!self::staticDsIsEnabled()) { + $dsRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( + 'uid', + 'tx_templavoila_datastructure', + 'scope=' . intval($scope) . ' AND pid=' . intval($pid) . t3lib_BEfunc::deleteClause('tx_templavoila_datastructure') + ); + foreach ($dsRows as $ds) { + $dscollection[] = $this->getDatastructureByUidOrFilename($ds['uid']); + } + } + usort($dscollection, array($this, 'sortDatastructures')); + return $dscollection; + } + + /** + * + * @param string $file + * @return mixed + */ + protected function validateStaticDS($file) { + if (!is_array($GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'])) { + return FALSE; + } + $confArr = $GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures']; + $confKey = FALSE; + $fileAbsName = t3lib_div::getFileAbsFileName($file); + foreach ($confArr as $key=>$conf) { + if (t3lib_div::getFileAbsFileName($conf['path']) == $fileAbsName) { + $confKey = $key; + break; + } + } + return $confKey; + } + + /** + * + * @return boolean + */ + protected function staticDsIsEnabled() { + $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['templavoila']); + return $extConf['staticDS.']['enable']; + } + + /** + * Sorts datastructure alphabetically + * + * @param tx_templavoila_datastructure $obj1 + * @param tx_templavoila_datastructure $obj2 + * @return int Result of the comparison (see strcmp()) + * @see usort() + * @see strcmp() + */ + public function sortDatastructures($obj1, $obj2) { + return strcmp(strtolower($obj1->getLabel()), strtolower($obj2->getLabel())); + } +} + + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_datastructureRepository.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_datastructureRepository.php']); +} +?> \ No newline at end of file Index: classes/class.tx_templavoila_datastructure_dbbase.php new file mode 100644 =================================================================== --- classes/class.tx_templavoila_datastructure_dbbase.php (revision 32853) +++ classes/class.tx_templavoila_datastructure_dbbase.php (working copy) @@ -0,0 +1,101 @@ + +* All rights reserved +* +* This script is part of the Typo3 project. The Typo3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + +/** + * Class to provide unique access to datastructure + * + * @author Tolleiv Nietsch + */ +class tx_templavoila_datastructure_dbbase extends tx_templavoila_datastructure { + + protected $row; + + /** + * + * @param integer $uid + */ + public function __construct($uid) { + $this->row = t3lib_beFunc::getRecordWSOL('tx_templavoila_datastructure', $uid); + + $this->setLabel($this->row['title']); + $this->setScope($this->row['scope']); + $this->setIcon($this->row['icon']); + } + + /** + * + * @return string; + */ + public function getStoragePids() { + return $this->row['pid']; + } + + /** + * + * @return string - numeric string + */ + public function getKey() { + return $this->row['uid']; + } + + /** + * Determine whether the current user has permission to create elements based on this + * datastructure or not + * + * @param mixed $parentRow + * @param mixed $removeItems + * @return boolean + */ + public function isPermittedForUser($parentRow = array(), $removeItems = array()) { + if ($GLOBALS['BE_USER']->isAdmin()) { + return TRUE; + } else if(in_array($this->getKey(), $removeItems)) { + return FALSE; + } + $permission = TRUE; + $denyItems = tx_templavoila_div::getDenyListForUser(); + + $currentSetting = $parentRow['tx_templavoila_ds']; + if ($this->getScope() == tx_templavoila_datastructure::SCOPE_PAGE) { + $inheritSetting = $parentRow['tx_templavoila_next_ds']; + } else { + $inheritSetting = -1; + } + + $key = 'tx_templavoila_datastructure:' . $this->getKey(); + if (in_array($key, $denyItems) && + $key != $currentSetting && + $key != $inheritSetting + ) { + $permission = FALSE; + } + return $permission; + } +} + + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_datastructure_dbbase.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_datastructure_dbbase.php']); +} +?> \ No newline at end of file Index: classes/class.tx_templavoila_datastructure_staticbase.php new file mode 100644 =================================================================== --- classes/class.tx_templavoila_datastructure_staticbase.php (revision 32853) +++ classes/class.tx_templavoila_datastructure_staticbase.php (working copy) @@ -0,0 +1,89 @@ + +* All rights reserved +* +* This script is part of the Typo3 project. The Typo3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + +/** + * Class to provide unique access to datastructure + * + * @author Tolleiv Nietsch + */ +class tx_templavoila_datastructure_staticbase extends tx_templavoila_datastructure { + + protected $filename; + /** + * + * @param integer $uid + */ + public function __construct($key) { + + $conf = $GLOBALS['TBE_MODULES_EXT']['xMOD_tx_templavoila_cm1']['staticDataStructures'][$key]; + + $this->filename = $conf['path']; + + $this->setLabel($conf['title']); + $this->setScope($conf['scope']); + } + + /** + * + * @return string; + */ + public function getStoragePids() { + $pids = array(); + $toList = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( + 'tx_templavoila_tmplobj.uid,tx_templavoila_tmplobj.pid', + 'tx_templavoila_tmplobj', + 'tx_templavoila_tmplobj.datastructure=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->filename, 'tx_templavoila_tmplobj') . t3lib_BEfunc::deleteClause('tx_templavoila_tmplobj') + ); + foreach ($toList as $toRow) { + $pids[$toRow['pid']]++; + } + return implode(',', array_keys($pids)); + } + + /** + * + * @return string - the filename + */ + public function getKey() { + return $this->filename; + } + + /** + * Determine whether the current user has permission to create elements based on this + * datastructure or not - not really useable for static datastructure but relevant for + * the overall system + * + * @param mixed $parentRow + * @param mixed $removeItems + * @return boolean + */ + public function isPermittedForUser($parentRow = array(), $removeItems = array()) { + return TRUE; + } +} + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_datastructure_staticbase.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_datastructure_staticbase.php']); +} +?> \ No newline at end of file Index: classes/class.tx_templavoila_div.php =================================================================== --- classes/class.tx_templavoila_div.php (revision 32853) +++ classes/class.tx_templavoila_div.php (working copy) @@ -118,5 +118,14 @@ final class tx_templavoila_div { return (stripos($url . '/', t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '/') === 0); } + public function getDenyListForUser() { + $denyItems = array(); + foreach ($GLOBALS['BE_USER']->userGroups as $group) { + $groupDenyItems = t3lib_div::trimExplode(',', $group['tx_templavoila_access'], true); + $denyItems = array_merge($denyItems, $groupDenyItems); + } + return $denyItems; + } + } ?> \ No newline at end of file Index: classes/class.tx_templavoila_template.php new file mode 100644 =================================================================== --- classes/class.tx_templavoila_template.php (revision 32853) +++ classes/class.tx_templavoila_template.php (working copy) @@ -0,0 +1,134 @@ + +* All rights reserved +* +* This script is part of the Typo3 project. The Typo3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + +/** + * Class to provide unique access to datastructure + * + * @author Tolleiv Nietsch + */ +class tx_templavoila_template { + + protected $row; + protected $label; + protected $iconFile; + + /** + * + * @param integer $uid + */ + public function __construct($uid) { + $this->row = t3lib_beFunc::getRecordWSOL('tx_templavoila_tmplobj', $uid); + + $this->setLabel($this->row['title']); + $this->setIcon($this->row['icon']); + } + + /** + * Retrieve the label of the template + * + * @return string + */ + public function getLabel() { + return $GLOBALS['LANG']->sL($this->label); + } + + /** + * + * @param string $str + * @return void + */ + protected function setLabel($str) { + $this->label = $str; + } + + /** + * Determine the icon and append the path - relative to the TYPO3 main folder + * + * @return string + */ + public function getIcon() { + $icon = ''; + if ($this->iconFile) { + $icon = '../uploads/tx_templavoila/' . $this->iconFile; + } + return $icon; + } + + /** + * + * @param string $filename + * @return void + */ + protected function setIcon($filename) { + $this->iconFile = $filename; + } + + /** + * + * @return string - numeric string + */ + public function getKey() { + return $this->row['uid']; + } + + /** + * Determine whether the current user has permission to create elements based on this + * template or not + * + * @param mixed $parentRow + * @param mixed $removeItems + * @return boolean + */ + public function isPermittedForUser($parentRow = array(), $removeItems = array()) { + if ($GLOBALS['BE_USER']->isAdmin()) { + return TRUE; + } else if(in_array($this->getKey(), $removeItems)) { + return FALSE; + } + $permission = TRUE; + $denyItems = tx_templavoila_div::getDenyListForUser(); + + $currentSetting = $parentRow['tx_templavoila_to']; + if ($this->getScope() == tx_templavoila_datastructure::SCOPE_PAGE) { + $inheritSetting = $parentRow['tx_templavoila_next_to']; + } else { + $inheritSetting = -1; + } + + $key = 'tx_templavoila_tmplobj:' . $this->getKey(); + if (in_array($key, $denyItems) && + $key != $currentSetting && + $key != $inheritSetting + ) { + $permission = FALSE; + } + return $permission; + } + +} + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_template.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_template.php']); +} +?> \ No newline at end of file Index: classes/class.tx_templavoila_templateRepository.php new file mode 100644 =================================================================== --- classes/class.tx_templavoila_templateRepository.php (revision 32853) +++ classes/class.tx_templavoila_templateRepository.php (working copy) @@ -0,0 +1,87 @@ + +* All rights reserved +* +* This script is part of the Typo3 project. The Typo3 project is +* free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* The GNU General Public License can be found at +* http://www.gnu.org/copyleft/gpl.html. +* +* This script is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* This copyright notice MUST APPEAR in all copies of the script! +***************************************************************/ + +/** + * Class to provide unique access to datastructure + * + * @author Tolleiv Nietsch + */ +class tx_templavoila_templateRepository { + + /** + * Retrieve a single datastructure by uid or xml-file path + * + * @param integer $uid + * @return tx_templavoila_datastructure + */ + public function getTemplateByUid($uid) { + $to = null; + if(version_compare(TYPO3_version,'4.3.0','<')) { + $className = t3lib_div::makeInstanceClassName('tx_templavoila_template'); + $to = new $className($uid); + } else { + $to = t3lib_div::makeInstance('tx_templavoila_template', $uid); + } + return $to; + } + + /** + * Retrieve a single datastructure by uid or xml-file path + * + * @param integer $uid + * @return tx_templavoila_datastructure + */ + public function getTemplatesByDatastructure(tx_templavoila_datastructure $ds) { + $toList = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows ( + 'tx_templavoila_tmplobj.uid', + 'tx_templavoila_tmplobj', + 'tx_templavoila_tmplobj.datastructure=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($ds->getKey(), 'tx_templavoila_tmplobj') . t3lib_BEfunc::deleteClause('tx_templavoila_tmplobj') + ); + $toCollection = array(); + foreach ($toList as $toRec) { + $toCollection[] = $this->getTemplateByUid($toRec['uid']); + } + usort($toCollection, array($this, 'sortTemplates')); + return $toCollection; + } + + /** + * Sorts datastructure alphabetically + * + * @param tx_templavoila_template $obj1 + * @param tx_templavoila_template $obj2 + * @return int Result of the comparison (see strcmp()) + * @see usort() + * @see strcmp() + */ + public function sortTemplates($obj1, $obj2) { + return strcmp(strtolower($obj1->getLabel()), strtolower($obj2->getLabel())); + } +} + + +if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_templateRepository.php']) { + include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/templavoila/classes/class.tx_templavoila_templateRepository.php']); +} +?> \ No newline at end of file Index: ext_autoload.php =================================================================== --- ext_autoload.php (revision 32853) +++ ext_autoload.php (working copy) @@ -1,6 +1,6 @@ $extensionPath . 'class.tx_templavoila_unusedce.php', 'tx_templavoila_usedce' => $extensionPath . 'class.tx_templavoila_usedce.php', 'tx_templavoila_xmlrelhndl' => $extensionPath . 'class.tx_templavoila_xmlrelhndl.php', + 'tx_templavoila_datastructure' => $extensionPath . 'classes/class.tx_templavoila_datastructure.php', + 'tx_templavoila_datastructurerepository' => $extensionPath . 'classes/class.tx_templavoila_datastructureRepository.php', + 'tx_templavoila_datastructure_dbbase' => $extensionPath . 'classes/class.tx_templavoila_datastructure_dbbase.php', + 'tx_templavoila_datastructure_staticbase' => $extensionPath . 'classes/class.tx_templavoila_datastructure_staticbase.php', 'tx_templavoila_div' => $extensionPath . 'classes/class.tx_templavoila_div.php', 'tx_templavoila_label' => $extensionPath . 'classes/class.tx_templavoila_label.php', + 'tx_templavoila_template' => $extensionPath . 'classes/class.tx_templavoila_template.php', + 'tx_templavoila_templaterepository' => $extensionPath . 'classes/class.tx_templavoila_templateRepository.php', 'tx_templavoila_preview_default' => $extensionPath . 'classes/preview/class.tx_templavoila_preview_default.php', 'tx_templavoila_preview_type_bullets' => $extensionPath . 'classes/preview/class.tx_templavoila_preview_type_bullets.php', 'tx_templavoila_preview_type_header' => $extensionPath . 'classes/preview/class.tx_templavoila_preview_type_header.php', @@ -57,4 +63,4 @@ return array( 'tx_templavoila_pi1' => $extensionPath . 'pi1/class.tx_templavoila_pi1.php', 'tx_templavoila_api_testcase' => $extensionPath . 'tests/tx_templavoila_api_testcase.php', ); -?> +?> \ No newline at end of file Index: ext_localconf.php =================================================================== --- ext_localconf.php (revision 32853) +++ ext_localconf.php (working copy) @@ -233,4 +233,14 @@ templavoila.wizards.newContentElement.wizardItems.special.elements.media { templavoila.wizards.newContentElement.wizardItems.special.show = uploads,media,menu,html,div '); } + +if(t3lib_div::int_from_ver(TYPO3_version) < 4003000) { + $list = include(t3lib_extMgm::extPath('templavoila') . '/ext_autoload.php'); + require_once $list['tx_templavoila_datastructure']; + require_once $list['tx_templavoila_datastructure_dbbase']; + require_once $list['tx_templavoila_datastructure_staticbase']; + require_once $list['tx_templavoila_datastructureRepository']; + require_once $list['tx_templavoila_templavoila']; + require_once $list['tx_templavoila_templavoilaRepository']; +} ?>