*/ // must be run within Dokuwiki if (!defined('DOKU_INC')) { die(); } class admin_plugin_dlcounter extends DokuWiki_Admin_Plugin { private $mydata; /** * @return int sort number in admin menu */ public function getMenuSort() { return 200; } /** * @return bool true if only access for superuser, false is for superusers and moderators */ public function forAdminOnly() { return false; } /** * Should carry out any processing required by the plugin. */ public function handle(){ $data = array( 'command' => 'name', 'file' => '', 'sort' => 'sort', 'strip' => true, 'align' => 'right', 'minwidth' => 0, 'cpad' => 1, 'halign' => 'center', 'bold' => 'b', 'header' => true, 'htext' => 'Downloads' ); $this->mydata = $data; } /** * Render HTML output, e.g. helpful text and a form */ public function html(){ $html = ""; $data = $this->mydata; $fname = DOKU_INC.'data/counts/download_counts.json'; $json = json_decode( file_get_contents($fname), TRUE ); $command = $data['command']; $file = $data['file']; if( $command == 'file' ){ // just want a counter $count = 0; if( $file != "" && array_key_exists( $file, $json ) ){ $count = $json[$file]; $html .= $count; } } else { // dump all the data in a table $sort = $data['sort']; $json = $this->stripKeys( $json ); if( $command == 'name' ){ if( $sort == 'sort' ){ ksort($json); } else if( $sort == 'rsort' ){ krsort($json); } } else if( $command == 'count' ){ if( $sort == 'sort' ) asort( $json ); else if( $sort == 'rsort' ) arsort( $json ); } $table = "
| ".$data['htext']." | |
|---|---|
| $file | ". "$count |