1788f86d9SMichael Hamann<?php 2788f86d9SMichael Hamann/** 3788f86d9SMichael Hamann * DokuWiki Plugin extension (Admin Component) 4788f86d9SMichael Hamann * 5788f86d9SMichael Hamann * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6788f86d9SMichael Hamann * @author Michael Hamann <michael@content-space.de> 7788f86d9SMichael Hamann */ 8788f86d9SMichael Hamann 902779b18SMichael Hamann/** 1002779b18SMichael Hamann * Admin part of the extension manager 1102779b18SMichael Hamann */ 1218b1e90aSAndreas Gohrclass admin_plugin_extension extends DokuWiki_Admin_Plugin 1318b1e90aSAndreas Gohr{ 1402779b18SMichael Hamann protected $infoFor = null; 15d7410643SAndreas Gohr /** @var helper_plugin_extension_gui */ 16d7410643SAndreas Gohr protected $gui; 17d7410643SAndreas Gohr 18d7410643SAndreas Gohr /** 19d7410643SAndreas Gohr * Constructor 20d7410643SAndreas Gohr * 21d7410643SAndreas Gohr * loads additional helpers 22d7410643SAndreas Gohr */ 2318b1e90aSAndreas Gohr public function __construct() 2418b1e90aSAndreas Gohr { 25d7410643SAndreas Gohr $this->gui = plugin_load('helper', 'extension_gui'); 26d7410643SAndreas Gohr } 27788f86d9SMichael Hamann 28788f86d9SMichael Hamann /** 29788f86d9SMichael Hamann * @return int sort number in admin menu 30788f86d9SMichael Hamann */ 3118b1e90aSAndreas Gohr public function getMenuSort() 3218b1e90aSAndreas Gohr { 33788f86d9SMichael Hamann return 0; 34788f86d9SMichael Hamann } 35788f86d9SMichael Hamann 36788f86d9SMichael Hamann /** 37788f86d9SMichael Hamann * @return bool true if only access for superuser, false is for superusers and moderators 38788f86d9SMichael Hamann */ 3918b1e90aSAndreas Gohr public function forAdminOnly() 4018b1e90aSAndreas Gohr { 41788f86d9SMichael Hamann return true; 42788f86d9SMichael Hamann } 43788f86d9SMichael Hamann 44788f86d9SMichael Hamann /** 4502779b18SMichael Hamann * Execute the requested action(s) and initialize the plugin repository 46788f86d9SMichael Hamann */ 4718b1e90aSAndreas Gohr public function handle() 4818b1e90aSAndreas Gohr { 4902779b18SMichael Hamann global $INPUT; 5002779b18SMichael Hamann // initialize the remote repository 51788f86d9SMichael Hamann /* @var helper_plugin_extension_repository $repository */ 52788f86d9SMichael Hamann $repository = $this->loadHelper('extension_repository'); 5355332151SAndreas Gohr 5498d21c04SAndreas Gohr if (!$repository->hasAccess(!$INPUT->bool('purge'))) { 55a72f333fSSatoshi Sahara $url = $this->gui->tabURL('', ['purge' => 1], '&'); 56cf833595SSatoshi Sahara msg($this->getLang('repo_error'). 57cf833595SSatoshi Sahara ' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1 58cf833595SSatoshi Sahara ); 59e45b5c14SAndreas Gohr } 60e45b5c14SAndreas Gohr 611ec86040SAndreas Gohr if (!in_array('ssl', stream_get_transports())) { 621ec86040SAndreas Gohr msg($this->getLang('nossl'), -1); 631ec86040SAndreas Gohr } 641ec86040SAndreas Gohr 6502779b18SMichael Hamann /* @var helper_plugin_extension_extension $extension */ 6602779b18SMichael Hamann $extension = $this->loadHelper('extension_extension'); 6702779b18SMichael Hamann 6832fdfac2SAndreas Gohr try { 69fee60c9eSAndreas Gohr if ($INPUT->post->has('fn') && checkSecurityToken()) { 7002779b18SMichael Hamann $actions = $INPUT->post->arr('fn'); 7102779b18SMichael Hamann foreach ($actions as $action => $extensions) { 7202779b18SMichael Hamann foreach ($extensions as $extname => $label) { 7302779b18SMichael Hamann switch ($action) { 7402779b18SMichael Hamann case 'install': 7502779b18SMichael Hamann case 'reinstall': 7602779b18SMichael Hamann case 'update': 77519895b5SAndreas Gohr $extension->setExtension($extname); 785c0b30bfSAndreas Gohr $installed = $extension->installOrUpdate(); 79fee60c9eSAndreas Gohr foreach ($installed as $ext => $info) { 80cf833595SSatoshi Sahara msg(sprintf( 8164159a61SAndreas Gohr $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), 82cf833595SSatoshi Sahara $info['base']), 1 8364159a61SAndreas Gohr ); 845c0b30bfSAndreas Gohr } 8502779b18SMichael Hamann break; 8602779b18SMichael Hamann case 'uninstall': 87519895b5SAndreas Gohr $extension->setExtension($extname); 8802779b18SMichael Hamann $status = $extension->uninstall(); 897e8500eeSGerrit Uitslag if ($status) { 90cf833595SSatoshi Sahara msg(sprintf( 9164159a61SAndreas Gohr $this->getLang('msg_delete_success'), 92cf833595SSatoshi Sahara hsc($extension->getDisplayName())), 1 9364159a61SAndreas Gohr ); 947e8500eeSGerrit Uitslag } else { 95cf833595SSatoshi Sahara msg(sprintf( 9664159a61SAndreas Gohr $this->getLang('msg_delete_failed'), 97cf833595SSatoshi Sahara hsc($extension->getDisplayName())), -1 9864159a61SAndreas Gohr ); 9902779b18SMichael Hamann } 10002779b18SMichael Hamann break; 10118b1e90aSAndreas Gohr case 'enable': 102519895b5SAndreas Gohr $extension->setExtension($extname); 10302779b18SMichael Hamann $status = $extension->enable(); 10402779b18SMichael Hamann if ($status !== true) { 10502779b18SMichael Hamann msg($status, -1); 10602779b18SMichael Hamann } else { 107cf833595SSatoshi Sahara msg(sprintf( 108cf833595SSatoshi Sahara $this->getLang('msg_enabled'), 109cf833595SSatoshi Sahara hsc($extension->getDisplayName())), 1 110cf833595SSatoshi Sahara ); 11102779b18SMichael Hamann } 11202779b18SMichael Hamann break; 11318b1e90aSAndreas Gohr case 'disable': 114519895b5SAndreas Gohr $extension->setExtension($extname); 11502779b18SMichael Hamann $status = $extension->disable(); 11602779b18SMichael Hamann if ($status !== true) { 11702779b18SMichael Hamann msg($status, -1); 11802779b18SMichael Hamann } else { 119cf833595SSatoshi Sahara msg(sprintf( 120cf833595SSatoshi Sahara $this->getLang('msg_disabled'), 121cf833595SSatoshi Sahara hsc($extension->getDisplayName())), 1 122cf833595SSatoshi Sahara ); 12302779b18SMichael Hamann } 12402779b18SMichael Hamann break; 12502779b18SMichael Hamann } 12602779b18SMichael Hamann } 12702779b18SMichael Hamann } 128a72f333fSSatoshi Sahara send_redirect($this->gui->tabURL('', [], '&', true)); 129fee60c9eSAndreas Gohr } elseif ($INPUT->post->str('installurl') && checkSecurityToken()) { 130*9ea219ceSPhy $installed = $extension->installFromURL( 131*9ea219ceSPhy $INPUT->post->str('installurl'), 132*9ea219ceSPhy $INPUT->post->bool('overwrite')); 133fee60c9eSAndreas Gohr foreach ($installed as $ext => $info) { 134cf833595SSatoshi Sahara msg(sprintf( 135cf833595SSatoshi Sahara $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), 136cf833595SSatoshi Sahara $info['base']), 1 137cf833595SSatoshi Sahara ); 138fee60c9eSAndreas Gohr } 139a72f333fSSatoshi Sahara send_redirect($this->gui->tabURL('', [], '&', true)); 140fee60c9eSAndreas Gohr } elseif (isset($_FILES['installfile']) && checkSecurityToken()) { 141bc20e40aSPhy $installed = $extension->installFromUpload('installfile', $INPUT->post->bool('overwrite')); 142fee60c9eSAndreas Gohr foreach ($installed as $ext => $info) { 143cf833595SSatoshi Sahara msg(sprintf( 144cf833595SSatoshi Sahara $this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), 145cf833595SSatoshi Sahara $info['base']), 1 146cf833595SSatoshi Sahara ); 147fee60c9eSAndreas Gohr } 148a72f333fSSatoshi Sahara send_redirect($this->gui->tabURL('', [], '&', true)); 14932fdfac2SAndreas Gohr } 150fee60c9eSAndreas Gohr } catch (Exception $e) { 151fee60c9eSAndreas Gohr msg($e->getMessage(), -1); 152a72f333fSSatoshi Sahara send_redirect($this->gui->tabURL('', [], '&', true)); 153fee60c9eSAndreas Gohr } 154788f86d9SMichael Hamann } 155788f86d9SMichael Hamann 156788f86d9SMichael Hamann /** 15702779b18SMichael Hamann * Render HTML output 158788f86d9SMichael Hamann */ 15918b1e90aSAndreas Gohr public function html() 16018b1e90aSAndreas Gohr { 161a72f333fSSatoshi Sahara echo '<h1>'.$this->getLang('menu').'</h1>'.DOKU_LF; 162a72f333fSSatoshi Sahara echo '<div id="extension__manager">'.DOKU_LF; 163788f86d9SMichael Hamann 164d7410643SAndreas Gohr $this->gui->tabNavigation(); 165d7410643SAndreas Gohr 1665d7f3164SAndreas Gohr switch ($this->gui->currentTab()) { 167d7410643SAndreas Gohr case 'search': 1681dd40c86SAndreas Gohr $this->gui->tabSearch(); 169d7410643SAndreas Gohr break; 1705d7f3164SAndreas Gohr case 'templates': 1711dd40c86SAndreas Gohr $this->gui->tabTemplates(); 1725d7f3164SAndreas Gohr break; 173ea9f3f90SAndreas Gohr case 'install': 174ea9f3f90SAndreas Gohr $this->gui->tabInstall(); 175ea9f3f90SAndreas Gohr break; 176d7410643SAndreas Gohr case 'plugins': 177d7410643SAndreas Gohr default: 1781dd40c86SAndreas Gohr $this->gui->tabPlugins(); 179d7410643SAndreas Gohr } 180d7410643SAndreas Gohr 181a72f333fSSatoshi Sahara echo '</div>'.DOKU_LF; 182788f86d9SMichael Hamann } 183788f86d9SMichael Hamann} 184788f86d9SMichael Hamann 185788f86d9SMichael Hamann// vim:ts=4:sw=4:et: 186