1<?php 2 3if(!defined('DOKU_INC')) die(); 4 5class action_plugin_publish_banner extends DokuWiki_Action_Plugin { 6 7 /** 8 * @var helper_plugin_publish 9 */ 10 private $hlp; 11 12 function __construct() { 13 $this->hlp = plugin_load('helper','publish'); 14 } 15 16 function register(Doku_Event_Handler &$controller) { 17 $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'handle_display_banner', array()); 18 } 19 20 function handle_display_banner(&$event, $param) { 21 global $ID; 22 global $INFO; 23 24 if (!$this->hlp->in_namespace($this->getConf('apr_namespaces'), $ID)) { 25 return; 26 } 27 28 if ($event->data != 'show') { 29 return; 30 } 31 32 if (!$INFO['exists']) { 33 return; 34 } 35 36 $meta = $INFO['meta']; 37 38 if (!$meta['approval']) { 39 $meta['approval'] = array(); 40 } 41 42 if($INFO['perm'] <= AUTH_READ && $this->getConf('hidereaderbanner')){ 43 return; 44 } 45 46 $this->showBanner(); 47 return; 48 } 49 50 function difflink($id, $rev1, $rev2) { 51 if($rev1 == $rev2) { return ''; } 52 return '<a href="' . wl($id, 'rev2[]=' . $rev1 . '&rev2[]=' . $rev2 . '&do[diff]=1') . 53 '" class="approved_diff_link">' . 54 '<img src="'.DOKU_BASE.'lib/images/diff.png" class="approved_diff_link" alt="Diff" />' . 55 '</a>'; 56 } 57 58 function showBanner() { 59 if ($this->hlp->isCurrentRevisionApproved()) { 60 $class = 'approved_yes'; 61 } else { 62 if ($this->hlp->isHiddenForUser()) { 63 return; 64 } 65 $class = 'approved_no'; 66 } 67 68 printf('<div class="approval %s">', $class); 69 $this->showLatestDraftIfNewer(); 70 $this->showLatestApprovedVersion(); 71 $this->showDraft(); 72 $this->showApproved(); 73 $this->showPreviousApproved(); 74 75 $this->showApproveAction(); 76 $this->showInternalNote(); 77 78 echo '</div>'; 79 } 80 81 function showInternalNote() { 82 $note = trim($this->getConf('internal note')); 83 if ($note === '') { 84 return; 85 } 86 if (!$this->hlp->isHidden()) { 87 return; 88 } 89 90 printf('<span>%s</span>', hsc($note)); 91 } 92 93 function showLatestDraftIfNewer() { 94 global $ID; 95 $revision = $this->hlp->getRevision(); 96 $latestRevision = $this->hlp->getLastestRevision(); 97 98 if ($revision >= $latestRevision) { 99 return; 100 } 101 if ($this->hlp->isRevisionApproved($latestRevision)) { 102 return; 103 } 104 105 echo '<span class="approval_latest_draft">'; 106 printf($this->getLang('apr_recent_draft'), wl($ID, 'force_rev=1')); 107 echo $this->difflink($ID, null, $revision) . '</span>'; 108 } 109 110 function showLatestApprovedVersion() { 111 global $ID; 112 $revision = $this->hlp->getRevision(); 113 $latestApprovedRevision = $this->hlp->getLatestApprovedRevision(); 114 115 if ($latestApprovedRevision <= $revision) { 116 return; 117 } 118 119 $latestRevision = $this->hlp->getLastestRevision(); 120 if ($latestApprovedRevision == $latestRevision) { 121 //$latestApprovedRevision = ''; 122 } 123 echo '<span class="approval_outdated">'; 124 printf($this->getLang('apr_outdated'), wl($ID, 'rev=' . $latestApprovedRevision)); 125 echo $this->difflink($ID, $latestApprovedRevision, $revision) . '</span>'; 126 } 127 128 function showDraft() { 129 $revision = $this->hlp->getRevision(); 130 131 if ($this->hlp->isCurrentRevisionApproved()) { 132 return; 133 } 134 135 $approvals = $this->hlp->getApprovalsOnRevision($this->hlp->getRevision()); 136 $approvalCount = count($approvals); 137 138 echo '<span class="approval_draft">'; 139 printf($this->getLang('apr_draft'), '<span class="approval_date">' . dformat($revision) . '</span>'); 140 echo '<br />'; 141 printf(' ' . $this->getLang('approvals'), $approvalCount, $this->getConf('number_of_approved')); 142 if ($approvalCount != 0) { 143 printf(' ' . $this->getLang('approved by'), implode(', ', $this->hlp->getApprovers())); 144 } 145 echo '</span>'; 146 } 147 148 function showApproved() { 149 if (!$this->hlp->isCurrentRevisionApproved()) { 150 return; 151 } 152 153 echo '<span class="approval_approved">'; 154 printf($this->getLang('apr_approved'), 155 '<span class="approval_date">' . dformat($this->hlp->getApprovalDate()) . '</span>', 156 implode(', ', $this->hlp->getApprovers())); 157 echo '</span>'; 158 } 159 160 function showPreviousApproved() { 161 global $ID; 162 $previousApproved = $this->hlp->getPreviousApprovedRevision(); 163 if (!$previousApproved) { 164 return; 165 } 166 echo '<span class="approval_previous">'; 167 printf($this->getLang('apr_previous'), 168 wl($ID, 'rev=' . $previousApproved), 169 dformat($previousApproved)); 170 echo $this->difflink($ID, $previousApproved, $this->hlp->getRevision()) . '</span>'; 171 } 172 173 private function showApproveAction() { 174 global $ID; 175 global $REV; 176 global $USERINFO; 177 if (!$this->hlp->canApprove()) { 178 return; 179 } 180 181 $approvals = $this->hlp->getApprovalsOnRevision($this->hlp->getRevision()); 182 foreach ($approvals as $approve) { 183 if ($approve[1] == $_SERVER['REMOTE_USER']) { 184 return; 185 } 186 if ($approve[1] == $USERINFO['mail']) { 187 return; 188 } 189 } 190 191 echo '<span class="approval_action">'; 192 echo '<a href="' . wl($ID, array('rev' => $REV, 'publish_approve'=>1)) . '">'; 193 echo $this->getLang('approve action'); 194 echo '</a>'; 195 echo '</span> '; 196 } 197} 198