1<?php
2
3namespace dokuwiki\plugin\extension;
4
5class Local
6{
7    /**
8     * Glob the given directory and init each subdirectory as an Extension
9     *
10     * @param string $directory
11     * @return Extension[]
12     */
13    protected function readExtensionsFromDirectory($directory)
14    {
15        $extensions = [];
16        $directory = rtrim($directory, '/');
17        $dirs = glob($directory . '/*', GLOB_ONLYDIR);
18        foreach ($dirs as $dir) {
19            $ext = Extension::createFromDirectory($dir);
20            $extensions[$ext->getId()] = $ext;
21        }
22        return $extensions;
23    }
24
25    /**
26     * Get all locally installed templates
27     *
28     * @return Extension[]
29     */
30    public function getTemplates()
31    {
32        $templates = $this->readExtensionsFromDirectory(DOKU_INC . 'lib/tpl/');
33        ksort($templates);
34        return $templates;
35    }
36
37    /**
38     * Get all locally installed plugins
39     *
40     * Note this skips the PluginController and just iterates over the plugin dir,
41     * it's basically the same as what the PluginController does, but allows us to
42     * directly initialize Extension objects.
43     *
44     * @return Extension[]
45     */
46    public function getPlugins()
47    {
48        $plugins = $this->readExtensionsFromDirectory(DOKU_PLUGIN);
49        ksort($plugins);
50        return $plugins;
51    }
52
53    /**
54     * Get all locally installed extensions
55     *
56     * @return Extension[]
57     */
58    public function getExtensions()
59    {
60        return array_merge($this->getPlugins(), $this->getTemplates());
61    }
62}
63