* @desc Renders an overview of the farm's animals */ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); if(!defined('DOKU_FARM_PLUGIN')) define('DOKU_FARM_PLUGIN', DOKU_PLUGIN.'farm/'); if(!defined('DOKU_FARMPLUGINLOADED')) define('DOKU_FARMPLUGINLOADED', true); define('DOKU_FARM_PLUGIN_ANIMALOVERVIEW_PERPAGE', 10); include_once DOKU_FARM_PLUGIN.'animal.class.php'; class dokuwiki_farm_overview { var $manager = null; /** * @param $manager object that must handle error(), success(), nicesize(), getLang() ... calls */ function __construct($manager) { $this->manager = & $manager; } /** * Process requests */ function process() { } /** * Renders */ function html() { global $conf; ptln('
'.$this->manager->getLang('overview_title').'
'); // Gather animals / sort $animals = dokuwiki_farm_animal::listAnimals($this->manager); $sort = ''; if(isset($this->manager->opt['sort'])) { $sort = $this->manager->opt['sort']; if(preg_match('/^size(desc)?$/', $sort)) { $l =array(); for($i=0; $igetInfos()->getSize()).uniqid()] = $animals[$i]; if($sort == 'size') { ksort($l); }else krsort($l); $animals = array(); foreach($l as $s => $i) $animals[] = $i; } if(preg_match('/^name(desc)?$/', $sort)) { $l =array(); for($i=0; $igetName().uniqid()] = $animals[$i]; if($sort == 'name') { ksort($l); }else krsort($l); $animals = array(); foreach($l as $s => $i) $animals[] = $i; } } $details = isset($this->manager->opt['details']) ? $this->manager->opt['details'] : null; // Outputs usages progressbars if needed if($this->manager->conf['farmmaxsize'] > 0) { $s = dokuwiki_farm_animal::farmSize(); $p = $s / $this->manager->conf['farmmaxsize']; if($p > 1) $p == 1; $g = min(255, 511 - round($p * 511)); $r = min(255, round(511 * $p)); ptln(' '.$this->manager->getLang('overview_diskusage').' : '.round(100 * $p).'% ('.$this->manager->nicesize($s).' / '.$this->manager->nicesize($this->manager->conf['farmmaxsize']).')
'); } if($this->manager->conf['farmmaxanimals'] > 0) { $s = count(dokuwiki_farm_animal::listAnimals()); $p = $s / $this->manager->conf['farmmaxanimals']; if($p > 1) $p == 1; $g = min(255, 511 - round($p * 511)); $r = min(255, round(511 * $p)); ptln(' '.$this->manager->getLang('overview_animalsamount').' : '.round(100 * $p).'% ('.$s.' / '.$this->manager->conf['farmmaxanimals'].')
'); } // Sorting options ptln(' '); // Animal pages $cnt = 0; $page = isset($this->manager->opt['page']) ? (int)$this->manager->opt['page'] : 1; if($page < 1) $page = 1; $pages = ceil(count($animals) / DOKU_FARM_PLUGIN_ANIMALOVERVIEW_PERPAGE); if($page > $pages) $page = $pages; echo '
'."\n"; for($p = 1; $p <= $pages; $p++) ptln(' '.$p.''); echo '
'."\n"; $start = ($page - 1) * DOKU_FARM_PLUGIN_ANIMALOVERVIEW_PERPAGE; foreach(array_slice($animals, $start, DOKU_FARM_PLUGIN_ANIMALOVERVIEW_PERPAGE) as $a) { ptln('
'); ptln(' '); ptln('
'); if($this->manager->conf['animalmaxsize'] > 0) { $s = $a->getInfos()->getSize('all', false); $p = $s / $this->manager->conf['animalmaxsize']; if($p > 1) $p == 1; $g = min(255, 511 - round($p * 511)); $r = min(255, round(511 * $p)); ptln(' '.$this->manager->getLang('animal_info_size').' : '.round(100 * $p).'% ('.$this->manager->nicesize($s).' / '.$this->manager->nicesize($this->manager->conf['animalmaxsize']).')
'); } if($details != $a->getName()) { if($this->manager->conf['animalmaxsize'] <= 0) ptln(' '.$this->manager->getLang('animal_info_size').' : '.$a->getInfos()->getSize('all', true).', '); ptln(' '.$this->manager->getLang('animal_info_creation').' : '.strftime($conf['dformat'], $a->getMetadata('creation_date'))); ptln(' '.$this->manager->getLang('animal_info_more').''); }else{ if($this->manager->conf['animalmaxsize'] <= 0) ptln(' '.$this->manager->getLang('animal_info_size').' : '.$a->getInfos()->getSize('all', true).'
'); ptln(' '.$this->manager->getLang('animal_info_status').' : '.$this->manager->getLang('animal_status_'.$a->getInfos()->getStatus()).'
'); ptln(' '.$this->manager->getLang('animal_info_creation').' : '.$a->getInfos()->getCreation(true).'
'); ptln('
'); foreach($a->getInfos()->pagesInfo(true) as $k => $i) { ptln(' '.$this->manager->getLang('animal_info_pages'.$k).' : '.$i.'
'); } ptln('
'); foreach($a->getInfos()->mediasInfo(true) as $k => $i) { ptln(' '.$this->manager->getLang('animal_info_medias'.$k).' : '.$i.'
'); } ptln('
'); ptln(' '.$this->manager->getLang('animal_info_cachesize').' : '.$a->getInfos()->getSize('cache', true).'
'); ptln(' '.$this->manager->getLang('animal_info_indexsize').' : '.$a->getInfos()->getSize('index', true).'
'); } ptln('
'); ptln('
'); $status = $a->getMetadata('status'); if($status == '') $status = 'open'; ptln(' '.$this->manager->getLang('animal_info_status').' : | '); $lockstate = $a->getLockState(); ptln(' '.$this->manager->getLang('animal_info_lockstate').' : | '); ptln(' edit configuration | '); ptln(' delete | '); ptln(' delete'); ptln('
'); ptln('
'); $cnt++; if($cnt >= DOKU_FARM_PLUGIN_ANIMALOVERVIEW_PERPAGE) break; } echo '
'."\n"; for($p = 1; $p <= $pages; $p++) ptln(' '.$p.''); echo '
'."\n"; } } ?>