index.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2008 Kasper Skaarhoj (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 Skaarhoj <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         reset($tables);
00238         while(list(,$t)=each($tables))  {
00239             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $t, '');
00240             $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00241             $recList[] = array($this->tableHead($t), $row[0]);
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.":&nbsp;&nbsp;&nbsp;</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         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_phash', 'data_page_id!=0');
00274         $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00275         $recList[] = array($this->tableHead("TYPO3 pages, raw"), $row[0]);
00276 
00277             // External files, unique
00278         $items = array();
00279         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),phash', 'index_phash', 'data_filename!=\'\'', 'phash_grouping');
00280         $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00281         $recList[] = array($this->tableHead("External files"), $row[0]);
00282 
00283             // External files
00284         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_phash', 'data_filename!=\'\'');
00285         $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00286         $recList[] = array($this->tableHead("External files, raw"), $row[0]);
00287 
00288         return $recList;
00289     }
00290 
00291     /**
00292      * [Describe function...]
00293      *
00294      * @return  [type]      ...
00295      */
00296     function getPhashT3pages()  {
00297         $recList[]=array(
00298             $this->tableHead("id/type"),
00299             $this->tableHead("Title"),
00300             $this->tableHead("Size"),
00301             $this->tableHead("Words"),
00302             $this->tableHead("mtime"),
00303             $this->tableHead("Indexed"),
00304             $this->tableHead("Updated"),
00305             $this->tableHead("Parsetime"),
00306             $this->tableHead("#sec/gr/full"),
00307             $this->tableHead("#sub"),
00308             $this->tableHead("Lang"),
00309             $this->tableHead("cHash"),
00310             $this->tableHead("phash")
00311         );
00312 
00313             // TYPO3 pages, unique
00314         $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');
00315         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))   {
00316 
00317             $cHash = count(unserialize($row["cHashParams"])) ? $this->formatCHash(unserialize($row["cHashParams"])) : "";
00318             $grListRec = $this->getGrlistRecord($row["phash"]);
00319             $recList[] = array(
00320                 $row["data_page_id"].($row["data_page_type"]?"/".$row["data_page_type"]:""),
00321                 t3lib_div::fixed_lgd($row["item_title"],30),
00322                 t3lib_div::formatSize($row["item_size"]),
00323                 $this->getNumberOfWords($row["phash"]),
00324                 t3lib_BEfunc::datetime($row["item_mtime"]),
00325                 t3lib_BEfunc::datetime($row["crdate"]),
00326                 ($row["tstamp"]!=$row["crdate"] ? t3lib_BEfunc::datetime($row["tstamp"]) : ""),
00327                 $row["parsetime"],
00328                 $this->getNumberOfSections($row["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row["phash"]),
00329                 $row["pcount"]."/".$this->formatFeGroup($grListRec),
00330                 $row["sys_language_uid"],
00331                 $cHash,
00332                 $row["phash"]
00333             );
00334 
00335             if ($row["pcount"]>1)   {
00336                 $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_phash.*', 'index_phash', 'phash_grouping='.intval($row['phash_grouping']).' AND phash!='.intval($row['phash']));
00337                 while($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2)) {
00338                     $grListRec = $this->getGrlistRecord($row2["phash"]);
00339                     $recList[] = array(
00340                         "",
00341                         "",
00342                         t3lib_div::formatSize($row2["item_size"]),
00343                         $this->getNumberOfWords($row2["phash"]),
00344                         t3lib_BEfunc::datetime($row2["item_mtime"]),
00345                         t3lib_BEfunc::datetime($row2["crdate"]),
00346                         ($row2["tstamp"]!=$row2["crdate"] ? t3lib_BEfunc::datetime($row2["tstamp"]) : ""),
00347                         $row2["parsetime"],
00348                         $this->getNumberOfSections($row2["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row2["phash"]),
00349                         "-/".$this->formatFeGroup($grListRec),
00350                         "",
00351                         "",
00352                         $row2["phash"]
00353                     );
00354                 }
00355             }
00356         }
00357         return $recList;
00358     }
00359 
00360     /**
00361      * [Describe function...]
00362      *
00363      * @return  [type]      ...
00364      */
00365     function getPhashExternalDocs() {
00366         $recList[]=array(
00367             $this->tableHead("Filename"),
00368             $this->tableHead("Size"),
00369             $this->tableHead("Words"),
00370             $this->tableHead("mtime"),
00371             $this->tableHead("Indexed"),
00372             $this->tableHead("Updated"),
00373             $this->tableHead("Parsetime"),
00374             $this->tableHead("#sec/gr/full"),
00375             $this->tableHead("#sub"),
00376             $this->tableHead("cHash"),
00377             $this->tableHead("phash"),
00378             $this->tableHead("Path")
00379         );
00380 
00381             // TYPO3 pages, unique
00382         $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');
00383         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))   {
00384 
00385             $cHash = count(unserialize($row["cHashParams"])) ? $this->formatCHash(unserialize($row["cHashParams"])) : "";
00386             $grListRec = $this->getGrlistRecord($row["phash"]);
00387             $recList[]=array(
00388                 t3lib_div::fixed_lgd($row["item_title"],30),
00389                 t3lib_div::formatSize($row["item_size"]),
00390                 $this->getNumberOfWords($row["phash"]),
00391                 t3lib_BEfunc::datetime($row["item_mtime"]),
00392                 t3lib_BEfunc::datetime($row["crdate"]),
00393                 ($row["tstamp"]!=$row["crdate"] ? t3lib_BEfunc::datetime($row["tstamp"]) : ""),
00394                 $row["parsetime"],
00395                 $this->getNumberOfSections($row["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row["phash"]),
00396                 $row["pcount"],
00397                 $cHash,
00398                 $row["phash"],
00399                 t3lib_div::fixed_lgd($row["data_filename"],100)
00400             );
00401 
00402             if ($row["pcount"]>1)   {
00403                 $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_phash.*', 'index_phash', 'phash_grouping='.intval($row['phash_grouping']).' AND phash!='.intval($row['phash']));
00404                 while($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2)) {
00405                     $cHash = count(unserialize($row2["cHashParams"])) ? $this->formatCHash(unserialize($row2["cHashParams"])) : "";
00406                     $grListRec = $this->getGrlistRecord($row2["phash"]);
00407                     $recList[]=array(
00408                         "",
00409                         "",
00410                         $this->getNumberOfWords($row2["phash"]),
00411                         "",
00412                         t3lib_BEfunc::datetime($row2["crdate"]),
00413                         ($row2["tstamp"]!=$row2["crdate"] ? t3lib_BEfunc::datetime($row2["tstamp"]) : ""),
00414                         $row2["parsetime"],
00415                         $this->getNumberOfSections($row2["phash"])."/".$grListRec[0]["pcount"]."/".$this->getNumberOfFulltext($row2["phash"]),
00416                         "",
00417                         $cHash,
00418                         $row2["phash"],
00419                         ""
00420                     );
00421                 }
00422             }
00423     //      debug($row);
00424         }
00425         return $recList;
00426     }
00427 
00428     /**
00429      * [Describe function...]
00430      *
00431      * @param   [type]      $fegroup_recs: ...
00432      * @return  [type]      ...
00433      */
00434     function formatFeGroup($fegroup_recs)   {
00435         reset($fegroup_recs);
00436         $str = array();
00437         while(list(,$row)=each($fegroup_recs))  {
00438             $str[] = $row["gr_list"]=="0,-1" ? "NL" : $row["gr_list"];
00439         }
00440         arsort($str);
00441         return implode("|",$str);
00442     }
00443 
00444     /**
00445      * [Describe function...]
00446      *
00447      * @param   [type]      $arr: ...
00448      * @return  [type]      ...
00449      */
00450     function formatCHash($arr)  {
00451         reset($arr);
00452         $list=array();
00453         while(list($k,$v)=each($arr))   {
00454             $list[]=$k."=".$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         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_section', 'phash='.intval($phash));
00467         $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00468         return $row[0];
00469     }
00470 
00471     /**
00472      * [Describe function...]
00473      *
00474      * @param   [type]      $phash: ...
00475      * @return  [type]      ...
00476      */
00477     function getNumberOfWords($phash)   {
00478         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_rel', 'phash='.intval($phash));
00479         $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00480         return $row[0];
00481     }
00482 
00483     /**
00484      * [Describe function...]
00485      *
00486      * @param   [type]      $phash: ...
00487      * @return  [type]      ...
00488      */
00489     function getGrlistRecord($phash)    {
00490         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_grlist.*', 'index_grlist', 'phash='.intval($phash));
00491         $allRows = array();
00492         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))   {
00493             $row["pcount"] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
00494             $allRows[] = $row;
00495         }
00496         return $allRows;
00497     }
00498 
00499     /**
00500      * [Describe function...]
00501      *
00502      * @param   [type]      $phash: ...
00503      * @return  [type]      ...
00504      */
00505     function getNumberOfFulltext($phash)    {
00506         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_fulltext', 'phash='.intval($phash));
00507         $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00508         return $row[0];
00509     }
00510 
00511     /**
00512      * [Describe function...]
00513      *
00514      * @return  [type]      ...
00515      */
00516     function getPhashTypes()    {
00517         $recList=array();
00518 
00519         // Types:
00520         $Itypes = array(
00521             "html" => 1,
00522             "htm" => 1,
00523             "pdf" => 2,
00524             "doc" => 3,
00525             "txt" => 4
00526         );
00527 
00528         $revTypes=array_flip($Itypes);
00529         $revTypes[0]="TYPO3 page";
00530 
00531         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),item_type', 'index_phash', '', 'item_type', 'item_type');
00532         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
00533             $iT = $row[1];
00534             $recList[] = array($this->tableHead($revTypes[$iT]." ($iT)"), $this->countUniqueTypes($iT)."/".$row[0]);
00535         }
00536 
00537         return $recList;
00538     }
00539 
00540     /**
00541      * [Describe function...]
00542      *
00543      * @param   [type]      $item_type: ...
00544      * @return  [type]      ...
00545      */
00546     function countUniqueTypes($item_type)   {
00547             // TYPO3 pages, unique
00548         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_phash', 'item_type='.$GLOBALS['TYPO3_DB']->fullQuoteStr($item_type, 'index_phash'), 'phash_grouping');
00549         $items = array();
00550         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
00551             $items[] = $row;
00552         }
00553         return count($items);
00554     }
00555 }
00556 
00557 
00558 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/indexed_search/mod/index.php"])    {
00559     include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/indexed_search/mod/index.php"]);
00560 }
00561 
00562 
00563 // Make instance:
00564 $SOBE = t3lib_div::makeInstance("SC_mod_tools_isearch_index");
00565 $SOBE->init();
00566 $SOBE->main();
00567 $SOBE->printContent();
00568 
00569 ?>

Generated on Sat Jan 3 04:23:25 2009 for TYPO3 API by  doxygen 1.4.7