SettingDirchoice.php 942 B

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