|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 /** 00028 * Module: Indexing Engine Overview 00029 * 00030 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00031 */ 00032 /** 00033 * [CLASS/FUNCTION INDEX of SCRIPT] 00034 * 00035 * 00036 * 00037 * 83: class SC_mod_tools_isearch_index 00038 * 97: function init() 00039 * 110: function jumpToUrl(URL) 00040 * 133: function menuConfig() 00041 * 156: function main() 00042 * 193: function printContent() 00043 * 00044 * SECTION: OTHER FUNCTIONS: 00045 * 216: function getRecordsNumbers() 00046 * 234: function tableHead($str) 00047 * 243: function getPhashStat() 00048 * 278: function getPhashT3pages() 00049 * 347: function getPhashExternalDocs() 00050 * 416: function formatFeGroup($fegroup_recs) 00051 * 432: function formatCHash($arr) 00052 * 447: function getNumberOfSections($phash) 00053 * 459: function getNumberOfWords($phash) 00054 * 471: function getGrlistRecord($phash) 00055 * 487: function getNumberOfFulltext($phash) 00056 * 498: function getPhashTypes() 00057 * 528: function countUniqueTypes($item_type) 00058 * 00059 * TOTAL FUNCTIONS: 18 00060 * (This index is automatically created/updated by the extension "extdeveval") 00061 * 00062 */ 00063 00064 00065 unset($MCONF); 00066 require('conf.php'); 00067 require($BACK_PATH . 'init.php'); 00068 require($BACK_PATH . 'template.php'); 00069 $BE_USER->modAccess($MCONF, 1); 00070 00071 t3lib_extMgm::isLoaded('indexed_search', 1); 00072 require_once(t3lib_extMgm::extPath('indexed_search') . 'class.indexer.php'); 00073 00074 00075 00076 /** 00077 * Backend module providing boring statistics of the index-tables. 00078 * 00079 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00080 * @package TYPO3 00081 * @subpackage tx_indexedsearch 00082 */ 00083 class SC_mod_tools_isearch_index { 00084 var $MCONF = array(); 00085 var $MOD_MENU = array(); 00086 var $MOD_SETTINGS = array(); 00087 00088 /** 00089 * document template object 00090 * 00091 * @var noDoc 00092 */ 00093 var $doc; 00094 00095 var $include_once = array(); 00096 var $content; 00097 00098 00099 /** 00100 * Initialization 00101 * 00102 * @return void 00103 */ 00104 function init() { 00105 $this->MCONF = $GLOBALS['MCONF']; 00106 00107 $this->menuConfig(); 00108 $this->doc = t3lib_div::makeInstance('template'); 00109 $this->doc->form = '<form action="" method="post">'; 00110 $this->doc->backPath = $GLOBALS['BACK_PATH']; 00111 $this->doc->setModuleTemplate(t3lib_extMgm::extRelPath('indexed_search') . '/mod/mod_template.html'); 00112 00113 // JavaScript 00114 $this->doc->JScodeArray['indexed_search'] = ' 00115 script_ended = 0; 00116 function jumpToUrl(URL) { 00117 window.location.href = URL; 00118 }'; 00119 00120 $this->doc->tableLayout = array( 00121 'defRow' => array( 00122 '0' => array('<td valign="top" nowrap>','</td>'), 00123 'defCol' => array('<td><img src="' . $this->doc->backPath . 'clear.gif" width=10 height=1></td><td valign="top" nowrap>','</td>') 00124 ) 00125 ); 00126 00127 $indexer = t3lib_div::makeInstance('tx_indexedsearch_indexer'); 00128 $indexer->initializeExternalParsers(); 00129 } 00130 00131 /** 00132 * MENU-ITEMS: 00133 * If array, then it's a selector box menu 00134 * If empty string it's just a variable, that'll be saved. 00135 * Values NOT in this array will not be saved in the settings-array for the module. 00136 * 00137 * @return void 00138 */ 00139 function menuConfig() { 00140 $this->MOD_MENU = array( 00141 'function' => array( 00142 'stat' => 'General statistics', 00143 'typo3pages' => 'List: TYPO3 Pages', 00144 'externalDocs' => 'List: External documents', 00145 ) 00146 ); 00147 00148 // cleanse settings 00149 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name'], 'ses'); 00150 } 00151 00152 /** 00153 * Main function to generate the content 00154 * 00155 * @return void 00156 */ 00157 function main() { 00158 $this->content = $this->doc->header('Indexing Engine Statistics'); 00159 $this->content .= $this->doc->spacer(5); 00160 00161 switch($this->MOD_SETTINGS['function']) { 00162 case 'stat': 00163 $this->content .= $this->doc->section('Records', $this->doc->table($this->getRecordsNumbers()), 0, 1); 00164 $this->content .= $this->doc->spacer(15); 00165 $this->content .= $this->doc->section('index_phash TYPES', $this->doc->table($this->getPhashTypes()), 1); 00166 $this->content .= $this->doc->spacer(15); 00167 break; 00168 case 'externalDocs': 00169 $this->content .= $this->doc->section('External documents', $this->doc->table($this->getPhashExternalDocs()), 0, 1); 00170 $this->content .= $this->doc->spacer(15); 00171 break; 00172 case 'typo3pages': 00173 $this->content .= $this->doc->section('TYPO3 Pages', $this->doc->table($this->getPhashT3pages()), 0, 1); 00174 $this->content .= $this->doc->spacer(15); 00175 break; 00176 } 00177 00178 $docHeaderButtons = $this->getButtons(); 00179 $markers = array( 00180 'CSH' => $docHeaderButtons['csh'], 00181 'FUNC_MENU' => t3lib_BEfunc::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']), 00182 'CONTENT' => $this->content 00183 ); 00184 00185 $this->content = $this->doc->startPage('Indexing Engine Statistics'); 00186 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers); 00187 $this->content .= $this->doc->endPage(); 00188 $this->content = $this->doc->insertStylesAndJS($this->content); 00189 } 00190 00191 /** 00192 * Print content 00193 * 00194 * @return void 00195 */ 00196 function printContent() { 00197 echo $this->content; 00198 } 00199 00200 /** 00201 * Create the panel of buttons for submitting the form or otherwise perform operations. 00202 * 00203 * @return array all available buttons as an assoc. array 00204 */ 00205 protected function getButtons() { 00206 $buttons = array( 00207 'csh' => '', 00208 'shortcut' => '' 00209 ); 00210 00211 // Shortcut 00212 if ($GLOBALS['BE_USER']->mayMakeShortcut()) { 00213 $buttons['shortcut'] = $this->doc->makeShortcutIcon('','function',$this->MCONF['name']); 00214 } 00215 return $buttons; 00216 } 00217 00218 00219 00220 00221 00222 00223 00224 00225 /*************************** 00226 * 00227 * OTHER FUNCTIONS: 00228 * 00229 ***************************/ 00230 00231 /** 00232 * @return [type] ... 00233 */ 00234 function getRecordsNumbers() { 00235 $tables=explode(",","index_phash,index_words,index_rel,index_grlist,index_section,index_fulltext"); 00236 $recList=array(); 00237 foreach ($tables as $t) { 00238 $recList[] = array( 00239 $this->tableHead($t), 00240 $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $t) 00241 ); 00242 } 00243 return $recList; 00244 } 00245 00246 /** 00247 * [Describe function...] 00248 * 00249 * @param [type] $str: ... 00250 * @return [type] ... 00251 */ 00252 function tableHead($str) { 00253 return "<strong>".$str.": </strong>"; 00254 } 00255 00256 /** 00257 * [Describe function...] 00258 * 00259 * @return [type] ... 00260 */ 00261 function getPhashStat() { 00262 $recList = array(); 00263 00264 // TYPO3 pages, unique 00265 $items = array(); 00266 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),phash', 'index_phash', 'data_page_id!=0', 'phash_grouping,pcount,phash'); 00267 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) { 00268 $items[] = $row; 00269 } 00270 $recList[] = array($this->tableHead("TYPO3 pages"), count($items)); 00271 00272 // TYPO3 pages: 00273 $recList[] = array( 00274 $this->tableHead("TYPO3 pages, raw"), 00275 $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_phash', 'data_page_id!=0') 00276 ); 00277 00278 // External files, unique 00279 $items = array(); 00280 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),phash', 'index_phash', 'data_filename!=\'\'', 'phash_grouping'); 00281 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res); 00282 $recList[] = array($this->tableHead("External files"), $row[0]); 00283 00284 // External files 00285 $recList[] = array( 00286 $this->tableHead("External files, raw"), 00287 $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_phash', 'data_filename!=\'\'') 00288 ); 00289 00290 return $recList; 00291 } 00292 00293 /** 00294 * [Describe function...] 00295 * 00296 * @return [type] ... 00297 */ 00298 function getPhashT3pages() { 00299 $recList[]=array( 00300 $this->tableHead("id/type"), 00301 $this->tableHead("Title"), 00302 $this->tableHead("Size"), 00303 $this->tableHead("Words"), 00304 $this->tableHead("mtime"), 00305 $this->tableHead("Indexed"), 00306 $this->tableHead("Updated"), 00307 $this->tableHead("Parsetime"), 00308 $this->tableHead("#sec/gr/full"), 00309 $this->tableHead("#sub"), 00310 $this->tableHead("Lang"), 00311 $this->tableHead("cHash"), 00312 $this->tableHead("phash") 00313 ); 00314 00315 // TYPO3 pages, unique 00316 $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'); 00317 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00318 00319 $cHash = count(unserialize($row["cHashParams"])) ? $this->formatCHash(unserialize($row["cHashParams"])) : ""; 00320 $grListRec = $this->getGrlistRecord($row["phash"]); 00321 $recList[] = array( 00322 $row["data_page_id"].($row["data_page_type"]?"/".$row["data_page_type"]:""), 00323 htmlentities(t3lib_div::fixed_lgd_cs($row["item_title"],30)), 00324 t3lib_div::formatSize($row["item_size"]), 00325 $this->getNumberOfWords($row["phash"]), 00326 t3lib_BEfunc::datetime($row["item_mtime"]), 00327 t3lib_BEfunc::datetime($row["crdate"]), 00328 ($row["tstamp"]!=$row["crdate"] ? t3lib_BEfunc::datetime($row["tstamp"]) : ""), 00329 $row["parsetime"], 00330 $this->getNumberOfSections($row["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row["phash"]), 00331 $row["pcount"]."/".$this->formatFeGroup($grListRec), 00332 $row["sys_language_uid"], 00333 $cHash, 00334 $row["phash"] 00335 ); 00336 00337 if ($row["pcount"]>1) { 00338 $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_phash.*', 'index_phash', 'phash_grouping='.intval($row['phash_grouping']).' AND phash!='.intval($row['phash'])); 00339 while($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2)) { 00340 $grListRec = $this->getGrlistRecord($row2["phash"]); 00341 $recList[] = array( 00342 "", 00343 "", 00344 t3lib_div::formatSize($row2["item_size"]), 00345 $this->getNumberOfWords($row2["phash"]), 00346 t3lib_BEfunc::datetime($row2["item_mtime"]), 00347 t3lib_BEfunc::datetime($row2["crdate"]), 00348 ($row2["tstamp"]!=$row2["crdate"] ? t3lib_BEfunc::datetime($row2["tstamp"]) : ""), 00349 $row2["parsetime"], 00350 $this->getNumberOfSections($row2["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row2["phash"]), 00351 "-/".$this->formatFeGroup($grListRec), 00352 "", 00353 "", 00354 $row2["phash"] 00355 ); 00356 } 00357 } 00358 } 00359 return $recList; 00360 } 00361 00362 /** 00363 * [Describe function...] 00364 * 00365 * @return [type] ... 00366 */ 00367 function getPhashExternalDocs() { 00368 $recList[]=array( 00369 $this->tableHead("Filename"), 00370 $this->tableHead("Size"), 00371 $this->tableHead("Words"), 00372 $this->tableHead("mtime"), 00373 $this->tableHead("Indexed"), 00374 $this->tableHead("Updated"), 00375 $this->tableHead("Parsetime"), 00376 $this->tableHead("#sec/gr/full"), 00377 $this->tableHead("#sub"), 00378 $this->tableHead("cHash"), 00379 $this->tableHead("phash"), 00380 $this->tableHead("Path") 00381 ); 00382 00383 // TYPO3 pages, unique 00384 $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'); 00385 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00386 00387 $cHash = count(unserialize($row["cHashParams"])) ? $this->formatCHash(unserialize($row["cHashParams"])) : ""; 00388 $grListRec = $this->getGrlistRecord($row["phash"]); 00389 $recList[]=array( 00390 htmlentities(t3lib_div::fixed_lgd_cs($row["item_title"],30)), 00391 t3lib_div::formatSize($row["item_size"]), 00392 $this->getNumberOfWords($row["phash"]), 00393 t3lib_BEfunc::datetime($row["item_mtime"]), 00394 t3lib_BEfunc::datetime($row["crdate"]), 00395 ($row["tstamp"]!=$row["crdate"] ? t3lib_BEfunc::datetime($row["tstamp"]) : ""), 00396 $row["parsetime"], 00397 $this->getNumberOfSections($row["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row["phash"]), 00398 $row["pcount"], 00399 $cHash, 00400 $row["phash"], 00401 htmlentities(t3lib_div::fixed_lgd_cs($row["data_filename"],100)) 00402 ); 00403 00404 if ($row["pcount"]>1) { 00405 $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_phash.*', 'index_phash', 'phash_grouping='.intval($row['phash_grouping']).' AND phash!='.intval($row['phash'])); 00406 while($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2)) { 00407 $cHash = count(unserialize($row2["cHashParams"])) ? $this->formatCHash(unserialize($row2["cHashParams"])) : ""; 00408 $grListRec = $this->getGrlistRecord($row2["phash"]); 00409 $recList[]=array( 00410 "", 00411 "", 00412 $this->getNumberOfWords($row2["phash"]), 00413 "", 00414 t3lib_BEfunc::datetime($row2["crdate"]), 00415 ($row2["tstamp"]!=$row2["crdate"] ? t3lib_BEfunc::datetime($row2["tstamp"]) : ""), 00416 $row2["parsetime"], 00417 $this->getNumberOfSections($row2["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row2["phash"]), 00418 "", 00419 $cHash, 00420 $row2["phash"], 00421 "" 00422 ); 00423 } 00424 } 00425 // debug($row); 00426 } 00427 return $recList; 00428 } 00429 00430 /** 00431 * [Describe function...] 00432 * 00433 * @param [type] $fegroup_recs: ... 00434 * @return [type] ... 00435 */ 00436 function formatFeGroup($fegroup_recs) { 00437 $str = array(); 00438 foreach ($fegroup_recs as $row) { 00439 $str[] = $row["gr_list"]=="0,-1" ? "NL" : $row["gr_list"]; 00440 } 00441 arsort($str); 00442 return implode("|",$str); 00443 } 00444 00445 /** 00446 * [Describe function...] 00447 * 00448 * @param [type] $arr: ... 00449 * @return [type] ... 00450 */ 00451 function formatCHash($arr) { 00452 $list = array(); 00453 foreach ($arr as $k => $v) { 00454 $list[] = htmlspecialchars($k) . '=' . htmlspecialchars($v); 00455 } 00456 return implode('<br />', $list); 00457 } 00458 00459 /** 00460 * [Describe function...] 00461 * 00462 * @param [type] $phash: ... 00463 * @return [type] ... 00464 */ 00465 function getNumberOfSections($phash) { 00466 return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_section', 'phash=' . intval($phash)); 00467 } 00468 00469 /** 00470 * [Describe function...] 00471 * 00472 * @param [type] $phash: ... 00473 * @return [type] ... 00474 */ 00475 function getNumberOfWords($phash) { 00476 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_rel', 'phash='.intval($phash)); 00477 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res); 00478 return $row[0]; 00479 } 00480 00481 /** 00482 * [Describe function...] 00483 * 00484 * @param [type] $phash: ... 00485 * @return [type] ... 00486 */ 00487 function getGrlistRecord($phash) { 00488 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_grlist.*', 'index_grlist', 'phash='.intval($phash)); 00489 $allRows = array(); 00490 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00491 $row["pcount"] = $GLOBALS['TYPO3_DB']->sql_num_rows($res); 00492 $allRows[] = $row; 00493 } 00494 return $allRows; 00495 } 00496 00497 /** 00498 * [Describe function...] 00499 * 00500 * @param [type] $phash: ... 00501 * @return [type] ... 00502 */ 00503 function getNumberOfFulltext($phash) { 00504 return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_fulltext', 'phash=' . intval($phash)); 00505 } 00506 00507 /** 00508 * [Describe function...] 00509 * 00510 * @return [type] ... 00511 */ 00512 function getPhashTypes() { 00513 $recList=array(); 00514 00515 // Types: 00516 $Itypes = array( 00517 "html" => 1, 00518 "htm" => 1, 00519 "pdf" => 2, 00520 "doc" => 3, 00521 "txt" => 4 00522 ); 00523 00524 $revTypes=array_flip($Itypes); 00525 $revTypes[0]="TYPO3 page"; 00526 00527 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),item_type', 'index_phash', '', 'item_type', 'item_type'); 00528 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) { 00529 $iT = $row[1]; 00530 $recList[] = array($this->tableHead($revTypes[$iT]." ($iT)"), $this->countUniqueTypes($iT)."/".$row[0]); 00531 } 00532 00533 return $recList; 00534 } 00535 00536 /** 00537 * [Describe function...] 00538 * 00539 * @param [type] $item_type: ... 00540 * @return [type] ... 00541 */ 00542 function countUniqueTypes($item_type) { 00543 // TYPO3 pages, unique 00544 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_phash', 'item_type='.$GLOBALS['TYPO3_DB']->fullQuoteStr($item_type, 'index_phash'), 'phash_grouping'); 00545 $items = array(); 00546 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) { 00547 $items[] = $row; 00548 } 00549 return count($items); 00550 } 00551 } 00552 00553 00554 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/indexed_search/mod/index.php"]) { 00555 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/indexed_search/mod/index.php"]); 00556 } 00557 00558 00559 // Make instance: 00560 $SOBE = t3lib_div::makeInstance("SC_mod_tools_isearch_index"); 00561 $SOBE->init(); 00562 $SOBE->main(); 00563 $SOBE->printContent(); 00564 00565 ?>
1.8.0