22656f1dfdde5cac92428584d1fa32a2faa06499
[TYPO3CMS/Extensions/contagged.git] / tx_contagged_userfunction.php
1 <?php
2
3 function user_addTermTypes(&$params, &$pObj) {
4 global $BE_USER;
5
6 $template = t3lib_div::makeInstance('t3lib_TStemplate');
7 $template->tt_track = 0;
8 $template->init();
9 $sysPage = t3lib_div::makeInstance('t3lib_pageSelect');
10 $rootline = $sysPage->getRootLine(getCurrentPageId());
11 $rootlineIndex = 0;
12 foreach ($rootline as $index => $rootlinePart) {
13 if ($rootlinePart['is_siteroot'] == 1) {
14 $rootlineIndex = $index;
15 break;
16 }
17 }
18 $template->runThroughTemplates($rootline, $rootlineIndex);
19 $template->generateConfig();
20 $conf = $template->setup['plugin.']['tx_contagged.'];
21
22 // make localized labels
23 $LOCAL_LANG_ARRAY = array();
24 if (!empty($conf['types.'])) {
25 foreach ($conf['types.'] as $typeName => $typeConfigArray) {
26 unset($LOCAL_LANG_ARRAY);
27 if (!$typeConfigArray['hideSelection'] > 0 && !$typeConfigArray['dataSource']) {
28 if (is_array($typeConfigArray['label.'])) {
29 foreach ($typeConfigArray['label.'] as $langKey => $labelText) {
30 $LOCAL_LANG_ARRAY[$langKey]['label'] = $labelText;
31 }
32 }
33 $LOCAL_LANG_ARRAY['default']['label'] = $typeConfigArray['label'] ? $typeConfigArray['label'] : $typeConfigArray['label.']['default'];
34 $params['items'][] = array($GLOBALS['LANG']->getLLL('label', $LOCAL_LANG_ARRAY), substr($typeName, 0, -1));
35 }
36 }
37 }
38 }
39
40 function getCurrentPageId() {
41 $pageId = (integer)t3lib_div::_GP('id');
42 if ($pageId > 0) {
43 return $pageId;
44 }
45
46 preg_match('/(?<=id=)[0-9]a/', urldecode(t3lib_div::_GET('returnUrl')), $matches);
47 if (count($matches) > 0) {
48 return $matches[0];
49 }
50
51 $rootTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1');
52 if (count($rootTemplates) > 0) {
53 return $rootTemplates[0]['pid'];
54 }
55
56 $rootPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1');
57 if (count($rootPages) > 0) {
58 return $rootPages[0]['uid'];
59 }
60
61 // take pid 1 as fallback
62 return 1;
63 }
64
65 ?>