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