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