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 * @throws ArchiveIllegalCompressionException 14 * @throws ArchiveIOException 15 */ 16 public function handle() 17 { 18 if (!isset($_POST['base'])) return null; 19 20 $base = preg_replace('/[^a-z0-9]/i', '', $_POST['base']); 21 22 $skeletor = new Skeletor( 23 Skeletor::TYPE_PLUGIN, 24 $base, 25 $_POST['desc'] ?: '', 26 $_POST['author'] ?: '', 27 $_POST['mail'] ?: '', 28 '', 29 $_POST['url'] ?: '' 30 ); 31 $skeletor->addBasics(); 32 33 if (!empty($_POST['use_lang'])) $skeletor->addLang(); 34 if (!empty($_POST['use_conf'])) $skeletor->addConf(); 35 if (!empty($_POST['use_test'])) $skeletor->addTest(); 36 37 foreach ($_POST['components'] as $id) { 38 [$type, , , $component] = array_pad(explode('_', $id, 4), 4, ''); 39 if (isset($_POST['options'][$id])) { 40 $options = array_filter(array_map('trim', explode(',', $_POST['options'][$id]))); 41 } else { 42 $options = []; 43 } 44 45 $skeletor->addComponent($type, $component, $options); 46 } 47 48 $zip = new Zip(); 49 $zip->setCompression(9); 50 $zip->create(); 51 foreach ($skeletor->getFiles() as $file => $content) { 52 $zip->addData($base . '/' . $file, $content); 53 } 54 55 return $zip->getArchive(); 56 } 57 58 59 /** 60 * Get options for all available plugin types 61 */ 62 public function getPluginTypes() 63 { 64 return Skeletor::PLUGIN_TYPES; 65 } 66 67 public function getEvents() 68 { 69 return array_map('trim', file(__DIR__ . '/../events.txt', FILE_IGNORE_NEW_LINES)); 70 } 71} 72