TYPO3 CMS  TYPO3_6-2
IndexingStatisticsController.php
Go to the documentation of this file.
1 <?php
3 
17 
24 
28  public function __construct() {
29  $GLOBALS['LANG']->includeLLFile('EXT:indexed_search/modfunc2/locallang.xlf');
30  }
31 
38  public function main() {
39  // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
40  $theOutput = $this->pObj->doc->header($GLOBALS['LANG']->getLL('title'));
41  $theOutput .= $this->pObj->doc->section('', $this->showStats(), 0, 1);
42  $menu = array();
43  $functionMenu = \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->pObj->id, 'SET[tx_indexedsearch_modfunc2_check]', $this->pObj->MOD_SETTINGS['tx_indexedsearch_modfunc2_check'], '', '', 'id="checkTx_indexedsearch_modfunc2_check"');
44  $menu[] = $functionMenu . '<label for="checkTx_indexedsearch_modfunc2_check"' . $GLOBALS['LANG']->getLL('checklabel') . '</label>';
45  $theOutput .= $this->pObj->doc->spacer(5);
46  return $theOutput;
47  }
48 
56  public function showStats() {
57  $conf['words'] = 50;
58 
59  // max words in result list
60  $conf['bid'] = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('id');
61 
62  // pageid for several statistics
63  $addwhere1 = '';
64 
65  // all records
66  $addwhere2 = ' AND tstamp > ' . ($GLOBALS['EXEC_TIME'] - 30 * 24 * 60 * 60);
67 
68  // last 30 days
69  $addwhere3 = ' AND tstamp > ' . ($GLOBALS['EXEC_TIME'] - 24 * 60 * 60);
70 
71  // last 24 hours
72  $content = '<p class="lead">' . $GLOBALS['LANG']->getLL('title2') . '</p>';
73  $content .= '<table cellpading="5" cellspacing="5" valign="top" class=""><tr><td valign="top">' . $this->listSeveralStats($GLOBALS['LANG']->getLL('all'), $addwhere1, $conf) . '</td><td valign="top">' . $this->listSeveralStats($GLOBALS['LANG']->getLL('last30days'), $addwhere2, $conf) . '</td><td valign="top">' . $this->listSeveralStats($GLOBALS['LANG']->getLL('last24hours'), $addwhere3, $conf) . '</td></tr></table>';
74  $content .= '<p>' . $this->note . '</p>';
75 
76  // Ask hook to include more on the page:
77  if ($hookObj = $this->hookRequest('additionalSearchStat')) {
78  $content .= $hookObj->additionalSearchStat();
79  }
80  return $content;
81  }
82 
92  public function listSeveralStats($title, $addwhere, $conf) {
93  global $LANG;
94  $queryParts['SELECT'] = 'word, COUNT(*) AS c';
95  $queryParts['FROM'] = 'index_stat_word';
96  $queryParts['WHERE'] = sprintf('pageid= %d ' . $addwhere, $conf['bid']);
97  $queryParts['GROUPBY'] = 'word';
98  $queryParts['ORDERBY'] = 'c DESC,word';
99  $queryParts['LIMIT'] = $conf['words'];
100  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($queryParts['SELECT'], $queryParts['FROM'], $queryParts['WHERE'], $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']);
101  if ($res) {
102  $count = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
103  } else {
104  $count = 0;
105  }
106  // exist several statistics for this page?
107  if ($count > 0) {
108  $this->note = $LANG->getLL('justthispage');
109  } else {
110  // Limit access to pages of the current site
111  $secureaddwhere = ' AND pageid IN (' . $this->extGetTreeList($conf['bid'], 100, 0, '1=1') . $conf['bid'] . ') ';
112  $this->note = $LANG->getLL('allpages');
113  $queryParts['WHERE'] = '1=1 ' . $addwhere . $secureaddwhere;
114  }
115  // make real query
116  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($queryParts['SELECT'], $queryParts['FROM'], $queryParts['WHERE'], $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']);
117  $table1 = '';
118  $i = 0;
119  if ($res) {
120  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
121  $i++;
122  $table1 .= '<tr class="bgColor4"><td>' . $i . '.</td><td>' . htmlspecialchars($row['word']) . '</td><td>&nbsp;&nbsp;' . $row['c'] . '</td></tr>';
123  }
124  }
125  if ($i == 0) {
126  $table1 = '<tr class="bgColor4"><td callspan="3">' . $LANG->getLL('noresults') . '</td></tr>';
127  }
128  $table1 = '<table class="bgColor5" cellpadding="2" cellspacing="1"><tr class="tableheader"><td colspan="3">' . $title . '</td></tr>' . $table1 . '</table>';
129  return $note . $table1;
130  }
131 
147  public function extGetTreeList($id, $depth, $begin = 0, $perms_clause) {
148  return GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\FrontendBackendUserAuthentication')->extGetTreeList($id, $depth, $begin, $perms_clause);
149  }
150 
159  public function hookRequest($functionName) {
160  // Hook: menuConfig_preProcessModMenu
161  if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['be_hooks'][$functionName]) {
162  $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['be_hooks'][$functionName]);
163  if (method_exists($hookObj, $functionName)) {
164  $hookObj->pObj = $this;
165  return $hookObj;
166  }
167  }
168  }
169 
170 }
static getFuncCheck($mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]