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 53 if(!$repository->hasAccess()){ 54 $url = $this->gui->tabURL('', array('purge'=>1)); 55 msg($this->getLang('repo_error').' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1); 56 } 57 58 /* @var helper_plugin_extension_extension $extension */ 59 $extension = $this->loadHelper('extension_extension'); 60 61 if ($INPUT->post->has('fn')) { 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 try { 70 $extension->setExtension($extname); 71 $installed = $extension->installOrUpdate(); 72 foreach($installed as $extension => $info){ 73 msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1); 74 } 75 }catch (Exception $e){ 76 msg($e->getMessage(), -1); 77 } 78 break; 79 case 'uninstall': 80 $extension->setExtension($extname); 81 $status = $extension->uninstall(); 82 if ($status !== true) { 83 msg($status, -1); 84 } else { 85 msg(sprintf($this->getLang('msg_delete_success'), hsc($extension->getDisplayName())), 1); 86 } 87 break; 88 case 'enable'; 89 $extension->setExtension($extname); 90 $status = $extension->enable(); 91 if ($status !== true) { 92 msg($status, -1); 93 } else { 94 msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getDisplayName())), 1); 95 } 96 break; 97 case 'disable'; 98 $extension->setExtension($extname); 99 $status = $extension->disable(); 100 if ($status !== true) { 101 msg($status, -1); 102 } else { 103 msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getDisplayName())), 1); 104 } 105 break; 106 } 107 } 108 } 109 } 110 } 111 112 /** 113 * Render HTML output 114 */ 115 public function html() { 116 ptln('<h1>'.$this->getLang('menu').'</h1>'); 117 ptln('<div id="extension__manager">'); 118 119 $this->gui->tabNavigation(); 120 121 switch($this->gui->currentTab()){ 122 case 'search': 123 $this->gui->tabSearch(); 124 break; 125 case 'templates': 126 $this->gui->tabTemplates(); 127 break; 128 case 'install': 129 $this->gui->tabInstall(); 130 break; 131 case 'plugins': 132 default: 133 $this->gui->tabPlugins(); 134 } 135 136 137 ptln('</div>'); 138 } 139} 140 141// vim:ts=4:sw=4:et: