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 try { 61 if($INPUT->post->has('fn') && checkSecurityToken()) { 62 $actions = $INPUT->post->arr('fn'); 63 foreach($actions as $action => $extensions) { 64 foreach($extensions as $extname => $label) { 65 switch($action) { 66 case 'install': 67 case 'reinstall': 68 case 'update': 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 break; 75 case 'uninstall': 76 $extension->setExtension($extname); 77 $status = $extension->uninstall(); 78 if($status !== true) { 79 msg($status, -1); 80 } else { 81 msg(sprintf($this->getLang('msg_delete_success'), hsc($extension->getDisplayName())), 1); 82 } 83 break; 84 case 'enable'; 85 $extension->setExtension($extname); 86 $status = $extension->enable(); 87 if($status !== true) { 88 msg($status, -1); 89 } else { 90 msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getDisplayName())), 1); 91 } 92 break; 93 case 'disable'; 94 $extension->setExtension($extname); 95 $status = $extension->disable(); 96 if($status !== true) { 97 msg($status, -1); 98 } else { 99 msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getDisplayName())), 1); 100 } 101 break; 102 } 103 } 104 } 105 send_redirect($this->gui->tabURL('', array(), '&', true)); 106 } elseif($INPUT->post->str('installurl') && checkSecurityToken()) { 107 $installed = $extension->installFromURL($INPUT->post->str('installurl')); 108 foreach($installed as $ext => $info) { 109 msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1); 110 } 111 send_redirect($this->gui->tabURL('', array(), '&', true)); 112 } elseif(isset($_FILES['installfile']) && checkSecurityToken()) { 113 $installed = $extension->installFromUpload('installfile'); 114 foreach($installed as $ext => $info) { 115 msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1); 116 } 117 send_redirect($this->gui->tabURL('', array(), '&', true)); 118 } 119 120 } catch(Exception $e) { 121 msg($e->getMessage(), -1); 122 send_redirect($this->gui->tabURL('', array(), '&', true)); 123 } 124 125 } 126 127 /** 128 * Render HTML output 129 */ 130 public function html() { 131 ptln('<h1>'.$this->getLang('menu').'</h1>'); 132 ptln('<div id="extension__manager">'); 133 134 $this->gui->tabNavigation(); 135 136 switch($this->gui->currentTab()) { 137 case 'search': 138 $this->gui->tabSearch(); 139 break; 140 case 'templates': 141 $this->gui->tabTemplates(); 142 break; 143 case 'install': 144 $this->gui->tabInstall(); 145 break; 146 case 'plugins': 147 default: 148 $this->gui->tabPlugins(); 149 } 150 151 ptln('</div>'); 152 } 153} 154 155// vim:ts=4:sw=4:et: