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