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