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