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