*/
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once DOKU_PLUGIN.'admin.php';
class admin_plugin_searchstats extends DokuWiki_Admin_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 getMenuSort() { return 200; }
function forAdminOnly() { return false; }
//Carry out any processing required by the plugin.
function handle() {
$dataObject = new action_plugin_searchstats();
$this->wordArray = $dataObject->getSearchWordArray();
}
//Render html output for the plugin.
function html() {
if(is_array($this->wordArray) && count($this->wordArray) > 0) {
ptln('
'.$this->getLang('menu').'
');
//print out bar chart
ptln('
');
$link = $this->_getBarChartTopKeywords(10);
ptln('
');
//print out data table
ptln('
');
ptln('');
ptln('');
ptln(''.$this->getLang('th_word').' | ');
ptln(''.$this->getLang('th_count').' | ');
ptln('
');
foreach($this->wordArray as $word => $count) {
ptln('');
ptln(''.$word.' | ');
ptln(''.$count.' | ');
ptln('
');
}
ptln('
');
}
else {
ptln(''.$this->getLang('nosearchwords').'
');
}
}
function _getBarChartTopKeywords($amount = 10) {
$countArray = count($this->wordArray);
$amount = ($countArray < $amount ? $countArray : $amount);
if(is_array($this->wordArray) && $amount > 0) {
$wordArray = array_slice($this->wordArray, 0, $amount);
$chxl = "&chxl=0:";
$chd = "&chd=t:";
$top = 0;
$i = 0;
foreach($wordArray as $word => $count) {
if($i == 0) {
if(function_exists('bcpow')) {
$top = bcpow(10, (int) strlen((string) $count));
}
else {
$strLen = (int) strlen((string) $count);
$top = 1;
while($strLen-- >= 1) {
$top = $top * 10;
}
}
}
$i++;
$chxl .= "|".$word;
$percentage = $count/$top*100;
$chd .= ($percentage).($i < $amount ? "," : "");
}
//$top = $top + (10-($top%10));
//set chart type to bar chart
$paramString = "?cht=bvg";
//set x and y axis visible
$paramString .= "&chxt=x,y";
//set min and max for y axis
$paramString .= "&chxr=1,0,".$top;
//set width and height for chart
$paramString .= "&chs=750x300";
//set color for bars
$paramString .= "&chco=A2C180";
//set chart title
$paramString .= "&chtt=".implode("+", explode(" ", $this->getLang('top10k')));
//set automatic bar width
$paramString .= "&chbh=a";
//chxl for custom axis labels
$paramString .= $chxl;
//chd for bar heights
$paramString .= $chd;
$link = "http://chart.apis.google.com/chart".$paramString;
return $link;
}
return false;
}
var $wordArray = array();
}
?>