[TASK] Remove function index
[Packages/TYPO3.CMS.git] / typo3 / sysext / indexed_search / mod / 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: Indexing Engine Overview
29 *
30 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 */
32
33
34 unset($MCONF);
35 require('conf.php');
36 require($BACK_PATH . 'init.php');
37 require($BACK_PATH . 'template.php');
38 $BE_USER->modAccess($MCONF, 1);
39
40 t3lib_extMgm::isLoaded('indexed_search', 1);
41 require_once(t3lib_extMgm::extPath('indexed_search') . 'class.indexer.php');
42
43
44
45 /**
46 * Backend module providing boring statistics of the index-tables.
47 *
48 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
49 * @package TYPO3
50 * @subpackage tx_indexedsearch
51 */
52 class SC_mod_tools_isearch_index {
53 var $MCONF = array();
54 var $MOD_MENU = array();
55 var $MOD_SETTINGS = array();
56
57 /**
58 * document template object
59 *
60 * @var noDoc
61 */
62 var $doc;
63
64 var $include_once = array();
65 var $content;
66
67
68 /**
69 * Initialization
70 *
71 * @return void
72 */
73 function init() {
74 $this->MCONF = $GLOBALS['MCONF'];
75
76 $this->menuConfig();
77 $this->doc = t3lib_div::makeInstance('template');
78 $this->doc->form = '<form action="" method="post">';
79 $this->doc->backPath = $GLOBALS['BACK_PATH'];
80 $this->doc->setModuleTemplate(t3lib_extMgm::extRelPath('indexed_search') . '/mod/mod_template.html');
81
82 // JavaScript
83 $this->doc->JScodeArray['indexed_search'] = '
84 script_ended = 0;
85 function jumpToUrl(URL) {
86 window.location.href = URL;
87 }';
88
89 $this->doc->tableLayout = array(
90 'defRow' => array(
91 '0' => array('<td valign="top" nowrap>','</td>'),
92 'defCol' => array('<td><img src="' . $this->doc->backPath . 'clear.gif" width=10 height=1></td><td valign="top" nowrap>','</td>')
93 )
94 );
95
96 $indexer = t3lib_div::makeInstance('tx_indexedsearch_indexer');
97 $indexer->initializeExternalParsers();
98 }
99
100 /**
101 * MENU-ITEMS:
102 * If array, then it's a selector box menu
103 * If empty string it's just a variable, that'll be saved.
104 * Values NOT in this array will not be saved in the settings-array for the module.
105 *
106 * @return void
107 */
108 function menuConfig() {
109 $this->MOD_MENU = array(
110 'function' => array(
111 'stat' => 'General statistics',
112 'typo3pages' => 'List: TYPO3 Pages',
113 'externalDocs' => 'List: External documents',
114 )
115 );
116
117 // cleanse settings
118 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name'], 'ses');
119 }
120
121 /**
122 * Main function to generate the content
123 *
124 * @return void
125 */
126 function main() {
127 $this->content = $this->doc->header('Indexing Engine Statistics');
128 $this->content .= $this->doc->spacer(5);
129
130 switch($this->MOD_SETTINGS['function']) {
131 case 'stat':
132 $this->content .= $this->doc->section('Records', $this->doc->table($this->getRecordsNumbers()), 0, 1);
133 $this->content .= $this->doc->spacer(15);
134 $this->content .= $this->doc->section('index_phash TYPES', $this->doc->table($this->getPhashTypes()), 1);
135 $this->content .= $this->doc->spacer(15);
136 break;
137 case 'externalDocs':
138 $this->content .= $this->doc->section('External documents', $this->doc->table($this->getPhashExternalDocs()), 0, 1);
139 $this->content .= $this->doc->spacer(15);
140 break;
141 case 'typo3pages':
142 $this->content .= $this->doc->section('TYPO3 Pages', $this->doc->table($this->getPhashT3pages()), 0, 1);
143 $this->content .= $this->doc->spacer(15);
144 break;
145 }
146
147 $docHeaderButtons = $this->getButtons();
148 $markers = array(
149 'CSH' => $docHeaderButtons['csh'],
150 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
151 'CONTENT' => $this->content
152 );
153
154 $this->content = $this->doc->startPage('Indexing Engine Statistics');
155 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
156 $this->content .= $this->doc->endPage();
157 $this->content = $this->doc->insertStylesAndJS($this->content);
158 }
159
160 /**
161 * Print content
162 *
163 * @return void
164 */
165 function printContent() {
166 echo $this->content;
167 }
168
169 /**
170 * Create the panel of buttons for submitting the form or otherwise perform operations.
171 *
172 * @return array all available buttons as an assoc. array
173 */
174 protected function getButtons() {
175 $buttons = array(
176 'csh' => '',
177 'shortcut' => ''
178 );
179
180 // Shortcut
181 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
182 $buttons['shortcut'] = $this->doc->makeShortcutIcon('','function',$this->MCONF['name']);
183 }
184 return $buttons;
185 }
186
187
188
189
190
191
192
193
194 /***************************
195 *
196 * OTHER FUNCTIONS:
197 *
198 ***************************/
199
200 /**
201 * @return [type] ...
202 */
203 function getRecordsNumbers() {
204 $tables=explode(",","index_phash,index_words,index_rel,index_grlist,index_section,index_fulltext");
205 $recList=array();
206 foreach ($tables as $t) {
207 $recList[] = array(
208 $this->tableHead($t),
209 $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $t)
210 );
211 }
212 return $recList;
213 }
214
215 /**
216 * [Describe function...]
217 *
218 * @param [type] $str: ...
219 * @return [type] ...
220 */
221 function tableHead($str) {
222 return "<strong>".$str.":&nbsp;&nbsp;&nbsp;</strong>";
223 }
224
225 /**
226 * [Describe function...]
227 *
228 * @return [type] ...
229 */
230 function getPhashStat() {
231 $recList = array();
232
233 // TYPO3 pages, unique
234 $items = array();
235 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),phash', 'index_phash', 'data_page_id!=0', 'phash_grouping,pcount,phash');
236 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
237 $items[] = $row;
238 }
239 $recList[] = array($this->tableHead("TYPO3 pages"), count($items));
240
241 // TYPO3 pages:
242 $recList[] = array(
243 $this->tableHead("TYPO3 pages, raw"),
244 $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_phash', 'data_page_id!=0')
245 );
246
247 // External files, unique
248 $items = array();
249 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),phash', 'index_phash', 'data_filename!=\'\'', 'phash_grouping');
250 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
251 $recList[] = array($this->tableHead("External files"), $row[0]);
252
253 // External files
254 $recList[] = array(
255 $this->tableHead("External files, raw"),
256 $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_phash', 'data_filename!=\'\'')
257 );
258
259 return $recList;
260 }
261
262 /**
263 * [Describe function...]
264 *
265 * @return [type] ...
266 */
267 function getPhashT3pages() {
268 $recList[]=array(
269 $this->tableHead("id/type"),
270 $this->tableHead("Title"),
271 $this->tableHead("Size"),
272 $this->tableHead("Words"),
273 $this->tableHead("mtime"),
274 $this->tableHead("Indexed"),
275 $this->tableHead("Updated"),
276 $this->tableHead("Parsetime"),
277 $this->tableHead("#sec/gr/full"),
278 $this->tableHead("#sub"),
279 $this->tableHead("Lang"),
280 $this->tableHead("cHash"),
281 $this->tableHead("phash")
282 );
283
284 // TYPO3 pages, unique
285 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*) AS pcount,index_phash.*', 'index_phash', 'data_page_id!=0', 'phash_grouping,phash,cHashParams,data_filename,data_page_id,data_page_reg1,data_page_type,data_page_mp,gr_list,item_type,item_title,item_description,item_mtime,tstamp,item_size,contentHash,crdate,parsetime,sys_language_uid,item_crdate,externalUrl,recordUid,freeIndexUid,freeIndexSetId', 'data_page_id');
286 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
287
288 $cHash = count(unserialize($row["cHashParams"])) ? $this->formatCHash(unserialize($row["cHashParams"])) : "";
289 $grListRec = $this->getGrlistRecord($row["phash"]);
290 $recList[] = array(
291 $row["data_page_id"].($row["data_page_type"]?"/".$row["data_page_type"]:""),
292 htmlentities(t3lib_div::fixed_lgd_cs($row["item_title"],30)),
293 t3lib_div::formatSize($row["item_size"]),
294 $this->getNumberOfWords($row["phash"]),
295 t3lib_BEfunc::datetime($row["item_mtime"]),
296 t3lib_BEfunc::datetime($row["crdate"]),
297 ($row["tstamp"]!=$row["crdate"] ? t3lib_BEfunc::datetime($row["tstamp"]) : ""),
298 $row["parsetime"],
299 $this->getNumberOfSections($row["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row["phash"]),
300 $row["pcount"]."/".$this->formatFeGroup($grListRec),
301 $row["sys_language_uid"],
302 $cHash,
303 $row["phash"]
304 );
305
306 if ($row["pcount"]>1) {
307 $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_phash.*', 'index_phash', 'phash_grouping='.intval($row['phash_grouping']).' AND phash!='.intval($row['phash']));
308 while($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2)) {
309 $grListRec = $this->getGrlistRecord($row2["phash"]);
310 $recList[] = array(
311 "",
312 "",
313 t3lib_div::formatSize($row2["item_size"]),
314 $this->getNumberOfWords($row2["phash"]),
315 t3lib_BEfunc::datetime($row2["item_mtime"]),
316 t3lib_BEfunc::datetime($row2["crdate"]),
317 ($row2["tstamp"]!=$row2["crdate"] ? t3lib_BEfunc::datetime($row2["tstamp"]) : ""),
318 $row2["parsetime"],
319 $this->getNumberOfSections($row2["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row2["phash"]),
320 "-/".$this->formatFeGroup($grListRec),
321 "",
322 "",
323 $row2["phash"]
324 );
325 }
326 }
327 }
328 return $recList;
329 }
330
331 /**
332 * [Describe function...]
333 *
334 * @return [type] ...
335 */
336 function getPhashExternalDocs() {
337 $recList[]=array(
338 $this->tableHead("Filename"),
339 $this->tableHead("Size"),
340 $this->tableHead("Words"),
341 $this->tableHead("mtime"),
342 $this->tableHead("Indexed"),
343 $this->tableHead("Updated"),
344 $this->tableHead("Parsetime"),
345 $this->tableHead("#sec/gr/full"),
346 $this->tableHead("#sub"),
347 $this->tableHead("cHash"),
348 $this->tableHead("phash"),
349 $this->tableHead("Path")
350 );
351
352 // TYPO3 pages, unique
353 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*) AS pcount,index_phash.*', 'index_phash', 'item_type!=\'0\'', 'phash_grouping,phash,cHashParams,data_filename,data_page_id,data_page_reg1,data_page_type,data_page_mp,gr_list,item_type,item_title,item_description,item_mtime,tstamp,item_size,contentHash,crdate,parsetime,sys_language_uid,item_crdate,externalUrl,recordUid,freeIndexUid,freeIndexSetId', 'item_type');
354 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
355
356 $cHash = count(unserialize($row["cHashParams"])) ? $this->formatCHash(unserialize($row["cHashParams"])) : "";
357 $grListRec = $this->getGrlistRecord($row["phash"]);
358 $recList[]=array(
359 htmlentities(t3lib_div::fixed_lgd_cs($row["item_title"],30)),
360 t3lib_div::formatSize($row["item_size"]),
361 $this->getNumberOfWords($row["phash"]),
362 t3lib_BEfunc::datetime($row["item_mtime"]),
363 t3lib_BEfunc::datetime($row["crdate"]),
364 ($row["tstamp"]!=$row["crdate"] ? t3lib_BEfunc::datetime($row["tstamp"]) : ""),
365 $row["parsetime"],
366 $this->getNumberOfSections($row["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row["phash"]),
367 $row["pcount"],
368 $cHash,
369 $row["phash"],
370 htmlentities(t3lib_div::fixed_lgd_cs($row["data_filename"],100))
371 );
372
373 if ($row["pcount"]>1) {
374 $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_phash.*', 'index_phash', 'phash_grouping='.intval($row['phash_grouping']).' AND phash!='.intval($row['phash']));
375 while($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2)) {
376 $cHash = count(unserialize($row2["cHashParams"])) ? $this->formatCHash(unserialize($row2["cHashParams"])) : "";
377 $grListRec = $this->getGrlistRecord($row2["phash"]);
378 $recList[]=array(
379 "",
380 "",
381 $this->getNumberOfWords($row2["phash"]),
382 "",
383 t3lib_BEfunc::datetime($row2["crdate"]),
384 ($row2["tstamp"]!=$row2["crdate"] ? t3lib_BEfunc::datetime($row2["tstamp"]) : ""),
385 $row2["parsetime"],
386 $this->getNumberOfSections($row2["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row2["phash"]),
387 "",
388 $cHash,
389 $row2["phash"],
390 ""
391 );
392 }
393 }
394 // debug($row);
395 }
396 return $recList;
397 }
398
399 /**
400 * [Describe function...]
401 *
402 * @param [type] $fegroup_recs: ...
403 * @return [type] ...
404 */
405 function formatFeGroup($fegroup_recs) {
406 $str = array();
407 foreach ($fegroup_recs as $row) {
408 $str[] = $row["gr_list"]=="0,-1" ? "NL" : $row["gr_list"];
409 }
410 arsort($str);
411 return implode("|",$str);
412 }
413
414 /**
415 * [Describe function...]
416 *
417 * @param [type] $arr: ...
418 * @return [type] ...
419 */
420 function formatCHash($arr) {
421 $list = array();
422 foreach ($arr as $k => $v) {
423 $list[] = htmlspecialchars($k) . '=' . htmlspecialchars($v);
424 }
425 return implode('<br />', $list);
426 }
427
428 /**
429 * [Describe function...]
430 *
431 * @param [type] $phash: ...
432 * @return [type] ...
433 */
434 function getNumberOfSections($phash) {
435 return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_section', 'phash=' . intval($phash));
436 }
437
438 /**
439 * [Describe function...]
440 *
441 * @param [type] $phash: ...
442 * @return [type] ...
443 */
444 function getNumberOfWords($phash) {
445 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_rel', 'phash='.intval($phash));
446 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
447 return $row[0];
448 }
449
450 /**
451 * [Describe function...]
452 *
453 * @param [type] $phash: ...
454 * @return [type] ...
455 */
456 function getGrlistRecord($phash) {
457 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_grlist.*', 'index_grlist', 'phash='.intval($phash));
458 $allRows = array();
459 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
460 $row["pcount"] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
461 $allRows[] = $row;
462 }
463 return $allRows;
464 }
465
466 /**
467 * [Describe function...]
468 *
469 * @param [type] $phash: ...
470 * @return [type] ...
471 */
472 function getNumberOfFulltext($phash) {
473 return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_fulltext', 'phash=' . intval($phash));
474 }
475
476 /**
477 * [Describe function...]
478 *
479 * @return [type] ...
480 */
481 function getPhashTypes() {
482 $recList=array();
483
484 // Types:
485 $Itypes = array(
486 "html" => 1,
487 "htm" => 1,
488 "pdf" => 2,
489 "doc" => 3,
490 "txt" => 4
491 );
492
493 $revTypes=array_flip($Itypes);
494 $revTypes[0]="TYPO3 page";
495
496 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),item_type', 'index_phash', '', 'item_type', 'item_type');
497 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
498 $iT = $row[1];
499 $recList[] = array($this->tableHead($revTypes[$iT]." ($iT)"), $this->countUniqueTypes($iT)."/".$row[0]);
500 }
501
502 return $recList;
503 }
504
505 /**
506 * [Describe function...]
507 *
508 * @param [type] $item_type: ...
509 * @return [type] ...
510 */
511 function countUniqueTypes($item_type) {
512 // TYPO3 pages, unique
513 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_phash', 'item_type='.$GLOBALS['TYPO3_DB']->fullQuoteStr($item_type, 'index_phash'), 'phash_grouping');
514 $items = array();
515 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
516 $items[] = $row;
517 }
518 return count($items);
519 }
520 }
521
522
523 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/indexed_search/mod/index.php"]) {
524 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/indexed_search/mod/index.php"]);
525 }
526
527
528 // Make instance:
529 $SOBE = t3lib_div::makeInstance("SC_mod_tools_isearch_index");
530 $SOBE->init();
531 $SOBE->main();
532 $SOBE->printContent();
533
534 ?>