|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2004-2011 Dimitri Ebert (dimitri.ebert@dkd.de) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 /** 00025 * Module extension (addition to function menu) 'Indexed search statistics' for the 'indexed_search' extension. 00026 * 00027 * @author Dimitri Ebert <dimitri.ebert@dkd.de> 00028 */ 00029 00030 /** 00031 * [CLASS/FUNCTION INDEX of SCRIPT] 00032 * 00033 * 00034 * 00035 * 60: class tx_indexedsearch_modfunc2 extends t3lib_extobjbase 00036 * 67: function main() 00037 * 88: function showStats() 00038 * 121: function listSeveralStats($title,$addwhere,$conf) 00039 * 199: function extGetTreeList($id,$depth,$begin = 0,$perms_clause) 00040 * 210: function &hookRequest($functionName) 00041 * 00042 * TOTAL FUNCTIONS: 5 00043 * (This index is automatically created/updated by the extension "extdeveval") 00044 * 00045 */ 00046 00047 00048 /** 00049 * Module extension (addition to function menu) 'Indexed search statistics' for the 'indexed_search' extension. 00050 * 00051 * @author Dimitri Ebert <dimitri.ebert@dkd.de> 00052 * @package TYPO3 00053 * @subpackage tx_indexedsearch 00054 */ 00055 class tx_indexedsearch_modfunc2 extends t3lib_extobjbase { 00056 00057 /** 00058 * Calls showStats to generate output. 00059 * 00060 * @return string html table with results from showStats() 00061 */ 00062 function main() { 00063 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted! 00064 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS; 00065 00066 $theOutput.=$this->pObj->doc->spacer(5); 00067 $theOutput.=$this->pObj->doc->section($LANG->getLL('title'),$this->showStats(),0,1); 00068 00069 $menu=array(); 00070 $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>'; 00071 $theOutput.=$this->pObj->doc->spacer(5); 00072 00073 return $theOutput; 00074 } 00075 00076 00077 /** 00078 * Generates html table containing the statistics. 00079 * Calls listSeveralStats 3 times, for all statistics, statistics of the last 30 days and statistics of the last 24 hours. 00080 * 00081 * @return string html table with results 00082 */ 00083 function showStats() { 00084 global $LANG, $TYPO3_CONF_VARS; 00085 00086 $conf['words']=50; // max words in result list 00087 $conf['bid'] = intval(t3lib_div::_GET('id')); // pageid for several statistics 00088 00089 $addwhere1=''; // all records 00090 $addwhere2=' AND tstamp > ' . ($GLOBALS['EXEC_TIME'] - 30 * 24 * 60 * 60); // last 30 days 00091 $addwhere3=' AND tstamp > ' . ($GLOBALS['EXEC_TIME'] - 24 * 60 * 60); // last 24 hours 00092 00093 $content.= $LANG->getLL('title2').' 00094 <table cellpading="5" cellspacing="5" valign="top"><tr><td valign="top">' 00095 .$this->listSeveralStats($LANG->getLL('all'),$addwhere1,$conf).'</td><td valign="top">' 00096 .$this->listSeveralStats($LANG->getLL('last30days'),$addwhere2,$conf).'</td><td valign="top">' 00097 .$this->listSeveralStats($LANG->getLL('last24hours'),$addwhere3,$conf).'</td></tr></table>' 00098 .$this->note; 00099 00100 // Ask hook to include more on the page: 00101 if ($hookObj = $this->hookRequest('additionalSearchStat')) { 00102 $content.= $hookObj->additionalSearchStat(); 00103 } 00104 00105 return $content; 00106 } 00107 00108 /** 00109 * Generates html table with title and several statistics 00110 * 00111 * @param string title for statistic, like 'Last 30 days' or 'Last 24 hours' 00112 * @param string add where for sql query 00113 * @param array configuration: words = max words for results, bid = pageid 00114 * @return string html table with results 00115 */ 00116 function listSeveralStats($title,$addwhere,$conf) { 00117 global $LANG; 00118 00119 $queryParts['SELECT'] = 'word, COUNT(*) AS c'; 00120 $queryParts['FROM']='index_stat_word'; 00121 $queryParts['WHERE']=sprintf('pageid= %d '.$addwhere, $conf['bid']); 00122 $queryParts['GROUPBY']='word'; 00123 $queryParts['ORDERBY']='c DESC,word'; 00124 $queryParts['LIMIT']=$conf['words']; 00125 00126 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00127 $queryParts['SELECT'], 00128 $queryParts['FROM'], 00129 $queryParts['WHERE'], 00130 $queryParts['GROUPBY'], 00131 $queryParts['ORDERBY'], 00132 $queryParts['LIMIT'] 00133 ); 00134 00135 if ($res) { 00136 $count = $GLOBALS['TYPO3_DB']->sql_num_rows($res); 00137 } else { 00138 $count = 0; 00139 } 00140 00141 // exist several statistics for this page? 00142 if ($count > 0) { 00143 $this->note = $LANG->getLL('justthispage'); 00144 } else { 00145 // Limit access to pages of the current site 00146 $secureaddwhere = ' AND pageid IN (' . ($this->extGetTreeList($conf['bid'], 100, 0, '1=1')) . $conf['bid'] . ') '; 00147 $this->note = $LANG->getLL('allpages'); 00148 00149 $queryParts['WHERE'] = '1=1 ' . $addwhere . $secureaddwhere; 00150 } 00151 00152 // make real query 00153 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00154 $queryParts['SELECT'], 00155 $queryParts['FROM'], 00156 $queryParts['WHERE'], 00157 $queryParts['GROUPBY'], 00158 $queryParts['ORDERBY'], 00159 $queryParts['LIMIT'] 00160 ); 00161 00162 $table1=''; 00163 $i=0; 00164 if ($res) { 00165 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00166 $i++; 00167 $table1.='<tr class="bgColor4"><td>'.$i.'.</td><td>'.$row['word'].'</td><td> '.$row['c'].'</td></tr>'; 00168 } 00169 } 00170 00171 if ($i==0) { 00172 $table1='<tr class="bgColor4"><td callspan="3">'.$LANG->getLL("noresults").'</td></tr>'; 00173 } 00174 00175 $table1='<table class="bgColor5" cellpadding="2" cellspacing="1"><tr class="tableheader"><td colspan="3">'.$title.'</td></tr>'.$table1.'</table>'; 00176 00177 return $note.$table1; 00178 } 00179 00180 /** 00181 * Calls t3lib_tsfeBeUserAuth::extGetTreeList. 00182 * Although this duplicates the function t3lib_tsfeBeUserAuth::extGetTreeList 00183 * this is necessary to create the object that is used recursively by the original function. 00184 * 00185 * Generates a list of Page-uid's from $id. List does not include $id itself 00186 * The only pages excluded from the list are deleted pages. 00187 * 00188 * @param integer Start page id 00189 * @param integer Depth to traverse down the page tree. 00190 * @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' 00191 * @param string Perms clause 00192 * @return string Returns the list with a comma in the end (if any pages selected!) 00193 */ 00194 function extGetTreeList($id,$depth,$begin = 0,$perms_clause) { 00195 return t3lib_tsfeBeUserAuth::extGetTreeList($id,$depth,$begin,$perms_clause); 00196 } 00197 00198 /** 00199 * Returns an object reference to the hook object if any 00200 * 00201 * @param string Name of the function you want to call / hook key 00202 * @return object Hook object, if any. Otherwise null. 00203 * @author Kasper Skårhøj 00204 */ 00205 function hookRequest($functionName) { 00206 global $TYPO3_CONF_VARS; 00207 00208 // Hook: menuConfig_preProcessModMenu 00209 if ($TYPO3_CONF_VARS['EXTCONF']['indexed_search']['be_hooks'][$functionName]) { 00210 $hookObj = t3lib_div::getUserObj($TYPO3_CONF_VARS['EXTCONF']['indexed_search']['be_hooks'][$functionName]); 00211 if (method_exists ($hookObj, $functionName)) { 00212 $hookObj->pObj = $this; 00213 return $hookObj; 00214 } 00215 } 00216 } 00217 } 00218 00219 00220 00221 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/indexed_search/modfunc2/class.tx_indexedsearch_modfunc2.php'])) { 00222 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/indexed_search/modfunc2/class.tx_indexedsearch_modfunc2.php']); 00223 } 00224 00225 ?>
1.8.0