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