forked from Gernott/mask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathext_localconf.php
executable file
·198 lines (179 loc) · 9.03 KB
/
ext_localconf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
// initialize mask utility for various things
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Domain\\Repository\\StorageRepository');
$fieldHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Helper\\FieldHelper');
$typoScriptCodeGenerator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\CodeGenerator\\TyposcriptCodeGenerator');
$settingsService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MASK\\Mask\\Domain\\Service\\SettingsService');
$configuration = $storageRepository->load();
$settings = $settingsService->get();
// Register Icons needed in the backend module
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance("TYPO3\CMS\Core\Imaging\IconRegistry");
$maskIcons = array(
"Check",
"Date",
"Datetime",
"File",
"Float",
"Inline",
"Integer",
"Link",
"Radio",
"Richtext",
"Select",
"String",
"Tab",
"Text",
"Content"
);
foreach ($maskIcons as $maskIcon) {
$iconRegistry->registerIcon(
'mask-fieldtype-' . $maskIcon, 'TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider', array(
'source' => 'EXT:mask/Resources/Public/Icons/Fieldtypes/' . $maskIcon . '.svg'
)
);
}
// Add all the typoscript we need in the correct files
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:mask/Configuration/TypoScript/page.txt">');
$tsConfig = $typoScriptCodeGenerator->generateTsConfig($configuration);
$pageTs = $typoScriptCodeGenerator->generatePageTyposcript($configuration);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig($tsConfig);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig($pageTs);
$setupTs = $typoScriptCodeGenerator->generateSetupTyposcript($configuration, $settings);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup($setupTs);
// for conditions on tt_content
if (!function_exists('user_mask_contentType')) {
function user_mask_contentType($param = "")
{
static $cTypeCache = [];
if (isset($_REQUEST["edit"]["tt_content"]) && is_array($_REQUEST["edit"]["tt_content"])) {
$field = explode("|", $param);
$request = $_REQUEST;
$first = array_shift($request["edit"]["tt_content"]);
if ($first == "new") { // if new element
if ($_REQUEST["defVals"]["tt_content"]["CType"] == $field[1]) {
return true;
} else {
return false;
}
} else { // if element exists
$uid = intval(key($_REQUEST["edit"]["tt_content"]));
if (!isset($cTypeCache[$uid])) {
/** @var \TYPO3\CMS\Core\Database\ConnectionPool $connection */
$connection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class);
$queryBuilder = $connection->getQueryBuilderForTable('tt_content');
/** @var \TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction $deletedRestriction */
$deletedRestriction = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction::class);
$queryBuilder->getRestrictions()->removeAll()->add($deletedRestriction);
$cTypeCache[$uid] = $queryBuilder->select($field[0])
->from('tt_content')
->where($queryBuilder->expr()->eq('uid', $uid))
->execute()
->fetchColumn(0);
}
return $cTypeCache[$uid] == $field[1];
}
} else {
// if content element is loaded by ajax, then it's ok
if (is_array($_REQUEST["ajax"])) {
return true;
} else {
return false;
}
}
}
}
// for conditions on the backend-layouts
if (!function_exists('user_mask_beLayout')) {
function user_mask_beLayout($layout = null)
{
// get current page uid:
if (is_array($_REQUEST["data"]["pages"])) { // after saving page
$uid = intval(key($_REQUEST["data"]["pages"]));
} elseif ($GLOBALS["SOBE"]->editconf["pages"]) { // after opening pages
$uid = intval(key($GLOBALS["SOBE"]->editconf["pages"]));
} else {
if ($GLOBALS["_SERVER"]["HTTP_REFERER"] != "") {
$url = $GLOBALS["_SERVER"]["HTTP_REFERER"];
$queryString = parse_url($url, PHP_URL_QUERY);
$result = array();
parse_str($queryString, $result);
if ($result["id"]) {
$uid = (int)$result["id"];
}
}
}
if ($uid) {
/** @var \TYPO3\CMS\Core\Database\Connection $connection */
$connection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)->getConnectionForTable('pages');
$query = $connection->createQueryBuilder();
/** @var \TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction $deletedRestriction */
$deletedRestriction = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction::class);
$query->getRestrictions()->removeAll()->add($deletedRestriction);
$data = $query->select('backend_layout', 'backend_layout_next_level')
->from('pages')
->where($query->expr()->eq('uid', $uid))
->execute()
->fetch(\Doctrine\DBAL\FetchMode::ASSOCIATIVE);
$backend_layout = $data["backend_layout"];
$backend_layout_next_level = $data["backend_layout_next_level"];
if ($backend_layout !== "") { // If backend_layout is set on current page
if (in_array($backend_layout,
[$layout, "pagets__" . $layout])) { // Check backend_layout of current page
return true;
} else {
return false;
}
} elseif ($backend_layout_next_level !== "") { // If backend_layout_next_level is set on current page
if (in_array($backend_layout_next_level,
[$layout, "pagets__" . $layout])) { // Check backend_layout_next_level of current page
return true;
} else {
return false;
}
} else { // If backend_layout and backend_layout_next_level is not set on current page, check backend_layout_next_level on rootline
$sysPage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
try {
$rootline = $sysPage->getRootLine($uid, '');
} catch (Exception $e) {
$rootline = [];
}
foreach ($rootline as $page) {
if (in_array($page["backend_layout_next_level"], [$layout, "pagets__" . $layout])) {
return true;
}
}
return false;
}
} else {
return false;
}
}
}
// set root line fields
if ($json['pages']['tca']) {
$rootlineFields = explode(",", $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields']);
foreach ($json['pages']['tca'] as $fieldKey => $value) {
$formType = $fieldHelper->getFormType($fieldKey, "", "pages");
if ($formType !== "Tab") {
// Add addRootLineFields for all page fields
$rootlineFields[] = $fieldKey;
}
}
$GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] = implode(",", $rootlineFields);
}
// SQL inject:
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
$signalSlotDispatcher->connect('TYPO3\\CMS\\Install\\Service\\SqlExpectedSchemaService', 'tablesDefinitionIsBeingBuilt',
'MASK\\Mask\\CodeGenerator\\SqlCodeGenerator', 'addDatabaseTablesDefinition');
// Enhance Fluid Output with overridden FluidTemplateContentObject
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Frontend\\ContentObject\\FluidTemplateContentObject'] = array(
'className' => 'MASK\\Mask\\Fluid\\FluidTemplateContentObject'
);
// Hook to override tt_content backend_preview
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'][$_EXTKEY] = \MASK\Mask\Hooks\PageLayoutViewDrawItem::class;
// Hook to override colpos check for unused tt_content elements
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['record_is_used'] [] = MASK\Mask\Hooks\PageLayoutViewHook::class . '->contentIsUsed';