2 /***************************************************************
5 * (c) 2004-2011 Dimitri Ebert (dimitri.ebert@dkd.de)
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
25 * Module extension (addition to function menu) 'Indexed search statistics' for the 'indexed_search' extension.
27 * @author Dimitri Ebert <dimitri.ebert@dkd.de>
31 * [CLASS/FUNCTION INDEX of SCRIPT]
35 * 60: class tx_indexedsearch_modfunc2 extends t3lib_extobjbase
37 * 88: function showStats()
38 * 121: function listSeveralStats($title,$addwhere,$conf)
39 * 199: function extGetTreeList($id,$depth,$begin = 0,$perms_clause)
40 * 210: function &hookRequest($functionName)
43 * (This index is automatically created/updated by the extension "extdeveval")
49 * Module extension (addition to function menu) 'Indexed search statistics' for the 'indexed_search' extension.
51 * @author Dimitri Ebert <dimitri.ebert@dkd.de>
53 * @subpackage tx_indexedsearch
55 class tx_indexedsearch_modfunc2
extends t3lib_extobjbase
{
58 * Calls showStats to generate output.
60 * @return string html table with results from showStats()
63 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
64 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
66 $theOutput.=$this->pObj
->doc
->spacer(5);
67 $theOutput.=$this->pObj
->doc
->section($LANG->getLL('title'),$this->showStats(),0,1);
70 $menu[]=t3lib_BEfunc
::getFuncCheck($this->pObj
->id
,'SET[tx_indexedsearch_modfunc2_check]',$this->pObj
->MOD_SETTINGS
['tx_indexedsearch_modfunc2_check'],'','','id="checkTx_indexedsearch_modfunc2_check"').'<label for="checkTx_indexedsearch_modfunc2_check"'.$LANG->getLL('checklabel').'</label>';
71 $theOutput.=$this->pObj
->doc
->spacer(5);
78 * Generates html table containing the statistics.
79 * Calls listSeveralStats 3 times, for all statistics, statistics of the last 30 days and statistics of the last 24 hours.
81 * @return string html table with results
83 function showStats() {
84 global $LANG, $TYPO3_CONF_VARS;
86 $conf['words']=50; // max words in result list
87 $conf['bid'] = intval(t3lib_div
::_GET('id')); // pageid for several statistics
89 $addwhere1=''; // all records
90 $addwhere2=' AND tstamp > ' . ($GLOBALS['EXEC_TIME'] - 30 * 24 * 60 * 60); // last 30 days
91 $addwhere3=' AND tstamp > ' . ($GLOBALS['EXEC_TIME'] - 24 * 60 * 60); // last 24 hours
93 $content.= $LANG->getLL('title2').'
94 <table cellpading="5" cellspacing="5" valign="top"><tr><td valign="top">'
95 .$this->listSeveralStats($LANG->getLL('all'),$addwhere1,$conf).'</td><td valign="top">'
96 .$this->listSeveralStats($LANG->getLL('last30days'),$addwhere2,$conf).'</td><td valign="top">'
97 .$this->listSeveralStats($LANG->getLL('last24hours'),$addwhere3,$conf).'</td></tr></table>'
100 // Ask hook to include more on the page:
101 if ($hookObj = $this->hookRequest('additionalSearchStat')) {
102 $content.= $hookObj->additionalSearchStat();
109 * Generates html table with title and several statistics
111 * @param string title for statistic, like 'Last 30 days' or 'Last 24 hours'
112 * @param string add where for sql query
113 * @param array configuration: words = max words for results, bid = pageid
114 * @return string html table with results
116 function listSeveralStats($title,$addwhere,$conf) {
119 $queryParts['SELECT'] = 'word, COUNT(*) AS c';
120 $queryParts['FROM']='index_stat_word';
121 $queryParts['WHERE']=sprintf('pageid= %d '.$addwhere, $conf['bid']);
122 $queryParts['GROUPBY']='word';
123 $queryParts['ORDERBY']='c DESC,word';
124 $queryParts['LIMIT']=$conf['words'];
126 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
127 $queryParts['SELECT'],
129 $queryParts['WHERE'],
130 $queryParts['GROUPBY'],
131 $queryParts['ORDERBY'],
136 $count = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
141 // exist several statistics for this page?
143 $this->note
= $LANG->getLL('justthispage');
145 // Limit access to pages of the current site
146 $secureaddwhere = ' AND pageid IN (' . ($this->extGetTreeList($conf['bid'], 100, 0, '1=1')) . $conf['bid'] . ') ';
147 $this->note
= $LANG->getLL('allpages');
149 $queryParts['WHERE'] = '1=1 ' . $addwhere . $secureaddwhere;
153 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
154 $queryParts['SELECT'],
156 $queryParts['WHERE'],
157 $queryParts['GROUPBY'],
158 $queryParts['ORDERBY'],
165 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
167 $table1 .= '<tr class="bgColor4"><td>' . $i . '.</td><td>' . htmlspecialchars($row['word']) . '</td><td> ' . $row['c'] . '</td></tr>';
172 $table1='<tr class="bgColor4"><td callspan="3">'.$LANG->getLL("noresults").'</td></tr>';
175 $table1='<table class="bgColor5" cellpadding="2" cellspacing="1"><tr class="tableheader"><td colspan="3">'.$title.'</td></tr>'.$table1.'</table>';
177 return $note.$table1;
181 * Calls t3lib_tsfeBeUserAuth::extGetTreeList.
182 * Although this duplicates the function t3lib_tsfeBeUserAuth::extGetTreeList
183 * this is necessary to create the object that is used recursively by the original function.
185 * Generates a list of Page-uid's from $id. List does not include $id itself
186 * The only pages excluded from the list are deleted pages.
188 * @param integer Start page id
189 * @param integer Depth to traverse down the page tree.
190 * @param integer $begin is an optional integer that determines at which level in the tree to start collecting uid's. Zero means 'start right away', 1 = 'next level and out'
191 * @param string Perms clause
192 * @return string Returns the list with a comma in the end (if any pages selected!)
194 function extGetTreeList($id,$depth,$begin = 0,$perms_clause) {
195 return t3lib_tsfeBeUserAuth
::extGetTreeList($id,$depth,$begin,$perms_clause);
199 * Returns an object reference to the hook object if any
201 * @param string Name of the function you want to call / hook key
202 * @return object Hook object, if any. Otherwise null.
203 * @author Kasper Skårhøj
205 function hookRequest($functionName) {
206 global $TYPO3_CONF_VARS;
208 // Hook: menuConfig_preProcessModMenu
209 if ($TYPO3_CONF_VARS['EXTCONF']['indexed_search']['be_hooks'][$functionName]) {
210 $hookObj = t3lib_div
::getUserObj($TYPO3_CONF_VARS['EXTCONF']['indexed_search']['be_hooks'][$functionName]);
211 if (method_exists ($hookObj, $functionName)) {
212 $hookObj->pObj
= $this;
221 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/indexed_search/modfunc2/class.tx_indexedsearch_modfunc2.php'])) {
222 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/indexed_search/modfunc2/class.tx_indexedsearch_modfunc2.php']);