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