7562ca4dc3d479145cec709f742c14f017496cf8
[Packages/TYPO3.CMS.git] / typo3 / sysext / integrity / Classes / View / DatabaseIntegrityView.php
1 <?php
2 namespace TYPO3\CMS\Integrity\View;
3
4 /**
5 * Script class for the DB int module
6 *
7 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
8 * @package TYPO3
9 * @subpackage tx_lowlevel
10 */
11 class DatabaseIntegrityView {
12
13 /**
14 * @todo Define visibility
15 */
16 public $MCONF = array();
17
18 /**
19 * @todo Define visibility
20 */
21 public $MOD_MENU = array();
22
23 /**
24 * @todo Define visibility
25 */
26 public $MOD_SETTINGS = array();
27
28 /**
29 * Document template object
30 *
31 * @var \TYPO3\CMS\Backend\Template\MediumDocumentTemplate
32 * @todo Define visibility
33 */
34 public $doc;
35
36 /**
37 * @todo Define visibility
38 */
39 public $content;
40
41 /**
42 * @todo Define visibility
43 */
44 public $menu;
45
46 protected $formName = 'queryform';
47
48 /**
49 * Initialization
50 *
51 * @return void
52 * @todo Define visibility
53 */
54 public function init() {
55 global $LANG, $BACK_PATH;
56 $this->MCONF = $GLOBALS['MCONF'];
57 $this->menuConfig();
58 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
59 $this->doc->backPath = $BACK_PATH;
60 $this->doc->setModuleTemplate('templates/dbint.html');
61 $this->doc->form = '<form action="" method="post" name="' . $this->formName . '">';
62 // JavaScript
63 $this->doc->JScode = '
64 <script language="javascript" type="text/javascript">
65 script_ended = 0;
66 function jumpToUrl(URL) {
67 window.location.href = URL;
68 }
69 </script>
70 ';
71 $this->doc->table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist" style="width:400px!important;">
72 <colgroup><col width="24"><col width="300"><col width="76"></colgroup>';
73 $this->doc->tableLayout = array(
74 '0' => array(
75 'defCol' => array('<td class="t3-row-header"><img src="' . $this->doc->backPath . 'clear.gif" width="10" height="1" alt="" /></td><td valign="top" class="t3-row-header"><strong>', '</strong></td>')
76 ),
77 'defRow' => array(
78 '0' => array('<td valign="top">', '</td>'),
79 '1' => array('<td valign="top">', '</td>'),
80 'defCol' => array('<td><img src="' . $this->doc->backPath . 'clear.gif" width="15" height="1" alt="" /></td><td valign="top">', '</td>')
81 )
82 );
83 }
84
85 /**
86 * Configure menu
87 *
88 * @return void
89 * @todo Define visibility
90 */
91 public function menuConfig() {
92 global $LANG;
93 // MENU-ITEMS:
94 // If array, then it's a selector box menu
95 // If empty string it's just a variable, that'll be saved.
96 // Values NOT in this array will not be saved in the settings-array for the module.
97 $this->MOD_MENU = array(
98 'function' => array(
99 0 => $GLOBALS['LANG']->getLL('menu', TRUE),
100 'records' => $GLOBALS['LANG']->getLL('recordStatistics', TRUE),
101 'relations' => $GLOBALS['LANG']->getLL('databaseRelations', TRUE),
102 'search' => $GLOBALS['LANG']->getLL('fullSearch', TRUE),
103 'filesearch' => $GLOBALS['LANG']->getLL('findFilename', TRUE),
104 'refindex' => $GLOBALS['LANG']->getLL('manageRefIndex', TRUE)
105 ),
106 'search' => array(
107 'raw' => $GLOBALS['LANG']->getLL('rawSearch', TRUE),
108 'query' => $GLOBALS['LANG']->getLL('advancedQuery', TRUE)
109 ),
110 'search_query_smallparts' => '',
111 'search_result_labels' => '',
112 'labels_noprefix' => '',
113 'options_sortlabel' => '',
114 'show_deleted' => '',
115 'queryConfig' => '',
116 // Current query
117 'queryTable' => '',
118 // Current table
119 'queryFields' => '',
120 // Current tableFields
121 'queryLimit' => '',
122 // Current limit
123 'queryOrder' => '',
124 // Current Order field
125 'queryOrderDesc' => '',
126 // Current Order field descending flag
127 'queryOrder2' => '',
128 // Current Order2 field
129 'queryOrder2Desc' => '',
130 // Current Order2 field descending flag
131 'queryGroup' => '',
132 // Current Group field
133 'storeArray' => '',
134 // Used to store the available Query config memory banks
135 'storeQueryConfigs' => '',
136 // Used to store the available Query configs in memory
137 'search_query_makeQuery' => array(
138 'all' => $GLOBALS['LANG']->getLL('selectRecords', TRUE),
139 'count' => $GLOBALS['LANG']->getLL('countResults', TRUE),
140 'explain' => $GLOBALS['LANG']->getLL('explainQuery', TRUE),
141 'csv' => $GLOBALS['LANG']->getLL('csvExport', TRUE)
142 ),
143 'sword' => ''
144 );
145 // CLEAN SETTINGS
146 $OLD_MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData($this->MOD_MENU, '', $this->MCONF['name'], 'ses');
147 $this->MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData($this->MOD_MENU, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SET'), $this->MCONF['name'], 'ses');
148 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('queryConfig')) {
149 $qA = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('queryConfig');
150 $this->MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData($this->MOD_MENU, array('queryConfig' => serialize($qA)), $this->MCONF['name'], 'ses');
151 }
152 $addConditionCheck = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('qG_ins');
153 foreach ($OLD_MOD_SETTINGS as $key => $val) {
154 if (substr($key, 0, 5) == 'query' && $this->MOD_SETTINGS[$key] != $val && $key != 'queryLimit' && $key != 'use_listview') {
155 $setLimitToStart = 1;
156 if ($key == 'queryTable' && !$addConditionCheck) {
157 $this->MOD_SETTINGS['queryConfig'] = '';
158 }
159 }
160 if ($key == 'queryTable' && $this->MOD_SETTINGS[$key] != $val) {
161 $this->MOD_SETTINGS['queryFields'] = '';
162 }
163 }
164 if ($setLimitToStart) {
165 $currentLimit = explode(',', $this->MOD_SETTINGS['queryLimit']);
166 if ($currentLimit[1]) {
167 $this->MOD_SETTINGS['queryLimit'] = '0,' . $currentLimit[1];
168 } else {
169 $this->MOD_SETTINGS['queryLimit'] = '0';
170 }
171 $this->MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData($this->MOD_MENU, $this->MOD_SETTINGS, $this->MCONF['name'], 'ses');
172 }
173 }
174
175 /**
176 * Main
177 *
178 * @return void
179 * @todo Define visibility
180 */
181 public function main() {
182 // Content creation
183 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableTopMenu']) {
184 $this->menu = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
185 }
186 switch ($this->MOD_SETTINGS['function']) {
187 case 'search':
188 $this->func_search();
189 break;
190 case 'records':
191 $this->func_records();
192 break;
193 case 'relations':
194 $this->func_relations();
195 break;
196 case 'filesearch':
197 $this->func_filesearch();
198 break;
199 case 'refindex':
200 $this->func_refindex();
201 break;
202 default:
203 $this->func_default();
204 break;
205 }
206 // Setting up the buttons and markers for docheader
207 $docHeaderButtons = $this->getButtons();
208 $markers = array(
209 'CSH' => $docHeaderButtons['csh'],
210 'FUNC_MENU' => $this->getFuncMenu(),
211 'CONTENT' => $this->content
212 );
213 // Build the <body> for the module
214 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
215 // Renders the module page
216 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
217 }
218
219 /**
220 * Print content
221 *
222 * @return void
223 * @todo Define visibility
224 */
225 public function printContent() {
226 echo $this->content;
227 }
228
229 /**
230 * Create the panel of buttons for submitting the form or otherwise perform operations.
231 *
232 * @return array All available buttons as an assoc. array
233 */
234 protected function getButtons() {
235 $buttons = array(
236 'csh' => '',
237 'shortcut' => ''
238 );
239 // Shortcut
240 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
241 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function,search,search_query_makeQuery', $this->MCONF['name']);
242 }
243 return $buttons;
244 }
245
246 /**
247 * Create the function menu
248 *
249 * @return string HTML of the function menu
250 */
251 protected function getFuncMenu() {
252 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableTopMenu']) {
253 $funcMenu = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
254 }
255 return $funcMenu;
256 }
257
258 /**
259 * Creates the overview menu.
260 *
261 * @return void
262 */
263 protected function func_default() {
264 $availableModFuncs = array('records', 'relations', 'search', 'filesearch', 'refindex');
265 $content = '<dl class="t3-overview-list">';
266 foreach ($availableModFuncs as $modFunc) {
267 $functionUrl = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('tools_dbint') . '&SET[function]=' . $modFunc;
268 $title = $GLOBALS['LANG']->getLL($modFunc);
269 $description = $GLOBALS['LANG']->getLL($modFunc . '_description');
270 $icon = '<img src="' . \t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], 'MOD:tools_dbint/db.gif', '', 1) . '" width="16" height="16" title="' . $title . '" alt="' . $title . '" />';
271 $content .= '
272 <dt><a href="' . htmlspecialchars($functionUrl) . '">' . $icon . $title . '</a></dt>
273 <dd>' . $description . '</dd>
274 ';
275 }
276 $content .= '</dl>';
277 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title'));
278 $this->content .= $this->doc->section('', $content, FALSE, TRUE);
279 }
280
281 /****************************
282 *
283 * Functionality implementation
284 *
285 ****************************/
286 /**
287 * Check and update reference index!
288 *
289 * @return void
290 * @todo Define visibility
291 */
292 public function func_refindex() {
293 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('manageRefIndex', TRUE));
294 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('_update') || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('_check')) {
295 $testOnly = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('_check') ? TRUE : FALSE;
296 // Call the functionality
297 $refIndexObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex');
298 list($headerContent, $bodyContent) = $refIndexObj->updateIndex($testOnly);
299 // Output content:
300 $this->content .= $this->doc->section('', str_replace(LF, '<br/>', $bodyContent), FALSE, TRUE);
301 }
302 // Output content:
303 $content = '<p>' . $GLOBALS['LANG']->getLL('referenceIndex_description') . '</p><br />';
304 $content .= '<input type="submit" name="_check" value="' . $GLOBALS['LANG']->getLL('referenceIndex_buttonCheck') . '" /> <input type="submit" name="_update" value="' . $GLOBALS['LANG']->getLL('referenceIndex_buttonUpdate') . '" /><br /><br />';
305 $this->content .= $this->doc->section('', $content, FALSE, TRUE);
306 // Command Line Interface
307 $content = '';
308 $content .= '<p>' . $GLOBALS['LANG']->getLL('checkScript') . '</p>';
309 $content .= '<h4>' . $GLOBALS['LANG']->getLL('checkScript_check_description') . '</h4>' . '<code>php ' . PATH_typo3 . 'cli_dispatch.phpsh lowlevel_refindex -c</code><br />';
310 $content .= '<h4>' . $GLOBALS['LANG']->getLL('checkScript_update_description') . '</h4>' . '<code>php ' . PATH_typo3 . 'cli_dispatch.phpsh lowlevel_refindex -e</code><br /><br />';
311 $content .= '<div class="typo3-message message-information"><div class="message-body">' . $GLOBALS['LANG']->getLL('checkScript_information') . '</div></div>';
312 $content .= '<p>' . $GLOBALS['LANG']->getLL('checkScript_moreDetails') . '<br /><a href="' . $GLOBALS['BACK_PATH'] . 'sysext/lowlevel/HOWTO_clean_up_TYPO3_installations.txt" target="_new">' . PATH_typo3 . 'sysext/lowlevel/HOWTO_clean_up_TYPO3_installations.txt</a></p>';
313 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('checkScript_headline'), $content, FALSE, TRUE);
314 }
315
316 /**
317 * Search (Full / Advanced)
318 *
319 * @return void
320 * @todo Define visibility
321 */
322 public function func_search() {
323 global $LANG;
324 $fullsearch = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\QueryView');
325 $fullsearch->setFormName($this->formName);
326 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('search'));
327 $this->content .= $this->doc->spacer(5);
328 $menu2 = '';
329 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableTopMenu']) {
330 $menu2 = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu(0, 'SET[search]', $this->MOD_SETTINGS['search'], $this->MOD_MENU['search']);
331 }
332 if ($this->MOD_SETTINGS['search'] == 'query' && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableTopMenu']) {
333 $menu2 .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu(0, 'SET[search_query_makeQuery]', $this->MOD_SETTINGS['search_query_makeQuery'], $this->MOD_MENU['search_query_makeQuery']) . '<br />';
334 }
335 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableTopCheckboxes'] && $this->MOD_SETTINGS['search'] == 'query') {
336 $menu2 .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($GLOBALS['SOBE']->id, 'SET[search_query_smallparts]', $this->MOD_SETTINGS['search_query_smallparts'], '', '', 'id="checkSearch_query_smallparts"') . '&nbsp;<label for="checkSearch_query_smallparts">' . $GLOBALS['LANG']->getLL('showSQL') . '</label><br />';
337 $menu2 .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($GLOBALS['SOBE']->id, 'SET[search_result_labels]', $this->MOD_SETTINGS['search_result_labels'], '', '', 'id="checkSearch_result_labels"') . '&nbsp;<label for="checkSearch_result_labels">' . $GLOBALS['LANG']->getLL('useFormattedStrings') . '</label><br />';
338 $menu2 .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($GLOBALS['SOBE']->id, 'SET[labels_noprefix]', $this->MOD_SETTINGS['labels_noprefix'], '', '', 'id="checkLabels_noprefix"') . '&nbsp;<label for="checkLabels_noprefix">' . $GLOBALS['LANG']->getLL('dontUseOrigValues') . '</label><br />';
339 $menu2 .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($GLOBALS['SOBE']->id, 'SET[options_sortlabel]', $this->MOD_SETTINGS['options_sortlabel'], '', '', 'id="checkOptions_sortlabel"') . '&nbsp;<label for="checkOptions_sortlabel">' . $GLOBALS['LANG']->getLL('sortOptions') . '</label><br />';
340 $menu2 .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($GLOBALS['SOBE']->id, 'SET[show_deleted]', $this->MOD_SETTINGS['show_deleted'], '', '', 'id="checkShow_deleted"') . '&nbsp;<label for="checkShow_deleted">' . $GLOBALS['LANG']->getLL('showDeleted') . '</label>';
341 }
342 $this->content .= $this->doc->section('', $menu2) . $this->doc->spacer(10);
343 switch ($this->MOD_SETTINGS['search']) {
344 case 'query':
345 $this->content .= $fullsearch->queryMaker();
346 break;
347 case 'raw':
348
349 default:
350 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('searchOptions'), $fullsearch->form(), FALSE, TRUE);
351 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('result'), $fullsearch->search(), FALSE, TRUE);
352 break;
353 }
354 }
355
356 /**
357 * Records overview
358 *
359 * @return void
360 * @todo Define visibility
361 */
362 public function func_records() {
363 /** @var $admin \TYPO3\CMS\Core\Integrity\DatabaseIntegrityCheck */
364 $admin = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Integrity\\DatabaseIntegrityCheck');
365 $admin->genTree_makeHTML = 0;
366 $admin->backPath = $GLOBALS['BACK_PATH'];
367 $admin->genTree(0, '');
368 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('records'));
369 // Pages stat
370 $codeArr = array();
371 $codeArr['tableheader'] = array('', $GLOBALS['LANG']->getLL('count'));
372 $i++;
373 $codeArr[$i][] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', array());
374 $codeArr[$i][] = $GLOBALS['LANG']->getLL('total_pages');
375 $codeArr[$i][] = count($admin->page_idArray);
376 $i++;
377 if (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('cms')) {
378 $codeArr[$i][] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', array('hidden' => 1));
379 $codeArr[$i][] = $GLOBALS['LANG']->getLL('hidden_pages');
380 $codeArr[$i][] = $admin->recStats['hidden'];
381 $i++;
382 }
383 $codeArr[$i][] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', array('deleted' => 1));
384 $codeArr[$i][] = $GLOBALS['LANG']->getLL('deleted_pages');
385 $codeArr[$i][] = count($admin->recStats['deleted']['pages']);
386 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('pages'), $this->doc->table($codeArr), FALSE, TRUE);
387 // Doktype
388 $codeArr = array();
389 $codeArr['tableheader'] = array($GLOBALS['LANG']->getLL('doktype_value'), $GLOBALS['LANG']->getLL('count'));
390 $doktype = $GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'];
391 if (is_array($doktype)) {
392 foreach ($doktype as $n => $setup) {
393 if ($setup[1] != '--div--') {
394 $codeArr[$n][] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', array('doktype' => $setup[1]));
395 $codeArr[$n][] = $GLOBALS['LANG']->sL($setup[0]) . ' (' . $setup[1] . ')';
396 $codeArr[$n][] = intval($admin->recStats['doktype'][$setup[1]]);
397 }
398 }
399 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('doktype'), $this->doc->table($codeArr), FALSE, TRUE);
400 }
401 // Tables and lost records
402 $id_list = '-1,0,' . implode(',', array_keys($admin->page_idArray));
403 $id_list = rtrim($id_list, ',');
404 $admin->lostRecords($id_list);
405 if ($admin->fixLostRecord(\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('fixLostRecords_table'), \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('fixLostRecords_uid'))) {
406 $admin = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Integrity\\DatabaseIntegrityCheck');
407 $admin->backPath = $BACK_PATH;
408 $admin->genTree(0, '');
409 $id_list = '-1,0,' . implode(',', array_keys($admin->page_idArray));
410 $id_list = rtrim($id_list, ',');
411 $admin->lostRecords($id_list);
412 }
413 $this->doc->table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist" style="width:700px!important;">';
414 $codeArr = array();
415 $codeArr['tableheader'] = array(
416 $GLOBALS['LANG']->getLL('label'),
417 $GLOBALS['LANG']->getLL('tablename'),
418 $GLOBALS['LANG']->getLL('total_lost'),
419 ''
420 );
421 $countArr = $admin->countRecords($id_list);
422 if (is_array($GLOBALS['TCA'])) {
423 foreach ($GLOBALS['TCA'] as $t => $value) {
424 if ($GLOBALS['TCA'][$t]['ctrl']['hideTable']) {
425 continue;
426 }
427 $codeArr[$t][] = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($t, array());
428 $codeArr[$t][] = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$t]['ctrl']['title']);
429 $codeArr[$t][] = $t;
430 if ($t === 'pages' && $admin->lostPagesList !== '') {
431 $lostRecordCount = count(explode(',', $admin->lostPagesList));
432 } else {
433 $lostRecordCount = count($admin->lRecords[$t]);
434 }
435 if ($countArr['all'][$t]) {
436 $theNumberOfRe = intval($countArr['non_deleted'][$t]) . '/' . $lostRecordCount;
437 } else {
438 $theNumberOfRe = '';
439 }
440 $codeArr[$t][] = $theNumberOfRe;
441 $lr = '';
442 if (is_array($admin->lRecords[$t])) {
443 foreach ($admin->lRecords[$t] as $data) {
444 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($admin->lostPagesList, $data[pid])) {
445 $lr .= '<nobr><strong><a href="' . htmlspecialchars((\TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('tools_dbint') . '&SET[function]=records&fixLostRecords_table=' . $t . '&fixLostRecords_uid=' . $data['uid'])) . '"><img src="' . $BACK_PATH . 'gfx/required_h.gif" width="10" hspace="3" height="10" border="0" align="top" title="' . $GLOBALS['LANG']->getLL('fixLostRecord') . '"></a>uid:' . $data['uid'] . ', pid:' . $data['pid'] . ', ' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(strip_tags($data['title']), 20)) . '</strong></nobr><br>';
446 } else {
447 $lr .= '<nobr><img src="' . $BACK_PATH . 'clear.gif" width="16" height="1" border="0"><font color="Gray">uid:' . $data['uid'] . ', pid:' . $data['pid'] . ', ' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(strip_tags($data['title']), 20)) . '</font></nobr><br>';
448 }
449 }
450 }
451 $codeArr[$t][] = $lr;
452 }
453 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('tables'), $this->doc->table($codeArr), FALSE, TRUE);
454 }
455 }
456
457 /**
458 * Show list references
459 *
460 * @return void
461 * @todo Define visibility
462 */
463 public function func_relations() {
464 global $LANG, $BACK_PATH;
465 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('relations'));
466 $admin = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Integrity\\DatabaseIntegrityCheck');
467 $admin->genTree_makeHTML = 0;
468 $admin->backPath = $BACK_PATH;
469 $fkey_arrays = $admin->getGroupFields('');
470 $admin->selectNonEmptyRecordsWithFkeys($fkey_arrays);
471 $fileTest = $admin->testFileRefs();
472 $code = '';
473 if (is_array($fileTest['noReferences'])) {
474 foreach ($fileTest['noReferences'] as $val) {
475 $code .= '<nobr>' . $val[0] . '/<strong>' . $val[1] . '</strong></nobr><br>';
476 }
477 } else {
478 $code = $GLOBALS['LANG']->getLL('no_files_found');
479 }
480 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('files_no_ref'), $code, FALSE, TRUE);
481 $code = '';
482 if (is_array($fileTest['moreReferences'])) {
483 foreach ($fileTest['moreReferences'] as $val) {
484 $code .= '<nobr>' . $val[0] . '/<strong>' . $val[1] . '</strong>: ' . $val[2] . ' ' . $GLOBALS['LANG']->getLL('references') . '</nobr><br>' . $val[3] . '<br><br>';
485 }
486 } else {
487 $code = $GLOBALS['LANG']->getLL('no_files_found');
488 }
489 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('files_many_ref'), $code, FALSE, TRUE);
490 $code = '';
491 if (is_array($fileTest['noFile'])) {
492 ksort($fileTest['noFile']);
493 foreach ($fileTest['noFile'] as $val) {
494 $code .= '<nobr>' . $val[0] . '/<strong>' . $val[1] . '</strong> ' . $GLOBALS['LANG']->getLL('isMissing') . ' </nobr><br>' . $GLOBALS['LANG']->getLL('referencedFrom') . $val[2] . '<br><br>';
495 }
496 } else {
497 $code = $GLOBALS['LANG']->getLL('no_files_found');
498 }
499 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('files_no_file'), $code, FALSE, TRUE);
500 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('select_db'), $admin->testDBRefs($admin->checkSelectDBRefs), FALSE, TRUE);
501 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('group_db'), $admin->testDBRefs($admin->checkGroupDBRefs), FALSE, TRUE);
502 }
503
504 /**
505 * Searching for files with a specific pattern
506 *
507 * @return void
508 * @todo Define visibility
509 */
510 public function func_filesearch() {
511 $pattern = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pattern');
512 $pcontent = $GLOBALS['LANG']->getLL('enterRegexPattern') . ' <input type="text" name="pattern" value="' . htmlspecialchars(($pattern ? $pattern : $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'])) . '"> <input type="submit" name="' . $GLOBALS['LANG']->getLL('SearchButton') . '">';
513 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('findFilename'));
514 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('pattern'), $pcontent, FALSE, TRUE);
515 if (strcmp($pattern, '')) {
516 $dirs = \TYPO3\CMS\Core\Utility\GeneralUtility::get_dirs(PATH_site);
517 $lines = array();
518 $depth = 10;
519 foreach ($dirs as $key => $value) {
520 $matching_files = array();
521 $info = '';
522 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList('typo3,typo3conf,tslib,media,t3lib', $value)) {
523 $info = $this->findFile(PATH_site . $value . '/', $pattern, $matching_files, $depth);
524 }
525 if (is_array($info)) {
526 $lines[] = '<hr><strong>' . $value . '/</strong> ' . $GLOBALS['LANG']->getLL('beingChecked');
527 $lines[] = $GLOBALS['LANG']->getLL('directories') . ' ' . $info[0];
528 if ($info[2]) {
529 $lines[] = '<span class="typo3-red">' . $GLOBALS['LANG']->getLL('directoriesTooDeep') . ' ' . $depth . '</span>';
530 }
531 $lines[] = $GLOBALS['LANG']->getLL('files') . ' ' . $info[1];
532 $lines[] = $GLOBALS['LANG']->getLL('matchingFiles') . '<br><nobr><span class="typo3-red">' . implode('<br>', $matching_files) . '</span></nobr>';
533 } else {
534 $lines[] = $GLOBALS['TBE_TEMPLATE']->dfw('<hr><strong>' . $value . '/</strong> ' . $GLOBALS['LANG']->getLL('notChecked'));
535 }
536 }
537 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('searchingForFilenames'), implode('<br>', $lines), FALSE, TRUE);
538 }
539 }
540
541 /**
542 * Searching for filename pattern recursively in the specified dir.
543 *
544 * @param string $basedir Base directory
545 * @param string $pattern Match pattern
546 * @param array $matching_files Array of matching files, passed by reference
547 * @param integer $depth Depth to recurse
548 * @return array Array with various information about the search result
549 * @see func_filesearch()
550 * @todo Define visibility
551 */
552 public function findFile($basedir, $pattern, &$matching_files, $depth) {
553 $files_searched = 0;
554 $dirs_searched = 0;
555 $dirs_error = 0;
556 // Traverse files:
557 $files = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($basedir, '', 1);
558 if (is_array($files)) {
559 $files_searched += count($files);
560 // Escape the regexp. Note: we cannot use preg_quote here because it will escape more than we need!
561 $regExpPattern = str_replace('/', '\\/', $pattern);
562 foreach ($files as $value) {
563 if (preg_match('/' . $regExpPattern . '/i', basename($value))) {
564 $matching_files[] = substr($value, strlen(PATH_site));
565 }
566 }
567 }
568 // Traverse subdirs
569 if ($depth > 0) {
570 $dirs = \TYPO3\CMS\Core\Utility\GeneralUtility::get_dirs($basedir);
571 if (is_array($dirs)) {
572 $dirs_searched += count($dirs);
573 foreach ($dirs as $value) {
574 $inf = $this->findFile($basedir . $value . '/', $pattern, $matching_files, $depth - 1);
575 $dirs_searched += $inf[0];
576 $files_searched += $inf[1];
577 $dirs_error = $inf[2];
578 }
579 }
580 } else {
581 $dirs = \TYPO3\CMS\Core\Utility\GeneralUtility::get_dirs($basedir);
582 if (is_array($dirs) && count($dirs)) {
583 // Means error - there were further subdirs!
584 $dirs_error = 1;
585 }
586 }
587 return array($dirs_searched, $files_searched, $dirs_error);
588 }
589
590 }
591
592
593 ?>