xref: /dokuwiki/lib/plugins/extension/Local.php (revision 176901c266ebe449733667e837c06293c2f8322a)
17c9966a5SAndreas Gohr<?php
27c9966a5SAndreas Gohr
37c9966a5SAndreas Gohrnamespace dokuwiki\plugin\extension;
47c9966a5SAndreas Gohr
57c9966a5SAndreas Gohrclass Local
67c9966a5SAndreas Gohr{
77c9966a5SAndreas Gohr    /**
87c9966a5SAndreas Gohr     * Glob the given directory and init each subdirectory as an Extension
97c9966a5SAndreas Gohr     *
107c9966a5SAndreas Gohr     * @param string $directory
117c9966a5SAndreas Gohr     * @return Extension[]
127c9966a5SAndreas Gohr     */
137c9966a5SAndreas Gohr    protected function readExtensionsFromDirectory($directory)
147c9966a5SAndreas Gohr    {
157c9966a5SAndreas Gohr        $extensions = [];
167c9966a5SAndreas Gohr        $directory = rtrim($directory, '/');
177c9966a5SAndreas Gohr        $dirs = glob($directory . '/*', GLOB_ONLYDIR);
187c9966a5SAndreas Gohr        foreach ($dirs as $dir) {
197c9966a5SAndreas Gohr            $ext = Extension::createFromDirectory($dir);
207c9966a5SAndreas Gohr            $extensions[$ext->getId()] = $ext;
217c9966a5SAndreas Gohr        }
227c9966a5SAndreas Gohr        return $extensions;
237c9966a5SAndreas Gohr    }
247c9966a5SAndreas Gohr
257c9966a5SAndreas Gohr    /**
267c9966a5SAndreas Gohr     * Get all locally installed templates
277c9966a5SAndreas Gohr     *
287c9966a5SAndreas Gohr     * @return Extension[]
297c9966a5SAndreas Gohr     */
307c9966a5SAndreas Gohr    public function getTemplates()
317c9966a5SAndreas Gohr    {
32*176901c2SAndreas Gohr        $templates = $this->readExtensionsFromDirectory(DOKU_INC . 'lib/tpl/');
337c9966a5SAndreas Gohr        ksort($templates);
347c9966a5SAndreas Gohr        return $templates;
357c9966a5SAndreas Gohr    }
367c9966a5SAndreas Gohr
377c9966a5SAndreas Gohr    /**
387c9966a5SAndreas Gohr     * Get all locally installed plugins
397c9966a5SAndreas Gohr     *
407c9966a5SAndreas Gohr     * Note this skips the PluginController and just iterates over the plugin dir,
417c9966a5SAndreas Gohr     * it's basically the same as what the PluginController does, but allows us to
427c9966a5SAndreas Gohr     * directly initialize Extension objects.
437c9966a5SAndreas Gohr     *
447c9966a5SAndreas Gohr     * @return Extension[]
457c9966a5SAndreas Gohr     */
467c9966a5SAndreas Gohr    public function getPlugins()
477c9966a5SAndreas Gohr    {
487c9966a5SAndreas Gohr        $plugins = $this->readExtensionsFromDirectory(DOKU_PLUGIN);
497c9966a5SAndreas Gohr        ksort($plugins);
507c9966a5SAndreas Gohr        return $plugins;
517c9966a5SAndreas Gohr    }
527c9966a5SAndreas Gohr
537c9966a5SAndreas Gohr    /**
547c9966a5SAndreas Gohr     * Get all locally installed extensions
557c9966a5SAndreas Gohr     *
567c9966a5SAndreas Gohr     * @return Extension[]
577c9966a5SAndreas Gohr     */
587c9966a5SAndreas Gohr    public function getExtensions()
597c9966a5SAndreas Gohr    {
607c9966a5SAndreas Gohr        return array_merge($this->getPlugins(), $this->getTemplates());
617c9966a5SAndreas Gohr    }
627c9966a5SAndreas Gohr}
63