xref: /plugin/dev/www/PluginWizard.php (revision cde324c25eade52a46b205d6870d3f1b4fc22e18)
189e2f9d1SAndreas Gohr<?php
289e2f9d1SAndreas Gohr
389e2f9d1SAndreas Gohrnamespace dokuwiki\plugin\dev\www;
489e2f9d1SAndreas Gohr
589e2f9d1SAndreas Gohruse dokuwiki\plugin\dev\Skeletor;
689e2f9d1SAndreas Gohruse splitbrain\PHPArchive\ArchiveIllegalCompressionException;
789e2f9d1SAndreas Gohruse splitbrain\PHPArchive\ArchiveIOException;
889e2f9d1SAndreas Gohruse splitbrain\PHPArchive\Zip;
989e2f9d1SAndreas Gohr
1089e2f9d1SAndreas Gohrclass PluginWizard
1189e2f9d1SAndreas Gohr{
1289e2f9d1SAndreas Gohr
1389e2f9d1SAndreas Gohr    /**
1489e2f9d1SAndreas Gohr     * @throws ArchiveIllegalCompressionException
1589e2f9d1SAndreas Gohr     * @throws ArchiveIOException
1689e2f9d1SAndreas Gohr     */
1789e2f9d1SAndreas Gohr    public function handle()
1889e2f9d1SAndreas Gohr    {
1989e2f9d1SAndreas Gohr        if (!isset($_POST['base'])) return null;
2089e2f9d1SAndreas Gohr
21*cde324c2SAndreas Gohr        $base = preg_replace('/[^a-z0-9]/i', '', $_POST['base']);
22*cde324c2SAndreas Gohr
2389e2f9d1SAndreas Gohr        $skeletor = new Skeletor(
2489e2f9d1SAndreas Gohr            Skeletor::TYPE_PLUGIN,
25*cde324c2SAndreas Gohr            $base,
2689e2f9d1SAndreas Gohr            $_POST['desc'] ?: '',
2789e2f9d1SAndreas Gohr            $_POST['author'] ?: '',
2889e2f9d1SAndreas Gohr            $_POST['mail'] ?: '',
2989e2f9d1SAndreas Gohr            '',
3089e2f9d1SAndreas Gohr            $_POST['url'] ?: ''
3189e2f9d1SAndreas Gohr        );
3289e2f9d1SAndreas Gohr        $skeletor->addBasics();
3389e2f9d1SAndreas Gohr
3489e2f9d1SAndreas Gohr        if (!empty($_POST['use_lang'])) $skeletor->addLang();
3589e2f9d1SAndreas Gohr        if (!empty($_POST['use_conf'])) $skeletor->addConf();
3689e2f9d1SAndreas Gohr        if (!empty($_POST['use_test'])) $skeletor->addTest();
3789e2f9d1SAndreas Gohr
3889e2f9d1SAndreas Gohr        foreach ($_POST['components'] as $id) {
3989e2f9d1SAndreas Gohr            list($type, /*"plugin"*/, /*base*/, $component) = array_pad(explode('_', $id, 4), 4, '');
4089e2f9d1SAndreas Gohr            if (isset($_POST['options'][$id])) {
4189e2f9d1SAndreas Gohr                $options = array_filter(array_map('trim', explode(',', $_POST['options'][$id])));
4289e2f9d1SAndreas Gohr            } else {
4389e2f9d1SAndreas Gohr                $options = [];
4489e2f9d1SAndreas Gohr            }
4589e2f9d1SAndreas Gohr
4689e2f9d1SAndreas Gohr            $skeletor->addComponent($type, $component, $options);
4789e2f9d1SAndreas Gohr        }
4889e2f9d1SAndreas Gohr
4989e2f9d1SAndreas Gohr        $zip = new Zip();
5089e2f9d1SAndreas Gohr        $zip->setCompression(9);
5189e2f9d1SAndreas Gohr        $zip->create();
5289e2f9d1SAndreas Gohr        foreach ($skeletor->getFiles() as $file => $content) {
53*cde324c2SAndreas Gohr            $zip->addData($base . '/' . $file, $content);
5489e2f9d1SAndreas Gohr        }
5589e2f9d1SAndreas Gohr
5689e2f9d1SAndreas Gohr        return $zip->getArchive();
5789e2f9d1SAndreas Gohr    }
5889e2f9d1SAndreas Gohr
5989e2f9d1SAndreas Gohr
6089e2f9d1SAndreas Gohr    /**
6189e2f9d1SAndreas Gohr     * Get options for all available plugin types
6289e2f9d1SAndreas Gohr     */
6389e2f9d1SAndreas Gohr    public function getPluginTypes()
6489e2f9d1SAndreas Gohr    {
6589e2f9d1SAndreas Gohr        return Skeletor::PLUGIN_TYPES;
6689e2f9d1SAndreas Gohr    }
6789e2f9d1SAndreas Gohr
6889e2f9d1SAndreas Gohr    public function getEvents()
6989e2f9d1SAndreas Gohr    {
7089e2f9d1SAndreas Gohr        return array_map('trim', file(__DIR__ . '/../events.txt', FILE_IGNORE_NEW_LINES));
7189e2f9d1SAndreas Gohr    }
7289e2f9d1SAndreas Gohr
7389e2f9d1SAndreas Gohr}
7489e2f9d1SAndreas Gohr
7589e2f9d1SAndreas Gohr
7689e2f9d1SAndreas Gohr
7789e2f9d1SAndreas Gohr
7889e2f9d1SAndreas Gohr
79