|
1
|
|
|
<?php |
|
2
|
|
|
namespace Fab\Vidi\Utility; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the Fab/Vidi project under GPLv2 or later. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please read the |
|
8
|
|
|
* LICENSE.md file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
use Psr\Log\LoggerInterface; |
|
12
|
|
|
use TYPO3\CMS\Backend\Backend\Shortcut\ShortcutRepository; |
|
13
|
|
|
use TYPO3\CMS\Backend\Routing\UriBuilder; |
|
14
|
|
|
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; |
|
15
|
|
|
use TYPO3\CMS\Core\Cache\CacheManager; |
|
16
|
|
|
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; |
|
17
|
|
|
use TYPO3\CMS\Core\Core\Environment; |
|
18
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
|
19
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
20
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder; |
|
21
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryHelper; |
|
22
|
|
|
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction; |
|
23
|
|
|
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; |
|
24
|
|
|
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction; |
|
25
|
|
|
use TYPO3\CMS\Core\Database\RelationHandler; |
|
26
|
|
|
use TYPO3\CMS\Core\Exception\SiteNotFoundException; |
|
27
|
|
|
use TYPO3\CMS\Core\Http\ServerRequest; |
|
28
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
|
29
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
|
30
|
|
|
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection; |
|
31
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
|
32
|
|
|
use TYPO3\CMS\Core\Log\LogManager; |
|
33
|
|
|
use TYPO3\CMS\Core\Resource\AbstractFile; |
|
34
|
|
|
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException; |
|
35
|
|
|
use TYPO3\CMS\Core\Resource\File; |
|
36
|
|
|
use TYPO3\CMS\Core\Resource\ProcessedFile; |
|
37
|
|
|
use TYPO3\CMS\Core\Resource\ResourceFactory; |
|
38
|
|
|
use TYPO3\CMS\Core\Routing\InvalidRouteArgumentsException; |
|
39
|
|
|
use TYPO3\CMS\Core\Routing\RouterInterface; |
|
40
|
|
|
use TYPO3\CMS\Core\Routing\SiteMatcher; |
|
41
|
|
|
use TYPO3\CMS\Core\Site\Entity\PseudoSite; |
|
42
|
|
|
use TYPO3\CMS\Core\Site\Entity\Site; |
|
43
|
|
|
use TYPO3\CMS\Core\Site\SiteFinder; |
|
44
|
|
|
use TYPO3\CMS\Core\Type\Bitmask\Permission; |
|
45
|
|
|
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser; |
|
46
|
|
|
use TYPO3\CMS\Core\Utility\ArrayUtility; |
|
47
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
|
|
|
|
|
|
48
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
49
|
|
|
use TYPO3\CMS\Core\Utility\HttpUtility; |
|
50
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
|
51
|
|
|
use TYPO3\CMS\Core\Utility\PathUtility; |
|
52
|
|
|
use TYPO3\CMS\Core\Versioning\VersionState; |
|
53
|
|
|
use TYPO3\CMS\Frontend\Compatibility\LegacyDomainResolver; |
|
54
|
|
|
use TYPO3\CMS\Frontend\Page\PageRepository; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Standard functions available for the TYPO3 backend. |
|
58
|
|
|
* You are encouraged to use this class in your own applications (Backend Modules) |
|
59
|
|
|
* Don't instantiate - call functions with "\TYPO3\CMS\Backend\Utility\BackendUtility::" prefixed the function name. |
|
60
|
|
|
*/ |
|
61
|
|
|
class BackendUtility |
|
62
|
|
|
{ |
|
63
|
|
|
|
|
64
|
|
|
/******************************************* |
|
65
|
|
|
* |
|
66
|
|
|
* SQL-related, selecting records, searching |
|
67
|
|
|
* |
|
68
|
|
|
*******************************************/ |
|
69
|
|
|
/** |
|
70
|
|
|
* Returns the WHERE clause " AND NOT [tablename].[deleted-field]" if a deleted-field |
|
71
|
|
|
* is configured in $GLOBALS['TCA'] for the tablename, $table |
|
72
|
|
|
* This function should ALWAYS be called in the backend for selection on tables which |
|
73
|
|
|
* are configured in $GLOBALS['TCA'] since it will ensure consistent selection of records, |
|
74
|
|
|
* even if they are marked deleted (in which case the system must always treat them as non-existent!) |
|
75
|
|
|
* In the frontend a function, ->enableFields(), is known to filter hidden-field, start- and endtime |
|
76
|
|
|
* and fe_groups as well. But that is a job of the frontend, not the backend. If you need filtering |
|
77
|
|
|
* on those fields as well in the backend you can use ->BEenableFields() though. |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $table Table name present in $GLOBALS['TCA'] |
|
80
|
|
|
* @param string $tableAlias Table alias if any |
|
81
|
|
|
* @return string WHERE clause for filtering out deleted records, eg " AND tablename.deleted=0 |
|
82
|
|
|
*/ |
|
83
|
|
|
public static function deleteClause($table, $tableAlias = '') |
|
84
|
|
|
{ |
|
85
|
|
|
if (empty($GLOBALS['TCA'][$table]['ctrl']['delete'])) { |
|
86
|
|
|
return ''; |
|
87
|
|
|
} |
|
88
|
|
|
$expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
89
|
|
|
->getQueryBuilderForTable($table) |
|
90
|
|
|
->expr(); |
|
91
|
|
|
return ' AND ' . $expressionBuilder->eq( |
|
92
|
|
|
($tableAlias ?: $table) . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'], |
|
93
|
|
|
0 |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
/** |
|
97
|
|
|
* Backend implementation of enableFields() |
|
98
|
|
|
* Notice that "fe_groups" is not selected for - only disabled, starttime and endtime. |
|
99
|
|
|
* Notice that deleted-fields are NOT filtered - you must ALSO call deleteClause in addition. |
|
100
|
|
|
* $GLOBALS["SIM_ACCESS_TIME"] is used for date. |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $table The table from which to return enableFields WHERE clause. Table name must have a 'ctrl' section in $GLOBALS['TCA']. |
|
103
|
|
|
* @param bool $inv Means that the query will select all records NOT VISIBLE records (inverted selection) |
|
104
|
|
|
* @return string WHERE clause part |
|
105
|
|
|
*/ |
|
106
|
|
|
public static function BEenableFields($table, $inv = false) |
|
107
|
|
|
{ |
|
108
|
|
|
$ctrl = $GLOBALS['TCA'][$table]['ctrl']; |
|
109
|
|
|
$expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
110
|
|
|
->getConnectionForTable($table) |
|
111
|
|
|
->getExpressionBuilder(); |
|
112
|
|
|
$query = $expressionBuilder->andX(); |
|
113
|
|
|
$invQuery = $expressionBuilder->orX(); |
|
114
|
|
|
|
|
115
|
|
|
if (is_array($ctrl)) { |
|
116
|
|
|
if (is_array($ctrl['enablecolumns'])) { |
|
117
|
|
|
if ($ctrl['enablecolumns']['disabled'] ?? false) { |
|
118
|
|
|
$field = $table . '.' . $ctrl['enablecolumns']['disabled']; |
|
119
|
|
|
$query->add($expressionBuilder->eq($field, 0)); |
|
120
|
|
|
$invQuery->add($expressionBuilder->neq($field, 0)); |
|
121
|
|
|
} |
|
122
|
|
|
if ($ctrl['enablecolumns']['starttime'] ?? false) { |
|
123
|
|
|
$field = $table . '.' . $ctrl['enablecolumns']['starttime']; |
|
124
|
|
|
$query->add($expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME'])); |
|
125
|
|
|
$invQuery->add( |
|
126
|
|
|
$expressionBuilder->andX( |
|
127
|
|
|
$expressionBuilder->neq($field, 0), |
|
128
|
|
|
$expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME']) |
|
129
|
|
|
) |
|
130
|
|
|
); |
|
131
|
|
|
} |
|
132
|
|
|
if ($ctrl['enablecolumns']['endtime'] ?? false) { |
|
133
|
|
|
$field = $table . '.' . $ctrl['enablecolumns']['endtime']; |
|
134
|
|
|
$query->add( |
|
135
|
|
|
$expressionBuilder->orX( |
|
136
|
|
|
$expressionBuilder->eq($field, 0), |
|
137
|
|
|
$expressionBuilder->gt($field, (int)$GLOBALS['SIM_ACCESS_TIME']) |
|
138
|
|
|
) |
|
139
|
|
|
); |
|
140
|
|
|
$invQuery->add( |
|
141
|
|
|
$expressionBuilder->andX( |
|
142
|
|
|
$expressionBuilder->neq($field, 0), |
|
143
|
|
|
$expressionBuilder->lte($field, (int)$GLOBALS['SIM_ACCESS_TIME']) |
|
144
|
|
|
) |
|
145
|
|
|
); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
if ($query->count() === 0) { |
|
151
|
|
|
return ''; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
return ' AND ' . ($inv ? $invQuery : $query); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Returns the URL to a given module |
|
159
|
|
|
* |
|
160
|
|
|
* @param string $moduleName Name of the module |
|
161
|
|
|
* @param array $urlParameters URL parameters that should be added as key value pairs |
|
162
|
|
|
* @return string Calculated URL |
|
163
|
|
|
*/ |
|
164
|
|
|
public static function getModuleUrl($moduleName, $urlParameters = []) |
|
165
|
|
|
{ |
|
166
|
|
|
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
|
167
|
|
|
try { |
|
168
|
|
|
$uri = $uriBuilder->buildUriFromRoute($moduleName, $urlParameters); |
|
169
|
|
|
} catch (\TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException $e) { |
|
|
|
|
|
|
170
|
|
|
$uri = $uriBuilder->buildUriFromRoutePath($moduleName, $urlParameters); |
|
171
|
|
|
} |
|
172
|
|
|
return (string)$uri; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
} |
|
176
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: