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