*/ // must be run within Dokuwiki if (!defined('DOKU_INC')) { die(); } class admin_plugin_approve extends DokuWiki_Admin_Plugin { /** @var helper_plugin_sqlite */ protected $sqlite; /** @var helper_plugin_approve */ protected $helper; /** * @return helper_plugin_sqlite */ protected function sqlite() { if (!$this->sqlite) { /** @var helper_plugin_approve_db $db_helper */ $db_helper = plugin_load('helper', 'approve_db'); $this->sqlite = $db_helper->getDB(); } return $this->sqlite; } /** * @return helper_plugin_approve */ protected function helper() { if (!$this->helper) { $helper = plugin_load('helper', 'approve'); $this->helper = $helper; } return $this->helper; } /** * @return int sort number in admin menu */ public function getMenuSort() { return 1; } protected function getPages() { global $conf; $datadir = $conf['datadir']; if (substr($datadir, -1) != '/') { $datadir .= '/'; } $directory = new RecursiveDirectoryIterator($datadir, FilesystemIterator::SKIP_DOTS); $iterator = new RecursiveIteratorIterator($directory); $pages = []; /** @var SplFileInfo $fileinfo */ foreach ($iterator as $fileinfo) { if (!$fileinfo->isFile()) continue; $path = $fileinfo->getPathname(); //remove .txt $id = str_replace('/', ':', substr($path, strlen($datadir), -4)); $pages[] = $id; } return $pages; } protected function updatePage() { //clean current settings $this->sqlite()->query('DELETE FROM page'); $wikiPages = $this->getPages(); $no_apr_namespace = $this->helper()->no_apr_namespace(); $weighted_assignments = $this->helper()->weighted_assignments(); foreach ($wikiPages as $id) { if ($this->helper()->isPageAssigned($id, $approver, $weighted_assignments)) { $data = [ 'page' => $id, 'hidden' => $this->helper()->in_hidden_namespace($id, $no_apr_namespace) ? '1' : '0' ]; if (!blank($approver)) { $data['approver'] = $approver; } $this->sqlite()->storeEntry('page', $data); } } } /** * Should carry out any processing required by the plugin. */ public function handle() { global $ID; /* @var Input */ global $INPUT; if($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) { $assignment = $INPUT->arr('assignment'); //insert empty string as NULL if ($INPUT->str('action') === 'delete') { $this->sqlite()->query('DELETE FROM maintainer WHERE id=?', $assignment['id']); $this->updatePage(); } else if ($INPUT->str('action') === 'add' && !blank($assignment['assign'])) { $data = [ 'namespace' => $assignment['assign'] ]; if (!blank($assignment['approver'])) { $data['approver'] = $assignment['approver']; } $this->sqlite()->storeEntry('maintainer', $data); $this->updatePage(); } send_redirect(wl($ID, array('do' => 'admin', 'page' => 'approve'), true, '&')); } } /** * Render HTML output, e.g. helpful text and a form */ public function html() { global $ID; /* @var DokuWiki_Auth_Plugin $auth */ global $auth; $res = $this->sqlite()->query('SELECT * FROM maintainer ORDER BY namespace'); $assignments = $this->sqlite()->res2arr($res); echo $this->locale_xhtml('assignments_intro'); echo '
'; echo ''; echo ''; echo ''; echo ''; // header echo ''; echo ''; echo ''; echo ''; echo ''; // existing assignments foreach($assignments as $assignment) { $id = $assignment['id']; $namespace = $assignment['namespace']; $approver = $assignment['approver'] ? $assignment['approver'] : '---'; $link = wl( $ID, array( 'do' => 'admin', 'page' => 'approve', 'action' => 'delete', 'sectok' => getSecurityToken(), 'assignment[id]' => $id ) ); echo ''; echo ''; $user = $auth->getUserData($approver); if ($user) { echo ''; } else { echo ''; } echo ''; echo ''; } // new assignment form echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'.$this->getLang('admin h_assignment_namespace').''.$this->getLang('admin h_assignment_approver').'
' . hsc($namespace) . '' . hsc($user['name']) . '' . hsc($approver) . ''.$this->getLang('admin btn_delete').'
'; echo ''; echo '
'; } } // vim:ts=4:sw=4:et: