Feature #22388 » 14015.diff

Administrator Admin, 2010-04-07 01:26

View differences:

t3lib/class.t3lib_extmgm.php (working copy)
1500 1500
		}
1501 1501
		return $out;
1502 1502
	}
1503

  
1504
	/**
1505
	 * Adds a new content element to the TCA and new content wizard. Type, title, description, icon, and wizard icon can be provided or will be set based on convention.
1506
	 *
1507
	 * @param	string		The extension key providing the content element.
1508
	 * @param	string		The unique key for the content element.
1509
	 * @param	string		Optional path to the flexform file. If not set, EXT:{extensionKey}/{key}/flexform.xml will be used.
1510
	 * @param	string		Optional type for use in the new content wizard.
1511
	 * @param	string		Optional title. If not set, LLL:EXT:{extensionKey}/{key}/locallang.xml:tt_content.{key}.title will be used.
1512
	 * @param	string		Optional description. If not set, LLL:EXT:{extensionKey}/{key}/locallang.xml:tt_content.{key}.description will be used.
1513
	 * @param	string		Option icon path. If not set, EXT:{extensionKey}/{key}/icon.gif will be used.
1514
	 * @param	string		Option icon path. If not set, EXT:{extensionKey}/{key}/wizard-icon.gif will be used.
1515
	 * @return	void
1516
	 */
1517
	public function addContentElement($extensionKey, $key, $flexformPath = '', $type = '', $title = '', $description = '', $icon = '', $wizardIcon = '') {
1518
		t3lib_div::loadTCA('tt_content');
1519

  
1520
			// Set defaults for title, description, icons, and content element type.
1521
		$locallangPath = 'LLL:EXT:' . $extensionKey . '/' . $key . '/locallang.xml:tt_content.' . $key . '.';
1522
		if (!$title) {
1523
			$title = $locallangPath . 'title';
1524
		}
1525
		if (!$description) {
1526
			$description = $locallangPath . 'description';
1527
		}
1528
		if (!$icon) {
1529
			$icon = 'EXT:' . $extensionKey . '/' . $key . '/icon.gif';
1530
		}
1531
		if (!$wizardIcon) {
1532
			$wizardIcon = t3lib_extMgm::extRelPath($extensionKey) . $key . '/wizard-icon.gif';
1533
		}
1534
		if (!$type) {
1535
			$type = 'special';
1536
		}
1537
		if (!$flexformPath && @file_exists(t3lib_extMgm::extPath($extensionKey) . $key . '/flexform.xml')) {
1538
			$flexformPath = 'FILE:EXT:' . $extensionKey . '/' . $key . '/flexform.xml';
1539
		}
1540

  
1541
		if ($flexformPath) {
1542
			$GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds']['*,' . $key] = $flexformPath;
1543
			$GLOBALS['TCA']['tt_content']['types'][$key] = array(
1544
				'showitem' => 'CType;;4;;1-1-1, hidden, header;;3;;2-2-2, linkToTop;;;;3-3-3, --div--;' . $title . ', pi_flexform;;;;1-1-1, --div--;LLL:EXT:cms/locallang_tca.xml:pages.tabs.access, starttime, endtime'
1545
			);
1546
		} else {
1547
			$GLOBALS['TCA']['tt_content']['types'][$key] = array(
1548
				'showitem' => 'CType;;4;;1-1-1, hidden, header;;3;;2-2-2, linkToTop;;;;3-3-3, --div--;LLL:EXT:cms/locallang_tca.xml:pages.tabs.access, starttime, endtime'
1549
			);
1550
		}
1551

  
1552
		t3lib_extMgm::addPlugin(array(
1553
			$title,
1554
			$key,
1555
			$icon
1556
		), 'CType');
1557

  
1558
		$TSConfig = 
1559
			'wizards.newContentElement.wizardItems.' . $type . ' {
1560
				elements {
1561
					' . $key . ' {
1562
						icon = ' . $wizardIcon . '
1563
						title = ' . $title . '
1564
						description = ' . $description . '
1565
						tt_content_defValues {
1566
							CType = ' . $key .'
1567
						}
1568
					}
1569
				}
1570
				show := addToList(' . $key .')
1571
			}';
1572

  
1573
		t3lib_extMgm::addPageTSConfig(
1574
			'mod.' . $TSConfig . chr(10) .
1575
			'templavoila.' . $TSConfig . chr(10)
1576
		);
1577
	}
1578

  
1579
	/**
1580
	 * Adds content to the default TypoScript setup by reading from a file.
1581
	 *
1582
	 * @param	string	The extension key providing the content element.
1583
	 * @param	string	The unique key for the content element.
1584
	 * @param	string	The path to the TypoScript file. If not set, EXT:{extensionKey}/{key}/content.ts will be used.
1585
	 * @return	void
1586
	 */
1587
	public function addTypoScriptFromFile($extensionKey, $key, $typoScriptPath = '') {
1588
		if (!$typoScriptPath) {
1589
			$typoScriptPath = t3lib_extMgm::extPath($extensionKey) . $key . '/content.ts';
1590
		}
1591

  
1592
		$type = 'CType';
1593
		$typoScriptContent = t3lib_div::getURL($typoScriptPath);
1594
		if ($typoScriptContent) {
1595
			t3lib_extMgm::addTypoScript($key, 'setup', '
1596
			# Setting ' . $key . ' TypoScript
1597
			' . $typoScriptContent . '
1598
			', 43);
1599
		}
1600
	}
1503 1601
}
1504 1602

  
1505 1603
?>
typo3/sysext/cms/tslib/class.tslib_content.php (working copy)
640 640
						case 'QTOBJECT':
641 641
							$content.=$this->QTOBJECT($conf);
642 642
						break;
643
						case 'FFSECTION':
644
							$content.=$this->FFSECTION($conf);
645
						break;
646
						case 'HEADERDATA':
647
							$content.=$this->HEADERDATA($conf);
648
						break;
643 649
						default:
644 650
								// call hook functions for extra processing
645 651
							if($name && is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClassDefault']))    {
......
2968 2974
		return $content;
2969 2975
	}
2970 2976

  
2977
	/**
2978
	 * Iterates over a flexform section, returning the combined output of all
2979
	 * elements within the specified section.
2980
	 *
2981
	 * @param	array	$conf: The TypoScript configuration.
2982
	 * @return	string
2983
	 *
2984
	 *
2985
	 * Example:
2986
	 *
2987
	 * 20 = FFSECTION
2988
	 * 20.rootPath = t3datastructure : pi_flexform->images/el
2989
	 * 20 {
2990
	 *   wrap = <ul id="gallery"> | </ul>
2991
	 *   20 = IMAGE
2992
	 *   20.file.import.data = flexformSection : image/el/path
2993
	 *   20.wrap = <li> | </li>
2994
	 * }
2995
	 *
2996
	 *
2997
	 */
2998
	public function FFSECTION(array $conf) {
2999
		$sectionArray = $this->getData($conf['rootPath'], $this->data);
3000
		$content = '';
3001
		if ($this->checkIf($conf['if.'])) {
3002
			foreach ($sectionArray as $index => $section) {
3003
				$this->sectionRootPath = $conf['rootPath'] . '/' . $index;
3004
				$content .= $this->cObjGet($conf);
3005
			}
2971 3006

  
3007
			if ($conf['wrap']) {
3008
				$content = $this->wrap($content, $conf['wrap']);
3009
			}
3010
			if ($conf['stdWrap.']) {
3011
				$content = $this->stdWrap($content, $conf['stdWrap.']);
3012
			}
3013
		}
2972 3014

  
3015
		return $content;
3016
	}
2973 3017

  
3018
	/**
3019
	 * Rendering the cObject HEADERDATA.
3020
	 * The result will not be outputted but added to the HTML HEAD section.
3021
	 *
3022
	 * @param	array		$conf: The TypoScript configuration.
3023
	 * @return	void
3024
	 */
3025
	public function HEADERDATA(array $conf) {
3026
		$additionalHeaderData = $this->stdWrap($conf['value'], $conf);
2974 3027

  
3028
		if ($additionalHeaderData !== '') {
3029
			$identifier = 'cObj.' . md5(trim($additionalHeaderData));
3030
			if (!isset($GLOBALS['TSFE']->additionalHeaderData[$identifier])) {
3031
				$GLOBALS['TSFE']->additionalHeaderData[$identifier] = $additionalHeaderData;
3032
			}
3033
		}
3034
	}
2975 3035

  
2976 3036

  
2977 3037

  
2978 3038

  
3039

  
3040

  
3041

  
2979 3042
	/************************************
2980 3043
	 *
2981 3044
	 * Various helper functions for content objects:
......
5651 5714
							break;
5652 5715
						}
5653 5716
					break;
5717
					case 't3datastructure':
5718
						list($fieldName, $path) = explode('->', $key, 2);
5719
						$flexFormArray = t3lib_div::xml2array($fieldArray[$fieldName]);
5720
						$retVal = $this->getFlexformValue($flexFormArray, $path);
5721
					break;
5722
					case 'flexformsection':
5723
						$rootPath = $this->sectionRootPath;
5724
						$retVal = $this->getData($rootPath . '/' . $key, $fieldArray);
5725
					break;
5654 5726
					case 'debug':
5655 5727
						switch((string)$key)	{
5656 5728
							case 'rootLine':
......
5803 5875
		return $returnValue;
5804 5876
	}
5805 5877

  
5878
	/**
5879
	 * Return value from somewhere inside a FlexForm structure
5880
	 *
5881
	 * @param	array		FlexForm data
5882
	 * @param	string		Field name to extract. Can be given like "test/el/2/test/el/field_templateObject" where each part will dig a level deeper in the FlexForm data.
5883
	 * @param	string		Sheet pointer, eg. "sDEF"
5884
	 * @param	string		Language pointer, eg. "lDEF"
5885
	 * @param	string		Value pointer, eg. "vDEF"
5886
	 * @return	string		The content.
5887
	 * @see tslib_pibase->pi_getFFvalue()
5888
	 */
5889
	protected function getFlexFormValue($flexFormArray, $fieldName, $sheet='sDEF', $lang='lDEF', $value='vDEF') {
5890
		$sheetArray = is_array($flexFormArray) ? $flexFormArray['data'][$sheet][$lang] : '';
5891
		if (is_array($sheetArray)) {
5892
			return $this->getFlexFormValueFromSheetArray($sheetArray, explode('/',$fieldName), $value);
5893
		}
5894
	}
5806 5895

  
5896
	/**
5897
	 * Returns part of $sheetArray pointed to by the keys in $fieldNameArray
5898
	 *
5899
	 * @param	array		Multidimensiona array, typically FlexForm contents
5900
	 * @param	array		Array where each value points to a key in the FlexForms content - the input array will have the value returned pointed to by these keys. All integer keys will not take their integer counterparts, but rather traverse the current position in the array an return element number X (whether this is right behavior is not settled yet...)
5901
	 * @param	string		Value for outermost key, typ. "vDEF" depending on language.
5902
	 * @return	mixed		The value, typ. string.
5903
	 * @access private
5904
	 * @see pi_getFFvalueFromSheetArray()
5905
	 */
5906
	protected function getFlexFormValueFromSheetArray($sheetArray, $fieldNameArr, $value) {
5907
		$tempArr = $sheetArray;
5908
		foreach($fieldNameArr as $k => $v)	{
5909
			if (t3lib_div::testInt($v))	{
5910
				if (is_array($tempArr))	{
5911
					foreach($tempArr as $index => $values) {
5912
						if ($index==$v)	{
5913
							$tempArr=$values;
5914
							break;
5915
						}
5916
					}
5917
				}
5918
			} else {
5919
				$tempArr = $tempArr[$v];
5920
			}
5921
		}
5922
		if (isset($tempArr[$value])) {
5923
			return $tempArr[$value];
5924
		} else {
5925
			return $tempArr;
5926
		}
5927
	}
5807 5928

  
5808 5929

  
5809 5930

  
(2-2/2)