1<?php 2 3use dokuwiki\Extension\Plugin; 4 5class helper_plugin_approve_acl extends Plugin 6{ 7 public function useApproveHere($id) { 8 /** @var helper_plugin_approve_db $db */ 9 $db = $this->loadHelper('approve_db'); 10 $page_metadata = $db->getPageMetadata($id); 11 if ($page_metadata === null) { // do not use approve plugin here 12 return false; 13 } 14 return true; 15 } 16 17 public function clientCanApprove($id): bool 18 { 19 global $INFO; 20 21 // user not log in 22 if (!isset($INFO['userinfo'])) return false; 23 24 /** @var helper_plugin_approve_db $db */ 25 $db = $this->loadHelper('approve_db'); 26 $page_metadata = $db->getPageMetadata($id); 27 28 if ($page_metadata === null) { 29 return false; 30 } elseif ($page_metadata['approver'] == $INFO['client']) { // user is approver 31 return true; 32 // user is in approvers group 33 } elseif (strncmp($page_metadata['approver'], "@", 1) === 0 && 34 in_array(substr($page_metadata['approver'], 1), $INFO['userinfo']['grps'])) { 35 return true; 36 // if the user has AUTH_DELETE permission and the approver is not defined or strict_approver is turn off 37 // user can approve the page 38 } elseif (auth_quickaclcheck($id) >= AUTH_DELETE && 39 ($page_metadata['approver'] === null || !$this->getConf('strict_approver'))) { 40 return true; 41 } 42 return false; 43 } 44 45 public function clientCanMarkReadyForApproval($id): bool { 46 global $INFO; 47 48 $ready_for_approval_acl = preg_split('/\s+/', $this->getConf('ready_for_approval_acl'), 49 -1, PREG_SPLIT_NO_EMPTY); 50 51 if (count($ready_for_approval_acl) == 0) { 52 return auth_quickaclcheck($id) >= AUTH_EDIT; 53 } 54 foreach ($ready_for_approval_acl as $user_or_group) { 55 if ($user_or_group[0] == '@' && in_array(substr($user_or_group, 1), $INFO['userinfo']['grps'])) { 56 return true; 57 } elseif ($user_or_group == $INFO['client']) { 58 return true; 59 } 60 } 61 return false; 62 } 63 64 public function clientCanSeeDrafts($id): bool { 65 66 // in view mode no one can see drafts 67 if ($this->getConf('viewmode') && get_doku_pref('approve_viewmode', false)) return false; 68 69 if (!$this->getConf('hide_drafts_for_viewers')) return true; 70 71 if (auth_quickaclcheck($id) >= AUTH_EDIT) return true; 72 if ($this->clientCanApprove($id)) return true; 73 74 return false; 75 } 76} 77