1<?php 2/** 3 * SearchStats Plugin: This plugin records the search words and displays stats in the admin section 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Michael Schuh <mike.schuh@gmx.at> 7 */ 8if (!defined('DOKU_INC')) die(); 9 10class helper_plugin_searchstats extends DokuWiki_Plugin { 11 12 function getInfo() { 13 return array( 14 'author' => 'Michael Schuh', 15 'email' => 'mike.schuh@gmx.at', 16 'date' => @file_get_contents(DOKU_PLUGIN.'searchstats/VERSION'), 17 'name' => 'Searchstats plugin (action, admin component)', 18 'desc' => 'This plugin records the search words and displays stats in the admin section', 19 'url' => 'http://blog.imho.at/20100902/artikel/dokuwiki-plugin-searchstats', 20 ); 21 } 22 23 function getMethods() { 24 $result = array(); 25 $result[] = array( 26 'name' => 'getSearchWordArray', 27 'desc' => 'returns search word array', 28 'params' => array( 29 'number of words' => 'integer'), 30 'return' => array('words' => 'array'), 31 ); 32 $result[] = array( 33 'name' => '_getSaveFolder', 34 'desc' => 'returns folder where data is saved', 35 'params' => array(), 36 'return' => array('savefolder' => 'string'), 37 ); 38 return $result; 39 } 40 41 function getSearchWordArray($amount = false) { 42 $wordArray = array(); 43 $dir = $this->_getSaveFolder(); 44 if ($dh = opendir($dir)) { 45 while (($file = readdir($dh)) !== false) { 46 if(is_file($dir.'/'.$file) && strstr($file, 'idx')) { 47 $handle = @fopen($dir.'/'.$file, "r"); 48 if ($handle) { 49 while (!feof($handle)) { 50 $lines[] = rtrim(fgets($handle, 4096)); 51 } 52 fclose($handle); 53 } 54 foreach($lines as $line) { 55 $lineArray = explode(';', $line); 56 if($lineArray[0] != '') { 57 $wordArray[$lineArray[0]] = $lineArray[1]; 58 } 59 } 60 } 61 } 62 } 63 closedir($dh); 64 arsort($wordArray); 65 if($amount && is_numeric($amount)) { 66 $wordArray = array_slice($wordArray, 0, $amount); 67 } 68 return $wordArray; 69 } 70 71 function _getSaveFolder() { 72 return $this->getConf('searchstats_savefolder'); 73 } 74 75} 76 77?>