1<?php 2 3namespace dokuwiki\plugin\dev\www; 4 5use dokuwiki\plugin\dev\Skeletor; 6use splitbrain\PHPArchive\ArchiveIllegalCompressionException; 7use splitbrain\PHPArchive\ArchiveIOException; 8use splitbrain\PHPArchive\Zip; 9 10class PluginWizard 11{ 12 13 /** 14 * @throws ArchiveIllegalCompressionException 15 * @throws ArchiveIOException 16 */ 17 public function handle() 18 { 19 if (!isset($_POST['base'])) return null; 20 21 $skeletor = new Skeletor( 22 Skeletor::TYPE_PLUGIN, 23 $_POST['base'] ?: '', //FIXME clean base 24 $_POST['desc'] ?: '', 25 $_POST['author'] ?: '', 26 $_POST['mail'] ?: '', 27 '', 28 $_POST['url'] ?: '' 29 ); 30 $skeletor->addBasics(); 31 32 if (!empty($_POST['use_lang'])) $skeletor->addLang(); 33 if (!empty($_POST['use_conf'])) $skeletor->addConf(); 34 if (!empty($_POST['use_test'])) $skeletor->addTest(); 35 36 foreach ($_POST['components'] as $id) { 37 list($type, /*"plugin"*/, /*base*/, $component) = array_pad(explode('_', $id, 4), 4, ''); 38 if (isset($_POST['options'][$id])) { 39 $options = array_filter(array_map('trim', explode(',', $_POST['options'][$id]))); 40 } else { 41 $options = []; 42 } 43 44 $skeletor->addComponent($type, $component, $options); 45 } 46 47 $zip = new Zip(); 48 $zip->setCompression(9); 49 $zip->create(); 50 foreach ($skeletor->getFiles() as $file => $content) { 51 $zip->addData($_POST['base'] . '/' . $file, $content); 52 } 53 54 return $zip->getArchive(); 55 } 56 57 58 /** 59 * Get options for all available plugin types 60 */ 61 public function getPluginTypes() 62 { 63 return Skeletor::PLUGIN_TYPES; 64 } 65 66 public function getEvents() 67 { 68 return array_map('trim', file(__DIR__ . '/../events.txt', FILE_IGNORE_NEW_LINES)); 69 } 70 71} 72 73 74 75 76 77