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