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