1<?php 2 3use dokuwiki\plugin\structpublish\meta\Revision; 4 5/** 6 * Action component responsible for the publish banner 7 * attached to struct data of a page 8 */ 9class action_plugin_structpublish_banner extends DokuWiki_Action_Plugin 10{ 11 /** @var \helper_plugin_structpublish_permissions */ 12 protected $permissionsHelper; 13 /** @var \helper_plugin_structpublish_db */ 14 protected $dbHelper; 15 16 /** 17 * @inheritDoc 18 */ 19 public function register(Doku_Event_Handler $controller) 20 { 21 $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'renderBanner'); 22 } 23 24 /** 25 * Add banner to pages under structpublish control 26 */ 27 public function renderBanner(Doku_Event $event) 28 { 29 global $ID; 30 global $INFO; 31 32 if ($event->data !== 'show') return; 33 34 $this->permissionsHelper = plugin_load('helper', 'structpublish_permissions'); 35 $this->dbHelper = plugin_load('helper', 'structpublish_permissions'); 36 if (!$this->permissionsHelper->isPublishable()) return; 37 38 $revision = new Revision($this->permissionsHelper->getDb(), $ID, $INFO['currentrev']); 39 40 echo $this->getBannerHtml($revision); 41 } 42 43 /** 44 * @param Revision $revision latest publish data 45 * @return string 46 */ 47 protected function getBannerHtml($revision) 48 { 49 global $ID; 50 $user = $_SERVER['REMOTE_USER']; 51 $html = ''; 52 53 if ($this->permissionsHelper->isPublisher($ID, $user)) { 54 55 $status = $revision->getStatus() ?: Revision::STATUS_DRAFT; 56 $version = $revision->getVersion() ?: ''; 57 $html = sprintf( 58 $this->getBannerTemplate(), 59 $status, 60 $version, 61 $status, 62 $this->formHtml() 63 ); 64 } 65 66 return $html; 67 } 68 69 protected function formHtml() 70 { 71 $form = new dokuwiki\Form\Form(); 72 $form->addButton('structpublish[review]', 'REVIEWED'); 73 $form->addButton('structpublish[publish]', 'PUBLISH'); 74 75 return $form->toHTML(); 76 } 77 78 protected function getBannerTemplate() 79 { 80 $template = '<div class="plugin-structpublish-banner banner-%s">'; 81 $template .= '<div class="plugin-structpublish-banner banner-header">structpublish</div>'; 82 $template .= '<div class="plugin-structpublish-version">' . $this->getLang('version') . ': %s</div>'; 83 $template .= '<div class="plugin-structpublish-status">' . $this->getLang('status') . ': %s</div>'; 84 $template .= '<div class="plugin-structpublish-actions">' . $this->getLang('actions') . ': %s</div>'; 85 $template .= '</div>'; 86 87 return $template; 88 } 89} 90