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