1<?php
2// must be run within DokuWiki
3if(!defined('DOKU_INC')) die();
4
5if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
6require_once DOKU_PLUGIN.'syntax.php';
7
8/**
9 * All DokuWiki plugins to extend the parser/rendering mechanism
10 * need to inherit from this class
11 */
12class action_plugin_prettyprint extends DokuWiki_Action_Plugin {
13
14    function register(Doku_Event_Handler $controller) {
15	    $controller->register_hook('DOKUWIKI_STARTED', 'AFTER',  $this, 'add_php_data');
16    }
17	private function _get_full_name($name, $meta) {
18		if ($meta['contributor'] != NULL) {
19			if (($contr = $meta['contributor'][$name]) != NULL) {
20				return $contr;
21			} else {
22				if ($name == $meta['user'])
23					return $meta['creator'];
24			}
25		} else {
26			return $meta['creator'];
27		}
28	}
29    function add_php_data(Doku_Event $event, $param) {
30		global $JSINFO, $ID, $REV;
31
32        $meta = p_get_metadata($ID);
33
34        $rev = $REV;
35        if(!$rev) { $rev = $meta['last_change']['date']; }
36        if(!$meta['approval']) { $meta['approval'] = array(); }
37        $allapproved = array_keys($meta['approval']);
38        sort($allapproved);
39        $latest_rev = $meta['last_change']['date'];
40
41        $longdate = dformat($rev);
42
43        # Is this document approved?
44        $approver = null;
45        if($meta['approval'][$rev]) {
46            # Approved
47            if(is_array($meta['approval'][$rev])) {
48              $approver = $meta['approval'][$rev][1];
49              if(!$approver) { $approver = $meta['approval'][$rev][2]; }
50              if(!$approver) { $approver = $meta['approval'][$rev][0]; }
51            }else{
52              $approver = $meta['approval'][$rev];
53            }
54        }
55
56	$JSINFO['date'] = $longdate;
57
58	$user_name = $meta['last_change']['user'];
59	if ($approver != null) {
60		$JSINFO['status'] = 'approved';
61	} else {
62		$JSINFO['status'] = 'draft';
63	}
64	$JSINFO['author'] = self::_get_full_name($user_name, $meta);
65    }
66}
67