*/ // must be run within Dokuwiki 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_redirect2 extends DokuWiki_Admin_Plugin { protected $LogFile; function __construct() { global $conf; $this->LogFile = $conf['cachedir'].'/redirection.log'; } /** * Access for managers allowed */ function forAdminOnly(){ return false; } /** * return sort order for position in admin menu */ function getMenuSort() { return 140; } /** * return prompt for admin menu */ function getMenuText($language) { return $this->getLang('name'); } /** * handle user request */ function handle() { global $INPUT; $map = plugin_load('helper', $this->getPluginName()); if ($INPUT->post->str('redirdata') && checkSecurityToken()) { if (io_saveFile($map->ConfFile, cleanText($INPUT->str('redirdata')))) { msg($this->getLang('saved'), 1); } } } /** * output appropriate html */ function html() { global $lang; $map = plugin_load('helper', $this->getPluginName()); echo $this->locale_xhtml('intro'); echo '
'; echo ''; echo ''; echo ''; echo '
'; echo ''; echo '
'; echo '
'; if (!$this->getConf('logging')) return; $logData = $this->getLogData(); echo '
'; echo $this->locale_xhtml('loginfo'); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; foreach ($logData as $id => $data) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo ''; echo '
CountStatusPage/MediaRedirect to | RefererRecent redirection
'.$data['count'].''.$data['status'].''.$this->html_atag($data['caller'], $id).''.$this->html_atag($data['caller'], $data['dest']).''.$data['last'].'
'; } /** * Load redierction data from log file */ protected function getLogData() { $logData = array(); if (!file_exists($this->LogFile)) return $logData; $logfile = new SplFileObject($this->LogFile); $logfile->setFlags(SplFileObject::READ_CSV); $logfile->setCsvControl("\t"); // tsv foreach ($logfile as $line) { if ($line[0] == NULL) continue; list($datetime, $caller, $status, $orig, $dest) = $line; if (!isset($logData[$orig])) { $logData[$orig] = array( 'count' => 1, 'caller' => $caller, 'status' => $status, 'dest' => $dest, 'last' => $datetime, ); } else { $logData[$orig]['count'] ++; if ($datetime > $logData[$orig]['last']) { $logData[$orig]['last'] = $datetime; } } } unset($logfile); uasort($logData, array($this, 'compareCounts')); return $logData; } protected function compareCounts($a, $b) { return $b['count'] - $a['count']; } private function html_atag($caller, $id) { if (preg_match('@^(https?://|/)@', $id)) { $linkType = 'external'; } elseif ($caller == 'redirectMedia') { $linkType = 'media'; } else { $linkType = 'page'; } $format = 'xhtml'; switch ($linkType) { case 'media': $link = '{{:'.$id.'?linkonly|'.$id.'}}'; $html = strip_tags(p_render($format, p_get_instructions($link), $info), ''); break; case 'page': $link = '[[:'.$id.'|'.$id.']]'; $html = strip_tags(p_render($format, p_get_instructions($link), $info), ''); break; default: $html = hsc($id); } return $html; } } //Setup VIM: ex: et ts=4 enc=utf-8 :