14d6d17d0SAndreas Gohr<?php 24d6d17d0SAndreas Gohr/** 34d6d17d0SAndreas Gohr * DokuWiki Plugin acknowledge (Action Component) 44d6d17d0SAndreas Gohr * 54d6d17d0SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 64d6d17d0SAndreas Gohr * @author Andreas Gohr, Anna Dabrowska <dokuwiki@cosmocode.de> 74d6d17d0SAndreas Gohr */ 84d6d17d0SAndreas Gohr 94d6d17d0SAndreas Gohr// must be run within Dokuwiki 104d6d17d0SAndreas Gohrif (!defined('DOKU_INC')) { 114d6d17d0SAndreas Gohr die(); 124d6d17d0SAndreas Gohr} 134d6d17d0SAndreas Gohr 144d6d17d0SAndreas Gohrclass action_plugin_acknowledge extends DokuWiki_Action_Plugin 154d6d17d0SAndreas Gohr{ 164d6d17d0SAndreas Gohr 17*ef3ab392SAndreas Gohr /** @inheritDoc */ 184d6d17d0SAndreas Gohr public function register(Doku_Event_Handler $controller) 194d6d17d0SAndreas Gohr { 20*ef3ab392SAndreas Gohr $controller->register_hook('COMMON_WIKIPAGE_SAVE', 'AFTER', $this, 'handlePageSave'); 21*ef3ab392SAndreas Gohr $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjax'); 224d6d17d0SAndreas Gohr } 234d6d17d0SAndreas Gohr 244d6d17d0SAndreas Gohr /** 25*ef3ab392SAndreas Gohr * Manage page meta data 264d6d17d0SAndreas Gohr * 27*ef3ab392SAndreas Gohr * Store page last modified date 28*ef3ab392SAndreas Gohr * Handle page deletions 29*ef3ab392SAndreas Gohr * Remove assignments on page save, they get readded on rendering if needed 304d6d17d0SAndreas Gohr * 31*ef3ab392SAndreas Gohr * @param Doku_Event $event 32*ef3ab392SAndreas Gohr * @param $param 334d6d17d0SAndreas Gohr */ 34*ef3ab392SAndreas Gohr public function handlePageSave(Doku_Event $event, $param) 354d6d17d0SAndreas Gohr { 36*ef3ab392SAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 37*ef3ab392SAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 38*ef3ab392SAndreas Gohr 39*ef3ab392SAndreas Gohr if ($event->data['changeType'] === DOKU_CHANGE_TYPE_DELETE) { 40*ef3ab392SAndreas Gohr $helper->removePage($event->data['id']); 41*ef3ab392SAndreas Gohr } elseif ($event->data['changeType'] !== DOKU_CHANGE_TYPE_MINOR_EDIT) { 42*ef3ab392SAndreas Gohr $helper->storePageDate($event->data['id'], $event->data['newRevision']); 434d6d17d0SAndreas Gohr } 444d6d17d0SAndreas Gohr 45*ef3ab392SAndreas Gohr $helper->clearAssignments($event->data['id']); 46*ef3ab392SAndreas Gohr } 47*ef3ab392SAndreas Gohr 48*ef3ab392SAndreas Gohr /** 49*ef3ab392SAndreas Gohr * @param Doku_Event $event 50*ef3ab392SAndreas Gohr * @param $param 51*ef3ab392SAndreas Gohr */ 52*ef3ab392SAndreas Gohr public function handleAjax(Doku_Event $event, $param) 53*ef3ab392SAndreas Gohr { 54*ef3ab392SAndreas Gohr if ($event->data === 'plugin_acknowledge_html') { 55*ef3ab392SAndreas Gohr echo $this->html(); 56*ef3ab392SAndreas Gohr $event->stopPropagation(); 57*ef3ab392SAndreas Gohr $event->preventDefault(); 58*ef3ab392SAndreas Gohr } 59*ef3ab392SAndreas Gohr } 60*ef3ab392SAndreas Gohr 61*ef3ab392SAndreas Gohr /** 62*ef3ab392SAndreas Gohr * Returns the acknowledgment form/confirmation 63*ef3ab392SAndreas Gohr * 64*ef3ab392SAndreas Gohr * @return string The HTML to display 65*ef3ab392SAndreas Gohr */ 66*ef3ab392SAndreas Gohr protected function html() 67*ef3ab392SAndreas Gohr { 68*ef3ab392SAndreas Gohr global $INPUT; 69*ef3ab392SAndreas Gohr global $USERINFO; 70*ef3ab392SAndreas Gohr $id = $INPUT->str('id'); 71*ef3ab392SAndreas Gohr $user = $INPUT->server->str('REMOTE_USER'); 72*ef3ab392SAndreas Gohr if ($id === '' || $user === '') return ''; 73*ef3ab392SAndreas Gohr 74*ef3ab392SAndreas Gohr /** @var helper_plugin_acknowledge $helper */ 75*ef3ab392SAndreas Gohr $helper = plugin_load('helper', 'acknowledge'); 76*ef3ab392SAndreas Gohr 77*ef3ab392SAndreas Gohr $html = ''; 78*ef3ab392SAndreas Gohr 79*ef3ab392SAndreas Gohr $ack = $helper->hasUserAcknowledged($id, $user); 80*ef3ab392SAndreas Gohr if ($ack) { 81*ef3ab392SAndreas Gohr 82*ef3ab392SAndreas Gohr $html .= '<div>'; 83*ef3ab392SAndreas Gohr $html .= 'You acknowledged this page ' . sprintf('%f', $ack); 84*ef3ab392SAndreas Gohr $html .= '</div>'; 85*ef3ab392SAndreas Gohr } elseif ($helper->isUserAssigned($id, $user, $USERINFO['grps'])) { 86*ef3ab392SAndreas Gohr $html .= '<div>'; 87*ef3ab392SAndreas Gohr $html .= 'You need to acknowledge this'; 88*ef3ab392SAndreas Gohr $html .= '</div>'; 89*ef3ab392SAndreas Gohr } 90*ef3ab392SAndreas Gohr 91*ef3ab392SAndreas Gohr return $html; 92*ef3ab392SAndreas Gohr } 934d6d17d0SAndreas Gohr} 944d6d17d0SAndreas Gohr 95