1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Etienne MELEARD <etienne.meleard@free.fr>
5 */
6
7// must be run within Dokuwiki
8if(!defined('DOKU_INC')) die();
9
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
11
12require_once(DOKU_PLUGIN.'syntax.php');
13
14class syntax_plugin_aclauditor extends DokuWiki_Syntax_Plugin {
15	function getInfo() {
16		return array(
17			'author' => 'Etienne MELEARD',
18			'email'  => 'etienne.meleard@free.fr',
19			'date'   => @file_get_contents(DOKU_PLUGIN.'aclauditor/VERSION'),
20			'name'   => 'ACL Auditor Plugin (syntax)',
21			'desc'   => 'Functions to get info about user /group ACLs of a wiki page',
22			'url'    => 'http://dokuwiki.org/plugin:aclauditor',
23		);
24	}
25
26	function getType() { return 'substition'; }
27	function getSort() { return 155; }
28
29	function connectTo($mode) {
30		$this->Lexer->addSpecialPattern('<ACLAUDITOR[^/]*/>', $mode, 'plugin_aclauditor');
31	}
32
33	function handle($match, $state, $pos, &$handler) {
34		$params = array();
35		foreach(preg_split('`\s+`', trim(substr($match, 11, -2))) as $p) {
36			$p = explode('=', $p, 2);
37			if(!in_array($p[0], array('who', 'what', 'scenario'))) continue;
38			$params[$p[0]] = isset($p[1]) ? $p[1] : null;
39		}
40		return $params;
41	}
42
43	function render($format, &$renderer, $data) {
44		if($format != 'xhtml') return false;
45		$renderer->info['cache'] = false;
46		if(!auth_isadmin()) return true;
47
48		global $ID;
49		if(!isset($data['scenario'])) {
50			$renderer->doc .= '<form action="'.wl($ID, array('do' => 'admin', 'page' => 'aclauditor', 'aclaudit_mode' => 'single')).'" method="post">';
51			if(isset($data['who']) && !empty($data['who'])) $renderer->doc .= '<input type="hidden" name="aclaudit_who" value="'.$data['who'].'" />';
52			if(isset($data['what']) && !empty($data['what'])) $renderer->doc .= '<input type="hidden" name="aclaudit_what" value="'.$data['what'].'" />';
53			$renderer->doc .= '<input type="submit" name="aclaudit_test'.((isset($data['who']) && isset($data['what'])) ? 'both' : (isset($data['what']) ? 'what' : 'who')).'" value="'.$this->getLang('menu').'" />';
54			$renderer->doc .= '</form>';
55		}else{
56			$renderer->doc .= '<form action="'.wl($ID, array('do' => 'admin', 'page' => 'aclauditor', 'aclaudit_mode' => 'scenario')).'" method="post">';
57			if(!empty($data['scenario'])) {
58				$renderer->doc .= '<input type="hidden" name="aclaudit_scenario_load_filename" value="'.$data['scenario'].'" />';
59				$renderer->doc .= '<input type="hidden" name="aclaudit_scenario_load" value="1" />';
60				$renderer->doc .= '<input type="submit" name="aclaudit_scenario_run" value="'.$this->getLang('run').'" />';
61			}else $renderer->doc .= '<input type="submit" name="" value="'.$this->getLang('run').'" />';
62			$renderer->doc .= '</form>';
63		}
64
65		return true;
66	}
67}
68