1<?php 2 3namespace dokuwiki\plugin\config\core\Setting; 4 5/** 6 * Class setting_dirchoice 7 */ 8class SettingDirchoice extends SettingMultichoice 9{ 10 11 protected $dir = ''; 12 13 /** @inheritdoc */ 14 public function initialize($default = null, $local = null, $protected = null) 15 { 16 17 // populate $this->_choices with a list of directories 18 $list = []; 19 20 if($dh = @opendir($this->dir)) { 21 while(false !== ($entry = readdir($dh))) { 22 if($entry == '.' || $entry == '..') continue; 23 if($this->pattern && !preg_match($this->pattern, $entry)) continue; 24 25 $file = (is_link($this->dir . $entry)) ? readlink($this->dir . $entry) : $this->dir . $entry; 26 if(is_dir($file)) $list[] = $entry; 27 } 28 closedir($dh); 29 } 30 sort($list); 31 $this->choices = $list; 32 33 parent::initialize($default, $local, $protected); 34 } 35} 36