function handle_revisions(Doku_Event &$event, $param)
 {
     global $ID;
     global $INFO;
     if (!$this->hlp->isActive()) {
         return;
     }
     $meta = p_get_metadata($ID);
     $latest_rev = $meta['last_change']['date'];
     $member = null;
     foreach ($event->data->_content as $key => $ref) {
         if (isset($ref['_elem']) && $ref['_elem'] == 'opentag' && $ref['_tag'] == 'div' && $ref['class'] == 'li') {
             $member = $key;
         }
         if ($member && $ref['_elem'] == 'tag' && $ref['_tag'] == 'input' && $ref['name'] == 'rev2[]') {
             $revision = $ref['value'];
             if ($revision == 'current') {
                 $revision = $INFO['meta']['date']['modified'];
             }
             if ($this->hlp->isRevisionApproved($revision)) {
                 $event->data->_content[$member]['class'] = 'li approved_revision';
             } else {
                 $event->data->_content[$member]['class'] = 'li unapproved_revision';
             }
             $member = null;
         }
     }
     return true;
 }
 function handle_recent(Doku_Event &$event, $param)
 {
     if (!$this->hlp->isActive()) {
         return;
     }
     $render = $event->data->_content;
     $parent = null;
     foreach ($render as $id => $element) {
         if ($this->isParentTag($element)) {
             $parent = $id;
             continue;
         }
         if ($parent === null) {
             continue;
         }
         $id = $this->getPageId($element);
         if (!$id) {
             continue;
         }
         if ($this->hlp->isCurrentRevisionApproved($id)) {
             $event->data->_content[$parent]['class'] .= ' approved_revision';
         } else {
             $event->data->_content[$parent]['class'] .= ' unapproved_revision';
         }
         $parent = null;
     }
     return true;
 }
 function addApproval()
 {
     global $USERINFO;
     global $ID;
     global $INFO;
     if (!$INFO['exists']) {
         msg($this->getLang('cannot approve a non-existing revision'), -1);
         return;
     }
     $approvalRevision = $this->helper->getRevision();
     $approvals = $this->helper->getApprovals();
     if (!isset($approvals[$approvalRevision])) {
         $approvals[$approvalRevision] = array();
     }
     $approvals[$approvalRevision][$INFO['client']] = array($INFO['client'], $_SERVER['REMOTE_USER'], $USERINFO['mail'], time());
     $success = p_set_metadata($ID, array('approval' => $approvals), true, true);
     if ($success) {
         msg($this->getLang('version approved'), 1);
         $data = array();
         $data['rev'] = $approvalRevision;
         $data['id'] = $ID;
         $data['approver'] = $_SERVER['REMOTE_USER'];
         $data['approver_info'] = $USERINFO;
         if ($this->getConf('send_mail_on_approve') && $this->helper->isRevisionApproved($approvalRevision)) {
             /** @var action_plugin_publish_mail $mail */
             $mail = plugin_load('action', 'publish_mail');
             $mail->send_approve_mail();
         }
         trigger_event('PLUGIN_PUBLISH_APPROVE', $data);
     } else {
         msg($this->getLang('cannot approve error'), -1);
     }
     send_redirect(wl($ID, array('rev' => $this->helper->getRevision()), true, '&'));
 }
 function hidePage(Doku_Event &$event, $params)
 {
     if (!$this->hlp->isHiddenForUser($event->data['id'])) {
         return;
     }
     $event->data['hidden'] = true;
 }
 function handle_start(&$event, $param)
 {
     global $ACT;
     global $REV;
     global $INFO;
     global $ID;
     if ($ACT !== 'show') {
         return;
     }
     if ($REV != '') {
         return;
     }
     if ($INFO['perm'] != AUTH_READ) {
         return;
     }
     global $_GET;
     if ($_GET['force_rev']) {
         return;
     }
     if (!$this->hlp->isActive()) {
         return;
     }
     if (!$this->hlp->isCurrentRevisionApproved()) {
         $latestApproved = $this->hlp->getLatestApprovedRevision();
         if ($latestApproved) {
             $REV = $latestApproved;
             $INFO['rev'] = $latestApproved;
         }
     }
 }
 /**
  * search callback function
  *
  * filter out pages which can't be approved by the current user
  * then check if they need approving
  */
 function _search_helper(&$data, $base, $file, $type, $lvl, $opts)
 {
     $ns = $opts[0];
     $valid_ns = $opts[1];
     $invalid_ns = $opts[2];
     if ($type == 'd') {
         return $this->hlp->in_sub_namespace($valid_ns, $ns . ':' . str_replace('/', ':', $file));
     }
     if (!preg_match('#\\.txt$#', $file)) {
         return false;
     }
     $id = pathID($ns . $file);
     if (!$this->hlp->in_namespace($valid_ns, $id)) {
         return false;
     }
     if ($this->hlp->in_namespace($invalid_ns, $id)) {
         return false;
     }
     if (auth_quickaclcheck($id) < AUTH_DELETE) {
         return false;
     }
     $meta = $this->hlp->getMeta($id);
     if ($this->hlp->isCurrentRevisionApproved($id)) {
         // Already approved
         return false;
     }
     $data[] = array($id, $meta['approval'], $meta['last_change']['date']);
     return false;
 }
 /**
  * @param Doku_Event $event
  * @param array $param
  */
 function remove(&$event, $param)
 {
     if (!$this->hlp->isActive()) {
         return;
     }
     if (!$this->getConf('delete attic on first approve')) {
         return;
     }
     if ($this->hlp->getPreviousApprovedRevision()) {
         return;
         // previous version exist
     }
     global $ID;
     $revisions = getRevisions($ID, 0, 0, 0);
     foreach ($revisions as $revision) {
         $fn = wikiFN($ID, $revision);
         if (file_exists($fn)) {
             @unlink($fn);
         }
     }
 }
 /**
  * Create the body of mails to inform about a changed or an approved page
  *
  * @param string $action Must either be "change" or "approve"
  * @return bool|string
  *
  */
 public function create_mail_body($action)
 {
     global $ID;
     global $conf;
     $pageinfo = pageinfo();
     // get mail text
     $rev = $pageinfo['lastmod'];
     if ($action === 'change') {
         $body = io_readFile($this->localFN('mailchangetext'));
         //If there is no approved revision show the diff to the revision before. Otherwise show the diff to the last approved revision.
         if ($this->hlp->hasApprovals($pageinfo['meta'])) {
             $aprpre = 'Aproved';
             $oldrev = $this->hlp->getLatestApprovedRevision($ID);
             $difflink = $this->hlp->getDifflink($ID, $oldrev, $rev);
         } else {
             $aprpre = 'Previous';
             $changelog = new PageChangelog($ID);
             $oldrev = $changelog->getRelativeRevision($rev, -1);
             $difflink = $this->hlp->getDifflink($ID, $oldrev, $rev);
         }
         $body = str_replace('@DIFF@', $difflink, $body);
         $body = str_replace('@APRPRE@', $aprpre, $body);
         $summary = $pageinfo['meta']['last_change']['sum'];
         $body = str_replace('@SUMMARY@', $summary, $body);
         if ($oldrev === false) {
             $oldlink = '---';
         } else {
             $oldlink = $this->revlink($ID, $oldrev);
         }
         $body = str_replace('@OLDPAGE@', $oldlink, $body);
         $newlink = $this->revlink($ID, $rev);
         $body = str_replace('@NEWPAGE@', $newlink, $body);
     } elseif ($action === 'approve') {
         $body = io_readFile($this->localFN('mailapprovetext'));
         $newlink = $this->revlink($ID, $rev);
         $body = str_replace('@URL@', $newlink, $body);
         $changelog = new PageChangelog($ID);
         $revinfo = $changelog->getRevisionInfo($rev);
         /** @var DokuWiki_Auth_Plugin $auth */
         global $auth;
         $userinfo = $auth->getUserData($revinfo['user']);
         $body = str_replace('@FULLNAME@', $userinfo['name'], $body);
     } else {
         return false;
     }
     $body = str_replace('@DOKUWIKIURL@', DOKU_URL, $body);
     $body = str_replace('@TITLE@', $conf['title'], $body);
     return $body;
 }
 private function showApproveAction()
 {
     global $ID;
     global $REV;
     global $USERINFO;
     if (!$this->hlp->canApprove()) {
         return;
     }
     $approvals = $this->hlp->getApprovalsOnRevision($this->hlp->getRevision());
     foreach ($approvals as $approve) {
         if ($approve[1] == $_SERVER['REMOTE_USER']) {
             return;
         }
         if ($approve[1] == $USERINFO['mail']) {
             return;
         }
     }
     echo '<span class="approval_action">';
     echo '<a href="' . wl($ID, array('rev' => $REV, 'publish_approve' => 1)) . '">';
     echo $this->getLang('approve action');
     echo '</a>';
     echo '</span> ';
 }