register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'renderBanner'); } /** * Add banner to pages under structpublish control */ public function renderBanner(Doku_Event $event) { global $ID; global $INFO; if ($event->data !== 'show') return; $this->permissionsHelper = plugin_load('helper', 'structpublish_permissions'); $this->dbHelper = plugin_load('helper', 'structpublish_db'); if (!$this->dbHelper->IS_PUBLISHER($ID)) return; $revision = new Revision($this->permissionsHelper->getDb(), $ID, $INFO['rev']); echo $this->getBannerHtml($revision); } /** * @param Revision $revision latest publish data * @return string */ protected function getBannerHtml($revision) { global $ID; $user = $_SERVER['REMOTE_USER']; $html = ''; if ($this->dbHelper->IS_PUBLISHER($ID, $user)) { $status = $revision->getStatus() ?: Revision::STATUS_DRAFT; $publisher = userlink($revision->getUser(), true); $publishDate = $revision->getDate(); $version = ''; if ($revision->getVersion()) { $version = ''; $version .= $revision->getVersion() . " ($publishDate, $publisher)"; $version .= ''; } $actionForm = $this->formHtml($status); $html = sprintf( $this->getBannerTemplate(), $status, $status, $version, $actionForm ); } return $html; } protected function formHtml($status) { if ($status === Revision::STATUS_PUBLISHED) return ''; $form = new dokuwiki\Form\Form(); if ($status !== Revision::STATUS_APPROVED) { $form->addButton('structpublish[approve]', 'APPROVE')->attr('type', 'submit'); } $form->addButton('structpublish[publish]', 'PUBLISH')->attr('type', 'submit'); return $form->toHTML(); } protected function getBannerTemplate() { $template = '
'; return $template; } }