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