1<?php 2 3namespace dokuwiki\plugin\extension; 4 5use dokuwiki\Logger; 6use RuntimeException; 7 8class Local 9{ 10 /** 11 * Glob the given directory and init each subdirectory as an Extension 12 * 13 * Directories that cannot be initialized as an extension (e.g. leftover 14 * directories with an invalid base name like "myplugin (copy)") are skipped 15 * so a single stray directory does not break the whole listing. 16 * 17 * @param string $directory 18 * @return Extension[] 19 */ 20 protected function readExtensionsFromDirectory($directory) 21 { 22 $extensions = []; 23 $directory = rtrim($directory, '/'); 24 $dirs = glob($directory . '/*', GLOB_ONLYDIR); 25 foreach ($dirs as $dir) { 26 try { 27 $ext = Extension::createFromDirectory($dir); 28 } catch (RuntimeException $e) { 29 Logger::debug('Skipping invalid extension directory: ' . $dir, $e->getMessage()); 30 continue; 31 } 32 $extensions[$ext->getId()] = $ext; 33 } 34 return $extensions; 35 } 36 37 /** 38 * Get all locally installed templates 39 * 40 * @return Extension[] 41 */ 42 public function getTemplates() 43 { 44 $templates = $this->readExtensionsFromDirectory(DOKU_INC . 'lib/tpl/'); 45 ksort($templates); 46 return $templates; 47 } 48 49 /** 50 * Get all locally installed plugins 51 * 52 * Note this skips the PluginController and just iterates over the plugin dir, 53 * it's basically the same as what the PluginController does, but allows us to 54 * directly initialize Extension objects. 55 * 56 * @return Extension[] 57 */ 58 public function getPlugins() 59 { 60 $plugins = $this->readExtensionsFromDirectory(DOKU_PLUGIN); 61 ksort($plugins); 62 return $plugins; 63 } 64 65 /** 66 * Get all locally installed extensions 67 * 68 * @return Extension[] 69 */ 70 public function getExtensions() 71 { 72 return array_merge($this->getPlugins(), $this->getTemplates()); 73 } 74} 75