d9c90d5484b4152889cc8bd8f33bf7b86b2f97e1
[Packages/TYPO3.CMS.git] / typo3 / sysext / indexed_search / modfunc2 / class.tx_indexedsearch_modfunc2.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004-2009 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 * [CLASS/FUNCTION INDEX of SCRIPT]
32 *
33 *
34 *
35 * 60: class tx_indexedsearch_modfunc2 extends t3lib_extobjbase
36 * 67: function main()
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)
41 *
42 * TOTAL FUNCTIONS: 5
43 * (This index is automatically created/updated by the extension "extdeveval")
44 *
45 */
46
47
48 /**
49 * Module extension (addition to function menu) 'Indexed search statistics' for the 'indexed_search' extension.
50 *
51 * @author Dimitri Ebert <dimitri.ebert@dkd.de>
52 * @package TYPO3
53 * @subpackage tx_indexedsearch
54 */
55 class tx_indexedsearch_modfunc2 extends t3lib_extobjbase {
56
57 /**
58 * Calls showStats to generate output.
59 *
60 * @return string html table with results from showStats()
61 */
62 function main() {
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;
65
66 $theOutput.=$this->pObj->doc->spacer(5);
67 $theOutput.=$this->pObj->doc->section($LANG->getLL('title'),$this->showStats(),0,1);
68
69 $menu=array();
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);
72
73 return $theOutput;
74 }
75
76
77 /**
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.
80 *
81 * @return string html table with results
82 */
83 function showStats() {
84 global $LANG, $TYPO3_CONF_VARS;
85
86 $conf['words']=50; // max words in result list
87 $conf['bid'] = intval(t3lib_div::_GET('id')); // pageid for several statistics
88
89 $addwhere1=''; // all records
90 $addwhere2=' AND tstamp > '.(time()-30*24*60*60); // last 30 days
91 $addwhere3=' AND tstamp > '.(time()-24*60*60); // last 24 hours
92
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>'
98 .$this->note;
99
100 // Ask hook to include more on the page:
101 if ($hookObj = &$this->hookRequest('additionalSearchStat')) {
102 $content.= $hookObj->additionalSearchStat();
103 }
104
105 return $content;
106 }
107
108 /**
109 * Generates html table with title and several statistics
110 *
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
115 */
116 function listSeveralStats($title,$addwhere,$conf) {
117 global $LANG;
118
119 $queryParts['SELECT']= '*, 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'];
125
126 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
127 $queryParts['SELECT'],
128 $queryParts['FROM'],
129 $queryParts['WHERE'],
130 $queryParts['GROUPBY'],
131 $queryParts['ORDERBY'],
132 $queryParts['LIMIT']
133 );
134
135 if ($res) {
136 $count = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
137 } else {
138 $count = 0;
139 }
140
141 // exist several statistics for this page?
142 if ($count > 0) {
143 $this->note = $LANG->getLL('justthispage');
144 } else {
145 // Limit access to pages of the current site
146 $secureaddwhere = ' AND pageid IN ('.($this->extGetTreeList($conf['bid'],100,0,'1')).$conf['bid'].') ';
147 $this->note = $LANG->getLL('allpages');
148
149 $queryParts['WHERE']= '1 '.$addwhere.$secureaddwhere;
150 }
151
152 // make real query
153 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
154 $queryParts['SELECT'],
155 $queryParts['FROM'],
156 $queryParts['WHERE'],
157 $queryParts['GROUPBY'],
158 $queryParts['ORDERBY'],
159 $queryParts['LIMIT']
160 );
161
162 $table1='';
163 $i=0;
164 if ($res) {
165 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
166 $i++;
167 $table1.='<tr class="bgColor4"><td>'.$i.'.</td><td>'.$row['word'].'</td><td>&nbsp;&nbsp;'.$row['c'].'</td></tr>';
168 }
169 }
170
171 if ($i==0) {
172 $table1='<tr class="bgColor4"><td callspan="3">'.$LANG->getLL("noresults").'</td></tr>';
173 }
174
175 $table1='<table class="bgColor5" cellpadding="2" cellspacing="1"><tr class="tableheader"><td colspan="3">'.$title.'</td></tr>'.$table1.'</table>';
176
177 return $note.$table1;
178 }
179
180 /**
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.
184 *
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.
187 *
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!)
193 */
194 function extGetTreeList($id,$depth,$begin = 0,$perms_clause) {
195 return t3lib_tsfeBeUserAuth::extGetTreeList($id,$depth,$begin,$perms_clause);
196 }
197
198 /**
199 * Returns an object reference to the hook object if any
200 *
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 Skaarhoj
204 */
205 function &hookRequest($functionName) {
206 global $TYPO3_CONF_VARS;
207
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;
213 return $hookObj;
214 }
215 }
216 }
217 }
218
219
220
221 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/indexed_search/modfunc2/class.tx_indexedsearch_modfunc2.php']) {
222 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/indexed_search/modfunc2/class.tx_indexedsearch_modfunc2.php']);
223 }
224
225 ?>