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