1<?php 2/** 3 * DokuWiki Plugin extension (Admin Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Michael Hamann <michael@content-space.de> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12/** 13 * Admin part of the extension manager 14 */ 15class admin_plugin_extension extends DokuWiki_Admin_Plugin { 16 protected $infoFor = null; 17 /** @var helper_plugin_extension_gui */ 18 protected $gui; 19 20 /** 21 * Constructor 22 * 23 * loads additional helpers 24 */ 25 public function __construct() { 26 $this->gui = plugin_load('helper', 'extension_gui'); 27 } 28 29 /** 30 * @return int sort number in admin menu 31 */ 32 public function getMenuSort() { 33 return 0; 34 } 35 36 /** 37 * @return bool true if only access for superuser, false is for superusers and moderators 38 */ 39 public function forAdminOnly() { 40 return true; 41 } 42 43 /** 44 * Execute the requested action(s) and initialize the plugin repository 45 */ 46 public function handle() { 47 global $INPUT; 48 // initialize the remote repository 49 /* @var helper_plugin_extension_repository $repository */ 50 $repository = $this->loadHelper('extension_repository'); 51 52 if(!$repository->hasAccess()) { 53 $url = $this->gui->tabURL('', array('purge' => 1)); 54 msg($this->getLang('repo_error').' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1); 55 } 56 57 /* @var helper_plugin_extension_extension $extension */ 58 $extension = $this->loadHelper('extension_extension'); 59 60 if($INPUT->post->has('fn') && checkSecurityToken()) { 61 $actions = $INPUT->post->arr('fn'); 62 foreach($actions as $action => $extensions) { 63 foreach($extensions as $extname => $label) { 64 switch($action) { 65 case 'install': 66 case 'reinstall': 67 case 'update': 68 try { 69 $extension->setExtension($extname); 70 $installed = $extension->installOrUpdate(); 71 foreach($installed as $ext => $info) { 72 msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1); 73 } 74 } catch(Exception $e) { 75 msg($e->getMessage(), -1); 76 } 77 break; 78 case 'uninstall': 79 $extension->setExtension($extname); 80 $status = $extension->uninstall(); 81 if($status !== true) { 82 msg($status, -1); 83 } else { 84 msg(sprintf($this->getLang('msg_delete_success'), hsc($extension->getDisplayName())), 1); 85 } 86 break; 87 case 'enable'; 88 $extension->setExtension($extname); 89 $status = $extension->enable(); 90 if($status !== true) { 91 msg($status, -1); 92 } else { 93 msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getDisplayName())), 1); 94 } 95 break; 96 case 'disable'; 97 $extension->setExtension($extname); 98 $status = $extension->disable(); 99 if($status !== true) { 100 msg($status, -1); 101 } else { 102 msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getDisplayName())), 1); 103 } 104 break; 105 } 106 } 107 } 108 } elseif($INPUT->post->str('installurl') && checkSecurityToken()) { 109 try { 110 $installed = $extension->installFromURL($INPUT->post->str('installurl')); 111 foreach($installed as $ext => $info) { 112 msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1); 113 } 114 } catch(Exception $e) { 115 msg($e->getMessage(), -1); 116 } 117 } elseif(isset($_FILES['installfile']) && checkSecurityToken()) { 118 try { 119 $installed = $extension->installFromUpload('installfile'); 120 foreach($installed as $ext => $info) { 121 msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1); 122 } 123 } catch(Exception $e) { 124 msg($e->getMessage(), -1); 125 } 126 } 127 } 128 129 /** 130 * Render HTML output 131 */ 132 public function html() { 133 ptln('<h1>'.$this->getLang('menu').'</h1>'); 134 ptln('<div id="extension__manager">'); 135 136 $this->gui->tabNavigation(); 137 138 switch($this->gui->currentTab()) { 139 case 'search': 140 $this->gui->tabSearch(); 141 break; 142 case 'templates': 143 $this->gui->tabTemplates(); 144 break; 145 case 'install': 146 $this->gui->tabInstall(); 147 break; 148 case 'plugins': 149 default: 150 $this->gui->tabPlugins(); 151 } 152 153 ptln('</div>'); 154 } 155} 156 157// vim:ts=4:sw=4:et: