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