1bc461538SMichael Große<?php 2bc461538SMichael Große/** 3bc461538SMichael Große * Plugin Skeleton: Displays "Hello World!" 4bc461538SMichael Große * 5bc461538SMichael Große * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6bc461538SMichael Große * @author Christopher Smith <chris@jalakai.co.uk> 7bc461538SMichael Große */ 8bc461538SMichael Große 9bc461538SMichael Große 10bc461538SMichael Große/** 11bc461538SMichael Große * All DokuWiki plugins to extend the admin function 12bc461538SMichael Große * need to inherit from this class 13bc461538SMichael Große */ 14bc461538SMichael Großeclass admin_plugin_farmer_plugins extends DokuWiki_Admin_Plugin { 15bc461538SMichael Große 16bc461538SMichael Große /** 17bc461538SMichael Große * handle user request 18bc461538SMichael Große */ 19*0b96e6d7SMichael Große public function handle() { 20bc461538SMichael Große 21bc461538SMichael Große if (!file_exists(DOKU_INC . 'inc/preload.php')) { 22bc461538SMichael Große global $ID; 23bc461538SMichael Große $get = $_GET; 24bc461538SMichael Große if(isset($get['id'])) unset($get['id']); 25bc461538SMichael Große $get['page'] = 'farmer_foo'; 26bc461538SMichael Große $self = wl($ID, $get, false, '&'); 27bc461538SMichael Große send_redirect($self); 28bc461538SMichael Große } 29bc461538SMichael Große 30*0b96e6d7SMichael Große if (isset($_REQUEST['farmer_submitBulk'])) { 31*0b96e6d7SMichael Große /** @var helper_plugin_farmer $helper */ 32*0b96e6d7SMichael Große $helper = plugin_load('helper', 'farmer'); 33*0b96e6d7SMichael Große $animals = $helper->getAllAnimals(); 34*0b96e6d7SMichael Große $plugin = $_REQUEST['farmer__bulkPluginSelect']; 35*0b96e6d7SMichael Große foreach ($animals as $animal) { 36*0b96e6d7SMichael Große $pluginConf = file(DOKU_FARMDIR . $animal . '/conf/plugins.local.php'); 37*0b96e6d7SMichael Große if ($_REQUEST['farmer_submitBulk'] === 'activate') { 38*0b96e6d7SMichael Große foreach ($pluginConf as $key => $line) { 39*0b96e6d7SMichael Große if (strpos($line, '$plugins[' . $plugin . ']') !== FALSE) { 40*0b96e6d7SMichael Große array_splice($pluginConf, $key, 1); 41*0b96e6d7SMichael Große break; // the plugin was deactivated and the deactivation is now removed 42bc461538SMichael Große } 43bc461538SMichael Große } 44*0b96e6d7SMichael Große } else { 45*0b96e6d7SMichael Große $pluginIsActive = true; 46*0b96e6d7SMichael Große foreach ($pluginConf as $key => $line) { 47*0b96e6d7SMichael Große if (strpos($line, '$plugins[' . $plugin . ']') !== FALSE) { 48*0b96e6d7SMichael Große $pluginIsActive = false; 49*0b96e6d7SMichael Große break; // the plugin is already deactivated; 50bc461538SMichael Große } 51bc461538SMichael Große } 52*0b96e6d7SMichael Große if ($pluginIsActive) { 53*0b96e6d7SMichael Große $pluginConf[] = '$plugins[' . $plugin . '] = 0'; 54bc461538SMichael Große } 55*0b96e6d7SMichael Große } 56*0b96e6d7SMichael Große io_saveFile(DOKU_FARMDIR . $animal . '/conf/plugins.local.php', implode('\n',$pluginConf)); 57*0b96e6d7SMichael Große touch(DOKU_FARMDIR . $animal . '/conf/local.php'); 58*0b96e6d7SMichael Große } 59*0b96e6d7SMichael Große } 60bc461538SMichael Große } 61bc461538SMichael Große 62bc461538SMichael Große /** 63bc461538SMichael Große * output appropriate html 64bc461538SMichael Große */ 65*0b96e6d7SMichael Große public function html() { 66bc461538SMichael Große echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.min.js"></script>'; 67bc461538SMichael Große echo '<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.min.css" type="text/css" rel="stylesheet" />'; 68bc461538SMichael Große 69*0b96e6d7SMichael Große $switchForm = new \dokuwiki\Form\Form(); 70*0b96e6d7SMichael Große $switchForm->addFieldsetOpen('edit a single animal or all at once?'); 71*0b96e6d7SMichael Große $switchForm->addRadioButton('bulkSingleSwitch', 'bulk edit all animals')->id('farmer__bulk')->attr('type','radio')->addClass('block'); 72*0b96e6d7SMichael Große $switchForm->addRadioButton('bulkSingleSwitch', 'edit a single animal')->id('farmer__single')->attr('type','radio')->addClass('block'); 73*0b96e6d7SMichael Große $switchForm->addFieldsetClose(); 74*0b96e6d7SMichael Große echo $switchForm->toHTML(); 75bc461538SMichael Große 76*0b96e6d7SMichael Große /** @var helper_plugin_farmer $helper */ 77*0b96e6d7SMichael Große $helper = plugin_load('helper', 'farmer'); 78*0b96e6d7SMichael Große $plugins = $helper->getAllPlugins(); 79*0b96e6d7SMichael Große 80*0b96e6d7SMichael Große $bulkForm = new \dokuwiki\Form\Form(); 81*0b96e6d7SMichael Große $bulkForm->id('farmer__bulkForm'); 82*0b96e6d7SMichael Große $bulkForm->addHTML('bulk'); 83*0b96e6d7SMichael Große $bulkForm->addTagOpen('select')->id('farmer__bulkPluginSelect')->attr('name','farmer__bulkPlugin'); 84*0b96e6d7SMichael Große $bulkForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', ""); 85*0b96e6d7SMichael Große $bulkForm->addTagClose('option'); 86*0b96e6d7SMichael Große foreach ($plugins as $plugin) { 87*0b96e6d7SMichael Große $bulkForm->addTagOpen('option')->attr('value', $plugin); 88*0b96e6d7SMichael Große $bulkForm->addHTML($plugin); 89*0b96e6d7SMichael Große $bulkForm->addTagClose('option'); 90*0b96e6d7SMichael Große } 91*0b96e6d7SMichael Große $bulkForm->addTagClose('select'); 92*0b96e6d7SMichael Große $bulkForm->addButton('farmer__submitBulk','Activate')->attr('value','activate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton'); 93*0b96e6d7SMichael Große $bulkForm->addButton('farmer__submitBulk','Deactivate')->attr('value','deactivate')->attr('type','submit')->attr('disabled','disabled')->addClass('bulkButton'); 94*0b96e6d7SMichael Große echo $bulkForm->toHTML(); 95*0b96e6d7SMichael Große 96*0b96e6d7SMichael Große $singleForm = new \dokuwiki\Form\Form(); 97*0b96e6d7SMichael Große $singleForm->id('farmer__singlePluginForm'); 98*0b96e6d7SMichael Große $singleForm->addTagOpen('select')->id('farmer__animalSelect'); 99*0b96e6d7SMichael Große $singleForm->addTagOpen('option')->attr('selected', 'selected')->attr('disabled', 'disabled')->attr('hidden', 'hidden')->attr('value', ""); 100*0b96e6d7SMichael Große $singleForm->addTagClose('option'); 101*0b96e6d7SMichael Große $animals = $helper->getAllAnimals(); 102*0b96e6d7SMichael Große foreach ($animals as $animal) { 103*0b96e6d7SMichael Große $singleForm->addTagOpen('option'); 104*0b96e6d7SMichael Große $singleForm->addHTML($animal); 105*0b96e6d7SMichael Große $singleForm->addTagClose('option'); 106*0b96e6d7SMichael Große } 107*0b96e6d7SMichael Große $singleForm->addTagClose('select'); 108*0b96e6d7SMichael Große echo $singleForm->toHTML(); 109bc461538SMichael Große } 110bc461538SMichael Große 111bc461538SMichael Große public function getMenuText() { 112bc461538SMichael Große return 'Farmer: Change animal plugins'; 113bc461538SMichael Große } 114bc461538SMichael Große 115bc461538SMichael Große public function getMenuSort() { 116bc461538SMichael Große return 42; 117bc461538SMichael Große } 118bc461538SMichael Große 119bc461538SMichael Große} 120bc461538SMichael Große 121