[TASK] Clean up phpDoc comments in typo3/sysext/
[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 'xml' => $GLOBALS['LANG']->getLL('xmlExport', TRUE)
156 ),
157
158 'sword' => ''
159 );
160 // CLEAN SETTINGS
161 $OLD_MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, '', $this->MCONF['name'], 'ses');
162 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name'], 'ses');
163
164 if (t3lib_div::_GP('queryConfig')) {
165 $qA = t3lib_div::_GP('queryConfig');
166 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, array('queryConfig'=>serialize($qA)), $this->MCONF['name'], 'ses');
167 }
168 $addConditionCheck = t3lib_div::_GP('qG_ins');
169 foreach ($OLD_MOD_SETTINGS as $key=>$val) {
170 if (substr($key, 0, 5)=='query' && $this->MOD_SETTINGS[$key]!=$val && $key!='queryLimit' && $key!='use_listview') {
171 $setLimitToStart = 1;
172 if ($key == 'queryTable' && !$addConditionCheck) {
173 $this->MOD_SETTINGS['queryConfig'] = '';
174 }
175 }
176 if ($key == 'queryTable' && $this->MOD_SETTINGS[$key]!=$val) {
177 $this->MOD_SETTINGS['queryFields'] = '';
178 }
179 }
180 if ($setLimitToStart) {
181 $currentLimit = explode(',', $this->MOD_SETTINGS['queryLimit']);
182 if ($currentLimit[1]) {
183 $this->MOD_SETTINGS['queryLimit']='0,'.$currentLimit[1];
184 } else {
185 $this->MOD_SETTINGS['queryLimit']='0';
186 }
187 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, $this->MOD_SETTINGS, $this->MCONF['name'], 'ses');
188 }
189 }
190
191 /**
192 * Main
193 *
194 * @return void
195 */
196 function main() {
197
198 // Content creation
199 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableTopMenu']) {
200 $this->menu = t3lib_BEfunc::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
201 }
202
203 switch($this->MOD_SETTINGS['function']) {
204 case 'search':
205 $this->func_search();
206 break;
207 case 'records':
208 $this->func_records();
209 break;
210 case 'relations':
211 $this->func_relations();
212 break;
213 case 'filesearch':
214 $this->func_filesearch();
215 break;
216 case 'refindex':
217 $this->func_refindex();
218 break;
219 default:
220 $this->func_default();
221 break;
222 }
223
224 // Setting up the buttons and markers for docheader
225 $docHeaderButtons = $this->getButtons();
226 $markers = array(
227 'CSH' => $docHeaderButtons['csh'],
228 'FUNC_MENU' => $this->getFuncMenu(),
229 'CONTENT' => $this->content
230 );
231
232 // Build the <body> for the module
233 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
234 // Renders the module page
235 $this->content = $this->doc->render(
236 $GLOBALS['LANG']->getLL('title'),
237 $this->content
238 );
239 }
240
241 /**
242 * Print content
243 *
244 * @return void
245 */
246 function printContent() {
247 echo $this->content;
248 }
249
250 /**
251 * Create the panel of buttons for submitting the form or otherwise perform operations.
252 *
253 * @return array All available buttons as an assoc. array
254 */
255 protected function getButtons() {
256
257 $buttons = array(
258 'csh' => '',
259 'shortcut' => ''
260 );
261
262 // Shortcut
263 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
264 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function,search,search_query_makeQuery', $this->MCONF['name']);
265 }
266 return $buttons;
267 }
268
269 /**
270 * Create the function menu
271 *
272 * @return string HTML of the function menu
273 */
274 protected function getFuncMenu() {
275 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableTopMenu']) {
276 $funcMenu = t3lib_BEfunc::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
277 }
278 return $funcMenu;
279 }
280
281 /**
282 * Creates the overview menu.
283 * @return void
284 */
285 protected function func_default() {
286 $availableModFuncs = array('records', 'relations', 'search', 'filesearch', 'refindex');
287
288 $content = '<dl class="t3-overview-list">';
289
290 foreach ($availableModFuncs as $modFunc) {
291 $functionUrl = t3lib_BEfunc::getModuleUrl('tools_dbint') . '&SET[function]=' . $modFunc;
292 $title = $GLOBALS['LANG']->getLL($modFunc);
293 $description = $GLOBALS['LANG']->getLL($modFunc . '_description');
294
295 $icon = '<img src="'
296 . t3lib_iconworks::skinImg($GLOBALS['BACK_PATH'], 'MOD:tools_dbint/db.gif', '', 1)
297 . '" width="16" height="16" title="' . $title . '" alt="' . $title
298 . '" />';
299
300 $content .= '
301 <dt><a href="' . htmlspecialchars($functionUrl) . '">' . $icon . $title . '</a></dt>
302 <dd>' . $description . '</dd>
303 ';
304 }
305
306 $content .= '</dl>';
307
308 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title'));
309 $this->content .= $this->doc->section('', $content, FALSE, TRUE);
310 }
311
312 /****************************
313 *
314 * Functionality implementation
315 *
316 ****************************/
317
318 /**
319 * Check and update reference index!
320 *
321 * @return void
322 */
323 function func_refindex() {
324 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('manageRefIndex', TRUE));
325
326 if (t3lib_div::_GP('_update') || t3lib_div::_GP('_check')) {
327 $testOnly = t3lib_div::_GP('_check')?TRUE:FALSE;
328
329 // Call the functionality
330 $refIndexObj = t3lib_div::makeInstance('t3lib_refindex');
331 list($headerContent, $bodyContent) = $refIndexObj->updateIndex($testOnly);
332
333 // Output content:
334 $this->content .= $this->doc->section('', str_replace(LF, '<br/>', $bodyContent), FALSE, TRUE);
335 }
336
337 // Output content:
338 $content = '<p>' . $GLOBALS['LANG']->getLL('referenceIndex_description') . '</p><br />';
339 $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 />';
340 $this->content.= $this->doc->section('', $content, FALSE, TRUE);
341
342 // Command Line Interface
343 $content = '';
344 $content .= '<p>' . $GLOBALS['LANG']->getLL('checkScript') . '</p>';
345 $content .= '<h4>' . $GLOBALS['LANG']->getLL('checkScript_check_description') . '</h4>' .
346 '<code>php ' . PATH_typo3 . 'cli_dispatch.phpsh lowlevel_refindex -c</code><br />';
347 $content .= '<h4>' . $GLOBALS['LANG']->getLL('checkScript_update_description') . '</h4>' .
348 '<code>php ' . PATH_typo3 . 'cli_dispatch.phpsh lowlevel_refindex -e</code><br /><br />';
349 $content .= '<div class="typo3-message message-information"><div class="message-body">' . $GLOBALS['LANG']->getLL('checkScript_information') . '</div></div>';
350 $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>';
351
352 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('checkScript_headline'), $content, FALSE, TRUE);
353 }
354
355 /**
356 * Search (Full / Advanced)
357 *
358 * @return void
359 */
360 function func_search() {
361 global $LANG;
362
363 $fullsearch = t3lib_div::makeInstance('t3lib_fullsearch');
364 $fullsearch->setFormName($this->formName);
365 $this->content.= $this->doc->header($GLOBALS['LANG']->getLL('search'));
366 $this->content.= $this->doc->spacer(5);
367
368 $menu2='';
369 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableTopMenu']) {
370 $menu2 = t3lib_BEfunc::getFuncMenu(0, 'SET[search]', $this->MOD_SETTINGS['search'], $this->MOD_MENU['search']);
371 }
372 if ($this->MOD_SETTINGS['search']=='query' && !$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableTopMenu']) {
373 $menu2 .= t3lib_BEfunc::getFuncMenu(0, 'SET[search_query_makeQuery]', $this->MOD_SETTINGS['search_query_makeQuery'], $this->MOD_MENU['search_query_makeQuery']) . '<br />';
374 }
375 if (!$GLOBALS['BE_USER']->userTS['mod.']['dbint.']['disableTopCheckboxes'] && $this->MOD_SETTINGS['search']=='query') {
376 $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 />';
377 $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 />';
378 $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 />';
379 $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 />';
380 $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>';
381 }
382
383 $this->content.= $this->doc->section('', $menu2).$this->doc->spacer(10);
384
385 switch($this->MOD_SETTINGS['search']) {
386 case 'query':
387 $this->content .= $fullsearch->queryMaker();
388 break;
389 case 'raw':
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 break;
394 }
395 }
396
397 /**
398 * Records overview
399 *
400 * @return void
401 */
402 function func_records() {
403 /** @var $admin t3lib_admin */
404 $admin = t3lib_div::makeInstance('t3lib_admin');
405 $admin->genTree_makeHTML = 0;
406 $admin->backPath = $GLOBALS['BACK_PATH'];
407 $admin->genTree(0, '');
408
409 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('records'));
410
411 // Pages stat
412 $codeArr = array();
413 $codeArr['tableheader'] = array('', $GLOBALS['LANG']->getLL('count'));
414 $i++;
415 $codeArr[$i][] = t3lib_iconWorks::getSpriteIconForRecord('pages', array());
416 $codeArr[$i][] = $GLOBALS['LANG']->getLL('total_pages');
417 $codeArr[$i][] = count($admin->page_idArray);
418 $i++;
419 if (t3lib_extMgm::isLoaded('cms')) {
420 $codeArr[$i][] = t3lib_iconWorks::getSpriteIconForRecord('pages', array('hidden' => 1));
421 $codeArr[$i][] = $GLOBALS['LANG']->getLL('hidden_pages');
422 $codeArr[$i][] = $admin->recStats['hidden'];
423 $i++;
424 }
425 $codeArr[$i][] = t3lib_iconWorks::getSpriteIconForRecord('pages', array('deleted' => 1));
426 $codeArr[$i][] = $GLOBALS['LANG']->getLL('deleted_pages');
427 $codeArr[$i][] = count($admin->recStats['deleted']['pages']);
428
429 $this->content.=$this->doc->section($GLOBALS['LANG']->getLL('pages'), $this->doc->table($codeArr), FALSE, TRUE);
430
431 // Doktype
432 $codeArr = array();
433 $codeArr['tableheader'] = array($GLOBALS['LANG']->getLL('doktype_value'), $GLOBALS['LANG']->getLL('count'));
434 $doktype = $GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'];
435 if (is_array($doktype)) {
436 foreach ($doktype as $n => $setup) {
437 if ($setup[1]!='--div--') {
438 $codeArr[$n][] = t3lib_iconWorks::getSpriteIconForRecord('pages', array('doktype' => $setup[1]));
439 $codeArr[$n][] = $GLOBALS['LANG']->sL($setup[0]) . ' (' . $setup[1] . ')';
440 $codeArr[$n][] = intval($admin->recStats['doktype'][$setup[1]]);
441 }
442 }
443 $this->content.=$this->doc->section($GLOBALS['LANG']->getLL('doktype'), $this->doc->table($codeArr), FALSE, TRUE);
444 }
445
446 // Tables and lost records
447 $id_list = '-1,0,' . implode(',', array_keys($admin->page_idArray));
448 $id_list = rtrim($id_list, ',');
449 $admin->lostRecords($id_list);
450
451 if ($admin->fixLostRecord(t3lib_div::_GET('fixLostRecords_table'), t3lib_div::_GET('fixLostRecords_uid'))) {
452 $admin = t3lib_div::makeInstance('t3lib_admin');
453 $admin->backPath = $BACK_PATH;
454 $admin->genTree(0, '');
455 $id_list = '-1,0,' . implode(',', array_keys($admin->page_idArray));
456 $id_list = rtrim($id_list, ',');
457 $admin->lostRecords($id_list);
458 }
459
460 $this->doc->table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist" style="width:700px!important;">';
461
462 $codeArr = array();
463 $codeArr['tableheader'] = array(
464 $GLOBALS['LANG']->getLL('label'),
465 $GLOBALS['LANG']->getLL('tablename'),
466 $GLOBALS['LANG']->getLL('total_lost'),
467 ''
468 );
469
470 $countArr = $admin->countRecords($id_list);
471 if (is_array($GLOBALS['TCA'])) {
472
473 foreach ($GLOBALS['TCA'] as $t => $value) {
474 if ($GLOBALS['TCA'][$t]['ctrl']['hideTable']) {
475 continue;
476 }
477 $codeArr[$t][]=t3lib_iconWorks::getSpriteIconForRecord($t, array());
478 $codeArr[$t][] = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$t]['ctrl']['title']);
479 $codeArr[$t][]=$t;
480
481 if ($t === 'pages' && $admin->lostPagesList !== '') {
482 $lostRecordCount = count(explode(',', $admin->lostPagesList));
483 } else {
484 $lostRecordCount = count($admin->lRecords[$t]);
485 }
486
487 if ($countArr['all'][$t]) {
488 $theNumberOfRe = intval($countArr['non_deleted'][$t]) . '/' . $lostRecordCount;
489 } else {
490 $theNumberOfRe ='';
491 }
492 $codeArr[$t][] = $theNumberOfRe;
493
494 $lr = '';
495 if (is_array($admin->lRecords[$t])) {
496 foreach ($admin->lRecords[$t] as $data) {
497 if (!t3lib_div::inList($admin->lostPagesList, $data[pid])) {
498 $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>';
499 } else {
500 $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>';
501 }
502 }
503 }
504 $codeArr[$t][]=$lr;
505 }
506 $this->content.=$this->doc->section($GLOBALS['LANG']->getLL('tables'), $this->doc->table($codeArr), FALSE, TRUE);
507 }
508 }
509
510 /**
511 * Show list references
512 *
513 * @return void
514 */
515 function func_relations() {
516 global $LANG,$BACK_PATH;
517
518 $this->content.= $this->doc->header($GLOBALS['LANG']->getLL('relations'));
519
520 $admin = t3lib_div::makeInstance('t3lib_admin');
521 $admin->genTree_makeHTML=0;
522 $admin->backPath = $BACK_PATH;
523
524 $fkey_arrays = $admin->getGroupFields('');
525 $admin->selectNonEmptyRecordsWithFkeys($fkey_arrays);
526
527 $fileTest = $admin->testFileRefs();
528
529 $code = '';
530 if (is_array($fileTest['noReferences'])) {
531 foreach ($fileTest['noReferences'] as $val) {
532 $code .= '<nobr>' . $val[0] . '/<strong>' . $val[1] . '</strong></nobr><br>';
533 }
534 } else {
535 $code = $GLOBALS['LANG']->getLL('no_files_found');
536 }
537 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('files_no_ref'), $code, FALSE, TRUE);
538
539 $code = '';
540 if (is_array($fileTest['moreReferences'])) {
541 foreach ($fileTest['moreReferences'] as $val) {
542 $code.='<nobr>' . $val[0] . '/<strong>' . $val[1] . '</strong>: ' . $val[2] . ' ' . $GLOBALS['LANG']->getLL('references') . '</nobr><br>' . $val[3] . '<br><br>';
543 }
544 } else {
545 $code = $GLOBALS['LANG']->getLL('no_files_found');
546 }
547 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('files_many_ref'), $code, FALSE, TRUE);
548
549 $code = '';
550 if (is_array($fileTest['noFile'])) {
551 ksort($fileTest['noFile']);
552 foreach ($fileTest['noFile'] as $val) {
553 $code.='<nobr>' . $val[0] . '/<strong>' . $val[1] . '</strong> ' . $GLOBALS['LANG']->getLL('isMissing') . ' </nobr><br>' . $GLOBALS['LANG']->getLL('referencedFrom') . $val[2] . '<br><br>';
554 }
555 } else {
556 $code = $GLOBALS['LANG']->getLL('no_files_found');
557 }
558 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('files_no_file'), $code, FALSE, TRUE);
559 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('select_db'), $admin->testDBRefs($admin->checkSelectDBRefs), FALSE, TRUE);
560 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('group_db'), $admin->testDBRefs($admin->checkGroupDBRefs), FALSE, TRUE);
561 }
562
563 /**
564 * Searching for files with a specific pattern
565 *
566 * @return void
567 */
568 function func_filesearch() {
569 $pattern = t3lib_div::_GP('pattern');
570 $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') . '">';
571 $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('findFilename'));
572 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('pattern'), $pcontent, FALSE, TRUE);
573
574 if (strcmp($pattern, '')) {
575 $dirs = t3lib_div::get_dirs(PATH_site);
576 $lines = array();
577 $depth = 10;
578
579 foreach ($dirs as $key => $value) {
580 $matching_files = array();
581 $info = '';
582 if (!t3lib_div::inList('typo3,typo3conf,tslib,media,t3lib', $value)) {
583 $info = $this->findFile(PATH_site . $value . '/', $pattern, $matching_files, $depth);
584 }
585 if (is_array($info)) {
586 $lines[] = '<hr><strong>' . $value . '/</strong> ' . $GLOBALS['LANG']->getLL('beingChecked');
587 $lines[] = $GLOBALS['LANG']->getLL('directories') . ' ' . $info[0];
588 if ($info[2]) {
589 $lines[] = '<span class="typo3-red">' . $GLOBALS['LANG']->getLL('directoriesTooDeep') . ' ' . $depth . '</span>';
590 }
591 $lines[] = $GLOBALS['LANG']->getLL('files') . ' ' . $info[1];
592 $lines[] = $GLOBALS['LANG']->getLL('matchingFiles') . '<br><nobr><span class="typo3-red">' . implode('<br>', $matching_files) . '</span></nobr>';
593 } else {
594 $lines[] = $GLOBALS['TBE_TEMPLATE']->dfw('<hr><strong>' . $value . '/</strong> ' . $GLOBALS['LANG']->getLL('notChecked'));
595 }
596 }
597
598 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('searchingForFilenames'), implode('<br>', $lines), FALSE, TRUE);
599 }
600 }
601
602 /**
603 * Searching for filename pattern recursively in the specified dir.
604 *
605 * @param string $basedir Base directory
606 * @param string $pattern Match pattern
607 * @param array $matching_files Array of matching files, passed by reference
608 * @param integer $depth Depth to recurse
609 * @return array Array with various information about the search result
610 * @see func_filesearch()
611 */
612 function findFile($basedir, $pattern, &$matching_files, $depth) {
613 $files_searched = 0;
614 $dirs_searched = 0;
615 $dirs_error = 0;
616
617 // Traverse files:
618 $files = t3lib_div::getFilesInDir($basedir, '', 1);
619 if (is_array($files)) {
620 $files_searched += count($files);
621 // Escape the regexp. Note: we cannot use preg_quote here because it will escape more than we need!
622 $regExpPattern = str_replace('/', '\\/', $pattern);
623 foreach ($files as $value) {
624 if (preg_match('/' . $regExpPattern . '/i', basename($value))) {
625 $matching_files[] = substr($value, strlen(PATH_site));
626 }
627 }
628 }
629
630 // Traverse subdirs
631 if ($depth > 0) {
632 $dirs = t3lib_div::get_dirs($basedir);
633 if (is_array($dirs)) {
634 $dirs_searched += count($dirs);
635
636 foreach ($dirs as $value) {
637 $inf = $this->findFile($basedir . $value . '/', $pattern, $matching_files, $depth-1);
638 $dirs_searched += $inf[0];
639 $files_searched += $inf[1];
640 $dirs_error = $inf[2];
641 }
642 }
643 } else {
644 $dirs = t3lib_div::get_dirs($basedir);
645 if (is_array($dirs) && count($dirs)) {
646 // Means error - there were further subdirs!
647 $dirs_error = 1;
648 }
649 }
650
651 return array($dirs_searched, $files_searched, $dirs_error);
652 }
653 }
654
655 // Make instance:
656 $SOBE = t3lib_div::makeInstance('SC_mod_tools_dbint_index');
657 $SOBE->init();
658 $SOBE->main();
659 $SOBE->printContent();
660
661 ?>