1<?php 2 3if(!defined('DOKU_INC')) die(); 4 5class action_plugin_publish_start extends DokuWiki_Action_Plugin { 6 7 private $hlp; 8 9 function __construct() { 10 $this->hlp = plugin_load('helper','publish'); 11 } 12 13 function register(&$controller) { 14 $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handle_start', array()); 15 } 16 17 function handle_start(&$event, $param) { 18 global $ACT; 19 global $REV; 20 global $INFO; 21 global $ID; 22 23 if($ACT != 'show') { return; } 24 25 if($REV != '') { return; } 26 27 # apply to readers only 28 if($INFO['perm'] != AUTH_READ) { return; } 29 30 # Check for override token 31 global $_GET; 32 if($_GET['force_rev']) { return; } 33 34 # Only apply to appropriate namespaces 35 if(!$this->hlp->in_namespace($this->getConf('apr_namespaces'), $ID)) { return; } 36 37 # Find latest rev 38 $meta = p_get_metadata($ID); 39 if($meta['approval'][$meta['last_change']['date']]) { return; } //REV=0 *is* approved 40 41 if(!$meta['approval']) { return; } //no approvals 42 43 # Get list of approvals 44 $all = array_keys($meta['approval']); 45 if(count($all) == 0) { return; } //no approvals 46 47 $REV = $all[count($all)-1]; 48 } 49 50} 51