TYPO3 CMS  TYPO3_6-2
ModuleController.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
29  public $MCONF = array();
30 
34  public $MOD_MENU = array();
35 
39  public $MOD_SETTINGS = array();
40 
47  public $doc;
48 
52  public $include_once = array();
53 
57  public $content;
58 
62  public function __construct() {
63  $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], TRUE);
65  }
66 
73  public function init() {
74  $this->MCONF = $GLOBALS['MCONF'];
75  $this->menuConfig();
76  $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
77  $this->doc->form = '<form action="" method="post">';
78  $this->doc->backPath = $GLOBALS['BACK_PATH'];
79  $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('indexed_search') . '/mod/mod_template.html');
80  $this->doc->tableLayout = array(
81  'defRow' => array(
82  '0' => array('<td valign="top" nowrap>', '</td>'),
83  'defCol' => array('<td><img src="' . $this->doc->backPath . 'clear.gif" width=10 height=1></td><td valign="top" nowrap>', '</td>')
84  )
85  );
86  $indexer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\IndexedSearch\\Indexer');
87  $indexer->initializeExternalParsers();
88  }
89 
99  public function menuConfig() {
100  $this->MOD_MENU = array(
101  'function' => array(
102  'stat' => 'General statistics',
103  'typo3pages' => 'List: TYPO3 Pages',
104  'externalDocs' => 'List: External documents'
105  )
106  );
107  // cleanse settings
108  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SET'), $this->MCONF['name'], 'ses');
109  }
110 
117  public function main() {
118  $this->content = $this->doc->header('Indexing Engine Statistics');
119  $this->content .= $this->doc->spacer(5);
120  switch ($this->MOD_SETTINGS['function']) {
121  case 'stat':
122  $this->content .= $this->doc->section('Records', $this->doc->table($this->getRecordsNumbers()), 0, 1);
123  $this->content .= $this->doc->spacer(15);
124  $this->content .= $this->doc->section('index_phash TYPES', $this->doc->table($this->getPhashTypes()), 1);
125  $this->content .= $this->doc->spacer(15);
126  break;
127  case 'externalDocs':
128  $this->content .= $this->doc->section('External documents', $this->doc->table($this->getPhashExternalDocs()), 0, 1);
129  $this->content .= $this->doc->spacer(15);
130  break;
131  case 'typo3pages':
132  $this->content .= $this->doc->section('TYPO3 Pages', $this->doc->table($this->getPhashT3pages()), 0, 1);
133  $this->content .= $this->doc->spacer(15);
134  break;
135  }
136  $docHeaderButtons = $this->getButtons();
137  $markers = array(
138  'CSH' => $docHeaderButtons['csh'],
139  'FUNC_MENU' => BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
140  'CONTENT' => $this->content
141  );
142  $this->content = $this->doc->startPage('Indexing Engine Statistics');
143  $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
144  $this->content .= $this->doc->endPage();
145  $this->content = $this->doc->insertStylesAndJS($this->content);
146  }
147 
154  public function printContent() {
155  echo $this->content;
156  }
157 
163  protected function getButtons() {
164  $buttons = array(
165  'csh' => '',
166  'shortcut' => ''
167  );
168  // Shortcut
169  if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
170  $buttons['shortcut'] = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
171  }
172  return $buttons;
173  }
174 
175  /***************************
176  *
177  * OTHER FUNCTIONS:
178  *
179  ***************************/
184  public function getRecordsNumbers() {
185  $tables = explode(',', 'index_phash,index_words,index_rel,index_grlist,index_section,index_fulltext');
186  $recList = array();
187  foreach ($tables as $t) {
188  $recList[] = array(
189  $this->tableHead($t),
190  $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $t)
191  );
192  }
193  return $recList;
194  }
195 
203  public function tableHead($str) {
204  return '<strong>' . $str . ':&nbsp;&nbsp;&nbsp;</strong>';
205  }
206 
213  public function getPhashStat() {
214  $recList = array();
215  // TYPO3 pages, unique
216  $items = array();
217  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),phash', 'index_phash', 'data_page_id<>0', 'phash_grouping,pcount,phash');
218  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
219  $items[] = $row;
220  }
221  $recList[] = array($this->tableHead('TYPO3 pages'), count($items));
222  // TYPO3 pages:
223  $recList[] = array(
224  $this->tableHead('TYPO3 pages, raw'),
225  $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_phash', 'data_page_id<>0')
226  );
227  // External files, unique
228  $items = array();
229  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),phash', 'index_phash', 'data_filename<>\'\'', 'phash_grouping');
230  $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
231  $recList[] = array($this->tableHead('External files'), $row[0]);
232  // External files
233  $recList[] = array(
234  $this->tableHead('External files, raw'),
235  $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_phash', 'data_filename<>\'\'')
236  );
237  return $recList;
238  }
239 
246  public function getPhashT3pages() {
247  $recList[] = array(
248  $this->tableHead('id/type'),
249  $this->tableHead('Title'),
250  $this->tableHead('Size'),
251  $this->tableHead('Words'),
252  $this->tableHead('mtime'),
253  $this->tableHead('Indexed'),
254  $this->tableHead('Updated'),
255  $this->tableHead('Parsetime'),
256  $this->tableHead('#sec/gr/full'),
257  $this->tableHead('#sub'),
258  $this->tableHead('Lang'),
259  $this->tableHead('cHash'),
260  $this->tableHead('phash')
261  );
262  // TYPO3 pages, unique
263  $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');
264  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
265  $cHash = count(unserialize($row['cHashParams'])) ? $this->formatCHash(unserialize($row['cHashParams'])) : '';
266  $grListRec = $this->getGrlistRecord($row['phash']);
267  $recList[] = array(
268  $row['data_page_id'] . ($row['data_page_type'] ? '/' . $row['data_page_type'] : ''),
269  htmlentities(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['item_title'], 30)),
270  \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($row['item_size']),
271  $this->getNumberOfWords($row['phash']),
272  BackendUtility::datetime($row['item_mtime']),
273  BackendUtility::datetime($row['crdate']),
274  $row['tstamp'] != $row['crdate'] ? BackendUtility::datetime($row['tstamp']) : '',
275  $row['parsetime'],
276  $this->getNumberOfSections($row['phash']) . '/' . $grListRec[0]['pcount'] . '/' . $this->getNumberOfFulltext($row['phash']),
277  $row['pcount'] . '/' . $this->formatFeGroup($grListRec),
278  $row['sys_language_uid'],
279  $cHash,
280  $row['phash']
281  );
282  if ($row['pcount'] > 1) {
283  $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_phash.*', 'index_phash', 'phash_grouping=' . (int)$row['phash_grouping'] . ' AND phash<>' . (int)$row['phash']);
284  while ($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2)) {
285  $grListRec = $this->getGrlistRecord($row2['phash']);
286  $recList[] = array(
287  '',
288  '',
289  \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($row2['item_size']),
290  $this->getNumberOfWords($row2['phash']),
291  BackendUtility::datetime($row2['item_mtime']),
292  BackendUtility::datetime($row2['crdate']),
293  $row2['tstamp'] != $row2['crdate'] ? BackendUtility::datetime($row2['tstamp']) : '',
294  $row2['parsetime'],
295  $this->getNumberOfSections($row2['phash']) . '/' . $grListRec[0]['pcount'] . '/' . $this->getNumberOfFulltext($row2['phash']),
296  '-/' . $this->formatFeGroup($grListRec),
297  '',
298  '',
299  $row2['phash']
300  );
301  }
302  }
303  }
304  return $recList;
305  }
306 
313  public function getPhashExternalDocs() {
314  $recList[] = array(
315  $this->tableHead('Filename'),
316  $this->tableHead('Size'),
317  $this->tableHead('Words'),
318  $this->tableHead('mtime'),
319  $this->tableHead('Indexed'),
320  $this->tableHead('Updated'),
321  $this->tableHead('Parsetime'),
322  $this->tableHead('#sec/gr/full'),
323  $this->tableHead('#sub'),
324  $this->tableHead('cHash'),
325  $this->tableHead('phash'),
326  $this->tableHead('Path')
327  );
328  // TYPO3 pages, unique
329  $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');
330  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
331  $cHash = count(unserialize($row['cHashParams'])) ? $this->formatCHash(unserialize($row['cHashParams'])) : '';
332  $grListRec = $this->getGrlistRecord($row['phash']);
333  $recList[] = array(
334  htmlentities(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['item_title'], 30)),
335  \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($row['item_size']),
336  $this->getNumberOfWords($row['phash']),
337  BackendUtility::datetime($row['item_mtime']),
338  BackendUtility::datetime($row['crdate']),
339  $row['tstamp'] != $row['crdate'] ? BackendUtility::datetime($row['tstamp']) : '',
340  $row['parsetime'],
341  $this->getNumberOfSections($row['phash']) . '/' . $grListRec[0]['pcount'] . '/' . $this->getNumberOfFulltext($row['phash']),
342  $row['pcount'],
343  $cHash,
344  $row['phash'],
345  htmlentities(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['data_filename'], 100))
346  );
347  if ($row['pcount'] > 1) {
348  $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_phash.*', 'index_phash', 'phash_grouping=' . (int)$row['phash_grouping'] . ' AND phash<>' . (int)$row['phash']);
349  while ($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2)) {
350  $cHash = count(unserialize($row2['cHashParams'])) ? $this->formatCHash(unserialize($row2['cHashParams'])) : '';
351  $grListRec = $this->getGrlistRecord($row2['phash']);
352  $recList[] = array(
353  '',
354  '',
355  $this->getNumberOfWords($row2['phash']),
356  '',
357  BackendUtility::datetime($row2['crdate']),
358  $row2['tstamp'] != $row2['crdate'] ? BackendUtility::datetime($row2['tstamp']) : '',
359  $row2['parsetime'],
360  $this->getNumberOfSections($row2['phash']) . '/' . $grListRec[0]['pcount'] . '/' . $this->getNumberOfFulltext($row2['phash']),
361  '',
362  $cHash,
363  $row2['phash'],
364  ''
365  );
366  }
367  }
368  }
369  return $recList;
370  }
371 
379  public function formatFeGroup($fegroup_recs) {
380  $str = array();
381  foreach ($fegroup_recs as $row) {
382  $str[] = $row['gr_list'] == '0,-1' ? 'NL' : $row['gr_list'];
383  }
384  arsort($str);
385  return implode('|', $str);
386  }
387 
395  public function formatCHash($arr) {
396  $list = array();
397  foreach ($arr as $k => $v) {
398  $list[] = htmlspecialchars($k) . '=' . htmlspecialchars($v);
399  }
400  return implode('<br />', $list);
401  }
402 
410  public function getNumberOfSections($phash) {
411  return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_section', 'phash=' . (int)$phash);
412  }
413 
421  public function getNumberOfWords($phash) {
422  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_rel', 'phash=' . (int)$phash);
423  $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
424  return $row[0];
425  }
426 
434  public function getGrlistRecord($phash) {
435  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_grlist.*', 'index_grlist', 'phash=' . (int)$phash);
436  $allRows = array();
437  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
438  $row['pcount'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
439  $allRows[] = $row;
440  }
441  return $allRows;
442  }
443 
451  public function getNumberOfFulltext($phash) {
452  return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('phash', 'index_fulltext', 'phash=' . (int)$phash);
453  }
454 
461  public function getPhashTypes() {
462  $recList = array();
463  // Types:
464  $Itypes = array(
465  'html' => 1,
466  'htm' => 1,
467  'pdf' => 2,
468  'doc' => 3,
469  'txt' => 4
470  );
471  $revTypes = array_flip($Itypes);
472  $revTypes[0] = 'TYPO3 page';
473  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*),item_type', 'index_phash', '', 'item_type', 'item_type');
474  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
475  $iT = $row[1];
476  $recList[] = array($this->tableHead($revTypes[$iT] . ' (' . $iT . ')'), $this->countUniqueTypes($iT) . '/' . $row[0]);
477  }
478  return $recList;
479  }
480 
488  public function countUniqueTypes($item_type) {
489  // TYPO3 pages, unique
490  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'index_phash', 'item_type=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($item_type, 'index_phash'), 'phash_grouping');
491  $items = array();
492  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res)) {
493  $items[] = $row;
494  }
495  return count($items);
496  }
497 
498 }
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
static getFuncMenu($mainParams, $elementName, $currentValue, $menuItems, $script='', $addparams='')
static formatSize($sizeInBytes, $labels='')
static fixed_lgd_cs($string, $chars, $appendString='...')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]