[TASK] Remove function index
[Packages/TYPO3.CMS.git] / typo3 / sysext / indexed_search / modfunc2 / class.tx_indexedsearch_modfunc2.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004-2011 Dimitri Ebert (dimitri.ebert@dkd.de)
6 * All rights reserved
7 *
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.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
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.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * Module extension (addition to function menu) 'Indexed search statistics' for the 'indexed_search' extension.
26 *
27 * @author Dimitri Ebert <dimitri.ebert@dkd.de>
28 */
29
30
31 /**
32 * Module extension (addition to function menu) 'Indexed search statistics' for the 'indexed_search' extension.
33 *
34 * @author Dimitri Ebert <dimitri.ebert@dkd.de>
35 * @package TYPO3
36 * @subpackage tx_indexedsearch
37 */
38 class tx_indexedsearch_modfunc2 extends t3lib_extobjbase {
39
40 /**
41 * Calls showStats to generate output.
42 *
43 * @return string html table with results from showStats()
44 */
45 function main() {
46 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
47 $theOutput = $this->pObj->doc->spacer(5);
48 $theOutput .= $this->pObj->doc->section($GLOBALS['LANG']->getLL('title'), $this->showStats(), 0, 1);
49
50 $menu = array();
51 $functionMenu = t3lib_BEfunc::getFuncCheck(
52 $this->pObj->id,
53 'SET[tx_indexedsearch_modfunc2_check]',
54 $this->pObj->MOD_SETTINGS['tx_indexedsearch_modfunc2_check'],
55 '',
56 '',
57 'id="checkTx_indexedsearch_modfunc2_check"'
58 );
59 $menu[] = $functionMenu . '<label for="checkTx_indexedsearch_modfunc2_check"' .
60 $GLOBALS['LANG']->getLL('checklabel') . '</label>';
61 $theOutput .= $this->pObj->doc->spacer(5);
62
63 return $theOutput;
64 }
65
66
67 /**
68 * Generates html table containing the statistics.
69 * Calls listSeveralStats 3 times, for all statistics, statistics of the last 30 days and statistics of the last 24 hours.
70 *
71 * @return string html table with results
72 */
73 function showStats() {
74 $conf['words']=50; // max words in result list
75 $conf['bid'] = intval(t3lib_div::_GET('id')); // pageid for several statistics
76
77 $addwhere1=''; // all records
78 $addwhere2=' AND tstamp > ' . ($GLOBALS['EXEC_TIME'] - 30 * 24 * 60 * 60); // last 30 days
79 $addwhere3=' AND tstamp > ' . ($GLOBALS['EXEC_TIME'] - 24 * 60 * 60); // last 24 hours
80
81 $content = $GLOBALS['LANG']->getLL('title2') . '
82 <table cellpading="5" cellspacing="5" valign="top"><tr><td valign="top">' .
83 $this->listSeveralStats($GLOBALS['LANG']->getLL('all'), $addwhere1,$conf) . '</td><td valign="top">' .
84 $this->listSeveralStats($GLOBALS['LANG']->getLL('last30days'), $addwhere2, $conf) . '</td><td valign="top">' .
85 $this->listSeveralStats($GLOBALS['LANG']->getLL('last24hours'), $addwhere3, $conf) . '</td></tr></table>' .
86 $this->note;
87
88 // Ask hook to include more on the page:
89 if ($hookObj = $this->hookRequest('additionalSearchStat')) {
90 $content.= $hookObj->additionalSearchStat();
91 }
92
93 return $content;
94 }
95
96 /**
97 * Generates html table with title and several statistics
98 *
99 * @param string title for statistic, like 'Last 30 days' or 'Last 24 hours'
100 * @param string add where for sql query
101 * @param array configuration: words = max words for results, bid = pageid
102 * @return string html table with results
103 */
104 function listSeveralStats($title,$addwhere,$conf) {
105 global $LANG;
106
107 $queryParts['SELECT'] = 'word, COUNT(*) AS c';
108 $queryParts['FROM']='index_stat_word';
109 $queryParts['WHERE']=sprintf('pageid= %d '.$addwhere, $conf['bid']);
110 $queryParts['GROUPBY']='word';
111 $queryParts['ORDERBY']='c DESC,word';
112 $queryParts['LIMIT']=$conf['words'];
113
114 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
115 $queryParts['SELECT'],
116 $queryParts['FROM'],
117 $queryParts['WHERE'],
118 $queryParts['GROUPBY'],
119 $queryParts['ORDERBY'],
120 $queryParts['LIMIT']
121 );
122
123 if ($res) {
124 $count = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
125 } else {
126 $count = 0;
127 }
128
129 // exist several statistics for this page?
130 if ($count > 0) {
131 $this->note = $LANG->getLL('justthispage');
132 } else {
133 // Limit access to pages of the current site
134 $secureaddwhere = ' AND pageid IN (' . ($this->extGetTreeList($conf['bid'], 100, 0, '1=1')) . $conf['bid'] . ') ';
135 $this->note = $LANG->getLL('allpages');
136
137 $queryParts['WHERE'] = '1=1 ' . $addwhere . $secureaddwhere;
138 }
139
140 // make real query
141 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
142 $queryParts['SELECT'],
143 $queryParts['FROM'],
144 $queryParts['WHERE'],
145 $queryParts['GROUPBY'],
146 $queryParts['ORDERBY'],
147 $queryParts['LIMIT']
148 );
149
150 $table1='';
151 $i=0;
152 if ($res) {
153 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
154 $i++;
155 $table1.='<tr class="bgColor4"><td>'.$i.'.</td><td>'.$row['word'].'</td><td>&nbsp;&nbsp;'.$row['c'].'</td></tr>';
156 }
157 }
158
159 if ($i==0) {
160 $table1='<tr class="bgColor4"><td callspan="3">'.$LANG->getLL("noresults").'</td></tr>';
161 }
162
163 $table1='<table class="bgColor5" cellpadding="2" cellspacing="1"><tr class="tableheader"><td colspan="3">'.$title.'</td></tr>'.$table1.'</table>';
164
165 return $note.$table1;
166 }
167
168 /**
169 * Calls t3lib_tsfeBeUserAuth::extGetTreeList.
170 * Although this duplicates the function t3lib_tsfeBeUserAuth::extGetTreeList
171 * this is necessary to create the object that is used recursively by the original function.
172 *
173 * Generates a list of Page-uid's from $id. List does not include $id itself
174 * The only pages excluded from the list are deleted pages.
175 *
176 * @param integer Start page id
177 * @param integer Depth to traverse down the page tree.
178 * @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'
179 * @param string Perms clause
180 * @return string Returns the list with a comma in the end (if any pages selected!)
181 */
182 function extGetTreeList($id,$depth,$begin = 0,$perms_clause) {
183 // TODO: Fix this as this calls a non-static method
184 return t3lib_tsfeBeUserAuth::extGetTreeList($id,$depth,$begin,$perms_clause);
185 }
186
187 /**
188 * Returns an object reference to the hook object if any
189 *
190 * @param string Name of the function you want to call / hook key
191 * @return object Hook object, if any. Otherwise NULL.
192 * @author Kasper Skårhøj
193 */
194 function hookRequest($functionName) {
195 // Hook: menuConfig_preProcessModMenu
196 if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['be_hooks'][$functionName]) {
197 $hookObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['be_hooks'][$functionName]);
198 if (method_exists ($hookObj, $functionName)) {
199 $hookObj->pObj = $this;
200 return $hookObj;
201 }
202 }
203 }
204 }
205
206
207
208 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/indexed_search/modfunc2/class.tx_indexedsearch_modfunc2.php'])) {
209 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/indexed_search/modfunc2/class.tx_indexedsearch_modfunc2.php']);
210 }
211
212 ?>