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