[FEATURE] Intgrate CSS class "lead" for introductions
[Packages/TYPO3.CMS.git] / typo3 / sysext / indexed_search / Classes / Controller / IndexingStatisticsController.php
1 <?php
2 namespace TYPO3\CMS\IndexedSearch\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2004-2013 Dimitri Ebert (dimitri.ebert@dkd.de)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Module extension (addition to function menu) 'Indexed search statistics' for the 'indexed_search' extension.
29 *
30 * @author Dimitri Ebert <dimitri.ebert@dkd.de>
31 */
32 class IndexingStatisticsController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
33
34 /**
35 * Calls showStats to generate output.
36 *
37 * @return string html table with results from showStats()
38 * @todo Define visibility
39 */
40 public function main() {
41 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted!
42 $theOutput = $this->pObj->doc->header($GLOBALS['LANG']->getLL('title'));
43 $theOutput .= $this->pObj->doc->section('', $this->showStats(), 0, 1);
44 $menu = array();
45 $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"');
46 $menu[] = $functionMenu . '<label for="checkTx_indexedsearch_modfunc2_check"' . $GLOBALS['LANG']->getLL('checklabel') . '</label>';
47 $theOutput .= $this->pObj->doc->spacer(5);
48 return $theOutput;
49 }
50
51 /**
52 * Generates html table containing the statistics.
53 * Calls listSeveralStats 3 times, for all statistics, statistics of the last 30 days and statistics of the last 24 hours.
54 *
55 * @return string html table with results
56 * @todo Define visibility
57 */
58 public function showStats() {
59 $conf['words'] = 50;
60
61 // max words in result list
62 $conf['bid'] = intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('id'));
63
64 // pageid for several statistics
65 $addwhere1 = '';
66
67 // all records
68 $addwhere2 = ' AND tstamp > ' . ($GLOBALS['EXEC_TIME'] - 30 * 24 * 60 * 60);
69
70 // last 30 days
71 $addwhere3 = ' AND tstamp > ' . ($GLOBALS['EXEC_TIME'] - 24 * 60 * 60);
72
73 // last 24 hours
74 $content = '<p class="lead">' . $GLOBALS['LANG']->getLL('title2') . '</p>';
75 $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>';
76 $content .= '<p>' . $this->note . '</p>';
77
78 // Ask hook to include more on the page:
79 if ($hookObj = $this->hookRequest('additionalSearchStat')) {
80 $content .= $hookObj->additionalSearchStat();
81 }
82 return $content;
83 }
84
85 /**
86 * Generates html table with title and several statistics
87 *
88 * @param string title for statistic, like 'Last 30 days' or 'Last 24 hours'
89 * @param string add where for sql query
90 * @param array configuration: words = max words for results, bid = pageid
91 * @return string html table with results
92 * @todo Define visibility
93 */
94 public function listSeveralStats($title, $addwhere, $conf) {
95 global $LANG;
96 $queryParts['SELECT'] = 'word, COUNT(*) AS c';
97 $queryParts['FROM'] = 'index_stat_word';
98 $queryParts['WHERE'] = sprintf('pageid= %d ' . $addwhere, $conf['bid']);
99 $queryParts['GROUPBY'] = 'word';
100 $queryParts['ORDERBY'] = 'c DESC,word';
101 $queryParts['LIMIT'] = $conf['words'];
102 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($queryParts['SELECT'], $queryParts['FROM'], $queryParts['WHERE'], $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']);
103 if ($res) {
104 $count = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
105 } else {
106 $count = 0;
107 }
108 // exist several statistics for this page?
109 if ($count > 0) {
110 $this->note = $LANG->getLL('justthispage');
111 } else {
112 // Limit access to pages of the current site
113 $secureaddwhere = ' AND pageid IN (' . $this->extGetTreeList($conf['bid'], 100, 0, '1=1') . $conf['bid'] . ') ';
114 $this->note = $LANG->getLL('allpages');
115 $queryParts['WHERE'] = '1=1 ' . $addwhere . $secureaddwhere;
116 }
117 // make real query
118 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($queryParts['SELECT'], $queryParts['FROM'], $queryParts['WHERE'], $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']);
119 $table1 = '';
120 $i = 0;
121 if ($res) {
122 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
123 $i++;
124 $table1 .= '<tr class="bgColor4"><td>' . $i . '.</td><td>' . htmlspecialchars($row['word']) . '</td><td>&nbsp;&nbsp;' . $row['c'] . '</td></tr>';
125 }
126 }
127 if ($i == 0) {
128 $table1 = '<tr class="bgColor4"><td callspan="3">' . $LANG->getLL('noresults') . '</td></tr>';
129 }
130 $table1 = '<table class="bgColor5" cellpadding="2" cellspacing="1"><tr class="tableheader"><td colspan="3">' . $title . '</td></tr>' . $table1 . '</table>';
131 return $note . $table1;
132 }
133
134 /**
135 * Calls \TYPO3\CMS\Backend\FrontendBackendUserAuthentication::extGetTreeList.
136 * Although this duplicates the function \TYPO3\CMS\Backend\FrontendBackendUserAuthentication::extGetTreeList
137 * this is necessary to create the object that is used recursively by the original function.
138 *
139 * Generates a list of Page-uid's from $id. List does not include $id itself
140 * The only pages excluded from the list are deleted pages.
141 *
142 * @param integer Start page id
143 * @param integer Depth to traverse down the page tree.
144 * @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'
145 * @param string Perms clause
146 * @return string Returns the list with a comma in the end (if any pages selected!)
147 * @todo Define visibility
148 */
149 public function extGetTreeList($id, $depth, $begin = 0, $perms_clause) {
150 // TODO: Fix this as this calls a non-static method
151 return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication::extGetTreeList($id, $depth, $begin, $perms_clause);
152 }
153
154 /**
155 * Returns an object reference to the hook object if any
156 *
157 * @param string Name of the function you want to call / hook key
158 * @return object Hook object, if any. Otherwise NULL.
159 * @author Kasper Skårhøj
160 * @todo Define visibility
161 */
162 public function hookRequest($functionName) {
163 // Hook: menuConfig_preProcessModMenu
164 if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['be_hooks'][$functionName]) {
165 $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['indexed_search']['be_hooks'][$functionName]);
166 if (method_exists($hookObj, $functionName)) {
167 $hookObj->pObj = $this;
168 return $hookObj;
169 }
170 }
171 }
172
173 }
174
175
176 ?>